[PATCH v1 06/23] perf pmu: Detect ARM and hybrid PMUs with sysfs

From: Ian Rogers
Date: Wed May 17 2023 - 10:59:19 EST


is_arm_pmu_core detects a core PMU via the presence of a "cpus" file
rather than a "cpumask" file. This pattern holds for hybrid PMUs so
rename the function and remove redundant perf_pmu__is_hybrid
tests.

Add a new helper is_pmu_hybrid similar to is_pmu_core.

Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/pmu.c | 29 ++++++++++++++++++-----------
tools/perf/util/pmu.h | 1 +
2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 729b1f166f80..0fa451c60c77 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -640,12 +640,14 @@ static char *pmu_id(const char *name)
return str;
}

-/*
- * PMU CORE devices have different name other than cpu in sysfs on some
- * platforms.
- * Looking for possible sysfs files to identify the arm core device.
+/**
+ * is_sysfs_pmu_core() - PMU CORE devices have different name other than cpu in
+ * sysfs on some platforms like ARM or Intel hybrid. Looking for
+ * possible the cpus file in sysfs files to identify whether this is a
+ * core device.
+ * @name: The PMU name such as "cpu_atom".
*/
-static int is_arm_pmu_core(const char *name)
+static int is_sysfs_pmu_core(const char *name)
{
char path[PATH_MAX];

@@ -811,7 +813,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
struct pmu_add_cpu_aliases_map_data data = {
.head = head,
.name = pmu->name,
- .cpu_name = is_arm_pmu_core(pmu->name) ? pmu->name : "cpu",
+ .cpu_name = is_sysfs_pmu_core(pmu->name) ? pmu->name : "cpu",
.pmu = pmu,
};

@@ -1649,22 +1651,27 @@ static int cmp_sevent(const void *a, const void *b)

bool is_pmu_core(const char *name)
{
- return !strcmp(name, "cpu") || is_arm_pmu_core(name);
+ return !strcmp(name, "cpu") || is_sysfs_pmu_core(name);
+}
+
+bool is_pmu_hybrid(const char *name)
+{
+ return !strcmp(name, "cpu_atom") || !strcmp(name, "cpu_core");
}

bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu)
{
- return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name);
+ return is_pmu_core(pmu->name);
}

bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu)
{
- return is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name);
+ return is_pmu_core(pmu->name);
}

bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu)
{
- return !perf_pmu__is_hybrid(pmu->name);
+ return !is_pmu_hybrid(pmu->name);
}

static bool pmu_alias_is_duplicate(struct sevent *alias_a,
@@ -1718,7 +1725,7 @@ void print_pmu_events(const struct print_callbacks *print_cb, void *print_state)
pmu = NULL;
j = 0;
while ((pmu = perf_pmu__scan(pmu)) != NULL) {
- bool is_cpu = is_pmu_core(pmu->name) || perf_pmu__is_hybrid(pmu->name);
+ bool is_cpu = is_pmu_core(pmu->name);

list_for_each_entry(event, &pmu->aliases, list) {
aliases[j].event = event;
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 49033bb134f3..99e0273027bf 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -220,6 +220,7 @@ void perf_pmu__del_formats(struct list_head *formats);
struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);

bool is_pmu_core(const char *name);
+bool is_pmu_hybrid(const char *name);
bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu);
bool perf_pmu__supports_wildcard_numeric(const struct perf_pmu *pmu);
bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu);
--
2.40.1.606.ga4b1b128d6-goog