Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/ztimer: fix re-scheduling of timers #20924

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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().
Enoch247 committed Oct 18, 2024
commit 45942f6821c4cc4fa0e563592320cfc2b6b74ddb
10 changes: 1 addition & 9 deletions sys/ztimer/core.c
Original file line number Diff line number Diff line change
@@ -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);

Loading
Oops, something went wrong.