Browse Source

kernel/timeout: Fix timeout "sooner" computation

There was an edge case in the timeout handling (exposed by, but not
strictly related to, the recent timeslice fix): the next_timeout()
computation would include time slice expiration as a clamp on the
result, but this would be invoked also on the z_set_timeout_expiry()
path which gets hooked on entry to a new thread which is needed to set
the timeout in the first place.  So if no other timer interrupt was
scheduled, it was possible to miss the first timeslice interrupt after
thread scheduling.

The explanation is much longer than the fix (use <= as the comparator
instead of <).

In practice this was only being hit in the existing test suite on
riscv miv running under renode using non-default clock rates.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
pull/31792/head
Andy Ross 4 years ago committed by Anas Nashif
parent
commit
887e1abace
  1. 2
      kernel/timeout.c

2
kernel/timeout.c

@ -215,7 +215,7 @@ void z_set_timeout_expiry(int32_t ticks, bool is_idle)
LOCKED(&timeout_lock) { LOCKED(&timeout_lock) {
int next_to = next_timeout(); int next_to = next_timeout();
bool sooner = (next_to == K_TICKS_FOREVER) bool sooner = (next_to == K_TICKS_FOREVER)
|| (ticks < next_to); || (ticks <= next_to);
bool imminent = next_to <= 1; bool imminent = next_to <= 1;
/* Only set new timeouts when they are sooner than /* Only set new timeouts when they are sooner than

Loading…
Cancel
Save