public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpuidle-haltpoll: Disable kvm guest polling when mwait_idle is used
@ 2022-12-06  6:43 lirongqing
  2022-12-06 11:59 ` Rafael J. Wysocki
  0 siblings, 1 reply; 7+ messages in thread
From: lirongqing @ 2022-12-06  6:43 UTC (permalink / raw)
  To: tglx, mingo, bp, dave.hansen, x86, rafael, daniel.lezcano, peterz,
	akpm, tony.luck, jpoimboe, linux-kernel, linux-pm

From: Li RongQing <lirongqing@baidu.com>

when KVM guest has mwait and mwait_idle is used as default idle function,
Loading cpuidle-haltpoll will make idle function back to default_idle which
is using HLT, As the commit aebef63cf7ff ("x86: Remove vendor checks from
prefer_mwait_c1_over_halt") explains that mwait is preferred

so disable kvm guest polling in this conditions to improve performance,
like sockperf localhost test shows that latency is reduced by about 20%

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 arch/x86/include/asm/processor.h   | 2 ++
 arch/x86/kernel/process.c          | 6 ++++++
 drivers/cpuidle/cpuidle-haltpoll.c | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 67c9d73..159ef33 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -862,4 +862,6 @@ bool arch_is_platform_page(u64 paddr);
 #define arch_is_platform_page arch_is_platform_page
 #endif
 
+bool is_mwait_idle(void);
+
 #endif /* _ASM_X86_PROCESSOR_H */
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index c21b734..330972c 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -896,6 +896,12 @@ void select_idle_routine(const struct cpuinfo_x86 *c)
 		x86_idle = default_idle;
 }
 
+bool is_mwait_idle(void)
+{
+	return x86_idle == mwait_idle;
+}
+EXPORT_SYMBOL_GPL(is_mwait_idle);
+
 void amd_e400_c1e_apic_setup(void)
 {
 	if (boot_cpu_has_bug(X86_BUG_AMD_APIC_C1E)) {
diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c
index 3a39a7f..8cf1ddf 100644
--- a/drivers/cpuidle/cpuidle-haltpoll.c
+++ b/drivers/cpuidle/cpuidle-haltpoll.c
@@ -17,6 +17,7 @@
 #include <linux/sched/idle.h>
 #include <linux/kvm_para.h>
 #include <linux/cpuidle_haltpoll.h>
+#include <linux/processor.h>
 
 static bool force __read_mostly;
 module_param(force, bool, 0444);
@@ -111,6 +112,9 @@ static int __init haltpoll_init(void)
 	if (!kvm_para_available() || !haltpoll_want())
 		return -ENODEV;
 
+	if (is_mwait_idle())
+		return -ENODEV;
+
 	cpuidle_poll_state_init(drv);
 
 	ret = cpuidle_register_driver(drv);
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-12-07 12:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-06  6:43 [PATCH] cpuidle-haltpoll: Disable kvm guest polling when mwait_idle is used lirongqing
2022-12-06 11:59 ` Rafael J. Wysocki
2022-12-06 12:08   ` Thomas Gleixner
2022-12-07  3:45     ` Li,Rongqing
2022-12-07 10:49     ` Li,Rongqing
2022-12-07 11:41       ` Thomas Gleixner
2022-12-07 12:18         ` Li,Rongqing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox