Skip to contentSkip to conversation

RFC, watchdog: add generic wdt driver API

PATCH In review Heiko Schocher 4 participants 7 messages Dec 4, 2011 – Dec 7, 2011

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RFC, watchdog: add generic wdt driver API

This driver implements a character device with major number 10 and minor number 130. It is a software abstraction of the hardware watchdog with two different APIs. While the driver periodically triggers the hardware watchdog, the software can setup independent timeout periods.

"REGULAR API"
provides a facility to setup a watchdog behaviour shared by all processes using the driver. This interface uses read, write and ioctl calls.

"CHAIN API"
can be used to register configurable "watchdog chains" from kernel and/or user space. This interface uses ioctl calls only.

more info about this two APIs are found in
Documentation/watchdog/wd-api.txt

Different hardware layers can attached to this driver. As this is an RFC add in this patch also, as an example for an hardware layer, support for the arm davinci internal WDT.

---
This patch is a port from Linux 2.4 and thought as an RFC, so comments are greately appreciated. First question is, has this watchdog driver API a chance to go in mainline? If so, what is the direction to go to push it ...

 Documentation/devicetree/bindings/watchdog/wd.txt |   18 +
 Documentation/watchdog/wd-api.txt                 |  196 ++++
 arch/arm/mach-davinci/time.c                      |    2 +
 drivers/watchdog/Kconfig                          |   31 +
 drivers/watchdog/Makefile                         |    2 +
 drivers/watchdog/wd.c                             | 1013 +++++++++++++++++++++
 drivers/watchdog/wd_davinci.c                     |  146 +++
 include/linux/wd.h                                |  131 +++
 include/linux/wd_hw.h                             |   55 ++
 9 files changed, 1594 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/watchdog/wd.txt
 create mode 100644 Documentation/watchdog/wd-api.txt
 create mode 100644 drivers/watchdog/wd.c
 create mode 100644 drivers/watchdog/wd_davinci.c
 create mode 100644 include/linux/wd.h
 create mode 100644 include/linux/wd_hw.h
Documentation/devicetree/bindings/watchdog/wd.txt new file +18 -0
new file mode 100644
index 0000000..75fa966
@@ -0,0 +1,18 @@
+* generic WDT interface
+
+driver implements a character device with major number 10 and minor
+number 130.  It is a software abstraction of the hardware watchdog
+with two different APIs.  While the driver periodically triggers the
+hardware watchdog, the software can setup independent timeout periods.
+
+Different hardware layers can attached to this driver. Here a summary
+of existing harware layers and the necessary properites for them:
+
+Davinci WDT:
+
+Required properties:
+- compatible : should be "ti,davinci-wdt"
+- reg : physical base address and length of memory mapped region.
+
+Optional properties
+- period: trigger period for wdt in jiffies
Documentation/watchdog/wd-api.txt new file +196 -0

196 lines not on this page · raw message

arch/arm/mach-davinci/time.c +2 -0
index e1969ce..2cba402 100644
@@ -423,6 +423,7 @@ struct sys_timer davinci_timer = {
 };
 
 
+#if !defined(CONFIG_WD_DAVINCI)
 /* reset board using watchdog timer */
 void davinci_watchdog_reset(struct platform_device *pdev)
 {
@@ -472,3 +473,4 @@ void davinci_watchdog_reset(struct platform_device *pdev)
 	wdtcr = 0x00004000;
 	__raw_writel(wdtcr, base + WDTCR);
 }
+#endif
drivers/watchdog/Kconfig +31 -0
index 79fd606..1dce4ff 100644
@@ -53,6 +53,37 @@ comment "Watchdog Device Drivers"
 
 # Architecture Independent
 
+config WD
+	bool "Generic watchdog driver"
+	help
+	  This is a generic high-level watchdog driver. It implements
+	  platform independent front end for watchdog devices. If you
+	  say Y here, you most likely should also enable a low-level
+	  watchdog driver characteristic for installed hardware.
+
+if WD
+
+config WD_TIMEOUT
+	int "Set default timeout for generic watchdog driver (in sec.)"
+	default "300"
+	help
+	  This option sets default watchdog timeout. It can be overwritten
+	  by user using kernel command line option or write() function called
+	  on watchdog device.
+
+comment "Low-level watchdog drivers"
+
+config WD_DAVINCI
+	bool "Driver for triggering internal WDT on davinci plattforms"
+	depends on WD
+	default n
+	select ARCH_HAS_NMI_WATCHDOG
+	help
+	  Low level functions for triggering the internal WDT
+	  on davinci plattforms. Tested on an am1808 based board.
+
+endif # WD
+
 config SOFT_WATCHDOG
 	tristate "Software watchdog"
 	help
drivers/watchdog/Makefile +2 -0
index fe893e9..784e2fd 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
 obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o
 obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
+obj-$(CONFIG_WD_DAVINCI) += wd_davinci.o
 
 # AVR32 Architecture
 obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
