Skip to content

Commit 494c403

Browse files
captain5050acmel
authored andcommitted
perf header: Pass a perf_cpu rather than a PMU to get_cpuid_str
On ARM the cpuid is dependent on the core type of the CPU in question. The PMU was passed for the sake of the CPU map but this means in places a temporary PMU is created just to pass a CPU value. Just pass the CPU and fix up the callers. As there are no longer PMU users in header.h, shuffle forward declarations earlier to work around build failures. Reviewed-by: James Clark <james.clark@linaro.org> Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Xu Yang <xu.yang_2@nxp.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Albert Ou <aou@eecs.berkeley.edu> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com> Cc: Ben Zong-You Xie <ben717@andestech.com> Cc: Benjamin Gray <bgray@linux.ibm.com> Cc: Bibo Mao <maobibo@loongson.cn> Cc: Clément Le Goffic <clement.legoffic@foss.st.com> Cc: Dima Kogan <dima@secretsauce.net> Cc: Dr. David Alan Gilbert <linux@treblig.org> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.g.garry@oracle.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linux.dev> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Will Deacon <will@kernel.org> Cc: Yicong Yang <yangyicong@hisilicon.com> Cc: linux-arm-kernel@lists.infradead.org Cc: linux-riscv@lists.infradead.org Link: https://lore.kernel.org/r/20241107162035.52206-7-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 7463ee1 commit 494c403

File tree

15 files changed

+57
-67
lines changed

15 files changed

+57
-67
lines changed

tools/perf/arch/arm64/util/arm-spe.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "../../../util/debug.h"
2424
#include "../../../util/auxtrace.h"
2525
#include "../../../util/record.h"
26+
#include "../../../util/header.h"
2627
#include "../../../util/arm-spe.h"
2728
#include <tools/libc_compat.h> // reallocarray
2829

@@ -85,22 +86,11 @@ static int arm_spe_save_cpu_header(struct auxtrace_record *itr,
8586
struct arm_spe_recording *sper =
8687
container_of(itr, struct arm_spe_recording, itr);
8788
struct perf_pmu *pmu = NULL;
88-
struct perf_pmu tmp_pmu;
89-
char cpu_id_str[16];
9089
char *cpuid = NULL;
9190
u64 val;
9291

93-
snprintf(cpu_id_str, sizeof(cpu_id_str), "%d", cpu.cpu);
94-
tmp_pmu.cpus = perf_cpu_map__new(cpu_id_str);
95-
if (!tmp_pmu.cpus)
96-
return -ENOMEM;
97-
9892
/* Read CPU MIDR */
99-
cpuid = perf_pmu__getcpuid(&tmp_pmu);
100-
101-
/* The CPU map will not be used anymore, release it */
102-
perf_cpu_map__put(tmp_pmu.cpus);
103-
93+
cpuid = get_cpuid_allow_env_override(cpu);
10494
if (!cpuid)
10595
return -ENOMEM;
10696
val = strtol(cpuid, NULL, 16);

tools/perf/arch/arm64/util/header.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,18 @@ int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu)
6262
return EINVAL;
6363
}
6464

65-
char *get_cpuid_str(struct perf_pmu *pmu)
65+
char *get_cpuid_str(struct perf_cpu cpu)
6666
{
67-
char *buf = NULL;
67+
char *buf = malloc(MIDR_SIZE);
6868
int res;
6969

70-
if (!pmu || !pmu->cpus)
71-
return NULL;
72-
73-
buf = malloc(MIDR_SIZE);
7470
if (!buf)
7571
return NULL;
7672

7773
/* read midr from list of cpus mapped to this pmu */
78-
res = get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus));
74+
res = get_cpuid(buf, MIDR_SIZE, cpu);
7975
if (res) {
80-
pr_err("failed to get cpuid string for PMU %s\n", pmu->name);
76+
pr_err("failed to get cpuid string for CPU %d\n", cpu.cpu);
8177
free(buf);
8278
buf = NULL;
8379
}

tools/perf/arch/loongarch/util/header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
9090
return ret;
9191
}
9292

