watchdog-api.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. The Linux Watchdog driver API.
  2. Copyright 2002 Christer Weingel <wingel@nano-system.com>
  3. Some parts of this document are copied verbatim from the sbc60xxwdt
  4. driver which is (c) Copyright 2000 Jakob Oestergaard <jakob@ostenfeld.dk>
  5. This document describes the state of the Linux 2.4.18 kernel.
  6. Introduction:
  7. A Watchdog Timer (WDT) is a hardware circuit that can reset the
  8. computer system in case of a software fault. You probably knew that
  9. already.
  10. Usually a userspace daemon will notify the kernel watchdog driver via the
  11. /dev/watchdog special device file that userspace is still alive, at
  12. regular intervals. When such a notification occurs, the driver will
  13. usually tell the hardware watchdog that everything is in order, and
  14. that the watchdog should wait for yet another little while to reset
  15. the system. If userspace fails (RAM error, kernel bug, whatever), the
  16. notifications cease to occur, and the hardware watchdog will reset the
  17. system (causing a reboot) after the timeout occurs.
  18. The Linux watchdog API is a rather AD hoc construction and different
  19. drivers implement different, and sometimes incompatible, parts of it.
  20. This file is an attempt to document the existing usage and allow
  21. future driver writers to use it as a reference.
  22. The simplest API:
  23. All drivers support the basic mode of operation, where the watchdog
  24. activates as soon as /dev/watchdog is opened and will reboot unless
  25. the watchdog is pinged within a certain time, this time is called the
  26. timeout or margin. The simplest way to ping the watchdog is to write
  27. some data to the device. So a very simple watchdog daemon would look
  28. like this:
  29. #include <stdlib.h>
  30. #include <fcntl.h>
  31. int main(int argc, const char *argv[]) {
  32. int fd=open("/dev/watchdog",O_WRONLY);
  33. if (fd==-1) {
  34. perror("watchdog");
  35. exit(1);
  36. }
  37. while(1) {
  38. write(fd, "\0", 1);
  39. sleep(10);
  40. }
  41. }
  42. A more advanced driver could for example check that a HTTP server is
  43. still responding before doing the write call to ping the watchdog.
  44. When the device is closed, the watchdog is disabled. This is not
  45. always such a good idea, since if there is a bug in the watchdog
  46. daemon and it crashes the system will not reboot. Because of this,
  47. some of the drivers support the configuration option "Disable watchdog
  48. shutdown on close", CONFIG_WATCHDOG_NOWAYOUT. If it is set to Y when
  49. compiling the kernel, there is no way of disabling the watchdog once
  50. it has been started. So, if the watchdog dameon crashes, the system
  51. will reboot after the timeout has passed.
  52. Some other drivers will not disable the watchdog, unless a specific
  53. magic character 'V' has been sent /dev/watchdog just before closing
  54. the file. If the userspace daemon closes the file without sending
  55. this special character, the driver will assume that the daemon (and
  56. userspace in general) died, and will stop pinging the watchdog without
  57. disabling it first. This will then cause a reboot.
  58. The ioctl API:
  59. All conforming drivers also support an ioctl API.
  60. Pinging the watchdog using an ioctl:
  61. All drivers that have an ioctl interface support at least one ioctl,
  62. KEEPALIVE. This ioctl does exactly the same thing as a write to the
  63. watchdog device, so the main loop in the above program could be
  64. replaced with:
  65. while (1) {
  66. ioctl(fd, WDIOC_KEEPALIVE, 0);
  67. sleep(10);
  68. }
  69. the argument to the ioctl is ignored.
  70. Setting and getting the timeout:
  71. For some drivers it is possible to modify the watchdog timeout on the
  72. fly with the SETTIMEOUT ioctl, those drivers have the WDIOF_SETTIMEOUT
  73. flag set in their option field. The argument is an integer
  74. representing the timeout in seconds. The driver returns the real
  75. timeout used in the same variable, and this timeout might differ from
  76. the requested one due to limitation of the hardware.
  77. int timeout = 45;
  78. ioctl(fd, WDIOC_SETTIMEOUT, &timeout);
  79. printf("The timeout was set to %d seconds\n", timeout);
  80. This example might actually print "The timeout was set to 60 seconds"
  81. if the device has a granularity of minutes for its timeout.
  82. Starting with the Linux 2.4.18 kernel, it is possible to query the
  83. current timeout using the GETTIMEOUT ioctl.
  84. ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
  85. printf("The timeout was is %d seconds\n", timeout);
  86. Envinronmental monitoring:
  87. All watchdog drivers are required return more information about the system,
  88. some do temperature, fan and power level monitoring, some can tell you
  89. the reason for the last reboot of the system. The GETSUPPORT ioctl is
  90. available to ask what the device can do:
  91. struct watchdog_info ident;
  92. ioctl(fd, WDIOC_GETSUPPORT, &ident);
  93. the fields returned in the ident struct are:
  94. identity a string identifying the watchdog driver
  95. firmware_version the firmware version of the card if available
  96. options a flags describing what the device supports
  97. the options field can have the following bits set, and describes what
  98. kind of information that the GET_STATUS and GET_BOOT_STATUS ioctls can
  99. return. [FIXME -- Is this correct?]
  100. WDIOF_OVERHEAT Reset due to CPU overheat
  101. The machine was last rebooted by the watchdog because the thermal limit was
  102. exceeded
  103. WDIOF_FANFAULT Fan failed
  104. A system fan monitored by the watchdog card has failed
  105. WDIOF_EXTERN1 External relay 1
  106. External monitoring relay/source 1 was triggered. Controllers intended for
  107. real world applications include external monitoring pins that will trigger
  108. a reset.
  109. WDIOF_EXTERN2 External relay 2
  110. External monitoring relay/source 2 was triggered
  111. WDIOF_POWERUNDER Power bad/power fault
  112. The machine is showing an undervoltage status
  113. WDIOF_CARDRESET Card previously reset the CPU
  114. The last reboot was caused by the watchdog card
  115. WDIOF_POWEROVER Power over voltage
  116. The machine is showing an overvoltage status. Note that if one level is
  117. under and one over both bits will be set - this may seem odd but makes
  118. sense.
  119. WDIOF_KEEPALIVEPING Keep alive ping reply
  120. The watchdog saw a keepalive ping since it was last queried.
  121. WDIOF_SETTIMEOUT Can set/get the timeout
  122. For those drivers that return any bits set in the option field, the
  123. GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current
  124. status, and the status at the last reboot, respectively.
  125. int flags;
  126. ioctl(fd, WDIOC_GETSTATUS, &flags);
  127. or
  128. ioctl(fd, WDIOC_GETBOOTSTATUS, &flags);
  129. Note that not all devices support these two calls, and some only
  130. support the GETBOOTSTATUS call.
  131. Some drivers can measure the temperature using the GETTEMP ioctl. The
  132. returned value is the temperature in degrees farenheit.
  133. int temperature;
  134. ioctl(fd, WDIOC_GETTEMP, &temperature);
  135. Finally the SETOPTIONS ioctl can be used to control some aspects of
  136. the cards operation; right now the pcwd driver is the only one
  137. supporting thiss ioctl.
  138. int options = 0;
  139. ioctl(fd, WDIOC_SETOPTIONS, options);
  140. The following options are available:
  141. WDIOS_DISABLECARD Turn off the watchdog timer
  142. WDIOS_ENABLECARD Turn on the watchdog timer
  143. WDIOS_TEMPPANIC Kernel panic on temperature trip
  144. [FIXME -- better explanations]
  145. Implementations in the current drivers in the kernel tree:
  146. Here I have tried to summarize what the different drivers support and
  147. where they do strange things compared to the other drivers.
  148. acquirewdt.c -- Acquire Single Board Computer
  149. This driver has a hardcoded timeout of 1 minute
  150. Supports CONFIG_WATCHDOG_NOWAYOUT
  151. GETSUPPORT returns KEEPALIVEPING. GETSTATUS will return 1 if
  152. the device is open, 0 if not. [FIXME -- isn't this rather
  153. silly? To be able to use the ioctl, the device must be open
  154. and so GETSTATUS will always return 1].
  155. advantechwdt.c -- Advantech Single Board Computer
  156. Timeout that defaults to 60 seconds, supports SETTIMEOUT.
  157. Supports CONFIG_WATCHDOG_NOWAYOUT
  158. GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
  159. The GETSTATUS call returns if the device is open or not.
  160. [FIXME -- silliness again?]
  161. booke_wdt.c -- PowerPC BookE Watchdog Timer
  162. Timeout default varies according to frequency, supports
  163. SETTIMEOUT
  164. Watchdog can not be turned off, CONFIG_WATCHDOG_NOWAYOUT
  165. does not make sense
  166. GETSUPPORT returns the watchdog_info struct, and
  167. GETSTATUS returns the supported options. GETBOOTSTATUS
  168. returns a 1 if the last reset was caused by the
  169. watchdog and a 0 otherwise. This watchdog can not be
  170. disabled once it has been started. The wdt_period kernel
  171. parameter selects which bit of the time base changing
  172. from 0->1 will trigger the watchdog exception. Changing
  173. the timeout from the ioctl calls will change the
  174. wdt_period as defined above. Finally if you would like to
  175. replace the default Watchdog Handler you can implement the
  176. WatchdogHandler() function in your own code.
  177. eurotechwdt.c -- Eurotech CPU-1220/1410
  178. The timeout can be set using the SETTIMEOUT ioctl and defaults
  179. to 60 seconds.
  180. Also has a module parameter "ev", event type which controls
  181. what should happen on a timeout, the string "int" or anything
  182. else that causes a reboot. [FIXME -- better description]
  183. Supports CONFIG_WATCHDOG_NOWAYOUT
  184. GETSUPPORT returns CARDRESET and WDIOF_SETTIMEOUT but
  185. GETSTATUS is not supported and GETBOOTSTATUS just returns 0.
  186. i810-tco.c -- Intel 810 chipset
  187. Also has support for a lot of other i8x0 stuff, but the
  188. watchdog is one of the things.
  189. The timeout is set using the module parameter "i810_margin",
  190. which is in steps of 0.6 seconds where 2<i810_margin<64. The
  191. driver supports the SETTIMEOUT ioctl.
  192. Supports CONFIG_WATCHDOG_NOWAYOUT.
  193. GETSUPPORT returns WDIOF_SETTIMEOUT. The GETSTATUS call
  194. returns some kind of timer value which ist not compatible with
  195. the other drivers. GETBOOT status returns some kind of
  196. hardware specific boot status. [FIXME -- describe this]
  197. ib700wdt.c -- IB700 Single Board Computer
  198. Default timeout of 30 seconds and the timeout is settable
  199. using the SETTIMEOUT ioctl. Note that only a few timeout
  200. values are supported.
  201. Supports CONFIG_WATCHDOG_NOWAYOUT
  202. GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
  203. The GETSTATUS call returns if the device is open or not.
  204. [FIXME -- silliness again?]
  205. machzwd.c -- MachZ ZF-Logic
  206. Hardcoded timeout of 10 seconds
  207. Has a module parameter "action" that controls what happens
  208. when the timeout runs out which can be 0 = RESET (default),
  209. 1 = SMI, 2 = NMI, 3 = SCI.
  210. Supports CONFIG_WATCHDOG_NOWAYOUT and the magic character
  211. 'V' close handling.
  212. GETSUPPORT returns WDIOF_KEEPALIVEPING, and the GETSTATUS call
  213. returns if the device is open or not. [FIXME -- silliness
  214. again?]
  215. mixcomwd.c -- MixCom Watchdog
  216. [FIXME -- I'm unable to tell what the timeout is]
  217. Supports CONFIG_WATCHDOG_NOWAYOUT
  218. GETSUPPORT returns WDIOF_KEEPALIVEPING, GETSTATUS returns if
  219. the device is opened or not [FIXME -- I'm not really sure how
  220. this works, there seems to be some magic connected to
  221. CONFIG_WATCHDOG_NOWAYOUT]
  222. pcwd.c -- Berkshire PC Watchdog
  223. Hardcoded timeout of 1.5 seconds
  224. Supports CONFIG_WATCHDOG_NOWAYOUT
  225. GETSUPPORT returns WDIOF_OVERHEAT|WDIOF_CARDRESET and both
  226. GETSTATUS and GETBOOTSTATUS return something useful.
  227. The SETOPTIONS call can be used to enable and disable the card
  228. and to ask the driver to call panic if the system overheats.
  229. sbc60xxwdt.c -- 60xx Single Board Computer
  230. Hardcoded timeout of 10 seconds
  231. Does not support CONFIG_WATCHDOG_NOWAYOUT, but has the magic
  232. character 'V' close handling.
  233. No bits set in GETSUPPORT
  234. scx200.c -- National SCx200 CPUs
  235. Not in the kernel yet.
  236. The timeout is set using a module parameter "margin" which
  237. defaults to 60 seconds. The timeout can also be set using
  238. SETTIMEOUT and read using GETTIMEOUT.
  239. Supports a module parameter "nowayout" that is initialized
  240. with the value of CONFIG_WATCHDOG_NOWAYOUT. Also supports the
  241. magic character 'V' handling.
  242. shwdt.c -- SuperH 3/4 processors
  243. [FIXME -- I'm unable to tell what the timeout is]
  244. Supports CONFIG_WATCHDOG_NOWAYOUT
  245. GETSUPPORT returns WDIOF_KEEPALIVEPING, and the GETSTATUS call
  246. returns if the device is open or not. [FIXME -- silliness
  247. again?]
  248. softdog.c -- Software watchdog
  249. The timeout is set with the module parameter "soft_margin"
  250. which defaults to 60 seconds, the timeout is also settable
  251. using the SETTIMEOUT ioctl.
  252. Supports CONFIG_WATCHDOG_NOWAYOUT
  253. WDIOF_SETTIMEOUT bit set in GETSUPPORT
  254. w83877f_wdt.c -- W83877F Computer
  255. Hardcoded timeout of 30 seconds
  256. Does not support CONFIG_WATCHDOG_NOWAYOUT, but has the magic
  257. character 'V' close handling.
  258. No bits set in GETSUPPORT
  259. w83627hf_wdt.c -- w83627hf watchdog
  260. Timeout that defaults to 60 seconds, supports SETTIMEOUT.
  261. Supports CONFIG_WATCHDOG_NOWAYOUT
  262. GETSUPPORT returns WDIOF_KEEPALIVEPING and WDIOF_SETTIMEOUT.
  263. The GETSTATUS call returns if the device is open or not.
  264. wdt.c -- ICS WDT500/501 ISA and
  265. wdt_pci.c -- ICS WDT500/501 PCI
  266. Default timeout of 60 seconds. The timeout is also settable
  267. using the SETTIMEOUT ioctl.
  268. Supports CONFIG_WATCHDOG_NOWAYOUT
  269. GETSUPPORT returns with bits set depending on the actual
  270. card. The WDT501 supports a lot of external monitoring, the
  271. WDT500 much less.
  272. wdt285.c -- Footbridge watchdog
  273. The timeout is set with the module parameter "soft_margin"
  274. which defaults to 60 seconds. The timeout is also settable
  275. using the SETTIMEOUT ioctl.
  276. Does not support CONFIG_WATCHDOG_NOWAYOUT
  277. WDIOF_SETTIMEOUT bit set in GETSUPPORT
  278. wdt977.c -- Netwinder W83977AF chip
  279. Hardcoded timeout of 3 minutes
  280. Supports CONFIG_WATCHDOG_NOWAYOUT
  281. Does not support any ioctls at all.