@@ -165,4 +166,5 @@ obj-$(CONFIG_XEN_WDT) += xen_wdt.o
 obj-$(CONFIG_WM831X_WATCHDOG) += wm831x_wdt.o
 obj-$(CONFIG_WM8350_WATCHDOG) += wm8350_wdt.o
 obj-$(CONFIG_MAX63XX_WATCHDOG) += max63xx_wdt.o
+obj-$(CONFIG_WD) += wd.o
 obj-$(CONFIG_SOFT_WATCHDOG) += softdog.o
drivers/watchdog/wd.c new file +1013 -0

1,013 lines not on this page · raw message

drivers/watchdog/wd_davinci.c new file +146 -0

146 lines not on this page · raw message

include/linux/wd.h new file +131 -0

131 lines not on this page · raw message

include/linux/wd_hw.h new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
1.7.6.4
#1 lore raw
Quoted 28 lines · Heiko Schocher

This driver implements a character device with major number 10 and minor number 130. It is a software abstraction of the hardware watchdog with two different APIs. While the driver periodically triggers the hardware watchdog, the software can setup independent timeout periods.

"REGULAR API"
provides a facility to setup a watchdog behaviour shared by all processes using the driver. This interface uses read, write and ioctl calls.

"CHAIN API"
can be used to register configurable "watchdog chains" from kernel and/or user space. This interface uses ioctl calls only.

more info about this two APIs are found in
Documentation/watchdog/wd-api.txt

Different hardware layers can attached to this driver. As this is an RFC add in this patch also, as an example for an hardware layer, support for the arm davinci internal WDT.

Quoted 5 lines

---
This patch is a port from Linux 2.4 and thought as an RFC, so comments are greately appreciated. First question is, has this watchdog driver API a chance to go in mainline? If so, what is the direction to go to push it ...

I don't see this flying. We finally have a watchdog framework in the kernel which covers the long existing API used by existing drivers. If I understood it right, this additional API needs new drivers for all the watchdogs? Also, I didn't fully get what you are missing from the combination of the current API and additional userspace-handling? (check [1] for one example, not really covering your use case but showing a potential way maybe) Didn't look much at the code, but glimpsing says it needs some cleanups regarding comments and excessive debug output.

Regards,

Wolfram

[1] http://lists.freedesktop.org/archives/systemd-devel/2011-November/003802.html

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#2 lore raw

Dear Wolfram,

Quoted 11 lines · In message <[email protected]> you wrote:
Quoted 5 lines

This patch is a port from Linux 2.4 and thought as an RFC, so comments are greately appreciated. First question is, has this watchdog driver API a chance to go in mainline? If so, what is the direction to go to push it ...

