Skip to content

Commit 61d0386

Browse files
mrutland-armwilldeacon
authored andcommitted
arm_pmu: fix event CPU filtering
Janne reports that perf has been broken on Apple M1 as of commit: bd27568 ("perf: Rewrite core context handling") That commit replaced the pmu::filter_match() callback with pmu::filter(), whose return value has the opposite polarity, with true implying events should be ignored rather than scheduled. While an attempt was made to update the logic in armv8pmu_filter() and armpmu_filter() accordingly, the return value remains inverted in a couple of cases: * If the arm_pmu does not have an arm_pmu::filter() callback, armpmu_filter() will always return whether the CPU is supported rather than whether the CPU is not supported. As a result, the perf core will not schedule events on supported CPUs, resulting in a loss of events. Additionally, the perf core will attempt to schedule events on unsupported CPUs, but this will be rejected by armpmu_add(), which may result in a loss of events from other PMUs on those unsupported CPUs. * If the arm_pmu does have an arm_pmu::filter() callback, and armpmu_filter() is called on a CPU which is not supported by the arm_pmu, armpmu_filter() will return false rather than true. As a result, the perf core will attempt to schedule events on unsupported CPUs, but this will be rejected by armpmu_add(), which may result in a loss of events from other PMUs on those unsupported CPUs. This means a loss of events can be seen with any arm_pmu driver, but with the ARMv8 PMUv3 driver (which is the only arm_pmu driver with an arm_pmu::filter() callback) the event loss will be more limited and may go unnoticed, which is how this issue evaded testing so far. Fix the CPU filtering by performing this consistently in armpmu_filter(), and remove the redundant arm_pmu::filter() callback and armv8pmu_filter() implementation. Commit bd27568 also silently removed the CHAIN event filtering from armv8pmu_filter(), which will be addressed by a separate patch without using the filter callback. Fixes: bd27568 ("perf: Rewrite core context handling") Reported-by: Janne Grunau <[email protected]> Link: https://lore.kernel.org/asahi/[email protected]/ Signed-off-by: Mark Rutland <[email protected]> Cc: Will Deacon <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Asahi Lina <[email protected]> Cc: Eric Curtin <[email protected]> Tested-by: Janne Grunau <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent a428eb4 commit 61d0386

File tree

3 files changed

+1
-15
lines changed

3 files changed

+1
-15
lines changed

arch/arm64/kernel/perf_event.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,12 +1023,6 @@ static int armv8pmu_set_event_filter(struct hw_perf_event *event,
10231023
return 0;
10241024
}
10251025

1026-
static bool armv8pmu_filter(struct pmu *pmu, int cpu)
1027-
{
1028-
struct arm_pmu *armpmu = to_arm_pmu(pmu);
1029-
return !cpumask_test_cpu(smp_processor_id(), &armpmu->supported_cpus);
1030-
}
1031-
10321026
static void armv8pmu_reset(void *info)
10331027
{
10341028
struct arm_pmu *cpu_pmu = (struct arm_pmu *)info;
@@ -1258,7 +1252,6 @@ static int armv8_pmu_init(struct arm_pmu *cpu_pmu, char *name,
12581252
cpu_pmu->stop = armv8pmu_stop;
12591253
cpu_pmu->reset = armv8pmu_reset;
12601254
cpu_pmu->set_event_filter = armv8pmu_set_event_filter;
1261-
cpu_pmu->filter = armv8pmu_filter;
12621255

12631256
cpu_pmu->pmu.event_idx = armv8pmu_user_event_idx;
12641257

drivers/perf/arm_pmu.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,7 @@ static void armpmu_disable(struct pmu *pmu)
550550
static bool armpmu_filter(struct pmu *pmu, int cpu)
551551
{
552552
struct arm_pmu *armpmu = to_arm_pmu(pmu);
553-
bool ret;
554-
555-
ret = cpumask_test_cpu(cpu, &armpmu->supported_cpus);
556-
if (ret && armpmu->filter)
557-
return armpmu->filter(pmu, cpu);
558-
559-
return ret;
553+
return !cpumask_test_cpu(cpu, &armpmu->supported_cpus);
560554
}
561555

562556
static ssize_t cpus_show(struct device *dev,

include/linux/perf/arm_pmu.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ struct arm_pmu {
100100
void (*stop)(struct arm_pmu *);
101101
void (*reset)(void *);
102102
int (*map_event)(struct perf_event *event);
103-
bool (*filter)(struct pmu *pmu, int cpu);
104103
int num_events;
105104
bool secure_access; /* 32-bit ARM only */
106105
#define ARMV8_PMUV3_MAX_COMMON_EVENTS 0x40

0 commit comments

Comments
 (0)