summaryrefslogtreecommitdiffstats
path: root/virt
diff options
context:
space:
mode:
authorAndrew Murray <andrew.murray@arm.com>2019-06-17 20:01:02 +0100
committerMarc Zyngier <marc.zyngier@arm.com>2019-07-05 13:56:10 +0100
commit6f4d2a0b0b1e9a1f7594e666eebad98372901818 (patch)
treee488b33e4a4968eb9559842778ecc0a14d65cf7a /virt
parent418e5ca88cc18b7e9eaafa40eac26397ccd66a71 (diff)
downloadlinux-6f4d2a0b0b1e9a1f7594e666eebad98372901818.tar.gz
linux-6f4d2a0b0b1e9a1f7594e666eebad98372901818.tar.bz2
linux-6f4d2a0b0b1e9a1f7594e666eebad98372901818.zip
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)
}
/**
+ * kvm_pmu_release_perf_event - remove the perf event
+ * @pmc: The PMU counter pointer
+ */
+static void kvm_pmu_release_perf_event(struct kvm_pmc *pmc)
+{
+ if (pmc->perf_event) {
+ perf_event_disable(pmc->perf_event);
+ perf_event_release_kernel(pmc->perf_event);
+ pmc->perf_event = NULL;
+ }
+}
+
+/**
* kvm_pmu_stop_counter - stop PMU counter
* @pmc: The PMU counter pointer
*
@@ -68,9 +81,7 @@ static void kvm_pmu_stop_counter(struct kvm_vcpu *vcpu, struct kvm_pmc *pmc)
reg = (pmc->idx == ARMV8_PMU_CYCLE_IDX)
? PMCCNTR_EL0 : PMEVCNTR0_EL0 + pmc->idx;
__vcpu_sys_reg(vcpu, reg) = counter;
- perf_event_disable(pmc->perf_event);
- perf_event_release_kernel(pmc->perf_event);
- pmc->perf_event = NULL;
+ kvm_pmu_release_perf_event(pmc);
}
}
@@ -101,15 +112,8 @@ void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu)
int i;
struct kvm_pmu *pmu = &vcpu->arch.pmu;
- for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
- struct kvm_pmc *pmc = &pmu->pmc[i];
-
- if (pmc->perf_event) {
- perf_event_disable(pmc->perf_event);
- perf_event_release_kernel(pmc->perf_event);
- pmc->perf_event = NULL;
- }
- }
+ for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
+ kvm_pmu_release_perf_event(&pmu->pmc[i]);
}
u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)