From 45942f6821c4cc4fa0e563592320cfc2b6b74ddb Mon Sep 17 00:00:00 2001 From: Joshua DeWeese Date: Fri, 18 Oct 2024 14:52:11 -0400 Subject: [PATCH] sys/ztimer: fix re-scheduling of timers If the timer at the head of a ztimer clock's timer list is re-scheduled (ztimer_set() called on an already set timer) and the timer is no longer at the head after being re-scheduled, clock-ops->set() is never called from inside ztimer_set(), and the underlying timer is left with an ISR scheduled to expire at the timer's old time. The intended behavior is that the clock's lower level timer should always be set to expire at the time of the clocks head timer. This patch changes ztimer_set() to call _ztimer_update(), which sets the lower level timer according to the current list of timers, rather than setting the timer directly inside of ztimer_set(). --- sys/ztimer/core.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/sys/ztimer/core.c b/sys/ztimer/core.c index dbf01c83b2ce..befa2266c3c4 100644 --- a/sys/ztimer/core.c +++ b/sys/ztimer/core.c @@ -193,15 +193,7 @@ uint32_t ztimer_set(ztimer_clock_t *clock, ztimer_t *timer, uint32_t val) timer->base.offset = val; _add_entry_to_list(clock, &timer->base); - if (clock->list.next == &timer->base) { -#ifdef MODULE_ZTIMER_EXTEND - if (clock->max_value < UINT32_MAX) { - val = _min_u32(val, clock->max_value >> 1); - } - DEBUG("ztimer_set(): %p setting %" PRIu32 "\n", (void *)clock, val); -#endif - clock->ops->set(clock, val); - } + _ztimer_update(clock); irq_restore(state);