Re: [PATCH 1/6 v2] sched/fair: Set next buddy for preempt short

From: Vincent Guittot

Date: Tue Jun 16 2026 - 09:57:42 EST


On Tue, 16 Jun 2026 at 10:52, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
>
> On Mon, Jun 15, 2026 at 06:24:15PM +0200, Vincent Guittot wrote:
> > If a shorter slice task can preempt current at wakeup, we make sure that
> > the decision will not be overwritten in between by setting the task as the
> > next buddy. This still implies that the waking task remains eligible when
> > the scheduler will actually pick the next task to run.
> >
> > Signed-off-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
> > ---
> > kernel/sched/fair.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> > index d78467ec6ee1..83bce5a04f3d 100644
> > --- a/kernel/sched/fair.c
> > +++ b/kernel/sched/fair.c
> > @@ -9903,7 +9903,7 @@ static void wakeup_preempt_fair(struct rq *rq, struct task_struct *p, int wake_f
> > preempt:
> > if (preempt_action == PREEMPT_WAKEUP_SHORT) {
> > cancel_protect_slice(se);
> > - clear_buddies(cfs_rq, se);
> > + set_next_buddy(&p->se);
> > }
>
> Should this not be something along the lines of set_preempt_buddy()?

The test with pick_next_entity() ensures that p is the eligible and
before any other task which seems stronger than set_preempt_buddy()
which only look at deadline but not eligibility