Watchdog driver API

Source: Internet
Author: User

A watch timer (wdt) is a hardware circuit that can be used to reset a computer system when system software errors occur.

Generally, the daemon of a user space uses a specific device/dev/watchdog to notify the watchdog Driver System of the kernel to remain alive at a certain interval. The driver then notifies the hardware device that everything is normal, and the hardware wdt circuit updates the Reset System restart timeout time. If the user space fails (RAM error, kernel bug, etc.), this notification will not occur, and the hardware wdt starts to restart the system after the timeout arrives.

All drivers must support the most basic operation mode: After/dev/watchdog is enabled, wdt is activated immediately. Wdt will reset the system unless the watchdog driver is pinged at a certain time. This interval is called timout or margin. The simplest way to ping watchdog is to write data to the wdt device. A very simple application layer watchdog daemon implementation see documentation/watchdog/src/watchdog-simple.c

When the watchdog device node is disabled, if the "magic close" function is not supported, the watchdog function is disable. Disabling the watchdog function is not a good implementation method, because if watchdog daemon is accidentally disabled (Daemon's own bug, the system kills daemon and so on), the watchdog circuit cannot restart the system. For this reason, many watchdog drivers support the Kernel configuration option "Disable watchdog shutdown on clost", config_watchdog_nowayout. After this kernel option is configured, once the system enables watchdog,
This function will no longer be disable. However, another problem is that if the watchdog process does not exist, the system will restart, whether or not the system must be restarted.

Magic close feature:

If the driver supports "Magic close", the driver will not disalbe watchdog daemon after the device file is closed, unless a specific magic character 'V' is written to the watchdog device before the driver is closed. If the userspace daemon does not send 'V' and the file is directly closed, the watchdog driver will think that the watchdog daemon is dead, if the dog is not fed for a given period of time, the wdt circuit will restart the system.

Ioctl api:

All compatible drivers should support this API.

Use IOCTL to ping watchdog:

All drivers must support one IOCTL operation wdioc_keepalive, and wdioc_keepalive and write operations have the same effect. Therefore, the main cycle of watchdog daemon can be implemented as follows:

While (1 ){

Inctl (FD, wdioc_keepalive, 0 );

Sleep (10 );

}

Setting and getting the timeout:

For some drivers, you can use wdioc_settimeout to modify timeout when watchdog is running. The option field of these drivers sets the wdiof_settimeout flag. The IOCTL operation parameter is an integer that represents the timeout seconds. The driver uses this parameter to return the current set timeout. Due to the limitation of the hardware circuit, the timeout may be different from the request set timeout.

In Linux kernel2.4.18, gettimeout IOCTL is added to query the current timeout value.

Pretimeouts:

Some watchdogs support setting a trigger mechanism at a certain time point before restarting the computer. It can be implemented through NMI, interrupt, or other mechanisms. This allows the system to record useful information (such as panic information and kernel coredumps) before reset ).

Pretimeout = 10;

IOCTL (FD, wdioc_setpretimeout, & pretimeout );

Note that pretimeout is the length from the trigger time to the system restart time. For example, if you set timeout to 60 and pretimeout to 10, the Agency will be triggered in 50 seconds (10 seconds before the restart.

The wdioc_getpretimeout operation is used to obtain the preset pretimeout:

IOCTL (FD, wdioc_getpretimeout, & timeout );

Not all watchdog drivers support pretimeout


Returns the number of seconds that watchdog is restarted.

Some drivers support obtaining the number of seconds required for system watchdog restart. wdioc_gettimeleft IOCTL is used to implement this function.

IOCTL (FD, wdioc_gettimeleft, & timeleft );
Printf ("the timeout was is % d seconds \ n", timeleft );

Environment Monitoring

All drivers must be able to return some information of the watchdog system. getsupport IOCTL is used to query information supported by devices.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.