Skip to content

Commit 538737d

Browse files
captain5050acmel
authored andcommitted
perf arm64 header: Use cpu argument in get_cpuid
Use the cpu to read the MIDR file requested. If the "any" value (-1) is passed that keep the behavior of returning the first MIDR file that can be read. 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-5-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent cec0d65 commit 538737d

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

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

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,52 @@
1414
#define MIDR_REVISION_MASK GENMASK(3, 0)
1515
#define MIDR_VARIANT_MASK GENMASK(23, 20)
1616

17-
static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus)
17+
static int _get_cpuid(char *buf, size_t sz, struct perf_cpu cpu)
1818
{
19+
char path[PATH_MAX];
20+
FILE *file;
1921
const char *sysfs = sysfs__mountpoint();
20-
struct perf_cpu cpu;
21-
int idx, ret = EINVAL;
2222

23+
assert(cpu.cpu != -1);
2324
if (!sysfs || sz < MIDR_SIZE)
2425
return EINVAL;
2526

26-
perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
27-
char path[PATH_MAX];
28-
FILE *file;
29-
30-
scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR,
31-
sysfs, cpu.cpu);
32-
33-
file = fopen(path, "r");
34-
if (!file) {
35-
pr_debug("fopen failed for file %s\n", path);
36-
continue;
37-
}
38-
39-
if (!fgets(buf, MIDR_SIZE, file)) {
40-
fclose(file);
41-
continue;
42-
}
43-
fclose(file);
27+
scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, sysfs, cpu.cpu);
4428

45-
/* got midr break loop */
46-
ret = 0;
47-
break;
29+
file = fopen(path, "r");
30+
if (!file) {
31+
pr_debug("fopen failed for file %s\n", path);
32+
return EINVAL;
4833
}
4934

50-
return ret;
35+
if (!fgets(buf, MIDR_SIZE, file)) {
36+
pr_debug("Failed to read file %s\n", path);
37+
fclose(file);
38+
return EINVAL;
39+
}
40+
fclose(file);
41+
return 0;
5142
}
5243

53-
int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu __maybe_unused)
44+
int get_cpuid(char *buf, size_t sz, struct perf_cpu cpu)
5445
{
55-
struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus();
56-
int ret;
46+
struct perf_cpu_map *cpus;
47+
int idx;
48+
49+
if (cpu.cpu != -1)
50+
return _get_cpuid(buf, sz, cpu);
5751

52+
cpus = perf_cpu_map__new_online_cpus();
5853
if (!cpus)
5954
return EINVAL;
6055

61-
ret = _get_cpuid(buf, sz, cpus);
62-
63-
perf_cpu_map__put(cpus);
56+
perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
57+
int ret = _get_cpuid(buf, sz, cpu);
6458

65-
return ret;
59+
if (ret == 0)
60+
return 0;
61+
}
62+
return EINVAL;
6663
}
6764

6865
char *get_cpuid_str(struct perf_pmu *pmu)
@@ -78,7 +75,7 @@ char *get_cpuid_str(struct perf_pmu *pmu)
7875
return NULL;
7976

8077
/* read midr from list of cpus mapped to this pmu */
81-
res = _get_cpuid(buf, MIDR_SIZE, pmu->cpus);
78+
res = get_cpuid(buf, MIDR_SIZE, perf_cpu_map__min(pmu->cpus));
8279
if (res) {
8380
pr_err("failed to get cpuid string for PMU %s\n", pmu->name);
8481
free(buf);

tools/perf/util/header.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/types.h>
1212
#include "env.h"
1313
#include "pmu.h"
14+
#include <perf/cpumap.h>
1415

1516
enum {
1617
HEADER_RESERVED = 0, /* always cleared */

0 commit comments

Comments
 (0)