[PATCH] x86/cpu/hygon: Prefer HLT over MWAIT for C1 idle when SMT is enabled

From: Mouse Zhang

Date: Wed Aug 19 2026 - 21:58:17 EST


In init_hygon(), set boot_option_idle_override to IDLE_NOMWAIT when no
explicit idle= option was given and SMT is enabled, so that the default
C1 idle uses HLT instead of MWAIT. This keeps
prefer_mwait_c1_over_halt() vendor-neutral while encoding the
Hygon-specific policy in its own init path.

On Hygon processors with SMT (2 or 4 threads per core) enabled,
entering C1 with MWAIT causes a significant single-thread performance
loss compared to HLT when the sibling thread is also in C1. When the
sibling thread is in C2, it enters that state via IOPORT, which is
independent of HLT and MWAIT, so performance is unaffected.

Hygon and AMD use different hardware implementations for MWAIT C1, and
HLT performs better than MWAIT on Hygon platforms when SMT is enabled.

On a Hygon family 18h model 7h system with SMT2 enabled, the
single-core UnixBench results show HLT outperforming MWAIT by 14.53%,
and the single-core SPEC CPU 2017 results show improvements of 12.68%
(intrate) and 19.73% (fprate).

Commit aebef63cf7ff ("x86: Remove vendor checks from
prefer_mwait_c1_over_halt"), merged in v6.0-rc1, removed the vendor
check that previously made Hygon use HLT, so Hygon adopted MWAIT and
hit the performance regression described above. Restore the pre-v6.0
default to avoid the regression.

Fixes: aebef63cf7ff ("x86: Remove vendor checks from prefer_mwait_c1_over_halt")
Signed-off-by: Mouse Zhang <zhangzihao@xxxxxxxxxxxx>
---
arch/x86/kernel/cpu/hygon.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/arch/x86/kernel/cpu/hygon.c b/arch/x86/kernel/cpu/hygon.c
index ec51c2b9a257..bac71b13a0a3 100644
--- a/arch/x86/kernel/cpu/hygon.c
+++ b/arch/x86/kernel/cpu/hygon.c
@@ -7,6 +7,7 @@
* Author: Pu Wen <puwen@xxxxxxxx>
*/
#include <linux/io.h>
+#include <linux/cpu_smt.h>

#include <asm/apic.h>
#include <asm/cpu.h>
@@ -174,6 +175,17 @@ static void init_hygon(struct cpuinfo_x86 *c)
{
u64 vm_cr;

+ /*
+ * On Hygon platforms with SMT enabled, MWAIT is disabled by default
+ * for better performance.
+ */
+ if (boot_option_idle_override == IDLE_NO_OVERRIDE &&
+ __max_threads_per_core > 1 &&
+ cpu_smt_control == CPU_SMT_ENABLED) {
+ pr_info("On Hygon platforms with SMT enabled, set idle=nomwait by default.\n");
+ boot_option_idle_override = IDLE_NOMWAIT;
+ }
+
early_init_hygon(c);

set_cpu_cap(c, X86_FEATURE_REP_GOOD);
--
2.39.3