hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/tools/perf/arch/arm64/util/header.c
....@@ -1,6 +1,11 @@
11 #include <stdio.h>
22 #include <stdlib.h>
3
+#include <perf/cpumap.h>
4
+#include <util/cpumap.h>
5
+#include <internal/cpumap.h>
36 #include <api/fs/fs.h>
7
+#include <errno.h>
8
+#include "debug.h"
49 #include "header.h"
510
611 #define MIDR "/regs/identification/midr_el1"
....@@ -9,26 +14,21 @@
914 #define MIDR_VARIANT_SHIFT 20
1015 #define MIDR_VARIANT_MASK (0xf << MIDR_VARIANT_SHIFT)
1116
12
-char *get_cpuid_str(struct perf_pmu *pmu)
17
+static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus)
1318 {
14
- char *buf = NULL;
15
- char path[PATH_MAX];
1619 const char *sysfs = sysfs__mountpoint();
17
- int cpu;
1820 u64 midr = 0;
19
- struct cpu_map *cpus;
20
- FILE *file;
21
+ int cpu;
2122
22
- if (!sysfs || !pmu || !pmu->cpus)
23
- return NULL;
23
+ if (!sysfs || sz < MIDR_SIZE)
24
+ return EINVAL;
2425
25
- buf = malloc(MIDR_SIZE);
26
- if (!buf)
27
- return NULL;
26
+ cpus = perf_cpu_map__get(cpus);
2827
29
- /* read midr from list of cpus mapped to this pmu */
30
- cpus = cpu_map__get(pmu->cpus);
31
- for (cpu = 0; cpu < cpus->nr; cpu++) {
28
+ for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) {
29
+ char path[PATH_MAX];
30
+ FILE *file;
31
+
3232 scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d"MIDR,
3333 sysfs, cpus->map[cpu]);
3434
....@@ -54,12 +54,48 @@
5454 break;
5555 }
5656
57
- 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) {
5895 pr_err("failed to get cpuid string for PMU %s\n", pmu->name);
5996 free(buf);
6097 buf = NULL;
6198 }
6299
63
- cpu_map__put(cpus);
64100 return buf;
65101 }