kernel: Re-order should_preempt() checks

Re-orders the checks in should_preempt() tests so that the
z_is_thread_timeout_active() check is done last.

This change has been observed to give a +7% performance boost on
the thread_metric benchmark's preemptive scheduling test.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
This commit is contained in:
Peter Mitsis 2024-10-16 11:32:28 -07:00 committed by Maureen Helm
commit 0bf44f2352

View file

@ -204,6 +204,13 @@ static ALWAYS_INLINE bool should_preempt(struct k_thread *thread,
return true;
}
/* Otherwise we have to be running a preemptible thread or
* switching to a metairq
*/
if (thread_is_preemptible(_current) || thread_is_metairq(thread)) {
return true;
}
/* Edge case on ARM where a thread can be pended out of an
* interrupt handler before the "synchronous" swap starts
* context switching. Platforms with atomic swap can never
@ -214,13 +221,6 @@ static ALWAYS_INLINE bool should_preempt(struct k_thread *thread,
return true;
}
/* Otherwise we have to be running a preemptible thread or
* switching to a metairq
*/
if (thread_is_preemptible(_current) || thread_is_metairq(thread)) {
return true;
}
return false;
}