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 <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Tested-by: Xu Yang <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Albert Ou <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Ben Zong-You Xie <[email protected]> Cc: Benjamin Gray <[email protected]> Cc: Bibo Mao <[email protected]> Cc: Clément Le Goffic <[email protected]> Cc: Dima Kogan <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mike Leach <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Sandipan Das <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yicong Yang <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
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)