Skip to content

Commit 83a6d80

Browse files
Yicong Yangwilldeacon
authored andcommitted
drivers/perf: hisi: Schedule perf session according to locality
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. Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20230815131010.2147-1-yangyicong@huawei.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 4c1d2f5 commit 83a6d80

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

drivers/perf/hisilicon/hisi_pcie_pmu.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ static int hisi_pcie_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
665665
struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node);
666666

667667
if (pcie_pmu->on_cpu == -1) {
668-
pcie_pmu->on_cpu = cpu;
669-
WARN_ON(irq_set_affinity(pcie_pmu->irq, cpumask_of(cpu)));
668+
pcie_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(&pcie_pmu->pdev->dev));
669+
WARN_ON(irq_set_affinity(pcie_pmu->irq, cpumask_of(pcie_pmu->on_cpu)));
670670
}
671671

672672
return 0;
@@ -676,14 +676,23 @@ static int hisi_pcie_pmu_offline_cpu(unsigned int cpu, struct hlist_node *node)
676676
{
677677
struct hisi_pcie_pmu *pcie_pmu = hlist_entry_safe(node, struct hisi_pcie_pmu, node);
678678
unsigned int target;
679+
cpumask_t mask;
680+
int numa_node;
679681

680682
/* Nothing to do if this CPU doesn't own the PMU */
681683
if (pcie_pmu->on_cpu != cpu)
682684
return 0;
683685

684686
pcie_pmu->on_cpu = -1;
685-
/* Choose a new CPU from all online cpus. */
686-
target = cpumask_any_but(cpu_online_mask, cpu);
687+
688+
/* Choose a local CPU from all online cpus. */
689+
numa_node = dev_to_node(&pcie_pmu->pdev->dev);
690+
if (cpumask_and(&mask, cpumask_of_node(numa_node), cpu_online_mask) &&
691+
cpumask_andnot(&mask, &mask, cpumask_of(cpu)))
692+
target = cpumask_any(&mask);
693+
else
694+
target = cpumask_any_but(cpu_online_mask, cpu);
695+
687696
if (target >= nr_cpu_ids) {
688697
pci_err(pcie_pmu->pdev, "There is no CPU to set\n");
689698
return 0;

0 commit comments

Comments
 (0)