cyclic: reduce get_timer_us() calls inside hlist_for_each_entry_safe()

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 not call get_timer_us() on each entry.

This allow to save computation time :
  _ before : ctrlc() is called every ~640ms
  _ after  : ctrlc() is called every ~230ms

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
Signed-off-by: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Marek Vasut <marek.vasut@mailbox.org>
This commit is contained in:
Patrice Chotard
2026-07-16 16:11:19 -06:00
committed by Tom Rini
parent 08af4faa0f
commit 9c1b13b3fd
+5 -3
View File
@@ -67,26 +67,28 @@ static void cyclic_run(void)
{
struct cyclic_info *cyclic;
struct hlist_node *tmp;
u64 now, cpu_time;
u64 now, after, cpu_time;
/* Prevent recursion */
if (gd->flags & GD_FLG_CYCLIC_RUNNING)
return;
gd->flags |= GD_FLG_CYCLIC_RUNNING;
now = get_timer_us(0);
hlist_for_each_entry_safe(cyclic, tmp, cyclic_get_list(), list) {
/*
* Check if this cyclic function needs to get called, e.g.
* do not call the cyclic func too often
*/
now = get_timer_us(0);
if (time_after_eq64(now, cyclic->next_call)) {
/* Call cyclic function and account it's cpu-time */
cyclic->next_call = now + cyclic->delay_us;
cyclic->func(cyclic);
after = get_timer_us(0);
cyclic->run_cnt++;
cpu_time = get_timer_us(0) - now;
cpu_time = after - now;
cyclic->cpu_time_us += cpu_time;
now = after;
/* Check if cpu-time exceeds max allowed time */
if ((cpu_time > CONFIG_CYCLIC_MAX_CPU_TIME_US) &&