2 * Performance counter support for POWER8 processors.
4 * Copyright 2009 Paul Mackerras, IBM Corporation.
5 * Copyright 2013 Michael Ellerman, IBM Corporation.
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.
13 #define pr_fmt(fmt) "power8-pmu: " fmt
15 #include <linux/kernel.h>
16 #include <linux/perf_event.h>
17 #include <asm/firmware.h>
18 #include <asm/cputable.h>
21 * Some power8 event codes.
23 #define EVENT(_name, _code) _name = _code,
26 #include "power8-events-list.h"
32 * Raw event encoding for POWER8:
34 * 60 56 52 48 44 40 36 32
35 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
36 * | | [ ] [ thresh_cmp ] [ thresh_ctl ]
38 * | | *- IFM (Linux) thresh start/stop OR FAB match -*
42 * 28 24 20 16 12 8 4 0
43 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
44 * [ ] [ sample ] [cache] [ pmc ] [unit ] c m [ pmcxsel ]
47 * | | *- L1/L2/L3 cache_sel |
49 * | *- sampling mode for marked events *- combine
53 * Below uses IBM bit numbering.
55 * MMCR1[x:y] = unit (PMCxUNIT)
56 * MMCR1[x] = combine (PMCxCOMB)
58 * if pmc == 3 and unit == 0 and pmcxsel[0:6] == 0b0101011
59 * # PM_MRK_FAB_RSP_MATCH
60 * MMCR1[20:27] = thresh_ctl (FAB_CRESP_MATCH / FAB_TYPE_MATCH)
61 * else if pmc == 4 and unit == 0xf and pmcxsel[0:6] == 0b0101001
62 * # PM_MRK_FAB_RSP_MATCH_CYC
63 * MMCR1[20:27] = thresh_ctl (FAB_CRESP_MATCH / FAB_TYPE_MATCH)
65 * MMCRA[48:55] = thresh_ctl (THRESH START/END)
68 * MMCRA[45:47] = thresh_sel
71 * MMCRA[22:24] = thresh_cmp[0:2]
72 * MMCRA[25:31] = thresh_cmp[3:9]
74 * if unit == 6 or unit == 7
75 * MMCRC[53:55] = cache_sel[1:3] (L2EVENT_SEL)
76 * else if unit == 8 or unit == 9:
77 * if cache_sel[0] == 0: # L3 bank
78 * MMCRC[47:49] = cache_sel[1:3] (L3EVENT_SEL0)
79 * else if cache_sel[0] == 1:
80 * MMCRC[50:51] = cache_sel[2:3] (L3EVENT_SEL1)
81 * else if cache_sel[1]: # L1 event
82 * MMCR1[16] = cache_sel[2]
83 * MMCR1[17] = cache_sel[3]
86 * MMCRA[63] = 1 (SAMPLE_ENABLE)
87 * MMCRA[57:59] = sample[0:2] (RAND_SAMP_ELIG)
88 * MMCRA[61:62] = sample[3:4] (RAND_SAMP_MODE)
95 #define EVENT_EBB_MASK 1ull
96 #define EVENT_EBB_SHIFT PERF_EVENT_CONFIG_EBB_SHIFT
97 #define EVENT_BHRB_MASK 1ull
98 #define EVENT_BHRB_SHIFT 62
99 #define EVENT_WANTS_BHRB (EVENT_BHRB_MASK << EVENT_BHRB_SHIFT)
100 #define EVENT_IFM_MASK 3ull
101 #define EVENT_IFM_SHIFT 60
102 #define EVENT_THR_CMP_SHIFT 40 /* Threshold CMP value */
103 #define EVENT_THR_CMP_MASK 0x3ff
104 #define EVENT_THR_CTL_SHIFT 32 /* Threshold control value (start/stop) */
105 #define EVENT_THR_CTL_MASK 0xffull
106 #define EVENT_THR_SEL_SHIFT 29 /* Threshold select value */
107 #define EVENT_THR_SEL_MASK 0x7
108 #define EVENT_THRESH_SHIFT 29 /* All threshold bits */
109 #define EVENT_THRESH_MASK 0x1fffffull
110 #define EVENT_SAMPLE_SHIFT 24 /* Sampling mode & eligibility */
111 #define EVENT_SAMPLE_MASK 0x1f
112 #define EVENT_CACHE_SEL_SHIFT 20 /* L2/L3 cache select */
113 #define EVENT_CACHE_SEL_MASK 0xf
114 #define EVENT_IS_L1 (4 << EVENT_CACHE_SEL_SHIFT)
115 #define EVENT_PMC_SHIFT 16 /* PMC number (1-based) */
116 #define EVENT_PMC_MASK 0xf
117 #define EVENT_UNIT_SHIFT 12 /* Unit */
118 #define EVENT_UNIT_MASK 0xf
119 #define EVENT_COMBINE_SHIFT 11 /* Combine bit */
120 #define EVENT_COMBINE_MASK 0x1
121 #define EVENT_MARKED_SHIFT 8 /* Marked bit */
122 #define EVENT_MARKED_MASK 0x1
123 #define EVENT_IS_MARKED (EVENT_MARKED_MASK << EVENT_MARKED_SHIFT)
124 #define EVENT_PSEL_MASK 0xff /* PMCxSEL value */
126 /* Bits defined by Linux */
127 #define EVENT_LINUX_MASK \
128 ((EVENT_EBB_MASK << EVENT_EBB_SHIFT) | \
129 (EVENT_BHRB_MASK << EVENT_BHRB_SHIFT) | \
130 (EVENT_IFM_MASK << EVENT_IFM_SHIFT))
132 #define EVENT_VALID_MASK \
133 ((EVENT_THRESH_MASK << EVENT_THRESH_SHIFT) | \
134 (EVENT_SAMPLE_MASK << EVENT_SAMPLE_SHIFT) | \
135 (EVENT_CACHE_SEL_MASK << EVENT_CACHE_SEL_SHIFT) | \
136 (EVENT_PMC_MASK << EVENT_PMC_SHIFT) | \
137 (EVENT_UNIT_MASK << EVENT_UNIT_SHIFT) | \
138 (EVENT_COMBINE_MASK << EVENT_COMBINE_SHIFT) | \
139 (EVENT_MARKED_MASK << EVENT_MARKED_SHIFT) | \
143 /* MMCRA IFM bits - POWER8 */
144 #define POWER8_MMCRA_IFM1 0x0000000040000000UL
145 #define POWER8_MMCRA_IFM2 0x0000000080000000UL
146 #define POWER8_MMCRA_IFM3 0x00000000C0000000UL
149 (PERF_SAMPLE_BRANCH_USER |\
150 PERF_SAMPLE_BRANCH_KERNEL |\
151 PERF_SAMPLE_BRANCH_HV)
154 * Layout of constraint bits:
156 * 60 56 52 48 44 40 36 32
157 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
158 * [ fab_match ] [ thresh_cmp ] [ thresh_ctl ] [ ]
162 * 28 24 20 16 12 8 4 0
163 * | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - | - - - - |
164 * [ ] | [ ] [ sample ] [ ] [6] [5] [4] [3] [2] [1]
166 * BHRB IFM -* | | | Count of events for each PMC.
167 * EBB -* | | p1, p2, p3, p4, p5, p6.
168 * L1 I/D qualifier -* |
169 * nc - number of counters -*
171 * The PMC fields P1..P6, and NC, are adder fields. As we accumulate constraints
172 * we want the low bit of each field to be added to any existing value.
174 * Everything else is a value field.
177 #define CNST_FAB_MATCH_VAL(v) (((v) & EVENT_THR_CTL_MASK) << 56)
178 #define CNST_FAB_MATCH_MASK CNST_FAB_MATCH_VAL(EVENT_THR_CTL_MASK)
180 /* We just throw all the threshold bits into the constraint */
181 #define CNST_THRESH_VAL(v) (((v) & EVENT_THRESH_MASK) << 32)
182 #define CNST_THRESH_MASK CNST_THRESH_VAL(EVENT_THRESH_MASK)
184 #define CNST_EBB_VAL(v) (((v) & EVENT_EBB_MASK) << 24)
185 #define CNST_EBB_MASK CNST_EBB_VAL(EVENT_EBB_MASK)
187 #define CNST_IFM_VAL(v) (((v) & EVENT_IFM_MASK) << 25)
188 #define CNST_IFM_MASK CNST_IFM_VAL(EVENT_IFM_MASK)
190 #define CNST_L1_QUAL_VAL(v) (((v) & 3) << 22)
191 #define CNST_L1_QUAL_MASK CNST_L1_QUAL_VAL(3)
193 #define CNST_SAMPLE_VAL(v) (((v) & EVENT_SAMPLE_MASK) << 16)
194 #define CNST_SAMPLE_MASK CNST_SAMPLE_VAL(EVENT_SAMPLE_MASK)
197 * For NC we are counting up to 4 events. This requires three bits, and we need
198 * the fifth event to overflow and set the 4th bit. To achieve that we bias the
199 * fields by 3 in test_adder.
201 #define CNST_NC_SHIFT 12
202 #define CNST_NC_VAL (1 << CNST_NC_SHIFT)
203 #define CNST_NC_MASK (8 << CNST_NC_SHIFT)
204 #define POWER8_TEST_ADDER (3 << CNST_NC_SHIFT)
207 * For the per-PMC fields we have two bits. The low bit is added, so if two
208 * events ask for the same PMC the sum will overflow, setting the high bit,
209 * indicating an error. So our mask sets the high bit.
211 #define CNST_PMC_SHIFT(pmc) ((pmc - 1) * 2)
212 #define CNST_PMC_VAL(pmc) (1 << CNST_PMC_SHIFT(pmc))
213 #define CNST_PMC_MASK(pmc) (2 << CNST_PMC_SHIFT(pmc))
215 /* Our add_fields is defined as: */
216 #define POWER8_ADD_FIELDS \
217 CNST_PMC_VAL(1) | CNST_PMC_VAL(2) | CNST_PMC_VAL(3) | \
218 CNST_PMC_VAL(4) | CNST_PMC_VAL(5) | CNST_PMC_VAL(6) | CNST_NC_VAL
221 /* Bits in MMCR1 for POWER8 */
222 #define MMCR1_UNIT_SHIFT(pmc) (60 - (4 * ((pmc) - 1)))
223 #define MMCR1_COMBINE_SHIFT(pmc) (35 - ((pmc) - 1))
224 #define MMCR1_PMCSEL_SHIFT(pmc) (24 - (((pmc) - 1)) * 8)
225 #define MMCR1_FAB_SHIFT 36
226 #define MMCR1_DC_QUAL_SHIFT 47
227 #define MMCR1_IC_QUAL_SHIFT 46
229 /* Bits in MMCRA for POWER8 */
230 #define MMCRA_SAMP_MODE_SHIFT 1
231 #define MMCRA_SAMP_ELIG_SHIFT 4
232 #define MMCRA_THR_CTL_SHIFT 8
233 #define MMCRA_THR_SEL_SHIFT 16
234 #define MMCRA_THR_CMP_SHIFT 32
235 #define MMCRA_SDAR_MODE_TLB (1ull << 42)
236 #define MMCRA_IFM_SHIFT 30
238 /* Bits in MMCR2 for POWER8 */
239 #define MMCR2_FCS(pmc) (1ull << (63 - (((pmc) - 1) * 9)))
240 #define MMCR2_FCP(pmc) (1ull << (62 - (((pmc) - 1) * 9)))
241 #define MMCR2_FCH(pmc) (1ull << (57 - (((pmc) - 1) * 9)))
244 static inline bool event_is_fab_match(u64 event
)
246 /* Only check pmc, unit and pmcxsel, ignore the edge bit (0) */
249 /* PM_MRK_FAB_RSP_MATCH & PM_MRK_FAB_RSP_MATCH_CYC */
250 return (event
== 0x30056 || event
== 0x4f052);
253 static int power8_get_constraint(u64 event
, unsigned long *maskp
, unsigned long *valp
)
255 unsigned int unit
, pmc
, cache
, ebb
;
256 unsigned long mask
, value
;
260 if (event
& ~EVENT_VALID_MASK
)
263 pmc
= (event
>> EVENT_PMC_SHIFT
) & EVENT_PMC_MASK
;
264 unit
= (event
>> EVENT_UNIT_SHIFT
) & EVENT_UNIT_MASK
;
265 cache
= (event
>> EVENT_CACHE_SEL_SHIFT
) & EVENT_CACHE_SEL_MASK
;
266 ebb
= (event
>> EVENT_EBB_SHIFT
) & EVENT_EBB_MASK
;
274 /* Ignore Linux defined bits when checking event below */
275 base_event
= event
& ~EVENT_LINUX_MASK
;
277 if (pmc
>= 5 && base_event
!= 0x500fa && base_event
!= 0x600f4)
280 mask
|= CNST_PMC_MASK(pmc
);
281 value
|= CNST_PMC_VAL(pmc
);
286 * Add to number of counters in use. Note this includes events with
287 * a PMC of 0 - they still need a PMC, it's just assigned later.
288 * Don't count events on PMC 5 & 6, there is only one valid event
289 * on each of those counters, and they are handled above.
291 mask
|= CNST_NC_MASK
;
292 value
|= CNST_NC_VAL
;
295 if (unit
>= 6 && unit
<= 9) {
297 * L2/L3 events contain a cache selector field, which is
298 * supposed to be programmed into MMCRC. However MMCRC is only
299 * HV writable, and there is no API for guest kernels to modify
300 * it. The solution is for the hypervisor to initialise the
301 * field to zeroes, and for us to only ever allow events that
302 * have a cache selector of zero. The bank selector (bit 3) is
303 * irrelevant, as long as the rest of the value is 0.
308 } else if (event
& EVENT_IS_L1
) {
309 mask
|= CNST_L1_QUAL_MASK
;
310 value
|= CNST_L1_QUAL_VAL(cache
);
313 if (event
& EVENT_IS_MARKED
) {
314 mask
|= CNST_SAMPLE_MASK
;
315 value
|= CNST_SAMPLE_VAL(event
>> EVENT_SAMPLE_SHIFT
);
319 * Special case for PM_MRK_FAB_RSP_MATCH and PM_MRK_FAB_RSP_MATCH_CYC,
320 * the threshold control bits are used for the match value.
322 if (event_is_fab_match(event
)) {
323 mask
|= CNST_FAB_MATCH_MASK
;
324 value
|= CNST_FAB_MATCH_VAL(event
>> EVENT_THR_CTL_SHIFT
);
327 * Check the mantissa upper two bits are not zero, unless the
328 * exponent is also zero. See the THRESH_CMP_MANTISSA doc.
330 unsigned int cmp
, exp
;
332 cmp
= (event
>> EVENT_THR_CMP_SHIFT
) & EVENT_THR_CMP_MASK
;
335 if (exp
&& (cmp
& 0x60) == 0)
338 mask
|= CNST_THRESH_MASK
;
339 value
|= CNST_THRESH_VAL(event
>> EVENT_THRESH_SHIFT
);
343 /* EBB events must specify the PMC */
346 if (event
& EVENT_WANTS_BHRB
) {
348 /* Only EBB events can request BHRB */
351 mask
|= CNST_IFM_MASK
;
352 value
|= CNST_IFM_VAL(event
>> EVENT_IFM_SHIFT
);
356 * All events must agree on EBB, either all request it or none.
357 * EBB events are pinned & exclusive, so this should never actually
358 * hit, but we leave it as a fallback in case.
360 mask
|= CNST_EBB_VAL(ebb
);
361 value
|= CNST_EBB_MASK
;
369 static int power8_compute_mmcr(u64 event
[], int n_ev
,
370 unsigned int hwc
[], unsigned long mmcr
[],
371 struct perf_event
*pevents
[])
373 unsigned long mmcra
, mmcr1
, mmcr2
, unit
, combine
, psel
, cache
, val
;
374 unsigned int pmc
, pmc_inuse
;
379 /* First pass to count resource use */
380 for (i
= 0; i
< n_ev
; ++i
) {
381 pmc
= (event
[i
] >> EVENT_PMC_SHIFT
) & EVENT_PMC_MASK
;
383 pmc_inuse
|= 1 << pmc
;
386 /* In continuous sampling mode, update SDAR on TLB miss */
387 mmcra
= MMCRA_SDAR_MODE_TLB
;
390 /* Second pass: assign PMCs, set all MMCR1 fields */
391 for (i
= 0; i
< n_ev
; ++i
) {
392 pmc
= (event
[i
] >> EVENT_PMC_SHIFT
) & EVENT_PMC_MASK
;
393 unit
= (event
[i
] >> EVENT_UNIT_SHIFT
) & EVENT_UNIT_MASK
;
394 combine
= (event
[i
] >> EVENT_COMBINE_SHIFT
) & EVENT_COMBINE_MASK
;
395 psel
= event
[i
] & EVENT_PSEL_MASK
;
398 for (pmc
= 1; pmc
<= 4; ++pmc
) {
399 if (!(pmc_inuse
& (1 << pmc
)))
403 pmc_inuse
|= 1 << pmc
;
407 mmcr1
|= unit
<< MMCR1_UNIT_SHIFT(pmc
);
408 mmcr1
|= combine
<< MMCR1_COMBINE_SHIFT(pmc
);
409 mmcr1
|= psel
<< MMCR1_PMCSEL_SHIFT(pmc
);
412 if (event
[i
] & EVENT_IS_L1
) {
413 cache
= event
[i
] >> EVENT_CACHE_SEL_SHIFT
;
414 mmcr1
|= (cache
& 1) << MMCR1_IC_QUAL_SHIFT
;
416 mmcr1
|= (cache
& 1) << MMCR1_DC_QUAL_SHIFT
;
419 if (event
[i
] & EVENT_IS_MARKED
) {
420 mmcra
|= MMCRA_SAMPLE_ENABLE
;
422 val
= (event
[i
] >> EVENT_SAMPLE_SHIFT
) & EVENT_SAMPLE_MASK
;
424 mmcra
|= (val
& 3) << MMCRA_SAMP_MODE_SHIFT
;
425 mmcra
|= (val
>> 2) << MMCRA_SAMP_ELIG_SHIFT
;
430 * PM_MRK_FAB_RSP_MATCH and PM_MRK_FAB_RSP_MATCH_CYC,
431 * the threshold bits are used for the match value.
433 if (event_is_fab_match(event
[i
])) {
434 mmcr1
|= ((event
[i
] >> EVENT_THR_CTL_SHIFT
) &
435 EVENT_THR_CTL_MASK
) << MMCR1_FAB_SHIFT
;
437 val
= (event
[i
] >> EVENT_THR_CTL_SHIFT
) & EVENT_THR_CTL_MASK
;
438 mmcra
|= val
<< MMCRA_THR_CTL_SHIFT
;
439 val
= (event
[i
] >> EVENT_THR_SEL_SHIFT
) & EVENT_THR_SEL_MASK
;
440 mmcra
|= val
<< MMCRA_THR_SEL_SHIFT
;
441 val
= (event
[i
] >> EVENT_THR_CMP_SHIFT
) & EVENT_THR_CMP_MASK
;
442 mmcra
|= val
<< MMCRA_THR_CMP_SHIFT
;
445 if (event
[i
] & EVENT_WANTS_BHRB
) {
446 val
= (event
[i
] >> EVENT_IFM_SHIFT
) & EVENT_IFM_MASK
;
447 mmcra
|= val
<< MMCRA_IFM_SHIFT
;
450 if (pevents
[i
]->attr
.exclude_user
)
451 mmcr2
|= MMCR2_FCP(pmc
);
453 if (pevents
[i
]->attr
.exclude_hv
)
454 mmcr2
|= MMCR2_FCH(pmc
);
456 if (pevents
[i
]->attr
.exclude_kernel
) {
457 if (cpu_has_feature(CPU_FTR_HVMODE
))
458 mmcr2
|= MMCR2_FCH(pmc
);
460 mmcr2
|= MMCR2_FCS(pmc
);
466 /* Return MMCRx values */
469 /* pmc_inuse is 1-based */
471 mmcr
[0] = MMCR0_PMC1CE
;
473 if (pmc_inuse
& 0x7c)
474 mmcr
[0] |= MMCR0_PMCjCE
;
476 /* If we're not using PMC 5 or 6, freeze them */
477 if (!(pmc_inuse
& 0x60))
478 mmcr
[0] |= MMCR0_FC56
;
489 /* Table of alternatives, sorted by column 0 */
490 static const unsigned int event_alternatives
[][MAX_ALT
] = {
491 { 0x10134, 0x301e2 }, /* PM_MRK_ST_CMPL */
492 { 0x10138, 0x40138 }, /* PM_BR_MRK_2PATH */
493 { 0x18082, 0x3e05e }, /* PM_L3_CO_MEPF */
494 { 0x1d14e, 0x401e8 }, /* PM_MRK_DATA_FROM_L2MISS */
495 { 0x1e054, 0x4000a }, /* PM_CMPLU_STALL */
496 { 0x20036, 0x40036 }, /* PM_BR_2PATH */
497 { 0x200f2, 0x300f2 }, /* PM_INST_DISP */
498 { 0x200f4, 0x600f4 }, /* PM_RUN_CYC */
499 { 0x2013c, 0x3012e }, /* PM_MRK_FILT_MATCH */
500 { 0x3e054, 0x400f0 }, /* PM_LD_MISS_L1 */
501 { 0x400fa, 0x500fa }, /* PM_RUN_INST_CMPL */
505 * Scan the alternatives table for a match and return the
506 * index into the alternatives table if found, else -1.
508 static int find_alternative(u64 event
)
512 for (i
= 0; i
< ARRAY_SIZE(event_alternatives
); ++i
) {
513 if (event
< event_alternatives
[i
][0])
516 for (j
= 0; j
< MAX_ALT
&& event_alternatives
[i
][j
]; ++j
)
517 if (event
== event_alternatives
[i
][j
])
524 static int power8_get_alternatives(u64 event
, unsigned int flags
, u64 alt
[])
526 int i
, j
, num_alt
= 0;
529 alt
[num_alt
++] = event
;
531 i
= find_alternative(event
);
533 /* Filter out the original event, it's already in alt[0] */
534 for (j
= 0; j
< MAX_ALT
; ++j
) {
535 alt_event
= event_alternatives
[i
][j
];
536 if (alt_event
&& alt_event
!= event
)
537 alt
[num_alt
++] = alt_event
;
541 if (flags
& PPMU_ONLY_COUNT_RUN
) {
543 * We're only counting in RUN state, so PM_CYC is equivalent to
544 * PM_RUN_CYC and PM_INST_CMPL === PM_RUN_INST_CMPL.
547 for (i
= 0; i
< num_alt
; ++i
) {
549 case 0x1e: /* PM_CYC */
550 alt
[j
++] = 0x600f4; /* PM_RUN_CYC */
552 case 0x600f4: /* PM_RUN_CYC */
555 case 0x2: /* PM_PPC_CMPL */
556 alt
[j
++] = 0x500fa; /* PM_RUN_INST_CMPL */
558 case 0x500fa: /* PM_RUN_INST_CMPL */
559 alt
[j
++] = 0x2; /* PM_PPC_CMPL */
569 static void power8_disable_pmc(unsigned int pmc
, unsigned long mmcr
[])
572 mmcr
[1] &= ~(0xffUL
<< MMCR1_PMCSEL_SHIFT(pmc
+ 1));
575 GENERIC_EVENT_ATTR(cpu
-cycles
, PM_CYC
);
576 GENERIC_EVENT_ATTR(stalled
-cycles
-frontend
, PM_GCT_NOSLOT_CYC
);
577 GENERIC_EVENT_ATTR(stalled
-cycles
-backend
, PM_CMPLU_STALL
);
578 GENERIC_EVENT_ATTR(instructions
, PM_INST_CMPL
);
579 GENERIC_EVENT_ATTR(branch
-instructions
, PM_BRU_FIN
);
580 GENERIC_EVENT_ATTR(branch
-misses
, PM_BR_MPRED_CMPL
);
581 GENERIC_EVENT_ATTR(cache
-references
, PM_LD_REF_L1
);
582 GENERIC_EVENT_ATTR(cache
-misses
, PM_LD_MISS_L1
);
584 CACHE_EVENT_ATTR(L1
-dcache
-load
-misses
, PM_LD_MISS_L1
);
585 CACHE_EVENT_ATTR(L1
-dcache
-loads
, PM_LD_REF_L1
);
587 CACHE_EVENT_ATTR(L1
-dcache
-prefetches
, PM_L1_PREF
);
588 CACHE_EVENT_ATTR(L1
-dcache
-store
-misses
, PM_ST_MISS_L1
);
589 CACHE_EVENT_ATTR(L1
-icache
-load
-misses
, PM_L1_ICACHE_MISS
);
590 CACHE_EVENT_ATTR(L1
-icache
-loads
, PM_INST_FROM_L1
);
591 CACHE_EVENT_ATTR(L1
-icache
-prefetches
, PM_IC_PREF_WRITE
);
593 CACHE_EVENT_ATTR(LLC
-load
-misses
, PM_DATA_FROM_L3MISS
);
594 CACHE_EVENT_ATTR(LLC
-loads
, PM_DATA_FROM_L3
);
595 CACHE_EVENT_ATTR(LLC
-prefetches
, PM_L3_PREF_ALL
);
596 CACHE_EVENT_ATTR(LLC
-store
-misses
, PM_L2_ST_MISS
);
597 CACHE_EVENT_ATTR(LLC
-stores
, PM_L2_ST
);
599 CACHE_EVENT_ATTR(branch
-load
-misses
, PM_BR_MPRED_CMPL
);
600 CACHE_EVENT_ATTR(branch
-loads
, PM_BRU_FIN
);
601 CACHE_EVENT_ATTR(dTLB
-load
-misses
, PM_DTLB_MISS
);
602 CACHE_EVENT_ATTR(iTLB
-load
-misses
, PM_ITLB_MISS
);
604 static struct attribute
*power8_events_attr
[] = {
605 GENERIC_EVENT_PTR(PM_CYC
),
606 GENERIC_EVENT_PTR(PM_GCT_NOSLOT_CYC
),
607 GENERIC_EVENT_PTR(PM_CMPLU_STALL
),
608 GENERIC_EVENT_PTR(PM_INST_CMPL
),
609 GENERIC_EVENT_PTR(PM_BRU_FIN
),
610 GENERIC_EVENT_PTR(PM_BR_MPRED_CMPL
),
611 GENERIC_EVENT_PTR(PM_LD_REF_L1
),
612 GENERIC_EVENT_PTR(PM_LD_MISS_L1
),
614 CACHE_EVENT_PTR(PM_LD_MISS_L1
),
615 CACHE_EVENT_PTR(PM_LD_REF_L1
),
616 CACHE_EVENT_PTR(PM_L1_PREF
),
617 CACHE_EVENT_PTR(PM_ST_MISS_L1
),
618 CACHE_EVENT_PTR(PM_L1_ICACHE_MISS
),
619 CACHE_EVENT_PTR(PM_INST_FROM_L1
),
620 CACHE_EVENT_PTR(PM_IC_PREF_WRITE
),
621 CACHE_EVENT_PTR(PM_DATA_FROM_L3MISS
),
622 CACHE_EVENT_PTR(PM_DATA_FROM_L3
),
623 CACHE_EVENT_PTR(PM_L3_PREF_ALL
),
624 CACHE_EVENT_PTR(PM_L2_ST_MISS
),
625 CACHE_EVENT_PTR(PM_L2_ST
),
627 CACHE_EVENT_PTR(PM_BR_MPRED_CMPL
),
628 CACHE_EVENT_PTR(PM_BRU_FIN
),
630 CACHE_EVENT_PTR(PM_DTLB_MISS
),
631 CACHE_EVENT_PTR(PM_ITLB_MISS
),
635 static struct attribute_group power8_pmu_events_group
= {
637 .attrs
= power8_events_attr
,
640 PMU_FORMAT_ATTR(event
, "config:0-49");
641 PMU_FORMAT_ATTR(pmcxsel
, "config:0-7");
642 PMU_FORMAT_ATTR(mark
, "config:8");
643 PMU_FORMAT_ATTR(combine
, "config:11");
644 PMU_FORMAT_ATTR(unit
, "config:12-15");
645 PMU_FORMAT_ATTR(pmc
, "config:16-19");
646 PMU_FORMAT_ATTR(cache_sel
, "config:20-23");
647 PMU_FORMAT_ATTR(sample_mode
, "config:24-28");
648 PMU_FORMAT_ATTR(thresh_sel
, "config:29-31");
649 PMU_FORMAT_ATTR(thresh_stop
, "config:32-35");
650 PMU_FORMAT_ATTR(thresh_start
, "config:36-39");
651 PMU_FORMAT_ATTR(thresh_cmp
, "config:40-49");
653 static struct attribute
*power8_pmu_format_attr
[] = {
654 &format_attr_event
.attr
,
655 &format_attr_pmcxsel
.attr
,
656 &format_attr_mark
.attr
,
657 &format_attr_combine
.attr
,
658 &format_attr_unit
.attr
,
659 &format_attr_pmc
.attr
,
660 &format_attr_cache_sel
.attr
,
661 &format_attr_sample_mode
.attr
,
662 &format_attr_thresh_sel
.attr
,
663 &format_attr_thresh_stop
.attr
,
664 &format_attr_thresh_start
.attr
,
665 &format_attr_thresh_cmp
.attr
,
669 struct attribute_group power8_pmu_format_group
= {
671 .attrs
= power8_pmu_format_attr
,
674 static const struct attribute_group
*power8_pmu_attr_groups
[] = {
675 &power8_pmu_format_group
,
676 &power8_pmu_events_group
,
680 static int power8_generic_events
[] = {
681 [PERF_COUNT_HW_CPU_CYCLES
] = PM_CYC
,
682 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND
] = PM_GCT_NOSLOT_CYC
,
683 [PERF_COUNT_HW_STALLED_CYCLES_BACKEND
] = PM_CMPLU_STALL
,
684 [PERF_COUNT_HW_INSTRUCTIONS
] = PM_INST_CMPL
,
685 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS
] = PM_BRU_FIN
,
686 [PERF_COUNT_HW_BRANCH_MISSES
] = PM_BR_MPRED_CMPL
,
687 [PERF_COUNT_HW_CACHE_REFERENCES
] = PM_LD_REF_L1
,
688 [PERF_COUNT_HW_CACHE_MISSES
] = PM_LD_MISS_L1
,
691 static u64
power8_bhrb_filter_map(u64 branch_sample_type
)
693 u64 pmu_bhrb_filter
= 0;
695 /* BHRB and regular PMU events share the same privilege state
696 * filter configuration. BHRB is always recorded along with a
697 * regular PMU event. As the privilege state filter is handled
698 * in the basic PMC configuration of the accompanying regular
699 * PMU event, we ignore any separate BHRB specific request.
702 /* No branch filter requested */
703 if (branch_sample_type
& PERF_SAMPLE_BRANCH_ANY
)
704 return pmu_bhrb_filter
;
706 /* Invalid branch filter options - HW does not support */
707 if (branch_sample_type
& PERF_SAMPLE_BRANCH_ANY_RETURN
)
710 if (branch_sample_type
& PERF_SAMPLE_BRANCH_IND_CALL
)
713 if (branch_sample_type
& PERF_SAMPLE_BRANCH_CALL
)
716 if (branch_sample_type
& PERF_SAMPLE_BRANCH_ANY_CALL
) {
717 pmu_bhrb_filter
|= POWER8_MMCRA_IFM1
;
718 return pmu_bhrb_filter
;
721 /* Every thing else is unsupported */
725 static void power8_config_bhrb(u64 pmu_bhrb_filter
)
727 /* Enable BHRB filter in PMU */
728 mtspr(SPRN_MMCRA
, (mfspr(SPRN_MMCRA
) | pmu_bhrb_filter
));
731 #define C(x) PERF_COUNT_HW_CACHE_##x
734 * Table of generalized cache-related events.
735 * 0 means not supported, -1 means nonsensical, other values
738 static int power8_cache_events
[C(MAX
)][C(OP_MAX
)][C(RESULT_MAX
)] = {
741 [ C(RESULT_ACCESS
) ] = PM_LD_REF_L1
,
742 [ C(RESULT_MISS
) ] = PM_LD_MISS_L1
,
745 [ C(RESULT_ACCESS
) ] = 0,
746 [ C(RESULT_MISS
) ] = PM_ST_MISS_L1
,
748 [ C(OP_PREFETCH
) ] = {
749 [ C(RESULT_ACCESS
) ] = PM_L1_PREF
,
750 [ C(RESULT_MISS
) ] = 0,
755 [ C(RESULT_ACCESS
) ] = PM_INST_FROM_L1
,
756 [ C(RESULT_MISS
) ] = PM_L1_ICACHE_MISS
,
759 [ C(RESULT_ACCESS
) ] = PM_L1_DEMAND_WRITE
,
760 [ C(RESULT_MISS
) ] = -1,
762 [ C(OP_PREFETCH
) ] = {
763 [ C(RESULT_ACCESS
) ] = PM_IC_PREF_WRITE
,
764 [ C(RESULT_MISS
) ] = 0,
769 [ C(RESULT_ACCESS
) ] = PM_DATA_FROM_L3
,
770 [ C(RESULT_MISS
) ] = PM_DATA_FROM_L3MISS
,
773 [ C(RESULT_ACCESS
) ] = PM_L2_ST
,
774 [ C(RESULT_MISS
) ] = PM_L2_ST_MISS
,
776 [ C(OP_PREFETCH
) ] = {
777 [ C(RESULT_ACCESS
) ] = PM_L3_PREF_ALL
,
778 [ C(RESULT_MISS
) ] = 0,
783 [ C(RESULT_ACCESS
) ] = 0,
784 [ C(RESULT_MISS
) ] = PM_DTLB_MISS
,
787 [ C(RESULT_ACCESS
) ] = -1,
788 [ C(RESULT_MISS
) ] = -1,
790 [ C(OP_PREFETCH
) ] = {
791 [ C(RESULT_ACCESS
) ] = -1,
792 [ C(RESULT_MISS
) ] = -1,
797 [ C(RESULT_ACCESS
) ] = 0,
798 [ C(RESULT_MISS
) ] = PM_ITLB_MISS
,
801 [ C(RESULT_ACCESS
) ] = -1,
802 [ C(RESULT_MISS
) ] = -1,
804 [ C(OP_PREFETCH
) ] = {
805 [ C(RESULT_ACCESS
) ] = -1,
806 [ C(RESULT_MISS
) ] = -1,
811 [ C(RESULT_ACCESS
) ] = PM_BRU_FIN
,
812 [ C(RESULT_MISS
) ] = PM_BR_MPRED_CMPL
,
815 [ C(RESULT_ACCESS
) ] = -1,
816 [ C(RESULT_MISS
) ] = -1,
818 [ C(OP_PREFETCH
) ] = {
819 [ C(RESULT_ACCESS
) ] = -1,
820 [ C(RESULT_MISS
) ] = -1,
825 [ C(RESULT_ACCESS
) ] = -1,
826 [ C(RESULT_MISS
) ] = -1,
829 [ C(RESULT_ACCESS
) ] = -1,
830 [ C(RESULT_MISS
) ] = -1,
832 [ C(OP_PREFETCH
) ] = {
833 [ C(RESULT_ACCESS
) ] = -1,
834 [ C(RESULT_MISS
) ] = -1,
841 static struct power_pmu power8_pmu
= {
844 .max_alternatives
= MAX_ALT
+ 1,
845 .add_fields
= POWER8_ADD_FIELDS
,
846 .test_adder
= POWER8_TEST_ADDER
,
847 .compute_mmcr
= power8_compute_mmcr
,
848 .config_bhrb
= power8_config_bhrb
,
849 .bhrb_filter_map
= power8_bhrb_filter_map
,
850 .get_constraint
= power8_get_constraint
,
851 .get_alternatives
= power8_get_alternatives
,
852 .disable_pmc
= power8_disable_pmc
,
853 .flags
= PPMU_HAS_SIER
| PPMU_ARCH_207S
,
854 .n_generic
= ARRAY_SIZE(power8_generic_events
),
855 .generic_events
= power8_generic_events
,
856 .cache_events
= &power8_cache_events
,
857 .attr_groups
= power8_pmu_attr_groups
,
861 static int __init
init_power8_pmu(void)
865 if (!cur_cpu_spec
->oprofile_cpu_type
||
866 strcmp(cur_cpu_spec
->oprofile_cpu_type
, "ppc64/power8"))
869 rc
= register_power_pmu(&power8_pmu
);
873 /* Tell userspace that EBB is supported */
874 cur_cpu_spec
->cpu_user_features2
|= PPC_FEATURE2_EBB
;
876 if (cpu_has_feature(CPU_FTR_PMAO_BUG
))
877 pr_info("PMAO restore workaround active.\n");
881 early_initcall(init_power8_pmu
);