[PATCH 1/2] cyclic: Fix rollover every 72 min on 32 bits platforms
Alexander Dahl
ada at thorsis.com
Thu Jan 9 08:56:27 CET 2025
Hello Patrice,
Am Wed, Jan 08, 2025 at 04:09:39PM +0100 schrieb Patrice Chotard:
> On 32 bits platforms, timer_get_us() returns an unsigned long which
> is a 32 bits. timer_get_us() wraps around every 72 minutes
> (2 ^ 32 / 1000000 =~ 4295 sec =~ 72 min).
>
> So the test "if time_after_eq64(now, cyclic->next_call)" is no more
> true when cyclic->next_call becomes above 32 bits max value (4294967295).
>
> At this point after 72 min, no more cyclic function are
> executed included watchdog one.
>
> Instead of using timer_get_us(), use get_timer_us() which returns a
> uint64_t, this allows a rollover every 584942 years.
This should be long enough. ;-)
>
> Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
> ---
>
> common/cyclic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/common/cyclic.c b/common/cyclic.c
> index 196797fd61e..e3f03a19d55 100644
> --- a/common/cyclic.c
> +++ b/common/cyclic.c
> @@ -61,7 +61,7 @@ static void cyclic_run(void)
> * Check if this cyclic function needs to get called, e.g.
> * do not call the cyclic func too often
> */
> - now = timer_get_us();
> + now = get_timer_us(0);
Acked-by: Alexander Dahl <ada at thorsis.com>
Greets
Alex
> if (time_after_eq64(now, cyclic->next_call)) {
> /* Call cyclic function and account it's cpu-time */
> cyclic->next_call = now + cyclic->delay_us;
> --
> 2.25.1
>
More information about the U-Boot
mailing list