Skip to content

Commit 7618756

Browse files
lkml-likexubonzini
authored andcommitted
KVM: x86/pmu: Setup pmc->eventsel for fixed PMCs
The current pmc->eventsel for fixed counter is underutilised. The pmc->eventsel can be setup for all known available fixed counters since we have mapping between fixed pmc index and the intel_arch_events array. Either gp or fixed counter, it will simplify the later checks for consistency between eventsel and perf_hw_id. Signed-off-by: Like Xu <likexu@tencent.com> Message-Id: <20211130074221.93635-2-likexu@tencent.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 006a0f0 commit 7618756

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎arch/x86/kvm/vmx/pmu_intel.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,21 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
459459
return 1;
460460
}
461461

462+
static void setup_fixed_pmc_eventsel(struct kvm_pmu *pmu)
463+
{
464+
size_t size = ARRAY_SIZE(fixed_pmc_events);
465+
struct kvm_pmc *pmc;
466+
u32 event;
467+
int i;
468+
469+
for (i = 0; i < pmu->nr_arch_fixed_counters; i++) {
470+
pmc = &pmu->fixed_counters[i];
471+
event = fixed_pmc_events[array_index_nospec(i, size)];
472+
pmc->eventsel = (intel_arch_events[event].unit_mask << 8) |
473+
intel_arch_events[event].eventsel;
474+
}
475+
}
476+
462477
static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
463478
{
464479
struct kvm_pmu *pmu = vcpu_to_pmu(vcpu);
@@ -507,6 +522,7 @@ static void intel_pmu_refresh(struct kvm_vcpu *vcpu)
507522
edx.split.bit_width_fixed, x86_pmu.bit_width_fixed);
508523
pmu->counter_bitmask[KVM_PMC_FIXED] =
509524
((u64)1 << edx.split.bit_width_fixed) - 1;
525+
setup_fixed_pmc_eventsel(pmu);
510526
}
511527

512528
pmu->global_ctrl = ((1ull << pmu->nr_arch_gp_counters) - 1) |

0 commit comments

Comments
 (0)