Skip to content

Commit c192026

Browse files
Yicong Yangwilldeacon
authored andcommitted
drivers/perf: hisi: Extract topology information to a separate structure
HiSilicon Uncore PMUs are identified by the IDs of the topology element on which the PMUs are located. Add a new separate struct hisi_pmu_toplogy to encapsulate this information. Add additional documentation on the meaning of each ID. - make sccl_id and sicl_id into a union since they're exclusive. It can also be accessed by scl_id if the SICL/SCCL distinction is not relevant - make index_id and sub_id signed so -1 may be used to indicate the PMU doesn't have this topology element or it could not be retrieved. This patch should have no functional changes. Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20241210141525.37788-6-yangyicong@huawei.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent 6cd1370 commit c192026

9 files changed

+78
-52
lines changed

drivers/perf/hisilicon/hisi_uncore_cpa_pmu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,19 @@ static int hisi_cpa_pmu_init_data(struct platform_device *pdev,
181181
struct hisi_pmu *cpa_pmu)
182182
{
183183
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
184-
&cpa_pmu->sicl_id)) {
184+
&cpa_pmu->topo.sicl_id)) {
185185
dev_err(&pdev->dev, "Can not read sicl-id\n");
186186
return -EINVAL;
187187
}
188188

189189
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
190-
&cpa_pmu->index_id)) {
190+
&cpa_pmu->topo.index_id)) {
191191
dev_err(&pdev->dev, "Cannot read idx-id\n");
192192
return -EINVAL;
193193
}
194194

195-
cpa_pmu->ccl_id = -1;
196-
cpa_pmu->sccl_id = -1;
195+
cpa_pmu->topo.ccl_id = -1;
196+
cpa_pmu->topo.sccl_id = -1;
197197
cpa_pmu->base = devm_platform_ioremap_resource(pdev, 0);
198198
if (IS_ERR(cpa_pmu->base))
199199
return PTR_ERR(cpa_pmu->base);
@@ -311,8 +311,8 @@ static int hisi_cpa_pmu_probe(struct platform_device *pdev)
311311
if (ret)
312312
return ret;
313313

314-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%d_cpa%u",
315-
cpa_pmu->sicl_id, cpa_pmu->index_id);
314+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%d_cpa%d",
315+
cpa_pmu->topo.sicl_id, cpa_pmu->topo.index_id);
316316
if (!name)
317317
return -ENOMEM;
318318

drivers/perf/hisilicon/hisi_uncore_ddrc_pmu.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,18 @@ static int hisi_ddrc_pmu_init_data(struct platform_device *pdev,
302302
* DDRC PMU, while SCCL_ID is in MPIDR[aff2].
303303
*/
304304
if (device_property_read_u32(&pdev->dev, "hisilicon,ch-id",
305-
&ddrc_pmu->index_id)) {
305+
&ddrc_pmu->topo.index_id)) {
306306
dev_err(&pdev->dev, "Can not read ddrc channel-id!\n");
307307
return -EINVAL;
308308
}
309309

310310
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
311-
&ddrc_pmu->sccl_id)) {
311+
&ddrc_pmu->topo.sccl_id)) {
312312
dev_err(&pdev->dev, "Can not read ddrc sccl-id!\n");
313313
return -EINVAL;
314314
}
315315
/* DDRC PMUs only share the same SCCL */
316-
ddrc_pmu->ccl_id = -1;
316+
ddrc_pmu->topo.ccl_id = -1;
317317

318318
ddrc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
319319
if (IS_ERR(ddrc_pmu->base)) {
@@ -324,7 +324,7 @@ static int hisi_ddrc_pmu_init_data(struct platform_device *pdev,
324324
ddrc_pmu->identifier = readl(ddrc_pmu->base + DDRC_VERSION);
325325
if (ddrc_pmu->identifier >= HISI_PMU_V2) {
326326
if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
327-
&ddrc_pmu->sub_id)) {
327+
&ddrc_pmu->topo.sub_id)) {
328328
dev_err(&pdev->dev, "Can not read sub-id!\n");
329329
return -EINVAL;
330330
}
@@ -501,13 +501,13 @@ static int hisi_ddrc_pmu_probe(struct platform_device *pdev)
501501

