SRF: Fix offline CPU preventing pc6 entry
Subsystems (4)
v5 cover SRF: Fix offline CPU preventing pc6 entry
Thanks for the feedback so far, sending next version of the patchset. Lots of simplifications and a little bit of rewording this time.
Rafael, I know you suggested to move the commit message from the 1/3 patch to the 3/3, but I feel like the change for SRF really is in the 1/3. If you in insist, I'll do that in the v6, but I think It serves it's purpose better like that, to justify getting rid of the old algorithm.
Changes since v4:
* Rebased on top of Linus' tree, picking up Rafael's acpi idle patches.
* Remove mwait_play_dead() code entirely from the native_play_dead() and delegate to idle driver right away, instead.
* ACPI: Don't filter FFH based cstates on AMD, rely on the BIOS to report them just like the AMD prefers (IOPORT based).
* Apply Peter's suggestion to intel idle to define a default enter_dead handler for all platforms in intel idle and allow for overwriting that in case It is needed.
Patryk Wlazlyn (3):
x86/smp: Allow calling mwait_play_dead with an arbitrary hint
ACPI: processor_idle: Add FFH state handling
intel_idle: Provide the default enter_dead() handler
arch/x86/include/asm/smp.h | 3 +++ arch/x86/kernel/acpi/cstate.c | 9 +++++++ arch/x86/kernel/smpboot.c | 46 ++++------------------------------- drivers/acpi/processor_idle.c | 2 ++ drivers/idle/intel_idle.c | 18 ++++++++++++-- include/acpi/processor.h | 5 ++++ 6 files changed, 40 insertions(+), 43 deletions(-)
Signature · 1 line
2.47.1
PATCH v5 1/3 x86/smp: Allow calling mwait_play_dead with an arbitrary hint
The MWAIT instruction needs different hints on different CPUs to reach specific idle states. The current hint calculation* in mwait_play_dead() code works in practice on current Intel hardware, but it fails on a recent one, Intel's Sierra Forest and possibly some future ones. Those newer CPUs' power efficiency suffers when the CPU is put offline.
* The current algorithm for looking up the mwait hint for the deepest cstate, in mwait_play_dead() code works by inspecting CPUID leaf 0x5 and calculates the mwait hint based on the number of reported substates. This approach depends on the hints associated with them to be continuous in the range [0, NUM_SUBSTATES-1]. This continuity is not documented and is not met on the recent Intel platforms.
For example, Intel's Sierra Forest report two cstates with two substates each in cpuid leaf 0x5:
Name* target cstate target subcstate (mwait hint)
===========================================================
C1 0x00 0x00 C1E 0x00 0x01
-- 0x10 ----
C6S 0x20 0x22 C6P 0x20 0x23
-- 0x30 ----
/* No more (sub)states all the way down to the end. */
===========================================================
* Names of the cstates are not included in the CPUID leaf 0x5, they are taken from the product specific documentation.
Notice that hints 0x20 and 0x21 are skipped entirely for the target cstate 0x20 (C6), being a cause of the problem for the current cpuid leaf 0x5 algorithm.
Allow cpuidle code to call mwait play dead loop with a known hint for the deepest idle state on a given platform, skipping the cpuid based calculation.
--- arch/x86/include/asm/smp.h | 3 +++ arch/x86/kernel/smpboot.c | 46 +++++--------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-)
arch/x86/include/asm/smp.h +3 -0
@@ -114,6 +114,7 @@ void wbinvd_on_cpu(int cpu);int wbinvd_on_all_cpus (void );void smp_kick_mwait_play_dead (void ); +void mwait_play_dead (unsigned long hint);void native_smp_send_reschedule (int cpu);void native_send_call_func_ipi (const struct cpumask *mask);
@@ -164,6 +165,8 @@ static inline struct cpumask *cpu_llc_shared_mask(int cpu) {return (struct cpumask *)cpumask_of (0 ); } + +static inline void mwait_play_dead (unsigned long eax_hint) { }#endif /* CONFIG_SMP */ #ifdef CONFIG_DEBUG_NMI_SELFTEST
arch/x86/kernel/smpboot.c +5 -41
66 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH v5 1/3] x86/smp: Allow calling mwait_play_dead with an arbitrary hint
Hello Patryk,
Quoted 34 lines · Patryk Wlazlyn
The MWAIT instruction needs different hints on different CPUs to reach specific idle states. The current hint calculation* in
mwait_play_dead()code works in practice on current Intel hardware, but it fails on a recent one, Intel's Sierra Forest and possibly some future ones. Those newer CPUs' power efficiency suffers when the CPU is put offline.* The current algorithm for looking up the mwait hint for the deepest cstate, in
mwait_play_dead()code works by inspecting CPUID leaf0x5and calculates the mwait hint based on the number of reported substates. This approach depends on the hints associated with them to be continuous in the range [0, NUM_SUBSTATES-1]. This continuity is not documented and is not met on the recent Intel platforms.For example, Intel's Sierra Forest report two cstates with two substates each in cpuid leaf
0x5:Name* target cstate target subcstate (mwait hint)
===========================================================C1 0x00 0x00 C1E 0x00 0x01--
0x10----C6S 0x20 0x22 C6P 0x20 0x23--
0x30----/* No more (sub)states all the way down to the end. */
===========================================================* Names of the cstates are not included in the CPUID leaf
0x5, they are taken from the product specific documentation.
Quoted 7 lines
Notice that hints
0x20and0x21are skipped entirely for the target cstate0x20(C6), being a cause of the problem for the current cpuid leaf0x5algorithm.Allow cpuidle code to call mwait play dead loop with a known hint for the deepest idle state on a given platform, skipping the cpuid based calculation.
Apologies for what may appear as bikeshedding, after this patch, the cpuidle code still won't call any mwait based play dead loop since the support for enter_dead for FFh based idle states in acpi_idle and intel_idle only gets added in Patches 2 and 3.
Does it make sense to split this Patch 1 into 2 patches : 1/4 and 4/4
1/4 just introduces the mwait_play_dead_with_hint() helper which will be used by patches 2 and 3.
4/4 get rids of the of logic to find the deepest state from mwait_play_dead() and modifies native_play_dead() to call cpuidle_play_dead() followed by hlt_play_dead() thus removing any reference to mwait_play_dead(). Optionally you can even rename mwait_play_dead_with_hints() to mwait_play_dead().
That way the changelog that you have for this patch can be used in 4/4 since with the addition of play_dead support for FFh states in both acpi_idle and intel_idle via patches 2 and 3, the logic to find the deepest ffh state in mwait_play_dead() is no longer required.
Thoughts ?
--
Thanks and Regards
gautham.
Quoted 104 lines
Signed-off-by Patryk Wlazlyn <[email protected]>--- arch/x86/include/asm/smp.h | 3 +++ arch/x86/kernel/smpboot.c | 46 +++++--------------------------------- 2 files changed, 8 insertions(+), 41 deletions(-)arch/x86/include/asm/smp.h +3
-0@@ -114,6 +114,7 @@ void wbinvd_on_cpu(int cpu);int wbinvd_on_all_cpus (void );void smp_kick_mwait_play_dead (void ); +void mwait_play_dead (unsigned long hint);void native_smp_send_reschedule (int cpu);void native_send_call_func_ipi (const struct cpumask *mask);@@ -164,6 +165,8 @@ static inline struct cpumask *cpu_llc_shared_mask(int cpu) {return (struct cpumask *)cpumask_of (0 ); } + +static inline void mwait_play_dead (unsigned long eax_hint) { }#endif /* CONFIG_SMP */ #ifdef CONFIG_DEBUG_NMI_SELFTEST arch/x86/kernel/smpboot.c +5
-41@@ -1276,45 +1276,9 @@ void play_dead_common(void)* We need to flush the caches before going to sleep, lest we have * dirty data in our caches when we come back up. */ -static inline void mwait_play_dead (void ) +void __noreturn mwait_play_dead (unsigned long eax_hint) {struct mwait_cpu_dead *md =this_cpu_ptr (&mwait_cpu_dead); -unsigned int eax, ebx, ecx, edx; -unsigned int highest_cstate =0 ; -unsigned int highest_subcstate =0 ; -int i; - -if (boot_cpu_data.x86_vendor ==X86_VENDOR_AMD || - boot_cpu_data.x86_vendor ==X86_VENDOR_HYGON ) -return ; -if (!this_cpu_has (X86_FEATURE_MWAIT )) -return ; -if (!this_cpu_has (X86_FEATURE_CLFLUSH )) -return ; -if (__this_cpu_read (cpu_info.cpuid_level) <CPUID_MWAIT_LEAF ) -return ; - - eax =CPUID_MWAIT_LEAF ; - ecx =0 ; -native_cpuid (&eax, &ebx, &ecx, &edx); - -/* -* eax will be 0 if EDX enumeration is not valid. -* Initialized below to cstate, sub_cstate value when EDX is valid. -*/ -if (!(ecx &CPUID5_ECX_EXTENSIONS_SUPPORTED )) { - eax =0 ; - }else { - edx >>=MWAIT_SUBSTATE_SIZE ; -for (i =0 ; i <7 && edx; i++, edx >>=MWAIT_SUBSTATE_SIZE ) { -if (edx &MWAIT_SUBSTATE_MASK ) { - highest_cstate = i; - highest_subcstate = edx &MWAIT_SUBSTATE_MASK ; - } - } - eax = (highest_cstate <<MWAIT_SUBSTATE_SIZE ) | - (highest_subcstate -1 ); - }/* Set up state for the kexec() hack below */ md->status =CPUDEAD_MWAIT_WAIT ;@@ -1335,7 +1299,7 @@ static inline void mwait_play_dead(void)mb ();__monitor (md,0 ,0 );mb (); -__mwait (eax,0 ); +__mwait (eax_hint,0 );if (READ_ONCE (md->control) ==CPUDEAD_MWAIT_KEXEC_HLT ) {/* @@ -1407,9 +1371,9 @@ void native_play_dead(void)play_dead_common ();tboot_shutdown (TB_SHUTDOWN_WFS ); -mwait_play_dead (); -if (cpuidle_play_dead ()) - hlt_play_dead(); +/* Below returns only on error. */ +cpuidle_play_dead (); + hlt_play_dead(); }#else /* ... !CONFIG_HOTPLUG_CPU */ Signature · 1 line
2.47.1
Re: [PATCH v5 1/3] x86/smp: Allow calling mwait_play_dead with an arbitrary hint
Quoted 18 lines
Hello Patryk,
Apologies for what may appear as bikeshedding, after this patch, the cpuidle code still won't call any mwait based play dead loop since the support for
enter_deadfor FFh based idle states inacpi_idleandintel_idleonly gets added in Patches 2 and 3.Does it make sense to split this Patch 1 into 2 patches : 1/4 and 4/4
1/4 just introduces the
mwait_play_dead_with_hint()helper which will be used by patches 2 and 3.4/4 get rids of the of logic to find the deepest state from
mwait_play_dead()and modifiesnative_play_dead()to callcpuidle_play_dead()followed byhlt_play_dead()thus removing any reference tomwait_play_dead(). Optionally you can even renamemwait_play_dead_with_hints()tomwait_play_dead().
Quoted 6 lines
That way the changelog that you have for this patch can be used in 4/4 since with the addition of
play_deadsupport for FFh states in bothacpi_idleandintel_idlevia patches 2 and 3, the logic to find the deepest ffh state inmwait_play_dead()is no longer required.Thoughts ?
Yeah, makes sense. I just wanted to simplify, but at some point crossed my mind that submitting it like you suggested may be better. I am going to split that if I don't see any objections.
Rafael J. Wysocki
maintainerRe: [PATCH v5 1/3] x86/smp: Allow calling mwait_play_dead with an arbitrary hint
Quoted 24 lines · Patryk Wlazlyn
Quoted 24 lines
Hello Patryk,
Apologies for what may appear as bikeshedding, after this patch, the cpuidle code still won't call any mwait based play dead loop since the support for
enter_deadfor FFh based idle states inacpi_idleandintel_idleonly gets added in Patches 2 and 3.Does it make sense to split this Patch 1 into 2 patches : 1/4 and 4/4
1/4 just introduces the
mwait_play_dead_with_hint()helper which will be used by patches 2 and 3.4/4 get rids of the of logic to find the deepest state from
mwait_play_dead()and modifiesnative_play_dead()to callcpuidle_play_dead()followed byhlt_play_dead()thus removing any reference tomwait_play_dead(). Optionally you can even renamemwait_play_dead_with_hints()tomwait_play_dead().That way the changelog that you have for this patch can be used in 4/4 since with the addition of
play_deadsupport for FFh states in bothacpi_idleandintel_idlevia patches 2 and 3, the logic to find the deepest ffh state inmwait_play_dead()is no longer required.
Quoted 4 lines
Quoted 1 line
Thoughts ?
Yeah, makes sense. I just wanted to simplify, but at some point crossed my mind that submitting it like you suggested may be better.
Not just it may be better, but this is the only way to do it or people who apply the first patch without the other two patches will likely have problems (and that may easily happen during bisection, for example).
Things should always work between consecutive patches in a patch series.
Quoted 1 line
I am going to split that if I don't see any objections.
Yes, please!
PATCH v5 2/3 ACPI: processor_idle: Add FFH state handling
In reply to Patryk WlazlynOne of the preceding commits removed the CPUID leaf 0x5 based play_dead in favor of delegating the play_dead functionality to the idle driver. It was mainly (perhaps exclusively) used for Intel CPUs. Add handling of the FFH states to the acpi idle driver in case intel idle is missing.
Notice, that on Intel, play_dead code relies on intel idle driver to be present or BIOS to expose the desired states now. On AMD, since the preferred play_dead method is via HLT or IOPORT over FFH/MWAIT, the code relies on BIOS to expose the states that will allow for efficient play_dead.
--- arch/x86/kernel/acpi/cstate.c | 9 +++++++++ drivers/acpi/processor_idle.c | 2 ++ include/acpi/processor.h | 5 +++++ 3 files changed, 16 insertions(+)
arch/x86/kernel/acpi/cstate.c +9 -0
@@ -204,6 +204,15 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu, }EXPORT_SYMBOL_GPL (acpi_processor_ffh_cstate_probe); +void acpi_processor_ffh_play_dead (struct acpi_processor_cx *cx) +{ +unsigned int cpu =smp_processor_id (); +struct cstate_entry *percpu_entry; + + percpu_entry =per_cpu_ptr (cpu_cstate_entry, cpu); +mwait_play_dead (percpu_entry->states[cx->index].eax); +} + void __cpuidle acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx) {unsigned int cpu =smp_processor_id ();
drivers/acpi/processor_idle.c +2 -0
@@ -590,6 +590,8 @@ static void acpi_idle_play_dead(struct cpuidle_device *dev, int index)raw_safe_halt (); else if (cx->entry_method == ACPI_CSTATE_SYSTEMIO) {io_idle (cx->address); + } else if (cx->entry_method == ACPI_CSTATE_FFH) { +acpi_processor_ffh_play_dead (cx); } else return; }
include/acpi/processor.h +5 -0
@@ -280,6 +280,7 @@ int acpi_processor_ffh_cstate_probe(unsigned int cpu,struct acpi_processor_cx *cx, struct acpi_power_register *reg);void acpi_processor_ffh_cstate_enter (struct acpi_processor_cx *cstate); +void acpi_processor_ffh_play_dead (struct acpi_processor_cx *cx);#else static inline void acpi_processor_power_init_bm_check (struct acpi_processor_flags
@@ -300,6 +301,10 @@ static inline void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx {return ; } +static inline void acpi_processor_ffh_play_dead (struct acpi_processor_cx *cx) +{ +return ; +}#endif static inline int call_on_cpu(int cpu, long (*fn)(void *), void *arg,
Signature · 1 line
2.47.1
PATCH v5 3/3 intel_idle: Provide the default enter_dead() handler
In reply to Patryk WlazlynThe recent mwait_play_dead code relies on cpuidle driver to call the function with the right mwait hint, for the deepest cstate for which the driver provides the enter_dead handler.
--- drivers/idle/intel_idle.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +16 -2
@@ -56,6 +56,7 @@#include <asm/mwait.h> #include <asm/spec-ctrl.h> #include <asm/fpu/api.h> +#include <asm/smp.h> #define INTEL_IDLE_VERSION "0.5.1"
@@ -227,6 +228,16 @@ static __cpuidle int intel_idle_s2idle(struct cpuidle_device *dev,return 0 ; } +static __cpuidle void intel_idle_enter_dead(struct cpuidle_device *dev, +int index) +{ +struct cpuidle_driver *drv =cpuidle_get_cpu_driver (dev); +struct cpuidle_state *state = &drv->states[index]; +unsigned long eax =flg2MWAIT (state->flags); + +mwait_play_dead (eax); +} +/* * States are indexed by the cstate number, * which is also the index into the MWAIT hint array.
@@ -1798,6 +1809,7 @@ static void __init intel_idle_init_cstates_acpi(struct cpuidle_driver *drv) state->flags |=CPUIDLE_FLAG_TIMER_STOP ; state->enter = intel_idle; + state->enter_dead = intel_idle_enter_dead; state->enter_s2idle = intel_idle_s2idle; } }
@@ -2143,10 +2155,12 @@ static void __init intel_idle_init_cstates_icpu(struct cpuidle_driver *drv)if (intel_idle_max_cstate_reached (cstate))break ; -if (!cpuidle_state_table[cstate].enter && - !cpuidle_state_table[cstate].enter_s2idle) +if (!cpuidle_state_table[cstate].enter)break ; +if (!cpuidle_state_table[cstate].enter_dead) + cpuidle_state_table[cstate].enter_dead = intel_idle_enter_dead; +/* If marked as unusable, skip this state. */ if (cpuidle_state_table[cstate].flags &CPUIDLE_FLAG_UNUSABLE ) { pr_debug("state %s is disabled\n",
Signature · 1 line
2.47.1