public inbox for cip-dev@lists.cip-project.org
 help / color / mirror / Atom feed
From: mosipov@ilbers.de (Maxim Yu. Osipov)
To: cip-dev@lists.cip-project.org
Subject: [cip-dev] [PATCH 07/10] watchdog: change watchdog_need_worker logic
Date: Fri, 10 Nov 2017 13:10:01 +0100	[thread overview]
Message-ID: <20171110121004.17775-8-mosipov@ilbers.de> (raw)
In-Reply-To: <20171110121004.17775-1-mosipov@ilbers.de>

From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

commit 3fbfe9264756d3fd99a9210345016c94ec4ada73 upstream.

If the driver indicates that the watchdog is running, the framework
should feed it until userspace opens the device, regardless of whether
the driver has set max_hw_heartbeat_ms.

This patch only affects the case where wdd->max_hw_heartbeat_ms is
zero, wdd->timeout is non-zero, the watchdog is not active and the
hardware device is running (*):

- If wdd->timeout is zero, watchdog_need_worker() returns false both
before and after this patch, and watchdog_next_keepalive() is not
called.

- If watchdog_active(wdd), the return value from watchdog_need_worker
is also the same as before (namely, hm && t > hm). Hence in that case,
watchdog_next_keepalive() is only called if hm == max_hw_heartbeat_ms
is non-zero, so the change to min_not_zero there is a no-op.

- If the watchdog is not active and the device is not running, we
return false from watchdog_need_worker just as before.

That leaves the watchdog_hw_running(wdd) && !watchdog_active(wdd) &&
wdd->timeout case. Again, it's easy to see that if
wdd->max_hw_heartbeat_ms is non-zero, we return true from
watchdog_need_worker with and without this patch, and the logic in
watchdog_next_keepalive is unchanged. Finally, if
wdd->max_hw_heartbeat_ms is 0, we used to end up in the
cancel_delayed_work branch, whereas with this patch we end up
scheduling a ping timeout_ms/2 from now.

(*) This should imply that no current kernel drivers are affected,
since the only drivers which explicitly set WDOG_HW_RUNNING are
imx2_wdt.c and dw_wdt.c, both of which also provide a non-zero value
for max_hw_heartbeat_ms. The watchdog core also sets WDOG_HW_RUNNING,
but only when the driver doesn't provide ->stop, in which case it
must, according to Documentation/watchdog/watchdog-kernel-api.txt, set
max_hw_heartbeat_ms.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
[mosipov at ilbers.de backported to 4.4.y]
Signed-off-by: Maxim Yu. Osipov <mosipov@ilbers.de>
---
 drivers/watchdog/watchdog_dev.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/watchdog/watchdog_dev.c b/drivers/watchdog/watchdog_dev.c
index e98e4294ec92..2a204bb56705 100644
--- a/drivers/watchdog/watchdog_dev.c
+++ b/drivers/watchdog/watchdog_dev.c
@@ -67,9 +67,13 @@ static inline bool watchdog_need_worker(struct watchdog_device *wdd)
 	 *   thus is aware that the framework supports generating heartbeat
 	 *   requests.
 	 * - Userspace requests a longer timeout than the hardware can handle.
+	 *
+	 * Alternatively, if userspace has not opened the watchdog
+	 * device, we take care of feeding the watchdog if it is
+	 * running.
 	 */
-	return hm && ((watchdog_active(wdd) && t > hm) ||
-		      (t && !watchdog_active(wdd) && watchdog_hw_running(wdd)));
+	return (hm && watchdog_active(wdd) && t > hm) ||
+		(t && !watchdog_active(wdd) && watchdog_hw_running(wdd));
 }
 
 static long watchdog_next_keepalive(struct watchdog_device *wdd)
@@ -81,7 +85,7 @@ static long watchdog_next_keepalive(struct watchdog_device *wdd)
 	unsigned int hw_heartbeat_ms;
 
 	virt_timeout = wdd->last_keepalive + msecs_to_jiffies(timeout_ms);
-	hw_heartbeat_ms = min(timeout_ms, wdd->max_hw_heartbeat_ms);
+	hw_heartbeat_ms = min_not_zero(timeout_ms, wdd->max_hw_heartbeat_ms);
 	keepalive_interval = msecs_to_jiffies(hw_heartbeat_ms / 2);
 
 	if (!watchdog_active(wdd))
-- 
2.11.0

  parent reply	other threads:[~2017-11-10 12:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 12:09 [cip-dev] [PATCH 00/10] Backport of watchdog core triggered keepalive infrastructure v2 Maxim Yu. Osipov
2017-11-10 12:09 ` [cip-dev] [PATCH 01/10] watchdog: Introduce hardware maximum heartbeat in watchdog core Maxim Yu. Osipov
2017-11-10 12:09 ` [cip-dev] [PATCH 02/10] watchdog: Introduce WDOG_HW_RUNNING flag Maxim Yu. Osipov
2017-11-10 12:09 ` [cip-dev] [PATCH 03/10] watchdog: Make stop function optional Maxim Yu. Osipov
2017-11-10 12:09 ` [cip-dev] [PATCH 04/10] watchdog: imx2: Convert to use infrastructure triggered keepalives Maxim Yu. Osipov
2017-11-10 12:09 ` [cip-dev] [PATCH 05/10] watchdog: core: Fix circular locking dependency Maxim Yu. Osipov
2017-11-10 12:10 ` [cip-dev] [PATCH 06/10] watchdog: skip min and max timeout validity check when max_hw_heartbeat_ms is defined Maxim Yu. Osipov
2017-11-10 12:10 ` Maxim Yu. Osipov [this message]
2017-11-10 12:10 ` [cip-dev] [PATCH 08/10] watchdog: core: Fix error handling of watchdog_dev_init() Maxim Yu. Osipov
2017-11-10 12:10 ` [cip-dev] [PATCH 09/10] watchdog: core: Clear WDOG_HW_RUNNING before calling the stop function Maxim Yu. Osipov
2017-11-10 12:10 ` [cip-dev] [PATCH 10/10] watchdog: core: add option to avoid early handling of watchdog Maxim Yu. Osipov
2017-11-15 15:22 ` [cip-dev] [PATCH 00/10] Backport of watchdog core triggered keepalive infrastructure v2 Ben Hutchings
  -- strict thread matches above, loose matches on Subject: below --
2017-10-04 14:40 [cip-dev] [PATCH 00/10] Backport of watchdog core triggered keepalive infrastructure Maxim Yu. Osipov
2017-10-04 14:41 ` [cip-dev] [PATCH 07/10] watchdog: change watchdog_need_worker logic Maxim Yu. Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171110121004.17775-8-mosipov@ilbers.de \
    --to=mosipov@ilbers.de \
    --cc=cip-dev@lists.cip-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox