8

Does the Raspberry Pi 4 have a hardware watchdog timer like the RPi3 does? If it does, which kernel module should I load in order to use it?

I'm running Raspbian Buster, kernel 4.19.93-v7l+

Thanks.

tlqmj
  • 119
  • 1
  • 1
  • 7
  • 1
    What kernel module do you load on the Pi 3 to enable the watchdog? – Botspot Feb 05 '20 at 20:20
  • Hi @tiqmj, Yes, Rpi4B has hardware watchdog preinstalled: "Rpi3B+ / Rpi4B Watchdog and LM2956 / LM2941 PSU Remote Control Problem" - https://raspberrypi.stackexchange.com/questions/99584/how-to-monitor-if-a-remote-rpi-freezes-and-reboots-it-using-a-watchdog-timer-or. Good luck and cheers. – tlfong01 Feb 06 '20 at 01:30
  • @Botspot according to [this](https://www.domoticz.com/wiki/Setting_up_the_raspberry_pi_watchdog), `bcm2835_wdt`. Altough maybe the preferred way is to use `/boot/config.txt` like @Milliways sugests. – tlqmj Feb 06 '20 at 12:21

4 Answers4

12

To check if the watchdog is available, you can run wdctl which gives you a bit more info than just looking at /dev/watchdog.

To start using the watchdog, you can still use the old watchdog daemon mentioned in the other answers, but since 2012 systemd has had built in support for watchdogs that doesn't require installing anything else and offers better compatibility with the shutdown/reboot process.

To use this, edit /etc/systemd/system.conf and set these values as required:

  • RuntimeWatchdogSec - reboot the system if nothing contacts the watchdog within this time (specify the value like 2min, 10s, etc.) This defaults to off, meaning the system will never reboot when it freezes.
  • RebootWatchdogSec - different timeout used when rebooting, in case you need more (or less) time. Defaults to 10min. Note that this only applies during the last phase of the reboot, once all running programs have been terminated. If your programs take too long to shut down, this value won't help (see below).
  • ShutdownWatchdogSec - this is no longer used, it was renamed to RebootWatchdogSec in July 2019.
  • KExecWatchdogSec - ignore this unless you know what kexec is and you know you are using it. (It's used when faking a reset by just restarting the kernel - the lack of a hardware reset means the watchdog is still running and may expire before everything has finished loading again).
  • WatchdogDevice - this can be ignored as the default of /dev/watchdog is fine.
  • DefaultTimeoutStopSec - how long to wait for each program to exit when shutting down or rebooting. Defaults to 90s but I am impatient so I set this to 10s as anything on my system that takes longer than five seconds is broken, so a 10 second timeout is just fine.

If you are using a Pi 2 or older, set dtparam=watchdog=on in /boot/config.txt and reboot. This is enabled by default from the Raspberry Pi 3 onwards, so you can skip this step with recent models.

You don't need to run systemctl enable watchdog (that's for the old method mentioned above) but you will need to run systemctl daemon-reload (or reboot) after making these changes before they will take effect.

Malvineous
  • 1,694
  • 11
  • 20
  • Thanks for this write up. How can one verify that the watchdog is working? I've read you can do a fork-bomb or a NULL pointer de-reference in the other answer. Would that be sufficient? – ScottN Jul 13 '20 at 23:47
  • Well I kinda got my answer, because I did the steps provided, but you said just a reboot or `systemctl daemon-reload` would work, the system was rebooting because no watchdog was being updated. I looked further and there is no watchdog service/unit file as the system complains when running `systemctl status watchdog` gives `Unit watchdog.service could not be found`. Are you sure something isn't supposed to be installed? Or do you have an example Unit file that can be created for the watchdog service? – ScottN Jul 13 '20 at 23:56
  • It sounds like it's working (the fact that it reboots suggests it's picking it up the watchdog) so if you're still having problems it'd probably be best to ask over at the Raspberry Pi forums as there will probably be a bit of back-and-forth trying to nut out the problem, which isn't really suited for squishing into the comments section on a Q&A site like here! – Malvineous Jul 14 '20 at 07:47
3

Do NOT attempt to load ANY modules.

Add dtparam=watchdog=on to config.txt and Device Tree will load the module.

NOTE you also need to enable the watchdog service. See https://raspberrypi.stackexchange.com/a/68332/8697

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • 1
    Is it smart, in general, to never load any modules? What's wrong/dangerous about it? – Botspot Feb 06 '20 at 12:54
  • You only have to edit `config.txt` on a Pi 2 and earlier. It is on by default since the Pi 3. There is nothing wrong with loading any modules. If the hardware is not present the module will just return an error. However most modules will load automatically, so if you do feel the need to load them yourself, you are probably heading down the wrong track. – Malvineous Jun 06 '20 at 11:33
3

Ok, after some testing it seems like the watchdog module is loaded by default. To check for yourself, see if /dev/watchdog exists.

This is the guide what worked for me.

tlqmj
  • 119
  • 1
  • 1
  • 7
  • In 2021, I found this the simplest, shortest and easiest way to get the watchdog up and running on a Pi 4: https://diode.io/raspberry%20pi/running-forever-with-the-raspberry-pi-hardware-watchdog-20202/ – Adam Reis May 29 '21 at 00:13
2

For the RaspberryPi4 it's more straightforward than for earlier software as much of the configuration scaffolding is already in place.

Edit /etc/systemd/system.conf adding the line

RuntimeWatchdogSec=15

then reload systemd's configuration with the command sudo systemctl daemon-reload.

Do not use values greater than 15 seconds, as that's the limit for the RPi4's countdown timer.

Optionally, if you want the watchdog timer to also detect systemd crashing then edit /boot/cmdline.txt to add to the existing line the new kernel parameter

bcm2835-wdt.nowayout=1

then reboot the system with the command sudo systemctl reboot.

vk5tu
  • 121
  • 2