502502
if (ddrc_pmu->identifier >= HISI_PMU_V2)
503503
name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
504-
"hisi_sccl%u_ddrc%u_%u",
505-
ddrc_pmu->sccl_id, ddrc_pmu->index_id,
506-
ddrc_pmu->sub_id);
504+
"hisi_sccl%d_ddrc%d_%d",
505+
ddrc_pmu->topo.sccl_id, ddrc_pmu->topo.index_id,
506+
ddrc_pmu->topo.sub_id);
507507
else
508508
name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
509-
"hisi_sccl%u_ddrc%u", ddrc_pmu->sccl_id,
510-
ddrc_pmu->index_id);
509+
"hisi_sccl%d_ddrc%d", ddrc_pmu->topo.sccl_id,
510+
ddrc_pmu->topo.index_id);
511511

512512
if (!name)
513513
return -ENOMEM;

drivers/perf/hisilicon/hisi_uncore_hha_pmu.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int hisi_hha_pmu_init_data(struct platform_device *pdev,
300300
* SCCL_ID is in MPIDR[aff2].
301301
*/
302302
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
303-
&hha_pmu->sccl_id)) {
303+
&hha_pmu->topo.sccl_id)) {
304304
dev_err(&pdev->dev, "Can not read hha sccl-id!\n");
305305
return -EINVAL;
306306
}
@@ -310,18 +310,18 @@ static int hisi_hha_pmu_init_data(struct platform_device *pdev,
310310
* both "hisilicon, idx-id" as preference, if available.
311311
*/
312312
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
313-
&hha_pmu->index_id)) {
313+
&hha_pmu->topo.index_id)) {
314314
status = acpi_evaluate_integer(ACPI_HANDLE(&pdev->dev),
315315
"_UID", NULL, &id);
316316
if (ACPI_FAILURE(status)) {
317317
dev_err(&pdev->dev, "Cannot read idx-id!\n");
318318
return -EINVAL;
319319
}
320320

321-
hha_pmu->index_id = id;
321+
hha_pmu->topo.index_id = id;
322322
}
323323
/* HHA PMUs only share the same SCCL */
324-
hha_pmu->ccl_id = -1;
324+
hha_pmu->topo.ccl_id = -1;
325325

326326
hha_pmu->base = devm_platform_ioremap_resource(pdev, 0);
327327
if (IS_ERR(hha_pmu->base)) {
@@ -510,8 +510,8 @@ static int hisi_hha_pmu_probe(struct platform_device *pdev)
510510
if (ret)
511511
return ret;
512512

513-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%u_hha%u",
514-
hha_pmu->sccl_id, hha_pmu->index_id);
513+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%d_hha%d",
514+
hha_pmu->topo.sccl_id, hha_pmu->topo.index_id);
515515
if (!name)
516516
return -ENOMEM;
517517

drivers/perf/hisilicon/hisi_uncore_l3c_pmu.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ static int hisi_l3c_pmu_init_data(struct platform_device *pdev,
360360
* SCCL_ID is in MPIDR[aff2] and CCL_ID is in MPIDR[aff1].
361361
*/
362362
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
363-
&l3c_pmu->sccl_id)) {
363+
&l3c_pmu->topo.sccl_id)) {
364364
dev_err(&pdev->dev, "Can not read l3c sccl-id!\n");
365365
return -EINVAL;
366366
}
367367

368368
if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
369-
&l3c_pmu->ccl_id)) {
369+
&l3c_pmu->topo.ccl_id)) {
370370
dev_err(&pdev->dev, "Can not read l3c ccl-id!\n");
371371
return -EINVAL;
372372
}
@@ -544,8 +544,8 @@ static int hisi_l3c_pmu_probe(struct platform_device *pdev)
544544
if (ret)
545545
return ret;
546546

547-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%u_l3c%u",
548-
l3c_pmu->sccl_id, l3c_pmu->ccl_id);
547+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%d_l3c%d",
548+
l3c_pmu->topo.sccl_id, l3c_pmu->topo.ccl_id);
549549
if (!name)
550550
return -ENOMEM;
551551

drivers/perf/hisilicon/hisi_uncore_pa_pmu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,19 @@ static int hisi_pa_pmu_init_data(struct platform_device *pdev,
274274
* to identify the PA PMU.
275275
*/
276276
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
277-
&pa_pmu->sicl_id)) {
277+
&pa_pmu->topo.sicl_id)) {
278278
dev_err(&pdev->dev, "Cannot read sicl-id!\n");
279279
return -EINVAL;
280280
}
281281

