diff mbox series

[v3,8/8] KVM: x86/cpuid: Use fast return for cpuid "0xa" leaf when !enable_pmu

Message ID 20221111102645.82001-9-likexu@tencent.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: Add AMD Guest PerfMonV2 PMU support | expand

Commit Message

Like Xu Nov. 11, 2022, 10:26 a.m. UTC
From: Like Xu <likexu@tencent.com>

Although when !enable_pmu, KVM will have zero-padded kvm_pmu_cap to do
subsequent cpuid leaf assignments, one extra branch instruction saves
a few subsequent zero-assignment instructions, speeding things up a bit.

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Like Xu <likexu@tencent.com>
---
 arch/x86/kvm/cpuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Sean Christopherson Jan. 20, 2023, 1:11 a.m. UTC | #1
On Fri, Nov 11, 2022, Like Xu wrote:
> From: Like Xu <likexu@tencent.com>
> 
> Although when !enable_pmu, KVM will have zero-padded kvm_pmu_cap to do
> subsequent cpuid leaf assignments, one extra branch instruction saves
> a few subsequent zero-assignment instructions, speeding things up a bit.

I doubt my motivation was performance, I'm guessing I suggested adding the explicit
!enable_pmu check because relying on kvm_pmu_cap to be zeroed isn't obvious.
diff mbox series

Patch

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index df551fa66ccc..719290ff6d77 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -922,7 +922,7 @@  static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
 		union cpuid10_eax eax;
 		union cpuid10_edx edx;
 
-		if (!static_cpu_has(X86_FEATURE_ARCH_PERFMON)) {
+		if (!enable_pmu || !static_cpu_has(X86_FEATURE_ARCH_PERFMON)) {
 			entry->eax = entry->ebx = entry->ecx = entry->edx = 0;
 			break;
 		}