Skip to content

Commit a3287c4

Browse files
committed
drivers/perf: arm_pmu: Request PMU SPIs with IRQF_PER_CPU
Since the PMU register interface is banked per CPU, CPU PMU interrrupts cannot be handled by a CPU other than the one with the PMU asserting the interrupt. This means that migrating PMU SPIs, as we do during a CPU hotplug operation doesn't make any sense and can lead to the IRQ being disabled entirely if we route a spurious IRQ to the new affinity target. This has been observed in practice on AMD Seattle, where CPUs on the non-boot cluster appear to take a spurious PMU IRQ when coming online, which is routed to CPU0 where it cannot be handled. This patch passes IRQF_PERCPU for PMU SPIs and forcefully sets their affinity prior to requesting them, ensuring that they cannot be migrated during hotplug events. This interacts badly with the DB8500 erratum workaround that ping-pongs the interrupt affinity from the handler, so we avoid passing IRQF_PERCPU in that case by allowing the IRQ flags to be overridden in the platdata. Fixes: 3cf7ee9 ("drivers/perf: arm_pmu: move irq request/free into probe") Cc: Mark Rutland <[email protected]> Cc: Linus Walleij <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent d0153c7 commit a3287c4

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

arch/arm/mach-ux500/cpu-db8500.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static irqreturn_t db8500_pmu_handler(int irq, void *dev, irq_handler_t handler)
133133

134134
static struct arm_pmu_platdata db8500_pmu_platdata = {
135135
.handle_irq = db8500_pmu_handler,
136+
.irq_flags = IRQF_NOBALANCING | IRQF_NO_THREAD,
136137
};
137138

138139
static struct of_dev_auxdata u8500_auxdata_lookup[] __initdata = {

drivers/perf/arm_pmu.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -569,22 +569,41 @@ int armpmu_request_irq(struct arm_pmu *armpmu, int cpu)
569569
if (irq != other_irq) {
570570
pr_warn("mismatched PPIs detected.\n");
571571
err = -EINVAL;
572+
goto err_out;
572573
}
573574
} else {
574-
err = request_irq(irq, handler,
575-
IRQF_NOBALANCING | IRQF_NO_THREAD, "arm-pmu",
575+
struct arm_pmu_platdata *platdata = armpmu_get_platdata(armpmu);
576+
unsigned long irq_flags;
577+
578+
err = irq_force_affinity(irq, cpumask_of(cpu));
579+
580+
if (err && num_possible_cpus() > 1) {
581+
pr_warn("unable to set irq affinity (irq=%d, cpu=%u)\n",
582+
irq, cpu);
583+
goto err_out;
584+
}
585+
586+
if (platdata && platdata->irq_flags) {
587+
irq_flags = platdata->irq_flags;
588+
} else {
589+
irq_flags = IRQF_PERCPU |
590+
IRQF_NOBALANCING |
591+
IRQF_NO_THREAD;
592+
}
593+
594+
err = request_irq(irq, handler, irq_flags, "arm-pmu",
576595
per_cpu_ptr(&hw_events->percpu_pmu, cpu));
577596
}
578597

579-
if (err) {
580-
pr_err("unable to request IRQ%d for ARM PMU counters\n",
581-
irq);
582-
return err;
583-
}
598+
if (err)
599+
goto err_out;
584600

585601
cpumask_set_cpu(cpu, &armpmu->active_irqs);
586-
587602
return 0;
603+
604+
err_out:
605+
pr_err("unable to request IRQ%d for ARM PMU counters\n", irq);
606+
return err;
588607
}
589608

590609
int armpmu_request_irqs(struct arm_pmu *armpmu)
@@ -628,12 +647,6 @@ static int arm_perf_starting_cpu(unsigned int cpu, struct hlist_node *node)
628647
enable_percpu_irq(irq, IRQ_TYPE_NONE);
629648
return 0;
630649
}
631-
632-
if (irq_force_affinity(irq, cpumask_of(cpu)) &&
633-
num_possible_cpus() > 1) {
634-
pr_warn("unable to set irq affinity (irq=%d, cpu=%u)\n",
635-
irq, cpu);
636-
}
637650
}
638651

639652
return 0;

include/linux/perf/arm_pmu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
* interrupt and passed the address of the low level handler,
2525
* and can be used to implement any platform specific handling
2626
* before or after calling it.
27+
*
28+
* @irq_flags: if non-zero, these flags will be passed to request_irq
29+
* when requesting interrupts for this PMU device.
2730
*/
2831
struct arm_pmu_platdata {
2932
irqreturn_t (*handle_irq)(int irq, void *dev,
3033
irq_handler_t pmu_handler);
34+
unsigned long irq_flags;
3135
};
3236

3337
#ifdef CONFIG_ARM_PMU

0 commit comments

Comments
 (0)