Browse Source

kernel: timeout: Optimize setting next alarm

Next timeout was set unconditionally at the end of sys_clock_announce.
However, if one of the current expired timeouts was setting a new
timeout which is the first to execute then system clock was configured
twice. Lets configure system clock only once in the isr at the and of
sys_clock_announce.

If timeouts are frequent this optimization can reduce CPU load. In
many cases setting the new sys_clock timeout is the most time
consuming operation in the sys_clock isr handler. As an example,
on the target I used setting new sys_clock timeout is taking 6 uS of
9 uS spent in the isr and it takes 16 uS with the redundant call.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
pull/71283/head
Krzysztof Chruściński 1 year ago committed by Anas Nashif
parent
commit
aee8dd1d33
  1. 2
      kernel/timeout.c

2
kernel/timeout.c

@ -135,7 +135,7 @@ void z_add_timeout(struct _timeout *to, _timeout_func_t fn, @@ -135,7 +135,7 @@ void z_add_timeout(struct _timeout *to, _timeout_func_t fn,
sys_dlist_append(&timeout_list, &to->node);
}
if (to == first()) {
if (to == first() && announce_remaining == 0) {
sys_clock_set_timeout(next_timeout(), false);
}
}

Loading…
Cancel
Save