Skip to content

Commit e55ac3e

Browse files
peter-mitsiskartben
authored andcommitted
kernel: Improve ordering in SMP k_thread_suspend()
The routine k_thread_suspend() has a fast path for non-SMP when suspending the current thread. When SMP is enabled, it is expected that the compiler drop the entire fast path checks because the whole expression would always evaluate to false. However, the compiler has been observed to only drop whole fast path check when the "!IS_ENABLED(CONFIG_SMP)" condition appears at the beginning of the fast path check. Signed-off-by: Peter Mitsis <[email protected]>
1 parent 01e4129 commit e55ac3e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/sched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ void z_impl_k_thread_suspend(k_tid_t thread)
453453
/* Special case "suspend the current thread" as it doesn't
454454
* need the async complexity below.
455455
*/
456-
if (thread == _current && !arch_is_in_isr() && !IS_ENABLED(CONFIG_SMP)) {
456+
if (!IS_ENABLED(CONFIG_SMP) && (thread == _current) && !arch_is_in_isr()) {
457457
k_spinlock_key_t key = k_spin_lock(&_sched_spinlock);
458458

459459
z_mark_thread_as_suspended(thread);

0 commit comments

Comments
 (0)