aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2006-06-28 19:03:06 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-28 19:03:06 -0400
commitfffcb480e4224f25c965b93fa65541bfc7dd732e (patch)
treea48383b5487798cdcc0153e342d6d88abe71333d /Documentation
parentb44597906e03d5e2b467c17a3b73585596c0d7be (diff)
parent56fb9e5346b99bc6b77def79b3739097bc13ea8a (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
* master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog: [WATCHDOG] Documentation/watchdog update [WATCHDOG] convert AT91RM9200 watchdog to platform driver [WATCHDOG] add WDIOC_GETTIMELEFT ioctl [WATCHDOG] Pre-Timeout flags
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/watchdog/pcwd-watchdog.txt75
-rw-r--r--Documentation/watchdog/src/watchdog-simple.c15
-rw-r--r--Documentation/watchdog/src/watchdog-test.c68
-rw-r--r--Documentation/watchdog/watchdog-api.txt56
-rw-r--r--Documentation/watchdog/watchdog.txt23
5 files changed, 126 insertions, 111 deletions
diff --git a/Documentation/watchdog/pcwd-watchdog.txt b/Documentation/watchdog/pcwd-watchdog.txt
index 12187a33e310..d9ee6336c1d4 100644
--- a/Documentation/watchdog/pcwd-watchdog.txt
+++ b/Documentation/watchdog/pcwd-watchdog.txt
@@ -22,78 +22,9 @@
22 to run the program with an "&" to run it in the background!) 22 to run the program with an "&" to run it in the background!)
23 23
24 If you want to write a program to be compatible with the PC Watchdog 24 If you want to write a program to be compatible with the PC Watchdog
25 driver, simply do the following: 25 driver, simply use of modify the watchdog test program:
26 26 Documentation/watchdog/src/watchdog-test.c
27-- Snippet of code -- 27
28/*
29 * Watchdog Driver Test Program
30 */
31
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <unistd.h>
36#include <fcntl.h>
37#include <sys/ioctl.h>
38#include <linux/types.h>
39#include <linux/watchdog.h>
40
41int fd;
42
43/*
44 * This function simply sends an IOCTL to the driver, which in turn ticks
45 * the PC Watchdog card to reset its internal timer so it doesn't trigger
46 * a computer reset.
47 */
48void keep_alive(void)
49{
50 int dummy;
51
52 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
53}
54
55/*
56 * The main program. Run the program with "-d" to disable the card,
57 * or "-e" to enable the card.
58 */
59int main(int argc, char *argv[])
60{
61 fd = open("/dev/watchdog", O_WRONLY);
62
63 if (fd == -1) {
64 fprintf(stderr, "Watchdog device not enabled.\n");
65 fflush(stderr);
66 exit(-1);
67 }
68
69 if (argc > 1) {
70 if (!strncasecmp(argv[1], "-d", 2)) {
71 ioctl(fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD);
72 fprintf(stderr, "Watchdog card disabled.\n");
73 fflush(stderr);
74 exit(0);
75 } else if (!strncasecmp(argv[1], "-e", 2)) {
76 ioctl(fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD);
77 fprintf(stderr, "Watchdog card enabled.\n");
78 fflush(stderr);
79 exit(0);
80 } else {
81 fprintf(stderr, "-d to disable, -e to enable.\n");
82 fprintf(stderr, "run by itself to tick the card.\n");
83 fflush(stderr);
84 exit(0);
85 }
86 } else {
87 fprintf(stderr, "Watchdog Ticking Away!\n");
88 fflush(stderr);
89 }
90
91 while(1) {
92 keep_alive();
93 sleep(1);
94 }
95}
96-- End snippet --
97 28
98 Other IOCTL functions include: 29 Other IOCTL functions include:
99 30
diff --git a/Documentation/watchdog/src/watchdog-simple.c b/Documentation/watchdog/src/watchdog-simple.c
new file mode 100644
index 000000000000..85cf17c48669
--- /dev/null
+++ b/Documentation/watchdog/src/watchdog-simple.c
@@ -0,0 +1,15 @@
1#include <stdlib.h>
2#include <fcntl.h>
3
4int main(int argc, const char *argv[]) {
5 int fd = open("/dev/watchdog", O_WRONLY);
6 if (fd == -1) {
7 perror("watchdog");
8 exit(1);
9 }
10 while (1) {
11 write(fd, "\0", 1);
12 fsync(fd);
13 sleep(10);
14 }
15}
diff --git a/Documentation/watchdog/src/watchdog-test.c b/Documentation/watchdog/src/watchdog-test.c
new file mode 100644
index 000000000000..65f6c19cb865
--- /dev/null
+++ b/Documentation/watchdog/src/watchdog-test.c
@@ -0,0 +1,68 @@
1/*
2 * Watchdog Driver Test Program
3 */
4
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8#include <unistd.h>
9#include <fcntl.h>
10#include <sys/ioctl.h>
11#include <linux/types.h>
12#include <linux/watchdog.h>
13
14int fd;
15
16/*
17 * This function simply sends an IOCTL to the driver, which in turn ticks
18 * the PC Watchdog card to reset its internal timer so it doesn't trigger
19 * a computer reset.
20 */
21void keep_alive(void)
22{
23 int dummy;
24
25 ioctl(fd, WDIOC_KEEPALIVE, &dummy);
26}
27
28/*
29 * The main program. Run the program with "-d" to disable the card,
30 * or "-e" to enable the card.
31 */
32int main(int argc, char *argv[])
33{
34 fd = open("/dev/watchdog", O_WRONLY);
35
36 if (fd == -1) {
37 fprintf(stderr, "Watchdog device not enabled.\n");
38 fflush(stderr);
39 exit(-1);
40 }
41
42 if (argc > 1) {
43 if (!strncasecmp(argv[1], "-d", 2)) {
44 ioctl(fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD);
45 fprintf(stderr, "Watchdog card disabled.\n");
46 fflush(stderr);
47 exit(0);
48 } else if (!strncasecmp(argv[1], "-e", 2)) {
49 ioctl(fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD);
50 fprintf(stderr, "Watchdog card enabled.\n");
51 fflush(stderr);
52 exit(0);
53 } else {
54 fprintf(stderr, "-d to disable, -e to enable.\n");
55 fprintf(stderr, "run by itself to tick the card.\n");
56 fflush(stderr);
57 exit(0);
58 }
59 } else {
60 fprintf(stderr, "Watchdog Ticking Away!\n");
61 fflush(stderr);
62 }
63
64 while(1) {
65 keep_alive();
66 sleep(1);
67 }
68}
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
34the watchdog is pinged within a certain time, this time is called the 34the watchdog is pinged within a certain time, this time is called the
35timeout or margin. The simplest way to ping the watchdog is to write 35timeout or margin. The simplest way to ping the watchdog is to write
36some data to the device. So a very simple watchdog daemon would look 36some data to the device. So a very simple watchdog daemon would look
37like this: 37like this source file: see Documentation/watchdog/src/watchdog-simple.c
38
39#include <stdlib.h>
40#include <fcntl.h>
41
42int 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
54A more advanced driver could for example check that a HTTP server is 39A more advanced driver could for example check that a HTTP server is
55still responding before doing the write call to ping the watchdog. 40still 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
113Envinronmental monitoring: 98Pretimeouts:
99
100Some watchdog timers can be set to have a trigger go off before the
101actual time they will reset the system. This can be done with an NMI,
102interrupt, or other mechanism. This allows Linux to record useful
103information (like panic information and kernel coredumps) before it
104resets.
105
106 pretimeout = 10;
107 ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout);
108
109Note that the pretimeout is the number of seconds before the time
110when the timeout will go off. It is not the number of seconds until
111the pretimeout. So, for instance, if you set the timeout to 60 seconds
112and the pretimeout to 10 seconds, the pretimout will go of in 50
113seconds. Setting a pretimeout to zero disables it.
114
115There 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
120Not all watchdog drivers will support a pretimeout.
121
122Get the number of seconds before reboot:
123
124Some watchdog drivers have the ability to report the remaining time
125before the system will reboot. The WDIOC_GETTIMELEFT is the ioctl
126that 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
131Environmental monitoring:
114 132
115All watchdog drivers are required return more information about the system, 133All watchdog drivers are required return more information about the system,
116some do temperature, fan and power level monitoring, some can tell you 134some 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
190The watchdog can do pretimeouts.
191
192 WDIOF_PRETIMEOUT Pretimeout (in seconds), get/set
193
172 194
173For those drivers that return any bits set in the option field, the 195For those drivers that return any bits set in the option field, the
174GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current 196GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current
diff --git a/Documentation/watchdog/watchdog.txt b/Documentation/watchdog/watchdog.txt
index dffda29c8799..4b1ff69cc19a 100644
--- a/Documentation/watchdog/watchdog.txt
+++ b/Documentation/watchdog/watchdog.txt
@@ -65,28 +65,7 @@ The external event interfaces on the WDT boards are not currently supported.
65Minor numbers are however allocated for it. 65Minor numbers are however allocated for it.
66 66
67 67
68Example Watchdog Driver 68Example Watchdog Driver: see Documentation/watchdog/src/watchdog-simple.c
69-----------------------
70
71#include <stdio.h>
72#include <unistd.h>
73#include <fcntl.h>
74
75int main(int argc, const char *argv[])
76{
77 int fd=open("/dev/watchdog",O_WRONLY);
78 if(fd==-1)
79 {
80 perror("watchdog");
81 exit(1);
82 }
83 while(1)
84 {
85 write(fd,"\0",1);
86 fsync(fd);
87 sleep(10);
88 }
89}
90 69
91 70
92Contact Information 71Contact Information