Re: [PATCH v2] sched/fair: Prefer waker CPU for reciprocal sync wakeups
From: K Prateek Nayak
Date: Wed Jul 22 2026 - 23:49:58 EST
Hello Shubhang,
On 7/23/2026 4:20 AM, Shubhang Kaushik (Ampere) wrote:
> +/*
> + * For reciprocal WF_SYNC handoffs, prefer the waker CPU when it has no
> + * other runnable fair 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 (!cpumask_test_cpu(cpu, p->cpus_ptr))
> + return false;
want_affine already covers the affinity test now that you've moved it
into the SD_WAKE_AFFINE branch.
> +
> + if (sched_asym_cpucap_active()) {
> + sync_entity_load_avg(&p->se);
> + if (!task_fits_cpu(p, cpu))
> + return false;
> + }
> +
> + return true;
Reads a lot like WA_IDLE. Couldn't this simply be an early returns
in select_idle_sibling() if we passed wake_flags there?
> +}
> +
> /*
> * Try and locate an idle core/thread in the LLC cache domain.
> */
> @@ -9579,6 +9602,11 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int wake_flags)
> */
> if (want_affine && (tmp->flags & SD_WAKE_AFFINE) &&
> cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) {
> + if (sync &&
> + READ_ONCE(p->last_wakee) == current &&
No need for READ_ONCE(), Last wakee is recorded when "p" has last
woken up a task and given we are now doing a wakeup for "p", it
is completely off the rq and p->last_wakee is stable.
> + prefer_sync_pair_cpu(p, cpu))
> + return cpu;
> +
> if (cpu != prev_cpu)
> new_cpu = wake_affine(tmp, p, cpu, prev_cpu, sync);
>
>
> ---
> base-commit: 248951ddc14de84de3910f9b13f51491a8cd91df
> change-id: 20260721-b4-sched-sync-wakeup-04d40cbeb1da
>
> Best regards,
--
Thanks and Regards,
Prateek