[PATCH 2/3] poller: add option to detect delayed poller activation

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Jul 1 01:52:50 PDT 2025


We already have checks that see if pollers run too long, but none to see
if poller run too late, because scheduling was disabled for a too long
period of time. Add an option that does this to aid with debugging.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/poller.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/common/poller.c b/common/poller.c
index 83f7205e5d57..18bd9c80f4b3 100644
--- a/common/poller.c
+++ b/common/poller.c
@@ -10,6 +10,7 @@
 #include <malloc.h>
 #include <module.h>
 #include <param.h>
+#include <linux/ktime.h>
 #include <poller.h>
 #include <clock.h>
 #include <linux/ktime.h>
@@ -188,19 +189,46 @@ static void poller_info(void)
 	}
 }
 
+static struct poller_async blocking_poller;
+
+static void blocking_poller_cb(void *priv)
+{
+	ktime_t diff = ktime_get() - blocking_poller.end;
+
+	if (diff < 0) {
+		pr_err("Poller watchdog activated %lluns too early!\n", diff);
+	} else if (diff > SECOND) {
+		pr_warn("Poller watchdog activated %llums too late!\n",
+			ktime_to_ms(diff));
+	}
+
+	poller_call_async(&blocking_poller, SECOND, blocking_poller_cb, NULL);
+}
+
+static void poller_blocking_time(void)
+{
+	if (blocking_poller.active)
+		return;
+
+	poller_async_register(&blocking_poller, "poller-monitor");
+	printf("Poller registered to monitor blocking time\n");
+	poller_call_async(&blocking_poller, SECOND, blocking_poller_cb, NULL);
+}
+
 BAREBOX_CMD_HELP_START(poller)
 BAREBOX_CMD_HELP_TEXT("print info about registered pollers")
 BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("Options:")
 BAREBOX_CMD_HELP_OPT ("-i", "Print information about registered pollers")
 BAREBOX_CMD_HELP_OPT ("-t", "measure how many pollers we run in 1s")
+BAREBOX_CMD_HELP_OPT ("-b", "warn if poller was blocked from running for more than 1 second")
 BAREBOX_CMD_HELP_END
 
 static int do_poller(int argc, char *argv[])
 {
 	int opt;
 
-	while ((opt = getopt(argc, argv, "it")) > 0) {
+	while ((opt = getopt(argc, argv, "itb")) > 0) {
 		switch (opt) {
 		case 'i':
 			poller_info();
@@ -208,6 +236,9 @@ static int do_poller(int argc, char *argv[])
 		case 't':
 			poller_time();
 			return 0;
+		case 'b':
+			poller_blocking_time();
+			return 0;
 		}
 	}
 
-- 
2.39.5




More information about the barebox mailing list