Skip to contentSkip to conversation

KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]

PATCH Applied Like Xu 4 participants 6 messages Dec 30, 2020 – Jan 20, 2021

Subsystems (3)
lore
Share & tools
lore

Like Xu

author
#0 lore raw

PATCH 1/1 KVM: x86/pmu: Fix HW_REF_CPU_CYCLES event pseudo-encoding in intel_arch_events[]

The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as 0x0300 in the intel_perfmon_event_map[]. Correct its usage.

Fixes 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
---
 arch/x86/kvm/vmx/pmu_intel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/pmu_intel.c +1 -1
index a886a47daebd..013e8d253dfa 100644
@@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
 	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
 	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
 	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
-	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
+	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
 };
 
 /* mapping between fixed pmc index and intel_arch_events array */
Signature · 1 line
2.29.2
author
#1 lore raw

Ping ?

Quoted 22 lines · Like Xu

The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as 0x0300 in the intel_perfmon_event_map[]. Correct its usage.

Fixes 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
---
  arch/x86/kvm/vmx/pmu_intel.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/pmu_intel.c +1 -1
index a886a47daebd..013e8d253dfa 100644
@@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
  	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
  	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
  	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
-	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
+	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
  };
 
  /* mapping between fixed pmc index and intel_arch_events array */
maintainer Reviewed-by
#2 lore raw
Quoted 8 lines · Like Xu

Ping ?

Quoted 5 lines · Like Xu

The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as 0x0300 in the intel_perfmon_event_map[]. Correct its usage.

Fixes 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
Quoted 4 lines
Quoted 4 lines
---
  arch/x86/kvm/vmx/pmu_intel.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines

arch/x86/kvm/vmx/pmu_intel.c static struct kvm_event_hw_type_mapping intel_arch_events[] = { · line 32

Quoted 10 lines
arch/x86/kvm/vmx/pmu_intel.c +1 -1
index a886a47daebd..013e8d253dfa 100644
@@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
  	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
  	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
  	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
-	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
+	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },

In a follow up patch, would it be sane/appropriate to define these magic numbers in asm/perf_event.h and share them between intel_perfmon_event_map and intel_arch_events? Without this patch, it's not at all obvious that these are intended to align with the Core (arch?) event definitions.

Quoted 3 lines
Quoted 2 lines
arch/x86/kvm/vmx/pmu_intel.c +0 -0
  };
  /* mapping between fixed pmc index and intel_arch_events array */
#3 lore raw
Quoted 10 lines · Sean Christopherson
Quoted 8 lines · Like Xu

Ping ?

Quoted 5 lines · Like Xu

The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as 0x0300 in the intel_perfmon_event_map[]. Correct its usage.

Fixes 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")

thx.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
---
   arch/x86/kvm/vmx/pmu_intel.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
Quoted 10 lines

arch/x86/kvm/vmx/pmu_intel.c static struct kvm_event_hw_type_mapping intel_arch_events[] = { · line 32

Quoted 10 lines
arch/x86/kvm/vmx/pmu_intel.c +1 -1
index a886a47daebd..013e8d253dfa 100644
@@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
   	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
   	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
   	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
-	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
+	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },

In a follow up patch, would it be sane/appropriate to define these magic numbers in asm/perf_event.h and share them between intel_perfmon_event_map and intel_arch_events? Without this patch, it's not at all obvious that these are intended to align with the Core (arch?) event definitions.

The asm/perf_event.h is x86 generic and svm has a amd_perfmon_event_map.

How about adding an interface similar to perf_get_x86_pmu_capability() so that we can use magic numbers directly from the host perf ? (it looks we may have a performance drop, compared to static array)

---
thx, likexu

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
arch/x86/kvm/vmx/pmu_intel.c +0 -0
   };
   /* mapping between fixed pmc index and intel_arch_events array */
#4 lore raw
Quoted 17 lines · Like
Quoted 15 lines · Sean Christopherson
Quoted 10 lines · Like Xu

arch/x86/kvm/vmx/pmu_intel.c static struct kvm_event_hw_type_mapping intel_arch_events[] = { · line 32

Quoted 10 lines
arch/x86/kvm/vmx/pmu_intel.c +1 -1
index a886a47daebd..013e8d253dfa 100644
@@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
   	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
   	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
   	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
-	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
+	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },

In a follow up patch, would it be sane/appropriate to define these magic numbers in asm/perf_event.h and share them between intel_perfmon_event_map and intel_arch_events? Without this patch, it's not at all obvious that these are intended to align with the Core (arch?) event definitions.

Quoted 1 line

The asm/perf_event.h is x86 generic and svm has a amd_perfmon_event_map.

Ugh, duh.

Quoted 3 lines

How about adding an interface similar to perf_get_x86_pmu_capability() so that we can use magic numbers directly from the host perf ? (it looks we may have a performance drop, compared to static array)

Alternatively, you could use the existing event_map() to generate intel_arch_events[] during init. That might be easier since, AFAICT, the array indices have different meaning for KVM than for perf.

Honestly, unless there are going to be new arch events in the near-ish future, it may not be worth the effort at this point. Until now, the above table hadn't changed in over five years. I.e. don't put a bunch of effort into this unless you want to :-)

maintainer Applied
#5 lore raw
In reply to Like Xu
Quoted 15 lines · Like Xu

The HW_REF_CPU_CYCLES event on the fixed counter 2 is pseudo-encoded as 0x0300 in the intel_perfmon_event_map[]. Correct its usage.

Fixes 62079d8a4312 ("KVM: PMU: add proper support for fixed counter 2")
---
  arch/x86/kvm/vmx/pmu_intel.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/pmu_intel.c +0 -0
index a886a47daebd..013e8d253dfa 100644

arch/x86/kvm/vmx/pmu_intel.c static struct kvm_event_hw_type_mapping intel_arch_events[] = { · line 35

Quoted 8 lines
arch/x86/kvm/vmx/pmu_intel.c +1 -1
@@ -29,7 +29,7 @@ static struct kvm_event_hw_type_mapping intel_arch_events[] = {
  	[4] = { 0x2e, 0x41, PERF_COUNT_HW_CACHE_MISSES },
  	[5] = { 0xc4, 0x00, PERF_COUNT_HW_BRANCH_INSTRUCTIONS },
  	[6] = { 0xc5, 0x00, PERF_COUNT_HW_BRANCH_MISSES },
-	[7] = { 0x00, 0x30, PERF_COUNT_HW_REF_CPU_CYCLES },
+	[7] = { 0x00, 0x03, PERF_COUNT_HW_REF_CPU_CYCLES },
  };
 
  /* mapping between fixed pmc index and intel_arch_events array */

Queued, thanks.

Paolo