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 <[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 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)