aboutsummaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorAndrew Murray <andrew.murray@arm.com>2019-06-17 15:01:02 -0400
committerMarc Zyngier <marc.zyngier@arm.com>2019-07-05 08:56:10 -0400
commit6f4d2a0b0b1e9a1f7594e666eebad98372901818 (patch)
treee488b33e4a4968eb9559842778ecc0a14d65cf7a /virt
parent418e5ca88cc18b7e9eaafa40eac26397ccd66a71 (diff)
KVM: arm/arm64: Extract duplicated code to own function
Let's reduce code duplication by extracting common code to its own function. Signed-off-by: Andrew Murray <andrew.murray@arm.com> Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'virt')
-rw-r--r--virt/kvm/arm/pmu.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c
index 99e51ee8fd9e..efdc7f6db6cd 100644
--- a/virt/kvm/arm/pmu.c
+++ b/virt/kvm/arm/pmu.c
@@ -54,6 +54,19 @@ void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val)
54} 54}
55 55
56/** 56/**
57 * kvm_pmu_release_perf_event - remove the perf event
58 * @pmc: The PMU counter pointer
59 */
60static void kvm_pmu_release_perf_event(struct kvm_pmc *pmc)
61{
62 if (pmc->perf_event) {
63 perf_event_disable(pmc->perf_event);
64 perf_event_release_kernel(pmc->perf_event);
65 pmc->perf_event = NULL;
66 }
67}
68
69/**
57 * kvm_pmu_stop_counter - stop PMU counter 70 * kvm_pmu_stop_counter - stop PMU counter
58 * @pmc: The PMU counter pointer 71 * @pmc: The PMU counter pointer
59 * 72 *
@@ -68,9 +81,7 @@ static void kvm_pmu_stop_counter(struct kvm_vcpu *vcpu, struct kvm_pmc *pmc)
68 reg = (pmc->idx == ARMV8_PMU_CYCLE_IDX) 81 reg = (pmc->idx == ARMV8_PMU_CYCLE_IDX)
69 ? PMCCNTR_EL0 : PMEVCNTR0_EL0 + pmc->idx; 82 ? PMCCNTR_EL0 : PMEVCNTR0_EL0 + pmc->idx;
70 __vcpu_sys_reg(vcpu, reg) = counter; 83 __vcpu_sys_reg(vcpu, reg) = counter;
71 perf_event_disable(pmc->perf_event); 84 kvm_pmu_release_perf_event(pmc);
72 perf_event_release_kernel(pmc->perf_event);
73 pmc->perf_event = NULL;
74 } 85 }
75} 86}
76 87
@@ -101,15 +112,8 @@ void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu)
101 int i; 112 int i;
102 struct kvm_pmu *pmu = &vcpu->arch.pmu; 113 struct kvm_pmu *pmu = &vcpu->arch.pmu;
103 114
104 for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) { 115 for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
105 struct kvm_pmc *pmc = &pmu->pmc[i]; 116 kvm_pmu_release_perf_event(&pmu->pmc[i]);
106
107 if (pmc->perf_event) {
108 perf_event_disable(pmc->perf_event);
109 perf_event_release_kernel(pmc->perf_event);
110 pmc->perf_event = NULL;
111 }
112 }
113} 117}
114 118
115u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu) 119u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)