|
6 | 6 |
|
7 | 7 | #include "../../../util/perf_regs.h"
|
8 | 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" |
9 | 13 |
|
10 | 14 | #include <linux/kernel.h>
|
11 | 15 |
|
| 16 | +#define PVR_POWER9 0x004E |
| 17 | + |
12 | 18 | const struct sample_reg sample_reg_masks[] = {
|
13 | 19 | SMPL_REG(r0, PERF_REG_POWERPC_R0),
|
14 | 20 | SMPL_REG(r1, PERF_REG_POWERPC_R1),
|
@@ -55,6 +61,9 @@ const struct sample_reg sample_reg_masks[] = {
|
55 | 61 | SMPL_REG(dsisr, PERF_REG_POWERPC_DSISR),
|
56 | 62 | SMPL_REG(sier, PERF_REG_POWERPC_SIER),
|
57 | 63 | SMPL_REG(mmcra, PERF_REG_POWERPC_MMCRA),
|
| 64 | + SMPL_REG(mmcr0, PERF_REG_POWERPC_MMCR0), |
| 65 | + SMPL_REG(mmcr1, PERF_REG_POWERPC_MMCR1), |
| 66 | + SMPL_REG(mmcr2, PERF_REG_POWERPC_MMCR2), |
58 | 67 | SMPL_REG_END
|
59 | 68 | };
|
60 | 69 |
|
@@ -163,3 +172,43 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
|
163 | 172 |
|
164 | 173 | return SDT_ARG_VALID;
|
165 | 174 | }
|
| 175 | + |
| 176 | +uint64_t arch__intr_reg_mask(void) |
| 177 | +{ |
| 178 | + struct perf_event_attr attr = { |
| 179 | + .type = PERF_TYPE_HARDWARE, |
| 180 | + .config = PERF_COUNT_HW_CPU_CYCLES, |
| 181 | + .sample_type = PERF_SAMPLE_REGS_INTR, |
| 182 | + .precise_ip = 1, |
| 183 | + .disabled = 1, |
| 184 | + .exclude_kernel = 1, |
| 185 | + }; |
| 186 | + int fd; |
| 187 | + u32 version; |
| 188 | + u64 extended_mask = 0, mask = PERF_REGS_MASK; |
| 189 | + |
| 190 | + /* |
| 191 | + * Get the PVR value to set the extended |
| 192 | + * mask specific to platform. |
| 193 | + */ |
| 194 | + version = (((mfspr(SPRN_PVR)) >> 16) & 0xFFFF); |
| 195 | + if (version == PVR_POWER9) |
| 196 | + extended_mask = PERF_REG_PMU_MASK_300; |
| 197 | + else |
| 198 | + return mask; |
| 199 | + |
| 200 | + attr.sample_regs_intr = extended_mask; |
| 201 | + attr.sample_period = 1; |
| 202 | + event_attr_init(&attr); |
| 203 | + |
| 204 | + /* |
| 205 | + * check if the pmu supports perf extended regs, before |
| 206 | + * returning the register mask to sample. |
| 207 | + */ |
| 208 | + fd = sys_perf_event_open(&attr, 0, -1, -1, 0); |
| 209 | + if (fd != -1) { |
| 210 | + close(fd); |
| 211 | + mask |= extended_mask; |
| 212 | + } |
| 213 | + return mask; |
| 214 | +} |
0 commit comments