谁在刷新Linux中的硬件看门狗?

发布于 2024-08-17 02:19:32 字数 1294 浏览 8 评论 0原文

我有一个运行 2.6 内核的处理器 AT91SAM9G20。看门狗在引导级别启用并配置为 16 秒。看门狗模式寄存器只能配置一次。 当代码挂在引导程序、引导加载程序或内核中时,主板将重新启动。但是,一旦内核启动,即使看门狗在任何应用程序中都没有刷新,主板也不会在 16 秒后重置,而是在 15 分钟后重置。

谁在刷新看门狗?

在我们的例子中,看门狗应该受到应用程序的影响,以便在我们的应用程序挂起时主板可以重置。

这些是正在运行的进程:

1 root     init
2 root     [kthreadd]
3 root     [ksoftirqd/0]
4 root     [watchdog/0]
5 root     [events/0]
6 root     [khelper]
63 root     [kblockd/0]
72 root     [ksuspend_usbd]
78 root     [khubd]
85 root     [kmmcd]
107 root     [pdflush]
108 root     [pdflush]
109 root     [kswapd0]
110 root     [aio/0]
740 root     [mtdblockd]
828 root     [rpciod/0]
982 root     [jffs2_gcd_mtd10]
1003 root     /sbin/udevd -d
1145 daemon   portmap
1158 dbus     dbus-daemon --system
1178 root     /usr/sbin/ifplugd -i eth0 -fwI -u0 -d5 -l -q
1190 root     /usr/sbin/ifplugd -i eth1 -fwI -u0 -d5 -l -q
1221 default  avahi-daemon: running [SP14.local]
1226 root     /usr/sbin/dropbear
1246 root     /root/bin/host_app
1254 root     /root/bin/mini_httpd -c *.cgi -d /root/bin -u root -E /root/bin/
1256 root     -sh
1257 root     /sbin/syslogd -n -m 0
1258 root     /sbin/klogd -n
1259 root     /usr/bin/tail -f /var/log/messages
1265 root     ps -e

我们正在使用 kernel-2.6.25-ts.at91sam9g20/kernel/softlockup.c 中提供的看门狗进行软锁定

I have a processor AT91SAM9G20 running a 2.6 kernel. Watchdog is enabled at bootstrap level and configured for 16 seconds. Watchdog mode register can be configured only once.
When code hangs either in bootstrap, bootloader or kernel, the board reboots. But once kernel comes up even though watchdog is not refreshed in any of the applications, the board is not being reset after 16 seconds, but 15 minutes.

Who is refreshing the watchdog?

In our case, the watchdog should be influenced by applications, so that the board can reset if our application hangs.

These are the running processes:

1 root     init
2 root     [kthreadd]
3 root     [ksoftirqd/0]
4 root     [watchdog/0]
5 root     [events/0]
6 root     [khelper]
63 root     [kblockd/0]
72 root     [ksuspend_usbd]
78 root     [khubd]
85 root     [kmmcd]
107 root     [pdflush]
108 root     [pdflush]
109 root     [kswapd0]
110 root     [aio/0]
740 root     [mtdblockd]
828 root     [rpciod/0]
982 root     [jffs2_gcd_mtd10]
1003 root     /sbin/udevd -d
1145 daemon   portmap
1158 dbus     dbus-daemon --system
1178 root     /usr/sbin/ifplugd -i eth0 -fwI -u0 -d5 -l -q
1190 root     /usr/sbin/ifplugd -i eth1 -fwI -u0 -d5 -l -q
1221 default  avahi-daemon: running [SP14.local]
1226 root     /usr/sbin/dropbear
1246 root     /root/bin/host_app
1254 root     /root/bin/mini_httpd -c *.cgi -d /root/bin -u root -E /root/bin/
1256 root     -sh
1257 root     /sbin/syslogd -n -m 0
1258 root     /sbin/klogd -n
1259 root     /usr/bin/tail -f /var/log/messages
1265 root     ps -e

We are using the watchdog for soft lockups available in kernel-2.6.25-ts.at91sam9g20/kernel/softlockup.c

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

同展鸳鸯锦 2024-08-24 02:19:32

如果您在内核中启用了看门狗驱动程序,则看门狗驱动程序会设置一个内核计时器,负责重置看门狗。对应的代码为 linux/drivers/watchdog/at91sam9_wdt.c 。所以它的工作原理是这样的:

如果没有应用程序打开 /dev/watchdog 文件,那么内核会负责重置看门狗。由于它是一个定时器,因此它不会出现为专用的内核线程,而是由软IRQ线程处理。现在,如果应用程序打开此文件,它就会对看门狗负责,并且可以通过写入该文件来重置它,如理查德帖子中链接的文档所述。

