Watchdog
1. Overview
A watchdog is an important hardware or software mechanism that is typically used to monitor the operating status of a system or device. When the system fails to respond or encounters an error, the watchdog performs an automatic reset or triggers specific recovery actions. Its main role is to enhance the system's reliability and stability, preventing the system from entering an unrecoverable state.
Main Functions of a Watchdog:
- Detecting System Failures: The watchdog timer continuously counts down, and under normal operation, the system is required to periodically "feed" the watchdog (i.e., reset the timer). If the system fails to feed the watchdog within the specified time, the watchdog considers the system to have failed (e.g., due to a freeze or unresponsiveness).
- Automatic System Reset: When the watchdog detects that the system has failed to feed the watchdog in time, it triggers an automatic system reset, typically restarting the device. This ensures that the system can recover from an error state and avoids prolonged stagnation.
- Enhancing System Fault Tolerance: In real-time or embedded systems, the watchdog acts as a last line of defense, automatically recovering the system when unpredictable issues occur in the system software, thus preventing the need for manual intervention.
- Preventing Software Lockups: The watchdog can monitor the software's operational status, especially for long-running software, to prevent issues such as dead loops or system hangs. It requires the software to complete certain critical tasks within a specified time; otherwise, the watchdog will trigger a reset.
2. Usage
The internal watchdog device is named
/dev/watchdog. Users can control this device via theechocommand.# Write any content (except uppercase 'V') to enable the watchdog. It needs to be fed (reset) every 44 seconds.
echo A > /dev/watchdog
# Enable the watchdog, and the kernel will automatically feed the watchdog every 22 seconds.
echo V > /dev/watchdog
3. Device Tree Overview
The Watchdog DTS source file is already defined in
kernel-6.10/arch/arm64/boot/dts/rockchip/rk3576.dtsi, and we can directly use it.wdt: watchdog@2ace0000 {
compatible = "snps,dw-wdt";
reg = <0x0 0x2ace0000 0x0 0x100>;
clocks = <&cru TCLK_WDT0>, <&cru PCLK_WDT0>;
clock-names = "tclk", "pclk";
interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
status = "disabled";
};The device file path is located in
kernel-6.1/arch/arm64/boot/dts/rockchip/luckfox-omni3576.dts. The code snippet to enable thewatchdogis as follows:&wdt{
status = "okay";
};