sys/ztimer: fix re-scheduling of timers #20924
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contribution description
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 insideztimer_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 ofztimer_set()
.This is a fix we might consider back porting. As far as I can tell this bug has always existed in
ztimer
.Testing procedure
make -C examples/hello-world/ all term
Testbench patch
Sample of testbench's expected (good) behavior
Sample of testbench's behavior without this fix
Issues/PRs references
This bug is possible the cause of the early timeout worked around in this #19965. Perhaps that workaround could be removed?