mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] watchdog: Print seconds to expire
Date: Thu,  4 Feb 2021 11:53:25 +0100	[thread overview]
Message-ID: <20210204105325.9970-1-s.hauer@pengutronix.de> (raw)

This adds a parameter to the watchdog devices that shows what we think
when the watchdog expires. The watchdog should reset the system once the
counter hits zero. When the system resets earlier or the counter shows
negative values then there might be problems with the watchdog. Useful
for debugging watchdog related problems.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/watchdog/wd_core.c | 29 +++++++++++++++++++++++++++++
 include/watchdog.h         |  3 +++
 2 files changed, 32 insertions(+)

diff --git a/drivers/watchdog/wd_core.c b/drivers/watchdog/wd_core.c
index 643c53268f..4b0ee31d5b 100644
--- a/drivers/watchdog/wd_core.c
+++ b/drivers/watchdog/wd_core.c
@@ -54,6 +54,9 @@ int watchdog_set_timeout(struct watchdog *wd, unsigned timeout)
 	if (ret)
 		return ret;
 
+	wd->last_ping = get_time_ns();
+	wd->timeout_cur = timeout;
+
 	wd->running = timeout ? WDOG_HW_RUNNING : WDOG_HW_NOT_RUNNING;
 
 	return 0;
@@ -155,6 +158,25 @@ static unsigned int dev_get_watchdog_priority(struct device_d *dev)
 	return priority;
 }
 
+static int seconds_to_expire_get(struct param_d *p, void *priv)
+{
+	struct watchdog *wd = priv;
+	uint64_t diff;
+
+	if (!wd->timeout_cur) {
+		wd->seconds_to_expire = -1;
+		return 0;
+	}
+
+	diff = get_time_ns() - wd->last_ping;
+
+	do_div(diff, 1000000000);
+
+	wd->seconds_to_expire = wd->timeout_cur - diff;
+
+	return 0;
+}
+
 int watchdog_register(struct watchdog *wd)
 {
 	struct param_d *p;
@@ -218,6 +240,13 @@ int watchdog_register(struct watchdog *wd)
 			goto error_unregister;
 	}
 
+	p = dev_add_param_uint32(&wd->dev, "seconds_to_expire", param_set_readonly,
+			seconds_to_expire_get, &wd->seconds_to_expire, "%d", wd);
+	if (IS_ERR(p)) {
+		ret = PTR_ERR(p);
+		goto error_unregister;
+	}
+
 	list_add_tail(&wd->list, &watchdog_list);
 
 	pr_debug("registering watchdog %s with priority %d\n", watchdog_name(wd),
diff --git a/include/watchdog.h b/include/watchdog.h
index 4d755a5a79..281885686e 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -22,8 +22,11 @@ struct watchdog {
 	struct device_d dev;
 	unsigned int priority;
 	unsigned int timeout_max;
+	unsigned int timeout_cur;
 	unsigned int poller_timeout_cur;
 	unsigned int poller_enable;
+	uint64_t last_ping;
+	int seconds_to_expire;
 	struct poller_async poller;
 	struct list_head list;
 	int running; /* enum wdog_hw_running */
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

                 reply	other threads:[~2021-02-04 10:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210204105325.9970-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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