2018-04-02 18:36:10

by Yazen Ghannam

[permalink] [raw]
Subject: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD systems

From: Yazen Ghannam <[email protected]>

Recent AMD systems support using MWAIT for C1 state. However, MWAIT will
not allow deeper cstates than C1 on current systems.

With play_dead() we expect the OS to use the deepest state available.
The deepest state available on AMD systems is reached through SystemIO
or HALT. If MWAIT is available, we use it instead of the other methods,
so we never reach the deepest state.

Don't try to use MWAIT to play_dead() on AMD systems. Instead, we'll use
CPUIDLE to enter the deepest state advertised by firmware. If CPUIDLE is
not available then we fallback to HALT.

Signed-off-by: Yazen Ghannam <[email protected]>
---
arch/x86/kernel/smpboot.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index ff99e2b6fc54..67cf00b25f83 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1536,6 +1536,9 @@ static inline void mwait_play_dead(void)
void *mwait_ptr;
int i;

+ /* Don't try native MWAIT on AMD. Stick to CPUIDLE and HALT. */
+ if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
+ return;
if (!this_cpu_has(X86_FEATURE_MWAIT))
return;
if (!this_cpu_has(X86_FEATURE_CLFLUSH))
--
2.14.1



2018-04-03 11:05:37

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD systems


* Yazen Ghannam <[email protected]> wrote:

> From: Yazen Ghannam <[email protected]>
>
> Recent AMD systems support using MWAIT for C1 state. However, MWAIT will
> not allow deeper cstates than C1 on current systems.
>
> With play_dead() we expect the OS to use the deepest state available.
> The deepest state available on AMD systems is reached through SystemIO
> or HALT. If MWAIT is available, we use it instead of the other methods,
> so we never reach the deepest state.
>
> Don't try to use MWAIT to play_dead() on AMD systems. Instead, we'll use
> CPUIDLE to enter the deepest state advertised by firmware. If CPUIDLE is
> not available then we fallback to HALT.
>
> Signed-off-by: Yazen Ghannam <[email protected]>
> ---
> arch/x86/kernel/smpboot.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> index ff99e2b6fc54..67cf00b25f83 100644
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -1536,6 +1536,9 @@ static inline void mwait_play_dead(void)
> void *mwait_ptr;
> int i;
>
> + /* Don't try native MWAIT on AMD. Stick to CPUIDLE and HALT. */
> + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
> + return;

The comment should mainly explain the 'why is this done', not the 'what is done'
which is pretty obvious from the code ...

Thanks,

Ingo

2018-04-03 13:57:11

by Yazen Ghannam

[permalink] [raw]
Subject: RE: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD systems

> -----Original Message-----
> From: Ingo Molnar <[email protected]> On Behalf Of Ingo Molnar
> Sent: Tuesday, April 3, 2018 7:04 AM
> To: Ghannam, Yazen <[email protected]>
> Cc: [email protected]; [email protected]; [email protected]
> Subject: Re: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD
> systems
>
>
> * Yazen Ghannam <[email protected]> wrote:
>
> > From: Yazen Ghannam <[email protected]>
> >
> > Recent AMD systems support using MWAIT for C1 state. However, MWAIT will
> > not allow deeper cstates than C1 on current systems.
> >
> > With play_dead() we expect the OS to use the deepest state available.
> > The deepest state available on AMD systems is reached through SystemIO
> > or HALT. If MWAIT is available, we use it instead of the other methods,
> > so we never reach the deepest state.
> >
> > Don't try to use MWAIT to play_dead() on AMD systems. Instead, we'll use
> > CPUIDLE to enter the deepest state advertised by firmware. If CPUIDLE is
> > not available then we fallback to HALT.
> >
> > Signed-off-by: Yazen Ghannam <[email protected]>
> > ---
> > arch/x86/kernel/smpboot.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> > index ff99e2b6fc54..67cf00b25f83 100644
> > --- a/arch/x86/kernel/smpboot.c
> > +++ b/arch/x86/kernel/smpboot.c
> > @@ -1536,6 +1536,9 @@ static inline void mwait_play_dead(void)
> > void *mwait_ptr;
> > int i;
> >
> > + /* Don't try native MWAIT on AMD. Stick to CPUIDLE and HALT. */
> > + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
> > + return;
>
> The comment should mainly explain the 'why is this done', not the 'what is done'
> which is pretty obvious from the code ...
>

Yes, I'll drop that comment since the commit message has the explanation.

Thanks,
Yazen

2018-04-03 14:42:21

by Ingo Molnar

[permalink] [raw]
Subject: Re: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD systems


* Ghannam, Yazen <[email protected]> wrote:

> > -----Original Message-----
> > From: Ingo Molnar <[email protected]> On Behalf Of Ingo Molnar
> > Sent: Tuesday, April 3, 2018 7:04 AM
> > To: Ghannam, Yazen <[email protected]>
> > Cc: [email protected]; [email protected]; [email protected]
> > Subject: Re: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD
> > systems
> >
> >
> > * Yazen Ghannam <[email protected]> wrote:
> >
> > > From: Yazen Ghannam <[email protected]>
> > >
> > > Recent AMD systems support using MWAIT for C1 state. However, MWAIT will
> > > not allow deeper cstates than C1 on current systems.
> > >
> > > With play_dead() we expect the OS to use the deepest state available.
> > > The deepest state available on AMD systems is reached through SystemIO
> > > or HALT. If MWAIT is available, we use it instead of the other methods,
> > > so we never reach the deepest state.
> > >
> > > Don't try to use MWAIT to play_dead() on AMD systems. Instead, we'll use
> > > CPUIDLE to enter the deepest state advertised by firmware. If CPUIDLE is
> > > not available then we fallback to HALT.
> > >
> > > Signed-off-by: Yazen Ghannam <[email protected]>
> > > ---
> > > arch/x86/kernel/smpboot.c | 3 +++
> > > 1 file changed, 3 insertions(+)
> > >
> > > diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> > > index ff99e2b6fc54..67cf00b25f83 100644
> > > --- a/arch/x86/kernel/smpboot.c
> > > +++ b/arch/x86/kernel/smpboot.c
> > > @@ -1536,6 +1536,9 @@ static inline void mwait_play_dead(void)
> > > void *mwait_ptr;
> > > int i;
> > >
> > > + /* Don't try native MWAIT on AMD. Stick to CPUIDLE and HALT. */
> > > + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
> > > + return;
> >
> > The comment should mainly explain the 'why is this done', not the 'what is done'
> > which is pretty obvious from the code ...
> >
>
> Yes, I'll drop that comment since the commit message has the explanation.

Or rather, explain the 'why' in the comment, because otherwise this is a pretty
obscure condition that is not self-documenting?

Thanks,

Ingo

2018-04-03 14:49:30

by Yazen Ghannam

[permalink] [raw]
Subject: RE: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD systems

> -----Original Message-----
> From: Ingo Molnar <[email protected]> On Behalf Of Ingo Molnar
> Sent: Tuesday, April 3, 2018 10:41 AM
> To: Ghannam, Yazen <[email protected]>
> Cc: [email protected]; [email protected]; [email protected]
> Subject: Re: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD
> systems
>
>
> * Ghannam, Yazen <[email protected]> wrote:
>
> > > -----Original Message-----
> > > From: Ingo Molnar <[email protected]> On Behalf Of Ingo
> Molnar
> > > Sent: Tuesday, April 3, 2018 7:04 AM
> > > To: Ghannam, Yazen <[email protected]>
> > > Cc: [email protected]; [email protected]; [email protected]
> > > Subject: Re: [PATCH] x86/smpboot: Don't do mwait_play_dead() on AMD
> > > systems
> > >
> > >
> > > * Yazen Ghannam <[email protected]> wrote:
> > >
> > > > From: Yazen Ghannam <[email protected]>
> > > >
> > > > Recent AMD systems support using MWAIT for C1 state. However, MWAIT
> will
> > > > not allow deeper cstates than C1 on current systems.
> > > >
> > > > With play_dead() we expect the OS to use the deepest state available.
> > > > The deepest state available on AMD systems is reached through SystemIO
> > > > or HALT. If MWAIT is available, we use it instead of the other methods,
> > > > so we never reach the deepest state.
> > > >
> > > > Don't try to use MWAIT to play_dead() on AMD systems. Instead, we'll use
> > > > CPUIDLE to enter the deepest state advertised by firmware. If CPUIDLE is
> > > > not available then we fallback to HALT.
> > > >
> > > > Signed-off-by: Yazen Ghannam <[email protected]>
> > > > ---
> > > > arch/x86/kernel/smpboot.c | 3 +++
> > > > 1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> > > > index ff99e2b6fc54..67cf00b25f83 100644
> > > > --- a/arch/x86/kernel/smpboot.c
> > > > +++ b/arch/x86/kernel/smpboot.c
> > > > @@ -1536,6 +1536,9 @@ static inline void mwait_play_dead(void)
> > > > void *mwait_ptr;
> > > > int i;
> > > >
> > > > + /* Don't try native MWAIT on AMD. Stick to CPUIDLE and HALT. */
> > > > + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
> > > > + return;
> > >
> > > The comment should mainly explain the 'why is this done', not the 'what is
> done'
> > > which is pretty obvious from the code ...
> > >
> >
> > Yes, I'll drop that comment since the commit message has the explanation.
>
> Or rather, explain the 'why' in the comment, because otherwise this is a pretty
> obscure condition that is not self-documenting?
>

Okay, how about this?

"MWAIT only provides shallow Cstates on AMD systems. Fallback to CPUIDLE and
HALT to have access to deeper Cstates."

Thanks,
Yazen