watchdog-api.txt 13 KB

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