Discussion:
[uClinux-dev] Coldfire watchdog timer best-practices?
Steve deRosier
2013-02-14 18:34:58 UTC
Permalink
I'd like to know what is the best way to handle the watchdog timer in
Linux? I've reviewed the docs and the watchdog framework and it's not
really fitting my needs.

The system I'm upgrading turns on the WDT very early in the
boot-loader There is code sprinkled through the boot-loader and then
sprinkled through various init calls in Linux 2.4 that kick the WDT
before it times out all through boot. Eventually when userspace comes
up, a user program opens the WDT device and takes control of kicking
it via an ioctl into a custom gpio driver. Of course there's still a
few spots in the kernel and drivers that seem to kick the WDT during
normal operation, so it's still a remote possibility that a reset
wouldn't occur even if the user-space program died.

As you might imagine, I don't like that the original coders simply,
via trial and error, sprinkled a WDT kick call randomly through all
the various kernel init calls in order to keep things going. I was
hoping that with a formal WDT framework in 3.x that the kernel had
some sort of hook to handle it in a clean and accepted manner.

The kernel driver framework seems to assume that the WDT will only be
handled by userspace and indeed doesn't start the WDT until the device
is opened. As near as I can tell, there's no provision to handle a WDT
that's started during or before kernel boot. True?

It's important to note that the WDT on the MCF5235, once started, can
not be disabled. And once it's time period is set, that can't be
changed either. It's set at a max interval of about 8 seconds.

I have thought of a few ways to proceed:

1. Implement a standard WDT that doesn't start till userspace opens
the device and convince the system designers that's OK.
2. Implement the existing strategy and just sprinkle the kicking code
through the kernel init and drivers, and add the standard WDT that
userspace can open and take over with.
3. Implement some kernel process that takes over automatic periodic
kicking until the real WDT driver is opened the first time by
userspace. Then that process gets disabled.

Anyway, any thoughts? How have other Coldfire projects handed the WDT in Linux?

Thanks,
- Steve
Wolfgang Wegner
2013-02-14 20:39:43 UTC
Permalink
On Thu, Feb 14, 2013 at 10:34:58AM -0800, Steve deRosier wrote:
[...]
Post by Steve deRosier
3. Implement some kernel process that takes over automatic periodic
kicking until the real WDT driver is opened the first time by
userspace. Then that process gets disabled.
Unfortunately, I do not remember where I stole this idea, but here is
how I did (maybe it was with a Coldfire 5373L):

- enable and initialize WDT in Bootloader (U-Boot)
- move Linux WDT init very early in the boot process
I modified the watchdog driver by adding a timer-interrupt based
kick at the init stage; This timer was active for a compile-time
configurable time (number of kicks, actually) - I used 120 seconds.
During this time, the in-kernel timer kicked the WDT to avoid
timeout during init. As soon as the WDT device was opened from user
space, this timer was permanently disabled to let the user space
take control.

Like this, I had the following "features":
- early start of WDT
- no problem during fsck or other boot-time delay (mounting/initializing
a flash filesystem or initializing some USB device did take ridiculous
amounts of time, occasionally)
- quite robust because the timer-based kicking during boot proved quite
resilient against arbitrary delays in other drivers' init code, while
still having a good chance to catch real errors because of this in-kernel
timer being stopped after a longer timeout.

I guess there may be more sophisticated methods, but for our project,
we did not have any failure or problem with this one.

Best regards,
Wolfgang

Loading...