blob: d59f5b2d4c2f6922cebaecf41b3d99b80a925b69 [file] [log] [blame]
Michael Ellermane05b9b92013-04-25 19:28:28 +00001/*
2 * Performance counter support for POWER8 processors.
3 *
4 * Copyright 2009 Paul Mackerras, IBM Corporation.
5 * Copyright 2013 Michael Ellerman, IBM Corporation.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#include <linux/kernel.h>
14#include <linux/perf_event.h>
15#include <asm/firmware.h>
16
17
18/*
19 * Some power8 event codes.
20 */
21#define PM_CYC 0x0001e
22#define PM_GCT_NOSLOT_CYC 0x100f8
23#define PM_CMPLU_STALL 0x4000a
24#define PM_INST_CMPL 0x00002
25#define PM_BRU_FIN 0x10068
26#define PM_BR_MPRED_CMPL 0x400f6
27
28
29/*
30 * Raw event encoding for POWER8:
31 *
32 * 60 56 52 48 44 40 36 32
33 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
34 * [ thresh_cmp ] [ thresh_ctl ]
35 * |
36 * thresh start/stop OR FAB match -*
37 *
38 * 28 24 20 16 12 8 4 0
39 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
40 * [ ] [ sample ] [cache] [ pmc ] [unit ] c m [ pmcxsel ]
41 * | | | | |
42 * | | | | *- mark
43 * | | *- L1/L2/L3 cache_sel |
44 * | | |
45 * | *- sampling mode for marked events *- combine
46 * |
47 * *- thresh_sel
48 *
49 * Below uses IBM bit numbering.
50 *
51 * MMCR1[x:y] = unit (PMCxUNIT)
52 * MMCR1[x] = combine (PMCxCOMB)
53 *
54 * if pmc == 3 and unit == 0 and pmcxsel[0:6] == 0b0101011
55 * # PM_MRK_FAB_RSP_MATCH
56 * MMCR1[20:27] = thresh_ctl (FAB_CRESP_MATCH / FAB_TYPE_MATCH)
57 * else if pmc == 4 and unit == 0xf and pmcxsel[0:6] == 0b0101001
58 * # PM_MRK_FAB_RSP_MATCH_CYC
59 * MMCR1[20:27] = thresh_ctl (FAB_CRESP_MATCH / FAB_TYPE_MATCH)
60 * else
61 * MMCRA[48:55] = thresh_ctl (THRESH START/END)
62 *
63 * if thresh_sel:
64 * MMCRA[45:47] = thresh_sel
65 *
66 * if thresh_cmp:
67 * MMCRA[22:24] = thresh_cmp[0:2]
68 * MMCRA[25:31] = thresh_cmp[3:9]
69 *
70 * if unit == 6 or unit == 7
71 * MMCRC[53:55] = cache_sel[1:3] (L2EVENT_SEL)
72 * else if unit == 8 or unit == 9:
73 * if cache_sel[0] == 0: # L3 bank
74 * MMCRC[47:49] = cache_sel[1:3] (L3EVENT_SEL0)
75 * else if cache_sel[0] == 1:
76 * MMCRC[50:51] = cache_sel[2:3] (L3EVENT_SEL1)
77 * else if cache_sel[1]: # L1 event
78 * MMCR1[16] = cache_sel[2]
79 * MMCR1[17] = cache_sel[3]
80 *
81 * if mark:
82 * MMCRA[63] = 1 (SAMPLE_ENABLE)
83 * MMCRA[57:59] = sample[0:2] (RAND_SAMP_ELIG)
84 * MMCRA[61:62] = sample[3:4] (RAND_SAMP_MODE)
85 *
86 */
87
88#define EVENT_THR_CMP_SHIFT 40 /* Threshold CMP value */
89#define EVENT_THR_CMP_MASK 0x3ff
90#define EVENT_THR_CTL_SHIFT 32 /* Threshold control value (start/stop) */
91#define EVENT_THR_CTL_MASK 0xffull
92#define EVENT_THR_SEL_SHIFT 29 /* Threshold select value */
93#define EVENT_THR_SEL_MASK 0x7
94#define EVENT_THRESH_SHIFT 29 /* All threshold bits */
95#define EVENT_THRESH_MASK 0x1fffffull
96#define EVENT_SAMPLE_SHIFT 24 /* Sampling mode & eligibility */
97#define EVENT_SAMPLE_MASK 0x1f
98#define EVENT_CACHE_SEL_SHIFT 20 /* L2/L3 cache select */
99#define EVENT_CACHE_SEL_MASK 0xf
100#define EVENT_IS_L1 (4 << EVENT_CACHE_SEL_SHIFT)
101#define EVENT_PMC_SHIFT 16 /* PMC number (1-based) */
102#define EVENT_PMC_MASK 0xf
103#define EVENT_UNIT_SHIFT 12 /* Unit */
104#define EVENT_UNIT_MASK 0xf
105#define EVENT_COMBINE_SHIFT 11 /* Combine bit */
106#define EVENT_COMBINE_MASK 0x1
107#define EVENT_MARKED_SHIFT 8 /* Marked bit */
108#define EVENT_MARKED_MASK 0x1
109#define EVENT_IS_MARKED (EVENT_MARKED_MASK << EVENT_MARKED_SHIFT)
110#define EVENT_PSEL_MASK 0xff /* PMCxSEL value */
111
Michael Ellermand8bec4c2013-06-28 18:15:10 +1000112#define EVENT_VALID_MASK \
113 ((EVENT_THRESH_MASK << EVENT_THRESH_SHIFT) | \
114 (EVENT_SAMPLE_MASK << EVENT_SAMPLE_SHIFT) | \
115 (EVENT_CACHE_SEL_MASK << EVENT_CACHE_SEL_SHIFT) | \
116 (EVENT_PMC_MASK << EVENT_PMC_SHIFT) | \
117 (EVENT_UNIT_MASK << EVENT_UNIT_SHIFT) | \
118 (EVENT_COMBINE_MASK << EVENT_COMBINE_SHIFT) | \
119 (EVENT_MARKED_MASK << EVENT_MARKED_SHIFT) | \
120 EVENT_PSEL_MASK)
121
Anshuman Khandualb1113552013-04-22 19:42:43 +0000122/* MMCRA IFM bits - POWER8 */
123#define POWER8_MMCRA_IFM1 0x0000000040000000UL
124#define POWER8_MMCRA_IFM2 0x0000000080000000UL
125#define POWER8_MMCRA_IFM3 0x00000000C0000000UL
126
127#define ONLY_PLM \
128 (PERF_SAMPLE_BRANCH_USER |\
129 PERF_SAMPLE_BRANCH_KERNEL |\
130 PERF_SAMPLE_BRANCH_HV)
131
Michael Ellermane05b9b92013-04-25 19:28:28 +0000132/*
133 * Layout of constraint bits:
134 *
135 * 60 56 52 48 44 40 36 32
136 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
137 * [ fab_match ] [ thresh_cmp ] [ thresh_ctl ] [ ]
138 * |
139 * thresh_sel -*
140 *
141 * 28 24 20 16 12 8 4 0
142 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
143 * [ ] [ sample ] [ ] [6] [5] [4] [3] [2] [1]
144 * | |
145 * L1 I/D qualifier -* | Count of events for each PMC.
146 * | p1, p2, p3, p4, p5, p6.
147 * nc - number of counters -*
148 *
149 * The PMC fields P1..P6, and NC, are adder fields. As we accumulate constraints
150 * we want the low bit of each field to be added to any existing value.
151 *
152 * Everything else is a value field.
153 */
154
155#define CNST_FAB_MATCH_VAL(v) (((v) & EVENT_THR_CTL_MASK) << 56)
156#define CNST_FAB_MATCH_MASK CNST_FAB_MATCH_VAL(EVENT_THR_CTL_MASK)
157
158/* We just throw all the threshold bits into the constraint */
159#define CNST_THRESH_VAL(v) (((v) & EVENT_THRESH_MASK) << 32)
160#define CNST_THRESH_MASK CNST_THRESH_VAL(EVENT_THRESH_MASK)
161
162#define CNST_L1_QUAL_VAL(v) (((v) & 3) << 22)
163#define CNST_L1_QUAL_MASK CNST_L1_QUAL_VAL(3)
164
165#define CNST_SAMPLE_VAL(v) (((v) & EVENT_SAMPLE_MASK) << 16)
166#define CNST_SAMPLE_MASK CNST_SAMPLE_VAL(EVENT_SAMPLE_MASK)
167
168/*
169 * For NC we are counting up to 4 events. This requires three bits, and we need
170 * the fifth event to overflow and set the 4th bit. To achieve that we bias the
171 * fields by 3 in test_adder.
172 */
173#define CNST_NC_SHIFT 12
174#define CNST_NC_VAL (1 << CNST_NC_SHIFT)
175#define CNST_NC_MASK (8 << CNST_NC_SHIFT)
176#define POWER8_TEST_ADDER (3 << CNST_NC_SHIFT)
177
178/*
179 * For the per-PMC fields we have two bits. The low bit is added, so if two
180 * events ask for the same PMC the sum will overflow, setting the high bit,
181 * indicating an error. So our mask sets the high bit.
182 */
183#define CNST_PMC_SHIFT(pmc) ((pmc - 1) * 2)
184#define CNST_PMC_VAL(pmc) (1 << CNST_PMC_SHIFT(pmc))
185#define CNST_PMC_MASK(pmc) (2 << CNST_PMC_SHIFT(pmc))
186
187/* Our add_fields is defined as: */
188#define POWER8_ADD_FIELDS \
189 CNST_PMC_VAL(1) | CNST_PMC_VAL(2) | CNST_PMC_VAL(3) | \
190 CNST_PMC_VAL(4) | CNST_PMC_VAL(5) | CNST_PMC_VAL(6) | CNST_NC_VAL
191
192
193/* Bits in MMCR1 for POWER8 */
194#define MMCR1_UNIT_SHIFT(pmc) (60 - (4 * ((pmc) - 1)))
195#define MMCR1_COMBINE_SHIFT(pmc) (35 - ((pmc) - 1))
196#define MMCR1_PMCSEL_SHIFT(pmc) (24 - (((pmc) - 1)) * 8)
197#define MMCR1_DC_QUAL_SHIFT 47
198#define MMCR1_IC_QUAL_SHIFT 46
199
200/* Bits in MMCRA for POWER8 */
201#define MMCRA_SAMP_MODE_SHIFT 1
202#define MMCRA_SAMP_ELIG_SHIFT 4
203#define MMCRA_THR_CTL_SHIFT 8
204#define MMCRA_THR_SEL_SHIFT 16
205#define MMCRA_THR_CMP_SHIFT 32
206#define MMCRA_SDAR_MODE_TLB (1ull << 42)
207
208
209static inline bool event_is_fab_match(u64 event)
210{
211 /* Only check pmc, unit and pmcxsel, ignore the edge bit (0) */
212 event &= 0xff0fe;
213
214 /* PM_MRK_FAB_RSP_MATCH & PM_MRK_FAB_RSP_MATCH_CYC */
215 return (event == 0x30056 || event == 0x4f052);
216}
217
218static int power8_get_constraint(u64 event, unsigned long *maskp, unsigned long *valp)
219{
220 unsigned int unit, pmc, cache;
221 unsigned long mask, value;
222
223 mask = value = 0;
224
Michael Ellermand8bec4c2013-06-28 18:15:10 +1000225 if (event & ~EVENT_VALID_MASK)
226 return -1;
227
Michael Ellermane05b9b92013-04-25 19:28:28 +0000228 pmc = (event >> EVENT_PMC_SHIFT) & EVENT_PMC_MASK;
229 unit = (event >> EVENT_UNIT_SHIFT) & EVENT_UNIT_MASK;
230 cache = (event >> EVENT_CACHE_SEL_SHIFT) & EVENT_CACHE_SEL_MASK;
231
232 if (pmc) {
233 if (pmc > 6)
234 return -1;
235
236 mask |= CNST_PMC_MASK(pmc);
237 value |= CNST_PMC_VAL(pmc);
238
239 if (pmc >= 5 && event != 0x500fa && event != 0x600f4)
240 return -1;
241 }
242
243 if (pmc <= 4) {
244 /*
245 * Add to number of counters in use. Note this includes events with
246 * a PMC of 0 - they still need a PMC, it's just assigned later.
247 * Don't count events on PMC 5 & 6, there is only one valid event
248 * on each of those counters, and they are handled above.
249 */
250 mask |= CNST_NC_MASK;
251 value |= CNST_NC_VAL;
252 }
253
254 if (unit >= 6 && unit <= 9) {
255 /*
256 * L2/L3 events contain a cache selector field, which is
257 * supposed to be programmed into MMCRC. However MMCRC is only
258 * HV writable, and there is no API for guest kernels to modify
259 * it. The solution is for the hypervisor to initialise the
260 * field to zeroes, and for us to only ever allow events that
261 * have a cache selector of zero.
262 */
263 if (cache)
264 return -1;
265
266 } else if (event & EVENT_IS_L1) {
267 mask |= CNST_L1_QUAL_MASK;
268 value |= CNST_L1_QUAL_VAL(cache);
269 }
270
271 if (event & EVENT_IS_MARKED) {
272 mask |= CNST_SAMPLE_MASK;
273 value |= CNST_SAMPLE_VAL(event >> EVENT_SAMPLE_SHIFT);
274 }
275
276 /*
277 * Special case for PM_MRK_FAB_RSP_MATCH and PM_MRK_FAB_RSP_MATCH_CYC,
278 * the threshold control bits are used for the match value.
279 */
280 if (event_is_fab_match(event)) {
281 mask |= CNST_FAB_MATCH_MASK;
282 value |= CNST_FAB_MATCH_VAL(event >> EVENT_THR_CTL_SHIFT);
283 } else {
284 /*
285 * Check the mantissa upper two bits are not zero, unless the
286 * exponent is also zero. See the THRESH_CMP_MANTISSA doc.
287 */
288 unsigned int cmp, exp;
289
290 cmp = (event >> EVENT_THR_CMP_SHIFT) & EVENT_THR_CMP_MASK;
291 exp = cmp >> 7;
292
293 if (exp && (cmp & 0x60) == 0)
294 return -1;
295
296 mask |= CNST_THRESH_MASK;
297 value |= CNST_THRESH_VAL(event >> EVENT_THRESH_SHIFT);
298 }
299
300 *maskp = mask;
301 *valp = value;
302
303 return 0;
304}
305
306static int power8_compute_mmcr(u64 event[], int n_ev,
307 unsigned int hwc[], unsigned long mmcr[])
308{
309 unsigned long mmcra, mmcr1, unit, combine, psel, cache, val;
310 unsigned int pmc, pmc_inuse;
311 int i;
312
313 pmc_inuse = 0;
314
315 /* First pass to count resource use */
316 for (i = 0; i < n_ev; ++i) {
317 pmc = (event[i] >> EVENT_PMC_SHIFT) & EVENT_PMC_MASK;
318 if (pmc)
319 pmc_inuse |= 1 << pmc;
320 }
321
322 /* In continous sampling mode, update SDAR on TLB miss */
323 mmcra = MMCRA_SDAR_MODE_TLB;
324 mmcr1 = 0;
325
326 /* Second pass: assign PMCs, set all MMCR1 fields */
327 for (i = 0; i < n_ev; ++i) {
328 pmc = (event[i] >> EVENT_PMC_SHIFT) & EVENT_PMC_MASK;
329 unit = (event[i] >> EVENT_UNIT_SHIFT) & EVENT_UNIT_MASK;
330 combine = (event[i] >> EVENT_COMBINE_SHIFT) & EVENT_COMBINE_MASK;
331 psel = event[i] & EVENT_PSEL_MASK;
332
333 if (!pmc) {
334 for (pmc = 1; pmc <= 4; ++pmc) {
335 if (!(pmc_inuse & (1 << pmc)))
336 break;
337 }
338
339 pmc_inuse |= 1 << pmc;
340 }
341
342 if (pmc <= 4) {
343 mmcr1 |= unit << MMCR1_UNIT_SHIFT(pmc);
344 mmcr1 |= combine << MMCR1_COMBINE_SHIFT(pmc);
345 mmcr1 |= psel << MMCR1_PMCSEL_SHIFT(pmc);
346 }
347
348 if (event[i] & EVENT_IS_L1) {
349 cache = event[i] >> EVENT_CACHE_SEL_SHIFT;
350 mmcr1 |= (cache & 1) << MMCR1_IC_QUAL_SHIFT;
351 cache >>= 1;
352 mmcr1 |= (cache & 1) << MMCR1_DC_QUAL_SHIFT;
353 }
354
355 if (event[i] & EVENT_IS_MARKED) {
356 mmcra |= MMCRA_SAMPLE_ENABLE;
357
358 val = (event[i] >> EVENT_SAMPLE_SHIFT) & EVENT_SAMPLE_MASK;
359 if (val) {
360 mmcra |= (val & 3) << MMCRA_SAMP_MODE_SHIFT;
361 mmcra |= (val >> 2) << MMCRA_SAMP_ELIG_SHIFT;
362 }
363 }
364
365 /*
366 * PM_MRK_FAB_RSP_MATCH and PM_MRK_FAB_RSP_MATCH_CYC,
367 * the threshold bits are used for the match value.
368 */
369 if (event_is_fab_match(event[i])) {
370 mmcr1 |= (event[i] >> EVENT_THR_CTL_SHIFT) &
371 EVENT_THR_CTL_MASK;
372 } else {
373 val = (event[i] >> EVENT_THR_CTL_SHIFT) & EVENT_THR_CTL_MASK;
374 mmcra |= val << MMCRA_THR_CTL_SHIFT;
375 val = (event[i] >> EVENT_THR_SEL_SHIFT) & EVENT_THR_SEL_MASK;
376 mmcra |= val << MMCRA_THR_SEL_SHIFT;
377 val = (event[i] >> EVENT_THR_CMP_SHIFT) & EVENT_THR_CMP_MASK;
378 mmcra |= val << MMCRA_THR_CMP_SHIFT;
379 }
380
381 hwc[i] = pmc - 1;
382 }
383
384 /* Return MMCRx values */
385 mmcr[0] = 0;
386
387 /* pmc_inuse is 1-based */
388 if (pmc_inuse & 2)
389 mmcr[0] = MMCR0_PMC1CE;
390
391 if (pmc_inuse & 0x7c)
392 mmcr[0] |= MMCR0_PMCjCE;
393
Michael Ellerman7a7a41f2013-06-28 18:15:12 +1000394 /* If we're not using PMC 5 or 6, freeze them */
395 if (!(pmc_inuse & 0x60))
396 mmcr[0] |= MMCR0_FC56;
397
Michael Ellermane05b9b92013-04-25 19:28:28 +0000398 mmcr[1] = mmcr1;
399 mmcr[2] = mmcra;
400
401 return 0;
402}
403
404#define MAX_ALT 2
405
406/* Table of alternatives, sorted by column 0 */
407static const unsigned int event_alternatives[][MAX_ALT] = {
408 { 0x10134, 0x301e2 }, /* PM_MRK_ST_CMPL */
409 { 0x10138, 0x40138 }, /* PM_BR_MRK_2PATH */
410 { 0x18082, 0x3e05e }, /* PM_L3_CO_MEPF */
411 { 0x1d14e, 0x401e8 }, /* PM_MRK_DATA_FROM_L2MISS */
412 { 0x1e054, 0x4000a }, /* PM_CMPLU_STALL */
413 { 0x20036, 0x40036 }, /* PM_BR_2PATH */
414 { 0x200f2, 0x300f2 }, /* PM_INST_DISP */
415 { 0x200f4, 0x600f4 }, /* PM_RUN_CYC */
416 { 0x2013c, 0x3012e }, /* PM_MRK_FILT_MATCH */
417 { 0x3e054, 0x400f0 }, /* PM_LD_MISS_L1 */
418 { 0x400fa, 0x500fa }, /* PM_RUN_INST_CMPL */
419};
420
421/*
422 * Scan the alternatives table for a match and return the
423 * index into the alternatives table if found, else -1.
424 */
425static int find_alternative(u64 event)
426{
427 int i, j;
428
429 for (i = 0; i < ARRAY_SIZE(event_alternatives); ++i) {
430 if (event < event_alternatives[i][0])
431 break;
432
433 for (j = 0; j < MAX_ALT && event_alternatives[i][j]; ++j)
434 if (event == event_alternatives[i][j])
435 return i;
436 }
437
438 return -1;
439}
440
441static int power8_get_alternatives(u64 event, unsigned int flags, u64 alt[])
442{
443 int i, j, num_alt = 0;
444 u64 alt_event;
445
446 alt[num_alt++] = event;
447
448 i = find_alternative(event);
449 if (i >= 0) {
450 /* Filter out the original event, it's already in alt[0] */
451 for (j = 0; j < MAX_ALT; ++j) {
452 alt_event = event_alternatives[i][j];
453 if (alt_event && alt_event != event)
454 alt[num_alt++] = alt_event;
455 }
456 }
457
458 if (flags & PPMU_ONLY_COUNT_RUN) {
459 /*
460 * We're only counting in RUN state, so PM_CYC is equivalent to
461 * PM_RUN_CYC and PM_INST_CMPL === PM_RUN_INST_CMPL.
462 */
463 j = num_alt;
464 for (i = 0; i < num_alt; ++i) {
465 switch (alt[i]) {
466 case 0x1e: /* PM_CYC */
467 alt[j++] = 0x600f4; /* PM_RUN_CYC */
468 break;
469 case 0x600f4: /* PM_RUN_CYC */
470 alt[j++] = 0x1e;
471 break;
472 case 0x2: /* PM_PPC_CMPL */
473 alt[j++] = 0x500fa; /* PM_RUN_INST_CMPL */
474 break;
475 case 0x500fa: /* PM_RUN_INST_CMPL */
476 alt[j++] = 0x2; /* PM_PPC_CMPL */
477 break;
478 }
479 }
480 num_alt = j;
481 }
482
483 return num_alt;
484}
485
486static void power8_disable_pmc(unsigned int pmc, unsigned long mmcr[])
487{
488 if (pmc <= 3)
489 mmcr[1] &= ~(0xffUL << MMCR1_PMCSEL_SHIFT(pmc + 1));
490}
491
492PMU_FORMAT_ATTR(event, "config:0-49");
493PMU_FORMAT_ATTR(pmcxsel, "config:0-7");
494PMU_FORMAT_ATTR(mark, "config:8");
495PMU_FORMAT_ATTR(combine, "config:11");
496PMU_FORMAT_ATTR(unit, "config:12-15");
497PMU_FORMAT_ATTR(pmc, "config:16-19");
498PMU_FORMAT_ATTR(cache_sel, "config:20-23");
499PMU_FORMAT_ATTR(sample_mode, "config:24-28");
500PMU_FORMAT_ATTR(thresh_sel, "config:29-31");
501PMU_FORMAT_ATTR(thresh_stop, "config:32-35");
502PMU_FORMAT_ATTR(thresh_start, "config:36-39");
503PMU_FORMAT_ATTR(thresh_cmp, "config:40-49");
504
505static struct attribute *power8_pmu_format_attr[] = {
506 &format_attr_event.attr,
507 &format_attr_pmcxsel.attr,
508 &format_attr_mark.attr,
509 &format_attr_combine.attr,
510 &format_attr_unit.attr,
511 &format_attr_pmc.attr,
512 &format_attr_cache_sel.attr,
513 &format_attr_sample_mode.attr,
514 &format_attr_thresh_sel.attr,
515 &format_attr_thresh_stop.attr,
516 &format_attr_thresh_start.attr,
517 &format_attr_thresh_cmp.attr,
518 NULL,
519};
520
521struct attribute_group power8_pmu_format_group = {
522 .name = "format",
523 .attrs = power8_pmu_format_attr,
524};
525
526static const struct attribute_group *power8_pmu_attr_groups[] = {
527 &power8_pmu_format_group,
528 NULL,
529};
530
531static int power8_generic_events[] = {
532 [PERF_COUNT_HW_CPU_CYCLES] = PM_CYC,
533 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = PM_GCT_NOSLOT_CYC,
534 [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = PM_CMPLU_STALL,
535 [PERF_COUNT_HW_INSTRUCTIONS] = PM_INST_CMPL,
536 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = PM_BRU_FIN,
537 [PERF_COUNT_HW_BRANCH_MISSES] = PM_BR_MPRED_CMPL,
538};
539
Anshuman Khandualb1113552013-04-22 19:42:43 +0000540static u64 power8_bhrb_filter_map(u64 branch_sample_type)
541{
542 u64 pmu_bhrb_filter = 0;
543 u64 br_privilege = branch_sample_type & ONLY_PLM;
544
545 /* BHRB and regular PMU events share the same prvillege state
546 * filter configuration. BHRB is always recorded along with a
547 * regular PMU event. So privilege state filter criteria for BHRB
548 * and the companion PMU events has to be the same. As a default
549 * "perf record" tool sets all privillege bits ON when no filter
550 * criteria is provided in the command line. So as along as all
551 * privillege bits are ON or they are OFF, we are good to go.
552 */
553 if ((br_privilege != 7) && (br_privilege != 0))
554 return -1;
555
556 /* No branch filter requested */
557 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY)
558 return pmu_bhrb_filter;
559
560 /* Invalid branch filter options - HW does not support */
561 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_RETURN)
562 return -1;
563
564 if (branch_sample_type & PERF_SAMPLE_BRANCH_IND_CALL)
565 return -1;
566
567 if (branch_sample_type & PERF_SAMPLE_BRANCH_ANY_CALL) {
568 pmu_bhrb_filter |= POWER8_MMCRA_IFM1;
569 return pmu_bhrb_filter;
570 }
571
572 /* Every thing else is unsupported */
573 return -1;
574}
575
576static void power8_config_bhrb(u64 pmu_bhrb_filter)
577{
578 /* Enable BHRB filter in PMU */
579 mtspr(SPRN_MMCRA, (mfspr(SPRN_MMCRA) | pmu_bhrb_filter));
580}
581
Michael Ellermane05b9b92013-04-25 19:28:28 +0000582static struct power_pmu power8_pmu = {
583 .name = "POWER8",
584 .n_counter = 6,
585 .max_alternatives = MAX_ALT + 1,
586 .add_fields = POWER8_ADD_FIELDS,
587 .test_adder = POWER8_TEST_ADDER,
588 .compute_mmcr = power8_compute_mmcr,
Anshuman Khandualb1113552013-04-22 19:42:43 +0000589 .config_bhrb = power8_config_bhrb,
590 .bhrb_filter_map = power8_bhrb_filter_map,
Michael Ellermane05b9b92013-04-25 19:28:28 +0000591 .get_constraint = power8_get_constraint,
592 .get_alternatives = power8_get_alternatives,
593 .disable_pmc = power8_disable_pmc,
Anshuman Khandualb1113552013-04-22 19:42:43 +0000594 .flags = PPMU_HAS_SSLOT | PPMU_HAS_SIER | PPMU_BHRB,
Michael Ellermane05b9b92013-04-25 19:28:28 +0000595 .n_generic = ARRAY_SIZE(power8_generic_events),
596 .generic_events = power8_generic_events,
597 .attr_groups = power8_pmu_attr_groups,
Anshuman Khandualb1113552013-04-22 19:42:43 +0000598 .bhrb_nr = 32,
Michael Ellermane05b9b92013-04-25 19:28:28 +0000599};
600
601static int __init init_power8_pmu(void)
602{
603 if (!cur_cpu_spec->oprofile_cpu_type ||
604 strcmp(cur_cpu_spec->oprofile_cpu_type, "ppc64/power8"))
605 return -ENODEV;
606
607 return register_power_pmu(&power8_pmu);
608}
609early_initcall(init_power8_pmu);