KVM: x86/pmu: Refactoring find_arch_event() to pmc_perf_hw_id()
[ Upstream commit 7c174f305cbee6bdba5018aae02b84369e7ab995 ] 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>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
91d8866ca5
commit
99cd2a0437
@@ -171,7 +171,6 @@ static bool pmc_resume_counter(struct kvm_pmc *pmc)
|
|||||||
void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
|
void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
|
||||||
{
|
{
|
||||||
unsigned config, type = PERF_TYPE_RAW;
|
unsigned config, type = PERF_TYPE_RAW;
|
||||||
u8 event_select, unit_mask;
|
|
||||||
struct kvm *kvm = pmc->vcpu->kvm;
|
struct kvm *kvm = pmc->vcpu->kvm;
|
||||||
struct kvm_pmu_event_filter *filter;
|
struct kvm_pmu_event_filter *filter;
|
||||||
int i;
|
int i;
|
||||||
@@ -203,17 +202,12 @@ void reprogram_gp_counter(struct kvm_pmc *pmc, u64 eventsel)
|
|||||||
if (!allow_event)
|
if (!allow_event)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
event_select = eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
|
|
||||||
unit_mask = (eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
|
|
||||||
|
|
||||||
if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE |
|
if (!(eventsel & (ARCH_PERFMON_EVENTSEL_EDGE |
|
||||||
ARCH_PERFMON_EVENTSEL_INV |
|
ARCH_PERFMON_EVENTSEL_INV |
|
||||||
ARCH_PERFMON_EVENTSEL_CMASK |
|
ARCH_PERFMON_EVENTSEL_CMASK |
|
||||||
HSW_IN_TX |
|
HSW_IN_TX |
|
||||||
HSW_IN_TX_CHECKPOINTED))) {
|
HSW_IN_TX_CHECKPOINTED))) {
|
||||||
config = kvm_x86_ops.pmu_ops->find_arch_event(pmc_to_pmu(pmc),
|
config = kvm_x86_ops.pmu_ops->pmc_perf_hw_id(pmc);
|
||||||
event_select,
|
|
||||||
unit_mask);
|
|
||||||
if (config != PERF_COUNT_HW_MAX)
|
if (config != PERF_COUNT_HW_MAX)
|
||||||
type = PERF_TYPE_HARDWARE;
|
type = PERF_TYPE_HARDWARE;
|
||||||
}
|
}
|
||||||
|
@@ -24,8 +24,7 @@ struct kvm_event_hw_type_mapping {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct kvm_pmu_ops {
|
struct kvm_pmu_ops {
|
||||||
unsigned (*find_arch_event)(struct kvm_pmu *pmu, u8 event_select,
|
unsigned int (*pmc_perf_hw_id)(struct kvm_pmc *pmc);
|
||||||
u8 unit_mask);
|
|
||||||
unsigned (*find_fixed_event)(int idx);
|
unsigned (*find_fixed_event)(int idx);
|
||||||
bool (*pmc_is_enabled)(struct kvm_pmc *pmc);
|
bool (*pmc_is_enabled)(struct kvm_pmc *pmc);
|
||||||
struct kvm_pmc *(*pmc_idx_to_pmc)(struct kvm_pmu *pmu, int pmc_idx);
|
struct kvm_pmc *(*pmc_idx_to_pmc)(struct kvm_pmu *pmu, int pmc_idx);
|
||||||
|
@@ -126,10 +126,10 @@ static inline struct kvm_pmc *get_gp_pmc_amd(struct kvm_pmu *pmu, u32 msr,
|
|||||||
return &pmu->gp_counters[msr_to_index(msr)];
|
return &pmu->gp_counters[msr_to_index(msr)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned amd_find_arch_event(struct kvm_pmu *pmu,
|
static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc)
|
||||||
u8 event_select,
|
|
||||||
u8 unit_mask)
|
|
||||||
{
|
{
|
||||||
|
u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
|
||||||
|
u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++)
|
for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++)
|
||||||
@@ -312,7 +312,7 @@ static void amd_pmu_reset(struct kvm_vcpu *vcpu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct kvm_pmu_ops amd_pmu_ops = {
|
struct kvm_pmu_ops amd_pmu_ops = {
|
||||||
.find_arch_event = amd_find_arch_event,
|
.pmc_perf_hw_id = amd_pmc_perf_hw_id,
|
||||||
.find_fixed_event = amd_find_fixed_event,
|
.find_fixed_event = amd_find_fixed_event,
|
||||||
.pmc_is_enabled = amd_pmc_is_enabled,
|
.pmc_is_enabled = amd_pmc_is_enabled,
|
||||||
.pmc_idx_to_pmc = amd_pmc_idx_to_pmc,
|
.pmc_idx_to_pmc = amd_pmc_idx_to_pmc,
|
||||||
|
@@ -68,10 +68,11 @@ static void global_ctrl_changed(struct kvm_pmu *pmu, u64 data)
|
|||||||
reprogram_counter(pmu, bit);
|
reprogram_counter(pmu, bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned intel_find_arch_event(struct kvm_pmu *pmu,
|
static unsigned int intel_pmc_perf_hw_id(struct kvm_pmc *pmc)
|
||||||
u8 event_select,
|
|
||||||
u8 unit_mask)
|
|
||||||
{
|
{
|
||||||
|
struct kvm_pmu *pmu = pmc_to_pmu(pmc);
|
||||||
|
u8 event_select = pmc->eventsel & ARCH_PERFMON_EVENTSEL_EVENT;
|
||||||
|
u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(intel_arch_events); i++)
|
for (i = 0; i < ARRAY_SIZE(intel_arch_events); i++)
|
||||||
@@ -432,7 +433,7 @@ static void intel_pmu_reset(struct kvm_vcpu *vcpu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct kvm_pmu_ops intel_pmu_ops = {
|
struct kvm_pmu_ops intel_pmu_ops = {
|
||||||
.find_arch_event = intel_find_arch_event,
|
.pmc_perf_hw_id = intel_pmc_perf_hw_id,
|
||||||
.find_fixed_event = intel_find_fixed_event,
|
.find_fixed_event = intel_find_fixed_event,
|
||||||
.pmc_is_enabled = intel_pmc_is_enabled,
|
.pmc_is_enabled = intel_pmc_is_enabled,
|
||||||
.pmc_idx_to_pmc = intel_pmc_idx_to_pmc,
|
.pmc_idx_to_pmc = intel_pmc_idx_to_pmc,
|
||||||
|
Reference in New Issue
Block a user