2023-06-22 05:10:12

by Ian Rogers

[permalink] [raw]
Subject: [PATCH v1 2/2] perf pmu: Remove a hard coded cpu PMU assumption

The property of "cpu" when it has no cpu map is true on S390 with the
PMU cpum_cf. Rather than maintain a list of such PMUs, reuse the
is_core test result from the caller.

Signed-off-by: Ian Rogers <[email protected]>
---
tools/perf/util/pmu.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 963c12f910c5..64fa568a5426 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -551,7 +551,7 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias,
* Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64)
* may have a "cpus" file.
*/
-static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name)
+static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name, bool is_core)
{
struct perf_cpu_map *cpus;
const char *templates[] = {
@@ -575,7 +575,8 @@ static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name)
return cpus;
}

- return !strcmp(name, "cpu") ? perf_cpu_map__get(cpu_map__online()) : NULL;
+ /* Nothing found, for core PMUs assume this means all CPUs. */
+ return is_core ? perf_cpu_map__get(cpu_map__online()) : NULL;
}

static bool pmu_is_uncore(int dirfd, const char *name)
@@ -886,7 +887,8 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
if (!pmu)
return NULL;

- pmu->cpus = pmu_cpumask(dirfd, name);
+ pmu->is_core = is_pmu_core(name);
+ pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core);
pmu->name = strdup(name);
if (!pmu->name)
goto err;
@@ -903,7 +905,6 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
}

pmu->type = type;
- pmu->is_core = is_pmu_core(name);
pmu->is_uncore = pmu_is_uncore(dirfd, name);
if (pmu->is_uncore)
pmu->id = pmu_id(name);
--
2.41.0.162.gfafddb0af9-goog



2023-06-22 08:54:11

by Thomas Richter

[permalink] [raw]
Subject: Re: [PATCH v1 2/2] perf pmu: Remove a hard coded cpu PMU assumption

On 6/22/23 07:03, Ian Rogers wrote:
> The property of "cpu" when it has no cpu map is true on S390 with the
> PMU cpum_cf. Rather than maintain a list of such PMUs, reuse the
> is_core test result from the caller.
>
> Signed-off-by: Ian Rogers <[email protected]>
> ---
> tools/perf/util/pmu.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
> index 963c12f910c5..64fa568a5426 100644
> --- a/tools/perf/util/pmu.c
> +++ b/tools/perf/util/pmu.c
> @@ -551,7 +551,7 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias,
> * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64)
> * may have a "cpus" file.
> */
> -static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name)
> +static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name, bool is_core)
> {
> struct perf_cpu_map *cpus;
> const char *templates[] = {
> @@ -575,7 +575,8 @@ static struct perf_cpu_map *pmu_cpumask(int dirfd, const char *name)
> return cpus;
> }
>
> - return !strcmp(name, "cpu") ? perf_cpu_map__get(cpu_map__online()) : NULL;
> + /* Nothing found, for core PMUs assume this means all CPUs. */
> + return is_core ? perf_cpu_map__get(cpu_map__online()) : NULL;
> }
>
> static bool pmu_is_uncore(int dirfd, const char *name)
> @@ -886,7 +887,8 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
> if (!pmu)
> return NULL;
>
> - pmu->cpus = pmu_cpumask(dirfd, name);
> + pmu->is_core = is_pmu_core(name);
> + pmu->cpus = pmu_cpumask(dirfd, name, pmu->is_core);
> pmu->name = strdup(name);
> if (!pmu->name)
> goto err;
> @@ -903,7 +905,6 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
> }
>
> pmu->type = type;
> - pmu->is_core = is_pmu_core(name);
> pmu->is_uncore = pmu_is_uncore(dirfd, name);
> if (pmu->is_uncore)
> pmu->id = pmu_id(name);

Looks good to me, for both patches:

Tested-by: Thomas Richter <[email protected]>
--
Thomas Richter, Dept 3303, IBM s390 Linux Development, Boeblingen, Germany
--
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschäftsführung: David Faller
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht Stuttgart, HRB 243294