[PATCH] sched_ext: add unlikely() hints in do_enqueue_task() hot path

David Carlier posted 1 patch 1 month, 1 week ago
kernel/sched/ext.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] sched_ext: add unlikely() hints in do_enqueue_task() hot path
Posted by David Carlier 1 month, 1 week ago
Add unlikely() branch hints to the scx_rq_online() and
scx_rq_bypassing() checks in do_enqueue_task() that are rarely taken
during normal operation.

The PF_EXITING and migration_disabled checks are left unchanged as the
existing code already places unlikely() precisely on the runtime
condition.

Signed-off-by: David Carlier <devnexen@gmail.com>
---
 kernel/sched/ext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
index c18e81e8ef51..9a888ce5e2f1 100644
--- a/kernel/sched/ext.c
+++ b/kernel/sched/ext.c
@@ -1360,10 +1360,10 @@ static void do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags,
 	 * is offline and are just running the hotplug path. Don't bother the
 	 * BPF scheduler.
 	 */
-	if (!scx_rq_online(rq))
+	if (unlikely(!scx_rq_online(rq)))
 		goto local;
 
-	if (scx_rq_bypassing(rq)) {
+	if (unlikely(scx_rq_bypassing(rq))) {
 		__scx_add_event(sch, SCX_EV_BYPASS_DISPATCH, 1);
 		goto bypass;
 	}
-- 
2.51.0
Re: [PATCH] sched_ext: add unlikely() hints in do_enqueue_task() hot path
Posted by Tejun Heo 1 month, 1 week ago
Hello,

On Thu, Feb 26, 2026 at 10:44:25PM +0000, David Carlier wrote:
> @@ -1360,10 +1360,10 @@ static void do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags,
>  	 * is offline and are just running the hotplug path. Don't bother the
>  	 * BPF scheduler.
>  	 */
> -	if (!scx_rq_online(rq))
> +	if (unlikely(!scx_rq_online(rq)))
>  		goto local;
>  
> -	if (scx_rq_bypassing(rq)) {
> +	if (unlikely(scx_rq_bypassing(rq))) {
>  		__scx_add_event(sch, SCX_EV_BYPASS_DISPATCH, 1);
>  		goto bypass;

both scx_rq_online() and scx_rq_bypassing() have the same likely/unlikely()
annotations built into them.

Thanks.

-- 
tejun