kernel: Always set clock expiry with sync with timeout module
System must not set the clock expiry via backdoor as it may
effect in unbound time drift of all scheduled timeouts.
Fixes: #11502
Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
diff --git a/kernel/timeout.c b/kernel/timeout.c
index f97076b..4ffae50 100644
--- a/kernel/timeout.c
+++ b/kernel/timeout.c
@@ -85,7 +85,9 @@
sys_dlist_append(&timeout_list, &to->node);
}
- z_clock_set_timeout(_get_next_timeout_expiry(), false);
+ if (to == first()) {
+ z_clock_set_timeout(_get_next_timeout_expiry(), false);
+ }
}
}
@@ -182,6 +184,17 @@
return ret;
}
+void z_set_timeout_expiry(s32_t ticks, bool idle)
+{
+ LOCKED(&timeout_lock) {
+ int next = _get_next_timeout_expiry();
+
+ if ((next == K_FOREVER) || (ticks < next)) {
+ z_clock_set_timeout(ticks, idle);
+ }
+ }
+}
+
int k_enable_sys_clock_always_on(void)
{
int ret = !can_wait_forever;