[PATCH v2] cpuidle-haltpoll: Enable kvm guest polling when dedicated physical CPUs are available

From: Wanpeng Li
Date: Thu Aug 29 2019 - 04:50:08 EST


From: Wanpeng Li <wanpengli@xxxxxxxxxxx>

The downside of guest side polling is that polling is performed even
with other runnable tasks in the host. However, even if poll in kvm
can aware whether or not other runnable tasks in the same pCPU, it
can still incur extra overhead in over-subscribe scenario. Now we can
just enable guest polling when dedicated pCPUs are available.

Acked-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Cc: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
Cc: Radim KrÄmÃÅ <rkrcmar@xxxxxxxxxx>
Signed-off-by: Wanpeng Li <wanpengli@xxxxxxxxxxx>
--
v1 -> v2:
* export kvm_arch_para_hints to fix haltpoll driver build as module error
* just disable haltpoll driver instead of both driver and governor
since KVM_HINTS_REALTIME is not defined in other arches, and governor
doesn't depend on x86, to fix the warning on powerpc

arch/x86/kernel/kvm.c | 1 +
drivers/cpuidle/cpuidle-haltpoll.c | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index f48401b..68463c1 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -711,6 +711,7 @@ unsigned int kvm_arch_para_hints(void)
{
return cpuid_edx(kvm_cpuid_base() | KVM_CPUID_FEATURES);
}
+EXPORT_SYMBOL_GPL(kvm_arch_para_hints);

static uint32_t __init kvm_detect(void)
{
diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-haltpoll.c
index 9ac093d..7aee38a 100644
--- a/drivers/cpuidle/cpuidle-haltpoll.c
+++ b/drivers/cpuidle/cpuidle-haltpoll.c
@@ -53,7 +53,8 @@ static int __init haltpoll_init(void)

cpuidle_poll_state_init(drv);

- if (!kvm_para_available())
+ if (!kvm_para_available() ||
+ !kvm_para_has_hint(KVM_HINTS_REALTIME))
return 0;

ret = cpuidle_register(&haltpoll_driver, NULL);
--
2.7.4