Skip to content

Commit 66daaf6

Browse files
nordic-krchkartben
authored andcommitted
kernel: sched: sleep: Use value returned by z_add_timeout
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 <krzysztof.chruscinski@nordicsemi.no>
1 parent 5f55fed commit 66daaf6

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

kernel/sched.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,19 +1091,13 @@ static int32_t z_tick_sleep(k_timeout_t timeout)
10911091
return 0;
10921092
}
10931093

1094-
if (Z_IS_TIMEOUT_RELATIVE(timeout)) {
1095-
expected_wakeup_ticks = timeout.ticks + sys_clock_tick_get_32();
1096-
} else {
1097-
expected_wakeup_ticks = Z_TICK_ABS(timeout.ticks);
1098-
}
1099-
11001094
k_spinlock_key_t key = k_spin_lock(&_sched_spinlock);
11011095

11021096
#if defined(CONFIG_TIMESLICING) && defined(CONFIG_SWAP_NONATOMIC)
11031097
pending_current = _current;
11041098
#endif /* CONFIG_TIMESLICING && CONFIG_SWAP_NONATOMIC */
11051099
unready_thread(_current);
1106-
z_add_thread_timeout(_current, timeout);
1100+
expected_wakeup_ticks = (uint32_t)z_add_thread_timeout(_current, timeout);
11071101
z_mark_thread_as_sleeping(_current);
11081102

11091103
(void)z_swap(&_sched_spinlock, key);

0 commit comments

Comments
 (0)