mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shubhang <sh@gentwo.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	 Vincent Guittot <vincent.guittot@linaro.org>,
	 Dietmar Eggemann <dietmar.eggemann@arm.com>,
	 Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>,  Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	 K Prateek Nayak <kprateek.nayak@amd.com>,
	 Christian Loehle <christian.loehle@arm.com>,
	 Madadi Vineeth Reddy <vineethr@linux.ibm.com>,
	 Shrikanth Hegde <sshegde@linux.ibm.com>,
	 "Christoph Lameter (Ampere)" <cl@gentwo.org>,
	 Shubhang Kaushik <shubhang@os.amperecomputing.com>,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5] sched/fair: Preserve wake-affine CPU for non-SMT reciprocal sync wakeups
Date: Mon, 12 Oct 2026 11:53:47 -0700 (PDT)	[thread overview]
Message-ID: <6e29ac5e-cf6c-d299-d72c-eef828bcfbe7@gentwo.org> (raw)
In-Reply-To: <20261012113340.GS4121339@noisy.programming.kicks-ass.net>

Hi Peter,

Thanks for the review.

On Mon, 12 Oct 2026, Peter Zijlstra wrote:

> On Thu, Oct 08, 2026 at 03:22:37PM -0700, Shubhang Kaushik (Ampere) wrote:
>
>> +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?
>

Yes, I see. It seems implicit that v5 relies on the earlier 
record_wakee(p) update to establish current->last_wakee == p, while the 
placement decision only shows p->last_wakee == current.

I will respin it so the reciprocal state is recorded as a local boolean
immediately after record_wakee(p):

         reciprocal_wakeup = in_task() &&
                 current->last_wakee == p &&
                 p->last_wakee == current;

The later placement decision will use that named state rather than a
bare last_wakee comparison.

Yes, I will add the in_task() guard to record_wakee() itself. Otherwise,
an IRQ/softirq wakeup records the interrupted task as the waker and can
create a false last_wakee relationship.

Lastly, I will make the non-SMT restriction explicit at the decision
point. On a non-SMT CPU, stacking the reciprocal WF_SYNC wakee behind
the waker preserves the intended handoff when the waker is its only
runnable task. On SMT, an idle sibling or idle core may run the wakee
in parallel, so select_idle_sibling() remains responsible for that
placement.

So I'll send a v6 with these changes accordingly.

Thanks,
Shubhang Kaushik

      reply	other threads:[~2026-10-12 18:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-08 22:22 Shubhang Kaushik (Ampere)
2026-10-12 11:33 ` Peter Zijlstra
2026-10-12 18:53   ` Shubhang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e29ac5e-cf6c-d299-d72c-eef828bcfbe7@gentwo.org \
    --to=sh@gentwo.org \
    --cc=bsegall@google.com \
    --cc=christian.loehle@arm.com \
    --cc=cl@gentwo.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=shubhang@os.amperecomputing.com \
    --cc=sshegde@linux.ibm.com \
    --cc=vincent.guittot@linaro.org \
    --cc=vineethr@linux.ibm.com \
    --cc=vschneid@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®