Skip to content

Commit b6c084d

Browse files
committed
ARM: perf: extend interrupt-affinity property for PPIs
On systems containing multiple, heterogeneous clusters we need a way to associate a PMU "device" with the CPU(s) on which it exists. For PMUs that signal overflow with SPIs, this relationship is determined via the "interrupt-affinity" property, which contains a list of phandles to CPU nodes for the PMU. For PMUs using PPIs, the per-cpu nature of the interrupt isn't enough to determine the set of CPUs which actually contain the device. This patch allows the interrupt-affinity property to be specified on a PMU node irrespective of the interrupt type. For PPIs, it identifies the set of CPUs signalling the PPI in question. Tested-by: Stephen Boyd <sboyd@codeaurora.org> # Krait PMU Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 8ae81c2 commit b6c084d

2 files changed

Lines changed: 53 additions & 24 deletions

File tree

‎Documentation/devicetree/bindings/arm/pmu.txt‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ Required properties:
2626

2727
Optional properties:
2828

29-
- interrupt-affinity : Valid only when using SPIs, specifies a list of phandles
30-
to CPU nodes corresponding directly to the affinity of
29+
- interrupt-affinity : When using SPIs, specifies a list of phandles to CPU
30+
nodes corresponding directly to the affinity of
3131
the SPIs listed in the interrupts property.
3232

33-
This property should be present when there is more than
33+
When using a PPI, specifies a list of phandles to CPU
34+
nodes corresponding to the set of CPUs which have
35+
a PMU of this type signalling the PPI listed in the
36+
interrupts property.
37+
38+
This property should be present when there is more than
3439
a single SPI.
3540

41+
3642
- qcom,no-pc-write : Indicates that this PMU doesn't support the 0xc and 0xd
3743
events.
3844

‎arch/arm/kernel/perf_event.c‎

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -790,32 +790,39 @@ static int probe_current_pmu(struct arm_pmu *pmu,
790790

791791
static int of_pmu_irq_cfg(struct arm_pmu *pmu)
792792
{
793-
int i, irq, *irqs;
793+
int *irqs, i = 0;
794+
bool using_spi = false;
794795
struct platform_device *pdev = pmu->plat_device;
795796

796-
/* Don't bother with PPIs; they're already affine */
797-
irq = platform_get_irq(pdev, 0);
798-
if (irq >= 0 && irq_is_percpu(irq)) {
799-
cpumask_setall(&pmu->supported_cpus);
800-
return 0;
801-
}
802-
803797
irqs = kcalloc(pdev->num_resources, sizeof(*irqs), GFP_KERNEL);
804798
if (!irqs)
805799
return -ENOMEM;
806800

807-
for (i = 0; i < pdev->num_resources; ++i) {
801+
do {
808802
struct device_node *dn;
809-
int cpu;
803+
int cpu, irq;
810804

811-
dn = of_parse_phandle(pdev->dev.of_node, "interrupt-affinity",
812-
i);
813-
if (!dn) {
814-
pr_warn("Failed to parse %s/interrupt-affinity[%d]\n",
815-
of_node_full_name(pdev->dev.of_node), i);
805+
/* See if we have an affinity entry */
806+
dn = of_parse_phandle(pdev->dev.of_node, "interrupt-affinity", i);
807+
if (!dn)
816808
break;
809+
810+
/* Check the IRQ type and prohibit a mix of PPIs and SPIs */
811+
irq = platform_get_irq(pdev, i);
812+
if (irq >= 0) {
813+
bool spi = !irq_is_percpu(irq);
814+
815+
if (i > 0 && spi != using_spi) {
816+
pr_err("PPI/SPI IRQ type mismatch for %s!\n",
817+
dn->name);
818+
kfree(irqs);
819+
return -EINVAL;
820+
}
821+
822+
using_spi = spi;
817823
}
818824

825+
/* Now look up the logical CPU number */
819826
for_each_possible_cpu(cpu)
820827
if (arch_find_n_match_cpu_physical_id(dn, cpu, NULL))
821828
break;
@@ -824,20 +831,36 @@ static int of_pmu_irq_cfg(struct arm_pmu *pmu)
824831
pr_warn("Failed to find logical CPU for %s\n",
825832
dn->name);
826833
of_node_put(dn);
834+
cpumask_setall(&pmu->supported_cpus);
827835
break;
828836
}
829837
of_node_put(dn);
830838

831-
irqs[i] = cpu;
839+
/* For SPIs, we need to track the affinity per IRQ */
840+
if (using_spi) {
841+
if (i >= pdev->num_resources) {
842+
of_node_put(dn);
843+
break;
844+
}
845+
846+
irqs[i] = cpu;
847+
}
848+
849+
/* Keep track of the CPUs containing this PMU type */
832850
cpumask_set_cpu(cpu, &pmu->supported_cpus);
833-
}
851+
of_node_put(dn);
852+
i++;
853+
} while (1);
834854

835-
if (i == pdev->num_resources) {
855+
/* If we didn't manage to parse anything, claim to support all CPUs */
856+
if (cpumask_weight(&pmu->supported_cpus) == 0)
857+
cpumask_setall(&pmu->supported_cpus);
858+
859+
/* If we matched up the IRQ affinities, use them to route the SPIs */
860+
if (using_spi && i == pdev->num_resources)
836861
pmu->irq_affinity = irqs;
837-
} else {
862+
else
838863
kfree(irqs);
839-
cpumask_setall(&pmu->supported_cpus);
840-
}
841864

842865
return 0;
843866
}

0 commit comments

Comments
 (0)