1
2
3
4
5
6
7
8
9
10
11
12
13
14#define pr_fmt(fmt) "power9-pmu: " fmt
15
16#include "isa207-common.h"
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83#define EVENT(_name, _code) _name = _code,
84
85enum {
86#include "power9-events-list.h"
87};
88
89#undef EVENT
90
91
92#define POWER9_MMCRA_IFM1 0x0000000040000000UL
93#define POWER9_MMCRA_IFM2 0x0000000080000000UL
94#define POWER9_MMCRA_IFM3 0x00000000C0000000UL
95#define POWER9_MMCRA_BHRB_MASK 0x00000000C0000000UL
96
97extern u64 PERF_REG_EXTENDED_MASK;
98
99
100#define PVR_POWER9_CUMULUS 0x00002000
101
102
103extern struct attribute_group isa207_pmu_format_group;
104
105int p9_dd21_bl_ev[] = {
106 PM_MRK_ST_DONE_L2,
107 PM_RADIX_PWC_L1_HIT,
108 PM_FLOP_CMPL,
109 PM_MRK_NTF_FIN,
110 PM_RADIX_PWC_L2_HIT,
111 PM_IFETCH_THROTTLE,
112 PM_MRK_L2_TM_ST_ABORT_SISTER,
113 PM_RADIX_PWC_L3_HIT,
114 PM_RUN_CYC_SMT2_MODE,
115 PM_TM_TX_PASS_RUN_INST,
116 PM_DISP_HELD_SYNC_HOLD,
117};
118
119int p9_dd22_bl_ev[] = {
120 PM_DTLB_MISS_16G,
121 PM_DERAT_MISS_2M,
122 PM_DTLB_MISS_2M,
123 PM_MRK_DTLB_MISS_1G,
124 PM_DTLB_MISS_4K,
125 PM_DERAT_MISS_1G,
126 PM_MRK_DERAT_MISS_2M,
127 PM_MRK_DTLB_MISS_4K,
128 PM_MRK_DTLB_MISS_16G,
129 PM_DTLB_MISS_64K,
130 PM_MRK_DERAT_MISS_1G,
131 PM_MRK_DTLB_MISS_64K,
132 PM_DISP_HELD_SYNC_HOLD,
133 PM_DTLB_MISS_16M,
134 PM_DTLB_MISS_1G,
135 PM_MRK_DTLB_MISS_16M,
136};
137
138
139static const unsigned int power9_event_alternatives[][MAX_ALT] = {
140 { PM_INST_DISP, PM_INST_DISP_ALT },
141 { PM_RUN_CYC_ALT, PM_RUN_CYC },
142 { PM_RUN_INST_CMPL_ALT, PM_RUN_INST_CMPL },
143 { PM_LD_MISS_L1, PM_LD_MISS_L1_ALT },
144 { PM_BR_2PATH, PM_BR_2PATH_ALT },
145};
146
147static int power9_get_alternatives(u64 event, unsigned int flags, u64 alt[])
148{
149 int num_alt = 0;
150
151 num_alt = isa207_get_alternatives(event, alt,
152 ARRAY_SIZE(power9_event_alternatives), flags,
153 power9_event_alternatives);
154
155 return num_alt;
156}
157
158GENERIC_EVENT_ATTR(cpu-cycles, PM_CYC);
159GENERIC_EVENT_ATTR(stalled-cycles-frontend, PM_ICT_NOSLOT_CYC);
160GENERIC_EVENT_ATTR(stalled-cycles-backend, PM_CMPLU_STALL);
161GENERIC_EVENT_ATTR(instructions, PM_INST_CMPL);
162GENERIC_EVENT_ATTR(branch-instructions, PM_BR_CMPL);
163GENERIC_EVENT_ATTR(branch-misses, PM_BR_MPRED_CMPL);
164GENERIC_EVENT_ATTR(cache-references, PM_LD_REF_L1);
165GENERIC_EVENT_ATTR(cache-misses, PM_LD_MISS_L1_FIN);
166GENERIC_EVENT_ATTR(mem-loads, MEM_LOADS);
167GENERIC_EVENT_ATTR(mem-stores, MEM_STORES);
168
169CACHE_EVENT_ATTR(L1-dcache-load-misses, PM_LD_MISS_L1_FIN);
170CACHE_EVENT_ATTR(L1-dcache-loads, PM_LD_REF_L1);
171CACHE_EVENT_ATTR(L1-dcache-prefetches, PM_L1_PREF);
172CACHE_EVENT_ATTR(L1-dcache-store-misses, PM_ST_MISS_L1);
173CACHE_EVENT_ATTR(L1-icache-load-misses, PM_L1_ICACHE_MISS);
174CACHE_EVENT_ATTR(L1-icache-loads, PM_INST_FROM_L1);
175CACHE_EVENT_ATTR(L1-icache-prefetches, PM_IC_PREF_WRITE);
176CACHE_EVENT_ATTR(LLC-load-misses, PM_DATA_FROM_L3MISS);
177CACHE_EVENT_ATTR(LLC-loads, PM_DATA_FROM_L3);
178CACHE_EVENT_ATTR(LLC-prefetches, PM_L3_PREF_ALL);
179CACHE_EVENT_ATTR(branch-load-misses, PM_BR_MPRED_CMPL);
180CACHE_EVENT_ATTR(branch-loads, PM_BR_CMPL);
181CACHE_EVENT_ATTR(dTLB-load-misses, PM_DTLB_MISS);
182CACHE_EVENT_ATTR(iTLB-load-misses, PM_ITLB_MISS);
183
184static struct attribute *power9_events_attr[] = {
185 GENERIC_EVENT_PTR(PM_CYC),
186 GENERIC_EVENT_PTR(PM_ICT_NOSLOT_CYC),
187 GENERIC_EVENT_PTR(PM_CMPLU_STALL),
188 GENERIC_EVENT_PTR(PM_INST_CMPL),
189 GENERIC_EVENT_PTR(PM_BR_CMPL),
190 GENERIC_EVENT_PTR(PM_BR_MPRED_CMPL),
191 GENERIC_EVENT_PTR(PM_LD_REF_L1),
192 GENERIC_EVENT_PTR(PM_LD_MISS_L1_FIN),
193 GENERIC_EVENT_PTR(MEM_LOADS),
194 GENERIC_EVENT_PTR(MEM_STORES),
195 CACHE_EVENT_PTR(PM_LD_MISS_L1_FIN),
196 CACHE_EVENT_PTR(PM_LD_REF_L1),
197 CACHE_EVENT_PTR(PM_L1_PREF),
198 CACHE_EVENT_PTR(PM_ST_MISS_L1),
199 CACHE_EVENT_PTR(PM_L1_ICACHE_MISS),
200 CACHE_EVENT_PTR(PM_INST_FROM_L1),
201 CACHE_EVENT_PTR(PM_IC_PREF_WRITE),
202 CACHE_EVENT_PTR(PM_DATA_FROM_L3MISS),
203 CACHE_EVENT_PTR(PM_DATA_FROM_L3),
204 CACHE_EVENT_PTR(PM_L3_PREF_ALL),
205 CACHE_EVENT_PTR(PM_BR_MPRED_CMPL),
206 CACHE_EVENT_PTR(PM_BR_CMPL),
207 CACHE_EVENT_PTR(PM_DTLB_MISS),
208 CACHE_EVENT_PTR(PM_ITLB_MISS),
209 NULL
210};
211
212static struct attribute_group power9_pmu_events_group = {
213 .name = "events",
214 .attrs = power9_events_attr,
215};
216
217PMU_FORMAT_ATTR(event, "config:0-51");
218PMU_FORMAT_ATTR(pmcxsel, "config:0-7");
219PMU_FORMAT_ATTR(mark, "config:8");
220PMU_FORMAT_ATTR(combine, "config:10-11");
221PMU_FORMAT_ATTR(unit, "config:12-15");
222PMU_FORMAT_ATTR(pmc, "config:16-19");
223PMU_FORMAT_ATTR(cache_sel, "config:20-23");
224PMU_FORMAT_ATTR(sample_mode, "config:24-28");
225PMU_FORMAT_ATTR(thresh_sel, "config:29-31");
226PMU_FORMAT_ATTR(thresh_stop, "config:32-35");
227PMU_FORMAT_ATTR(thresh_start, "config:36-39");
228PMU_FORMAT_ATTR(thresh_cmp, "config:40-49");
229PMU_FORMAT_ATTR(sdar_mode, "config:50-51");
230
231static struct attribute *power9_pmu_format_attr[] = {
232 &format_attr_event.attr,
233 &format_attr_pmcxsel.attr,
234 &format_attr_mark.attr,
235 &format_attr_combine.attr,
236 &format_attr_unit.attr,
237 &format_attr_pmc.attr,
238 &format_attr_cache_sel.attr,
239 &format_attr_sample_mode.attr,
240 &format_attr_thresh_sel.attr,
241 &format_attr_thresh_stop.attr,
242 &format_attr_thresh_start.attr,
243 &format_attr_thresh_cmp.attr,
244 &format_attr_sdar_mode.attr,
245 NULL,
246};
247
248static struct attribute_group power9_pmu_format_group = {
249 .name = "format",
250 .attrs = power9_pmu_format_attr,
251};
252
253static const struct attribute_group *power9_pmu_attr_groups[] = {
254 &power9_pmu_format_group,
255 &power9_pmu_events_group,
256 NULL,
257};
258
259static int power9_generic_events[] = {
260 [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC,
261 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = PM_ICT_NOSLOT_CYC,
262 [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = PM_CMPLU_STALL,
263 [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL,
264 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BR_CMPL,
265 [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED_CMPL,
266 [PERF_COUNT_HW_CACHE_REFERENCES] = PM_LD_REF_L1,
267 [PERF_COUNT_HW_CACHE_MISSES] = PM_LD_MISS_L1_FIN,
268};
269
270static u64 power9_bhrb_filter_map(u64 branch_sample_type)
271{
272 u64 pmu_bhrb_filter = 0;
273
274
275
276
277
278
279
280
281
282 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY)
283 return pmu_bhrb_filter;
284
285
286 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN)
287 return -1;
288
289 if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)
290 return -1;
291
292 if (branch_sample_type & PERF_SAMPLE_BRANCH_CALL)
293 return -1;
294
295 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {
296 pmu_bhrb_filter |= POWER9_MMCRA_IFM1;
297 return pmu_bhrb_filter;
298 }
299
300
301 return -1;
302}
303
304static void power9_config_bhrb(u64 pmu_bhrb_filter)
305{
306 pmu_bhrb_filter &= POWER9_MMCRA_BHRB_MASK;
307
308
309 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
310}
311
312#define C(x) PERF_COUNT_HW_CACHE_##x
313
314
315
316
317
318
319static u64 power9_cache_events[C(MAX)][C(OP_MAX)][C(RESULT_MAX)] = {
320 [ C(L1D) ] = {
321 [ C(OP_READ) ] = {
322 [ C(RESULT_ACCESS) ] = PM_LD_REF_L1,
323 [ C(RESULT_MISS) ] = PM_LD_MISS_L1_FIN,
324 },
325 [ C(OP_WRITE) ] = {
326 [ C(RESULT_ACCESS) ] = 0,
327 [ C(RESULT_MISS) ] = PM_ST_MISS_L1,
328 },
329 [ C(OP_PREFETCH) ] = {
330 [ C(RESULT_ACCESS) ] = PM_L1_PREF,
331 [ C(RESULT_MISS) ] = 0,
332 },
333 },
334 [ C(L1I) ] = {
335 [ C(OP_READ) ] = {
336 [ C(RESULT_ACCESS) ] = PM_INST_FROM_L1,
337 [ C(RESULT_MISS) ] = PM_L1_ICACHE_MISS,
338 },
339 [ C(OP_WRITE) ] = {
340 [ C(RESULT_ACCESS) ] = PM_L1_DEMAND_WRITE,
341 [ C(RESULT_MISS) ] = -1,
342 },
343 [ C(OP_PREFETCH) ] = {
344 [ C(RESULT_ACCESS) ] = PM_IC_PREF_WRITE,
345 [ C(RESULT_MISS) ] = 0,
346 },
347 },
348 [ C(LL) ] = {
349 [ C(OP_READ) ] = {
350 [ C(RESULT_ACCESS) ] = PM_DATA_FROM_L3,
351 [ C(RESULT_MISS) ] = PM_DATA_FROM_L3MISS,
352 },
353 [ C(OP_WRITE) ] = {
354 [ C(RESULT_ACCESS) ] = 0,
355 [ C(RESULT_MISS) ] = 0,
356 },
357 [ C(OP_PREFETCH) ] = {
358 [ C(RESULT_ACCESS) ] = PM_L3_PREF_ALL,
359 [ C(RESULT_MISS) ] = 0,
360 },
361 },
362 [ C(DTLB) ] = {
363 [ C(OP_READ) ] = {
364 [ C(RESULT_ACCESS) ] = 0,
365 [ C(RESULT_MISS) ] = PM_DTLB_MISS,
366 },
367 [ C(OP_WRITE) ] = {
368 [ C(RESULT_ACCESS) ] = -1,
369 [ C(RESULT_MISS) ] = -1,
370 },
371 [ C(OP_PREFETCH) ] = {
372 [ C(RESULT_ACCESS) ] = -1,
373 [ C(RESULT_MISS) ] = -1,
374 },
375 },
376 [ C(ITLB) ] = {
377 [ C(OP_READ) ] = {
378 [ C(RESULT_ACCESS) ] = 0,
379 [ C(RESULT_MISS) ] = PM_ITLB_MISS,
380 },
381 [ C(OP_WRITE) ] = {
382 [ C(RESULT_ACCESS) ] = -1,
383 [ C(RESULT_MISS) ] = -1,
384 },
385 [ C(OP_PREFETCH) ] = {
386 [ C(RESULT_ACCESS) ] = -1,
387 [ C(RESULT_MISS) ] = -1,
388 },
389 },
390 [ C(BPU) ] = {
391 [ C(OP_READ) ] = {
392 [ C(RESULT_ACCESS) ] = PM_BR_CMPL,
393 [ C(RESULT_MISS) ] = PM_BR_MPRED_CMPL,
394 },
395 [ C(OP_WRITE) ] = {
396 [ C(RESULT_ACCESS) ] = -1,
397 [ C(RESULT_MISS) ] = -1,
398 },
399 [ C(OP_PREFETCH) ] = {
400 [ C(RESULT_ACCESS) ] = -1,
401 [ C(RESULT_MISS) ] = -1,
402 },
403 },
404 [ C(NODE) ] = {
405 [ C(OP_READ) ] = {
406 [ C(RESULT_ACCESS) ] = -1,
407 [ C(RESULT_MISS) ] = -1,
408 },
409 [ C(OP_WRITE) ] = {
410 [ C(RESULT_ACCESS) ] = -1,
411 [ C(RESULT_MISS) ] = -1,
412 },
413 [ C(OP_PREFETCH) ] = {
414 [ C(RESULT_ACCESS) ] = -1,
415 [ C(RESULT_MISS) ] = -1,
416 },
417 },
418};
419
420#undef C
421
422static struct power_pmu power9_pmu = {
423 .name = "POWER9",
424 .n_counter = MAX_PMU_COUNTERS,
425 .add_fields = ISA207_ADD_FIELDS,
426 .test_adder = ISA207_TEST_ADDER,
427 .group_constraint_mask = CNST_CACHE_PMC4_MASK,
428 .group_constraint_val = CNST_CACHE_PMC4_VAL,
429 .compute_mmcr = isa207_compute_mmcr,
430 .config_bhrb = power9_config_bhrb,
431 .bhrb_filter_map = power9_bhrb_filter_map,
432 .get_constraint = isa207_get_constraint,
433 .get_alternatives = power9_get_alternatives,
434 .get_mem_data_src = isa207_get_mem_data_src,
435 .get_mem_weight = isa207_get_mem_weight,
436 .disable_pmc = isa207_disable_pmc,
437 .flags = PPMU_HAS_SIER | PPMU_ARCH_207S,
438 .n_generic = ARRAY_SIZE(power9_generic_events),
439 .generic_events = power9_generic_events,
440 .cache_events = &power9_cache_events,
441 .attr_groups = power9_pmu_attr_groups,
442 .bhrb_nr = 32,
443 .capabilities = PERF_PMU_CAP_EXTENDED_REGS,
444};
445
446int init_power9_pmu(void)
447{
448 int rc = 0;
449 unsigned int pvr = mfspr(SPRN_PVR);
450
451
452 if (!cur_cpu_spec->oprofile_cpu_type ||
453 strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power9"))
454 return -ENODEV;
455
456
457 if (!(pvr & PVR_POWER9_CUMULUS)) {
458 if ((PVR_CFG(pvr) == 2) && (PVR_MIN(pvr) == 1)) {
459 power9_pmu.blacklist_ev = p9_dd21_bl_ev;
460 power9_pmu.n_blacklist_ev = ARRAY_SIZE(p9_dd21_bl_ev);
461 } else if ((PVR_CFG(pvr) == 2) && (PVR_MIN(pvr) == 2)) {
462 power9_pmu.blacklist_ev = p9_dd22_bl_ev;
463 power9_pmu.n_blacklist_ev = ARRAY_SIZE(p9_dd22_bl_ev);
464 }
465 }
466
467
468 PERF_REG_EXTENDED_MASK = PERF_REG_PMU_MASK_300;
469
470 rc = register_power_pmu(&power9_pmu);
471 if (rc)
472 return rc;
473
474
475 cur_cpu_spec->cpu_user_features2 |= PPC_FEATURE2_EBB;
476
477 return 0;
478}
479