Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147441599
D13713.id37309.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D13713.id37309.diff
View Options
Index: share/man/man4/watchdog.4
===================================================================
--- share/man/man4/watchdog.4
+++ share/man/man4/watchdog.4
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd December 21, 2009
+.Dd December 30, 2017
.Dt WATCHDOG 4
.Os
.Sh NAME
@@ -40,8 +40,11 @@
.Pp
The device
.Pa /dev/fido
-responds to a single
+supports several optional
.Xr ioctl 2
+calls for configuration, and
+responds to a single operational
+.Xr ioctl
call,
.Dv WDIOCPATPAT .
It takes a single argument which represents a timeout value specified as a
@@ -60,12 +63,16 @@
will be kept from timing out from the kernel.
.Pp
The
+.Dv WDIOCPATPAT
.Xr ioctl 2
call will return success if just one of the available
.Xr watchdog 9
implementations supports setting the timeout to the specified timeout.
This
means that at least one watchdog is armed.
+By default, this will be a hardware watchdog if one is present, but if
+no hardware watchdog is able to process the request, a default software
+watchdog is enabled.
If the call fails, for instance if
none of
.Xr watchdog 9
@@ -78,7 +85,10 @@
The watchdog might
still be armed!
.Sh RETURN VALUES
-The ioctl returns zero on success and non-zero on failure.
+The
+.Dv WDIOCPATPAT
+.Xr ioctl
+returns zero on success and non-zero on failure.
.Bl -tag -width Er
.It Bq Er EOPNOTSUPP
No watchdog present in the kernel or
@@ -122,8 +132,8 @@
.Pp
.Dl "options SW_WATCHDOG"
.Pp
-in your kernel config adds a software watchdog in the kernel, dropping to KDB
-or panic-ing when firing.
+in your kernel config forces a software watchdog in the kernel
+to be configured, dropping to KDB or panicking when firing.
.Sh SEE ALSO
.Xr watchdogd 8 ,
.Xr watchdog 9
Index: sys/conf/NOTES
===================================================================
--- sys/conf/NOTES
+++ sys/conf/NOTES
@@ -2592,7 +2592,9 @@
options BOOTP_BLOCKSIZE=8192 # Override NFS block size
#
-# Add software watchdog routines.
+# Enable software watchdog routines, even if hardware watchdog is present.
+# By default, software watchdog timer is enabled only if no hardware watchdog
+# is present.
#
options SW_WATCHDOG
Index: sys/dev/watchdog/watchdog.c
===================================================================
--- sys/dev/watchdog/watchdog.c
+++ sys/dev/watchdog/watchdog.c
@@ -78,6 +78,9 @@
static int wd_lastpat_valid = 0;
static time_t wd_lastpat = 0; /* when the watchdog was last patted */
+/* Hook for external software watchdog to register for use if needed */
+void (*wdog_software_attach)(void);
+
static void
pow2ns_to_ts(int pow2ns, struct timespec *ts)
{
@@ -120,6 +123,7 @@
wdog_kern_pat(u_int utim)
{
int error;
+ static int first = 1;
if ((utim & WD_LASTVAL) != 0 && (utim & WD_INTERVAL) > 0)
return (EINVAL);
@@ -161,6 +165,17 @@
} else {
EVENTHANDLER_INVOKE(watchdog_list, utim, &error);
}
+ /*
+ * If we no hardware watchdog responded, we have not tried to
+ * attach an external software watchdog, and one is available,
+ * attach it now and retry.
+ */
+ if (error == EOPNOTSUPP && first && *wdog_software_attach != NULL) {
+ (*wdog_software_attach)();
+ EVENTHANDLER_INVOKE(watchdog_list, utim, &error);
+ }
+ first = 0;
+
wd_set_pretimeout(wd_pretimeout, true);
/*
* If we were able to arm/strobe the watchdog, then
Index: sys/kern/kern_clock.c
===================================================================
--- sys/kern/kern_clock.c
+++ sys/kern/kern_clock.c
@@ -335,14 +335,18 @@
}
}
-#ifdef SW_WATCHDOG
#include <sys/watchdog.h>
static int watchdog_ticks;
static int watchdog_enabled;
static void watchdog_fire(void);
static void watchdog_config(void *, u_int, int *);
-#endif /* SW_WATCHDOG */
+
+static void
+watchdog_attach(void)
+{
+ EVENTHANDLER_REGISTER(watchdog_list, watchdog_config, NULL, 0);
+}
/*
* Clock handling routines.
@@ -410,8 +414,14 @@
if (profhz == 0)
profhz = i;
psratio = profhz / i;
+
#ifdef SW_WATCHDOG
- EVENTHANDLER_REGISTER(watchdog_list, watchdog_config, NULL, 0);
+ /* Enable hardclock watchdog now, even if a hardware watchdog exists. */
+ watchdog_attach();
+#else
+ /* Volunteer to run a software watchdog. */
+ if (wdog_software_attach == NULL)
+ wdog_software_attach = watchdog_attach;
#endif
}
@@ -482,10 +492,8 @@
#ifdef DEVICE_POLLING
hardclock_device_poll(); /* this is very short and quick */
#endif /* DEVICE_POLLING */
-#ifdef SW_WATCHDOG
if (watchdog_enabled > 0 && --watchdog_ticks <= 0)
watchdog_fire();
-#endif /* SW_WATCHDOG */
}
void
@@ -496,9 +504,7 @@
struct proc *p = td->td_proc;
int *t = DPCPU_PTR(pcputicks);
int flags, global, newticks;
-#ifdef SW_WATCHDOG
int i;
-#endif /* SW_WATCHDOG */
/*
* Update per-CPU and possibly global ticks values.
@@ -558,13 +564,11 @@
atomic_store_rel_int(&devpoll_run, 0);
}
#endif /* DEVICE_POLLING */
-#ifdef SW_WATCHDOG
if (watchdog_enabled > 0) {
i = atomic_fetchadd_int(&watchdog_ticks, -newticks);
if (i > 0 && i <= newticks)
watchdog_fire();
}
-#endif /* SW_WATCHDOG */
}
if (curcpu == CPU_FIRST())
cpu_tick_calibration();
@@ -841,8 +845,6 @@
0, 0, sysctl_kern_clockrate, "S,clockinfo",
"Rate and period of various kernel clocks");
-#ifdef SW_WATCHDOG
-
static void
watchdog_config(void *unused __unused, u_int cmd, int *error)
{
@@ -891,5 +893,3 @@
panic("watchdog timeout");
#endif
}
-
-#endif /* SW_WATCHDOG */
Index: sys/kern/kern_dump.c
===================================================================
--- sys/kern/kern_dump.c
+++ sys/kern/kern_dump.c
@@ -27,8 +27,6 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include "opt_watchdog.h"
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -36,9 +34,7 @@
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/kerneldump.h>
-#ifdef SW_WATCHDOG
#include <sys/watchdog.h>
-#endif
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
@@ -205,9 +201,7 @@
}
dumpsys_map_chunk(pa, chunk, &va);
-#ifdef SW_WATCHDOG
wdog_kern_pat(WD_LASTVAL);
-#endif
error = dump_append(di, va, 0, sz);
dumpsys_unmap_chunk(pa, chunk, va);
Index: sys/sys/watchdog.h
===================================================================
--- sys/sys/watchdog.h
+++ sys/sys/watchdog.h
@@ -112,6 +112,14 @@
u_int wdog_kern_last_timeout(void);
int wdog_kern_pat(u_int utim);
+
+/*
+ * The following function pointer is used to attach a software watchdog
+ * if no hardware watchdog has been attached, and if the software module
+ * has initialized the function pointer.
+ */
+
+extern void (*wdog_software_attach)(void);
#endif
#endif /* _SYS_WATCHDOG_H */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 12, 1:14 AM (28 m, 57 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29559004
Default Alt Text
D13713.id37309.diff (6 KB)
Attached To
Mode
D13713: make SW_WATCHDOG dynamic
Attached
Detach File
Event Timeline
Log In to Comment