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>
This commit is contained in:
parent
418e5ca88c
commit
6f4d2a0b0b
|
@ -53,6 +53,19 @@ void kvm_pmu_set_counter_value(struct kvm_vcpu *vcpu, u64 select_idx, u64 val)
|
||||||
__vcpu_sys_reg(vcpu, reg) += (s64)val - kvm_pmu_get_counter_value(vcpu, select_idx);
|
__vcpu_sys_reg(vcpu, reg) += (s64)val - kvm_pmu_get_counter_value(vcpu, select_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* kvm_pmu_stop_counter - stop PMU counter
|
||||||
* @pmc: The PMU counter pointer
|
* @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)
|
reg = (pmc->idx == ARMV8_PMU_CYCLE_IDX)
|
||||||
? PMCCNTR_EL0 : PMEVCNTR0_EL0 + pmc->idx;
|
? PMCCNTR_EL0 : PMEVCNTR0_EL0 + pmc->idx;
|
||||||
__vcpu_sys_reg(vcpu, reg) = counter;
|
__vcpu_sys_reg(vcpu, reg) = counter;
|
||||||
perf_event_disable(pmc->perf_event);
|
kvm_pmu_release_perf_event(pmc);
|
||||||
perf_event_release_kernel(pmc->perf_event);
|
|
||||||
pmc->perf_event = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,15 +112,8 @@ void kvm_pmu_vcpu_destroy(struct kvm_vcpu *vcpu)
|
||||||
int i;
|
int i;
|
||||||
struct kvm_pmu *pmu = &vcpu->arch.pmu;
|
struct kvm_pmu *pmu = &vcpu->arch.pmu;
|
||||||
|
|
||||||
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++) {
|
for (i = 0; i < ARMV8_PMU_MAX_COUNTERS; i++)
|
||||||
struct kvm_pmc *pmc = &pmu->pmc[i];
|
kvm_pmu_release_perf_event(&pmu->pmc[i]);
|
||||||
|
|
||||||
if (pmc->perf_event) {
|
|
||||||
perf_event_disable(pmc->perf_event);
|
|
||||||
perf_event_release_kernel(pmc->perf_event);
|
|
||||||
pmc->perf_event = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)
|
u64 kvm_pmu_valid_counter_mask(struct kvm_vcpu *vcpu)
|
||||||
|
|
Loading…
Reference in New Issue