282282
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
283-
&pa_pmu->index_id)) {
283+
&pa_pmu->topo.index_id)) {
284284
dev_err(&pdev->dev, "Cannot read idx-id!\n");
285285
return -EINVAL;
286286
}
287287

288-
pa_pmu->ccl_id = -1;
289-
pa_pmu->sccl_id = -1;
288+
pa_pmu->topo.ccl_id = -1;
289+
pa_pmu->topo.sccl_id = -1;
290290

291291
pa_pmu->dev_info = device_get_match_data(&pdev->dev);
292292
if (!pa_pmu->dev_info)
@@ -488,9 +488,9 @@ static int hisi_pa_pmu_probe(struct platform_device *pdev)
488488
if (ret)
489489
return ret;
490490

491-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%d_%s%u",
492-
pa_pmu->sicl_id, pa_pmu->dev_info->name,
493-
pa_pmu->index_id);
491+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sicl%d_%s%d",
492+
pa_pmu->topo.sicl_id, pa_pmu->dev_info->name,
493+
pa_pmu->topo.index_id);
494494
if (!name)
495495
return -ENOMEM;
496496

drivers/perf/hisilicon/hisi_uncore_pmu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,18 +444,19 @@ static void hisi_read_sccl_and_ccl_id(int *scclp, int *cclp)
444444
*/
445445
static bool hisi_pmu_cpu_is_associated_pmu(struct hisi_pmu *hisi_pmu)
446446
{
447+
struct hisi_pmu_topology *topo = &hisi_pmu->topo;
447448
int sccl_id, ccl_id;
448449

449-
if (hisi_pmu->ccl_id == -1) {
450+
if (topo->ccl_id == -1) {
450451
/* If CCL_ID is -1, the PMU only shares the same SCCL */
451452
hisi_read_sccl_and_ccl_id(&sccl_id, NULL);
452453

453-
return sccl_id == hisi_pmu->sccl_id;
454+
return sccl_id == topo->sccl_id;
454455
}
455456

456457
hisi_read_sccl_and_ccl_id(&sccl_id, &ccl_id);
457458

458-
return sccl_id == hisi_pmu->sccl_id && ccl_id == hisi_pmu->ccl_id;
459+
return sccl_id == topo->sccl_id && ccl_id == topo->ccl_id;
459460
}
460461

461462
int hisi_uncore_pmu_online_cpu(unsigned int cpu, struct hlist_node *node)

drivers/perf/hisilicon/hisi_uncore_pmu.h

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,43 @@ struct hisi_pmu_hwevents {
8181
const struct attribute_group **attr_groups;
8282
};
8383

84+
/**
85+
* struct hisi_pmu_topology - Describe the topology hierarchy on which the PMU
86+
* is located.
87+
* @sccl_id: ID of the SCCL on which the PMU locate is located.
88+
* @sicl_id: ID of the SICL on which the PMU locate is located.
89+
* @scl_id: ID used by the core which is unaware of the SCCL/SICL.
90+
* @ccl_id: ID of the CCL (CPU cluster) on which the PMU is located.
91+
* @index_id: the ID of the PMU module if there're several PMUs at a
92+
* particularly location in the topology.
93+
* @sub_id: submodule ID of the PMU. For example we use this for DDRC PMU v2
94+
* since each DDRC has more than one DMC
95+
*
96+
* The ID will be -1 if the PMU isn't located on a certain topology.
97+
*/
98+
struct hisi_pmu_topology {
99+
/*
100+
* SCCL (Super CPU CLuster) and SICL (Super I/O Cluster) are parallel
101+
* so a PMU cannot locate on a SCCL and a SICL. If the SCCL/SICL
102+
* distinction is not relevant, use scl_id instead.
103+
*/
104+
union {
105+
int sccl_id;
106+
int sicl_id;
107+
int scl_id;
108+
};
109+
int ccl_id;
110+
int index_id;
111+
int sub_id;
112+
};
113+
84114
/* Generic pmu struct for different pmu types */
85115
struct hisi_pmu {
86116
struct pmu pmu;
87117
const struct hisi_uncore_ops *ops;
88118
const struct hisi_pmu_dev_info *dev_info;
89119
struct hisi_pmu_hwevents pmu_events;
120+
struct hisi_pmu_topology topo;
90121
/*
91122
* CPUs associated to the PMU and are preferred to use for counting.
92123
* Could be empty if PMU has no association (e.g. PMU on SICL), in
@@ -98,14 +129,7 @@ struct hisi_pmu {
98129
int irq;
99130
struct device *dev;
100131
struct hlist_node node;
101-
int sccl_id;
102-
int sicl_id;
103-
int ccl_id;
104132
void __iomem *base;
105-
/* the ID of the PMU modules */
106-
u32 index_id;
107-
/* For DDRC PMU v2: each DDRC has more than one DMC */
108-
u32 sub_id;
109133
int num_counters;
110134
int counter_bits;
111135
/* check event code range */

drivers/perf/hisilicon/hisi_uncore_sllc_pmu.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,19 @@ static int hisi_sllc_pmu_init_data(struct platform_device *pdev,
293293
* while SCCL_ID is from MPIDR_EL1 by CPU.
294294
*/
295295
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
296-
&sllc_pmu->sccl_id)) {
296+
&sllc_pmu->topo.sccl_id)) {
297297
dev_err(&pdev->dev, "Cannot read sccl-id!\n");
298298
return -EINVAL;
299299
}
300300

