Skip to content

Commit 126d7d7

Browse files
robherringwilldeacon
authored andcommitted
arm64: perf/kvm: Use a common PMU cycle counter define
The PMUv3 and KVM code each have a define for the PMU cycle counter index. Move KVM's define to a shared location and use it for PMUv3 driver. Reviewed-by: Marc Zyngier <maz@kernel.org> Acked-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Rob Herring (Arm) <robh@kernel.org> Tested-by: James Clark <james.clark@linaro.org> Link: https://lore.kernel.org/r/20240731-arm-pmu-3-9-icntr-v3-5-280a8d7ff465@kernel.org Signed-off-by: Will Deacon <will@kernel.org>
1 parent f9b11aa commit 126d7d7

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

arch/arm64/kvm/sys_regs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/printk.h>
1919
#include <linux/uaccess.h>
2020

21+
#include <asm/arm_pmuv3.h>
2122
#include <asm/cacheflush.h>
2223
#include <asm/cputype.h>
2324
#include <asm/debug-monitors.h>

drivers/perf/arm_pmuv3.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,6 @@ static const struct attribute_group armv8_pmuv3_caps_attr_group = {
451451
.attrs = armv8_pmuv3_caps_attrs,
452452
};
453453

454-
/*
455-
* Perf Events' indices
456-
*/
457-
#define ARMV8_IDX_CYCLE_COUNTER 31
458-
459454
/*
460455
* We unconditionally enable ARMv8.5-PMU long event counter support
461456
* (64-bit events) where supported. Indicate if this arm_pmu has long
@@ -574,7 +569,7 @@ static u64 armv8pmu_read_counter(struct perf_event *event)
574569
int idx = hwc->idx;
575570
u64 value;
576571

577-
if (idx == ARMV8_IDX_CYCLE_COUNTER)
572+
if (idx == ARMV8_PMU_CYCLE_IDX)
578573
value = read_pmccntr();
579574
else
580575
value = armv8pmu_read_hw_counter(event);
@@ -607,7 +602,7 @@ static void armv8pmu_write_counter(struct perf_event *event, u64 value)
607602

608603
value = armv8pmu_bias_long_counter(event, value);
609604

610-
if (idx == ARMV8_IDX_CYCLE_COUNTER)
605+
if (idx == ARMV8_PMU_CYCLE_IDX)
611606
write_pmccntr(value);
612607
else
613608
armv8pmu_write_hw_counter(event, value);
@@ -644,7 +639,7 @@ static void armv8pmu_write_event_type(struct perf_event *event)
644639
armv8pmu_write_evtype(idx - 1, hwc->config_base);
645640
armv8pmu_write_evtype(idx, chain_evt);
646641
} else {
647-
if (idx == ARMV8_IDX_CYCLE_COUNTER)
642+
if (idx == ARMV8_PMU_CYCLE_IDX)
648643
write_pmccfiltr(hwc->config_base);
649644
else
650645
armv8pmu_write_evtype(idx, hwc->config_base);
@@ -772,7 +767,7 @@ static void armv8pmu_enable_user_access(struct arm_pmu *cpu_pmu)
772767
/* Clear any unused counters to avoid leaking their contents */
773768
for_each_andnot_bit(i, cpu_pmu->cntr_mask, cpuc->used_mask,
774769
ARMPMU_MAX_HWEVENTS) {
775-
if (i == ARMV8_IDX_CYCLE_COUNTER)
770+
if (i == ARMV8_PMU_CYCLE_IDX)
776771
write_pmccntr(0);
777772
else
778773
armv8pmu_write_evcntr(i, 0);
@@ -933,8 +928,8 @@ static int armv8pmu_get_event_idx(struct pmu_hw_events *cpuc,
933928
/* Always prefer to place a cycle counter into the cycle counter. */
934929
if ((evtype == ARMV8_PMUV3_PERFCTR_CPU_CYCLES) &&
935930
!armv8pmu_event_get_threshold(&event->attr)) {
936-
if (!test_and_set_bit(ARMV8_IDX_CYCLE_COUNTER, cpuc->used_mask))
937-
return ARMV8_IDX_CYCLE_COUNTER;
931+
if (!test_and_set_bit(ARMV8_PMU_CYCLE_IDX, cpuc->used_mask))
932+
return ARMV8_PMU_CYCLE_IDX;
938933
else if (armv8pmu_event_is_64bit(event) &&
939934
armv8pmu_event_want_user_access(event) &&
940935
!armv8pmu_has_long_event(cpu_pmu))
@@ -1196,7 +1191,7 @@ static void __armv8pmu_probe_pmu(void *info)
11961191
0, FIELD_GET(ARMV8_PMU_PMCR_N, armv8pmu_pmcr_read()));
11971192

11981193
/* Add the CPU cycles counter */
1199-
set_bit(ARMV8_IDX_CYCLE_COUNTER, cpu_pmu->cntr_mask);
1194+
set_bit(ARMV8_PMU_CYCLE_IDX, cpu_pmu->cntr_mask);
12001195

12011196
pmceid[0] = pmceid_raw[0] = read_pmceid0();
12021197
pmceid[1] = pmceid_raw[1] = read_pmceid1();

include/kvm/arm_pmu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/perf_event.h>
1111
#include <linux/perf/arm_pmuv3.h>
1212

13-
#define ARMV8_PMU_CYCLE_IDX (ARMV8_PMU_MAX_COUNTERS - 1)
1413

1514
#if IS_ENABLED(CONFIG_HW_PERF_EVENTS) && IS_ENABLED(CONFIG_KVM)
1615
struct kvm_pmc {

include/linux/perf/arm_pmuv3.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#define ARMV8_PMU_MAX_GENERAL_COUNTERS 31
1010
#define ARMV8_PMU_MAX_COUNTERS 32
1111

12+
#define ARMV8_PMU_CYCLE_IDX 31
13+
14+
1215
/*
1316
* Common architectural and microarchitectural event numbers.
1417
*/

0 commit comments

Comments
 (0)