SOFT_WDT (hereinafter referred to as the software) is a software implementation of the Linux watchdog.
This software is open source, free software.
:
Https://github.com/sunmingbao/soft-wdt/archive/master.zip
the SoftwareAlmost the same as the/DRIVERS/WATCHDOG/SOFTDOG.C implementation of the software watchdog.
The basic difference is that the former supports a watchdog. The software supports a large number of watchdog dogs.
After the SOFT_WDT code is compiled. Generates a kernel module SOFT_WDT.KO.
After the module is loaded, a device file is created/DEV/SOFT_WDT
User-state program, via system call open every time/DEV/SOFT_WDT is opened, a new watchdog is obtained,
This watchdog is used just like a regular watchdog.
Like what:
1) Writing to FD no matter what data, it is tantamount to feeding the dog.
2) The user is able to perform various operations on the watchdog via the IOCTL.
3) Assuming that the analog is loaded, the module parameter Nowayout value is 0,
Then when the user writes to the FD contains the character V (note. is capitalized) when the data is
The watchdog is set to shut down.
Here's how to use this software
(a) module compilation
Method one, compile separately
Under the SOFT_WDT Source code folder. Run such as the following command to
Make-c/path/to/kernel/source/dir m= ' pwd ' modules
Method Two, compile in the Linux kernel compilation system
1. Copy the soft_wdt.c to the drivers/watchdog/folder.
2. Place the following line of code. Append to Drivers/watchdog/makefile of kernel source code (in Architecture independant section)
obj-$ (CONFIG_SOFT_WDT) + = SOFT_WDT.O
3. Append the following to the drivers/watchdog/kconfig of the kernel source code (in the Architecture independant section)
Config SOFT_WDT
TriState "software watchdog timer (multiple dogs)"
Default m
Help
A software watchdog driver, supporting multiple dogs.
Each time, user opens the device file (/DEV/SOFT_WDT),
A new dog was created, associated with the FD returned
By the open system call. The usage of each dog is just
The same as ordinary watchdog, including MAGIC CLOSE.
Currently the driver supports a maximum of dogs.
To compile this driver as a module, choose M here:the
Module would be called SOFT_WDT.
4. Run make Menuconfig to enter the watchdog driver's selection interface, then exit directly and save the configuration.
5. Run make modules. Then under the drivers/watchdog/folder. The module file is generated Soft_wdt.ko
(ii) Module loading
The module parameters provided by the software are as follows.
The user can specify according to the need.
Nowayout-Once the watchdog is activated, it cannot be stopped (0. No;1,yes. default=0)
Timeout-watchdog timeout time. Units: seconds. (0 ~ 65536, default=5)
No_reboot-watchdog timeout. Do not restart the system. (0,no; 1,yes default=0)
Core_dump_ill_task-watchdog timeout, core dump exception task, (0,no; 1,yes default=1)
Note that the core dump is implemented by sending the SIGABRT signal to the exception thread.
So. Assume that you are using a watchdog program. Want to log the exception information yourself. Can be achieved by capturing SIGABRT signals.
The following is a demonstration sample of the load command.
1. Load with default parameters (default values as listed above)
Insmod Soft_wdt.ko
2. Specify the number of parameters to load (12 seconds timeout, the watchdog can be closed.) Timeout does not restart the machine)
Insmod Soft_wdt.ko timeout=12 nowayout=0 no_reboot=1
(iii) User-state program using watchdog
The following is a demo sample code
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys /types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/ watchdog.h> #define SOFT_WDT_DEV "/DEV/SOFT_WDT" int feed_dog_cnt;int feed_dog_gap;int main (int argc, char *argv[]) {int i; int timeout; struct Watchdog_info ident; int FD; if (argc<3) {printf ("usage:\n%s <feed_gap (in seconds) > <feed_cnt>\n", Argv[0]); return 0; } fd=open ("/dev/soft_wdt", o_wronly); if (FD < 0) {printf ("Open%s failed\n", Soft_wdt_dev); Exit (1); } printf ("Open%s succeed\n", Soft_wdt_dev); Timeout = 7; printf ("Set timeout to%d\n", timeout); IOCTL (FD, Wdioc_settimeout, &timeout); Timeout = 0; IOCTL (FD, Wdioc_gettimeout, &timeout); printf ("Get timeout returns%d\n", timeout); IOCTL (FD, Wdioc_getsupport, &ident); printf ("Dog name is%s\n", ident.identity); printf ("Make the Dog closable\n"); Write (FD, "V", 1); Feed_dog_gap = Atoi (argv[1]); feed_dog_cnt = Atoi (argv[2]); for (i=0; i<feed_dog_cnt; i++) {printf ("Feed dog\n"); Write (FD, "1234", 4); Usleep (feed_dog_gap*1000000); } printf ("Stop Feeding dog\n"); while (1) {usleep (1000000); } return 0;}
A software-implemented Linux watchdog-SOFT_WDT