4.5.18. Watchdog Test
4.5.18.1. Test Principle
The X5 integrates a hardware watchdog (watchdog@34250000, driver dw_wdt). After the WDT is started, its internal counter counts down continuously. A kick (keepalive) must be received before the timeout expires to reload the counter; otherwise an SoC system reset is triggered.
Typical behavior:
Kernel auto-feed (default): The kernel
watchdogdthread kicks the WDT periodically./sys/class/watchdog/watchdog0/stateisinactive, and no userspace program is required.Userspace takeover: After a process opens
/dev/watchdog0and writes to it, the kernel stops auto-feeding and that process must keep feeding the watchdog.Disable watchdog: When
nowayout=0, the watchdog can be stopped via Magic Close; a reboot is required to enable it again.
Kernel / Userspace DesignWare WDT No kick before timeout
┌─────────────┐ Periodic kick ┌──────────────┐ ┌────────────┐
│ Feed source │ ────────────────> │ Counter down │ ──────────────────────> │ SoC reset │
└─────────────┘ └──────────────┘ └────────────┘
4.5.18.2. Preparation
Script Usage
watchdog_test.sh supports the -h option to display help information:
# ./watchdog_test.sh --help
usage: ./watchdog_test.sh <command>
commands:
info show hardware watchdog information
timeout show configured watchdog timeout (seconds)
feeder show whether kernel or userspace is feeding
timeleft show remaining timeout (seconds)
feed feed watchdog N times: feed <count> [-i interval_sec]
disable stop watchdog (requires nowayout=0)
examples:
./watchdog_test.sh info
./watchdog_test.sh feeder
./watchdog_test.sh feed 1
./watchdog_test.sh feed 6 -i 2
Parameter description:
info: Show basic hardware watchdog informationtimeout: Show the configured timeout (seconds)feeder: Determine whether the kernel or userspace is feeding the watchdogtimeleft: Show the remaining timeout (seconds)feed: Feed the watchdog<count>times[-i interval_sec]; default interval is 1 seconddisable: Stop the watchdog; a reboot is required to enable it again-h / --help: Show help
4.5.18.3. Test Steps
Check Default Timeout
# ./watchdog_test.sh timeout
Watchdog timeout: 10 sec
Check Feeding Source
# ./watchdog_test.sh feeder
========================================
Watchdog Feeding Source
========================================
Sysfs state : inactive
Sampling timeleft (1s x 7, kernel feeds about every 5s):
[1] timeleft=9s
[2] timeleft=8s
[3] timeleft=7s
[4] timeleft=6s
[5] timeleft=10s
[6] timeleft=9s
[7] timeleft=8s
Timeleft seq : 9 8 7 6 10 9 8
Feed source : kernel # kernel is feeding the watchdog
Reason : state=inactive, timeleft increased during sampling
(kernel watchdog worker kicked the hardware WDT)
========================================
root@buildroot:/app/platform_samples/chip_base_test/14_watchdog_test
Check Remaining Timeout
# ./watchdog_test.sh timeleft
Watchdog timeleft: 9 sec (timeout=10 sec)
Feed Test
Feed once
# ./watchdog_test.sh feed 1
Feeding watchdog on /dev/watchdog0: 1 time(s), interval=1s
[1/1] keepalive ok, timeleft=10s
[ 647.681517] watchdog: watchdog0: watchdog did not stop!
Feed done (1 times)
Note: userspace took over (state may become active);
kernel auto-feed pauses until reboot or disable
Feed multiple times with a 5-second interval
# ./watchdog_test.sh feed 10 -i 5
Feeding watchdog on /dev/watchdog0: 10 time(s), interval=5s
[1/10] keepalive ok, timeleft=10s
[2/10] keepalive ok, timeleft=10s
[3/10] keepalive ok, timeleft=10s
[4/10] keepalive ok, timeleft=10s
[5/10] keepalive ok, timeleft=10s
[6/10] keepalive ok, timeleft=10s
[7/10] keepalive ok, timeleft=10s
[8/10] keepalive ok, timeleft=10s
[9/10] keepalive ok, timeleft=10s
[10/10] keepalive ok, timeleft=10s
[ 329.019018] watchdog: watchdog0: watchdog did not stop!
Feed done (10 times)
Note: userspace took over (state may become active);
kernel auto-feed pauses until reboot or disable
Note: Once userspace feeds the watchdog, kernel auto-feed pauses. If you feed only N times and then exit without further feeding, the system will reset on timeout.
Disable Watchdog
# ./watchdog_test.sh disable
Stopping watchdog via magic close on /dev/watchdog0 ...
State after disable: inactive
Timeleft after disable: 0 sec
Watchdog disable command sent (magic close 'V')
Note: reboot or re-probe driver to re-enable if needed
Note: A reboot is required to enable the watchdog again after it is disabled.
4.5.18.4. Test Metrics
The watchdog is a Synopsys DesignWare hardware WDT with driver
dw_wdt; the device node/dev/watchdog0is available.Under
/sys/class/watchdog/watchdog0, attributes such astimeleft,timeout,identity, andstateare present.