Skip to content

Commit

Permalink
kernel: Re-order should_preempt() checks
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
peter-mitsis authored and MaureenHelm committed Oct 21, 2024
1 parent 73d04a4 commit 0bf44f2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions kernel/include/kthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit 0bf44f2

Please sign in to comment.