xref: /freebsd/share/man/man4/watchdog.4 (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1.\" Copyright (c) 2004 Poul-Henning Kamp <phk@FreeBSD.org>
2.\" Copyright (c) 2003, 2004 Sean M. Kelly <smkelly@FreeBSD.org>
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd January 2, 2018
27.Dt WATCHDOG 4
28.Os
29.Sh NAME
30.Nm watchdog
31.Nd "hardware and software watchdog"
32.Sh SYNOPSIS
33.In sys/watchdog.h
34.Sh DESCRIPTION
35The
36.Nm
37facility is used for controlling hardware and software watchdogs.
38.Pp
39The device
40.Pa /dev/fido
41supports several optional
42.Xr ioctl 2
43calls for configuration, and
44responds to a set of operational
45.Xr ioctl 2
46calls:
47.Bl -tag -width "WDIOC_CONTROL int  "
48.It Dv WDIOCPATPAT
49Pat the watchdog.
50.It Dv WDIOC_CONTROL
51Enable, disable, or reset the watchdog.
52.El
53.Pp
54The
55.Dv WDIOCPATPAT
56.Xr ioctl 2
57call takes a single argument which represents a timeout value specified as a
58.Vt sbintime_t
59of the timeout period for the watchdog.
60.Pp
61The
62.Dv WDIOCPATPAT
63.Xr ioctl 2
64call will return success if just one of the available
65.Xr watchdog 9
66implementations supports setting the timeout to the specified timeout.
67This
68means that at least one watchdog is armed.
69By default, this will be a hardware watchdog if one is present, but if
70no hardware watchdog is able to process the request, a default software
71watchdog is enabled.
72If the call fails, for instance if
73none of
74.Xr watchdog 9
75implementations support the timeout length, all watchdogs are disabled and must
76be explicitly re-enabled.
77.Pp
78To disable the watchdogs use the
79.Dv WDIOC_CONTROL
80.Xr ioctl 2
81call with the
82.Dv WD_CTRL_DISABLE
83flag.
84If disarming the watchdog(s) failed an error is returned.
85The watchdog might
86still be armed!
87To reenable the watchdogs use the
88.Dv WDIOC_CONTROL
89.Xr ioctl 2
90call with the
91.Dv WD_CTRL_ENABLE
92flag.
93Another way to pat the watchdog is with the
94.Dv WDIOC_CONTROL
95.Xr ioctl 2
96call passing the
97.Dv WDIOC_CTRL_RESET
98flag.
99.Pp
100The optional configuration
101.Xr ioctl 2
102commands are listed here, along with the type of the parameter used.
103Examples of their use can be found in
104.Xr watchdogd 8 .
105.Bl -tag -width "WDIOC_GETPRETTIMEOUT sbintime_t"
106.It Dv WDIOC_SETTIMEOUT Fa sbintime_t
107set/reset the timer
108.It Dv WDIOC_GETTIMEOUT Fa sbintime_t
109get total timeout
110.It Dv WDIOC_GETTIMELEFT Fa sbintime_t
111get time left
112.It Dv WDIOC_GETPRETIMEOUT Fa sbintime_t
113get the pre-timeout
114.It Dv WDIOC_SETPRETIMEOUT Fa sbintime_t
115set the pre-timeout
116.It Dv WDIOC_SETPRETIMEOUTACT Fa int
117Set the action when a pre-timeout occurs (see
118.Li WD_SOFT_*
119below).
120.It Dv WDIOC_SETSOFT Fa int
121Use an internal software watchdog instead of hardware.
122There is also an external software watchdog, which is used by default
123if no hardware watchdog was attached.
124.It Dv WDIOC_SETSOFTTIMEOUTACT Fa int
125Set the action when a soft timeout occurs.
126.El
127.Pp
128The actions that may be specified for the pre-timeout or the internal software
129watchdog are listed here.
130Multiple actions can be specified by ORing values together.
131.Bl -tag -width  WD_SOFT_PRINT
132.It Dv WD_SOFT_PANIC
133panic
134.It Dv WD_SOFT_DDB
135enter debugger
136.It Dv WD_SOFT_LOG
137log(9)
138.It Dv WD_SOFT_PRINT
139printf(9)
140.El
141.Sh RETURN VALUES
142The
143.Dv WDIOCPATPAT
144.Xr ioctl 2
145returns zero on success and non-zero on failure.
146.Bl -tag -width Er
147.It Bq Er EOPNOTSUPP
148No watchdog present in the kernel or
149none of the watchdogs supports the requested timeout value
150(timeout value other than 0).
151.It Bq Er EOPNOTSUPP
152Watchdog could not be disabled (timeout value of 0).
153.It Bq Er EINVAL
154Invalid flag combination passed.
155.El
156.Pp
157The configuration
158.Xr ioctl 2
159operations return zero on success and non-zero on failure.
160.Sh EXAMPLES
161.Bd -literal -offset indent
162#include <paths.h>
163#include <sys/watchdog.h>
164
165#define WDPATH	"/dev/" _PATH_WATCHDOG
166int wdfd = -1;
167
168static void
169wd_init(void)
170{
171	wdfd = open(WDPATH, O_RDWR);
172	if (wdfd == -1)
173		err(1, WDPATH);
174}
175static void
176wd_reset(u_int timeout)
177{
178	if (ioctl(wdfd, WDIOCPATPAT, &timeout) == -1)
179		err(1, "WDIOCPATPAT");
180}
181
182/* in main() */
183wd_init();
184wd_reset(WD_ACTIVE|WD_TO_8SEC);
185/* potential freeze point */
186wd_reset(WD_TO_NEVER);
187.Ed
188.Pp
189Enables a watchdog to recover from a potentially freezing piece of code.
190.Pp
191.Dl "options SW_WATCHDOG"
192.Pp
193in your kernel config forces a software watchdog in the kernel
194to be configured even if a hardware watchdog is configured,
195dropping to KDB or panicking when firing, depending
196on the KDB and KDB_UNATTENDED kernel configuration options.
197.Sh SEE ALSO
198.Xr watchdogd 8 ,
199.Xr watchdog 9
200.Sh HISTORY
201The
202.Nm
203code first appeared in
204.Fx 5.1 .
205.Sh AUTHORS
206.An -nosplit
207The
208.Nm
209facility was written by
210.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
211The software watchdog code and this manual page were written by
212.An Sean Kelly Aq Mt smkelly@FreeBSD.org .
213Some contributions were made by
214.An Jeff Roberson Aq Mt jeff@FreeBSD.org .
215.Sh BUGS
216The
217.Dv WD_PASSIVE
218option has not yet been implemented.
219