[PATCH v2 2/2] cyclic: parse cyclic list only if next cyclic timestamp is reached
Patrice Chotard
patrice.chotard at foss.st.com
Fri Jul 3 12:12:45 CEST 2026
On STM32MP157C-DK2, when using the "ums" command, in sleep_thread(),
ctrlc() is called every ~640ms which doesn't allows high reactivity when
user press CTRL+C in U-Boot console.
In sleep_thread() loop, ctrlc() is called every 200000 iterations.
But schedule is called on each loop iteration.
Optimize cyclic_run() in order to parse the cyclic list only is the
next cyclic to run is due.
During cyclic list parsing, save the nearest cyclic timestamp, which
allows to exit from next cyclic_run() call if no cyclic will be executed.
This allow to save computation time :
_ before : ctrlc() is called every ~640ms
_ after : ctrlc() is called every ~230ms
Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
Cc: Marek Vasut <marek.vasut at mailbox.org>
---
common/cyclic.c | 16 ++++++++++++++++
include/asm-generic/global_data.h | 4 ++++
2 files changed, 20 insertions(+)
diff --git a/common/cyclic.c b/common/cyclic.c
index b37cd6d8ff0..10ea0711ba1 100644
--- a/common/cyclic.c
+++ b/common/cyclic.c
@@ -68,11 +68,17 @@ static void cyclic_run(void)
struct cyclic_info *cyclic;
struct hlist_node *tmp;
u64 now, cpu_time;
+ u64 next_call = UINT64_MAX;
/* Prevent recursion */
if (gd->flags & GD_FLG_CYCLIC_RUNNING)
return;
+ /* check if the next cyclic function's timestamp is reached */
+ now = get_timer_us(0);
+ if (time_after_eq64(gd->next_cyclic_call, now))
+ return;
+
gd->flags |= GD_FLG_CYCLIC_RUNNING;
hlist_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
/*
@@ -102,7 +108,17 @@ static void cyclic_run(void)
cyclic->already_warned = true;
}
}
+ if (next_call > cyclic->next_call) {
+ next_call = cyclic->next_call;
+ /* move this cyclic to list's head */
+ hlist_del(&cyclic->list);
+ hlist_add_head(&cyclic->list, cyclic_get_list());
+ }
}
+
+ if (next_call != UINT64_MAX)
+ gd->next_cyclic_call = next_call;
+
gd->flags &= ~GD_FLG_CYCLIC_RUNNING;
}
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 745d2c3a966..25e488d7020 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -441,6 +441,10 @@ struct global_data {
* @cyclic_list: list of registered cyclic functions
*/
struct hlist_head cyclic_list;
+ /**
+ * @next_cyclic_call: timestamp of next cyclic call
+ */
+ u64 next_cyclic_call;
#endif
#if CONFIG_IS_ENABLED(UPL)
/**
--
2.43.0
More information about the U-Boot
mailing list