Skip to content

Commit 7c174f3

Browse files
lkml-likexubonzini
authored andcommitted
KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id()
The find_arch_event() returns a "unsigned int" value, which is used by the pmc_reprogram_counter() to program a PERF_TYPE_HARDWARE type perf_event. The returned value is actually the kernel defined generic perf_hw_id, let's rename it to pmc_perf_hw_id() with simpler incoming parameters for better self-explanation. Signed-off-by: Like Xu <likexu@tencent.com> Message-Id: <20211130074221.93635-3-likexu@tencent.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 7618756 commit 7c174f3

4 files changed

Lines changed: 11 additions & 17 deletions

File tree

‎arch/x86/kvm/pmu.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)
174174
void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
175175
{
176176
unsigned config, type = PERF_TYPE_RAW;
177-
u8 event_select, unit_mask;
178177
struct kvm *kvm = pmc->vcpu->kvm;
179178
struct kvm_pmu_event_filter *filter;
180179
int i;
@@ -206,17 +205,12 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
206205
if (!allow_event)
207206
return;
208207

209-
event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
210-
unit_mask = (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
211-
212208
if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE |
213209
ARCH_PERFMON_EVENTSEL_INV |
214210
ARCH_PERFMON_EVENTSEL_CMASK |
215211
HSW_IN_TX |
216212
HSW_IN_TX_CHECKPOINTED))) {
217-
config = kvm_x86_ops.pmu_ops->find_arch_event(pmc_to_pmu(pmc),
218-
event_select,
219-
unit_mask);
213+
config = kvm_x86_ops.pmu_ops->pmc_perf_hw_id(pmc);
220214
if (config != PERF_COUNT_HW_MAX)
221215
type = PERF_TYPE_HARDWARE;
222216
}

‎arch/x86/kvm/pmu.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ struct kvm_event_hw_type_mapping {
2424
};
2525

2626
struct kvm_pmu_ops {
27-
unsigned (*find_arch_event)(struct kvm_pmu *pmu, u8 event_select,
28-
u8 unit_mask);
27+
unsigned int (*pmc_perf_hw_id)(struct kvm_pmc *pmc);
2928
unsigned (*find_fixed_event)(int idx);
3029
bool (*pmc_is_enabled)(struct kvm_pmc *pmc);
3130
struct kvm_pmc *(*pmc_idx_to_pmc)(struct kvm_pmu *pmu, int pmc_idx);

‎arch/x86/kvm/svm/pmu.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ static inline struct kvm_pmc *get_gp_pmc_amd(struct kvm_pmu *pmu, u32 msr,
138138
return &pmu->gp_counters[msr_to_index(msr)];
139139
}
140140

141-
static unsigned amd_find_arch_event(struct kvm_pmu *pmu,
142-
u8 event_select,
143-
u8 unit_mask)
141+
static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc)
144142
{
143+
u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
144+
u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
145145
int i;
146146

147147
for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++)
@@ -323,7 +323,7 @@ static void amd_pmu_reset(struct kvm_vcpu *vcpu)
323323
}
324324

325325
struct kvm_pmu_ops amd_pmu_ops = {
326-
.find_arch_event = amd_find_arch_event,
326+
.pmc_perf_hw_id = amd_pmc_perf_hw_id,
327327
.find_fixed_event = amd_find_fixed_event,
328328
.pmc_is_enabled = amd_pmc_is_enabled,
329329
.pmc_idx_to_pmc = amd_pmc_idx_to_pmc,

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ static void global_ctrl_changed(struct kvm_pmu *pmu, u64 data)
6868
reprogram_counter(pmu, bit);
6969
}
7070

71-
static unsigned intel_find_arch_event(struct kvm_pmu *pmu,
72-
u8 event_select,
73-
u8 unit_mask)
71+
static unsigned int intel_pmc_perf_hw_id(struct kvm_pmc *pmc)
7472
{
73+
struct kvm_pmu *pmu = pmc_to_pmu(pmc);
74+
u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
75+
u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
7576
int i;
7677

7778
for (i = 0; i < ARRAY_SIZE(intel_arch_events); i++)
@@ -720,7 +721,7 @@ static void intel_pmu_cleanup(struct kvm_vcpu *vcpu)
720721
}
721722

722723
struct kvm_pmu_ops intel_pmu_ops = {
723-
.find_arch_event = intel_find_arch_event,
724+
.pmc_perf_hw_id = intel_pmc_perf_hw_id,
724725
.find_fixed_event = intel_find_fixed_event,
725726
.pmc_is_enabled = intel_pmc_is_enabled,
726727
.pmc_idx_to_pmc = intel_pmc_idx_to_pmc,

0 commit comments

Comments
 (0)