301301
if (device_property_read_u32(&pdev->dev, "hisilicon,idx-id",
302-
&sllc_pmu->index_id)) {
302+
&sllc_pmu->topo.index_id)) {
303303
dev_err(&pdev->dev, "Cannot read idx-id!\n");
304304
return -EINVAL;
305305
}
306306

307307
/* SLLC PMUs only share the same SCCL */
308-
sllc_pmu->ccl_id = -1;
308+
sllc_pmu->topo.ccl_id = -1;
309309

310310
sllc_pmu->base = devm_platform_ioremap_resource(pdev, 0);
311311
if (IS_ERR(sllc_pmu->base)) {
@@ -433,8 +433,8 @@ static int hisi_sllc_pmu_probe(struct platform_device *pdev)
433433
if (ret)
434434
return ret;
435435

436-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%u_sllc%u",
437-
sllc_pmu->sccl_id, sllc_pmu->index_id);
436+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%d_sllc%d",
437+
sllc_pmu->topo.sccl_id, sllc_pmu->topo.index_id);
438438
if (!name)
439439
return -ENOMEM;
440440

drivers/perf/hisilicon/hisi_uncore_uc_pmu.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,19 @@ static int hisi_uc_pmu_init_data(struct platform_device *pdev,
372372
* They have some CCLs per SCCL and then 4 UC PMU per CCL.
373373
*/
374374
if (device_property_read_u32(&pdev->dev, "hisilicon,scl-id",
375-
&uc_pmu->sccl_id)) {
375+
&uc_pmu->topo.sccl_id)) {
376376
dev_err(&pdev->dev, "Can not read uc sccl-id!\n");
377377
return -EINVAL;
378378
}
379379

380380
if (device_property_read_u32(&pdev->dev, "hisilicon,ccl-id",
381-
&uc_pmu->ccl_id)) {
381+
&uc_pmu->topo.ccl_id)) {
382382
dev_err(&pdev->dev, "Can not read uc ccl-id!\n");
383383
return -EINVAL;
384384
}
385385

386386
if (device_property_read_u32(&pdev->dev, "hisilicon,sub-id",
387-
&uc_pmu->sub_id)) {
387+
&uc_pmu->topo.sub_id)) {
388388
dev_err(&pdev->dev, "Can not read sub-id!\n");
389389
return -EINVAL;
390390
}
@@ -538,8 +538,9 @@ static int hisi_uc_pmu_probe(struct platform_device *pdev)
538538
if (ret)
539539
return ret;
540540

541-
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%d_uc%d_%u",
542-
uc_pmu->sccl_id, uc_pmu->ccl_id, uc_pmu->sub_id);
541+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "hisi_sccl%d_uc%d_%d",
542+
uc_pmu->topo.sccl_id, uc_pmu->topo.ccl_id,
543+
uc_pmu->topo.sub_id);
543544
if (!name)
544545
return -ENOMEM;
545546

0 commit comments

Comments
 (0)