]> www.infradead.org Git - users/willy/xarray.git/commitdiff
KVM: x86/pmu: Reuse pmc_perf_hw_id() and drop find_fixed_event()
authorLike Xu <likexu@tencent.com>
Tue, 30 Nov 2021 07:42:18 +0000 (15:42 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 7 Jan 2022 15:44:42 +0000 (10:44 -0500)
Since we set the same semantic event value for the fixed counter in
pmc->eventsel, returning the perf_hw_id for the fixed counter via
find_fixed_event() can be painlessly replaced by pmc_perf_hw_id()
with the help of pmc_is_fixed() check.

Signed-off-by: Like Xu <likexu@tencent.com>
Message-Id: <20211130074221.93635-4-likexu@tencent.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/pmu.c
arch/x86/kvm/pmu.h
arch/x86/kvm/svm/pmu.c
arch/x86/kvm/vmx/pmu_intel.c

index 3b3ccf5b11064f608bcff04a25912ee55271bdb0..b7a1ae28ab872b93f723939dd8bbf8d9695a6104 100644 (file)
@@ -262,7 +262,7 @@ void reprogram_fixed_counter(struct kvm_pmc *pmc, u8 ctrl, int idx)
 
        pmc->current_config = (u64)ctrl;
        pmc_reprogram_counter(pmc, PERF_TYPE_HARDWARE,
-                             kvm_x86_ops.pmu_ops->find_fixed_event(idx),
+                             kvm_x86_ops.pmu_ops->pmc_perf_hw_id(pmc),
                              !(en_field & 0x2), /* exclude user */
                              !(en_field & 0x1), /* exclude kernel */
                              pmi, false, false);
index dd7dbb1c5048d50092d1b8b91b93f3eed30ccc0f..c91d9725aafdf1cac9d89b70e940ac7ed83a1738 100644 (file)
@@ -25,7 +25,6 @@ struct kvm_event_hw_type_mapping {
 
 struct kvm_pmu_ops {
        unsigned int (*pmc_perf_hw_id)(struct kvm_pmc *pmc);
-       unsigned (*find_fixed_event)(int idx);
        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 *(*rdpmc_ecx_to_pmc)(struct kvm_vcpu *vcpu,
index fb0ce8cda8a752af7a0b90cd8e5fffd54ed6cdd5..12d8b301065ab940f0ee3c71d6f0e47d49038fbb 100644 (file)
@@ -144,6 +144,10 @@ static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc)
        u8 unit_mask = (pmc->eventsel & ARCH_PERFMON_EVENTSEL_UMASK) >> 8;
        int i;
 
+       /* return PERF_COUNT_HW_MAX as AMD doesn't have fixed events */
+       if (WARN_ON(pmc_is_fixed(pmc)))
+               return PERF_COUNT_HW_MAX;
+
        for (i = 0; i < ARRAY_SIZE(amd_event_mapping); i++)
                if (amd_event_mapping[i].eventsel == event_select
                    && amd_event_mapping[i].unit_mask == unit_mask)
@@ -155,12 +159,6 @@ static unsigned int amd_pmc_perf_hw_id(struct kvm_pmc *pmc)
        return amd_event_mapping[i].event_type;
 }
 
-/* return PERF_COUNT_HW_MAX as AMD doesn't have fixed events */
-static unsigned amd_find_fixed_event(int idx)
-{
-       return PERF_COUNT_HW_MAX;
-}
-
 /* check if a PMC is enabled by comparing it against global_ctrl bits. Because
  * AMD CPU doesn't have global_ctrl MSR, all PMCs are enabled (return TRUE).
  */
@@ -324,7 +322,6 @@ static void amd_pmu_reset(struct kvm_vcpu *vcpu)
 
 struct kvm_pmu_ops amd_pmu_ops = {
        .pmc_perf_hw_id = amd_pmc_perf_hw_id,
-       .find_fixed_event = amd_find_fixed_event,
        .pmc_is_enabled = amd_pmc_is_enabled,
        .pmc_idx_to_pmc = amd_pmc_idx_to_pmc,
        .rdpmc_ecx_to_pmc = amd_rdpmc_ecx_to_pmc,
index 7b530de7ae232461a5befd84cda90147ac8d447a..5e0ac57d6d1b84f699af816e08d1936bf5d767b6 100644 (file)
@@ -76,9 +76,9 @@ static unsigned int intel_pmc_perf_hw_id(struct kvm_pmc *pmc)
        int i;
 
        for (i = 0; i < ARRAY_SIZE(intel_arch_events); i++)
-               if (intel_arch_events[i].eventsel == event_select
-                   && intel_arch_events[i].unit_mask == unit_mask
-                   && (pmu->available_event_types & (1 << i)))
+               if (intel_arch_events[i].eventsel == event_select &&
+                   intel_arch_events[i].unit_mask == unit_mask &&
+                   (pmc_is_fixed(pmc) || pmu->available_event_types & (1 << i)))
                        break;
 
        if (i == ARRAY_SIZE(intel_arch_events))
@@ -87,18 +87,6 @@ static unsigned int intel_pmc_perf_hw_id(struct kvm_pmc *pmc)
        return intel_arch_events[i].event_type;
 }
 
-static unsigned intel_find_fixed_event(int idx)
-{
-       u32 event;
-       size_t size = ARRAY_SIZE(fixed_pmc_events);
-
-       if (WARN_ON_ONCE(idx >= size))
-               return PERF_COUNT_HW_MAX;
-
-       event = fixed_pmc_events[array_index_nospec(idx, size)];
-       return intel_arch_events[event].event_type;
-}
-
 /* check if a PMC is enabled by comparing it with globl_ctrl bits. */
 static bool intel_pmc_is_enabled(struct kvm_pmc *pmc)
 {
@@ -722,7 +710,6 @@ static void intel_pmu_cleanup(struct kvm_vcpu *vcpu)
 
 struct kvm_pmu_ops intel_pmu_ops = {
        .pmc_perf_hw_id = intel_pmc_perf_hw_id,
-       .find_fixed_event = intel_find_fixed_event,
        .pmc_is_enabled = intel_pmc_is_enabled,
        .pmc_idx_to_pmc = intel_pmc_idx_to_pmc,
        .rdpmc_ecx_to_pmc = intel_rdpmc_ecx_to_pmc,