From: Shubhang <sh@gentwo.org>
To: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
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>,
Christoph Lameter <cl@gentwo.org>,
Shubhang Kaushik <shubhang@os.amperecomputing.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] sched/core: Preserve wake flags across queued wakeups
Date: Wed, 22 Jul 2026 09:17:02 -0700 (PDT) [thread overview]
Message-ID: <888ae543-2e09-e885-b18a-4c5d1d3f1697@gentwo.org> (raw)
In-Reply-To: <1bebcf2d-2325-4e11-bb5f-347a0ac10fcc@amd.com>
Hi Prateek,
On Wed, 22 Jul 2026, K Prateek Nayak wrote:
> Hello Shubhang,
>
> On 7/22/2026 12:24 PM, Shubhang Kaushik (Ampere) wrote:
>> Changes in v3:
>> - Use READ_ONCE()/WRITE_ONCE() for sched_remote_wakeup_flags.
>
> Why? Adding to the llist will have release semantics and I don't think
> there is any way for the receiver to see an object on the llist and it
> not having "sched_remote_wakeup_flags" set properly.
>
> Otherwise, a bunch of csd initialization bits would also need
> READ_ONCE() / WRITE_ONCE() but I don't see any.
Thanks, that makes sense.
I added READ_ONCE()/WRITE_ONCE() because the field is written by the
waking CPU and read by the target CPU, so I initially treated it as an
explicit cross-CPU field. But the flags are stored before the task is
published with llist_add(), and the target CPU reads them only after
removing the entry from the llist. So yeah, will drop that.
>> --- a/include/linux/sched.h
>> +++ b/include/linux/sched.h
>> @@ -983,6 +983,16 @@ struct task_struct {
>>
>> /* Used for emulating ABI behavior of previous Linux versions: */
>> unsigned int personality;
>> + /*
>> + * Must not share the scheduler bitfield word because wakelist
>> + * queueing is not serialized by p->on_cpu.
>> + *
>> + * smp_load_acquire(&p->on_cpu) in ttwu_queue_wakelist() pairs
>
> This should be "before" and not "in" here ^^
>
>> + * with smp_mb__after_spinlock() in schedule(), making current's
>
> What? That load acquire pairs with smp_store_release() in finish_task()
> before interrupts are enabled after context-switch on the destination
> CPU.
>
Agreed, will fix this comment.
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index 96226707c2f6135341aa779b8262f113e103d8ad..7ddcc6a7f1c06675ce8084cd304475d61f869eb7 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -3902,13 +3902,16 @@ void sched_ttwu_pending(void *arg)
>> update_rq_clock(rq);
>>
>> llist_for_each_entry_safe(p, t, llist, wake_entry.llist) {
>> + int wake_flags;
>
> Do we really need that local variable?
>
No, once READ_ONCE() goes away this can be passed directly to
ttwu_do_activate(). I'll drop the local variable as well.
>> @@ -3947,11 +3950,14 @@ bool call_function_single_prep_ipi(int cpu)
>> * via sched_ttwu_wakeup() for activation so the wakee incurs the cost
>> * of the wakeup instead of the waker.
>> */
>> +#define WF_TTWU_QUEUE_MASK (WF_TTWU | WF_SYNC | WF_MIGRATED | \
>> + WF_RQ_SELECTED)
>
> I much rather prefer it in single line even though it crosses
> 80 characters. #defines like SCHED_DL_FLAGS run even longer.
Sure, will keep it in one line.
>> static void __ttwu_queue_wakelist(struct task_struct *p, int cpu, int wake_flags)
>> {
>> struct rq *rq = cpu_rq(cpu);
>>
>> - p->sched_remote_wakeup = !!(wake_flags & WF_MIGRATED);
>> + WRITE_ONCE(p->sched_remote_wakeup_flags,
>> + wake_flags & WF_TTWU_QUEUE_MASK);
>>
>> WRITE_ONCE(rq->ttwu_pending, 1);
>> #ifdef CONFIG_SMP
>
> FWIW, feel free to include:
>
> Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Thanks, I'll add it.
Regards,
Shubhang Kaushik
prev parent reply other threads:[~2026-07-22 16:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 6:54 Shubhang Kaushik (Ampere)
2026-07-22 8:53 ` K Prateek Nayak
2026-07-22 16:17 ` 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=888ae543-2e09-e885-b18a-4c5d1d3f1697@gentwo.org \
--to=sh@gentwo.org \
--cc=bsegall@google.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=vincent.guittot@linaro.org \
--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®