Skip to contentSkip to conversation

sched/fair: align proxy wakeup buddy handling with EEVDF

PATCH In review zhidao su (Xiaomi) 2 participants 3 messages Jul 6 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched/fair: align proxy wakeup buddy handling with EEVDF

Proxy execution still nominates a newly woken task as NEXT_BUDDY before the wakeup path has passed the same policy and EEVDF eligibility gates used by the updated fair scheduler wakeup logic.

Move the NEXT_BUDDY nomination later in check_preempt_wakeup_fair() so throttled, already-rescheduled, disabled-preemption, idle-class, and non-normal wakeups return before updating cfs_rq->next.

Also clear stale buddy state when PREEMPT_SHORT overrides slice protection.

---
 kernel/sched/fair.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
kernel/sched/fair.c +6 -5
index 1f1c53c7deb2b..6a6cf8019be90 100644
@@ -8755,10 +8755,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 	if (task_is_throttled(p))
 		return;
 
-	if (sched_feat(NEXT_BUDDY) && !(wake_flags & WF_FORK) && !pse->sched_delayed) {
-		set_next_buddy(pse);
-	}
-
 	/*
 	 * We can come here with TIF_NEED_RESCHED already set from new task
 	 * wake up path.
@@ -8811,6 +8807,9 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 	 */
 	do_preempt_short = sched_feat(PREEMPT_SHORT) && (pse->slice < se->slice);
 
+	if (sched_feat(NEXT_BUDDY) && !(wake_flags & WF_FORK) && !pse->sched_delayed)
+		set_next_buddy(pse);
+
 	/*
 	 * If @p has become the most eligible task, force preemption.
 	 */
@@ -8823,8 +8822,10 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
 	return;
 
 preempt:
-	if (do_preempt_short)
+	if (do_preempt_short) {
 		cancel_protect_slice(se);
+		clear_buddies(cfs_rq, se);
+	}
 
 	resched_curr_lazy(rq);
 }
Signature · 1 line
2.43.0
maintainer
#1 lore raw

kernel/sched/fair.c static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int

Quoted 22 lines · zhidao su (Xiaomi)

Proxy execution still nominates a newly woken task as NEXT_BUDDY before the wakeup path has passed the same policy and EEVDF eligibility gates used by the updated fair scheduler wakeup logic.

Move the NEXT_BUDDY nomination later in check_preempt_wakeup_fair() so throttled, already-rescheduled, disabled-preemption, idle-class, and non-normal wakeups return before updating cfs_rq->next.

Also clear stale buddy state when PREEMPT_SHORT overrides slice protection.

---
 kernel/sched/fair.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
kernel/sched/fair.c +0 -0
index 1f1c53c7deb2b..6a6cf8019be90 100644
@@ -8755,10 +8755,6 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int

Which version are you using ? there is nothing like check_preempt_wakeup_fair() in mainline or tip/sched/core

And does the issue still apply with the latest scheduler changes?

Quoted 35 lines
kernel/sched/fair.c +6 -6
        if (task_is_throttled(p))
                return;
 
-       if (sched_feat(NEXT_BUDDY) && !(wake_flags & WF_FORK) && !pse->sched_delayed) {
-               set_next_buddy(pse);
-       }
-
        /*
         * We can come here with TIF_NEED_RESCHED already set from new task
         * wake up path.
@@ -8811,6 +8807,9 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
         */
        do_preempt_short = sched_feat(PREEMPT_SHORT) && (pse->slice < se->slice);
 
+       if (sched_feat(NEXT_BUDDY) && !(wake_flags & WF_FORK) && !pse->sched_delayed)
+               set_next_buddy(pse);
+
        /*
         * If @p has become the most eligible task, force preemption.
         */
@@ -8823,8 +8822,10 @@ static void check_preempt_wakeup_fair(struct rq *rq, struct task_struct *p, int
        return;
 
 preempt:
-       if (do_preempt_short)
+       if (do_preempt_short) {
                cancel_protect_slice(se);
+               clear_buddies(cfs_rq, se);
+       }
 
        resched_curr_lazy(rq);
 }
--

2.43.0

#2 lore raw

From: "zhidao su (Xiaomi)" <[email protected]>

Quoted 4 lines · Vincent Guittot

Which version are you using ? there is nothing like check_preempt_wakeup_fair() in mainline or tip/sched/core

And does the issue still apply with the latest scheduler changes?

Thanks for checking, and sorry for the noise.

You are right. I based this on an old local proxy-exec work branch and failed to state the base tree/commit in the submission. That branch still had check_preempt_wakeup_fair(), but current mainline/tip and the newer proxy-exec branches have moved to wakeup_preempt_fair().

I rechecked the newer code and the wakeup path has already been reworked around preempt_action/set_preempt_buddy(), including the PREEMPT_WAKEUP_SHORT buddy cleanup path. So this patch does not apply to the current scheduler code and should be ignored.

I'll fix my local pre-send checks so patches like this have to apply to the intended target baseline before I send them.

Thanks,
zhidao