How to use hardware WatchdogTimer


#1

Hello,
I m working on IOT device dell gateway in that Ubuntu Core 16 OS is there and I want to use Hardware Timer for any unexpected crashes or etc…

  1. So I have opened “/dev/watchdog” but it will busy always and get failed.

So i don’t know why its happening , is there any security in Ubuntu Core 16 to access some path.
and
2) I have tried some command to change RunTimeWatchdogSec but It could same nothing change.

snap set core watchdog.runtime-timeout=10m

systemctl show | grep -i watchdog

RuntimeWatchdogUSec=1min
ShutdownWatchdogUSec=10min

  1. In Dell gateway User manual there is one WDT and it is provide some Enable/Disable policy and some configuration files like /etc/systemd/system.conf.d etc… so IF i m enable this Timer so after words is that working same as our OS WDT ???

please let me know.


#2

Here some code .

int32_t ret_val = 0;
const string watchdog_dev("/dev/watchdog");
/Open Watchdog device/
watchdog_fd = open(watchdog_dev.c_str(), O_RDWR);
if (watchdog_fd < 0)
{
SPDLOG_LOGGER_CALL(loggerObject,spdlog::level::err, “open Failed . {}”,watchdog_fd);
//return -1;
}
else
{
ret_val = ioctl(watchdog_fd, WDIOC_SETTIMEOUT, &watchdog_timeout);
if (ret_val < 0)
{
SPDLOG_LOGGER_CALL(loggerObject,spdlog::level::err, “set watchdog timeout Failed in ,error is {}”, errno);
stopWatchdogTimer();

    }

#3

According to the output, the watchdog timer is configured and working.

If the manual says the watchdog timer is configured through /etc/systemd/system.conf.d/SOMEFILE.conf, you should follow it, otherwise the setting may become inconsistent.
And, YES, the watchdog timer is system-wide like what you want to do.


#4

the hardware watchdog is handled by snapd on Ubuntu Core, configuration is described at


#5

Thanks for valuable replay.

Actually I have one Main Application(Gateway App) and one watchdog Application(working as Daemon ) so watchdog App would be continuously eye on Main App(Gateway App) if something goes wrong i GatewayApp or crash happen then Watchdog App will restart it.

So Now the point is IF my Watchdog App will hang or some kill it then who has taken care SO I want to handle through OS timer.

BUT when I open “/dev/watchdog” open then it will GIVE error “Resource Busy”.

snap set core watchdog.runtime-timeout=1m

IF I set above parameter then How to know OS timer to WHEN restart the system untill OS was not hang.
Actually my Use case is mention above.
please Update me …

Thanks…


#6

if you have that time set the OS will automatically restart via the builtin kernel mechnism … if you need to know the value in your application this would only be doable via something like:

snap get system watchdog.runtime-timeout

but i fear outside of that manual snap get... command you can only obtain the value via the snapd-control interface from an API call …


#7

ok…
Thanks for this response.


#8

hey,
How to Test hardware watchdog timer is work properly or not in Ubuntu core 16.

Thanks…


#9

log in, run sudo -s (to permanently become root) and then:

cat >> /dev/watchdog

and press enter twice … the prompt will not return and after the timeout you defined the system should reboot.


#10

I have tried this above command BUT Resource Busy comes. So in this case how to verify watchdog Timer???

root@511SP42:~# cat >> /dev/watchdog
bash: /dev/watchdog: Device or resource busy