[PATCH 2/2] cyclic: parse cyclic list only if next cyclic timestamp is reached
Patrice CHOTARD
patrice.chotard at foss.st.com
Fri Jul 3 11:55:12 CEST 2026
On 7/3/26 00:10, Marek Vasut wrote:
> On 7/2/26 5:24 PM, Patrice Chotard wrote:
>> 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 | 12 ++++++++++++
>> include/asm-generic/global_data.h | 4 ++++
>> 2 files changed, 16 insertions(+)
>>
>> diff --git a/common/cyclic.c b/common/cyclic.c
>> index b37cd6d8ff0..714d6863d5b 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,13 @@ static void cyclic_run(void)
>> cyclic->already_warned = true;
>> }
>> }
>> + if (next_call > cyclic->next_call)
>> + next_call = cyclic->next_call;
>
> Can you move this entry to the beginning of the cyclic list, so that the entry with the earliest deadline would be right at the beginning of the list ? That should squeeze some more improvement out of this I think.
Hi Marek
I did a test, it doesn't bring any noticeable improvements, but nevertheless i will submit a v3 with this update.
>
>> }
>> +
>> + if (next_call != UINT64_MAX)
>
> Can the next_call literally hit UINT64_MAX in that one unlikely case ?
> You likely do need a separate flag, bool next_call_valid, to avoid that edge case.
In case, no cyclic has been registered, we don't parse the cyclic list and next_call stays set to UINT64_MAX
We don't want that next_cyclic_call be set to UINT64_MAX, otherwise in that case, we will always exit cyclic_run() before parsing cyclic list.
Patrice
>
>> + gd->next_cyclic_call = next_call;
>> +
>> gd->flags &= ~GD_FLG_CYCLIC_RUNNING;
>> }
> Thank you !
More information about the U-Boot
mailing list