You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kernel: timeout: avoid premature adjustment of timeout
The existing loop over timeouts in z_clock_announce adjusts the delay of
the first timeout that has not been expired by the number of ticks
remaining. This adjustment is (by some interpretations) incorrect when
the timeout was added while processing a previous timeout and the
adjustment is not zero, which can happen if multiple ticks are announced
in one call.
Resolve this by changing how the tick clock is managed:
* curr_ticks/k_uptime_get() is adjusted as soon as the
z_clock_announce() is invoked. This means that timer callbacks are
able to observe the best available estimate of the current time,
rather than the time at which each callback was supposed to be
invoked. The new policy also ensures that k_uptime_get() is
consistent with k_cycle_get().
* Prior to invoking any callbacks the sequence of expired timeouts is
removed from the timeout queue, ensuring new timeouts are scheduled
without the risk of inadvertently reducing their delay by unprocessed
ticks.
* Prior to a callback the timeout dticks field is updated to be relative
to the current time, i.e. a non-positive value corresponding to how
late the timeout was invoked.
* The tick offset used when scheduling a recurring timeout is adjusted
by the lateness of the invocation, ensuring that the expected callback
times are at a fixed interval even if individual callbacks are late.
* The dticks field is zeroed when a timer is initialized, aborted,
started, or stopped, ensuring that non-recurring timeouts respect the
offset passed as the initial duration.
The new policy also enables a future enhancement where each k_timer can
be configured to select between policies where repeating timeouts should
be relative to the scheduled time of the last callback (historical
behavior) or the actual time of the last callback (useful for certain
cases).
Closes#12332.
Signed-off-by: Peter A. Bigot <[email protected]>
0 commit comments