Skip to content

Commit 0144ba0

Browse files
wei-w-wangPeter Zijlstra
authored andcommitted
KVM: x86: use the KVM side max supported fixed counter
KVM vPMU doesn't support to emulate all the fixed counters that the host PMU driver has supported, e.g. the fixed counter 3 used by Topdown metrics hasn't been supported by KVM so far. Rename MAX_FIXED_COUNTERS to KVM_PMC_MAX_FIXED to have a more straightforward naming convention as INTEL_PMC_MAX_FIXED used by the host PMU driver, and fix vPMU to use the KVM side KVM_PMC_MAX_FIXED for the virtual fixed counter emulation, instead of the host side INTEL_PMC_MAX_FIXED. Signed-off-by: Wei Wang <[email protected]> Signed-off-by: Kan Liang <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 2145e77 commit 0144ba0

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ struct kvm_pmc {
498498
bool intr;
499499
};
500500

501+
#define KVM_PMC_MAX_FIXED 3
501502
struct kvm_pmu {
502503
unsigned nr_arch_gp_counters;
503504
unsigned nr_arch_fixed_counters;
@@ -511,7 +512,7 @@ struct kvm_pmu {
511512
u64 reserved_bits;
512513
u8 version;
513514
struct kvm_pmc gp_counters[INTEL_PMC_MAX_GENERIC];
514-
struct kvm_pmc fixed_counters[INTEL_PMC_MAX_FIXED];
515+
struct kvm_pmc fixed_counters[KVM_PMC_MAX_FIXED];
515516
struct irq_work irq_work;
516517
DECLARE_BITMAP(reprogram_pmi, X86_PMC_IDX_MAX);
517518
DECLARE_BITMAP(all_valid_pmc_idx, X86_PMC_IDX_MAX);

arch/x86/kvm/cpuid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function)
875875
eax.split.bit_width = cap.bit_width_gp;
876876
eax.split.mask_length = cap.events_mask_len;
877877

878-
edx.split.num_counters_fixed = min(cap.num_counters_fixed, MAX_FIXED_COUNTERS);
878+
edx.split.num_counters_fixed =
879+
min(cap.num_counters_fixed, KVM_PMC_MAX_FIXED);
879880
edx.split.bit_width_fixed = cap.bit_width_fixed;
880881
if (cap.version)
881882
edx.split.anythread_deprecated = 1;

arch/x86/kvm/pmu.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#define VMWARE_BACKDOOR_PMC_REAL_TIME 0x10001
1616
#define VMWARE_BACKDOOR_PMC_APPARENT_TIME 0x10002
1717

18-
#define MAX_FIXED_COUNTERS 3
19-
2018
struct kvm_event_hw_type_mapping {
2119
u8 eventsel;
2220
u8 unit_mask;

arch/x86/kvm/vmx/pmu_intel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ static void intel_pmu_init(struct kvm_vcpu *vcpu)
565565
pmu->gp_counters[i].current_config = 0;
566566
}
567567

568-
for (i = 0; i < INTEL_PMC_MAX_FIXED; i++) {
568+
for (i = 0; i < KVM_PMC_MAX_FIXED; i++) {
569569
pmu->fixed_counters[i].type = KVM_PMC_FIXED;
570570
pmu->fixed_counters[i].vcpu = vcpu;
571571
pmu->fixed_counters[i].idx = i + INTEL_PMC_IDX_FIXED;
@@ -591,7 +591,7 @@ static void intel_pmu_reset(struct kvm_vcpu *vcpu)
591591
pmc->counter = pmc->eventsel = 0;
592592
}
593593

594-
for (i = 0; i < INTEL_PMC_MAX_FIXED; i++) {
594+
for (i = 0; i < KVM_PMC_MAX_FIXED; i++) {
595595
pmc = &pmu->fixed_counters[i];
596596

597597
pmc_stop_counter(pmc);

arch/x86/kvm/x86.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6514,7 +6514,7 @@ static void kvm_init_msr_list(void)
65146514
u32 dummy[2];
65156515
unsigned i;
65166516

6517-
BUILD_BUG_ON_MSG(INTEL_PMC_MAX_FIXED != 4,
6517+
BUILD_BUG_ON_MSG(KVM_PMC_MAX_FIXED != 3,
65186518
"Please update the fixed PMCs in msrs_to_saved_all[]");
65196519

65206520
perf_get_x86_pmu_capability(&x86_pmu);

0 commit comments

Comments
 (0)