Commit 66daaf6b authored by Krzysztof Chruściński's avatar Krzysztof Chruściński Committed by Benjamin Cabé
Browse files

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: default avatarKrzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
parent 5f55fed4
Loading
Loading
Loading
Loading
+1 −7
Changes for kernel/sched.c: 1 added line, 7 removed lines.
Original line number Diff line number Diff line
@@ -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);