[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241203193220.1070811-7-oliver.upton@linux.dev>
Date: Tue, 3 Dec 2024 11:32:12 -0800
From: Oliver Upton <oliver.upton@...ux.dev>
To: kvmarm@...ts.linux.dev
Cc: Marc Zyngier <maz@...nel.org>,
Joey Gouly <joey.gouly@....com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Zenghui Yu <yuzenghui@...wei.com>,
Mingwei Zhang <mizhang@...gle.com>,
Colton Lewis <coltonlewis@...gle.com>,
Raghavendra Rao Ananta <rananta@...gle.com>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Mark Rutland <mark.rutland@....com>,
linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Oliver Upton <oliver.upton@...ux.dev>
Subject: [RFC PATCH 06/14] KVM: arm64: Use PERF_COUNT_HW_CPU_CYCLES for fixed cycle counter
KVM will soon be able to emulate PMUv3 on non-PMUv3 hardware. Use the
generic event for CPU cycles to allow a non-PMUv3 driver to map the
event correctly on underlying hardware.
Signed-off-by: Oliver Upton <oliver.upton@...ux.dev>
---
arch/arm64/kvm/pmu-emul.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c
index 3e7091e1a2e4..0b2ad60717e8 100644
--- a/arch/arm64/kvm/pmu-emul.c
+++ b/arch/arm64/kvm/pmu-emul.c
@@ -700,16 +700,27 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
{
struct kvm_vcpu *vcpu = kvm_pmc_to_vcpu(pmc);
struct arm_pmu *arm_pmu = vcpu->kvm->arch.arm_pmu;
+ struct perf_event_attr attr = {};
struct perf_event *event;
- struct perf_event_attr attr;
u64 eventsel, evtreg;
evtreg = kvm_pmc_read_evtreg(pmc);
kvm_pmu_stop_counter(pmc);
if (pmc->idx == ARMV8_PMU_CYCLE_IDX) {
- eventsel = ARMV8_PMUV3_PERFCTR_CPU_CYCLES;
+ /*
+ * Use the common event space for the cycle counter, allowing
+ * the underlying PMU driver to map it onto hardware in the
+ * unlikely case the host doesn't actually have PMUv3.
+ */
+ attr.type = PERF_TYPE_HARDWARE;
+ eventsel = PERF_COUNT_HW_CPU_CYCLES;
} else {
+ /*
+ * Otherwise, treat the event as a raw event for the selected
+ * PMU.
+ */
+ attr.type = arm_pmu->pmu.type;
eventsel = evtreg & kvm_pmu_event_mask(vcpu->kvm);
/*
@@ -729,8 +740,6 @@ static void kvm_pmu_create_perf_event(struct kvm_pmc *pmc)
return;
}
- memset(&attr, 0, sizeof(struct perf_event_attr));
- attr.type = arm_pmu->pmu.type;
attr.size = sizeof(attr);
attr.pinned = 1;
attr.disabled = !kvm_pmu_counter_is_enabled(pmc);
--
2.39.5
Powered by blists - more mailing lists