Skip to content

Commit df5a5f3

Browse files
John Garryacmel
authored andcommitted
perf tools: Add arm64 version of get_cpuid()
Add an arm64 version of get_cpuid(), which is used for various annotation and headers - for example, I now get the CPUID in "perf report --header", as shown in this snippet: # hostname : ubuntu # os release : 5.5.0-rc1-dirty # perf version : 5.5.rc1.gbf8a13dc9851 # arch : aarch64 # nrcpus online : 96 # nrcpus avail : 96 # cpuid : 0x00000000480fd010 Since much of the code to read the MIDR is already in get_cpuid_str(), factor out this code. Tester notes: I tested this patch on my new ARM64 Kunpeng 920 server. [root@node1 zsk]# ./perf --version perf version 5.6.rc1.g2cdb955b7252 Both perf list and perf stat can work. Signed-off-by: John Garry <[email protected]> Tested-by: Shaokun Zhang <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 365f9cc commit df5a5f3

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

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

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include <stdio.h>
22
#include <stdlib.h>
33
#include <perf/cpumap.h>
4+
#include <util/cpumap.h>
45
#include <internal/cpumap.h>
56
#include <api/fs/fs.h>
7+
#include <errno.h>
68
#include "debug.h"
79
#include "header.h"
810

@@ -12,26 +14,21 @@
1214
#define MIDR_VARIANT_SHIFT 20
1315
#define MIDR_VARIANT_MASK (0xf << MIDR_VARIANT_SHIFT)
1416

15-
char *get_cpuid_str(struct perf_pmu *pmu)
17+
static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus)
1618
{
17-
char *buf = NULL;
18-
char path[PATH_MAX];
1919
const char *sysfs = sysfs__mountpoint();
20-
int cpu;
2120
u64 midr = 0;
22-
struct perf_cpu_map *cpus;
23-
FILE *file;
21+
int cpu;
2422

25-
if (!sysfs || !pmu || !pmu->cpus)
26-
return NULL;
23+
if (!sysfs || sz < MIDR_SIZE)
24+
return EINVAL;
2725

28-
buf = malloc(MIDR_SIZE);
29-
if (!buf)
30-
return NULL;
26+
cpus = perf_cpu_map__get(cpus);
3127

32-
/* read midr from list of cpus mapped to this pmu */
33-
cpus = perf_cpu_map__get(pmu->cpus);
3428
for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) {
29+
char path[PATH_MAX];
30+
FILE *file;
31+
3532
scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d"MIDR,
3633
sysfs, cpus->map[cpu]);
3734

@@ -57,12 +54,48 @@ char *get_cpuid_str(struct perf_pmu *pmu)
5754
break;
5855
}
5956

60-
if (!midr) {
57+
perf_cpu_map__put(cpus);
58+
59+
if (!midr)
60+
return EINVAL;
61+
62+
return 0;
63+
}
64+
65+
int get_cpuid(char *buf, size_t sz)
66+
{
67+
struct perf_cpu_map *cpus = perf_cpu_map__new(NULL);
68+
int ret;
69+
70+
if (!cpus)
71+
return EINVAL;
72+
73+
ret = _get_cpuid(buf, sz, cpus);
74+
75+
perf_cpu_map__put(cpus);
76+
77+
return ret;
78+
}
79+
80+
char *get_cpuid_str(struct perf_pmu *pmu)
81+
{
82+
char *buf = NULL;
83+
int res;
84+
85+
if (!pmu || !pmu->cpus)
86+
return NULL;
87+
88+
buf = malloc(MIDR_SIZE);
89+
if (!buf)
90+
return NULL;
91+
92+
/* read midr from list of cpus mapped to this pmu */
93+
res = _get_cpuid(buf, MIDR_SIZE, pmu->cpus);
94+
if (res) {
6195
pr_err("failed to get cpuid string for PMU %s\n", pmu->name);
6296
free(buf);
6397
buf = NULL;
6498
}
6599

66-
perf_cpu_map__put(cpus);
67100
return buf;
68101
}

0 commit comments

Comments
 (0)