From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Will Deacon <will@kernel.org>, Peter Zijlstra <peterz@infradead.org>
Cc: Gabriele Monaco <gmonaco@redhat.com>,
Sechang Lim <rhkrqnwk98@gmail.com>,
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>,
<linux-kernel@vger.kernel.org>,
Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH v2] sched: set TIF_NEED_RESCHED before calling __trace_set_need_resched()
Date: Thu, 16 Jul 2026 23:55:16 +0530 [thread overview]
Message-ID: <6e385952-9885-4736-8501-45aafe4310cd@amd.com> (raw)
In-Reply-To: <alj0Rb7_pZk8u_Rh@willie-the-truck>
Hello Will,
On 7/16/2026 8:39 PM, Will Deacon wrote:
> On Wed, Jul 01, 2026 at 10:49:39AM +0200, Peter Zijlstra wrote:
>> On Wed, Jul 01, 2026 at 01:39:23PM +0530, K Prateek Nayak wrote:
>>> Hello Peter,
>>>
>>> On 7/1/2026 12:24 PM, Peter Zijlstra wrote:
>>>>> @@ -1204,16 +1217,16 @@ static void __resched_curr(struct rq *rq, int tif)
>>>>> cpu = cpu_of(rq);
>>>>>
>>>>> if (cpu == smp_processor_id()) {
>>>>> - set_ti_thread_flag(cti, tif);
>>>>> + int set = test_and_set_ti_thread_flag(cti, tif);
>>>>> +
>>>>> + if (trace_sched_set_need_resched_tp_enabled() && !set)
>>>>> + trace_call__sched_set_need_resched_tp(curr, cpu, tif);
>>>>> if (tif == TIF_NEED_RESCHED)
>>>>> set_preempt_need_resched();
>>>>> - trace_sched_set_need_resched_tp(curr, cpu, tif);
>>>>> return;
>>>>> }
>>>>
>>>> I can't help but notice that the local and !POLLING cases show
>>>> remarkable similarity. Just not sure extracting that isn't going to make
>>>> a mess.
>>>>
>>>> Anyway, yes this looks about right.
>>>
>>> If the fetch_or() based path is okay for !POLLING and local cases which
>>> uses a slightly (vastly?) worse instruction to set the ti->flags, we can
>>> instead do:
>>>
>> Tempting, but at least arm64 would have to agree I think. That said, I
>> wonder why ARM64 doesn't use LDXR+WFE for idle, just like we have
>> MONITOR+MWAIT.
>>
>> Probably too damn many idle flavours to deal with or somesuch.
>
> I think the problem is a combination of:
>
> 1. You probably want to enter a deeper sleep state after polling for a
> bit, but you might just get stuck in the WFE if you don't get an
> update.
But you can idle with scheduler tick enabled with WFE and that should
allow you to retrospect and go deeper at the next tick if needed, no?
> 2. An IRQ doesn't wake WFE if IRQs are disabled (this is different to
> WFI).
I'm out of my depths here but the on x86 side mwait_idle() does an
MWAIT with interrupts enabled.
The polling flag being set is simply an optimization for the IPI sender
to set RESCHED bit instead of sending a physical IPI - an external
interrupt is still possible and will break out of idle.
Also, the other question on the thread was: Is try_cmpxchg() much
worse than a test_and_set_ti_thread_flag() (which uses
test_and_set_bit()) on ARM64?
The full diff in
https://lore.kernel.org/lkml/14abaec8-05ca-4034-b153-b993ed60a1fb@amd.com/
replaces a test_and_set_ti_thread_flag() path with a try_cmpxchg()
one and we were wondering if the code unification is worth the
performance lost.
--
Thanks and Regards,
Prateek
next prev parent reply other threads:[~2026-07-16 18:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-27 8:16 Sechang Lim
2026-06-29 4:11 ` K Prateek Nayak
2026-06-29 12:40 ` Gabriele Monaco
2026-06-29 17:35 ` K Prateek Nayak
2026-06-30 8:58 ` Gabriele Monaco
2026-06-30 16:16 ` K Prateek Nayak
2026-06-30 20:34 ` Peter Zijlstra
2026-07-01 6:51 ` K Prateek Nayak
2026-07-01 6:54 ` Peter Zijlstra
2026-07-01 8:09 ` K Prateek Nayak
2026-07-01 8:49 ` Peter Zijlstra
2026-07-16 15:09 ` Will Deacon
2026-07-16 18:25 ` K Prateek Nayak [this message]
2026-06-30 7:58 ` Sechang Lim
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=6e385952-9885-4736-8501-45aafe4310cd@amd.com \
--to=kprateek.nayak@amd.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=gmonaco@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rhkrqnwk98@gmail.com \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=will@kernel.org \
/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®