93-
char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
93+
char *get_cpuid_str(struct perf_cpu cpu __maybe_unused)
9494
{
9595
return _get_cpuid();
9696
}

tools/perf/arch/powerpc/util/header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
4242
}
4343

4444
char *
45-
get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
45+
get_cpuid_str(struct perf_cpu cpu __maybe_unused)
4646
{
4747
char *bufp;
4848
unsigned long pvr;

tools/perf/arch/riscv/util/header.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
9898
}
9999

100100
char *
101-
get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
101+
get_cpuid_str(struct perf_cpu cpu __maybe_unused)
102102
{
103103
return _get_cpuid();
104104
}

tools/perf/arch/s390/util/header.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ int get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
137137
return (nbytes >= sz) ? ENOBUFS : 0;
138138
}
139139

140-
char *get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
140+
char *get_cpuid_str(struct perf_cpu cpu)
141141
{
142142
char *buf = malloc(128);
143143

144-
if (buf && get_cpuid(buf, 128))
144+
if (buf && get_cpuid(buf, 128, cpu))
145145
zfree(&buf);
146146
return buf;
147147
}

tools/perf/arch/x86/util/header.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ get_cpuid(char *buffer, size_t sz, struct perf_cpu cpu __maybe_unused)
6363
return __get_cpuid(buffer, sz, "%s,%u,%u,%u$");
6464
}
6565

66-
char *
67-
get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
66+
char *get_cpuid_str(struct perf_cpu cpu __maybe_unused)
6867
{
6968
char *buf = malloc(128);
7069

tools/perf/pmu-events/empty-pmu-events.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,16 @@ static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu)
515515
} last_map_search;
516516
static bool has_last_result, has_last_map_search;
517517
const struct pmu_events_map *map = NULL;
518+
struct perf_cpu cpu = {-1};
518519
char *cpuid = NULL;
519520
size_t i;
520521

521522
if (has_last_result && last_result.pmu == pmu)
522523
return last_result.map;
523524

524-
cpuid = perf_pmu__getcpuid(pmu);
525+
if (pmu)
526+
cpu = perf_cpu_map__min(pmu->cpus);
527+
cpuid = get_cpuid_allow_env_override(cpu);
525528

526529
/*
527530
* On some platforms which uses cpus map, cpuid can be NULL for

tools/perf/pmu-events/jevents.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,13 +1031,16 @@ def print_system_mapping_table() -> None:
10311031
} last_map_search;
10321032
static bool has_last_result, has_last_map_search;
10331033
const struct pmu_events_map *map = NULL;
1034+
struct perf_cpu cpu = {-1};
10341035
char *cpuid = NULL;
10351036
size_t i;
10361037
10371038
if (has_last_result && last_result.pmu == pmu)
10381039
return last_result.map;
10391040
1040-
cpuid = perf_pmu__getcpuid(pmu);
1041+
if (pmu)
1042+
cpu = perf_cpu_map__min(pmu->cpus);
1043+
cpuid = get_cpuid_allow_env_override(cpu);
10411044
10421045
/*
10431046
* On some platforms which uses cpus map, cpuid can be NULL for

tools/perf/tests/expr.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#include "util/expr.h"
55
#include "util/hashmap.h"
66
#include "util/header.h"
7-
#include "util/pmu.h"
8-
#include "util/pmus.h"
97
#include "util/smt.h"
108
#include "tests.h"
9+
#include <perf/cpumap.h>
1110
#include <math.h>
1211
#include <stdlib.h>
1312
#include <string.h>
@@ -78,8 +77,8 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
7877
struct expr_parse_ctx *ctx;
7978
bool is_intel = false;
8079
char strcmp_cpuid_buf[256];
81-
struct perf_pmu *pmu = perf_pmus__find_core_pmu();
82-
char *cpuid = perf_pmu__getcpuid(pmu);
80+
struct perf_cpu cpu = {-1};
81+
char *cpuid = get_cpuid_allow_env_override(cpu);
8382
char *escaped_cpuid1, *escaped_cpuid2;
8483

8584
TEST_ASSERT_VAL("get_cpuid", cpuid);

0 commit comments

Comments
 (0)