Skip to content

Commit 14b22ae

Browse files
Ganapatrao Kulkarniacmel
authored andcommitted
perf pmu: Add helper function is_pmu_core to detect PMU CORE devices
On some platforms, PMU core devices sysfs name is not cpu. Adding function is_pmu_core to detect PMU core devices using core device specific hints in sysfs. For arm64 platforms, all core devices have file "cpus" in sysfs. Signed-off-by: Ganapatrao Kulkarni <[email protected]> Tested-by: Shaokun Zhang <[email protected]> Tested-by: Jin Yao <[email protected]> Acked-by: Will Deacon <[email protected]> Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b57df28 commit 14b22ae

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

tools/perf/util/pmu.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,34 @@ static bool pmu_is_uncore(const char *name)
536536
return !!cpus;
537537
}
538538

539+
/*
540+
* PMU CORE devices have different name other than cpu in sysfs on some
541+
* platforms. looking for possible sysfs files to identify as core device.
542+
*/
543+
static int is_pmu_core(const char *name)
544+
{
545+
struct stat st;
546+
char path[PATH_MAX];
547+
const char *sysfs = sysfs__mountpoint();
548+
549+
if (!sysfs)
550+
return 0;
551+
552+
/* Look for cpu sysfs (x86 and others) */
553+
scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu", sysfs);
554+
if ((stat(path, &st) == 0) &&
555+
(strncmp(name, "cpu", strlen("cpu")) == 0))
556+
return 1;
557+
558+
/* Look for cpu sysfs (specific to arm) */
559+
scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/cpus",
560+
sysfs, name);
561+
if (stat(path, &st) == 0)
562+
return 1;
563+
564+
return 0;
565+
}
566+
539567
/*
540568
* Return the CPU id as a raw string.
541569
*
@@ -609,7 +637,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
609637
*/
610638
i = 0;
611639
while (1) {
612-
const char *pname;
613640

614641
pe = &map->table[i++];
615642
if (!pe->name) {
@@ -618,9 +645,13 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu)
618645
break;
619646
}
620647

621-
pname = pe->pmu ? pe->pmu : "cpu";
622-
if (strncmp(pname, name, strlen(pname)))
623-
continue;
648+
if (!is_pmu_core(name)) {
649+
/* check for uncore devices */
650+
if (pe->pmu == NULL)
651+
continue;
652+
if (strncmp(pe->pmu, name, strlen(pe->pmu)))
653+
continue;
654+
}
624655

625656
/* need type casts to override 'const' */
626657
__perf_pmu__new_alias(head, NULL, (char *)pe->name,

0 commit comments

Comments
 (0)