Skip to contentSkip to conversation

sched_ext: add unlikely() hints in do_enqueue_task() hot path

PATCH In review David Carlier 2 participants 2 messages Feb 26 – Feb 27 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched_ext: add unlikely() hints in do_enqueue_task() hot path

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.

---
 kernel/sched/ext.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/ext.c +2 -2
index c18e81e8ef51..9a888ce5e2f1 100644
@@ -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;
 	}
Signature · 1 line
2.51.0
#1 lore raw

Hello,

kernel/sched/ext.c static void do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags, · line 1368

Quoted 12 lines · David Carlier
kernel/sched/ext.c +2 -2
@@ -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.

Signature · 1 line
tejun