4.5.18. WatchDog 测试
4.5.18.1. 测试原理
X5 集成watchdog@34250000,驱动 dw_wdt)。WDT 启动
典型
内核
代 :内核喂(默认) watchdogd线程周期性 kick, /sys/class/watchdog/watchdog0/state为inactive,无需用户 态 程序 参与 用户
态 :进程 open接管 /dev/watchdog0并写入 数据 后,内核 停止 代 喂,须 由 该 进程 持续 喂狗 关闭
看门狗 :nowayout=0时可 通过 Magic Close 关闭;关闭 后 需 重启 才能 再次 启用
内核 / 用户态 DesignWare WDT 超时未 kick
┌─────────────┐ 周期性 kick ┌──────────────┐ ┌─────────┐
│ 喂狗源 │ ──────────────> │ 计数器递减 │ ──────────────> │ SoC 复位│
└─────────────┘ └──────────────┘ └─────────┘
4.5.18.2. 准备工作
脚本使用说明
watchdog_test.sh 支持-h 参数
# ./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
各
info: 查看硬件 看门狗 基本 信息 timeout查看当前 配置 的 超时 时间 (秒) feeder判断当前 是 内核 态 还是 用户 态在 喂狗 timeleft查看当前 剩余 超时 时间 (秒) feed喂狗 <次数> [-i 间隔秒数] ; 默认 间隔 1 秒 disable关闭看门狗,关闭 后 需 重启 才能 再次 启用 -h / --help显示帮助
4.5.18.3. 测试方法
查看默认超时时间
# ./watchdog_test.sh timeout
Watchdog timeout: 10 sec
查看喂狗来源
# ./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 # 当前是内核态喂狗
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
查看剩余超时时间
# ./watchdog_test.sh timeleft
Watchdog timeleft: 9 sec (timeout=10 sec)
喂狗测试
喂狗
一次
# ./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
喂狗
多次,且 每次 间隔 5s
# ./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
注意 :用户
关闭看门狗
# ./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
注意 :关闭
4.5.18.4. 测试指标
看门狗
为 Synopsys DesignWare 硬件 WDT,驱动 dw_wdt,设备节点 /dev/watchdog0可用/sys/class/watchdog/watchdog0目录下 timeleft、timeout、identity、state等属性 存在