[PATCH 2/2] poller: report pollers taking more than 20 milliseconds
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu May 2 08:14:30 PDT 2024
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 at 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 at 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
More information about the barebox
mailing list