hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/tools/perf/arch/powerpc/util/perf_regs.c
....@@ -2,11 +2,19 @@
22 #include <errno.h>
33 #include <string.h>
44 #include <regex.h>
5
+#include <linux/zalloc.h>
56
6
-#include "../../perf.h"
7
-#include "../../util/util.h"
8
-#include "../../util/perf_regs.h"
9
-#include "../../util/debug.h"
7
+#include "../../../util/perf_regs.h"
8
+#include "../../../util/debug.h"
9
+#include "../../../util/event.h"
10
+#include "../../../util/header.h"
11
+#include "../../../perf-sys.h"
12
+#include "utils_header.h"
13
+
14
+#include <linux/kernel.h>
15
+
16
+#define PVR_POWER9 0x004E
17
+#define PVR_POWER10 0x0080
1018
1119 const struct sample_reg sample_reg_masks[] = {
1220 SMPL_REG(r0, PERF_REG_POWERPC_R0),
....@@ -52,6 +60,14 @@
5260 SMPL_REG(trap, PERF_REG_POWERPC_TRAP),
5361 SMPL_REG(dar, PERF_REG_POWERPC_DAR),
5462 SMPL_REG(dsisr, PERF_REG_POWERPC_DSISR),
63
+ SMPL_REG(sier, PERF_REG_POWERPC_SIER),
64
+ SMPL_REG(mmcra, PERF_REG_POWERPC_MMCRA),
65
+ SMPL_REG(mmcr0, PERF_REG_POWERPC_MMCR0),
66
+ SMPL_REG(mmcr1, PERF_REG_POWERPC_MMCR1),
67
+ SMPL_REG(mmcr2, PERF_REG_POWERPC_MMCR2),
68
+ SMPL_REG(mmcr3, PERF_REG_POWERPC_MMCR3),
69
+ SMPL_REG(sier2, PERF_REG_POWERPC_SIER2),
70
+ SMPL_REG(sier3, PERF_REG_POWERPC_SIER3),
5571 SMPL_REG_END
5672 };
5773
....@@ -160,3 +176,45 @@
160176
161177 return SDT_ARG_VALID;
162178 }
179
+
180
+uint64_t arch__intr_reg_mask(void)
181
+{
182
+ struct perf_event_attr attr = {
183
+ .type = PERF_TYPE_HARDWARE,
184
+ .config = PERF_COUNT_HW_CPU_CYCLES,
185
+ .sample_type = PERF_SAMPLE_REGS_INTR,
186
+ .precise_ip = 1,
187
+ .disabled = 1,
188
+ .exclude_kernel = 1,
189
+ };
190
+ int fd;
191
+ u32 version;
192
+ u64 extended_mask = 0, mask = PERF_REGS_MASK;
193
+
194
+ /*
195
+ * Get the PVR value to set the extended
196
+ * mask specific to platform.
197
+ */
198
+ version = (((mfspr(SPRN_PVR)) >> 16) & 0xFFFF);
199
+ if (version == PVR_POWER9)
200
+ extended_mask = PERF_REG_PMU_MASK_300;
201
+ else if (version == PVR_POWER10)
202
+ extended_mask = PERF_REG_PMU_MASK_31;
203
+ else
204
+ return mask;
205
+
206
+ attr.sample_regs_intr = extended_mask;
207
+ attr.sample_period = 1;
208
+ event_attr_init(&attr);
209
+
210
+ /*
211
+ * check if the pmu supports perf extended regs, before
212
+ * returning the register mask to sample.
213
+ */
214
+ fd = sys_perf_event_open(&attr, 0, -1, -1, 0);
215
+ if (fd != -1) {
216
+ close(fd);
217
+ mask |= extended_mask;
218
+ }
219
+ return mask;
220
+}