Skip to contentSkip to conversation

watchdog: add pretimeout ioctl

PATCH In review [email protected] 3 participants 6 messages Jun 27, 2006 – Jun 28, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: add pretimeout ioctl

Some watchdog timers support the concept of a "pretimeout" which occurs some time before the real timeout. The pretimeout can be delivered via an interrupt or NMI and can be used to panic the system when it occurs (so you get useful information instead of a blind reboot).

The IPMI watchdog has had this built in, but this creates a standard mechanism for all watchdogs and switches the IPMI driver over to it.

Documentation/watchdog/watchdog-api.txt +29 -1
Index: linux-2.6.16/Documentation/watchdog/watchdog-api.txt
===================================================================
@@ -107,7 +107,31 @@ current timeout using the GETTIMEOUT ioc
     ioctl(fd, WDIOC_GETTIMEOUT, &timeout);
     printf("The timeout was is %d seconds\n", timeout);
 
-Envinronmental monitoring:
+Pretimeouts:
+
+Some watchdog timers can be set to have a trigger go off before the
+actual time they will reset the system.  This can be done with an NMI,
+interrupt, or other mechanism.  This allows Linux to record useful
+information (like panic information and kernel coredumps) before it
+resets.
+
+    pretimeout = 10;
+    ioctl(fd, WDIOC_SETPRETIMEOUT, &pretimeout);
+
+Note that the pretimeout is the number of seconds before the time
+when the timeout will go off.  It is not the number of seconds until
+the pretimeout.  So, for instance, if you set the timeout to 60 seconds
+and the pretimeout to 10 seconds, the pretimout will go of in 50
+seconds.  Setting a pretimeout to zero disables it.
+
+There is also a get function for getting the pretimeout:
+
+    ioctl(fd, WDIOC_GETPRETIMEOUT, &timeout);
+    printf("The pretimeout was is %d seconds\n", timeout);
+
+Not all watchdog drivers will support a pretimeout.
+
+Environmental monitoring:
 
 All watchdog drivers are required return more information about the system,
 some do temperature, fan and power level monitoring, some can tell you
@@ -166,6 +190,10 @@ The watchdog saw a keepalive ping since 
 
 	WDIOF_SETTIMEOUT	Can set/get the timeout
 
+The watchdog can do pretimeouts.
+
+	WDIOF_PRETIMEOUT	Pretimeout (in seconds), get/set
+
 
 For those drivers that return any bits set in the option field, the
 GETSTATUS and GETBOOTSTATUS ioctls can be used to ask for the current
drivers/char/ipmi/ipmi_watchdog.c +9 -13
Index: linux-2.6.16/drivers/char/ipmi/ipmi_watchdog.c
===================================================================
@@ -122,16 +122,9 @@
 #define IPMI_WDOG_SET_TIMER		0x24
 #define IPMI_WDOG_GET_TIMER		0x25
 
-/* These are here until the real ones get into the watchdog.h interface. */
-#ifndef WDIOC_GETTIMEOUT
-#define	WDIOC_GETTIMEOUT        _IOW(WATCHDOG_IOCTL_BASE, 20, int)
-#endif
-#ifndef WDIOC_SET_PRETIMEOUT
-#define	WDIOC_SET_PRETIMEOUT     _IOW(WATCHDOG_IOCTL_BASE, 21, int)
-#endif
-#ifndef WDIOC_GET_PRETIMEOUT
-#define	WDIOC_GET_PRETIMEOUT     _IOW(WATCHDOG_IOCTL_BASE, 22, int)
-#endif
+/* These are here for backwards compatability for a while. */
+#define	WDIOC_OLD_IPMI_SET_PRETIMEOUT     _IOW(WATCHDOG_IOCTL_BASE, 21, int)
+#define	WDIOC_OLD_IPMI_GET_PRETIMEOUT     _IOW(WATCHDOG_IOCTL_BASE, 22, int)
 
 static int nowayout = WATCHDOG_NOWAYOUT;
 
