]>
Commit | Line | Data |
---|---|---|
a7e3ed1e | 1 | /* |
efc9f05d SE |
2 | * Per core/cpu state |
3 | * | |
4 | * Used to coordinate shared registers between HT threads or | |
5 | * among events on a single PMU. | |
a7e3ed1e | 6 | */ |
de0428a7 | 7 | |
c767a54b JP |
8 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
9 | ||
de0428a7 KW |
10 | #include <linux/stddef.h> |
11 | #include <linux/types.h> | |
12 | #include <linux/init.h> | |
13 | #include <linux/slab.h> | |
69c60c88 | 14 | #include <linux/export.h> |
de0428a7 | 15 | |
3a632cb2 | 16 | #include <asm/cpufeature.h> |
de0428a7 KW |
17 | #include <asm/hardirq.h> |
18 | #include <asm/apic.h> | |
19 | ||
20 | #include "perf_event.h" | |
a7e3ed1e | 21 | |
f22f54f4 | 22 | /* |
b622d644 | 23 | * Intel PerfMon, used on Core and later. |
f22f54f4 | 24 | */ |
ec75a716 | 25 | static u64 intel_perfmon_event_map[PERF_COUNT_HW_MAX] __read_mostly = |
f22f54f4 | 26 | { |
c3b7cdf1 PE |
27 | [PERF_COUNT_HW_CPU_CYCLES] = 0x003c, |
28 | [PERF_COUNT_HW_INSTRUCTIONS] = 0x00c0, | |
29 | [PERF_COUNT_HW_CACHE_REFERENCES] = 0x4f2e, | |
30 | [PERF_COUNT_HW_CACHE_MISSES] = 0x412e, | |
31 | [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = 0x00c4, | |
32 | [PERF_COUNT_HW_BRANCH_MISSES] = 0x00c5, | |
33 | [PERF_COUNT_HW_BUS_CYCLES] = 0x013c, | |
34 | [PERF_COUNT_HW_REF_CPU_CYCLES] = 0x0300, /* pseudo-encoding */ | |
f22f54f4 PZ |
35 | }; |
36 | ||
5c543e3c | 37 | static struct event_constraint intel_core_event_constraints[] __read_mostly = |
f22f54f4 PZ |
38 | { |
39 | INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */ | |
40 | INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */ | |
41 | INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */ | |
42 | INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */ | |
43 | INTEL_EVENT_CONSTRAINT(0x19, 0x2), /* DELAYED_BYPASS */ | |
44 | INTEL_EVENT_CONSTRAINT(0xc1, 0x1), /* FP_COMP_INSTR_RET */ | |
45 | EVENT_CONSTRAINT_END | |
46 | }; | |
47 | ||
5c543e3c | 48 | static struct event_constraint intel_core2_event_constraints[] __read_mostly = |
f22f54f4 | 49 | { |
b622d644 PZ |
50 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
51 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
cd09c0c4 | 52 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ |
f22f54f4 PZ |
53 | INTEL_EVENT_CONSTRAINT(0x10, 0x1), /* FP_COMP_OPS_EXE */ |
54 | INTEL_EVENT_CONSTRAINT(0x11, 0x2), /* FP_ASSIST */ | |
55 | INTEL_EVENT_CONSTRAINT(0x12, 0x2), /* MUL */ | |
56 | INTEL_EVENT_CONSTRAINT(0x13, 0x2), /* DIV */ | |
57 | INTEL_EVENT_CONSTRAINT(0x14, 0x1), /* CYCLES_DIV_BUSY */ | |
58 | INTEL_EVENT_CONSTRAINT(0x18, 0x1), /* IDLE_DURING_DIV */ | |
59 | INTEL_EVENT_CONSTRAINT(0x19, 0x2), /* DELAYED_BYPASS */ | |
60 | INTEL_EVENT_CONSTRAINT(0xa1, 0x1), /* RS_UOPS_DISPATCH_CYCLES */ | |
b622d644 | 61 | INTEL_EVENT_CONSTRAINT(0xc9, 0x1), /* ITLB_MISS_RETIRED (T30-9) */ |
f22f54f4 PZ |
62 | INTEL_EVENT_CONSTRAINT(0xcb, 0x1), /* MEM_LOAD_RETIRED */ |
63 | EVENT_CONSTRAINT_END | |
64 | }; | |
65 | ||
5c543e3c | 66 | static struct event_constraint intel_nehalem_event_constraints[] __read_mostly = |
f22f54f4 | 67 | { |
b622d644 PZ |
68 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
69 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
cd09c0c4 | 70 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ |
f22f54f4 PZ |
71 | INTEL_EVENT_CONSTRAINT(0x40, 0x3), /* L1D_CACHE_LD */ |
72 | INTEL_EVENT_CONSTRAINT(0x41, 0x3), /* L1D_CACHE_ST */ | |
73 | INTEL_EVENT_CONSTRAINT(0x42, 0x3), /* L1D_CACHE_LOCK */ | |
74 | INTEL_EVENT_CONSTRAINT(0x43, 0x3), /* L1D_ALL_REF */ | |
75 | INTEL_EVENT_CONSTRAINT(0x48, 0x3), /* L1D_PEND_MISS */ | |
76 | INTEL_EVENT_CONSTRAINT(0x4e, 0x3), /* L1D_PREFETCH */ | |
77 | INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */ | |
78 | INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */ | |
79 | EVENT_CONSTRAINT_END | |
80 | }; | |
81 | ||
5c543e3c | 82 | static struct extra_reg intel_nehalem_extra_regs[] __read_mostly = |
a7e3ed1e | 83 | { |
53ad0447 YZ |
84 | /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ |
85 | INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0xffff, RSP_0), | |
f20093ee | 86 | INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x100b), |
a7e3ed1e AK |
87 | EVENT_EXTRA_END |
88 | }; | |
89 | ||
5c543e3c | 90 | static struct event_constraint intel_westmere_event_constraints[] __read_mostly = |
f22f54f4 | 91 | { |
b622d644 PZ |
92 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
93 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
cd09c0c4 | 94 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ |
f22f54f4 PZ |
95 | INTEL_EVENT_CONSTRAINT(0x51, 0x3), /* L1D */ |
96 | INTEL_EVENT_CONSTRAINT(0x60, 0x1), /* OFFCORE_REQUESTS_OUTSTANDING */ | |
97 | INTEL_EVENT_CONSTRAINT(0x63, 0x3), /* CACHE_LOCK_CYCLES */ | |
d1100770 | 98 | INTEL_EVENT_CONSTRAINT(0xb3, 0x1), /* SNOOPQ_REQUEST_OUTSTANDING */ |
f22f54f4 PZ |
99 | EVENT_CONSTRAINT_END |
100 | }; | |
101 | ||
5c543e3c | 102 | static struct event_constraint intel_snb_event_constraints[] __read_mostly = |
b06b3d49 LM |
103 | { |
104 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | |
105 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
cd09c0c4 | 106 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ |
fd4a5aef SE |
107 | INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_DISPATCH */ |
108 | INTEL_UEVENT_CONSTRAINT(0x05a3, 0xf), /* CYCLE_ACTIVITY.STALLS_L2_PENDING */ | |
109 | INTEL_UEVENT_CONSTRAINT(0x02a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */ | |
110 | INTEL_UEVENT_CONSTRAINT(0x06a3, 0x4), /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */ | |
b06b3d49 | 111 | INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.PENDING */ |
b06b3d49 LM |
112 | INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */ |
113 | INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */ | |
f8378f52 AK |
114 | INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_DISPATCH */ |
115 | INTEL_UEVENT_CONSTRAINT(0x02a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */ | |
b06b3d49 LM |
116 | EVENT_CONSTRAINT_END |
117 | }; | |
118 | ||
69943182 SE |
119 | static struct event_constraint intel_ivb_event_constraints[] __read_mostly = |
120 | { | |
121 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | |
122 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
123 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ | |
124 | INTEL_UEVENT_CONSTRAINT(0x0148, 0x4), /* L1D_PEND_MISS.PENDING */ | |
125 | INTEL_UEVENT_CONSTRAINT(0x0279, 0xf), /* IDQ.EMTPY */ | |
126 | INTEL_UEVENT_CONSTRAINT(0x019c, 0xf), /* IDQ_UOPS_NOT_DELIVERED.CORE */ | |
6113af14 | 127 | INTEL_UEVENT_CONSTRAINT(0x02a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_LDM_PENDING */ |
69943182 SE |
128 | INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_EXECUTE */ |
129 | INTEL_UEVENT_CONSTRAINT(0x05a3, 0xf), /* CYCLE_ACTIVITY.STALLS_L2_PENDING */ | |
130 | INTEL_UEVENT_CONSTRAINT(0x06a3, 0xf), /* CYCLE_ACTIVITY.STALLS_LDM_PENDING */ | |
131 | INTEL_UEVENT_CONSTRAINT(0x08a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */ | |
132 | INTEL_UEVENT_CONSTRAINT(0x0ca3, 0x4), /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */ | |
133 | INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */ | |
741a698f PZ |
134 | /* |
135 | * Errata BV98 -- MEM_*_RETIRED events can leak between counters of SMT | |
136 | * siblings; disable these events because they can corrupt unrelated | |
137 | * counters. | |
138 | */ | |
139 | INTEL_EVENT_CONSTRAINT(0xd0, 0x0), /* MEM_UOPS_RETIRED.* */ | |
140 | INTEL_EVENT_CONSTRAINT(0xd1, 0x0), /* MEM_LOAD_UOPS_RETIRED.* */ | |
141 | INTEL_EVENT_CONSTRAINT(0xd2, 0x0), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */ | |
142 | INTEL_EVENT_CONSTRAINT(0xd3, 0x0), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */ | |
69943182 SE |
143 | EVENT_CONSTRAINT_END |
144 | }; | |
145 | ||
5c543e3c | 146 | static struct extra_reg intel_westmere_extra_regs[] __read_mostly = |
a7e3ed1e | 147 | { |
53ad0447 YZ |
148 | /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ |
149 | INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0xffff, RSP_0), | |
150 | INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0xffff, RSP_1), | |
f20093ee | 151 | INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x100b), |
a7e3ed1e AK |
152 | EVENT_EXTRA_END |
153 | }; | |
154 | ||
0af3ac1f AK |
155 | static struct event_constraint intel_v1_event_constraints[] __read_mostly = |
156 | { | |
157 | EVENT_CONSTRAINT_END | |
158 | }; | |
159 | ||
5c543e3c | 160 | static struct event_constraint intel_gen_event_constraints[] __read_mostly = |
f22f54f4 | 161 | { |
b622d644 PZ |
162 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
163 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
cd09c0c4 | 164 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ |
f22f54f4 PZ |
165 | EVENT_CONSTRAINT_END |
166 | }; | |
167 | ||
1fa64180 YZ |
168 | static struct event_constraint intel_slm_event_constraints[] __read_mostly = |
169 | { | |
170 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | |
171 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
1fa64180 YZ |
172 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* pseudo CPU_CLK_UNHALTED.REF */ |
173 | EVENT_CONSTRAINT_END | |
174 | }; | |
175 | ||
ee89cbc2 | 176 | static struct extra_reg intel_snb_extra_regs[] __read_mostly = { |
53ad0447 YZ |
177 | /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ |
178 | INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x3f807f8fffull, RSP_0), | |
179 | INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0x3f807f8fffull, RSP_1), | |
f20093ee | 180 | INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd), |
f1923820 SE |
181 | EVENT_EXTRA_END |
182 | }; | |
183 | ||
184 | static struct extra_reg intel_snbep_extra_regs[] __read_mostly = { | |
53ad0447 YZ |
185 | /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ |
186 | INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x3fffff8fffull, RSP_0), | |
187 | INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0x3fffff8fffull, RSP_1), | |
f1a52789 | 188 | INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd), |
ee89cbc2 SE |
189 | EVENT_EXTRA_END |
190 | }; | |
191 | ||
7f2ee91f IM |
192 | EVENT_ATTR_STR(mem-loads, mem_ld_nhm, "event=0x0b,umask=0x10,ldlat=3"); |
193 | EVENT_ATTR_STR(mem-loads, mem_ld_snb, "event=0xcd,umask=0x1,ldlat=3"); | |
194 | EVENT_ATTR_STR(mem-stores, mem_st_snb, "event=0xcd,umask=0x2"); | |
f20093ee SE |
195 | |
196 | struct attribute *nhm_events_attrs[] = { | |
197 | EVENT_PTR(mem_ld_nhm), | |
198 | NULL, | |
199 | }; | |
200 | ||
201 | struct attribute *snb_events_attrs[] = { | |
202 | EVENT_PTR(mem_ld_snb), | |
9ad64c0f | 203 | EVENT_PTR(mem_st_snb), |
f20093ee SE |
204 | NULL, |
205 | }; | |
206 | ||
3a632cb2 AK |
207 | static struct event_constraint intel_hsw_event_constraints[] = { |
208 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | |
209 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
210 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ | |
211 | INTEL_EVENT_CONSTRAINT(0x48, 0x4), /* L1D_PEND_MISS.* */ | |
212 | INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */ | |
213 | INTEL_EVENT_CONSTRAINT(0xcd, 0x8), /* MEM_TRANS_RETIRED.LOAD_LATENCY */ | |
214 | /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */ | |
c420f19b | 215 | INTEL_UEVENT_CONSTRAINT(0x08a3, 0x4), |
3a632cb2 | 216 | /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */ |
c420f19b | 217 | INTEL_UEVENT_CONSTRAINT(0x0ca3, 0x4), |
3a632cb2 | 218 | /* CYCLE_ACTIVITY.CYCLES_NO_EXECUTE */ |
c420f19b | 219 | INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), |
3a632cb2 AK |
220 | EVENT_CONSTRAINT_END |
221 | }; | |
222 | ||
91f1b705 AK |
223 | struct event_constraint intel_bdw_event_constraints[] = { |
224 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | |
225 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
226 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ | |
227 | INTEL_UEVENT_CONSTRAINT(0x148, 0x4), /* L1D_PEND_MISS.PENDING */ | |
228 | INTEL_EVENT_CONSTRAINT(0xa3, 0x4), /* CYCLE_ACTIVITY.* */ | |
229 | EVENT_CONSTRAINT_END | |
230 | }; | |
231 | ||
f22f54f4 PZ |
232 | static u64 intel_pmu_event_map(int hw_event) |
233 | { | |
234 | return intel_perfmon_event_map[hw_event]; | |
235 | } | |
236 | ||
74e6543f YZ |
237 | #define SNB_DMND_DATA_RD (1ULL << 0) |
238 | #define SNB_DMND_RFO (1ULL << 1) | |
239 | #define SNB_DMND_IFETCH (1ULL << 2) | |
240 | #define SNB_DMND_WB (1ULL << 3) | |
241 | #define SNB_PF_DATA_RD (1ULL << 4) | |
242 | #define SNB_PF_RFO (1ULL << 5) | |
243 | #define SNB_PF_IFETCH (1ULL << 6) | |
244 | #define SNB_LLC_DATA_RD (1ULL << 7) | |
245 | #define SNB_LLC_RFO (1ULL << 8) | |
246 | #define SNB_LLC_IFETCH (1ULL << 9) | |
247 | #define SNB_BUS_LOCKS (1ULL << 10) | |
248 | #define SNB_STRM_ST (1ULL << 11) | |
249 | #define SNB_OTHER (1ULL << 15) | |
250 | #define SNB_RESP_ANY (1ULL << 16) | |
251 | #define SNB_NO_SUPP (1ULL << 17) | |
252 | #define SNB_LLC_HITM (1ULL << 18) | |
253 | #define SNB_LLC_HITE (1ULL << 19) | |
254 | #define SNB_LLC_HITS (1ULL << 20) | |
255 | #define SNB_LLC_HITF (1ULL << 21) | |
256 | #define SNB_LOCAL (1ULL << 22) | |
257 | #define SNB_REMOTE (0xffULL << 23) | |
258 | #define SNB_SNP_NONE (1ULL << 31) | |
259 | #define SNB_SNP_NOT_NEEDED (1ULL << 32) | |
260 | #define SNB_SNP_MISS (1ULL << 33) | |
261 | #define SNB_NO_FWD (1ULL << 34) | |
262 | #define SNB_SNP_FWD (1ULL << 35) | |
263 | #define SNB_HITM (1ULL << 36) | |
264 | #define SNB_NON_DRAM (1ULL << 37) | |
265 | ||
266 | #define SNB_DMND_READ (SNB_DMND_DATA_RD|SNB_LLC_DATA_RD) | |
267 | #define SNB_DMND_WRITE (SNB_DMND_RFO|SNB_LLC_RFO) | |
268 | #define SNB_DMND_PREFETCH (SNB_PF_DATA_RD|SNB_PF_RFO) | |
269 | ||
270 | #define SNB_SNP_ANY (SNB_SNP_NONE|SNB_SNP_NOT_NEEDED| \ | |
271 | SNB_SNP_MISS|SNB_NO_FWD|SNB_SNP_FWD| \ | |
272 | SNB_HITM) | |
273 | ||
274 | #define SNB_DRAM_ANY (SNB_LOCAL|SNB_REMOTE|SNB_SNP_ANY) | |
275 | #define SNB_DRAM_REMOTE (SNB_REMOTE|SNB_SNP_ANY) | |
276 | ||
277 | #define SNB_L3_ACCESS SNB_RESP_ANY | |
278 | #define SNB_L3_MISS (SNB_DRAM_ANY|SNB_NON_DRAM) | |
279 | ||
280 | static __initconst const u64 snb_hw_cache_extra_regs | |
281 | [PERF_COUNT_HW_CACHE_MAX] | |
282 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
283 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
284 | { | |
285 | [ C(LL ) ] = { | |
286 | [ C(OP_READ) ] = { | |
287 | [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_L3_ACCESS, | |
288 | [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_L3_MISS, | |
289 | }, | |
290 | [ C(OP_WRITE) ] = { | |
291 | [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_L3_ACCESS, | |
292 | [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_L3_MISS, | |
293 | }, | |
294 | [ C(OP_PREFETCH) ] = { | |
295 | [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_L3_ACCESS, | |
296 | [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_L3_MISS, | |
297 | }, | |
298 | }, | |
299 | [ C(NODE) ] = { | |
300 | [ C(OP_READ) ] = { | |
301 | [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_DRAM_ANY, | |
302 | [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_DRAM_REMOTE, | |
303 | }, | |
304 | [ C(OP_WRITE) ] = { | |
305 | [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_DRAM_ANY, | |
306 | [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_DRAM_REMOTE, | |
307 | }, | |
308 | [ C(OP_PREFETCH) ] = { | |
309 | [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_DRAM_ANY, | |
310 | [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_DRAM_REMOTE, | |
311 | }, | |
312 | }, | |
313 | }; | |
314 | ||
b06b3d49 LM |
315 | static __initconst const u64 snb_hw_cache_event_ids |
316 | [PERF_COUNT_HW_CACHE_MAX] | |
317 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
318 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
319 | { | |
320 | [ C(L1D) ] = { | |
321 | [ C(OP_READ) ] = { | |
322 | [ C(RESULT_ACCESS) ] = 0xf1d0, /* MEM_UOP_RETIRED.LOADS */ | |
323 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPLACEMENT */ | |
324 | }, | |
325 | [ C(OP_WRITE) ] = { | |
326 | [ C(RESULT_ACCESS) ] = 0xf2d0, /* MEM_UOP_RETIRED.STORES */ | |
327 | [ C(RESULT_MISS) ] = 0x0851, /* L1D.ALL_M_REPLACEMENT */ | |
328 | }, | |
329 | [ C(OP_PREFETCH) ] = { | |
330 | [ C(RESULT_ACCESS) ] = 0x0, | |
331 | [ C(RESULT_MISS) ] = 0x024e, /* HW_PRE_REQ.DL1_MISS */ | |
332 | }, | |
333 | }, | |
334 | [ C(L1I ) ] = { | |
335 | [ C(OP_READ) ] = { | |
336 | [ C(RESULT_ACCESS) ] = 0x0, | |
337 | [ C(RESULT_MISS) ] = 0x0280, /* ICACHE.MISSES */ | |
338 | }, | |
339 | [ C(OP_WRITE) ] = { | |
340 | [ C(RESULT_ACCESS) ] = -1, | |
341 | [ C(RESULT_MISS) ] = -1, | |
342 | }, | |
343 | [ C(OP_PREFETCH) ] = { | |
344 | [ C(RESULT_ACCESS) ] = 0x0, | |
345 | [ C(RESULT_MISS) ] = 0x0, | |
346 | }, | |
347 | }, | |
348 | [ C(LL ) ] = { | |
b06b3d49 | 349 | [ C(OP_READ) ] = { |
63b6a675 | 350 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
b06b3d49 | 351 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
352 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ |
353 | [ C(RESULT_MISS) ] = 0x01b7, | |
b06b3d49 LM |
354 | }, |
355 | [ C(OP_WRITE) ] = { | |
63b6a675 | 356 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
b06b3d49 | 357 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
358 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ |
359 | [ C(RESULT_MISS) ] = 0x01b7, | |
b06b3d49 LM |
360 | }, |
361 | [ C(OP_PREFETCH) ] = { | |
63b6a675 | 362 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
b06b3d49 | 363 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
364 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ |
365 | [ C(RESULT_MISS) ] = 0x01b7, | |
b06b3d49 LM |
366 | }, |
367 | }, | |
368 | [ C(DTLB) ] = { | |
369 | [ C(OP_READ) ] = { | |
370 | [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOP_RETIRED.ALL_LOADS */ | |
371 | [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.CAUSES_A_WALK */ | |
372 | }, | |
373 | [ C(OP_WRITE) ] = { | |
374 | [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOP_RETIRED.ALL_STORES */ | |
375 | [ C(RESULT_MISS) ] = 0x0149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */ | |
376 | }, | |
377 | [ C(OP_PREFETCH) ] = { | |
378 | [ C(RESULT_ACCESS) ] = 0x0, | |
379 | [ C(RESULT_MISS) ] = 0x0, | |
380 | }, | |
381 | }, | |
382 | [ C(ITLB) ] = { | |
383 | [ C(OP_READ) ] = { | |
384 | [ C(RESULT_ACCESS) ] = 0x1085, /* ITLB_MISSES.STLB_HIT */ | |
385 | [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.CAUSES_A_WALK */ | |
386 | }, | |
387 | [ C(OP_WRITE) ] = { | |
388 | [ C(RESULT_ACCESS) ] = -1, | |
389 | [ C(RESULT_MISS) ] = -1, | |
390 | }, | |
391 | [ C(OP_PREFETCH) ] = { | |
392 | [ C(RESULT_ACCESS) ] = -1, | |
393 | [ C(RESULT_MISS) ] = -1, | |
394 | }, | |
395 | }, | |
396 | [ C(BPU ) ] = { | |
397 | [ C(OP_READ) ] = { | |
398 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */ | |
399 | [ C(RESULT_MISS) ] = 0x00c5, /* BR_MISP_RETIRED.ALL_BRANCHES */ | |
400 | }, | |
401 | [ C(OP_WRITE) ] = { | |
402 | [ C(RESULT_ACCESS) ] = -1, | |
403 | [ C(RESULT_MISS) ] = -1, | |
404 | }, | |
405 | [ C(OP_PREFETCH) ] = { | |
406 | [ C(RESULT_ACCESS) ] = -1, | |
407 | [ C(RESULT_MISS) ] = -1, | |
408 | }, | |
409 | }, | |
89d6c0b5 PZ |
410 | [ C(NODE) ] = { |
411 | [ C(OP_READ) ] = { | |
74e6543f YZ |
412 | [ C(RESULT_ACCESS) ] = 0x01b7, |
413 | [ C(RESULT_MISS) ] = 0x01b7, | |
89d6c0b5 PZ |
414 | }, |
415 | [ C(OP_WRITE) ] = { | |
74e6543f YZ |
416 | [ C(RESULT_ACCESS) ] = 0x01b7, |
417 | [ C(RESULT_MISS) ] = 0x01b7, | |
89d6c0b5 PZ |
418 | }, |
419 | [ C(OP_PREFETCH) ] = { | |
74e6543f YZ |
420 | [ C(RESULT_ACCESS) ] = 0x01b7, |
421 | [ C(RESULT_MISS) ] = 0x01b7, | |
89d6c0b5 PZ |
422 | }, |
423 | }, | |
424 | ||
b06b3d49 LM |
425 | }; |
426 | ||
0f1b5ca2 AK |
427 | /* |
428 | * Notes on the events: | |
429 | * - data reads do not include code reads (comparable to earlier tables) | |
430 | * - data counts include speculative execution (except L1 write, dtlb, bpu) | |
431 | * - remote node access includes remote memory, remote cache, remote mmio. | |
432 | * - prefetches are not included in the counts because they are not | |
433 | * reliably counted. | |
434 | */ | |
435 | ||
436 | #define HSW_DEMAND_DATA_RD BIT_ULL(0) | |
437 | #define HSW_DEMAND_RFO BIT_ULL(1) | |
438 | #define HSW_ANY_RESPONSE BIT_ULL(16) | |
439 | #define HSW_SUPPLIER_NONE BIT_ULL(17) | |
440 | #define HSW_L3_MISS_LOCAL_DRAM BIT_ULL(22) | |
441 | #define HSW_L3_MISS_REMOTE_HOP0 BIT_ULL(27) | |
442 | #define HSW_L3_MISS_REMOTE_HOP1 BIT_ULL(28) | |
443 | #define HSW_L3_MISS_REMOTE_HOP2P BIT_ULL(29) | |
444 | #define HSW_L3_MISS (HSW_L3_MISS_LOCAL_DRAM| \ | |
445 | HSW_L3_MISS_REMOTE_HOP0|HSW_L3_MISS_REMOTE_HOP1| \ | |
446 | HSW_L3_MISS_REMOTE_HOP2P) | |
447 | #define HSW_SNOOP_NONE BIT_ULL(31) | |
448 | #define HSW_SNOOP_NOT_NEEDED BIT_ULL(32) | |
449 | #define HSW_SNOOP_MISS BIT_ULL(33) | |
450 | #define HSW_SNOOP_HIT_NO_FWD BIT_ULL(34) | |
451 | #define HSW_SNOOP_HIT_WITH_FWD BIT_ULL(35) | |
452 | #define HSW_SNOOP_HITM BIT_ULL(36) | |
453 | #define HSW_SNOOP_NON_DRAM BIT_ULL(37) | |
454 | #define HSW_ANY_SNOOP (HSW_SNOOP_NONE| \ | |
455 | HSW_SNOOP_NOT_NEEDED|HSW_SNOOP_MISS| \ | |
456 | HSW_SNOOP_HIT_NO_FWD|HSW_SNOOP_HIT_WITH_FWD| \ | |
457 | HSW_SNOOP_HITM|HSW_SNOOP_NON_DRAM) | |
458 | #define HSW_SNOOP_DRAM (HSW_ANY_SNOOP & ~HSW_SNOOP_NON_DRAM) | |
459 | #define HSW_DEMAND_READ HSW_DEMAND_DATA_RD | |
460 | #define HSW_DEMAND_WRITE HSW_DEMAND_RFO | |
461 | #define HSW_L3_MISS_REMOTE (HSW_L3_MISS_REMOTE_HOP0|\ | |
462 | HSW_L3_MISS_REMOTE_HOP1|HSW_L3_MISS_REMOTE_HOP2P) | |
463 | #define HSW_LLC_ACCESS HSW_ANY_RESPONSE | |
464 | ||
91f1b705 AK |
465 | #define BDW_L3_MISS_LOCAL BIT(26) |
466 | #define BDW_L3_MISS (BDW_L3_MISS_LOCAL| \ | |
467 | HSW_L3_MISS_REMOTE_HOP0|HSW_L3_MISS_REMOTE_HOP1| \ | |
468 | HSW_L3_MISS_REMOTE_HOP2P) | |
469 | ||
470 | ||
0f1b5ca2 AK |
471 | static __initconst const u64 hsw_hw_cache_event_ids |
472 | [PERF_COUNT_HW_CACHE_MAX] | |
473 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
474 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
475 | { | |
476 | [ C(L1D ) ] = { | |
477 | [ C(OP_READ) ] = { | |
478 | [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOPS_RETIRED.ALL_LOADS */ | |
479 | [ C(RESULT_MISS) ] = 0x151, /* L1D.REPLACEMENT */ | |
480 | }, | |
481 | [ C(OP_WRITE) ] = { | |
482 | [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOPS_RETIRED.ALL_STORES */ | |
483 | [ C(RESULT_MISS) ] = 0x0, | |
484 | }, | |
485 | [ C(OP_PREFETCH) ] = { | |
486 | [ C(RESULT_ACCESS) ] = 0x0, | |
487 | [ C(RESULT_MISS) ] = 0x0, | |
488 | }, | |
489 | }, | |
490 | [ C(L1I ) ] = { | |
491 | [ C(OP_READ) ] = { | |
492 | [ C(RESULT_ACCESS) ] = 0x0, | |
493 | [ C(RESULT_MISS) ] = 0x280, /* ICACHE.MISSES */ | |
494 | }, | |
495 | [ C(OP_WRITE) ] = { | |
496 | [ C(RESULT_ACCESS) ] = -1, | |
497 | [ C(RESULT_MISS) ] = -1, | |
498 | }, | |
499 | [ C(OP_PREFETCH) ] = { | |
500 | [ C(RESULT_ACCESS) ] = 0x0, | |
501 | [ C(RESULT_MISS) ] = 0x0, | |
502 | }, | |
503 | }, | |
504 | [ C(LL ) ] = { | |
505 | [ C(OP_READ) ] = { | |
506 | [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
507 | [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
508 | }, | |
509 | [ C(OP_WRITE) ] = { | |
510 | [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
511 | [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
512 | }, | |
513 | [ C(OP_PREFETCH) ] = { | |
514 | [ C(RESULT_ACCESS) ] = 0x0, | |
515 | [ C(RESULT_MISS) ] = 0x0, | |
516 | }, | |
517 | }, | |
518 | [ C(DTLB) ] = { | |
519 | [ C(OP_READ) ] = { | |
520 | [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOPS_RETIRED.ALL_LOADS */ | |
521 | [ C(RESULT_MISS) ] = 0x108, /* DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK */ | |
522 | }, | |
523 | [ C(OP_WRITE) ] = { | |
524 | [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOPS_RETIRED.ALL_STORES */ | |
525 | [ C(RESULT_MISS) ] = 0x149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */ | |
526 | }, | |
527 | [ C(OP_PREFETCH) ] = { | |
528 | [ C(RESULT_ACCESS) ] = 0x0, | |
529 | [ C(RESULT_MISS) ] = 0x0, | |
530 | }, | |
531 | }, | |
532 | [ C(ITLB) ] = { | |
533 | [ C(OP_READ) ] = { | |
534 | [ C(RESULT_ACCESS) ] = 0x6085, /* ITLB_MISSES.STLB_HIT */ | |
535 | [ C(RESULT_MISS) ] = 0x185, /* ITLB_MISSES.MISS_CAUSES_A_WALK */ | |
536 | }, | |
537 | [ C(OP_WRITE) ] = { | |
538 | [ C(RESULT_ACCESS) ] = -1, | |
539 | [ C(RESULT_MISS) ] = -1, | |
540 | }, | |
541 | [ C(OP_PREFETCH) ] = { | |
542 | [ C(RESULT_ACCESS) ] = -1, | |
543 | [ C(RESULT_MISS) ] = -1, | |
544 | }, | |
545 | }, | |
546 | [ C(BPU ) ] = { | |
547 | [ C(OP_READ) ] = { | |
548 | [ C(RESULT_ACCESS) ] = 0xc4, /* BR_INST_RETIRED.ALL_BRANCHES */ | |
549 | [ C(RESULT_MISS) ] = 0xc5, /* BR_MISP_RETIRED.ALL_BRANCHES */ | |
550 | }, | |
551 | [ C(OP_WRITE) ] = { | |
552 | [ C(RESULT_ACCESS) ] = -1, | |
553 | [ C(RESULT_MISS) ] = -1, | |
554 | }, | |
555 | [ C(OP_PREFETCH) ] = { | |
556 | [ C(RESULT_ACCESS) ] = -1, | |
557 | [ C(RESULT_MISS) ] = -1, | |
558 | }, | |
559 | }, | |
560 | [ C(NODE) ] = { | |
561 | [ C(OP_READ) ] = { | |
562 | [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
563 | [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
564 | }, | |
565 | [ C(OP_WRITE) ] = { | |
566 | [ C(RESULT_ACCESS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
567 | [ C(RESULT_MISS) ] = 0x1b7, /* OFFCORE_RESPONSE */ | |
568 | }, | |
569 | [ C(OP_PREFETCH) ] = { | |
570 | [ C(RESULT_ACCESS) ] = 0x0, | |
571 | [ C(RESULT_MISS) ] = 0x0, | |
572 | }, | |
573 | }, | |
574 | }; | |
575 | ||
576 | static __initconst const u64 hsw_hw_cache_extra_regs | |
577 | [PERF_COUNT_HW_CACHE_MAX] | |
578 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
579 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
580 | { | |
581 | [ C(LL ) ] = { | |
582 | [ C(OP_READ) ] = { | |
583 | [ C(RESULT_ACCESS) ] = HSW_DEMAND_READ| | |
584 | HSW_LLC_ACCESS, | |
585 | [ C(RESULT_MISS) ] = HSW_DEMAND_READ| | |
586 | HSW_L3_MISS|HSW_ANY_SNOOP, | |
587 | }, | |
588 | [ C(OP_WRITE) ] = { | |
589 | [ C(RESULT_ACCESS) ] = HSW_DEMAND_WRITE| | |
590 | HSW_LLC_ACCESS, | |
591 | [ C(RESULT_MISS) ] = HSW_DEMAND_WRITE| | |
592 | HSW_L3_MISS|HSW_ANY_SNOOP, | |
593 | }, | |
594 | [ C(OP_PREFETCH) ] = { | |
595 | [ C(RESULT_ACCESS) ] = 0x0, | |
596 | [ C(RESULT_MISS) ] = 0x0, | |
597 | }, | |
598 | }, | |
599 | [ C(NODE) ] = { | |
600 | [ C(OP_READ) ] = { | |
601 | [ C(RESULT_ACCESS) ] = HSW_DEMAND_READ| | |
602 | HSW_L3_MISS_LOCAL_DRAM| | |
603 | HSW_SNOOP_DRAM, | |
604 | [ C(RESULT_MISS) ] = HSW_DEMAND_READ| | |
605 | HSW_L3_MISS_REMOTE| | |
606 | HSW_SNOOP_DRAM, | |
607 | }, | |
608 | [ C(OP_WRITE) ] = { | |
609 | [ C(RESULT_ACCESS) ] = HSW_DEMAND_WRITE| | |
610 | HSW_L3_MISS_LOCAL_DRAM| | |
611 | HSW_SNOOP_DRAM, | |
612 | [ C(RESULT_MISS) ] = HSW_DEMAND_WRITE| | |
613 | HSW_L3_MISS_REMOTE| | |
614 | HSW_SNOOP_DRAM, | |
615 | }, | |
616 | [ C(OP_PREFETCH) ] = { | |
617 | [ C(RESULT_ACCESS) ] = 0x0, | |
618 | [ C(RESULT_MISS) ] = 0x0, | |
619 | }, | |
620 | }, | |
621 | }; | |
622 | ||
caaa8be3 | 623 | static __initconst const u64 westmere_hw_cache_event_ids |
f22f54f4 PZ |
624 | [PERF_COUNT_HW_CACHE_MAX] |
625 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
626 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
627 | { | |
628 | [ C(L1D) ] = { | |
629 | [ C(OP_READ) ] = { | |
630 | [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */ | |
631 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */ | |
632 | }, | |
633 | [ C(OP_WRITE) ] = { | |
634 | [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */ | |
635 | [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */ | |
636 | }, | |
637 | [ C(OP_PREFETCH) ] = { | |
638 | [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */ | |
639 | [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */ | |
640 | }, | |
641 | }, | |
642 | [ C(L1I ) ] = { | |
643 | [ C(OP_READ) ] = { | |
644 | [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */ | |
645 | [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */ | |
646 | }, | |
647 | [ C(OP_WRITE) ] = { | |
648 | [ C(RESULT_ACCESS) ] = -1, | |
649 | [ C(RESULT_MISS) ] = -1, | |
650 | }, | |
651 | [ C(OP_PREFETCH) ] = { | |
652 | [ C(RESULT_ACCESS) ] = 0x0, | |
653 | [ C(RESULT_MISS) ] = 0x0, | |
654 | }, | |
655 | }, | |
656 | [ C(LL ) ] = { | |
657 | [ C(OP_READ) ] = { | |
63b6a675 | 658 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
e994d7d2 | 659 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
660 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ |
661 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 | 662 | }, |
e994d7d2 AK |
663 | /* |
664 | * Use RFO, not WRITEBACK, because a write miss would typically occur | |
665 | * on RFO. | |
666 | */ | |
f22f54f4 | 667 | [ C(OP_WRITE) ] = { |
63b6a675 PZ |
668 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
669 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
670 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | |
e994d7d2 | 671 | [ C(RESULT_MISS) ] = 0x01b7, |
f22f54f4 PZ |
672 | }, |
673 | [ C(OP_PREFETCH) ] = { | |
63b6a675 | 674 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
e994d7d2 | 675 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
676 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ |
677 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 PZ |
678 | }, |
679 | }, | |
680 | [ C(DTLB) ] = { | |
681 | [ C(OP_READ) ] = { | |
682 | [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */ | |
683 | [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */ | |
684 | }, | |
685 | [ C(OP_WRITE) ] = { | |
686 | [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */ | |
687 | [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */ | |
688 | }, | |
689 | [ C(OP_PREFETCH) ] = { | |
690 | [ C(RESULT_ACCESS) ] = 0x0, | |
691 | [ C(RESULT_MISS) ] = 0x0, | |
692 | }, | |
693 | }, | |
694 | [ C(ITLB) ] = { | |
695 | [ C(OP_READ) ] = { | |
696 | [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */ | |
697 | [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.ANY */ | |
698 | }, | |
699 | [ C(OP_WRITE) ] = { | |
700 | [ C(RESULT_ACCESS) ] = -1, | |
701 | [ C(RESULT_MISS) ] = -1, | |
702 | }, | |
703 | [ C(OP_PREFETCH) ] = { | |
704 | [ C(RESULT_ACCESS) ] = -1, | |
705 | [ C(RESULT_MISS) ] = -1, | |
706 | }, | |
707 | }, | |
708 | [ C(BPU ) ] = { | |
709 | [ C(OP_READ) ] = { | |
710 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */ | |
711 | [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */ | |
712 | }, | |
713 | [ C(OP_WRITE) ] = { | |
714 | [ C(RESULT_ACCESS) ] = -1, | |
715 | [ C(RESULT_MISS) ] = -1, | |
716 | }, | |
717 | [ C(OP_PREFETCH) ] = { | |
718 | [ C(RESULT_ACCESS) ] = -1, | |
719 | [ C(RESULT_MISS) ] = -1, | |
720 | }, | |
721 | }, | |
89d6c0b5 PZ |
722 | [ C(NODE) ] = { |
723 | [ C(OP_READ) ] = { | |
724 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
725 | [ C(RESULT_MISS) ] = 0x01b7, | |
726 | }, | |
727 | [ C(OP_WRITE) ] = { | |
728 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
729 | [ C(RESULT_MISS) ] = 0x01b7, | |
730 | }, | |
731 | [ C(OP_PREFETCH) ] = { | |
732 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
733 | [ C(RESULT_MISS) ] = 0x01b7, | |
734 | }, | |
735 | }, | |
f22f54f4 PZ |
736 | }; |
737 | ||
e994d7d2 | 738 | /* |
63b6a675 PZ |
739 | * Nehalem/Westmere MSR_OFFCORE_RESPONSE bits; |
740 | * See IA32 SDM Vol 3B 30.6.1.3 | |
e994d7d2 AK |
741 | */ |
742 | ||
63b6a675 PZ |
743 | #define NHM_DMND_DATA_RD (1 << 0) |
744 | #define NHM_DMND_RFO (1 << 1) | |
745 | #define NHM_DMND_IFETCH (1 << 2) | |
746 | #define NHM_DMND_WB (1 << 3) | |
747 | #define NHM_PF_DATA_RD (1 << 4) | |
748 | #define NHM_PF_DATA_RFO (1 << 5) | |
749 | #define NHM_PF_IFETCH (1 << 6) | |
750 | #define NHM_OFFCORE_OTHER (1 << 7) | |
751 | #define NHM_UNCORE_HIT (1 << 8) | |
752 | #define NHM_OTHER_CORE_HIT_SNP (1 << 9) | |
753 | #define NHM_OTHER_CORE_HITM (1 << 10) | |
754 | /* reserved */ | |
755 | #define NHM_REMOTE_CACHE_FWD (1 << 12) | |
756 | #define NHM_REMOTE_DRAM (1 << 13) | |
757 | #define NHM_LOCAL_DRAM (1 << 14) | |
758 | #define NHM_NON_DRAM (1 << 15) | |
759 | ||
87e24f4b PZ |
760 | #define NHM_LOCAL (NHM_LOCAL_DRAM|NHM_REMOTE_CACHE_FWD) |
761 | #define NHM_REMOTE (NHM_REMOTE_DRAM) | |
63b6a675 PZ |
762 | |
763 | #define NHM_DMND_READ (NHM_DMND_DATA_RD) | |
764 | #define NHM_DMND_WRITE (NHM_DMND_RFO|NHM_DMND_WB) | |
765 | #define NHM_DMND_PREFETCH (NHM_PF_DATA_RD|NHM_PF_DATA_RFO) | |
766 | ||
767 | #define NHM_L3_HIT (NHM_UNCORE_HIT|NHM_OTHER_CORE_HIT_SNP|NHM_OTHER_CORE_HITM) | |
87e24f4b | 768 | #define NHM_L3_MISS (NHM_NON_DRAM|NHM_LOCAL_DRAM|NHM_REMOTE_DRAM|NHM_REMOTE_CACHE_FWD) |
63b6a675 | 769 | #define NHM_L3_ACCESS (NHM_L3_HIT|NHM_L3_MISS) |
e994d7d2 AK |
770 | |
771 | static __initconst const u64 nehalem_hw_cache_extra_regs | |
772 | [PERF_COUNT_HW_CACHE_MAX] | |
773 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
774 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
775 | { | |
776 | [ C(LL ) ] = { | |
777 | [ C(OP_READ) ] = { | |
63b6a675 PZ |
778 | [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_L3_ACCESS, |
779 | [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_L3_MISS, | |
e994d7d2 AK |
780 | }, |
781 | [ C(OP_WRITE) ] = { | |
63b6a675 PZ |
782 | [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_L3_ACCESS, |
783 | [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_L3_MISS, | |
e994d7d2 AK |
784 | }, |
785 | [ C(OP_PREFETCH) ] = { | |
63b6a675 PZ |
786 | [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_L3_ACCESS, |
787 | [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_L3_MISS, | |
e994d7d2 | 788 | }, |
89d6c0b5 PZ |
789 | }, |
790 | [ C(NODE) ] = { | |
791 | [ C(OP_READ) ] = { | |
87e24f4b PZ |
792 | [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_LOCAL|NHM_REMOTE, |
793 | [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_REMOTE, | |
89d6c0b5 PZ |
794 | }, |
795 | [ C(OP_WRITE) ] = { | |
87e24f4b PZ |
796 | [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_LOCAL|NHM_REMOTE, |
797 | [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_REMOTE, | |
89d6c0b5 PZ |
798 | }, |
799 | [ C(OP_PREFETCH) ] = { | |
87e24f4b PZ |
800 | [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_LOCAL|NHM_REMOTE, |
801 | [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_REMOTE, | |
89d6c0b5 PZ |
802 | }, |
803 | }, | |
e994d7d2 AK |
804 | }; |
805 | ||
caaa8be3 | 806 | static __initconst const u64 nehalem_hw_cache_event_ids |
f22f54f4 PZ |
807 | [PERF_COUNT_HW_CACHE_MAX] |
808 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
809 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
810 | { | |
811 | [ C(L1D) ] = { | |
812 | [ C(OP_READ) ] = { | |
f4929bd3 PZ |
813 | [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */ |
814 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */ | |
f22f54f4 PZ |
815 | }, |
816 | [ C(OP_WRITE) ] = { | |
f4929bd3 PZ |
817 | [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */ |
818 | [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */ | |
f22f54f4 PZ |
819 | }, |
820 | [ C(OP_PREFETCH) ] = { | |
821 | [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */ | |
822 | [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */ | |
823 | }, | |
824 | }, | |
825 | [ C(L1I ) ] = { | |
826 | [ C(OP_READ) ] = { | |
827 | [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */ | |
828 | [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */ | |
829 | }, | |
830 | [ C(OP_WRITE) ] = { | |
831 | [ C(RESULT_ACCESS) ] = -1, | |
832 | [ C(RESULT_MISS) ] = -1, | |
833 | }, | |
834 | [ C(OP_PREFETCH) ] = { | |
835 | [ C(RESULT_ACCESS) ] = 0x0, | |
836 | [ C(RESULT_MISS) ] = 0x0, | |
837 | }, | |
838 | }, | |
839 | [ C(LL ) ] = { | |
840 | [ C(OP_READ) ] = { | |
e994d7d2 AK |
841 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
842 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
843 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ | |
844 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 | 845 | }, |
e994d7d2 AK |
846 | /* |
847 | * Use RFO, not WRITEBACK, because a write miss would typically occur | |
848 | * on RFO. | |
849 | */ | |
f22f54f4 | 850 | [ C(OP_WRITE) ] = { |
e994d7d2 AK |
851 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
852 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
853 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | |
854 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 PZ |
855 | }, |
856 | [ C(OP_PREFETCH) ] = { | |
e994d7d2 AK |
857 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
858 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
859 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ | |
860 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 PZ |
861 | }, |
862 | }, | |
863 | [ C(DTLB) ] = { | |
864 | [ C(OP_READ) ] = { | |
865 | [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */ | |
866 | [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */ | |
867 | }, | |
868 | [ C(OP_WRITE) ] = { | |
869 | [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */ | |
870 | [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */ | |
871 | }, | |
872 | [ C(OP_PREFETCH) ] = { | |
873 | [ C(RESULT_ACCESS) ] = 0x0, | |
874 | [ C(RESULT_MISS) ] = 0x0, | |
875 | }, | |
876 | }, | |
877 | [ C(ITLB) ] = { | |
878 | [ C(OP_READ) ] = { | |
879 | [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */ | |
880 | [ C(RESULT_MISS) ] = 0x20c8, /* ITLB_MISS_RETIRED */ | |
881 | }, | |
882 | [ C(OP_WRITE) ] = { | |
883 | [ C(RESULT_ACCESS) ] = -1, | |
884 | [ C(RESULT_MISS) ] = -1, | |
885 | }, | |
886 | [ C(OP_PREFETCH) ] = { | |
887 | [ C(RESULT_ACCESS) ] = -1, | |
888 | [ C(RESULT_MISS) ] = -1, | |
889 | }, | |
890 | }, | |
891 | [ C(BPU ) ] = { | |
892 | [ C(OP_READ) ] = { | |
893 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */ | |
894 | [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */ | |
895 | }, | |
896 | [ C(OP_WRITE) ] = { | |
897 | [ C(RESULT_ACCESS) ] = -1, | |
898 | [ C(RESULT_MISS) ] = -1, | |
899 | }, | |
900 | [ C(OP_PREFETCH) ] = { | |
901 | [ C(RESULT_ACCESS) ] = -1, | |
902 | [ C(RESULT_MISS) ] = -1, | |
903 | }, | |
904 | }, | |
89d6c0b5 PZ |
905 | [ C(NODE) ] = { |
906 | [ C(OP_READ) ] = { | |
907 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
908 | [ C(RESULT_MISS) ] = 0x01b7, | |
909 | }, | |
910 | [ C(OP_WRITE) ] = { | |
911 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
912 | [ C(RESULT_MISS) ] = 0x01b7, | |
913 | }, | |
914 | [ C(OP_PREFETCH) ] = { | |
915 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
916 | [ C(RESULT_MISS) ] = 0x01b7, | |
917 | }, | |
918 | }, | |
f22f54f4 PZ |
919 | }; |
920 | ||
caaa8be3 | 921 | static __initconst const u64 core2_hw_cache_event_ids |
f22f54f4 PZ |
922 | [PERF_COUNT_HW_CACHE_MAX] |
923 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
924 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
925 | { | |
926 | [ C(L1D) ] = { | |
927 | [ C(OP_READ) ] = { | |
928 | [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI */ | |
929 | [ C(RESULT_MISS) ] = 0x0140, /* L1D_CACHE_LD.I_STATE */ | |
930 | }, | |
931 | [ C(OP_WRITE) ] = { | |
932 | [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI */ | |
933 | [ C(RESULT_MISS) ] = 0x0141, /* L1D_CACHE_ST.I_STATE */ | |
934 | }, | |
935 | [ C(OP_PREFETCH) ] = { | |
936 | [ C(RESULT_ACCESS) ] = 0x104e, /* L1D_PREFETCH.REQUESTS */ | |
937 | [ C(RESULT_MISS) ] = 0, | |
938 | }, | |
939 | }, | |
940 | [ C(L1I ) ] = { | |
941 | [ C(OP_READ) ] = { | |
942 | [ C(RESULT_ACCESS) ] = 0x0080, /* L1I.READS */ | |
943 | [ C(RESULT_MISS) ] = 0x0081, /* L1I.MISSES */ | |
944 | }, | |
945 | [ C(OP_WRITE) ] = { | |
946 | [ C(RESULT_ACCESS) ] = -1, | |
947 | [ C(RESULT_MISS) ] = -1, | |
948 | }, | |
949 | [ C(OP_PREFETCH) ] = { | |
950 | [ C(RESULT_ACCESS) ] = 0, | |
951 | [ C(RESULT_MISS) ] = 0, | |
952 | }, | |
953 | }, | |
954 | [ C(LL ) ] = { | |
955 | [ C(OP_READ) ] = { | |
956 | [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */ | |
957 | [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */ | |
958 | }, | |
959 | [ C(OP_WRITE) ] = { | |
960 | [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */ | |
961 | [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */ | |
962 | }, | |
963 | [ C(OP_PREFETCH) ] = { | |
964 | [ C(RESULT_ACCESS) ] = 0, | |
965 | [ C(RESULT_MISS) ] = 0, | |
966 | }, | |
967 | }, | |
968 | [ C(DTLB) ] = { | |
969 | [ C(OP_READ) ] = { | |
970 | [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */ | |
971 | [ C(RESULT_MISS) ] = 0x0208, /* DTLB_MISSES.MISS_LD */ | |
972 | }, | |
973 | [ C(OP_WRITE) ] = { | |
974 | [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */ | |
975 | [ C(RESULT_MISS) ] = 0x0808, /* DTLB_MISSES.MISS_ST */ | |
976 | }, | |
977 | [ C(OP_PREFETCH) ] = { | |
978 | [ C(RESULT_ACCESS) ] = 0, | |
979 | [ C(RESULT_MISS) ] = 0, | |
980 | }, | |
981 | }, | |
982 | [ C(ITLB) ] = { | |
983 | [ C(OP_READ) ] = { | |
984 | [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */ | |
985 | [ C(RESULT_MISS) ] = 0x1282, /* ITLBMISSES */ | |
986 | }, | |
987 | [ C(OP_WRITE) ] = { | |
988 | [ C(RESULT_ACCESS) ] = -1, | |
989 | [ C(RESULT_MISS) ] = -1, | |
990 | }, | |
991 | [ C(OP_PREFETCH) ] = { | |
992 | [ C(RESULT_ACCESS) ] = -1, | |
993 | [ C(RESULT_MISS) ] = -1, | |
994 | }, | |
995 | }, | |
996 | [ C(BPU ) ] = { | |
997 | [ C(OP_READ) ] = { | |
998 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */ | |
999 | [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */ | |
1000 | }, | |
1001 | [ C(OP_WRITE) ] = { | |
1002 | [ C(RESULT_ACCESS) ] = -1, | |
1003 | [ C(RESULT_MISS) ] = -1, | |
1004 | }, | |
1005 | [ C(OP_PREFETCH) ] = { | |
1006 | [ C(RESULT_ACCESS) ] = -1, | |
1007 | [ C(RESULT_MISS) ] = -1, | |
1008 | }, | |
1009 | }, | |
1010 | }; | |
1011 | ||
caaa8be3 | 1012 | static __initconst const u64 atom_hw_cache_event_ids |
f22f54f4 PZ |
1013 | [PERF_COUNT_HW_CACHE_MAX] |
1014 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
1015 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
1016 | { | |
1017 | [ C(L1D) ] = { | |
1018 | [ C(OP_READ) ] = { | |
1019 | [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE.LD */ | |
1020 | [ C(RESULT_MISS) ] = 0, | |
1021 | }, | |
1022 | [ C(OP_WRITE) ] = { | |
1023 | [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE.ST */ | |
1024 | [ C(RESULT_MISS) ] = 0, | |
1025 | }, | |
1026 | [ C(OP_PREFETCH) ] = { | |
1027 | [ C(RESULT_ACCESS) ] = 0x0, | |
1028 | [ C(RESULT_MISS) ] = 0, | |
1029 | }, | |
1030 | }, | |
1031 | [ C(L1I ) ] = { | |
1032 | [ C(OP_READ) ] = { | |
1033 | [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */ | |
1034 | [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */ | |
1035 | }, | |
1036 | [ C(OP_WRITE) ] = { | |
1037 | [ C(RESULT_ACCESS) ] = -1, | |
1038 | [ C(RESULT_MISS) ] = -1, | |
1039 | }, | |
1040 | [ C(OP_PREFETCH) ] = { | |
1041 | [ C(RESULT_ACCESS) ] = 0, | |
1042 | [ C(RESULT_MISS) ] = 0, | |
1043 | }, | |
1044 | }, | |
1045 | [ C(LL ) ] = { | |
1046 | [ C(OP_READ) ] = { | |
1047 | [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */ | |
1048 | [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */ | |
1049 | }, | |
1050 | [ C(OP_WRITE) ] = { | |
1051 | [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */ | |
1052 | [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */ | |
1053 | }, | |
1054 | [ C(OP_PREFETCH) ] = { | |
1055 | [ C(RESULT_ACCESS) ] = 0, | |
1056 | [ C(RESULT_MISS) ] = 0, | |
1057 | }, | |
1058 | }, | |
1059 | [ C(DTLB) ] = { | |
1060 | [ C(OP_READ) ] = { | |
1061 | [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE_LD.MESI (alias) */ | |
1062 | [ C(RESULT_MISS) ] = 0x0508, /* DTLB_MISSES.MISS_LD */ | |
1063 | }, | |
1064 | [ C(OP_WRITE) ] = { | |
1065 | [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE_ST.MESI (alias) */ | |
1066 | [ C(RESULT_MISS) ] = 0x0608, /* DTLB_MISSES.MISS_ST */ | |
1067 | }, | |
1068 | [ C(OP_PREFETCH) ] = { | |
1069 | [ C(RESULT_ACCESS) ] = 0, | |
1070 | [ C(RESULT_MISS) ] = 0, | |
1071 | }, | |
1072 | }, | |
1073 | [ C(ITLB) ] = { | |
1074 | [ C(OP_READ) ] = { | |
1075 | [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */ | |
1076 | [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */ | |
1077 | }, | |
1078 | [ C(OP_WRITE) ] = { | |
1079 | [ C(RESULT_ACCESS) ] = -1, | |
1080 | [ C(RESULT_MISS) ] = -1, | |
1081 | }, | |
1082 | [ C(OP_PREFETCH) ] = { | |
1083 | [ C(RESULT_ACCESS) ] = -1, | |
1084 | [ C(RESULT_MISS) ] = -1, | |
1085 | }, | |
1086 | }, | |
1087 | [ C(BPU ) ] = { | |
1088 | [ C(OP_READ) ] = { | |
1089 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */ | |
1090 | [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */ | |
1091 | }, | |
1092 | [ C(OP_WRITE) ] = { | |
1093 | [ C(RESULT_ACCESS) ] = -1, | |
1094 | [ C(RESULT_MISS) ] = -1, | |
1095 | }, | |
1096 | [ C(OP_PREFETCH) ] = { | |
1097 | [ C(RESULT_ACCESS) ] = -1, | |
1098 | [ C(RESULT_MISS) ] = -1, | |
1099 | }, | |
1100 | }, | |
1101 | }; | |
1102 | ||
1fa64180 YZ |
1103 | static struct extra_reg intel_slm_extra_regs[] __read_mostly = |
1104 | { | |
1105 | /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ | |
06c939c1 PZ |
1106 | INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x768005ffffull, RSP_0), |
1107 | INTEL_UEVENT_EXTRA_REG(0x02b7, MSR_OFFCORE_RSP_1, 0x768005ffffull, RSP_1), | |
1fa64180 YZ |
1108 | EVENT_EXTRA_END |
1109 | }; | |
1110 | ||
1111 | #define SLM_DMND_READ SNB_DMND_DATA_RD | |
1112 | #define SLM_DMND_WRITE SNB_DMND_RFO | |
1113 | #define SLM_DMND_PREFETCH (SNB_PF_DATA_RD|SNB_PF_RFO) | |
1114 | ||
1115 | #define SLM_SNP_ANY (SNB_SNP_NONE|SNB_SNP_MISS|SNB_NO_FWD|SNB_HITM) | |
1116 | #define SLM_LLC_ACCESS SNB_RESP_ANY | |
1117 | #define SLM_LLC_MISS (SLM_SNP_ANY|SNB_NON_DRAM) | |
1118 | ||
1119 | static __initconst const u64 slm_hw_cache_extra_regs | |
1120 | [PERF_COUNT_HW_CACHE_MAX] | |
1121 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
1122 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
1123 | { | |
1124 | [ C(LL ) ] = { | |
1125 | [ C(OP_READ) ] = { | |
1126 | [ C(RESULT_ACCESS) ] = SLM_DMND_READ|SLM_LLC_ACCESS, | |
1127 | [ C(RESULT_MISS) ] = SLM_DMND_READ|SLM_LLC_MISS, | |
1128 | }, | |
1129 | [ C(OP_WRITE) ] = { | |
1130 | [ C(RESULT_ACCESS) ] = SLM_DMND_WRITE|SLM_LLC_ACCESS, | |
1131 | [ C(RESULT_MISS) ] = SLM_DMND_WRITE|SLM_LLC_MISS, | |
1132 | }, | |
1133 | [ C(OP_PREFETCH) ] = { | |
1134 | [ C(RESULT_ACCESS) ] = SLM_DMND_PREFETCH|SLM_LLC_ACCESS, | |
1135 | [ C(RESULT_MISS) ] = SLM_DMND_PREFETCH|SLM_LLC_MISS, | |
1136 | }, | |
1137 | }, | |
1138 | }; | |
1139 | ||
1140 | static __initconst const u64 slm_hw_cache_event_ids | |
1141 | [PERF_COUNT_HW_CACHE_MAX] | |
1142 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
1143 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
1144 | { | |
1145 | [ C(L1D) ] = { | |
1146 | [ C(OP_READ) ] = { | |
1147 | [ C(RESULT_ACCESS) ] = 0, | |
1148 | [ C(RESULT_MISS) ] = 0x0104, /* LD_DCU_MISS */ | |
1149 | }, | |
1150 | [ C(OP_WRITE) ] = { | |
1151 | [ C(RESULT_ACCESS) ] = 0, | |
1152 | [ C(RESULT_MISS) ] = 0, | |
1153 | }, | |
1154 | [ C(OP_PREFETCH) ] = { | |
1155 | [ C(RESULT_ACCESS) ] = 0, | |
1156 | [ C(RESULT_MISS) ] = 0, | |
1157 | }, | |
1158 | }, | |
1159 | [ C(L1I ) ] = { | |
1160 | [ C(OP_READ) ] = { | |
1161 | [ C(RESULT_ACCESS) ] = 0x0380, /* ICACHE.ACCESSES */ | |
1162 | [ C(RESULT_MISS) ] = 0x0280, /* ICACGE.MISSES */ | |
1163 | }, | |
1164 | [ C(OP_WRITE) ] = { | |
1165 | [ C(RESULT_ACCESS) ] = -1, | |
1166 | [ C(RESULT_MISS) ] = -1, | |
1167 | }, | |
1168 | [ C(OP_PREFETCH) ] = { | |
1169 | [ C(RESULT_ACCESS) ] = 0, | |
1170 | [ C(RESULT_MISS) ] = 0, | |
1171 | }, | |
1172 | }, | |
1173 | [ C(LL ) ] = { | |
1174 | [ C(OP_READ) ] = { | |
1175 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ | |
1176 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
1177 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ | |
1178 | [ C(RESULT_MISS) ] = 0x01b7, | |
1179 | }, | |
1180 | [ C(OP_WRITE) ] = { | |
1181 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ | |
1182 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
1183 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | |
1184 | [ C(RESULT_MISS) ] = 0x01b7, | |
1185 | }, | |
1186 | [ C(OP_PREFETCH) ] = { | |
1187 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ | |
1188 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
1189 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ | |
1190 | [ C(RESULT_MISS) ] = 0x01b7, | |
1191 | }, | |
1192 | }, | |
1193 | [ C(DTLB) ] = { | |
1194 | [ C(OP_READ) ] = { | |
1195 | [ C(RESULT_ACCESS) ] = 0, | |
1196 | [ C(RESULT_MISS) ] = 0x0804, /* LD_DTLB_MISS */ | |
1197 | }, | |
1198 | [ C(OP_WRITE) ] = { | |
1199 | [ C(RESULT_ACCESS) ] = 0, | |
1200 | [ C(RESULT_MISS) ] = 0, | |
1201 | }, | |
1202 | [ C(OP_PREFETCH) ] = { | |
1203 | [ C(RESULT_ACCESS) ] = 0, | |
1204 | [ C(RESULT_MISS) ] = 0, | |
1205 | }, | |
1206 | }, | |
1207 | [ C(ITLB) ] = { | |
1208 | [ C(OP_READ) ] = { | |
1209 | [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */ | |
1210 | [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */ | |
1211 | }, | |
1212 | [ C(OP_WRITE) ] = { | |
1213 | [ C(RESULT_ACCESS) ] = -1, | |
1214 | [ C(RESULT_MISS) ] = -1, | |
1215 | }, | |
1216 | [ C(OP_PREFETCH) ] = { | |
1217 | [ C(RESULT_ACCESS) ] = -1, | |
1218 | [ C(RESULT_MISS) ] = -1, | |
1219 | }, | |
1220 | }, | |
1221 | [ C(BPU ) ] = { | |
1222 | [ C(OP_READ) ] = { | |
1223 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */ | |
1224 | [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */ | |
1225 | }, | |
1226 | [ C(OP_WRITE) ] = { | |
1227 | [ C(RESULT_ACCESS) ] = -1, | |
1228 | [ C(RESULT_MISS) ] = -1, | |
1229 | }, | |
1230 | [ C(OP_PREFETCH) ] = { | |
1231 | [ C(RESULT_ACCESS) ] = -1, | |
1232 | [ C(RESULT_MISS) ] = -1, | |
1233 | }, | |
1234 | }, | |
1235 | }; | |
1236 | ||
f22f54f4 PZ |
1237 | static void intel_pmu_disable_all(void) |
1238 | { | |
89cbc767 | 1239 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
f22f54f4 PZ |
1240 | |
1241 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0); | |
1242 | ||
15c7ad51 | 1243 | if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) |
f22f54f4 | 1244 | intel_pmu_disable_bts(); |
8062382c AS |
1245 | else |
1246 | intel_bts_disable_local(); | |
ca037701 PZ |
1247 | |
1248 | intel_pmu_pebs_disable_all(); | |
caff2bef | 1249 | intel_pmu_lbr_disable_all(); |
f22f54f4 PZ |
1250 | } |
1251 | ||
11164cd4 | 1252 | static void intel_pmu_enable_all(int added) |
f22f54f4 | 1253 | { |
89cbc767 | 1254 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
f22f54f4 | 1255 | |
d329527e PZ |
1256 | intel_pmu_pebs_enable_all(); |
1257 | intel_pmu_lbr_enable_all(); | |
144d31e6 GN |
1258 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, |
1259 | x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask); | |
f22f54f4 | 1260 | |
15c7ad51 | 1261 | if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) { |
f22f54f4 | 1262 | struct perf_event *event = |
15c7ad51 | 1263 | cpuc->events[INTEL_PMC_IDX_FIXED_BTS]; |
f22f54f4 PZ |
1264 | |
1265 | if (WARN_ON_ONCE(!event)) | |
1266 | return; | |
1267 | ||
1268 | intel_pmu_enable_bts(event->hw.config); | |
8062382c AS |
1269 | } else |
1270 | intel_bts_enable_local(); | |
f22f54f4 PZ |
1271 | } |
1272 | ||
11164cd4 PZ |
1273 | /* |
1274 | * Workaround for: | |
1275 | * Intel Errata AAK100 (model 26) | |
1276 | * Intel Errata AAP53 (model 30) | |
40b91cd1 | 1277 | * Intel Errata BD53 (model 44) |
11164cd4 | 1278 | * |
351af072 ZY |
1279 | * The official story: |
1280 | * These chips need to be 'reset' when adding counters by programming the | |
1281 | * magic three (non-counting) events 0x4300B5, 0x4300D2, and 0x4300B1 either | |
1282 | * in sequence on the same PMC or on different PMCs. | |
1283 | * | |
1284 | * In practise it appears some of these events do in fact count, and | |
1285 | * we need to programm all 4 events. | |
11164cd4 | 1286 | */ |
351af072 | 1287 | static void intel_pmu_nhm_workaround(void) |
11164cd4 | 1288 | { |
89cbc767 | 1289 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
351af072 ZY |
1290 | static const unsigned long nhm_magic[4] = { |
1291 | 0x4300B5, | |
1292 | 0x4300D2, | |
1293 | 0x4300B1, | |
1294 | 0x4300B1 | |
1295 | }; | |
1296 | struct perf_event *event; | |
1297 | int i; | |
11164cd4 | 1298 | |
351af072 ZY |
1299 | /* |
1300 | * The Errata requires below steps: | |
1301 | * 1) Clear MSR_IA32_PEBS_ENABLE and MSR_CORE_PERF_GLOBAL_CTRL; | |
1302 | * 2) Configure 4 PERFEVTSELx with the magic events and clear | |
1303 | * the corresponding PMCx; | |
1304 | * 3) set bit0~bit3 of MSR_CORE_PERF_GLOBAL_CTRL; | |
1305 | * 4) Clear MSR_CORE_PERF_GLOBAL_CTRL; | |
1306 | * 5) Clear 4 pairs of ERFEVTSELx and PMCx; | |
1307 | */ | |
11164cd4 | 1308 | |
351af072 ZY |
1309 | /* |
1310 | * The real steps we choose are a little different from above. | |
1311 | * A) To reduce MSR operations, we don't run step 1) as they | |
1312 | * are already cleared before this function is called; | |
1313 | * B) Call x86_perf_event_update to save PMCx before configuring | |
1314 | * PERFEVTSELx with magic number; | |
1315 | * C) With step 5), we do clear only when the PERFEVTSELx is | |
1316 | * not used currently. | |
1317 | * D) Call x86_perf_event_set_period to restore PMCx; | |
1318 | */ | |
11164cd4 | 1319 | |
351af072 ZY |
1320 | /* We always operate 4 pairs of PERF Counters */ |
1321 | for (i = 0; i < 4; i++) { | |
1322 | event = cpuc->events[i]; | |
1323 | if (event) | |
1324 | x86_perf_event_update(event); | |
1325 | } | |
11164cd4 | 1326 | |
351af072 ZY |
1327 | for (i = 0; i < 4; i++) { |
1328 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, nhm_magic[i]); | |
1329 | wrmsrl(MSR_ARCH_PERFMON_PERFCTR0 + i, 0x0); | |
1330 | } | |
1331 | ||
1332 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0xf); | |
1333 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0); | |
11164cd4 | 1334 | |
351af072 ZY |
1335 | for (i = 0; i < 4; i++) { |
1336 | event = cpuc->events[i]; | |
1337 | ||
1338 | if (event) { | |
1339 | x86_perf_event_set_period(event); | |
31fa58af | 1340 | __x86_pmu_enable_event(&event->hw, |
351af072 ZY |
1341 | ARCH_PERFMON_EVENTSEL_ENABLE); |
1342 | } else | |
1343 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, 0x0); | |
11164cd4 | 1344 | } |
351af072 ZY |
1345 | } |
1346 | ||
1347 | static void intel_pmu_nhm_enable_all(int added) | |
1348 | { | |
1349 | if (added) | |
1350 | intel_pmu_nhm_workaround(); | |
11164cd4 PZ |
1351 | intel_pmu_enable_all(added); |
1352 | } | |
1353 | ||
f22f54f4 PZ |
1354 | static inline u64 intel_pmu_get_status(void) |
1355 | { | |
1356 | u64 status; | |
1357 | ||
1358 | rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status); | |
1359 | ||
1360 | return status; | |
1361 | } | |
1362 | ||
1363 | static inline void intel_pmu_ack_status(u64 ack) | |
1364 | { | |
1365 | wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack); | |
1366 | } | |
1367 | ||
ca037701 | 1368 | static void intel_pmu_disable_fixed(struct hw_perf_event *hwc) |
f22f54f4 | 1369 | { |
15c7ad51 | 1370 | int idx = hwc->idx - INTEL_PMC_IDX_FIXED; |
f22f54f4 PZ |
1371 | u64 ctrl_val, mask; |
1372 | ||
1373 | mask = 0xfULL << (idx * 4); | |
1374 | ||
1375 | rdmsrl(hwc->config_base, ctrl_val); | |
1376 | ctrl_val &= ~mask; | |
7645a24c | 1377 | wrmsrl(hwc->config_base, ctrl_val); |
f22f54f4 PZ |
1378 | } |
1379 | ||
2b9e344d PZ |
1380 | static inline bool event_is_checkpointed(struct perf_event *event) |
1381 | { | |
1382 | return (event->hw.config & HSW_IN_TX_CHECKPOINTED) != 0; | |
1383 | } | |
1384 | ||
ca037701 | 1385 | static void intel_pmu_disable_event(struct perf_event *event) |
f22f54f4 | 1386 | { |
aff3d91a | 1387 | struct hw_perf_event *hwc = &event->hw; |
89cbc767 | 1388 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
aff3d91a | 1389 | |
15c7ad51 | 1390 | if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) { |
f22f54f4 PZ |
1391 | intel_pmu_disable_bts(); |
1392 | intel_pmu_drain_bts_buffer(); | |
1393 | return; | |
1394 | } | |
1395 | ||
144d31e6 GN |
1396 | cpuc->intel_ctrl_guest_mask &= ~(1ull << hwc->idx); |
1397 | cpuc->intel_ctrl_host_mask &= ~(1ull << hwc->idx); | |
2b9e344d | 1398 | cpuc->intel_cp_status &= ~(1ull << hwc->idx); |
144d31e6 | 1399 | |
60ce0fbd SE |
1400 | /* |
1401 | * must disable before any actual event | |
1402 | * because any event may be combined with LBR | |
1403 | */ | |
a46a2300 | 1404 | if (needs_branch_stack(event)) |
60ce0fbd SE |
1405 | intel_pmu_lbr_disable(event); |
1406 | ||
f22f54f4 | 1407 | if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) { |
aff3d91a | 1408 | intel_pmu_disable_fixed(hwc); |
f22f54f4 PZ |
1409 | return; |
1410 | } | |
1411 | ||
aff3d91a | 1412 | x86_pmu_disable_event(event); |
ca037701 | 1413 | |
ab608344 | 1414 | if (unlikely(event->attr.precise_ip)) |
ef21f683 | 1415 | intel_pmu_pebs_disable(event); |
f22f54f4 PZ |
1416 | } |
1417 | ||
ca037701 | 1418 | static void intel_pmu_enable_fixed(struct hw_perf_event *hwc) |
f22f54f4 | 1419 | { |
15c7ad51 | 1420 | int idx = hwc->idx - INTEL_PMC_IDX_FIXED; |
f22f54f4 | 1421 | u64 ctrl_val, bits, mask; |
f22f54f4 PZ |
1422 | |
1423 | /* | |
1424 | * Enable IRQ generation (0x8), | |
1425 | * and enable ring-3 counting (0x2) and ring-0 counting (0x1) | |
1426 | * if requested: | |
1427 | */ | |
1428 | bits = 0x8ULL; | |
1429 | if (hwc->config & ARCH_PERFMON_EVENTSEL_USR) | |
1430 | bits |= 0x2; | |
1431 | if (hwc->config & ARCH_PERFMON_EVENTSEL_OS) | |
1432 | bits |= 0x1; | |
1433 | ||
1434 | /* | |
1435 | * ANY bit is supported in v3 and up | |
1436 | */ | |
1437 | if (x86_pmu.version > 2 && hwc->config & ARCH_PERFMON_EVENTSEL_ANY) | |
1438 | bits |= 0x4; | |
1439 | ||
1440 | bits <<= (idx * 4); | |
1441 | mask = 0xfULL << (idx * 4); | |
1442 | ||
1443 | rdmsrl(hwc->config_base, ctrl_val); | |
1444 | ctrl_val &= ~mask; | |
1445 | ctrl_val |= bits; | |
7645a24c | 1446 | wrmsrl(hwc->config_base, ctrl_val); |
f22f54f4 PZ |
1447 | } |
1448 | ||
aff3d91a | 1449 | static void intel_pmu_enable_event(struct perf_event *event) |
f22f54f4 | 1450 | { |
aff3d91a | 1451 | struct hw_perf_event *hwc = &event->hw; |
89cbc767 | 1452 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
aff3d91a | 1453 | |
15c7ad51 | 1454 | if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) { |
0a3aee0d | 1455 | if (!__this_cpu_read(cpu_hw_events.enabled)) |
f22f54f4 PZ |
1456 | return; |
1457 | ||
1458 | intel_pmu_enable_bts(hwc->config); | |
1459 | return; | |
1460 | } | |
60ce0fbd SE |
1461 | /* |
1462 | * must enabled before any actual event | |
1463 | * because any event may be combined with LBR | |
1464 | */ | |
a46a2300 | 1465 | if (needs_branch_stack(event)) |
60ce0fbd | 1466 | intel_pmu_lbr_enable(event); |
f22f54f4 | 1467 | |
144d31e6 GN |
1468 | if (event->attr.exclude_host) |
1469 | cpuc->intel_ctrl_guest_mask |= (1ull << hwc->idx); | |
1470 | if (event->attr.exclude_guest) | |
1471 | cpuc->intel_ctrl_host_mask |= (1ull << hwc->idx); | |
1472 | ||
2b9e344d PZ |
1473 | if (unlikely(event_is_checkpointed(event))) |
1474 | cpuc->intel_cp_status |= (1ull << hwc->idx); | |
1475 | ||
f22f54f4 | 1476 | if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) { |
aff3d91a | 1477 | intel_pmu_enable_fixed(hwc); |
f22f54f4 PZ |
1478 | return; |
1479 | } | |
1480 | ||
ab608344 | 1481 | if (unlikely(event->attr.precise_ip)) |
ef21f683 | 1482 | intel_pmu_pebs_enable(event); |
ca037701 | 1483 | |
31fa58af | 1484 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); |
f22f54f4 PZ |
1485 | } |
1486 | ||
1487 | /* | |
1488 | * Save and restart an expired event. Called by NMI contexts, | |
1489 | * so it has to be careful about preempting normal event ops: | |
1490 | */ | |
de0428a7 | 1491 | int intel_pmu_save_and_restart(struct perf_event *event) |
f22f54f4 | 1492 | { |
cc2ad4ba | 1493 | x86_perf_event_update(event); |
2dbf0116 AK |
1494 | /* |
1495 | * For a checkpointed counter always reset back to 0. This | |
1496 | * avoids a situation where the counter overflows, aborts the | |
1497 | * transaction and is then set back to shortly before the | |
1498 | * overflow, and overflows and aborts again. | |
1499 | */ | |
1500 | if (unlikely(event_is_checkpointed(event))) { | |
1501 | /* No race with NMIs because the counter should not be armed */ | |
1502 | wrmsrl(event->hw.event_base, 0); | |
1503 | local64_set(&event->hw.prev_count, 0); | |
1504 | } | |
cc2ad4ba | 1505 | return x86_perf_event_set_period(event); |
f22f54f4 PZ |
1506 | } |
1507 | ||
1508 | static void intel_pmu_reset(void) | |
1509 | { | |
0a3aee0d | 1510 | struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds); |
f22f54f4 PZ |
1511 | unsigned long flags; |
1512 | int idx; | |
1513 | ||
948b1bb8 | 1514 | if (!x86_pmu.num_counters) |
f22f54f4 PZ |
1515 | return; |
1516 | ||
1517 | local_irq_save(flags); | |
1518 | ||
c767a54b | 1519 | pr_info("clearing PMU state on CPU#%d\n", smp_processor_id()); |
f22f54f4 | 1520 | |
948b1bb8 | 1521 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
715c85b1 PA |
1522 | wrmsrl_safe(x86_pmu_config_addr(idx), 0ull); |
1523 | wrmsrl_safe(x86_pmu_event_addr(idx), 0ull); | |
f22f54f4 | 1524 | } |
948b1bb8 | 1525 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) |
715c85b1 | 1526 | wrmsrl_safe(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); |
948b1bb8 | 1527 | |
f22f54f4 PZ |
1528 | if (ds) |
1529 | ds->bts_index = ds->bts_buffer_base; | |
1530 | ||
1531 | local_irq_restore(flags); | |
1532 | } | |
1533 | ||
1534 | /* | |
1535 | * This handler is triggered by the local APIC, so the APIC IRQ handling | |
1536 | * rules apply: | |
1537 | */ | |
1538 | static int intel_pmu_handle_irq(struct pt_regs *regs) | |
1539 | { | |
1540 | struct perf_sample_data data; | |
1541 | struct cpu_hw_events *cpuc; | |
1542 | int bit, loops; | |
2e556b5b | 1543 | u64 status; |
b0b2072d | 1544 | int handled; |
f22f54f4 | 1545 | |
89cbc767 | 1546 | cpuc = this_cpu_ptr(&cpu_hw_events); |
f22f54f4 | 1547 | |
2bce5dac | 1548 | /* |
72db5596 AK |
1549 | * No known reason to not always do late ACK, |
1550 | * but just in case do it opt-in. | |
2bce5dac | 1551 | */ |
72db5596 AK |
1552 | if (!x86_pmu.late_ack) |
1553 | apic_write(APIC_LVTPC, APIC_DM_NMI); | |
3fb2b8dd | 1554 | intel_pmu_disable_all(); |
b0b2072d | 1555 | handled = intel_pmu_drain_bts_buffer(); |
8062382c | 1556 | handled += intel_bts_interrupt(); |
f22f54f4 | 1557 | status = intel_pmu_get_status(); |
a3ef2229 MM |
1558 | if (!status) |
1559 | goto done; | |
f22f54f4 PZ |
1560 | |
1561 | loops = 0; | |
1562 | again: | |
2e556b5b | 1563 | intel_pmu_ack_status(status); |
f22f54f4 | 1564 | if (++loops > 100) { |
ae0def05 DH |
1565 | static bool warned = false; |
1566 | if (!warned) { | |
1567 | WARN(1, "perfevents: irq loop stuck!\n"); | |
1568 | perf_event_print_debug(); | |
1569 | warned = true; | |
1570 | } | |
f22f54f4 | 1571 | intel_pmu_reset(); |
3fb2b8dd | 1572 | goto done; |
f22f54f4 PZ |
1573 | } |
1574 | ||
1575 | inc_irq_stat(apic_perf_irqs); | |
ca037701 | 1576 | |
caff2bef PZ |
1577 | intel_pmu_lbr_read(); |
1578 | ||
b292d7a1 HD |
1579 | /* |
1580 | * CondChgd bit 63 doesn't mean any overflow status. Ignore | |
1581 | * and clear the bit. | |
1582 | */ | |
1583 | if (__test_and_clear_bit(63, (unsigned long *)&status)) { | |
1584 | if (!status) | |
1585 | goto done; | |
1586 | } | |
1587 | ||
ca037701 PZ |
1588 | /* |
1589 | * PEBS overflow sets bit 62 in the global status register | |
1590 | */ | |
de725dec PZ |
1591 | if (__test_and_clear_bit(62, (unsigned long *)&status)) { |
1592 | handled++; | |
ca037701 | 1593 | x86_pmu.drain_pebs(regs); |
de725dec | 1594 | } |
ca037701 | 1595 | |
52ca9ced AS |
1596 | /* |
1597 | * Intel PT | |
1598 | */ | |
1599 | if (__test_and_clear_bit(55, (unsigned long *)&status)) { | |
1600 | handled++; | |
1601 | intel_pt_interrupt(); | |
1602 | } | |
1603 | ||
2dbf0116 | 1604 | /* |
2b9e344d PZ |
1605 | * Checkpointed counters can lead to 'spurious' PMIs because the |
1606 | * rollback caused by the PMI will have cleared the overflow status | |
1607 | * bit. Therefore always force probe these counters. | |
2dbf0116 | 1608 | */ |
2b9e344d | 1609 | status |= cpuc->intel_cp_status; |
2dbf0116 | 1610 | |
984b3f57 | 1611 | for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) { |
f22f54f4 PZ |
1612 | struct perf_event *event = cpuc->events[bit]; |
1613 | ||
de725dec PZ |
1614 | handled++; |
1615 | ||
f22f54f4 PZ |
1616 | if (!test_bit(bit, cpuc->active_mask)) |
1617 | continue; | |
1618 | ||
1619 | if (!intel_pmu_save_and_restart(event)) | |
1620 | continue; | |
1621 | ||
fd0d000b | 1622 | perf_sample_data_init(&data, 0, event->hw.last_period); |
f22f54f4 | 1623 | |
60ce0fbd SE |
1624 | if (has_branch_stack(event)) |
1625 | data.br_stack = &cpuc->lbr_stack; | |
1626 | ||
a8b0ca17 | 1627 | if (perf_event_overflow(event, &data, regs)) |
a4eaf7f1 | 1628 | x86_pmu_stop(event, 0); |
f22f54f4 PZ |
1629 | } |
1630 | ||
f22f54f4 PZ |
1631 | /* |
1632 | * Repeat if there is more work to be done: | |
1633 | */ | |
1634 | status = intel_pmu_get_status(); | |
1635 | if (status) | |
1636 | goto again; | |
1637 | ||
3fb2b8dd | 1638 | done: |
11164cd4 | 1639 | intel_pmu_enable_all(0); |
72db5596 AK |
1640 | /* |
1641 | * Only unmask the NMI after the overflow counters | |
1642 | * have been reset. This avoids spurious NMIs on | |
1643 | * Haswell CPUs. | |
1644 | */ | |
1645 | if (x86_pmu.late_ack) | |
1646 | apic_write(APIC_LVTPC, APIC_DM_NMI); | |
de725dec | 1647 | return handled; |
f22f54f4 PZ |
1648 | } |
1649 | ||
f22f54f4 | 1650 | static struct event_constraint * |
ca037701 | 1651 | intel_bts_constraints(struct perf_event *event) |
f22f54f4 | 1652 | { |
ca037701 PZ |
1653 | struct hw_perf_event *hwc = &event->hw; |
1654 | unsigned int hw_event, bts_event; | |
f22f54f4 | 1655 | |
18a073a3 PZ |
1656 | if (event->attr.freq) |
1657 | return NULL; | |
1658 | ||
ca037701 PZ |
1659 | hw_event = hwc->config & INTEL_ARCH_EVENT_MASK; |
1660 | bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS); | |
f22f54f4 | 1661 | |
ca037701 | 1662 | if (unlikely(hw_event == bts_event && hwc->sample_period == 1)) |
f22f54f4 | 1663 | return &bts_constraint; |
ca037701 | 1664 | |
f22f54f4 PZ |
1665 | return NULL; |
1666 | } | |
1667 | ||
5a425294 | 1668 | static int intel_alt_er(int idx) |
b79e8941 | 1669 | { |
9a5e3fb5 | 1670 | if (!(x86_pmu.flags & PMU_FL_HAS_RSP_1)) |
5a425294 | 1671 | return idx; |
b79e8941 | 1672 | |
5a425294 PZ |
1673 | if (idx == EXTRA_REG_RSP_0) |
1674 | return EXTRA_REG_RSP_1; | |
1675 | ||
1676 | if (idx == EXTRA_REG_RSP_1) | |
1677 | return EXTRA_REG_RSP_0; | |
1678 | ||
1679 | return idx; | |
1680 | } | |
1681 | ||
1682 | static void intel_fixup_er(struct perf_event *event, int idx) | |
1683 | { | |
1684 | event->hw.extra_reg.idx = idx; | |
1685 | ||
1686 | if (idx == EXTRA_REG_RSP_0) { | |
b79e8941 | 1687 | event->hw.config &= ~INTEL_ARCH_EVENT_MASK; |
53ad0447 | 1688 | event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_0].event; |
b79e8941 | 1689 | event->hw.extra_reg.reg = MSR_OFFCORE_RSP_0; |
5a425294 PZ |
1690 | } else if (idx == EXTRA_REG_RSP_1) { |
1691 | event->hw.config &= ~INTEL_ARCH_EVENT_MASK; | |
53ad0447 | 1692 | event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_1].event; |
5a425294 | 1693 | event->hw.extra_reg.reg = MSR_OFFCORE_RSP_1; |
b79e8941 | 1694 | } |
b79e8941 PZ |
1695 | } |
1696 | ||
efc9f05d SE |
1697 | /* |
1698 | * manage allocation of shared extra msr for certain events | |
1699 | * | |
1700 | * sharing can be: | |
1701 | * per-cpu: to be shared between the various events on a single PMU | |
1702 | * per-core: per-cpu + shared by HT threads | |
1703 | */ | |
a7e3ed1e | 1704 | static struct event_constraint * |
efc9f05d | 1705 | __intel_shared_reg_get_constraints(struct cpu_hw_events *cpuc, |
b36817e8 SE |
1706 | struct perf_event *event, |
1707 | struct hw_perf_event_extra *reg) | |
a7e3ed1e | 1708 | { |
efc9f05d | 1709 | struct event_constraint *c = &emptyconstraint; |
a7e3ed1e | 1710 | struct er_account *era; |
cd8a38d3 | 1711 | unsigned long flags; |
5a425294 | 1712 | int idx = reg->idx; |
a7e3ed1e | 1713 | |
5a425294 PZ |
1714 | /* |
1715 | * reg->alloc can be set due to existing state, so for fake cpuc we | |
1716 | * need to ignore this, otherwise we might fail to allocate proper fake | |
1717 | * state for this extra reg constraint. Also see the comment below. | |
1718 | */ | |
1719 | if (reg->alloc && !cpuc->is_fake) | |
b36817e8 | 1720 | return NULL; /* call x86_get_event_constraint() */ |
a7e3ed1e | 1721 | |
b79e8941 | 1722 | again: |
5a425294 | 1723 | era = &cpuc->shared_regs->regs[idx]; |
cd8a38d3 SE |
1724 | /* |
1725 | * we use spin_lock_irqsave() to avoid lockdep issues when | |
1726 | * passing a fake cpuc | |
1727 | */ | |
1728 | raw_spin_lock_irqsave(&era->lock, flags); | |
efc9f05d SE |
1729 | |
1730 | if (!atomic_read(&era->ref) || era->config == reg->config) { | |
1731 | ||
5a425294 PZ |
1732 | /* |
1733 | * If its a fake cpuc -- as per validate_{group,event}() we | |
1734 | * shouldn't touch event state and we can avoid doing so | |
1735 | * since both will only call get_event_constraints() once | |
1736 | * on each event, this avoids the need for reg->alloc. | |
1737 | * | |
1738 | * Not doing the ER fixup will only result in era->reg being | |
1739 | * wrong, but since we won't actually try and program hardware | |
1740 | * this isn't a problem either. | |
1741 | */ | |
1742 | if (!cpuc->is_fake) { | |
1743 | if (idx != reg->idx) | |
1744 | intel_fixup_er(event, idx); | |
1745 | ||
1746 | /* | |
1747 | * x86_schedule_events() can call get_event_constraints() | |
1748 | * multiple times on events in the case of incremental | |
1749 | * scheduling(). reg->alloc ensures we only do the ER | |
1750 | * allocation once. | |
1751 | */ | |
1752 | reg->alloc = 1; | |
1753 | } | |
1754 | ||
efc9f05d SE |
1755 | /* lock in msr value */ |
1756 | era->config = reg->config; | |
1757 | era->reg = reg->reg; | |
1758 | ||
1759 | /* one more user */ | |
1760 | atomic_inc(&era->ref); | |
1761 | ||
a7e3ed1e | 1762 | /* |
b36817e8 SE |
1763 | * need to call x86_get_event_constraint() |
1764 | * to check if associated event has constraints | |
a7e3ed1e | 1765 | */ |
b36817e8 | 1766 | c = NULL; |
5a425294 PZ |
1767 | } else { |
1768 | idx = intel_alt_er(idx); | |
1769 | if (idx != reg->idx) { | |
1770 | raw_spin_unlock_irqrestore(&era->lock, flags); | |
1771 | goto again; | |
1772 | } | |
a7e3ed1e | 1773 | } |
cd8a38d3 | 1774 | raw_spin_unlock_irqrestore(&era->lock, flags); |
a7e3ed1e | 1775 | |
efc9f05d SE |
1776 | return c; |
1777 | } | |
1778 | ||
1779 | static void | |
1780 | __intel_shared_reg_put_constraints(struct cpu_hw_events *cpuc, | |
1781 | struct hw_perf_event_extra *reg) | |
1782 | { | |
1783 | struct er_account *era; | |
1784 | ||
1785 | /* | |
5a425294 PZ |
1786 | * Only put constraint if extra reg was actually allocated. Also takes |
1787 | * care of event which do not use an extra shared reg. | |
1788 | * | |
1789 | * Also, if this is a fake cpuc we shouldn't touch any event state | |
1790 | * (reg->alloc) and we don't care about leaving inconsistent cpuc state | |
1791 | * either since it'll be thrown out. | |
efc9f05d | 1792 | */ |
5a425294 | 1793 | if (!reg->alloc || cpuc->is_fake) |
efc9f05d SE |
1794 | return; |
1795 | ||
1796 | era = &cpuc->shared_regs->regs[reg->idx]; | |
1797 | ||
1798 | /* one fewer user */ | |
1799 | atomic_dec(&era->ref); | |
1800 | ||
1801 | /* allocate again next time */ | |
1802 | reg->alloc = 0; | |
1803 | } | |
1804 | ||
1805 | static struct event_constraint * | |
1806 | intel_shared_regs_constraints(struct cpu_hw_events *cpuc, | |
1807 | struct perf_event *event) | |
1808 | { | |
b36817e8 SE |
1809 | struct event_constraint *c = NULL, *d; |
1810 | struct hw_perf_event_extra *xreg, *breg; | |
1811 | ||
1812 | xreg = &event->hw.extra_reg; | |
1813 | if (xreg->idx != EXTRA_REG_NONE) { | |
1814 | c = __intel_shared_reg_get_constraints(cpuc, event, xreg); | |
1815 | if (c == &emptyconstraint) | |
1816 | return c; | |
1817 | } | |
1818 | breg = &event->hw.branch_reg; | |
1819 | if (breg->idx != EXTRA_REG_NONE) { | |
1820 | d = __intel_shared_reg_get_constraints(cpuc, event, breg); | |
1821 | if (d == &emptyconstraint) { | |
1822 | __intel_shared_reg_put_constraints(cpuc, xreg); | |
1823 | c = d; | |
1824 | } | |
1825 | } | |
efc9f05d | 1826 | return c; |
a7e3ed1e AK |
1827 | } |
1828 | ||
de0428a7 KW |
1829 | struct event_constraint * |
1830 | x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |
1831 | { | |
1832 | struct event_constraint *c; | |
1833 | ||
1834 | if (x86_pmu.event_constraints) { | |
1835 | for_each_event_constraint(c, x86_pmu.event_constraints) { | |
9fac2cf3 | 1836 | if ((event->hw.config & c->cmask) == c->code) { |
9fac2cf3 | 1837 | event->hw.flags |= c->flags; |
de0428a7 | 1838 | return c; |
9fac2cf3 | 1839 | } |
de0428a7 KW |
1840 | } |
1841 | } | |
1842 | ||
1843 | return &unconstrained; | |
1844 | } | |
1845 | ||
f22f54f4 PZ |
1846 | static struct event_constraint * |
1847 | intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |
1848 | { | |
1849 | struct event_constraint *c; | |
1850 | ||
ca037701 PZ |
1851 | c = intel_bts_constraints(event); |
1852 | if (c) | |
1853 | return c; | |
1854 | ||
687805e4 | 1855 | c = intel_shared_regs_constraints(cpuc, event); |
f22f54f4 PZ |
1856 | if (c) |
1857 | return c; | |
1858 | ||
687805e4 | 1859 | c = intel_pebs_constraints(event); |
a7e3ed1e AK |
1860 | if (c) |
1861 | return c; | |
1862 | ||
f22f54f4 PZ |
1863 | return x86_get_event_constraints(cpuc, event); |
1864 | } | |
1865 | ||
efc9f05d SE |
1866 | static void |
1867 | intel_put_shared_regs_event_constraints(struct cpu_hw_events *cpuc, | |
a7e3ed1e AK |
1868 | struct perf_event *event) |
1869 | { | |
efc9f05d | 1870 | struct hw_perf_event_extra *reg; |
a7e3ed1e | 1871 | |
efc9f05d SE |
1872 | reg = &event->hw.extra_reg; |
1873 | if (reg->idx != EXTRA_REG_NONE) | |
1874 | __intel_shared_reg_put_constraints(cpuc, reg); | |
b36817e8 SE |
1875 | |
1876 | reg = &event->hw.branch_reg; | |
1877 | if (reg->idx != EXTRA_REG_NONE) | |
1878 | __intel_shared_reg_put_constraints(cpuc, reg); | |
efc9f05d | 1879 | } |
a7e3ed1e | 1880 | |
efc9f05d SE |
1881 | static void intel_put_event_constraints(struct cpu_hw_events *cpuc, |
1882 | struct perf_event *event) | |
1883 | { | |
1884 | intel_put_shared_regs_event_constraints(cpuc, event); | |
a7e3ed1e AK |
1885 | } |
1886 | ||
0780c927 | 1887 | static void intel_pebs_aliases_core2(struct perf_event *event) |
b4cdc5c2 | 1888 | { |
0780c927 | 1889 | if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) { |
7639dae0 PZ |
1890 | /* |
1891 | * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P | |
1892 | * (0x003c) so that we can use it with PEBS. | |
1893 | * | |
1894 | * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't | |
1895 | * PEBS capable. However we can use INST_RETIRED.ANY_P | |
1896 | * (0x00c0), which is a PEBS capable event, to get the same | |
1897 | * count. | |
1898 | * | |
1899 | * INST_RETIRED.ANY_P counts the number of cycles that retires | |
1900 | * CNTMASK instructions. By setting CNTMASK to a value (16) | |
1901 | * larger than the maximum number of instructions that can be | |
1902 | * retired per cycle (4) and then inverting the condition, we | |
1903 | * count all cycles that retire 16 or less instructions, which | |
1904 | * is every cycle. | |
1905 | * | |
1906 | * Thereby we gain a PEBS capable cycle counter. | |
1907 | */ | |
f9b4eeb8 PZ |
1908 | u64 alt_config = X86_CONFIG(.event=0xc0, .inv=1, .cmask=16); |
1909 | ||
0780c927 PZ |
1910 | alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK); |
1911 | event->hw.config = alt_config; | |
1912 | } | |
1913 | } | |
1914 | ||
1915 | static void intel_pebs_aliases_snb(struct perf_event *event) | |
1916 | { | |
1917 | if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) { | |
1918 | /* | |
1919 | * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P | |
1920 | * (0x003c) so that we can use it with PEBS. | |
1921 | * | |
1922 | * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't | |
1923 | * PEBS capable. However we can use UOPS_RETIRED.ALL | |
1924 | * (0x01c2), which is a PEBS capable event, to get the same | |
1925 | * count. | |
1926 | * | |
1927 | * UOPS_RETIRED.ALL counts the number of cycles that retires | |
1928 | * CNTMASK micro-ops. By setting CNTMASK to a value (16) | |
1929 | * larger than the maximum number of micro-ops that can be | |
1930 | * retired per cycle (4) and then inverting the condition, we | |
1931 | * count all cycles that retire 16 or less micro-ops, which | |
1932 | * is every cycle. | |
1933 | * | |
1934 | * Thereby we gain a PEBS capable cycle counter. | |
1935 | */ | |
1936 | u64 alt_config = X86_CONFIG(.event=0xc2, .umask=0x01, .inv=1, .cmask=16); | |
7639dae0 PZ |
1937 | |
1938 | alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK); | |
1939 | event->hw.config = alt_config; | |
1940 | } | |
0780c927 PZ |
1941 | } |
1942 | ||
1943 | static int intel_pmu_hw_config(struct perf_event *event) | |
1944 | { | |
1945 | int ret = x86_pmu_hw_config(event); | |
1946 | ||
1947 | if (ret) | |
1948 | return ret; | |
1949 | ||
1950 | if (event->attr.precise_ip && x86_pmu.pebs_aliases) | |
1951 | x86_pmu.pebs_aliases(event); | |
7639dae0 | 1952 | |
a46a2300 | 1953 | if (needs_branch_stack(event)) { |
60ce0fbd SE |
1954 | ret = intel_pmu_setup_lbr_filter(event); |
1955 | if (ret) | |
1956 | return ret; | |
48070342 AS |
1957 | |
1958 | /* | |
1959 | * BTS is set up earlier in this path, so don't account twice | |
1960 | */ | |
1961 | if (!intel_pmu_has_bts(event)) { | |
1962 | /* disallow lbr if conflicting events are present */ | |
1963 | if (x86_add_exclusive(x86_lbr_exclusive_lbr)) | |
1964 | return -EBUSY; | |
1965 | ||
1966 | event->destroy = hw_perf_lbr_event_destroy; | |
1967 | } | |
60ce0fbd SE |
1968 | } |
1969 | ||
b4cdc5c2 PZ |
1970 | if (event->attr.type != PERF_TYPE_RAW) |
1971 | return 0; | |
1972 | ||
1973 | if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY)) | |
1974 | return 0; | |
1975 | ||
1976 | if (x86_pmu.version < 3) | |
1977 | return -EINVAL; | |
1978 | ||
1979 | if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | |
1980 | return -EACCES; | |
1981 | ||
1982 | event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY; | |
1983 | ||
1984 | return 0; | |
1985 | } | |
1986 | ||
144d31e6 GN |
1987 | struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) |
1988 | { | |
1989 | if (x86_pmu.guest_get_msrs) | |
1990 | return x86_pmu.guest_get_msrs(nr); | |
1991 | *nr = 0; | |
1992 | return NULL; | |
1993 | } | |
1994 | EXPORT_SYMBOL_GPL(perf_guest_get_msrs); | |
1995 | ||
1996 | static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) | |
1997 | { | |
89cbc767 | 1998 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
144d31e6 GN |
1999 | struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; |
2000 | ||
2001 | arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL; | |
2002 | arr[0].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; | |
2003 | arr[0].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask; | |
26a4f3c0 GN |
2004 | /* |
2005 | * If PMU counter has PEBS enabled it is not enough to disable counter | |
2006 | * on a guest entry since PEBS memory write can overshoot guest entry | |
2007 | * and corrupt guest memory. Disabling PEBS solves the problem. | |
2008 | */ | |
2009 | arr[1].msr = MSR_IA32_PEBS_ENABLE; | |
2010 | arr[1].host = cpuc->pebs_enabled; | |
2011 | arr[1].guest = 0; | |
144d31e6 | 2012 | |
26a4f3c0 | 2013 | *nr = 2; |
144d31e6 GN |
2014 | return arr; |
2015 | } | |
2016 | ||
2017 | static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr) | |
2018 | { | |
89cbc767 | 2019 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
144d31e6 GN |
2020 | struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; |
2021 | int idx; | |
2022 | ||
2023 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | |
2024 | struct perf_event *event = cpuc->events[idx]; | |
2025 | ||
2026 | arr[idx].msr = x86_pmu_config_addr(idx); | |
2027 | arr[idx].host = arr[idx].guest = 0; | |
2028 | ||
2029 | if (!test_bit(idx, cpuc->active_mask)) | |
2030 | continue; | |
2031 | ||
2032 | arr[idx].host = arr[idx].guest = | |
2033 | event->hw.config | ARCH_PERFMON_EVENTSEL_ENABLE; | |
2034 | ||
2035 | if (event->attr.exclude_host) | |
2036 | arr[idx].host &= ~ARCH_PERFMON_EVENTSEL_ENABLE; | |
2037 | else if (event->attr.exclude_guest) | |
2038 | arr[idx].guest &= ~ARCH_PERFMON_EVENTSEL_ENABLE; | |
2039 | } | |
2040 | ||
2041 | *nr = x86_pmu.num_counters; | |
2042 | return arr; | |
2043 | } | |
2044 | ||
2045 | static void core_pmu_enable_event(struct perf_event *event) | |
2046 | { | |
2047 | if (!event->attr.exclude_host) | |
2048 | x86_pmu_enable_event(event); | |
2049 | } | |
2050 | ||
2051 | static void core_pmu_enable_all(int added) | |
2052 | { | |
89cbc767 | 2053 | struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events); |
144d31e6 GN |
2054 | int idx; |
2055 | ||
2056 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | |
2057 | struct hw_perf_event *hwc = &cpuc->events[idx]->hw; | |
2058 | ||
2059 | if (!test_bit(idx, cpuc->active_mask) || | |
2060 | cpuc->events[idx]->attr.exclude_host) | |
2061 | continue; | |
2062 | ||
2063 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); | |
2064 | } | |
2065 | } | |
2066 | ||
3a632cb2 AK |
2067 | static int hsw_hw_config(struct perf_event *event) |
2068 | { | |
2069 | int ret = intel_pmu_hw_config(event); | |
2070 | ||
2071 | if (ret) | |
2072 | return ret; | |
2073 | if (!boot_cpu_has(X86_FEATURE_RTM) && !boot_cpu_has(X86_FEATURE_HLE)) | |
2074 | return 0; | |
2075 | event->hw.config |= event->attr.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED); | |
2076 | ||
2077 | /* | |
2078 | * IN_TX/IN_TX-CP filters are not supported by the Haswell PMU with | |
2079 | * PEBS or in ANY thread mode. Since the results are non-sensical forbid | |
2080 | * this combination. | |
2081 | */ | |
2082 | if ((event->hw.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED)) && | |
2083 | ((event->hw.config & ARCH_PERFMON_EVENTSEL_ANY) || | |
2084 | event->attr.precise_ip > 0)) | |
2085 | return -EOPNOTSUPP; | |
2086 | ||
2dbf0116 AK |
2087 | if (event_is_checkpointed(event)) { |
2088 | /* | |
2089 | * Sampling of checkpointed events can cause situations where | |
2090 | * the CPU constantly aborts because of a overflow, which is | |
2091 | * then checkpointed back and ignored. Forbid checkpointing | |
2092 | * for sampling. | |
2093 | * | |
2094 | * But still allow a long sampling period, so that perf stat | |
2095 | * from KVM works. | |
2096 | */ | |
2097 | if (event->attr.sample_period > 0 && | |
2098 | event->attr.sample_period < 0x7fffffff) | |
2099 | return -EOPNOTSUPP; | |
2100 | } | |
3a632cb2 AK |
2101 | return 0; |
2102 | } | |
2103 | ||
2104 | static struct event_constraint counter2_constraint = | |
2105 | EVENT_CONSTRAINT(0, 0x4, 0); | |
2106 | ||
2107 | static struct event_constraint * | |
2108 | hsw_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |
2109 | { | |
2110 | struct event_constraint *c = intel_get_event_constraints(cpuc, event); | |
2111 | ||
2112 | /* Handle special quirk on in_tx_checkpointed only in counter 2 */ | |
2113 | if (event->hw.config & HSW_IN_TX_CHECKPOINTED) { | |
2114 | if (c->idxmsk64 & (1U << 2)) | |
2115 | return &counter2_constraint; | |
2116 | return &emptyconstraint; | |
2117 | } | |
2118 | ||
2119 | return c; | |
2120 | } | |
2121 | ||
294fe0f5 AK |
2122 | /* |
2123 | * Broadwell: | |
2124 | * | |
2125 | * The INST_RETIRED.ALL period always needs to have lowest 6 bits cleared | |
2126 | * (BDM55) and it must not use a period smaller than 100 (BDM11). We combine | |
2127 | * the two to enforce a minimum period of 128 (the smallest value that has bits | |
2128 | * 0-5 cleared and >= 100). | |
2129 | * | |
2130 | * Because of how the code in x86_perf_event_set_period() works, the truncation | |
2131 | * of the lower 6 bits is 'harmless' as we'll occasionally add a longer period | |
2132 | * to make up for the 'lost' events due to carrying the 'error' in period_left. | |
2133 | * | |
2134 | * Therefore the effective (average) period matches the requested period, | |
2135 | * despite coarser hardware granularity. | |
2136 | */ | |
2137 | static unsigned bdw_limit_period(struct perf_event *event, unsigned left) | |
2138 | { | |
2139 | if ((event->hw.config & INTEL_ARCH_EVENT_MASK) == | |
2140 | X86_CONFIG(.event=0xc0, .umask=0x01)) { | |
2141 | if (left < 128) | |
2142 | left = 128; | |
2143 | left &= ~0x3fu; | |
2144 | } | |
2145 | return left; | |
2146 | } | |
2147 | ||
641cc938 JO |
2148 | PMU_FORMAT_ATTR(event, "config:0-7" ); |
2149 | PMU_FORMAT_ATTR(umask, "config:8-15" ); | |
2150 | PMU_FORMAT_ATTR(edge, "config:18" ); | |
2151 | PMU_FORMAT_ATTR(pc, "config:19" ); | |
2152 | PMU_FORMAT_ATTR(any, "config:21" ); /* v3 + */ | |
2153 | PMU_FORMAT_ATTR(inv, "config:23" ); | |
2154 | PMU_FORMAT_ATTR(cmask, "config:24-31" ); | |
3a632cb2 AK |
2155 | PMU_FORMAT_ATTR(in_tx, "config:32"); |
2156 | PMU_FORMAT_ATTR(in_tx_cp, "config:33"); | |
641cc938 JO |
2157 | |
2158 | static struct attribute *intel_arch_formats_attr[] = { | |
2159 | &format_attr_event.attr, | |
2160 | &format_attr_umask.attr, | |
2161 | &format_attr_edge.attr, | |
2162 | &format_attr_pc.attr, | |
2163 | &format_attr_inv.attr, | |
2164 | &format_attr_cmask.attr, | |
2165 | NULL, | |
2166 | }; | |
2167 | ||
0bf79d44 JO |
2168 | ssize_t intel_event_sysfs_show(char *page, u64 config) |
2169 | { | |
2170 | u64 event = (config & ARCH_PERFMON_EVENTSEL_EVENT); | |
2171 | ||
2172 | return x86_event_sysfs_show(page, config, event); | |
2173 | } | |
2174 | ||
caaa8be3 | 2175 | static __initconst const struct x86_pmu core_pmu = { |
f22f54f4 PZ |
2176 | .name = "core", |
2177 | .handle_irq = x86_pmu_handle_irq, | |
2178 | .disable_all = x86_pmu_disable_all, | |
144d31e6 GN |
2179 | .enable_all = core_pmu_enable_all, |
2180 | .enable = core_pmu_enable_event, | |
f22f54f4 | 2181 | .disable = x86_pmu_disable_event, |
b4cdc5c2 | 2182 | .hw_config = x86_pmu_hw_config, |
a072738e | 2183 | .schedule_events = x86_schedule_events, |
f22f54f4 PZ |
2184 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
2185 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | |
2186 | .event_map = intel_pmu_event_map, | |
f22f54f4 PZ |
2187 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
2188 | .apic = 1, | |
2189 | /* | |
2190 | * Intel PMCs cannot be accessed sanely above 32 bit width, | |
2191 | * so we install an artificial 1<<31 period regardless of | |
2192 | * the generic event period: | |
2193 | */ | |
2194 | .max_period = (1ULL << 31) - 1, | |
2195 | .get_event_constraints = intel_get_event_constraints, | |
a7e3ed1e | 2196 | .put_event_constraints = intel_put_event_constraints, |
f22f54f4 | 2197 | .event_constraints = intel_core_event_constraints, |
144d31e6 | 2198 | .guest_get_msrs = core_guest_get_msrs, |
641cc938 | 2199 | .format_attrs = intel_arch_formats_attr, |
0bf79d44 | 2200 | .events_sysfs_show = intel_event_sysfs_show, |
f22f54f4 PZ |
2201 | }; |
2202 | ||
de0428a7 | 2203 | struct intel_shared_regs *allocate_shared_regs(int cpu) |
efc9f05d SE |
2204 | { |
2205 | struct intel_shared_regs *regs; | |
2206 | int i; | |
2207 | ||
2208 | regs = kzalloc_node(sizeof(struct intel_shared_regs), | |
2209 | GFP_KERNEL, cpu_to_node(cpu)); | |
2210 | if (regs) { | |
2211 | /* | |
2212 | * initialize the locks to keep lockdep happy | |
2213 | */ | |
2214 | for (i = 0; i < EXTRA_REG_MAX; i++) | |
2215 | raw_spin_lock_init(®s->regs[i].lock); | |
2216 | ||
2217 | regs->core_id = -1; | |
2218 | } | |
2219 | return regs; | |
2220 | } | |
2221 | ||
a7e3ed1e AK |
2222 | static int intel_pmu_cpu_prepare(int cpu) |
2223 | { | |
2224 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); | |
2225 | ||
b36817e8 | 2226 | if (!(x86_pmu.extra_regs || x86_pmu.lbr_sel_map)) |
69092624 LM |
2227 | return NOTIFY_OK; |
2228 | ||
efc9f05d SE |
2229 | cpuc->shared_regs = allocate_shared_regs(cpu); |
2230 | if (!cpuc->shared_regs) | |
a7e3ed1e AK |
2231 | return NOTIFY_BAD; |
2232 | ||
a7e3ed1e AK |
2233 | return NOTIFY_OK; |
2234 | } | |
2235 | ||
74846d35 PZ |
2236 | static void intel_pmu_cpu_starting(int cpu) |
2237 | { | |
a7e3ed1e AK |
2238 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); |
2239 | int core_id = topology_core_id(cpu); | |
2240 | int i; | |
2241 | ||
69092624 LM |
2242 | init_debug_store_on_cpu(cpu); |
2243 | /* | |
2244 | * Deal with CPUs that don't clear their LBRs on power-up. | |
2245 | */ | |
2246 | intel_pmu_lbr_reset(); | |
2247 | ||
b36817e8 SE |
2248 | cpuc->lbr_sel = NULL; |
2249 | ||
2250 | if (!cpuc->shared_regs) | |
69092624 LM |
2251 | return; |
2252 | ||
9a5e3fb5 | 2253 | if (!(x86_pmu.flags & PMU_FL_NO_HT_SHARING)) { |
90413464 SE |
2254 | void **onln = &cpuc->kfree_on_online[X86_PERF_KFREE_SHARED]; |
2255 | ||
b36817e8 SE |
2256 | for_each_cpu(i, topology_thread_cpumask(cpu)) { |
2257 | struct intel_shared_regs *pc; | |
a7e3ed1e | 2258 | |
b36817e8 SE |
2259 | pc = per_cpu(cpu_hw_events, i).shared_regs; |
2260 | if (pc && pc->core_id == core_id) { | |
90413464 | 2261 | *onln = cpuc->shared_regs; |
b36817e8 SE |
2262 | cpuc->shared_regs = pc; |
2263 | break; | |
2264 | } | |
a7e3ed1e | 2265 | } |
b36817e8 SE |
2266 | cpuc->shared_regs->core_id = core_id; |
2267 | cpuc->shared_regs->refcnt++; | |
a7e3ed1e AK |
2268 | } |
2269 | ||
b36817e8 SE |
2270 | if (x86_pmu.lbr_sel_map) |
2271 | cpuc->lbr_sel = &cpuc->shared_regs->regs[EXTRA_REG_LBR]; | |
74846d35 PZ |
2272 | } |
2273 | ||
2274 | static void intel_pmu_cpu_dying(int cpu) | |
2275 | { | |
a7e3ed1e | 2276 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); |
efc9f05d | 2277 | struct intel_shared_regs *pc; |
a7e3ed1e | 2278 | |
efc9f05d | 2279 | pc = cpuc->shared_regs; |
a7e3ed1e AK |
2280 | if (pc) { |
2281 | if (pc->core_id == -1 || --pc->refcnt == 0) | |
2282 | kfree(pc); | |
efc9f05d | 2283 | cpuc->shared_regs = NULL; |
a7e3ed1e AK |
2284 | } |
2285 | ||
74846d35 PZ |
2286 | fini_debug_store_on_cpu(cpu); |
2287 | } | |
2288 | ||
641cc938 JO |
2289 | PMU_FORMAT_ATTR(offcore_rsp, "config1:0-63"); |
2290 | ||
a63fcab4 SE |
2291 | PMU_FORMAT_ATTR(ldlat, "config1:0-15"); |
2292 | ||
641cc938 JO |
2293 | static struct attribute *intel_arch3_formats_attr[] = { |
2294 | &format_attr_event.attr, | |
2295 | &format_attr_umask.attr, | |
2296 | &format_attr_edge.attr, | |
2297 | &format_attr_pc.attr, | |
2298 | &format_attr_any.attr, | |
2299 | &format_attr_inv.attr, | |
2300 | &format_attr_cmask.attr, | |
3a632cb2 AK |
2301 | &format_attr_in_tx.attr, |
2302 | &format_attr_in_tx_cp.attr, | |
641cc938 JO |
2303 | |
2304 | &format_attr_offcore_rsp.attr, /* XXX do NHM/WSM + SNB breakout */ | |
a63fcab4 | 2305 | &format_attr_ldlat.attr, /* PEBS load latency */ |
641cc938 JO |
2306 | NULL, |
2307 | }; | |
2308 | ||
caaa8be3 | 2309 | static __initconst const struct x86_pmu intel_pmu = { |
f22f54f4 PZ |
2310 | .name = "Intel", |
2311 | .handle_irq = intel_pmu_handle_irq, | |
2312 | .disable_all = intel_pmu_disable_all, | |
2313 | .enable_all = intel_pmu_enable_all, | |
2314 | .enable = intel_pmu_enable_event, | |
2315 | .disable = intel_pmu_disable_event, | |
b4cdc5c2 | 2316 | .hw_config = intel_pmu_hw_config, |
a072738e | 2317 | .schedule_events = x86_schedule_events, |
f22f54f4 PZ |
2318 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
2319 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | |
2320 | .event_map = intel_pmu_event_map, | |
f22f54f4 PZ |
2321 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
2322 | .apic = 1, | |
2323 | /* | |
2324 | * Intel PMCs cannot be accessed sanely above 32 bit width, | |
2325 | * so we install an artificial 1<<31 period regardless of | |
2326 | * the generic event period: | |
2327 | */ | |
2328 | .max_period = (1ULL << 31) - 1, | |
3f6da390 | 2329 | .get_event_constraints = intel_get_event_constraints, |
a7e3ed1e | 2330 | .put_event_constraints = intel_put_event_constraints, |
0780c927 | 2331 | .pebs_aliases = intel_pebs_aliases_core2, |
3f6da390 | 2332 | |
641cc938 | 2333 | .format_attrs = intel_arch3_formats_attr, |
0bf79d44 | 2334 | .events_sysfs_show = intel_event_sysfs_show, |
641cc938 | 2335 | |
a7e3ed1e | 2336 | .cpu_prepare = intel_pmu_cpu_prepare, |
74846d35 PZ |
2337 | .cpu_starting = intel_pmu_cpu_starting, |
2338 | .cpu_dying = intel_pmu_cpu_dying, | |
144d31e6 | 2339 | .guest_get_msrs = intel_guest_get_msrs, |
2a0ad3b3 | 2340 | .sched_task = intel_pmu_lbr_sched_task, |
f22f54f4 PZ |
2341 | }; |
2342 | ||
c1d6f42f | 2343 | static __init void intel_clovertown_quirk(void) |
3c44780b PZ |
2344 | { |
2345 | /* | |
2346 | * PEBS is unreliable due to: | |
2347 | * | |
2348 | * AJ67 - PEBS may experience CPL leaks | |
2349 | * AJ68 - PEBS PMI may be delayed by one event | |
2350 | * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12] | |
2351 | * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS | |
2352 | * | |
2353 | * AJ67 could be worked around by restricting the OS/USR flags. | |
2354 | * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI. | |
2355 | * | |
2356 | * AJ106 could possibly be worked around by not allowing LBR | |
2357 | * usage from PEBS, including the fixup. | |
2358 | * AJ68 could possibly be worked around by always programming | |
ec75a716 | 2359 | * a pebs_event_reset[0] value and coping with the lost events. |
3c44780b PZ |
2360 | * |
2361 | * But taken together it might just make sense to not enable PEBS on | |
2362 | * these chips. | |
2363 | */ | |
c767a54b | 2364 | pr_warn("PEBS disabled due to CPU errata\n"); |
3c44780b PZ |
2365 | x86_pmu.pebs = 0; |
2366 | x86_pmu.pebs_constraints = NULL; | |
2367 | } | |
2368 | ||
c93dc84c PZ |
2369 | static int intel_snb_pebs_broken(int cpu) |
2370 | { | |
2371 | u32 rev = UINT_MAX; /* default to broken for unknown models */ | |
2372 | ||
2373 | switch (cpu_data(cpu).x86_model) { | |
2374 | case 42: /* SNB */ | |
2375 | rev = 0x28; | |
2376 | break; | |
2377 | ||
2378 | case 45: /* SNB-EP */ | |
2379 | switch (cpu_data(cpu).x86_mask) { | |
2380 | case 6: rev = 0x618; break; | |
2381 | case 7: rev = 0x70c; break; | |
2382 | } | |
2383 | } | |
2384 | ||
2385 | return (cpu_data(cpu).microcode < rev); | |
2386 | } | |
2387 | ||
2388 | static void intel_snb_check_microcode(void) | |
2389 | { | |
2390 | int pebs_broken = 0; | |
2391 | int cpu; | |
2392 | ||
2393 | get_online_cpus(); | |
2394 | for_each_online_cpu(cpu) { | |
2395 | if ((pebs_broken = intel_snb_pebs_broken(cpu))) | |
2396 | break; | |
2397 | } | |
2398 | put_online_cpus(); | |
2399 | ||
2400 | if (pebs_broken == x86_pmu.pebs_broken) | |
2401 | return; | |
2402 | ||
2403 | /* | |
2404 | * Serialized by the microcode lock.. | |
2405 | */ | |
2406 | if (x86_pmu.pebs_broken) { | |
2407 | pr_info("PEBS enabled due to microcode update\n"); | |
2408 | x86_pmu.pebs_broken = 0; | |
2409 | } else { | |
2410 | pr_info("PEBS disabled due to CPU errata, please upgrade microcode\n"); | |
2411 | x86_pmu.pebs_broken = 1; | |
2412 | } | |
2413 | } | |
2414 | ||
338b522c KL |
2415 | /* |
2416 | * Under certain circumstances, access certain MSR may cause #GP. | |
2417 | * The function tests if the input MSR can be safely accessed. | |
2418 | */ | |
2419 | static bool check_msr(unsigned long msr, u64 mask) | |
2420 | { | |
2421 | u64 val_old, val_new, val_tmp; | |
2422 | ||
2423 | /* | |
2424 | * Read the current value, change it and read it back to see if it | |
2425 | * matches, this is needed to detect certain hardware emulators | |
2426 | * (qemu/kvm) that don't trap on the MSR access and always return 0s. | |
2427 | */ | |
2428 | if (rdmsrl_safe(msr, &val_old)) | |
2429 | return false; | |
2430 | ||
2431 | /* | |
2432 | * Only change the bits which can be updated by wrmsrl. | |
2433 | */ | |
2434 | val_tmp = val_old ^ mask; | |
2435 | if (wrmsrl_safe(msr, val_tmp) || | |
2436 | rdmsrl_safe(msr, &val_new)) | |
2437 | return false; | |
2438 | ||
2439 | if (val_new != val_tmp) | |
2440 | return false; | |
2441 | ||
2442 | /* Here it's sure that the MSR can be safely accessed. | |
2443 | * Restore the old value and return. | |
2444 | */ | |
2445 | wrmsrl(msr, val_old); | |
2446 | ||
2447 | return true; | |
2448 | } | |
2449 | ||
c1d6f42f | 2450 | static __init void intel_sandybridge_quirk(void) |
6a600a8b | 2451 | { |
c93dc84c PZ |
2452 | x86_pmu.check_microcode = intel_snb_check_microcode; |
2453 | intel_snb_check_microcode(); | |
6a600a8b PZ |
2454 | } |
2455 | ||
c1d6f42f PZ |
2456 | static const struct { int id; char *name; } intel_arch_events_map[] __initconst = { |
2457 | { PERF_COUNT_HW_CPU_CYCLES, "cpu cycles" }, | |
2458 | { PERF_COUNT_HW_INSTRUCTIONS, "instructions" }, | |
2459 | { PERF_COUNT_HW_BUS_CYCLES, "bus cycles" }, | |
2460 | { PERF_COUNT_HW_CACHE_REFERENCES, "cache references" }, | |
2461 | { PERF_COUNT_HW_CACHE_MISSES, "cache misses" }, | |
2462 | { PERF_COUNT_HW_BRANCH_INSTRUCTIONS, "branch instructions" }, | |
2463 | { PERF_COUNT_HW_BRANCH_MISSES, "branch misses" }, | |
ffb871bc GN |
2464 | }; |
2465 | ||
c1d6f42f PZ |
2466 | static __init void intel_arch_events_quirk(void) |
2467 | { | |
2468 | int bit; | |
2469 | ||
2470 | /* disable event that reported as not presend by cpuid */ | |
2471 | for_each_set_bit(bit, x86_pmu.events_mask, ARRAY_SIZE(intel_arch_events_map)) { | |
2472 | intel_perfmon_event_map[intel_arch_events_map[bit].id] = 0; | |
c767a54b JP |
2473 | pr_warn("CPUID marked event: \'%s\' unavailable\n", |
2474 | intel_arch_events_map[bit].name); | |
c1d6f42f PZ |
2475 | } |
2476 | } | |
2477 | ||
2478 | static __init void intel_nehalem_quirk(void) | |
2479 | { | |
2480 | union cpuid10_ebx ebx; | |
2481 | ||
2482 | ebx.full = x86_pmu.events_maskl; | |
2483 | if (ebx.split.no_branch_misses_retired) { | |
2484 | /* | |
2485 | * Erratum AAJ80 detected, we work it around by using | |
2486 | * the BR_MISP_EXEC.ANY event. This will over-count | |
2487 | * branch-misses, but it's still much better than the | |
2488 | * architectural event which is often completely bogus: | |
2489 | */ | |
2490 | intel_perfmon_event_map[PERF_COUNT_HW_BRANCH_MISSES] = 0x7f89; | |
2491 | ebx.split.no_branch_misses_retired = 0; | |
2492 | x86_pmu.events_maskl = ebx.full; | |
c767a54b | 2493 | pr_info("CPU erratum AAJ80 worked around\n"); |
c1d6f42f PZ |
2494 | } |
2495 | } | |
2496 | ||
7f2ee91f IM |
2497 | EVENT_ATTR_STR(mem-loads, mem_ld_hsw, "event=0xcd,umask=0x1,ldlat=3"); |
2498 | EVENT_ATTR_STR(mem-stores, mem_st_hsw, "event=0xd0,umask=0x82") | |
f9134f36 | 2499 | |
4b2c4f1f | 2500 | /* Haswell special events */ |
7f2ee91f IM |
2501 | EVENT_ATTR_STR(tx-start, tx_start, "event=0xc9,umask=0x1"); |
2502 | EVENT_ATTR_STR(tx-commit, tx_commit, "event=0xc9,umask=0x2"); | |
2503 | EVENT_ATTR_STR(tx-abort, tx_abort, "event=0xc9,umask=0x4"); | |
2504 | EVENT_ATTR_STR(tx-capacity, tx_capacity, "event=0x54,umask=0x2"); | |
2505 | EVENT_ATTR_STR(tx-conflict, tx_conflict, "event=0x54,umask=0x1"); | |
2506 | EVENT_ATTR_STR(el-start, el_start, "event=0xc8,umask=0x1"); | |
2507 | EVENT_ATTR_STR(el-commit, el_commit, "event=0xc8,umask=0x2"); | |
2508 | EVENT_ATTR_STR(el-abort, el_abort, "event=0xc8,umask=0x4"); | |
2509 | EVENT_ATTR_STR(el-capacity, el_capacity, "event=0x54,umask=0x2"); | |
2510 | EVENT_ATTR_STR(el-conflict, el_conflict, "event=0x54,umask=0x1"); | |
2511 | EVENT_ATTR_STR(cycles-t, cycles_t, "event=0x3c,in_tx=1"); | |
2512 | EVENT_ATTR_STR(cycles-ct, cycles_ct, "event=0x3c,in_tx=1,in_tx_cp=1"); | |
4b2c4f1f | 2513 | |
f9134f36 | 2514 | static struct attribute *hsw_events_attrs[] = { |
4b2c4f1f AK |
2515 | EVENT_PTR(tx_start), |
2516 | EVENT_PTR(tx_commit), | |
2517 | EVENT_PTR(tx_abort), | |
2518 | EVENT_PTR(tx_capacity), | |
2519 | EVENT_PTR(tx_conflict), | |
2520 | EVENT_PTR(el_start), | |
2521 | EVENT_PTR(el_commit), | |
2522 | EVENT_PTR(el_abort), | |
2523 | EVENT_PTR(el_capacity), | |
2524 | EVENT_PTR(el_conflict), | |
2525 | EVENT_PTR(cycles_t), | |
2526 | EVENT_PTR(cycles_ct), | |
f9134f36 AK |
2527 | EVENT_PTR(mem_ld_hsw), |
2528 | EVENT_PTR(mem_st_hsw), | |
2529 | NULL | |
2530 | }; | |
2531 | ||
de0428a7 | 2532 | __init int intel_pmu_init(void) |
f22f54f4 PZ |
2533 | { |
2534 | union cpuid10_edx edx; | |
2535 | union cpuid10_eax eax; | |
ffb871bc | 2536 | union cpuid10_ebx ebx; |
a1eac7ac | 2537 | struct event_constraint *c; |
f22f54f4 | 2538 | unsigned int unused; |
338b522c KL |
2539 | struct extra_reg *er; |
2540 | int version, i; | |
f22f54f4 PZ |
2541 | |
2542 | if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { | |
a072738e CG |
2543 | switch (boot_cpu_data.x86) { |
2544 | case 0x6: | |
2545 | return p6_pmu_init(); | |
e717bf4e VW |
2546 | case 0xb: |
2547 | return knc_pmu_init(); | |
a072738e CG |
2548 | case 0xf: |
2549 | return p4_pmu_init(); | |
2550 | } | |
f22f54f4 | 2551 | return -ENODEV; |
f22f54f4 PZ |
2552 | } |
2553 | ||
2554 | /* | |
2555 | * Check whether the Architectural PerfMon supports | |
2556 | * Branch Misses Retired hw_event or not. | |
2557 | */ | |
ffb871bc GN |
2558 | cpuid(10, &eax.full, &ebx.full, &unused, &edx.full); |
2559 | if (eax.split.mask_length < ARCH_PERFMON_EVENTS_COUNT) | |
f22f54f4 PZ |
2560 | return -ENODEV; |
2561 | ||
2562 | version = eax.split.version_id; | |
2563 | if (version < 2) | |
2564 | x86_pmu = core_pmu; | |
2565 | else | |
2566 | x86_pmu = intel_pmu; | |
2567 | ||
2568 | x86_pmu.version = version; | |
948b1bb8 RR |
2569 | x86_pmu.num_counters = eax.split.num_counters; |
2570 | x86_pmu.cntval_bits = eax.split.bit_width; | |
2571 | x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1; | |
f22f54f4 | 2572 | |
c1d6f42f PZ |
2573 | x86_pmu.events_maskl = ebx.full; |
2574 | x86_pmu.events_mask_len = eax.split.mask_length; | |
2575 | ||
70ab7003 AK |
2576 | x86_pmu.max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, x86_pmu.num_counters); |
2577 | ||
f22f54f4 PZ |
2578 | /* |
2579 | * Quirk: v2 perfmon does not report fixed-purpose events, so | |
2580 | * assume at least 3 events: | |
2581 | */ | |
2582 | if (version > 1) | |
948b1bb8 | 2583 | x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3); |
f22f54f4 | 2584 | |
c9b08884 | 2585 | if (boot_cpu_has(X86_FEATURE_PDCM)) { |
8db909a7 PZ |
2586 | u64 capabilities; |
2587 | ||
2588 | rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities); | |
2589 | x86_pmu.intel_cap.capabilities = capabilities; | |
2590 | } | |
2591 | ||
ca037701 PZ |
2592 | intel_ds_init(); |
2593 | ||
c1d6f42f PZ |
2594 | x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */ |
2595 | ||
f22f54f4 PZ |
2596 | /* |
2597 | * Install the hw-cache-events table: | |
2598 | */ | |
2599 | switch (boot_cpu_data.x86_model) { | |
0f7c29ce | 2600 | case 14: /* 65nm Core "Yonah" */ |
f22f54f4 PZ |
2601 | pr_cont("Core events, "); |
2602 | break; | |
2603 | ||
0f7c29ce | 2604 | case 15: /* 65nm Core2 "Merom" */ |
c1d6f42f | 2605 | x86_add_quirk(intel_clovertown_quirk); |
0f7c29ce PZ |
2606 | case 22: /* 65nm Core2 "Merom-L" */ |
2607 | case 23: /* 45nm Core2 "Penryn" */ | |
2608 | case 29: /* 45nm Core2 "Dunnington (MP) */ | |
f22f54f4 PZ |
2609 | memcpy(hw_cache_event_ids, core2_hw_cache_event_ids, |
2610 | sizeof(hw_cache_event_ids)); | |
2611 | ||
caff2bef PZ |
2612 | intel_pmu_lbr_init_core(); |
2613 | ||
f22f54f4 | 2614 | x86_pmu.event_constraints = intel_core2_event_constraints; |
17e31629 | 2615 | x86_pmu.pebs_constraints = intel_core2_pebs_event_constraints; |
f22f54f4 PZ |
2616 | pr_cont("Core2 events, "); |
2617 | break; | |
2618 | ||
0f7c29ce PZ |
2619 | case 30: /* 45nm Nehalem */ |
2620 | case 26: /* 45nm Nehalem-EP */ | |
2621 | case 46: /* 45nm Nehalem-EX */ | |
f22f54f4 PZ |
2622 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, |
2623 | sizeof(hw_cache_event_ids)); | |
e994d7d2 AK |
2624 | memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs, |
2625 | sizeof(hw_cache_extra_regs)); | |
f22f54f4 | 2626 | |
caff2bef PZ |
2627 | intel_pmu_lbr_init_nhm(); |
2628 | ||
f22f54f4 | 2629 | x86_pmu.event_constraints = intel_nehalem_event_constraints; |
17e31629 | 2630 | x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints; |
11164cd4 | 2631 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
a7e3ed1e | 2632 | x86_pmu.extra_regs = intel_nehalem_extra_regs; |
ec75a716 | 2633 | |
f20093ee SE |
2634 | x86_pmu.cpu_events = nhm_events_attrs; |
2635 | ||
91fc4cc0 | 2636 | /* UOPS_ISSUED.STALLED_CYCLES */ |
f9b4eeb8 PZ |
2637 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = |
2638 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
91fc4cc0 | 2639 | /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */ |
f9b4eeb8 PZ |
2640 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = |
2641 | X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1); | |
94403f88 | 2642 | |
c1d6f42f | 2643 | x86_add_quirk(intel_nehalem_quirk); |
ec75a716 | 2644 | |
11164cd4 | 2645 | pr_cont("Nehalem events, "); |
f22f54f4 | 2646 | break; |
caff2bef | 2647 | |
0f7c29ce PZ |
2648 | case 28: /* 45nm Atom "Pineview" */ |
2649 | case 38: /* 45nm Atom "Lincroft" */ | |
2650 | case 39: /* 32nm Atom "Penwell" */ | |
2651 | case 53: /* 32nm Atom "Cloverview" */ | |
2652 | case 54: /* 32nm Atom "Cedarview" */ | |
f22f54f4 PZ |
2653 | memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, |
2654 | sizeof(hw_cache_event_ids)); | |
2655 | ||
caff2bef PZ |
2656 | intel_pmu_lbr_init_atom(); |
2657 | ||
f22f54f4 | 2658 | x86_pmu.event_constraints = intel_gen_event_constraints; |
17e31629 | 2659 | x86_pmu.pebs_constraints = intel_atom_pebs_event_constraints; |
f22f54f4 PZ |
2660 | pr_cont("Atom events, "); |
2661 | break; | |
2662 | ||
0f7c29ce | 2663 | case 55: /* 22nm Atom "Silvermont" */ |
ef454cae | 2664 | case 76: /* 14nm Atom "Airmont" */ |
0f7c29ce | 2665 | case 77: /* 22nm Atom "Silvermont Avoton/Rangely" */ |
1fa64180 YZ |
2666 | memcpy(hw_cache_event_ids, slm_hw_cache_event_ids, |
2667 | sizeof(hw_cache_event_ids)); | |
2668 | memcpy(hw_cache_extra_regs, slm_hw_cache_extra_regs, | |
2669 | sizeof(hw_cache_extra_regs)); | |
2670 | ||
2671 | intel_pmu_lbr_init_atom(); | |
2672 | ||
2673 | x86_pmu.event_constraints = intel_slm_event_constraints; | |
2674 | x86_pmu.pebs_constraints = intel_slm_pebs_event_constraints; | |
2675 | x86_pmu.extra_regs = intel_slm_extra_regs; | |
9a5e3fb5 | 2676 | x86_pmu.flags |= PMU_FL_HAS_RSP_1; |
1fa64180 YZ |
2677 | pr_cont("Silvermont events, "); |
2678 | break; | |
2679 | ||
0f7c29ce PZ |
2680 | case 37: /* 32nm Westmere */ |
2681 | case 44: /* 32nm Westmere-EP */ | |
2682 | case 47: /* 32nm Westmere-EX */ | |
f22f54f4 PZ |
2683 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, |
2684 | sizeof(hw_cache_event_ids)); | |
e994d7d2 AK |
2685 | memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs, |
2686 | sizeof(hw_cache_extra_regs)); | |
f22f54f4 | 2687 | |
caff2bef PZ |
2688 | intel_pmu_lbr_init_nhm(); |
2689 | ||
f22f54f4 | 2690 | x86_pmu.event_constraints = intel_westmere_event_constraints; |
40b91cd1 | 2691 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
17e31629 | 2692 | x86_pmu.pebs_constraints = intel_westmere_pebs_event_constraints; |
a7e3ed1e | 2693 | x86_pmu.extra_regs = intel_westmere_extra_regs; |
9a5e3fb5 | 2694 | x86_pmu.flags |= PMU_FL_HAS_RSP_1; |
30112039 | 2695 | |
f20093ee SE |
2696 | x86_pmu.cpu_events = nhm_events_attrs; |
2697 | ||
30112039 | 2698 | /* UOPS_ISSUED.STALLED_CYCLES */ |
f9b4eeb8 PZ |
2699 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = |
2700 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
30112039 | 2701 | /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */ |
f9b4eeb8 PZ |
2702 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = |
2703 | X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1); | |
30112039 | 2704 | |
f22f54f4 PZ |
2705 | pr_cont("Westmere events, "); |
2706 | break; | |
b622d644 | 2707 | |
0f7c29ce PZ |
2708 | case 42: /* 32nm SandyBridge */ |
2709 | case 45: /* 32nm SandyBridge-E/EN/EP */ | |
47a8863d | 2710 | x86_add_quirk(intel_sandybridge_quirk); |
b06b3d49 LM |
2711 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, |
2712 | sizeof(hw_cache_event_ids)); | |
74e6543f YZ |
2713 | memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs, |
2714 | sizeof(hw_cache_extra_regs)); | |
b06b3d49 | 2715 | |
c5cc2cd9 | 2716 | intel_pmu_lbr_init_snb(); |
b06b3d49 LM |
2717 | |
2718 | x86_pmu.event_constraints = intel_snb_event_constraints; | |
de0428a7 | 2719 | x86_pmu.pebs_constraints = intel_snb_pebs_event_constraints; |
0780c927 | 2720 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; |
f1923820 SE |
2721 | if (boot_cpu_data.x86_model == 45) |
2722 | x86_pmu.extra_regs = intel_snbep_extra_regs; | |
2723 | else | |
2724 | x86_pmu.extra_regs = intel_snb_extra_regs; | |
ee89cbc2 | 2725 | /* all extra regs are per-cpu when HT is on */ |
9a5e3fb5 SE |
2726 | x86_pmu.flags |= PMU_FL_HAS_RSP_1; |
2727 | x86_pmu.flags |= PMU_FL_NO_HT_SHARING; | |
e04d1b23 | 2728 | |
f20093ee SE |
2729 | x86_pmu.cpu_events = snb_events_attrs; |
2730 | ||
e04d1b23 | 2731 | /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */ |
f9b4eeb8 PZ |
2732 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = |
2733 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
e04d1b23 | 2734 | /* UOPS_DISPATCHED.THREAD,c=1,i=1 to count stall cycles*/ |
f9b4eeb8 PZ |
2735 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = |
2736 | X86_CONFIG(.event=0xb1, .umask=0x01, .inv=1, .cmask=1); | |
e04d1b23 | 2737 | |
b06b3d49 LM |
2738 | pr_cont("SandyBridge events, "); |
2739 | break; | |
0f7c29ce PZ |
2740 | |
2741 | case 58: /* 22nm IvyBridge */ | |
2742 | case 62: /* 22nm IvyBridge-EP/EX */ | |
20a36e39 SE |
2743 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, |
2744 | sizeof(hw_cache_event_ids)); | |
1996388e VW |
2745 | /* dTLB-load-misses on IVB is different than SNB */ |
2746 | hw_cache_event_ids[C(DTLB)][C(OP_READ)][C(RESULT_MISS)] = 0x8108; /* DTLB_LOAD_MISSES.DEMAND_LD_MISS_CAUSES_A_WALK */ | |
2747 | ||
20a36e39 SE |
2748 | memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs, |
2749 | sizeof(hw_cache_extra_regs)); | |
2750 | ||
2751 | intel_pmu_lbr_init_snb(); | |
2752 | ||
69943182 | 2753 | x86_pmu.event_constraints = intel_ivb_event_constraints; |
20a36e39 SE |
2754 | x86_pmu.pebs_constraints = intel_ivb_pebs_event_constraints; |
2755 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; | |
f1923820 SE |
2756 | if (boot_cpu_data.x86_model == 62) |
2757 | x86_pmu.extra_regs = intel_snbep_extra_regs; | |
2758 | else | |
2759 | x86_pmu.extra_regs = intel_snb_extra_regs; | |
20a36e39 | 2760 | /* all extra regs are per-cpu when HT is on */ |
9a5e3fb5 SE |
2761 | x86_pmu.flags |= PMU_FL_HAS_RSP_1; |
2762 | x86_pmu.flags |= PMU_FL_NO_HT_SHARING; | |
20a36e39 | 2763 | |
f20093ee SE |
2764 | x86_pmu.cpu_events = snb_events_attrs; |
2765 | ||
20a36e39 SE |
2766 | /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */ |
2767 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = | |
2768 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
2769 | ||
2770 | pr_cont("IvyBridge events, "); | |
2771 | break; | |
2772 | ||
b06b3d49 | 2773 | |
d86c8eaf AK |
2774 | case 60: /* 22nm Haswell Core */ |
2775 | case 63: /* 22nm Haswell Server */ | |
2776 | case 69: /* 22nm Haswell ULT */ | |
2777 | case 70: /* 22nm Haswell + GT3e (Intel Iris Pro graphics) */ | |
72db5596 | 2778 | x86_pmu.late_ack = true; |
0f1b5ca2 AK |
2779 | memcpy(hw_cache_event_ids, hsw_hw_cache_event_ids, sizeof(hw_cache_event_ids)); |
2780 | memcpy(hw_cache_extra_regs, hsw_hw_cache_extra_regs, sizeof(hw_cache_extra_regs)); | |
3a632cb2 | 2781 | |
e9d7f7cd | 2782 | intel_pmu_lbr_init_hsw(); |
3a632cb2 AK |
2783 | |
2784 | x86_pmu.event_constraints = intel_hsw_event_constraints; | |
3044318f | 2785 | x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints; |
36bbb2f2 | 2786 | x86_pmu.extra_regs = intel_snbep_extra_regs; |
3044318f | 2787 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; |
3a632cb2 | 2788 | /* all extra regs are per-cpu when HT is on */ |
9a5e3fb5 SE |
2789 | x86_pmu.flags |= PMU_FL_HAS_RSP_1; |
2790 | x86_pmu.flags |= PMU_FL_NO_HT_SHARING; | |
3a632cb2 AK |
2791 | |
2792 | x86_pmu.hw_config = hsw_hw_config; | |
2793 | x86_pmu.get_event_constraints = hsw_get_event_constraints; | |
f9134f36 | 2794 | x86_pmu.cpu_events = hsw_events_attrs; |
b7af41a1 | 2795 | x86_pmu.lbr_double_abort = true; |
3a632cb2 AK |
2796 | pr_cont("Haswell events, "); |
2797 | break; | |
2798 | ||
91f1b705 AK |
2799 | case 61: /* 14nm Broadwell Core-M */ |
2800 | case 86: /* 14nm Broadwell Xeon D */ | |
2801 | x86_pmu.late_ack = true; | |
2802 | memcpy(hw_cache_event_ids, hsw_hw_cache_event_ids, sizeof(hw_cache_event_ids)); | |
2803 | memcpy(hw_cache_extra_regs, hsw_hw_cache_extra_regs, sizeof(hw_cache_extra_regs)); | |
2804 | ||
2805 | /* L3_MISS_LOCAL_DRAM is BIT(26) in Broadwell */ | |
2806 | hw_cache_extra_regs[C(LL)][C(OP_READ)][C(RESULT_MISS)] = HSW_DEMAND_READ | | |
2807 | BDW_L3_MISS|HSW_SNOOP_DRAM; | |
2808 | hw_cache_extra_regs[C(LL)][C(OP_WRITE)][C(RESULT_MISS)] = HSW_DEMAND_WRITE|BDW_L3_MISS| | |
2809 | HSW_SNOOP_DRAM; | |
2810 | hw_cache_extra_regs[C(NODE)][C(OP_READ)][C(RESULT_ACCESS)] = HSW_DEMAND_READ| | |
2811 | BDW_L3_MISS_LOCAL|HSW_SNOOP_DRAM; | |
2812 | hw_cache_extra_regs[C(NODE)][C(OP_WRITE)][C(RESULT_ACCESS)] = HSW_DEMAND_WRITE| | |
2813 | BDW_L3_MISS_LOCAL|HSW_SNOOP_DRAM; | |
2814 | ||
2815 | intel_pmu_lbr_init_snb(); | |
2816 | ||
2817 | x86_pmu.event_constraints = intel_bdw_event_constraints; | |
2818 | x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints; | |
2819 | x86_pmu.extra_regs = intel_snbep_extra_regs; | |
2820 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; | |
2821 | /* all extra regs are per-cpu when HT is on */ | |
9a5e3fb5 SE |
2822 | x86_pmu.flags |= PMU_FL_HAS_RSP_1; |
2823 | x86_pmu.flags |= PMU_FL_NO_HT_SHARING; | |
91f1b705 AK |
2824 | |
2825 | x86_pmu.hw_config = hsw_hw_config; | |
2826 | x86_pmu.get_event_constraints = hsw_get_event_constraints; | |
2827 | x86_pmu.cpu_events = hsw_events_attrs; | |
294fe0f5 | 2828 | x86_pmu.limit_period = bdw_limit_period; |
91f1b705 AK |
2829 | pr_cont("Broadwell events, "); |
2830 | break; | |
2831 | ||
f22f54f4 | 2832 | default: |
0af3ac1f AK |
2833 | switch (x86_pmu.version) { |
2834 | case 1: | |
2835 | x86_pmu.event_constraints = intel_v1_event_constraints; | |
2836 | pr_cont("generic architected perfmon v1, "); | |
2837 | break; | |
2838 | default: | |
2839 | /* | |
2840 | * default constraints for v2 and up | |
2841 | */ | |
2842 | x86_pmu.event_constraints = intel_gen_event_constraints; | |
2843 | pr_cont("generic architected perfmon, "); | |
2844 | break; | |
2845 | } | |
f22f54f4 | 2846 | } |
ffb871bc | 2847 | |
a1eac7ac RR |
2848 | if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) { |
2849 | WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", | |
2850 | x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC); | |
2851 | x86_pmu.num_counters = INTEL_PMC_MAX_GENERIC; | |
2852 | } | |
2853 | x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1; | |
2854 | ||
2855 | if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED) { | |
2856 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", | |
2857 | x86_pmu.num_counters_fixed, INTEL_PMC_MAX_FIXED); | |
2858 | x86_pmu.num_counters_fixed = INTEL_PMC_MAX_FIXED; | |
2859 | } | |
2860 | ||
2861 | x86_pmu.intel_ctrl |= | |
2862 | ((1LL << x86_pmu.num_counters_fixed)-1) << INTEL_PMC_IDX_FIXED; | |
2863 | ||
2864 | if (x86_pmu.event_constraints) { | |
2865 | /* | |
2866 | * event on fixed counter2 (REF_CYCLES) only works on this | |
2867 | * counter, so do not extend mask to generic counters | |
2868 | */ | |
2869 | for_each_event_constraint(c, x86_pmu.event_constraints) { | |
3a632cb2 | 2870 | if (c->cmask != FIXED_EVENT_FLAGS |
a1eac7ac RR |
2871 | || c->idxmsk64 == INTEL_PMC_MSK_FIXED_REF_CYCLES) { |
2872 | continue; | |
2873 | } | |
2874 | ||
2875 | c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1; | |
2876 | c->weight += x86_pmu.num_counters; | |
2877 | } | |
2878 | } | |
2879 | ||
338b522c KL |
2880 | /* |
2881 | * Access LBR MSR may cause #GP under certain circumstances. | |
2882 | * E.g. KVM doesn't support LBR MSR | |
2883 | * Check all LBT MSR here. | |
2884 | * Disable LBR access if any LBR MSRs can not be accessed. | |
2885 | */ | |
2886 | if (x86_pmu.lbr_nr && !check_msr(x86_pmu.lbr_tos, 0x3UL)) | |
2887 | x86_pmu.lbr_nr = 0; | |
2888 | for (i = 0; i < x86_pmu.lbr_nr; i++) { | |
2889 | if (!(check_msr(x86_pmu.lbr_from + i, 0xffffUL) && | |
2890 | check_msr(x86_pmu.lbr_to + i, 0xffffUL))) | |
2891 | x86_pmu.lbr_nr = 0; | |
2892 | } | |
2893 | ||
2894 | /* | |
2895 | * Access extra MSR may cause #GP under certain circumstances. | |
2896 | * E.g. KVM doesn't support offcore event | |
2897 | * Check all extra_regs here. | |
2898 | */ | |
2899 | if (x86_pmu.extra_regs) { | |
2900 | for (er = x86_pmu.extra_regs; er->msr; er++) { | |
2901 | er->extra_msr_access = check_msr(er->msr, 0x1ffUL); | |
2902 | /* Disable LBR select mapping */ | |
2903 | if ((er->idx == EXTRA_REG_LBR) && !er->extra_msr_access) | |
2904 | x86_pmu.lbr_sel_map = NULL; | |
2905 | } | |
2906 | } | |
2907 | ||
069e0c3c AK |
2908 | /* Support full width counters using alternative MSR range */ |
2909 | if (x86_pmu.intel_cap.full_width_write) { | |
2910 | x86_pmu.max_period = x86_pmu.cntval_mask; | |
2911 | x86_pmu.perfctr = MSR_IA32_PMC0; | |
2912 | pr_cont("full-width counters, "); | |
2913 | } | |
2914 | ||
f22f54f4 PZ |
2915 | return 0; |
2916 | } |