I don't see this flying. We finally have a watchdog framework in the kernel which covers the long existing API used by existing drivers. If I understood it right, this additional API needs new drivers for all the watchdogs? Also, I didn't fully get what you are missing from the combination of the current API and additional userspace-handling? (check [1] for one example, not really

Watchdog support is somethign that usually comes into play for security-critical devices. Doing this stuff in user space may or may not be sufficient; for example, we've seen requirements where all related code must be running from ROM (including all other kernel code).

Also, the implementation submitted by Heiko allows for easy watchdog control for kernel tasks. I don;t see a good way to do this through user space.

But as Heikow wrote; this is a RFC patch, and the main purpose is to try to find out if it has a chance to go into mainline - several earlier attempts (which go back as far as 2002 - see for example [1], [2]) all failed with similar arguments like yours: "It's too complex, we already have watchdog support, nobody needs this". Funny enough that we have a number of customers who consider the existing wdt support unsufficient for their use cases. We've been using it on all kinds on PPC systems, and now on ARM as well.

We will not fight for inclusion of this driver, we just wat to know if it's worth investing efforts to get it accepted or if this is a lost case.

[1] http://osdir.com/ml/linux.ports.ppc.embedded/2003-12/msg00188.html
[2] http://thread.gmane.org/gmane.linux.kernel/884598

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: [email protected]
Gewöhnlich glaubt der Mensch,  wenn er nur Worte hört,  es müsse sich
dabei doch auch was denken lassen.                 -- Goethe, Faust I
#3 lore raw
Quoted 7 lines

that we have a number of customers who consider the existing wdt support unsufficient for their use cases. We've been using it on all kinds on PPC systems, and now on ARM as well.

We will not fight for inclusion of this driver, we just wat to know if it's worth investing efforts to get it accepted or if this is a lost case.

I think it would be better to start from the needed feature list than the implementation of an old and wildly different pile of code. Then discuss adding those features that are relevant to the current framework - which ought to be relatively easy now each watchdog is a set of methods.

Alan

#6 lore raw
In reply to Wolfgang Denk

Hi Wolfgang,

Quoted 3 lines
Quoted 3 lines

right, this additional API needs new drivers for all the watchdogs? Also, I didn't fully get what you are missing from the combination of the current API and additional userspace-handling? (check [1] for one example, not really

...

Quoted 8 lines

But as Heikow wrote; this is a RFC patch, and the main purpose is to try to find out if it has a chance to go into mainline - several earlier attempts (which go back as far as 2002 - see for example [1], [2]) all failed with similar arguments like yours: "It's too complex, we already have watchdog support, nobody needs this". Funny enough that we have a number of customers who consider the existing wdt support unsufficient for their use cases. We've been using it on all kinds on PPC systems, and now on ARM as well.

I never said the features are useless. I also didn't say you should do everything in userspace. I asked because I wanted to know what exactly are the things you are missing from what is possible today. So, this could maybe be added to the current watchdog frameworks. Adding a new framework (with lots of issues) and requiring a new set of drivers won't cut it.

Regards,

Wolfram

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#4 lore raw
In reply to Alan Cox

Hello Alan,

Quoted 4 lines · Alan Cox
Quoted 4 lines

that we have a number of customers who consider the existing wdt support unsufficient for their use cases. We've been using it on all kinds on PPC systems, and now on ARM as well.

Quoted 8 lines
Quoted 3 lines

We will not fight for inclusion of this driver, we just wat to know if it's worth investing efforts to get it accepted or if this is a lost case.

I think it would be better to start from the needed feature list than the implementation of an old and wildly different pile of code. Then discuss adding those features that are relevant to the current framework - which ought to be relatively easy now each watchdog is a set of methods.

Ok, I try to describe the needed new features called in the old driver code Chain API:

The chain API is used to register configurable "watchdog chains" from either user or kernel space. A watchdog chain is identified by an unsigned integer and can contain up to three action stages. Configured through ioctl().

A "time interval" in seconds and an "action" is associated with each stage. When the chain is not reset before the interval elapses, the associated action is triggered and the chain moves on to the next stage.

A chain can request to kill the registering process if the interval elapses. In this case a restarted process can register with the driver giving the same identifier and reset the chain. This is the main reason why there is no association between chains and processes or open device files.

Possible chain actions:
- ACTION_SIGNAL: sends a configurable signal to the process
- ACTION_KILL: sends the SIGKILL signal to the process
- ACTION_REBOOT: tries a soft reboot
- ACTION_RESET: triggers a hard-reset

ioctl calls:
- WD_REGISTER: register a chain

The parameter given to the call is a pointer to a structure with the following layout:

struct wd_param {
unsigned chainid;
unsigned long timer_count[3];
int action[3];
int signal;
} wd_param;

Each stage is configured with entries in the arrays "timer_count" and "action."

The timer_count contains the length of the interval in seconds while action contains one of the above described ACTION_* constants.

A timer_count of zero signals the end of the chain.

- WD_RESET:
This call resets the chain denoted by the unsigned integer passed to it. When reset, a chain will expire beginning with stage zero again.

- WD_UNREGISTER:
As closing the device file will not have any effect on chains, a process must unregister a chain if the service is no longer needed. This can be done with this ioctl taking an unsigned integer as a parameter denoting the chain with the same chainid to be unregistered.

Has such a framework a chance to go in mainline? What would be a good starting point to integrate it? As this "chain API" would controlled through ioctl() calls maybe drivers/watchdog/watchdog_dev.c would be a good place... or a drivers/watchdog/watchdog_chain.c which gets the ioctl calls, watchdog_dev.c couldn't parse ...

bye,
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#5 lore raw
Quoted 5 lines

A chain can request to kill the registering process if the interval elapses. In this case a restarted process can register with the driver giving the same identifier and reset the chain. This is the main reason why there is no association between chains and processes or open device files.

How do genuinely unused chains get automatically cleaned up

Quoted 3 lines

Possible chain actions:
- ACTION_SIGNAL: sends a configurable signal to the process
- ACTION_KILL: sends the SIGKILL signal to the process

These two are the same (detail)

Quoted 4 lines

starting point to integrate it? As this "chain API" would controlled through ioctl() calls maybe drivers/watchdog/watchdog_dev.c would be a good place... or a drivers/watchdog/watchdog_chain.c which gets the ioctl calls, watchdog_dev.c couldn't parse ...

It doesn't actually seem to have any connection at all with the kernel watchdog drivers. I don't mean that as a criticism but what you are describing seems to be some kind of software timer groups.

If you wanted to link it to a real watchdog presumably you'd just put the watchdog pinging user space process in a group and set it to get killed if the group triggered.

I'm not sure I understand why it can't be done cleanly in userspace either.

If you have a daemon accepting unix domain connections then it can get the pid of the other end and can kill it, or monitor incoming packets and requests from it. If that process is also the one pinging the hardware watchdog it can provide reboot protection against its own crashing. It can also do much more flexible and interesting policy things like only pinging the watchdog each time all the clients check in.

Alan