你的内核中是否配置了看门狗驱动程序?
如果没有,您应该对其进行配置,并查看重置是否仍然发生。如果仍然发生,则您的重置可能来自其他地方。

如果您的内核太旧而没有适当的看门狗驱动程序(2.6.25 中不存在),您应该从 2.6.28 向后移植它。或者您可以尝试禁用引导加载程序中的看门狗,然后查看重置是否仍然发生。

If you enabled the watchdog driver in your kernel, the watchdog driver sets up a kernel timer, in charge of resetting the watchdog. The corresponding code is linux/drivers/watchdog/at91sam9_wdt.c. So it works like this:

If no application opens the /dev/watchdog file, then the kernel takes care of resetting the watchdog. Since it is a timer, it won't appear as a dedicated kernel thread, but handled by the soft IRQ thread. Now, if an application opens this file, it becomes responsible of the watchdog, and can reset it by writing to the file, as documented by the documentation linked in Richard's post.

Is the watchdog driver configured in your kernel?
If not, you should configure it, and see if the reset still happens. If it still happens, it is likely that your reset comes from somewhere else.

If your kernel is too old to have a proper watchdog driver (not present in 2.6.25) you should backport it from 2.6.28. Or you can try to disable the watchdog in your bootloader and see if the reset still occurs.

心碎的声音 2024-08-24 02:19:32

2016 年 7 月 将 4.7 内核中的 3fbfe92647(watchdog:更改 watchdog_need_worker 逻辑) 提交为 < code>watchdog_dev.c 为所有看门狗定时器驱动程序启用了与 shodanex 的答案相同的行为。除了这个线程和源代码之外,这似乎没有在任何地方记录。

/*
* 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));

In July 2016 commit 3fbfe92647 (watchdog: change watchdog_need_worker logic) in the 4.7 kernel to watchdog_dev.c enabled the same behavior as shodanex's answer for all watchdog timer drivers. This doesn't seem to be documented anywhere other than this thread and the source code.

/*
* 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));
〗斷ホ乔殘χμё〖 2024-08-24 02:19:32

这可能会给您一个提示: http://www.mjmwired.net/ kernel/Documentation/watchdog/watchdog-api.txt

让用户空间守护进程处理看门狗是非常有意义的。它可能默认为 15 分钟超时。

This may give you a hint: http://www.mjmwired.net/kernel/Documentation/watchdog/watchdog-api.txt

It makes perfect sense to have a user space daemon handling the watchdog. It probably defaults to a 15 minute timeout.

や三分注定 2024-08-24 02:19:32

我们在 AT91SAM9263 上的 WDT 上也遇到了类似的问题。问题出在 WDT_MR(地址:0xFFFFFD44)寄存器的位 29 WDIDLEHLT 上。该位被设置为 1,但根据我们的应用程序需求,它应该为 0。

数据表文档中的位解释:

• WDIDLEHLT:看门狗空闲停止

  1. 0:看门狗在系统处于空闲模式时运行。
  2. 1:当系统处于空闲状态时,看门狗停止。

这意味着当内核处于空闲状态时,WDT 计数器不会递增,因此在复位发生之前有 15 个或更多的延迟。

您可以尝试“dd if=/dev/zero of=/dev/null”,这将阻止内核进入空闲状态,您应该在 16 秒内(或您在 WDT_MR 寄存器中设置的任何时间段)重置。

因此,解决方案是更新 u-boot 代码或其他设置 WDT_MR 寄存器的代码。请记住该寄存器只写入一次......

we had a similar problem regarding WDT on AT91SAM9263. Problem was with bit 29 WDIDLEHLT of WDT_MR (Address: 0xFFFFFD44) register. This bit was set to 1 but it should be 0 for our application needs.

Bit explanation from datasheet documentation:

• WDIDLEHLT: Watchdog Idle Halt

  1. 0: The Watchdog runs when the system is in idle mode.
  2. 1: The Watchdog stops when the system is in idle state.

This means that WDT counter does not increment when kernel is in idle state, hence the 15 or more delay until reset happens.

You can try "dd if=/dev/zero of=/dev/null" which will prevent kernel from entering idle state and you should get a reset in 16 seconds (or whatever period you have set in WDT_MR register).

So, the solution is to update u-boot code or other piece of code that sets WDT_MR register. Remember this register is write once...

薄暮涼年 2024-08-24 02:19:32

内核不会刷新看门狗定时器吗?看门狗旨在在整个系统(而不仅仅是单个应用程序)挂起时重置主板。

Wouldn't the kernel be refreshing the watchdog timer? The watchdog is designed to reset the board if the whole system hangs, not just a single application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文