diff options
Diffstat (limited to 'Documentation/watchdog/watchdog-api.txt')
-rw-r--r-- | Documentation/watchdog/watchdog-api.txt | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/Documentation/watchdog/watchdog-api.txt b/Documentation/watchdog/watchdog-api.txt index 21ed51173662..958ff3d48be3 100644 --- a/Documentation/watchdog/watchdog-api.txt +++ b/Documentation/watchdog/watchdog-api.txt | |||
@@ -34,22 +34,7 @@ activates as soon as /dev/watchdog is opened and will reboot unless | |||
34 | the watchdog is pinged within a certain time, this time is called the | 34 | the watchdog is pinged within a certain time, this time is called the |
35 | timeout or margin. The simplest way to ping the watchdog is to write | 35 | timeout or margin. The simplest way to ping the watchdog is to write |
36 | some data to the device. So a very simple watchdog daemon would look | 36 | some data to the device. So a very simple watchdog daemon would look |
37 | like this: | 37 | like this source file: see Documentation/watchdog/src/watchdog-simple.c |
38 | |||
39 | #include <stdlib.h> | ||
40 | #include <fcntl.h> | ||
41 | |||
42 | int main(int argc, const char *argv[]) { | ||
43 | int fd=open("/dev/watchdog",O_WRONLY); | ||
44 | if (fd==-1) { | ||
45 | perror("watchdog"); | ||
46 | exit(1); | ||
47 | } | ||
48 | while(1) { | ||
49 | write(fd, "\0", 1); | ||
50 | sleep(10); | ||
51 | } | ||
52 | } | ||
53 | 38 | ||
54 | A more advanced driver could for example check that a HTTP server is | 39 | A more advanced driver could for example check that a HTTP server is |
55 | still responding before doing the write call to ping the watchdog. | 40 | still responding before doing the write call to ping the watchdog. |
@@ -110,7 +95,40 @@ current timeout using the GETTIMEOUT ioctl. | |||
110 | ioctl(fd, WDIOC_GETTIMEOUT, &timeout); | 95 | ioctl(fd, WDIOC_GETTIMEOUT, &timeout); |
111 | printf("The timeout was is %d seconds\n", timeout); | 96 | printf("The timeout was is %d seconds\n", timeout); |
112 | 97 | ||
113 | Envinronmental monitoring: | 98 | Pretimeouts: |
99 | |||
100 | Some watchdog timers can be set to have a trigger go off before the | ||
101 | actual time they will reset the system. This can be done with an NMI, | ||
102 | interrupt, or other mechanism. This allows Linux to record useful | ||
103 | information (like panic information and kernel coredumps) before it | ||
104 | resets. | ||
105 | |||
106 | pretimeout = 10; | ||
107 | ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout); | ||
108 | |||
109 | Note that the pretimeout is the number of seconds before the time | ||
110 | when the timeout will go off. It is not the number of seconds until | ||
111 | the pretimeout. So, for instance, if you set the timeout to 60 seconds | ||
112 | and the pretimeout to 10 seconds, the pretimout will go of in 50 | ||
113 | seconds. Setting a pretimeout to zero disables it. | ||
114 | |||
115 | There is also a get function for getting the pretimeout: | ||
116 | |||
117 | ioctl(fd, WDIOC_GETPRETIMEOUT, &timeout); | ||
118 | printf("The pretimeout was is %d seconds\n", timeout); | ||
119 | |||
120 | Not all watchdog drivers will support a pretimeout. | ||
121 | |||
122 | Get the number of seconds before reboot: | ||
123 | |||
124 | Some watchdog drivers have the ability to report the remaining time | ||
125 | before the system will reboot. The WDIOC_GETTIMELEFT is the ioctl | ||
126 | that returns the number of seconds before reboot. | ||
127 | |||
128 | ioctl(fd, WDIOC_GETTIMELEFT, &timeleft); | ||
129 | printf("The timeout was is %d seconds\n", timeleft); | ||
130 | |||
131 | Environmental monitoring: | ||
114 | 132 | ||
115 | All watchdog drivers are required return more information about the system, | 133 | All watchdog drivers are required return more information about the system, |
116 | some do temperature, fan and power level monitoring, some can tell you | 134 | some do temperature, fan and power level monitoring, some can tell you |
@@ -169,6 +187,10 @@ The watchdog saw a keepalive ping since it was last queried. | |||
169 | 187 | ||
170 | WDIOF_SETTIMEOUT Can set/get the timeout | 188 | WDIOF_SETTIMEOUT Can set/get the timeout |
171 | 189 | ||
190 | The watchdog can do pretimeouts. | ||
191 | |||
192 | WDIOF_PRETIMEOUT Pretimeout (in seconds), get/set | ||
193 | |||
172 | 194 | ||
173 | For those drivers that return any bits set in the option field, the | 195 | For those drivers that return any bits set in the option field, the |
174 | GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current | 196 | GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current |