Skip to contentSkip to conversation

drivers/perf: hisi: Schedule perf session according to locality

PATCH Superseded Yicong Yang 2 participants 3 messages Aug 8, 2023 – Aug 15, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/perf: hisi: Schedule perf session according to locality

From: Yicong Yang <[email protected]>

The PCIe PMUs locate on different NUMA node but currently we don't consider it and likely stack all the sessions on the same CPU:

[root@localhost tmp]# cat /sys/devices/hisi_pcie*/cpumask 0
0
0
0
0
0

This can be optimize a bit to use a local CPU for the PMU.

---
 drivers/perf/hisilicon/hisi_pcie_pmu.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/perf/hisilicon/hisi_pcie_pmu.c +12 -3
index e10fc7cb9493..60ecf469782b 100644
@@ -665,7 +665,7 @@ static int hisi_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
 	struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node);
 
 	if (pcie_pmu->on_cpu == -1) {
-		pcie_pmu->on_cpu = cpu;
+		pcie_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(&pcie_pmu->pdev->dev));
 		WARN_ON(irq_set_affinity(pcie_pmu->irq, cpumask_of(cpu)));
 	}
 
@@ -676,14 +676,23 @@ static int hisi_pcie_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
 {
 	struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node);
 	unsigned int target;
+	cpumask_t mask;
+	int numa_node;
 
 	/* Nothing to do if this CPU doesn't own the PMU */
 	if (pcie_pmu->on_cpu != cpu)
 		return 0;
 
 	pcie_pmu->on_cpu = -1;
-	/* Choose a new CPU from all online cpus. */
-	target = cpumask_any_but(cpu_online_mask, cpu);
+
+	/* Choose a local CPU from all online cpus. */
+	numa_node = dev_to_node(&pcie_pmu->pdev->dev);
+	if (cpumask_and(&mask, cpumask_of_node(numa_node), cpu_online_mask) &&
+	    cpumask_andnot(&mask, &mask, cpumask_of(cpu)))
+		target = cpumask_any(&mask);
+	else
+		target = cpumask_any_but(cpu_online_mask, cpu);
+
 	if (target >= nr_cpu_ids) {
 		pci_err(pcie_pmu->pdev, "There is no CPU to set\n");
 		return 0;
Signature · 7 lines
2.24.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw
Quoted 25 lines · Yicong Yang

From: Yicong Yang <[email protected]>

The PCIe PMUs locate on different NUMA node but currently we don't consider it and likely stack all the sessions on the same CPU:

[root@localhost tmp]# cat /sys/devices/hisi_pcie*/cpumask 0
0
0
0
0
0

This can be optimize a bit to use a local CPU for the PMU.

---
 drivers/perf/hisilicon/hisi_pcie_pmu.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/perf/hisilicon/hisi_pcie_pmu.c +0 -0
index e10fc7cb9493..60ecf469782b 100644

drivers/perf/hisilicon/hisi_pcie_pmu.c static int hisi_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *node) · line 669

Quoted 6 lines
drivers/perf/hisilicon/hisi_pcie_pmu.c +1 -1
@@ -665,7 +665,7 @@ static int hisi_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
 	struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node);
 
 	if (pcie_pmu->on_cpu == -1) {
-		pcie_pmu->on_cpu = cpu;
+		pcie_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(&pcie_pmu->pdev->dev));
 		WARN_ON(irq_set_affinity(pcie_pmu->irq, cpumask_of(cpu)));

Hmm, this is a bit weird now, because the interrupt is affine to a different CPU from the one you've chosen. Are you sure that's ok? When the offline notifier picks a new target, it moves the irq as well.

Will

#2 lore raw
Quoted 28 lines · Will Deacon
Quoted 27 lines · Yicong Yang

From: Yicong Yang <[email protected]>

The PCIe PMUs locate on different NUMA node but currently we don't consider it and likely stack all the sessions on the same CPU:

[root@localhost tmp]# cat /sys/devices/hisi_pcie*/cpumask 0
0
0
0
0
0

This can be optimize a bit to use a local CPU for the PMU.

---
 drivers/perf/hisilicon/hisi_pcie_pmu.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/perf/hisilicon/hisi_pcie_pmu.c +0 -0
index e10fc7cb9493..60ecf469782b 100644
@@ -665,7 +665,7 @@ static int hisi_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
 	struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node);
 
Quoted 9 lines

drivers/perf/hisilicon/hisi_pcie_pmu.c static int hisi_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *node) · line 669

Quoted 4 lines
drivers/perf/hisilicon/hisi_pcie_pmu.c +1 -1
 	if (pcie_pmu->on_cpu == -1) {
-		pcie_pmu->on_cpu = cpu;
+		pcie_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(&pcie_pmu->pdev->dev));
 		WARN_ON(irq_set_affinity(pcie_pmu->irq, cpumask_of(cpu)));

Hmm, this is a bit weird now, because the interrupt is affine to a different CPU from the one you've chosen. Are you sure that's ok? When the offline notifier picks a new target, it moves the irq as well.

Thanks for pointing it out. This is indeed a problem. Will fix this.

Thanks.