From 66daaf6ba367ddcdc901f870f0b2111bc0dd7e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Fri, 28 Mar 2025 09:42:04 +0100 Subject: [PATCH] kernel: sched: sleep: Use value returned by z_add_timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit z_tick_sleep function needs to calculate expected wakeup tick. It required reading current system clock tick. It can be costly since it is a register access. When timeout is added this value is calculated and z_add_timeout returns it. It can be used instead to optimize sleep performance. Signed-off-by: Krzysztof Chruściński --- kernel/sched.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/kernel/sched.c b/kernel/sched.c index 35129039da4..995ded3d322 100644 --- a/kernel/sched.c +++ b/kernel/sched.c @@ -1091,19 +1091,13 @@ static int32_t z_tick_sleep(k_timeout_t timeout) return 0; } - if (Z_IS_TIMEOUT_RELATIVE(timeout)) { - expected_wakeup_ticks = timeout.ticks + sys_clock_tick_get_32(); - } else { - expected_wakeup_ticks = Z_TICK_ABS(timeout.ticks); - } - k_spinlock_key_t key = k_spin_lock(&_sched_spinlock); #if defined(CONFIG_TIMESLICING) && defined(CONFIG_SWAP_NONATOMIC) pending_current = _current; #endif /* CONFIG_TIMESLICING && CONFIG_SWAP_NONATOMIC */ unready_thread(_current); - z_add_thread_timeout(_current, timeout); + expected_wakeup_ticks = (uint32_t)z_add_thread_timeout(_current, timeout); z_mark_thread_as_sleeping(_current); (void)z_swap(&_sched_spinlock, key);