watchdog-api.txt 14 KB

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