Re: [PATCH v5] sched/fair: Preserve wake-affine CPU for non-SMT reciprocal sync wakeups

From: Peter Zijlstra

Date: Mon Oct 12 2026 - 07:36:21 EST


On Thu, Oct 08, 2026 at 03:22:37PM -0700, Shubhang Kaushik (Ampere) wrote:

> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index 57360f5cdde4fa66f4cba2cbb53d4e322134504e..ce624fdc1f4480bc6e7ae710950fcaa93ab32a3e 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -9167,6 +9167,26 @@ static inline bool asym_fits_cpu(unsigned long util,
> return true;
> }
>
> +/*
> + * For reciprocal WF_SYNC handoffs, prefer the waker CPU when it has no
> + * other runnable task.
> + */
> +static bool prefer_sync_pair_cpu(struct task_struct *p, int cpu)
> +{
> + struct rq *rq = cpu_rq(cpu);
> +
> + if ((rq->nr_running - cfs_h_nr_delayed(rq)) != 1)
> + return false;
> +
> + if (sched_asym_cpucap_active()) {
> + sync_entity_load_avg(&p->se);
> + if (!task_fits_cpu(p, cpu))
> + return false;
> + }
> +
> + return true;
> +}
> +
> /*
> * Try and locate an idle core/thread in the LLC cache domain.
> */
> @@ -9955,6 +9975,12 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
> if (cpu != prev_cpu)
> new_cpu = wake_affine(tmp, p, cpu, prev_cpu, sync);
>
> + if (sync && !sched_smt_active() &&
> + new_cpu == cpu &&
> + p->last_wakee == current &&
> + prefer_sync_pair_cpu(p, cpu))
> + return cpu;
> +
> sd = NULL; /* Prefer wake_affine over balance flags */
> break;
> }

Hurmph.. just looking at this patch makes me go WTF. I've not read this
lengthy Changelog you put on top, because none of that survives unless
one goes trawl through git.

So this code is confusing as heck. Nor is is evident why it wants to be
!SMT.

The way I read this:

if the new_cpu is the current cpu (default case) AND
p was last woken by us AND
random
stay here.

The function babbles something about a sync-pair, but then doesn't
actually do anything with a pair, or ensures there is a pair.

I'm supposing what you're getting at is the earlier:

'p->last_wakee == current' combined with the fact that current is now
waking p

But then I have to note that last_wakee isn't all that nice, since
record_wakee() isn't guarded by in_task() -- it really should be.

Try and convince me with readable code?