[PATCH] KVM: x86: disable halt polling when powersave governor is used

From: Dapeng Mi
Date: Thu Sep 15 2022 - 03:28:52 EST


Halt polling is enabled by default even through the CPU frequency
governor is configured to powersave. Generally halt polling would
consume extra power and this's not identical with the intent of
powersave governor.

disabling halt polling in powersave governor can save the precious
power in power critical case.

FIO random read test on Alder Lake platform shows halt polling
occupies ~17% CPU utilization and consume 7% extra CPU power.
After disabling halt polling, CPU has more chance to enter deeper
C-states (C1E%: 25.3% -> 33.4%, C10%: 4.4% -> 17.4%).

On Alder Lake platform, we don't find there are obvious performance
downgrade after disabling halt polling on FIO and Netperf cases.
Netperf UDP_RR case runs from two VMs locate on two different physical
machines.

FIO(MB/s) Base Disable-halt-polling Delta%
Rand-read 432.6 436.3 0.8%

Netperf Base Disable-halt-polling Delta%
UDP_RR 509.8 508.5 -0.3%

Signed-off-by: Dapeng Mi <dapeng1.mi@xxxxxxxxx>
---
arch/x86/kvm/x86.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index d7374d768296..c0eb6574cbbb 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -13015,7 +13015,22 @@ bool kvm_vector_hashing_enabled(void)

bool kvm_arch_no_poll(struct kvm_vcpu *vcpu)
{
- return (vcpu->arch.msr_kvm_poll_control & 1) == 0;
+ struct cpufreq_policy *policy = cpufreq_cpu_get(vcpu->cpu);
+ bool powersave = false;
+
+ /*
+ * Halt polling could consume much CPU power, if CPU frequency
+ * governor is set to "powersave", disable halt polling.
+ */
+ if (policy) {
+ if ((policy->policy == CPUFREQ_POLICY_POWERSAVE) ||
+ (policy->governor &&
+ !strncmp(policy->governor->name, "powersave",
+ CPUFREQ_NAME_LEN)))
+ powersave = true;
+ cpufreq_cpu_put(policy);
+ }
+ return ((vcpu->arch.msr_kvm_poll_control & 1) == 0) || powersave;
}
EXPORT_SYMBOL_GPL(kvm_arch_no_poll);

--
2.34.1