linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv4 0/2] watchdog: Introduce "early-timeout-sec" property
@ 2015-02-19  8:01 Timo Kokkonen
  2015-02-19  8:01 ` [PATCHv4 1/2] at91sam9_wdt: Allow watchdog to reset device at early boot Timo Kokkonen
  2015-02-19  8:01 ` [PATCHv4 2/2] devicetree: Document generic watchdog properties Timo Kokkonen
  0 siblings, 2 replies; 3+ messages in thread
From: Timo Kokkonen @ 2015-02-19  8:01 UTC (permalink / raw)
  To: linux-arm-kernel

Currently we have no means to adjust the watchdog behavior on early
start up before user space has opened the device. The generic behavior
among the watchdog drivers is to not start the watchdog at all (or
disable it, if possible, or in case at91sam9_wdt, start a kernel timer
that keeps on pinging the watchdog on behalf of user space until a
watchdog daemon opens it). This unfortunately opens a time window
between starting the driver and starting the user space watchdog
daemon where a crash in the kernel or user space might prevent the
watchdog from ever resetting the device at all. This is obviously bad
on production systems.

Introduce a new device tree property that, when set, changes the
watchdog driver behavior in such way that there no longer is any
window where crash is not caught by the watchdog. In atmel HW we need
to use a kernel timer to ping the watchdog for the duration of the
timeout, but that is trivial as we already have a timer there that
keeps pinging it until the watchdog device is open. The documentation
however only states how the driver should behave, not how it should be
implemented in some other watchdog hardware.

Patch revision history:

-v4: Binding documentation is now separated completely from the driver
  patch. The documentation no longer makes any assumptions about how
  the actual implementation is made, it just describes the actual
  behavior the driver should implement in order to satisfy the
  requirement.

- v3: Rename the property to "early-timeout-sec" and use it as a
  timeout value that stops the timer in the atmel driver after the
  timeout expires. A watchdog.txt is also introduced for documenting
  the common watchdog properties, including now this one and
  "timeout-sec" property.

- v2: Rename the property to "enable-early-reset" as the behavior
  itself is not atmel specific. This way other drivers are free to
  implement same behavior with the same property name.

- v1: Propose property name "atmle,no-early-timer" for disabling the
  timer that keeps the atmel watchdog running until user space opens
  the device.


Timo Kokkonen (2):
  at91sam9_wdt: Allow watchdog to reset device at early boot
  devicetree: Document generic watchdog properties

 .../devicetree/bindings/watchdog/watchdog.txt        | 20 ++++++++++++++++++++
 drivers/watchdog/at91sam9_wdt.c                      |  9 ++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/watchdog/watchdog.txt

-- 
2.1.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCHv4 1/2] at91sam9_wdt: Allow watchdog to reset device at early boot
  2015-02-19  8:01 [PATCHv4 0/2] watchdog: Introduce "early-timeout-sec" property Timo Kokkonen
@ 2015-02-19  8:01 ` Timo Kokkonen
  2015-02-19  8:01 ` [PATCHv4 2/2] devicetree: Document generic watchdog properties Timo Kokkonen
  1 sibling, 0 replies; 3+ messages in thread
From: Timo Kokkonen @ 2015-02-19  8:01 UTC (permalink / raw)
  To: linux-arm-kernel

By default the driver will start a kernel timer which keeps on kicking
the watchdog HW until user space has opened the watchdog
device. Usually this is desirable as the watchdog HW is running by
default and the user space may not have any watchdog daemon running at
all.

However, on production systems it may be mandatory that also early
crashes and lockups will lead to a watchdog reset, even if they happen
before the user space has opened the watchdog device.

To resolve the issue, add a new device tree property
"early-timeout-sec" which will let the kernel timer to ping the
watchdog HW only as long as the specified timeout permits. The default
is still to use kernel timer, but more strict behavior can be enabled
via the device tree property.

Signed-off-by: Timo Kokkonen <timo.kokkonen@offcode.fi>
---
 drivers/watchdog/at91sam9_wdt.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c
