RE: [PATCH] x86: Prefer MWAIT over HALT on AMD processors

From: Carroll, Lewis
Date: Tue Apr 05 2022 - 22:23:57 EST


[AMD Official Use Only]

Merging some comments from subsequent threads below...

> -----Original Message-----
> From: Borislav Petkov <bp@xxxxxxxxx>
> Sent: Tuesday, April 5, 2022 10:06 AM
> To: Karny, Wyes <Wyes.Karny@xxxxxxx>
> Cc: linux-kernel@xxxxxxxxxxxxxxx; Carroll, Lewis <Lewis.Carroll@xxxxxxx>;
> Limonciello, Mario <Mario.Limonciello@xxxxxxx>; Shenoy, Gautham Ranjal
> <gautham.shenoy@xxxxxxx>; Narayan, Ananth <Ananth.Narayan@xxxxxxx>; Rao,
> Bharata Bhasker <bharata@xxxxxxx>; len.brown@xxxxxxxxx; x86@xxxxxxxxxx;
> tglx@xxxxxxxxxxxxx; mingo@xxxxxxxxxx; dave.hansen@xxxxxxxxxxxxxxx;
> hpa@xxxxxxxxx; peterz@xxxxxxxxxxxxx; chang.seok.bae@xxxxxxxxx;
> keescook@xxxxxxxxxxxx; metze@xxxxxxxxx; zhengqi.arch@xxxxxxxxxxxxx;
> mark.rutland@xxxxxxx
> Subject: Re: [PATCH] x86: Prefer MWAIT over HALT on AMD processors
>
> [CAUTION: External Email]
>
> On Tue, Apr 05, 2022 at 06:30:21PM +0530, Wyes Karny wrote:
> > From: Lewis Caroll <lewis.carroll@xxxxxxx>
> >
> > Currently in the absence of the cpuidle driver (eg: when global
> > C-States are disabled in the BIOS or when cpuidle is driver is not
> > compiled in),
>
> When does that ever happen?
>
> Sounds like a very very niche situation to me...
>

This happens when:
* User disables global C-states in BIOS
* User disables cpuidle (e.g. idle=off or processor.max_cstate=0)
* Kernel does not have CONFIG_ACPI_PROCESSOR_IDLE
Genesis of this patch is customer performance observations.

> > Here we enable MWAIT instruction as the default idle call for AMD Zen
> > processors which support MWAIT. We retain the existing behaviour for
> > older processors which depend on HALT.
>
> Please use passive voice in your commit message: no "we" or "I", etc, and
> describe your changes in imperative mood.
>
> Also, pls read section "2) Describe your changes" in
> Documentation/process/submitting-patches.rst for more details.
>
> Also, see section "Changelog" in
> Documentation/process/maintainer-tip.rst
>
> Bottom line is: personal pronouns are ambiguous in text, especially with so
> many parties/companies/etc developing the kernel so let's avoid them please.
>
> > static int prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c) {
> > - if (c->x86_vendor != X86_VENDOR_INTEL)
> > + if (!early_mwait_supported(c))
>
> Isn't it enough to simply do here:
>
> if (cpu_has(c, X86_FEATURE_ZEN))
> return 1;
>
> if (c->x86_vendor != X86_VENDOR_INTEL)
> return 0;
>
> ...

Yes. We felt the code more readable with the prefer_mwait_c1_over_halt fn.
Hygon CPU init indeed sets X86_FEATURE ZEN.
AMD CPU init sets X86_FEATURE_ZEN for family >= 17h (not only 17h).
Cleanest solution might be a new CPU feature (e.g. X86_PREFER_MWAIT_IDLE) that
gets set appropriately, but that would require touching more files.

>
>
> --
> Regards/Gruss,
> Boris.