mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] poller: report pollers taking more than 20 milliseconds
Date: Thu,  2 May 2024 17:14:30 +0200	[thread overview]
Message-ID: <20240502151430.3963160-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240502151430.3963160-1-a.fatoum@pengutronix.de>

Pollers are meant to be running for a short duration. A poller that runs
longer than 20 milliseconds probably deserves a closer look.

Let's print a one time warning in this case and have the poller command
output report how many times the condition occurred.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/poller.c  | 35 ++++++++++++++++++++++++++++++++---
 include/poller.h |  3 ++-
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/common/poller.c b/common/poller.c
index 0409d3cf8111..77d93ae8ccdf 100644
--- a/common/poller.c
+++ b/common/poller.c
@@ -3,6 +3,8 @@
  * Copyright (C) 2010 Marc Kleine-Budde <mkl@pengutronix.de>
  */
 
+#define pr_fmt(fmt) "poller: " fmt
+
 #include <common.h>
 #include <driver.h>
 #include <malloc.h>
@@ -10,6 +12,13 @@
 #include <param.h>
 #include <poller.h>
 #include <clock.h>
+#include <linux/ktime.h>
+
+/*
+ * Pollers are meant to poll and quickly execute actions.
+ * Exceeding the maximum runtime below triggers a one-time warning.
+ */
+#define POLLER_MAX_RUNTIME_MS	20
 
 static LIST_HEAD(poller_list);
 static int __poller_active;
@@ -116,9 +125,23 @@ void poller_call(void)
 
 	__poller_active = 1;
 
-	list_for_each_entry_safe(poller, tmp, &poller_list, list)
+	list_for_each_entry_safe(poller, tmp, &poller_list, list) {
+		ktime_t start = ktime_get();
+		s64 duration_ms;
+
 		poller->func(poller);
 
+		duration_ms = ktime_ms_delta(ktime_get(), start);
+		if (duration_ms > POLLER_MAX_RUNTIME_MS) {
+			if (!poller->overtime)
+				pr_warn("'%s' took unexpectedly long: %llums\n",
+					poller->name, duration_ms);
+
+			if (poller->overtime < U16_MAX)
+				poller->overtime++;
+		}
+	}
+
 	__poller_active = 0;
 }
 
@@ -155,8 +178,14 @@ static void poller_info(void)
 		return;
 	}
 
-	list_for_each_entry(poller, &poller_list, list)
-		printf("%s\n", poller->name);
+	list_for_each_entry(poller, &poller_list, list) {
+		printf("%s", poller->name);
+		if (poller->overtime)
+			printf(": overtime %s%u",
+			       poller->overtime == U16_MAX ? ">= " : "",
+			       poller->overtime);
+		printf("\n");
+	}
 }
 
 BAREBOX_CMD_HELP_START(poller)
diff --git a/include/poller.h b/include/poller.h
index 6e51a0613356..31db907ba5b8 100644
--- a/include/poller.h
+++ b/include/poller.h
@@ -11,7 +11,8 @@
 
 struct poller_struct {
 	void (*func)(struct poller_struct *poller);
-	int registered;
+	u16 registered:1;
+	u16 overtime;
 	struct list_head list;
 	char *name;
 };
-- 
2.39.2




  reply	other threads:[~2024-05-02 15:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 15:14 [PATCH 1/2] include: ktime: implement __ktime_divns for 32-bit systems Ahmad Fatoum
2024-05-02 15:14 ` Ahmad Fatoum [this message]
2024-05-03  6:53 ` Sascha Hauer

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=20240502151430.3963160-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@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