Skip to content

Commit 6cd1370

Browse files
Yicong Yangwilldeacon
authored andcommitted
drivers/perf: hisi: Refactor the detection of associated CPUs
There are two type of PMUs supported currently: 1) PMUs locate on SCCL (Super CPU Cluster [1]), associated with certain CCL (CPU cluster [1])(e.g. L3C PMU) or not (e.g. DDRC PMU) 2) PMUs locate on the SICL (Super IO Cluster [1]), which has no association with certain CPU topology (e.g. CPA PMU) Currently the associated CPUs of the PMU is detected in the cpuhp online callback as below: - for type 1) the CPUs match PMU's sccl_id and ccl_id - for type 2) PMU's sccl_id is -1 and all online CPUs will be associated Since uncore PMUs are not bound to certain CPU context and event could be counting started by any online CPU, the associated CPUs are just a preference. Below disadvantages are observed in current implementation: - the PMU cannot be used if its associated CPUs are offline - SICL PMUs are associated to all the online CPUs implicitly without the consideration of locality So refactor the way we detect the associated CPUs in below aspects: - add a clear definition of hisi_pmu::associated_cpus - initialize hisi_pmu::on_cpu based on locality if no associated CPU found, otherwise update it from associated CPUs - drop the detection with a sccl_id of -1 for SICL PMUs [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/admin-guide/perf/hisi-pmu.rst?h=v6.12-rc1 Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20241210141525.37788-5-yangyicong@huawei.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 83037a4 commit 6cd1370

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

drivers/perf/hisilicon/hisi_uncore_pmu.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,6 @@ static bool hisi_pmu_cpu_is_associated_pmu(struct hisi_pmu *hisi_pmu)
446446
{
447447
int sccl_id, ccl_id;
448448

449-
/* If SCCL_ID is -1, the PMU is in a SICL and has no CPU affinity */
450-
if (hisi_pmu->sccl_id == -1)
451-
return true;
452-
453449
if (hisi_pmu->ccl_id == -1) {
454450
/* If CCL_ID is -1, the PMU only shares the same SCCL */
455451
hisi_read_sccl_and_ccl_id(&sccl_id, NULL);
@@ -467,13 +463,25 @@ int hisi_uncore_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)
467463
struct hisi_pmu *hisi_pmu = hlist_entry_safe(node, struct hisi_pmu,
468464
node);
469465

470-
if (!hisi_pmu_cpu_is_associated_pmu(hisi_pmu))
466+
/*
467+
* If the CPU is not associated to PMU, initialize the hisi_pmu->on_cpu
468+
* based on the locality if it hasn't been initialized yet. For PMUs
469+
* do have associated CPUs, it'll be updated later.
470+
*/
471+
if (!hisi_pmu_cpu_is_associated_pmu(hisi_pmu)) {
472+
if (hisi_pmu->on_cpu != -1)
473+
return 0;
474+
475+
hisi_pmu->on_cpu = cpumask_local_spread(0, dev_to_node(hisi_pmu->dev));
476+
WARN_ON(irq_set_affinity(hisi_pmu->irq, cpumask_of(cpu)));
471477
return 0;
478+
}
472479

473480
cpumask_set_cpu(cpu, &hisi_pmu->associated_cpus);
474481

475-
/* If another CPU is already managing this PMU, simply return. */
476-
if (hisi_pmu->on_cpu != -1)
482+
/* If another associated CPU is already managing this PMU, simply return. */
483+
if (hisi_pmu->on_cpu != -1 &&
484+
cpumask_test_cpu(hisi_pmu->on_cpu, &hisi_pmu->associated_cpus))
477485
return 0;
478486

479487
/* Use this CPU in cpumask for event counting */

drivers/perf/hisilicon/hisi_uncore_pmu.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ struct hisi_pmu {
8787
const struct hisi_uncore_ops *ops;
8888
const struct hisi_pmu_dev_info *dev_info;
8989
struct hisi_pmu_hwevents pmu_events;
90-
/* associated_cpus: All CPUs associated with the PMU */
90+
/*
91+
* CPUs associated to the PMU and are preferred to use for counting.
92+
* Could be empty if PMU has no association (e.g. PMU on SICL), in
93+
* which case any online CPU will be used.
94+
*/
9195
cpumask_t associated_cpus;
9296
/* CPU used for counting */
9397
int on_cpu;

0 commit comments

Comments
 (0)