From: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
rafael.j.wysocki@intel.com, len.brown@intel.com,
artem.bityutskiy@linux.intel.com, dave.hansen@linux.intel.com,
patryk.wlazlyn@linux.intel.com
Subject: [PATCH v2 2/3] x86/smp: Allow forcing the mwait hint for play dead loop
Date: Tue, 29 Oct 2024 11:15:06 +0100 [thread overview]
Message-ID: <20241029101507.7188-3-patryk.wlazlyn@linux.intel.com> (raw)
In-Reply-To: <20241029101507.7188-1-patryk.wlazlyn@linux.intel.com>
The current implementation for looking up the mwait hint for the deepest
cstate depends on them to be continuous in range [0, NUM_SUBSTATES-1].
While that is correct on most Intel x86 platforms, it is not
architectural and may not result in reaching the most optimized idle
state on some of them.
For example Intel's Sierra Forest report two C6 substates in cpuid leaf 5:
C6S (hint 0x22)
C6SP (hint 0x23)
Hints 0x20 and 0x21 are skipped entirely, causing the current
implementation to compute the wrong hint, when looking for the deepest
cstate for offlined CPU to enter. As a result, package with an offlined
CPU can never reach PC6.
Allow the idle driver to communicate the deepest idle cstate to the x86
offline code.
Signed-off-by: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
---
arch/x86/include/asm/smp.h | 3 +++
arch/x86/kernel/smpboot.c | 12 +++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index ca073f40698f..2cb083a84225 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -114,6 +114,7 @@ void wbinvd_on_cpu(int cpu);
int wbinvd_on_all_cpus(void);
void smp_kick_mwait_play_dead(void);
+void smp_set_mwait_play_dead_hint(unsigned int 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 smp_set_mwait_play_dead_hint(unsigned int hint) { }
#endif /* CONFIG_SMP */
#ifdef CONFIG_DEBUG_NMI_SELFTEST
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 683898e3b20e..08f7b43f3fc3 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -127,6 +127,9 @@ int __read_mostly __max_smt_threads = 1;
/* Flag to indicate if a complete sched domain rebuild is required */
bool x86_topology_update;
+#define PLAY_DEAD_MWAIT_HINT_UNSET 0U
+static unsigned int __read_mostly play_dead_mwait_hint;
+
int arch_update_cpu_topology(void)
{
int retval = x86_topology_update;
@@ -1270,6 +1273,11 @@ void play_dead_common(void)
local_irq_disable();
}
+void smp_set_mwait_play_dead_hint(unsigned int hint)
+{
+ WRITE_ONCE(play_dead_mwait_hint, hint);
+}
+
/* Computes mwait hint for the deepest mwait hint based on cpuid leaf 0x5 */
static inline unsigned int get_deepest_mwait_hint(void)
{
@@ -1322,7 +1330,9 @@ static inline void mwait_play_dead(void)
if (__this_cpu_read(cpu_info.cpuid_level) < CPUID_MWAIT_LEAF)
return;
- hint = get_deepest_mwait_hint();
+ hint = READ_ONCE(play_dead_mwait_hint);
+ if (hint == PLAY_DEAD_MWAIT_HINT_UNSET)
+ hint = get_deepest_mwait_hint();
/* Set up state for the kexec() hack below */
md->status = CPUDEAD_MWAIT_WAIT;
--
2.47.0
next prev parent reply other threads:[~2024-10-29 10:15 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 10:15 [PATCH v2 0/3] SRF: Fix offline CPU preventing pc6 entry Patryk Wlazlyn
2024-10-29 10:15 ` [PATCH v2 1/3] x86/smp: Move mwait hint computation out of mwait_play_dead Patryk Wlazlyn
2024-10-29 10:15 ` Patryk Wlazlyn [this message]
2024-10-29 18:30 ` [PATCH v2 2/3] x86/smp: Allow forcing the mwait hint for play dead loop Dave Hansen
2024-10-30 9:58 ` Artem Bityutskiy
2024-10-30 19:32 ` Dave Hansen
2024-10-30 19:53 ` Rafael J. Wysocki
2024-10-30 20:11 ` Dave Hansen
2024-10-30 20:14 ` Rafael J. Wysocki
2024-11-06 8:14 ` Artem Bityutskiy
2024-11-06 14:46 ` Dave Hansen
2024-10-30 13:33 ` Patryk Wlazlyn
2024-10-30 22:55 ` Dave Hansen
2024-10-29 10:15 ` [PATCH v2 3/3] intel_idle: Identify the deepest cstate for SRF Patryk Wlazlyn
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=20241029101507.7188-3-patryk.wlazlyn@linux.intel.com \
--to=patryk.wlazlyn@linux.intel.com \
--cc=artem.bityutskiy@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
--cc=x86@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.