@@ -598,7 +591,8 @@ static void panic_halt_ipmi_heartbeat(vo
 
 static struct watchdog_info ident =
 {
-	.options	= 0,	/* WDIOF_SETTIMEOUT, */
+	.options	= (WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE
+			   | WDIOF_PRETIMEOUT),
 	.firmware_version = 1,
 	.identity	= "IPMI"
 };
@@ -628,14 +622,16 @@ static int ipmi_ioctl(struct inode *inod
 			return -EFAULT;
 		return 0;
 
-	case WDIOC_SET_PRETIMEOUT:
+	case WDIOC_OLD_IPMI_SET_PRETIMEOUT:
+	case WDIOC_SETPRETIMEOUT:
 		i = copy_from_user(&val, argp, sizeof(int));
 		if (i)
 			return -EFAULT;
 		pretimeout = val;
 		return ipmi_set_timeout(IPMI_SET_TIMEOUT_HB_IF_NECESSARY);
 
-	case WDIOC_GET_PRETIMEOUT:
+	case WDIOC_OLD_IPMI_GET_PRETIMEOUT:
+	case WDIOC_GETPRETIMEOUT:
 		i = copy_to_user(argp, &pretimeout, sizeof(pretimeout));
 		if (i)
 			return -EFAULT;
include/linux/watchdog.h +3 -0
Index: linux-2.6.16/include/linux/watchdog.h
===================================================================
@@ -28,6 +28,8 @@ struct watchdog_info {
 #define	WDIOC_KEEPALIVE		_IOR(WATCHDOG_IOCTL_BASE, 5, int)
 #define	WDIOC_SETTIMEOUT        _IOWR(WATCHDOG_IOCTL_BASE, 6, int)
 #define	WDIOC_GETTIMEOUT        _IOR(WATCHDOG_IOCTL_BASE, 7, int)
+#define	WDIOC_SETPRETIMEOUT     _IOWR(WATCHDOG_IOCTL_BASE, 8, int)
+#define	WDIOC_GETPRETIMEOUT     _IOR(WATCHDOG_IOCTL_BASE, 9, int)
 
 #define	WDIOF_UNKNOWN		-1	/* Unknown flag error */
 #define	WDIOS_UNKNOWN		-1	/* Unknown status error */
@@ -41,6 +43,7 @@ struct watchdog_info {
 #define WDIOF_POWEROVER		0x0040	/* Power over voltage */
 #define WDIOF_SETTIMEOUT	0x0080  /* Set timeout (in seconds) */
 #define WDIOF_MAGICCLOSE	0x0100	/* Supports magic close char */
+#define WDIOF_PRETIMEOUT	0x0200  /* Pretimeout (in seconds), get/set */
 #define	WDIOF_KEEPALIVEPING	0x8000	/* Keep alive ping reply */
 
 #define	WDIOS_DISABLECARD	0x0001	/* Turn off the watchdog timer */
#1 lore raw

Ar Maw, 2006-06-27 am 13:22 -0500, ysgrifennodd [email protected]:

Quoted 5 lines

Some watchdog timers support the concept of a "pretimeout" which occurs some time before the real timeout. The pretimeout can be delivered via an interrupt or NMI and can be used to panic the system when it occurs (so you get useful information instead of a blind reboot).

All watchdogs can do pre-timeouts in software so possibly this should use a software fallback as well if you want good coverage ?

#2 lore raw
Quoted 9 lines · Alan Cox

Ar Maw, 2006-06-27 am 13:22 -0500, ysgrifennodd [email protected]:

Quoted 6 lines

Some watchdog timers support the concept of a "pretimeout" which occurs some time before the real timeout. The pretimeout can be delivered via an interrupt or NMI and can be used to panic the system when it occurs (so you get useful information instead of a blind reboot).

Quoted 3 lines

All watchdogs can do pre-timeouts in software so possibly this should use a software fallback as well if you want good coverage ?

I hadn't thought of that, but a software emulator could be used with this interface, but it doesn't really help with hard lockups. This is primarily intended to set up watchdogs that can delver an NMI, since even if the machine is hard-locked the NMI will come through. Of course, there's all kinds of problems with getting the NMI to a useful handler, but that's another story.

-Corey

#3 lore raw

Ar Maw, 2006-06-27 am 20:05 -0500, ysgrifennodd Corey Minyard:

Quoted 1 line

since even if the machine is hard-locked the NMI will come through.

Don't bet on that. There are a considerable number of crash stall cases where NMI will not be delivered, plus you can disable NMI if you are really sneaky and want to.

The usual case NMI fails is crashed video cards. The PCI transaction stalls forever on many boards and the CPU therefore never finishes the instruction and never services the NMI

Alan

#4 lore raw
In reply to [email protected]
Quoted 9 lines · [email protected] wrote:

Some watchdog timers support the concept of a "pretimeout" which occurs some time before the real timeout. The pretimeout can be delivered via an interrupt or NMI and can be used to panic the system when it occurs (so you get useful information instead of a blind reboot).

The IPMI watchdog has had this built in, but this creates a standard mechanism for all watchdogs and switches the IPMI driver over to it.

This patch seems to be kinda-sorta already half-present in Wim's development tree. Could you take a look at what's in 2.6.17-mm3, see if any additional work is needed and if so, send a patch against that?

Then we can feed it all in when (or after) Wim does his 2.6.18 merge, which is hopefully soon..

#5 lore raw

Oops, my bad, yes, it's already there. Sorry about that.

-Corey

Quoted 19 lines · Andrew Morton
Quoted 9 lines · [email protected] wrote:

Some watchdog timers support the concept of a "pretimeout" which occurs some time before the real timeout. The pretimeout can be delivered via an interrupt or NMI and can be used to panic the system when it occurs (so you get useful information instead of a blind reboot).

The IPMI watchdog has had this built in, but this creates a standard mechanism for all watchdogs and switches the IPMI driver over to it.

This patch seems to be kinda-sorta already half-present in Wim's development tree. Could you take a look at what's in 2.6.17-mm3, see if any additional work is needed and if so, send a patch against that?

Then we can feed it all in when (or after) Wim does his 2.6.18 merge, which is hopefully soon..