谁在Linux中默默地踢看门狗定时器?

时间:2017-03-09 02:37:55

标签: linux-device-driver

我在嵌入式平台上使用4.9 Linux内核并注意到监视程序计时器正在自动刷新,即使我没有像watchdog documentation那样运行的用户空间守护程序。

1 个答案:

答案 0 :(得分:1)

几乎逐字逐句地从shodanex's answer转到相关问题。

如果在内核中启用了监视程序驱动程序,则监视程序驱动程序会设置一个内核计时器,负责重置监视程序。

如果没有应用程序打开/ dev / watchdog文件,则内核负责重置监视程序。由于它是一个计时器,它不会作为专用内核线程出现,而是由软IRQ线程处理。现在,如果应用程序打开此文件,它将负责监视程序,并可以通过写入文件来重置它,如文档the watchdog documentation所示。

2016年7月a commit in the 4.7 kernel to watchdog_dev.c为所有看门狗定时器驱动程序启用了此行为。在此之前,它似乎是参差不齐和特定于驱动程序。除了此线程和源代码之外,该行为似乎没有记录在任何地方。

/*
* A worker to generate heartbeat requests is needed if all of the
* following conditions are true.
* - Userspace activated the watchdog.
* - The driver provided a value for the maximum hardware timeout, and
*   thus is aware that the framework supports generating heartbeat
*   requests.
* - Userspace requests a longer timeout than the hardware can handle.
*
* Alternatively, if userspace has not opened the watchdog
* device, we take care of feeding the watchdog if it is
* running.
*/

return (hm && watchdog_active(wdd) && t > hm) ||
       (t && !watchdog_active(wdd) && watchdog_hw_running(wdd));