index 6df9405..1b40bfa 100644
--- a/drivers/watchdog/at91sam9_wdt.c
+++ b/drivers/watchdog/at91sam9_wdt.c
@@ -89,6 +89,8 @@ struct at91wdt {
 	u32 mr_mask;
 	unsigned long heartbeat;	/* WDT heartbeat in jiffies */
 	bool nowayout;
+	/* Timeout in jiffies for stopping the early timer */
+	unsigned long early_timer;
 	unsigned int irq;
 };
 
@@ -122,7 +124,8 @@ static void at91_ping(unsigned long data)
 {
 	struct at91wdt *wdt = (struct at91wdt *)data;
 	if (time_before(jiffies, wdt->next_heartbeat) ||
-	    !watchdog_active(&wdt->wdd)) {
+		(time_before(jiffies, wdt->early_timer) &&
+			!watchdog_active(&wdt->wdd))) {
 		at91_wdt_reset(wdt);
 		mod_timer(&wdt->timer, jiffies + wdt->heartbeat);
 	} else {
@@ -316,6 +319,10 @@ static int of_at91wdt_init(struct device_node *np, struct at91wdt *wdt)
 
 	wdt->mr |= max | ((max - min) << 16);
 
+	if (!of_property_read_u32_index(np, "early-timeout-sec", 0,
+					(u32 *)&wdt->early_timer))
+		wdt->early_timer = wdt->early_timer * HZ + jiffies;
+
 	return 0;
 }
 #else
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCHv4 2/2] devicetree: Document generic watchdog properties
  2015-02-19  8:01 [PATCHv4 0/2] watchdog: Introduce "early-timeout-sec" property Timo Kokkonen
  2015-02-19  8:01 ` [PATCHv4 1/2] at91sam9_wdt: Allow watchdog to reset device at early boot Timo Kokkonen
@ 2015-02-19  8:01 ` Timo Kokkonen
  1 sibling, 0 replies; 3+ messages in thread
From: Timo Kokkonen @ 2015-02-19  8:01 UTC (permalink / raw)
  To: linux-arm-kernel

There is no documentation for the watchdog properties that are common
among most of the watchdog drivers. Add document where these generic
properties can be described and told how they should be used in
drivers.

Signed-off-by: Timo Kokkonen <timo.kokkonen@offcode.fi>
---
 .../devicetree/bindings/watchdog/watchdog.txt        | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/watchdog/watchdog.txt

diff --git a/Documentation/devicetree/bindings/watchdog/watchdog.txt b/Documentation/devicetree/bindings/watchdog/watchdog.txt
new file mode 100644
index 0000000..3781406
--- /dev/null
+++ b/Documentation/devicetree/bindings/watchdog/watchdog.txt
@@ -0,0 +1,20 @@
+These properties are common among most watchdog drivers. Any driver
+that requires the functionality listed below should implement them
+using these definitions.
+
+Optional properties:
+- timeout-sec: Contains the watchdog timeout in seconds.
+- early-timeout-sec: If present, specify the timeout in seconds for
+  how long it can take for the watchdog daemon to take over the
+  watchdog device. If driver supports this property it must ensure the
+  watchdog hardware is running during this period and a watchdog reset
+  must occur if user space fails to open the device in time. If left
+  zero, the driver only needs to guarantee the watchdog is not
+  stopped or is started during driver init.
+
+Example:
+
+watchdog {
+	 timeout-sec = <60>;
+	 early-timeout-sec = <120>;
+};
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-19  8:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-19  8:01 [PATCHv4 0/2] watchdog: Introduce "early-timeout-sec" property Timo Kokkonen
2015-02-19  8:01 ` [PATCHv4 1/2] at91sam9_wdt: Allow watchdog to reset device at early boot Timo Kokkonen
2015-02-19  8:01 ` [PATCHv4 2/2] devicetree: Document generic watchdog properties Timo Kokkonen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).