From 6a153efc1b1bba0b8f2ba3869a1e478b6fcf3c0e Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Mon, 19 Aug 2019 21:40:01 -0700 Subject: [PATCH] kernel/timeout: Fix timeslicing edge case in SMP The timeout code has an optimization where it refuses to send a new timeout to the driver unless it is sooner than one already scheduled. This won't work on SMP, though, because the timeout value when timeslicing is enabled depends on the current thread, and on SMP the decision as to the next thread will not be made until later (when we swap, or exit an interrupt). Signed-off-by: Andy Ross --- kernel/timeout.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/timeout.c b/kernel/timeout.c index ede4c4e8f91..12e4c48483a 100644 --- a/kernel/timeout.c +++ b/kernel/timeout.c @@ -168,8 +168,12 @@ void z_set_timeout_expiry(s32_t ticks, bool idle) * one is about to expire: drivers have internal logic * that will bump the timeout to the "next" tick if * it's not considered to be settable as directed. + * SMP can't use this optimization though: we don't + * know when context switches happen until interrupt + * exit and so can't get the timeslicing clamp folded + * in. */ - if (sooner && !imminent) { + if (!imminent && (sooner || IS_ENABLED(CONFIG_SMP))) { z_clock_set_timeout(ticks, idle); } }