Re: [PATCH 7/8] sched/eevdf: Compare min slice during wake_affine

From: Vincent Guittot

Date: Tue Sep 29 2026 - 08:43:49 EST


On Sat, 26 Sept 2026 at 20:19, Kayra Cizmeci <kayracizmeci@xxxxxxxxx> wrote:
>
> Hi Vincent,
>
> > Add a new level in wake affine where we check on which CPU the task
> > would most probably run 1st between this and prev CPUs.
>
> > @@ -8402,6 +8402,9 @@ static int wake_wide(struct task_struct *p)
> > * wake_affine_idle() - only considers 'now', it check if the waking CPU is
> > * cache-affine and is (or will be) idle.
> > *
> > + * wake_affine_slice() - only considers 'now', it check if the waking CPU can
> > + * be preempted because using longer slice.
> > + *
> > * wake_affine_weight() - considers the weight to reflect the average
> > * scheduling latency of the CPUs. This seems to work
> > * for the overloaded case.
> > @@ -8437,6 +8440,20 @@ wake_affine_idle(int this_cpu, int prev_cpu, int sync)
> > return nr_cpumask_bits;
> > }
>
> > +static int
> > +wake_affine_slice(struct task_struct *p, int this_cpu, int prev_cpu)
> > +{
> > + struct sched_entity *se = &p->se;
> > +
> > + if (se->slice < get_rq_min_slice(cpu_rq(prev_cpu)))
> > + return prev_cpu;
> > +
> > + if (se->slice < get_rq_min_slice(cpu_rq(this_cpu)))
> > + return this_cpu;
> > +
> > + return nr_cpumask_bits;
> > +}
> > +
> > static int
> > wake_affine_weight(struct sched_domain *sd, struct task_struct *p,
> > int this_cpu, int prev_cpu, int sync)
> > @@ -8488,6 +8505,9 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p,
> > if (sched_feat(WA_IDLE))
> > target = wake_affine_idle(this_cpu, prev_cpu, sync);
> >
> > + if (sched_feat(PREEMPT_SHORT) && target == nr_cpumask_bits)
> > + target = wake_affine_slice(p, this_cpu, prev_cpu);
> > +
> > if (sched_feat(WA_WEIGHT) && target == nr_cpumask_bits)
> > target = wake_affine_weight(sd, p, this_cpu, prev_cpu, sync);
> >
> > --
> > 2.53.0
>
> this_cpu has min_slice of 7 while prev_cpu has min_slice of 5.
> se->slice == 4, so on wake_affine_slice() prev_cpu is chosen.
>
> Ain't getting onto a cpu with bigger min_slice is better for us?
> If so, is this works for you?

For wake affine , we try to favor prev cpu if possible

>
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 09f0667e97a2..e50c339e5c2d 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -8444,14 +8444,13 @@ static int
> wake_affine_slice(struct task_struct *p, int this_cpu, int prev_cpu)
> {
> struct sched_entity *se = &p->se;
> + u64 min_prev = get_rq_min_slice(cpu_rq(prev_cpu));
> + u64 min_this = get_rq_min_slice(cpu_rq(this_cpu));
>
> - if (se->slice < get_rq_min_slice(cpu_rq(prev_cpu)))
> - return prev_cpu;
> -
> - if (se->slice < get_rq_min_slice(cpu_rq(this_cpu)))
> - return this_cpu;
> + if (se->slice >= max(min_prev, min_this))
> + return nr_cpumask_bits;
>
> - return nr_cpumask_bits;
> + return min_prev >= min_this ? prev_cpu : this_cpu;
> }
>
> static int
>
> Thanks,
> Kayra
>
>