Skip to content

Commit 99cd2a0

Browse files
lkml-likexugregkh
authored andcommitted
KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id()
[ Upstream commit 7c174f3 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 91d8866 commit 99cd2a0

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
@@ -171,7 +171,6 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)
171171
void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
172172
{
173173
unsigned config, type = PERF_TYPE_RAW;
174-
u8 event_select, unit_mask;
175174
struct kvm *kvm = pmc->vcpu->kvm;
176175
struct kvm_pmu_event_filter *filter;
177176
int i;
@@ -203,17 +202,12 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
203202
if (!allow_event)
204203
return;
205204

206-
event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
207-
unit_mask = (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
208-
209205
if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE |
210206
ARCH_PERFMON_EVENTSEL_INV |
211207
ARCH_PERFMON_EVENTSEL_CMASK |
212208
HSW_IN_TX |
213209
HSW_IN_TX_CHECKPOINTED))) {
214-
config = kvm_x86_ops.pmu_ops->find_arch_event(pmc_to_pmu(pmc),
215-
event_select,
216-
unit_mask);
210+
config = kvm_x86_ops.pmu_ops->pmc_perf_hw_id(pmc);
217211
if (config != PERF_COUNT_HW_MAX)
218212
type = PERF_TYPE_HARDWARE;
219213
}

‎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
@@ -126,10 +126,10 @@ static inline struct kvm_pmc *get_gp_pmc_amd(struct kvm_pmu *pmu, u32 msr,
126126
return &pmu->gp_counters[msr_to_index(msr)];
127127
}
128128

129-
static unsigned amd_find_arch_event(struct kvm_pmu *pmu,
130-
u8 event_select,
131-
u8 unit_mask)
129+
static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc)
132130
{
131+
u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
132+
u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
133133
int i;
134134

135135
for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++)
@@ -312,7 +312,7 @@ static void amd_pmu_reset(struct kvm_vcpu *vcpu)
312312
}
313313

314314
struct kvm_pmu_ops amd_pmu_ops = {
315-
.find_arch_event = amd_find_arch_event,
315+
.pmc_perf_hw_id = amd_pmc_perf_hw_id,
316316
.find_fixed_event = amd_find_fixed_event,
317317
.pmc_is_enabled = amd_pmc_is_enabled,
318318
.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++)
@@ -432,7 +433,7 @@ static void intel_pmu_reset(struct kvm_vcpu *vcpu)
432433
}
433434

434435
struct kvm_pmu_ops intel_pmu_ops = {
435-
.find_arch_event = intel_find_arch_event,
436+
.pmc_perf_hw_id = intel_pmc_perf_hw_id,
436437
.find_fixed_event = intel_find_fixed_event,
437438
.pmc_is_enabled = intel_pmc_is_enabled,
438439
.pmc_idx_to_pmc = intel_pmc_idx_to_pmc,

0 commit comments

Comments
 (0)