From: Frederic Weisbecker <frederic@kernel.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>,
Daniel Lezcano <daniel.lezcano@linaro.org>,
linux-pm@vger.kernel.org, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH 3/5] cpuidle: Handle TIF_NR_POLLING on behalf of CPUIDLE_FLAG_MWAIT states
Date: Wed, 18 Dec 2024 15:04:15 +0100 [thread overview]
Message-ID: <Z2LWX5jOTOD89yPl@localhost.localdomain> (raw)
In-Reply-To: <CAJZ5v0hJyeoeZ3L=RicDiHz9X8PqEvTgWJVT3s9rsy653w_Fug@mail.gmail.com>
Le Wed, Dec 18, 2024 at 02:24:36PM +0100, Rafael J. Wysocki a écrit :
> On Fri, Dec 6, 2024 at 2:04 PM Frederic Weisbecker <frederic@kernel.org> wrote:
> >
> > From: Peter Zijlstra <peterz@infradead.org>
> >
> > The current handling of TIF_NR_POLLING is a bit of a maze:
> >
> > 1) TIF_NR_POLLING is set on idle entry (one atomic set)
> >
> > 2) Once cpuidle has selected an appropriate state and the tick is
> > evaluated and then possibly stopped, TIF_NR_POLLING is cleared
> > (one RmW operation)
> >
> > 2) The cpuidle state is then called with TIF_NR_POLLING cleared but if
> > the state polls on (or monitors) need_resched() it sets again
> > TIF_NR_POLLING before sleeping and clears it on wake-up. Summary:
> > another pair of set/clear
> >
> > 3) Set back TIF_NR_POLLING (one atomic set)
> >
> > 4) goto 2) if need_resched() is not set
> >
> > All those costly atomic operations, fully ordered RmW for some of
> > them, could be avoided if the cpuidle core knew in advance if the target
> > state polls on (or monitors) need_resched(). If so, TIF_NR_POLLING could
> > simply be set once upon entering the idle loop and cleared once after
> > idle loop exit.
> >
> > Start dealing with that with handling TIF_NR_POLLING on behalf of
> > mwait based states.
> >
> > [fweisbec: _ Handle broadcast properly
> > _ Ignore mwait_idle() as it can be used by default_idle_call()]
> >
> > Not-yet-signed-off-by: Peter Zijlstra <peterz@infradead.org>
> > Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
> > ---
> > arch/x86/include/asm/mwait.h | 3 +--
> > drivers/cpuidle/cpuidle.c | 22 +++++++++++++++++++-
> > include/linux/sched/idle.h | 7 ++++++-
> > kernel/sched/idle.c | 40 +++++++++++++-----------------------
> > 4 files changed, 42 insertions(+), 30 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h
> > index 920426d691ce..3634d00e5c37 100644
> > --- a/arch/x86/include/asm/mwait.h
> > +++ b/arch/x86/include/asm/mwait.h
> > @@ -116,7 +116,7 @@ static __always_inline void __sti_mwait(unsigned long eax, unsigned long ecx)
> > */
> > static __always_inline void mwait_idle_with_hints(unsigned long eax, unsigned long ecx)
> > {
> > - if (static_cpu_has_bug(X86_BUG_MONITOR) || !current_set_polling_and_test()) {
> > + if (static_cpu_has_bug(X86_BUG_MONITOR) || !need_resched()) {
>
> I'm not sure how X86_BUG_MONITOR is going to work after the change.
>
> As is, X86_BUG_MONITOR prevents current_set_polling_and_test() from
> being called, so __current_set_polling() will not be called and
> TIF_POLLING_NRFLAG will not be set, so an IPI is going to be used for
> CPU wakeup, which is what X86_BUG_MONITOR wants.
>
> Preventing need_resched() from being called doesn't have this effect
> and the rest of the patch doesn't do anything about X86_BUG_MONITOR.
>
> Is anything missing?
I fear you're right, I overlooked that. Probably I should set CPUIDLE_FLAG_MWAIT
only if !boot_cpu_has_bug(X86_BUG_MONITOR). Lemme see that.
Thanks.
next prev parent reply other threads:[~2024-12-18 14:04 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 13:04 [PATCH 0/5] cpuidle: Handle TIF_NR_POLLING on behalf of polling idle states v2 Frederic Weisbecker
2024-12-06 13:04 ` [PATCH 1/5] cpuidle: Remove unnecessary current_clr_polling_and_test() from haltpoll Frederic Weisbecker
2024-12-06 13:04 ` [PATCH 2/5] cpuidle: Introduce CPUIDLE_FLAG_MWAIT Frederic Weisbecker
2024-12-10 14:03 ` Peter Zijlstra
2024-12-06 13:04 ` [PATCH 3/5] cpuidle: Handle TIF_NR_POLLING on behalf of CPUIDLE_FLAG_MWAIT states Frederic Weisbecker
2024-12-10 14:03 ` Peter Zijlstra
2024-12-18 13:24 ` Rafael J. Wysocki
2024-12-18 14:04 ` Frederic Weisbecker [this message]
2024-12-06 13:04 ` [PATCH 4/5] cpuidle: Remove call_cpuidle_s2idle() Frederic Weisbecker
2024-12-06 13:04 ` [PATCH 5/5] cpuidle: Handle TIF_NR_POLLING on behalf of software polling idle states Frederic Weisbecker
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=Z2LWX5jOTOD89yPl@localhost.localdomain \
--to=frederic@kernel.org \
--cc=bp@alien8.de \
--cc=daniel.lezcano@linaro.org \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=tglx@linutronix.de \
/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