]>
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 */ | |
127 | INTEL_UEVENT_CONSTRAINT(0x04a3, 0xf), /* CYCLE_ACTIVITY.CYCLES_NO_EXECUTE */ | |
128 | INTEL_UEVENT_CONSTRAINT(0x05a3, 0xf), /* CYCLE_ACTIVITY.STALLS_L2_PENDING */ | |
129 | INTEL_UEVENT_CONSTRAINT(0x06a3, 0xf), /* CYCLE_ACTIVITY.STALLS_LDM_PENDING */ | |
130 | INTEL_UEVENT_CONSTRAINT(0x08a3, 0x4), /* CYCLE_ACTIVITY.CYCLES_L1D_PENDING */ | |
131 | INTEL_UEVENT_CONSTRAINT(0x0ca3, 0x4), /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */ | |
132 | INTEL_UEVENT_CONSTRAINT(0x01c0, 0x2), /* INST_RETIRED.PREC_DIST */ | |
741a698f PZ |
133 | /* |
134 | * Errata BV98 -- MEM_*_RETIRED events can leak between counters of SMT | |
135 | * siblings; disable these events because they can corrupt unrelated | |
136 | * counters. | |
137 | */ | |
138 | INTEL_EVENT_CONSTRAINT(0xd0, 0x0), /* MEM_UOPS_RETIRED.* */ | |
139 | INTEL_EVENT_CONSTRAINT(0xd1, 0x0), /* MEM_LOAD_UOPS_RETIRED.* */ | |
140 | INTEL_EVENT_CONSTRAINT(0xd2, 0x0), /* MEM_LOAD_UOPS_LLC_HIT_RETIRED.* */ | |
141 | INTEL_EVENT_CONSTRAINT(0xd3, 0x0), /* MEM_LOAD_UOPS_LLC_MISS_RETIRED.* */ | |
69943182 SE |
142 | EVENT_CONSTRAINT_END |
143 | }; | |
144 | ||
5c543e3c | 145 | static struct extra_reg intel_westmere_extra_regs[] __read_mostly = |
a7e3ed1e | 146 | { |
53ad0447 YZ |
147 | /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ |
148 | INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0xffff, RSP_0), | |
149 | INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0xffff, RSP_1), | |
f20093ee | 150 | INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x100b), |
a7e3ed1e AK |
151 | EVENT_EXTRA_END |
152 | }; | |
153 | ||
0af3ac1f AK |
154 | static struct event_constraint intel_v1_event_constraints[] __read_mostly = |
155 | { | |
156 | EVENT_CONSTRAINT_END | |
157 | }; | |
158 | ||
5c543e3c | 159 | static struct event_constraint intel_gen_event_constraints[] __read_mostly = |
f22f54f4 | 160 | { |
b622d644 PZ |
161 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ |
162 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
cd09c0c4 | 163 | FIXED_EVENT_CONSTRAINT(0x0300, 2), /* CPU_CLK_UNHALTED.REF */ |
f22f54f4 PZ |
164 | EVENT_CONSTRAINT_END |
165 | }; | |
166 | ||
1fa64180 YZ |
167 | static struct event_constraint intel_slm_event_constraints[] __read_mostly = |
168 | { | |
169 | FIXED_EVENT_CONSTRAINT(0x00c0, 0), /* INST_RETIRED.ANY */ | |
170 | FIXED_EVENT_CONSTRAINT(0x003c, 1), /* CPU_CLK_UNHALTED.CORE */ | |
171 | FIXED_EVENT_CONSTRAINT(0x013c, 2), /* CPU_CLK_UNHALTED.REF */ | |
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 | ||
f20093ee SE |
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"); | |
9ad64c0f | 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 */ | |
215 | INTEL_EVENT_CONSTRAINT(0x08a3, 0x4), | |
216 | /* CYCLE_ACTIVITY.STALLS_L1D_PENDING */ | |
217 | INTEL_EVENT_CONSTRAINT(0x0ca3, 0x4), | |
218 | /* CYCLE_ACTIVITY.CYCLES_NO_EXECUTE */ | |
219 | INTEL_EVENT_CONSTRAINT(0x04a3, 0xf), | |
220 | EVENT_CONSTRAINT_END | |
221 | }; | |
222 | ||
f22f54f4 PZ |
223 | static u64 intel_pmu_event_map(int hw_event) |
224 | { | |
225 | return intel_perfmon_event_map[hw_event]; | |
226 | } | |
227 | ||
74e6543f YZ |
228 | #define SNB_DMND_DATA_RD (1ULL << 0) |
229 | #define SNB_DMND_RFO (1ULL << 1) | |
230 | #define SNB_DMND_IFETCH (1ULL << 2) | |
231 | #define SNB_DMND_WB (1ULL << 3) | |
232 | #define SNB_PF_DATA_RD (1ULL << 4) | |
233 | #define SNB_PF_RFO (1ULL << 5) | |
234 | #define SNB_PF_IFETCH (1ULL << 6) | |
235 | #define SNB_LLC_DATA_RD (1ULL << 7) | |
236 | #define SNB_LLC_RFO (1ULL << 8) | |
237 | #define SNB_LLC_IFETCH (1ULL << 9) | |
238 | #define SNB_BUS_LOCKS (1ULL << 10) | |
239 | #define SNB_STRM_ST (1ULL << 11) | |
240 | #define SNB_OTHER (1ULL << 15) | |
241 | #define SNB_RESP_ANY (1ULL << 16) | |
242 | #define SNB_NO_SUPP (1ULL << 17) | |
243 | #define SNB_LLC_HITM (1ULL << 18) | |
244 | #define SNB_LLC_HITE (1ULL << 19) | |
245 | #define SNB_LLC_HITS (1ULL << 20) | |
246 | #define SNB_LLC_HITF (1ULL << 21) | |
247 | #define SNB_LOCAL (1ULL << 22) | |
248 | #define SNB_REMOTE (0xffULL << 23) | |
249 | #define SNB_SNP_NONE (1ULL << 31) | |
250 | #define SNB_SNP_NOT_NEEDED (1ULL << 32) | |
251 | #define SNB_SNP_MISS (1ULL << 33) | |
252 | #define SNB_NO_FWD (1ULL << 34) | |
253 | #define SNB_SNP_FWD (1ULL << 35) | |
254 | #define SNB_HITM (1ULL << 36) | |
255 | #define SNB_NON_DRAM (1ULL << 37) | |
256 | ||
257 | #define SNB_DMND_READ (SNB_DMND_DATA_RD|SNB_LLC_DATA_RD) | |
258 | #define SNB_DMND_WRITE (SNB_DMND_RFO|SNB_LLC_RFO) | |
259 | #define SNB_DMND_PREFETCH (SNB_PF_DATA_RD|SNB_PF_RFO) | |
260 | ||
261 | #define SNB_SNP_ANY (SNB_SNP_NONE|SNB_SNP_NOT_NEEDED| \ | |
262 | SNB_SNP_MISS|SNB_NO_FWD|SNB_SNP_FWD| \ | |
263 | SNB_HITM) | |
264 | ||
265 | #define SNB_DRAM_ANY (SNB_LOCAL|SNB_REMOTE|SNB_SNP_ANY) | |
266 | #define SNB_DRAM_REMOTE (SNB_REMOTE|SNB_SNP_ANY) | |
267 | ||
268 | #define SNB_L3_ACCESS SNB_RESP_ANY | |
269 | #define SNB_L3_MISS (SNB_DRAM_ANY|SNB_NON_DRAM) | |
270 | ||
271 | static __initconst const u64 snb_hw_cache_extra_regs | |
272 | [PERF_COUNT_HW_CACHE_MAX] | |
273 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
274 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
275 | { | |
276 | [ C(LL ) ] = { | |
277 | [ C(OP_READ) ] = { | |
278 | [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_L3_ACCESS, | |
279 | [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_L3_MISS, | |
280 | }, | |
281 | [ C(OP_WRITE) ] = { | |
282 | [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_L3_ACCESS, | |
283 | [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_L3_MISS, | |
284 | }, | |
285 | [ C(OP_PREFETCH) ] = { | |
286 | [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_L3_ACCESS, | |
287 | [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_L3_MISS, | |
288 | }, | |
289 | }, | |
290 | [ C(NODE) ] = { | |
291 | [ C(OP_READ) ] = { | |
292 | [ C(RESULT_ACCESS) ] = SNB_DMND_READ|SNB_DRAM_ANY, | |
293 | [ C(RESULT_MISS) ] = SNB_DMND_READ|SNB_DRAM_REMOTE, | |
294 | }, | |
295 | [ C(OP_WRITE) ] = { | |
296 | [ C(RESULT_ACCESS) ] = SNB_DMND_WRITE|SNB_DRAM_ANY, | |
297 | [ C(RESULT_MISS) ] = SNB_DMND_WRITE|SNB_DRAM_REMOTE, | |
298 | }, | |
299 | [ C(OP_PREFETCH) ] = { | |
300 | [ C(RESULT_ACCESS) ] = SNB_DMND_PREFETCH|SNB_DRAM_ANY, | |
301 | [ C(RESULT_MISS) ] = SNB_DMND_PREFETCH|SNB_DRAM_REMOTE, | |
302 | }, | |
303 | }, | |
304 | }; | |
305 | ||
b06b3d49 LM |
306 | static __initconst const u64 snb_hw_cache_event_ids |
307 | [PERF_COUNT_HW_CACHE_MAX] | |
308 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
309 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
310 | { | |
311 | [ C(L1D) ] = { | |
312 | [ C(OP_READ) ] = { | |
313 | [ C(RESULT_ACCESS) ] = 0xf1d0, /* MEM_UOP_RETIRED.LOADS */ | |
314 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPLACEMENT */ | |
315 | }, | |
316 | [ C(OP_WRITE) ] = { | |
317 | [ C(RESULT_ACCESS) ] = 0xf2d0, /* MEM_UOP_RETIRED.STORES */ | |
318 | [ C(RESULT_MISS) ] = 0x0851, /* L1D.ALL_M_REPLACEMENT */ | |
319 | }, | |
320 | [ C(OP_PREFETCH) ] = { | |
321 | [ C(RESULT_ACCESS) ] = 0x0, | |
322 | [ C(RESULT_MISS) ] = 0x024e, /* HW_PRE_REQ.DL1_MISS */ | |
323 | }, | |
324 | }, | |
325 | [ C(L1I ) ] = { | |
326 | [ C(OP_READ) ] = { | |
327 | [ C(RESULT_ACCESS) ] = 0x0, | |
328 | [ C(RESULT_MISS) ] = 0x0280, /* ICACHE.MISSES */ | |
329 | }, | |
330 | [ C(OP_WRITE) ] = { | |
331 | [ C(RESULT_ACCESS) ] = -1, | |
332 | [ C(RESULT_MISS) ] = -1, | |
333 | }, | |
334 | [ C(OP_PREFETCH) ] = { | |
335 | [ C(RESULT_ACCESS) ] = 0x0, | |
336 | [ C(RESULT_MISS) ] = 0x0, | |
337 | }, | |
338 | }, | |
339 | [ C(LL ) ] = { | |
b06b3d49 | 340 | [ C(OP_READ) ] = { |
63b6a675 | 341 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
b06b3d49 | 342 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
343 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ |
344 | [ C(RESULT_MISS) ] = 0x01b7, | |
b06b3d49 LM |
345 | }, |
346 | [ C(OP_WRITE) ] = { | |
63b6a675 | 347 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
b06b3d49 | 348 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
349 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ |
350 | [ C(RESULT_MISS) ] = 0x01b7, | |
b06b3d49 LM |
351 | }, |
352 | [ C(OP_PREFETCH) ] = { | |
63b6a675 | 353 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
b06b3d49 | 354 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
355 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ |
356 | [ C(RESULT_MISS) ] = 0x01b7, | |
b06b3d49 LM |
357 | }, |
358 | }, | |
359 | [ C(DTLB) ] = { | |
360 | [ C(OP_READ) ] = { | |
361 | [ C(RESULT_ACCESS) ] = 0x81d0, /* MEM_UOP_RETIRED.ALL_LOADS */ | |
362 | [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.CAUSES_A_WALK */ | |
363 | }, | |
364 | [ C(OP_WRITE) ] = { | |
365 | [ C(RESULT_ACCESS) ] = 0x82d0, /* MEM_UOP_RETIRED.ALL_STORES */ | |
366 | [ C(RESULT_MISS) ] = 0x0149, /* DTLB_STORE_MISSES.MISS_CAUSES_A_WALK */ | |
367 | }, | |
368 | [ C(OP_PREFETCH) ] = { | |
369 | [ C(RESULT_ACCESS) ] = 0x0, | |
370 | [ C(RESULT_MISS) ] = 0x0, | |
371 | }, | |
372 | }, | |
373 | [ C(ITLB) ] = { | |
374 | [ C(OP_READ) ] = { | |
375 | [ C(RESULT_ACCESS) ] = 0x1085, /* ITLB_MISSES.STLB_HIT */ | |
376 | [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.CAUSES_A_WALK */ | |
377 | }, | |
378 | [ C(OP_WRITE) ] = { | |
379 | [ C(RESULT_ACCESS) ] = -1, | |
380 | [ C(RESULT_MISS) ] = -1, | |
381 | }, | |
382 | [ C(OP_PREFETCH) ] = { | |
383 | [ C(RESULT_ACCESS) ] = -1, | |
384 | [ C(RESULT_MISS) ] = -1, | |
385 | }, | |
386 | }, | |
387 | [ C(BPU ) ] = { | |
388 | [ C(OP_READ) ] = { | |
389 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */ | |
390 | [ C(RESULT_MISS) ] = 0x00c5, /* BR_MISP_RETIRED.ALL_BRANCHES */ | |
391 | }, | |
392 | [ C(OP_WRITE) ] = { | |
393 | [ C(RESULT_ACCESS) ] = -1, | |
394 | [ C(RESULT_MISS) ] = -1, | |
395 | }, | |
396 | [ C(OP_PREFETCH) ] = { | |
397 | [ C(RESULT_ACCESS) ] = -1, | |
398 | [ C(RESULT_MISS) ] = -1, | |
399 | }, | |
400 | }, | |
89d6c0b5 PZ |
401 | [ C(NODE) ] = { |
402 | [ C(OP_READ) ] = { | |
74e6543f YZ |
403 | [ C(RESULT_ACCESS) ] = 0x01b7, |
404 | [ C(RESULT_MISS) ] = 0x01b7, | |
89d6c0b5 PZ |
405 | }, |
406 | [ C(OP_WRITE) ] = { | |
74e6543f YZ |
407 | [ C(RESULT_ACCESS) ] = 0x01b7, |
408 | [ C(RESULT_MISS) ] = 0x01b7, | |
89d6c0b5 PZ |
409 | }, |
410 | [ C(OP_PREFETCH) ] = { | |
74e6543f YZ |
411 | [ C(RESULT_ACCESS) ] = 0x01b7, |
412 | [ C(RESULT_MISS) ] = 0x01b7, | |
89d6c0b5 PZ |
413 | }, |
414 | }, | |
415 | ||
b06b3d49 LM |
416 | }; |
417 | ||
caaa8be3 | 418 | static __initconst const u64 westmere_hw_cache_event_ids |
f22f54f4 PZ |
419 | [PERF_COUNT_HW_CACHE_MAX] |
420 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
421 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
422 | { | |
423 | [ C(L1D) ] = { | |
424 | [ C(OP_READ) ] = { | |
425 | [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */ | |
426 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */ | |
427 | }, | |
428 | [ C(OP_WRITE) ] = { | |
429 | [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */ | |
430 | [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */ | |
431 | }, | |
432 | [ C(OP_PREFETCH) ] = { | |
433 | [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */ | |
434 | [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */ | |
435 | }, | |
436 | }, | |
437 | [ C(L1I ) ] = { | |
438 | [ C(OP_READ) ] = { | |
439 | [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */ | |
440 | [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */ | |
441 | }, | |
442 | [ C(OP_WRITE) ] = { | |
443 | [ C(RESULT_ACCESS) ] = -1, | |
444 | [ C(RESULT_MISS) ] = -1, | |
445 | }, | |
446 | [ C(OP_PREFETCH) ] = { | |
447 | [ C(RESULT_ACCESS) ] = 0x0, | |
448 | [ C(RESULT_MISS) ] = 0x0, | |
449 | }, | |
450 | }, | |
451 | [ C(LL ) ] = { | |
452 | [ C(OP_READ) ] = { | |
63b6a675 | 453 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
e994d7d2 | 454 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
455 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ |
456 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 | 457 | }, |
e994d7d2 AK |
458 | /* |
459 | * Use RFO, not WRITEBACK, because a write miss would typically occur | |
460 | * on RFO. | |
461 | */ | |
f22f54f4 | 462 | [ C(OP_WRITE) ] = { |
63b6a675 PZ |
463 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
464 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
465 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | |
e994d7d2 | 466 | [ C(RESULT_MISS) ] = 0x01b7, |
f22f54f4 PZ |
467 | }, |
468 | [ C(OP_PREFETCH) ] = { | |
63b6a675 | 469 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
e994d7d2 | 470 | [ C(RESULT_ACCESS) ] = 0x01b7, |
63b6a675 PZ |
471 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ |
472 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 PZ |
473 | }, |
474 | }, | |
475 | [ C(DTLB) ] = { | |
476 | [ C(OP_READ) ] = { | |
477 | [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */ | |
478 | [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */ | |
479 | }, | |
480 | [ C(OP_WRITE) ] = { | |
481 | [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */ | |
482 | [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */ | |
483 | }, | |
484 | [ C(OP_PREFETCH) ] = { | |
485 | [ C(RESULT_ACCESS) ] = 0x0, | |
486 | [ C(RESULT_MISS) ] = 0x0, | |
487 | }, | |
488 | }, | |
489 | [ C(ITLB) ] = { | |
490 | [ C(OP_READ) ] = { | |
491 | [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */ | |
492 | [ C(RESULT_MISS) ] = 0x0185, /* ITLB_MISSES.ANY */ | |
493 | }, | |
494 | [ C(OP_WRITE) ] = { | |
495 | [ C(RESULT_ACCESS) ] = -1, | |
496 | [ C(RESULT_MISS) ] = -1, | |
497 | }, | |
498 | [ C(OP_PREFETCH) ] = { | |
499 | [ C(RESULT_ACCESS) ] = -1, | |
500 | [ C(RESULT_MISS) ] = -1, | |
501 | }, | |
502 | }, | |
503 | [ C(BPU ) ] = { | |
504 | [ C(OP_READ) ] = { | |
505 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */ | |
506 | [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */ | |
507 | }, | |
508 | [ C(OP_WRITE) ] = { | |
509 | [ C(RESULT_ACCESS) ] = -1, | |
510 | [ C(RESULT_MISS) ] = -1, | |
511 | }, | |
512 | [ C(OP_PREFETCH) ] = { | |
513 | [ C(RESULT_ACCESS) ] = -1, | |
514 | [ C(RESULT_MISS) ] = -1, | |
515 | }, | |
516 | }, | |
89d6c0b5 PZ |
517 | [ C(NODE) ] = { |
518 | [ C(OP_READ) ] = { | |
519 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
520 | [ C(RESULT_MISS) ] = 0x01b7, | |
521 | }, | |
522 | [ C(OP_WRITE) ] = { | |
523 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
524 | [ C(RESULT_MISS) ] = 0x01b7, | |
525 | }, | |
526 | [ C(OP_PREFETCH) ] = { | |
527 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
528 | [ C(RESULT_MISS) ] = 0x01b7, | |
529 | }, | |
530 | }, | |
f22f54f4 PZ |
531 | }; |
532 | ||
e994d7d2 | 533 | /* |
63b6a675 PZ |
534 | * Nehalem/Westmere MSR_OFFCORE_RESPONSE bits; |
535 | * See IA32 SDM Vol 3B 30.6.1.3 | |
e994d7d2 AK |
536 | */ |
537 | ||
63b6a675 PZ |
538 | #define NHM_DMND_DATA_RD (1 << 0) |
539 | #define NHM_DMND_RFO (1 << 1) | |
540 | #define NHM_DMND_IFETCH (1 << 2) | |
541 | #define NHM_DMND_WB (1 << 3) | |
542 | #define NHM_PF_DATA_RD (1 << 4) | |
543 | #define NHM_PF_DATA_RFO (1 << 5) | |
544 | #define NHM_PF_IFETCH (1 << 6) | |
545 | #define NHM_OFFCORE_OTHER (1 << 7) | |
546 | #define NHM_UNCORE_HIT (1 << 8) | |
547 | #define NHM_OTHER_CORE_HIT_SNP (1 << 9) | |
548 | #define NHM_OTHER_CORE_HITM (1 << 10) | |
549 | /* reserved */ | |
550 | #define NHM_REMOTE_CACHE_FWD (1 << 12) | |
551 | #define NHM_REMOTE_DRAM (1 << 13) | |
552 | #define NHM_LOCAL_DRAM (1 << 14) | |
553 | #define NHM_NON_DRAM (1 << 15) | |
554 | ||
87e24f4b PZ |
555 | #define NHM_LOCAL (NHM_LOCAL_DRAM|NHM_REMOTE_CACHE_FWD) |
556 | #define NHM_REMOTE (NHM_REMOTE_DRAM) | |
63b6a675 PZ |
557 | |
558 | #define NHM_DMND_READ (NHM_DMND_DATA_RD) | |
559 | #define NHM_DMND_WRITE (NHM_DMND_RFO|NHM_DMND_WB) | |
560 | #define NHM_DMND_PREFETCH (NHM_PF_DATA_RD|NHM_PF_DATA_RFO) | |
561 | ||
562 | #define NHM_L3_HIT (NHM_UNCORE_HIT|NHM_OTHER_CORE_HIT_SNP|NHM_OTHER_CORE_HITM) | |
87e24f4b | 563 | #define NHM_L3_MISS (NHM_NON_DRAM|NHM_LOCAL_DRAM|NHM_REMOTE_DRAM|NHM_REMOTE_CACHE_FWD) |
63b6a675 | 564 | #define NHM_L3_ACCESS (NHM_L3_HIT|NHM_L3_MISS) |
e994d7d2 AK |
565 | |
566 | static __initconst const u64 nehalem_hw_cache_extra_regs | |
567 | [PERF_COUNT_HW_CACHE_MAX] | |
568 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
569 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
570 | { | |
571 | [ C(LL ) ] = { | |
572 | [ C(OP_READ) ] = { | |
63b6a675 PZ |
573 | [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_L3_ACCESS, |
574 | [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_L3_MISS, | |
e994d7d2 AK |
575 | }, |
576 | [ C(OP_WRITE) ] = { | |
63b6a675 PZ |
577 | [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_L3_ACCESS, |
578 | [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_L3_MISS, | |
e994d7d2 AK |
579 | }, |
580 | [ C(OP_PREFETCH) ] = { | |
63b6a675 PZ |
581 | [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_L3_ACCESS, |
582 | [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_L3_MISS, | |
e994d7d2 | 583 | }, |
89d6c0b5 PZ |
584 | }, |
585 | [ C(NODE) ] = { | |
586 | [ C(OP_READ) ] = { | |
87e24f4b PZ |
587 | [ C(RESULT_ACCESS) ] = NHM_DMND_READ|NHM_LOCAL|NHM_REMOTE, |
588 | [ C(RESULT_MISS) ] = NHM_DMND_READ|NHM_REMOTE, | |
89d6c0b5 PZ |
589 | }, |
590 | [ C(OP_WRITE) ] = { | |
87e24f4b PZ |
591 | [ C(RESULT_ACCESS) ] = NHM_DMND_WRITE|NHM_LOCAL|NHM_REMOTE, |
592 | [ C(RESULT_MISS) ] = NHM_DMND_WRITE|NHM_REMOTE, | |
89d6c0b5 PZ |
593 | }, |
594 | [ C(OP_PREFETCH) ] = { | |
87e24f4b PZ |
595 | [ C(RESULT_ACCESS) ] = NHM_DMND_PREFETCH|NHM_LOCAL|NHM_REMOTE, |
596 | [ C(RESULT_MISS) ] = NHM_DMND_PREFETCH|NHM_REMOTE, | |
89d6c0b5 PZ |
597 | }, |
598 | }, | |
e994d7d2 AK |
599 | }; |
600 | ||
caaa8be3 | 601 | static __initconst const u64 nehalem_hw_cache_event_ids |
f22f54f4 PZ |
602 | [PERF_COUNT_HW_CACHE_MAX] |
603 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
604 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
605 | { | |
606 | [ C(L1D) ] = { | |
607 | [ C(OP_READ) ] = { | |
f4929bd3 PZ |
608 | [ C(RESULT_ACCESS) ] = 0x010b, /* MEM_INST_RETIRED.LOADS */ |
609 | [ C(RESULT_MISS) ] = 0x0151, /* L1D.REPL */ | |
f22f54f4 PZ |
610 | }, |
611 | [ C(OP_WRITE) ] = { | |
f4929bd3 PZ |
612 | [ C(RESULT_ACCESS) ] = 0x020b, /* MEM_INST_RETURED.STORES */ |
613 | [ C(RESULT_MISS) ] = 0x0251, /* L1D.M_REPL */ | |
f22f54f4 PZ |
614 | }, |
615 | [ C(OP_PREFETCH) ] = { | |
616 | [ C(RESULT_ACCESS) ] = 0x014e, /* L1D_PREFETCH.REQUESTS */ | |
617 | [ C(RESULT_MISS) ] = 0x024e, /* L1D_PREFETCH.MISS */ | |
618 | }, | |
619 | }, | |
620 | [ C(L1I ) ] = { | |
621 | [ C(OP_READ) ] = { | |
622 | [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */ | |
623 | [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */ | |
624 | }, | |
625 | [ C(OP_WRITE) ] = { | |
626 | [ C(RESULT_ACCESS) ] = -1, | |
627 | [ C(RESULT_MISS) ] = -1, | |
628 | }, | |
629 | [ C(OP_PREFETCH) ] = { | |
630 | [ C(RESULT_ACCESS) ] = 0x0, | |
631 | [ C(RESULT_MISS) ] = 0x0, | |
632 | }, | |
633 | }, | |
634 | [ C(LL ) ] = { | |
635 | [ C(OP_READ) ] = { | |
e994d7d2 AK |
636 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ |
637 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
638 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ | |
639 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 | 640 | }, |
e994d7d2 AK |
641 | /* |
642 | * Use RFO, not WRITEBACK, because a write miss would typically occur | |
643 | * on RFO. | |
644 | */ | |
f22f54f4 | 645 | [ C(OP_WRITE) ] = { |
e994d7d2 AK |
646 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ |
647 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
648 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | |
649 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 PZ |
650 | }, |
651 | [ C(OP_PREFETCH) ] = { | |
e994d7d2 AK |
652 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ |
653 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
654 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ | |
655 | [ C(RESULT_MISS) ] = 0x01b7, | |
f22f54f4 PZ |
656 | }, |
657 | }, | |
658 | [ C(DTLB) ] = { | |
659 | [ C(OP_READ) ] = { | |
660 | [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */ | |
661 | [ C(RESULT_MISS) ] = 0x0108, /* DTLB_LOAD_MISSES.ANY */ | |
662 | }, | |
663 | [ C(OP_WRITE) ] = { | |
664 | [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */ | |
665 | [ C(RESULT_MISS) ] = 0x010c, /* MEM_STORE_RETIRED.DTLB_MISS */ | |
666 | }, | |
667 | [ C(OP_PREFETCH) ] = { | |
668 | [ C(RESULT_ACCESS) ] = 0x0, | |
669 | [ C(RESULT_MISS) ] = 0x0, | |
670 | }, | |
671 | }, | |
672 | [ C(ITLB) ] = { | |
673 | [ C(OP_READ) ] = { | |
674 | [ C(RESULT_ACCESS) ] = 0x01c0, /* INST_RETIRED.ANY_P */ | |
675 | [ C(RESULT_MISS) ] = 0x20c8, /* ITLB_MISS_RETIRED */ | |
676 | }, | |
677 | [ C(OP_WRITE) ] = { | |
678 | [ C(RESULT_ACCESS) ] = -1, | |
679 | [ C(RESULT_MISS) ] = -1, | |
680 | }, | |
681 | [ C(OP_PREFETCH) ] = { | |
682 | [ C(RESULT_ACCESS) ] = -1, | |
683 | [ C(RESULT_MISS) ] = -1, | |
684 | }, | |
685 | }, | |
686 | [ C(BPU ) ] = { | |
687 | [ C(OP_READ) ] = { | |
688 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ALL_BRANCHES */ | |
689 | [ C(RESULT_MISS) ] = 0x03e8, /* BPU_CLEARS.ANY */ | |
690 | }, | |
691 | [ C(OP_WRITE) ] = { | |
692 | [ C(RESULT_ACCESS) ] = -1, | |
693 | [ C(RESULT_MISS) ] = -1, | |
694 | }, | |
695 | [ C(OP_PREFETCH) ] = { | |
696 | [ C(RESULT_ACCESS) ] = -1, | |
697 | [ C(RESULT_MISS) ] = -1, | |
698 | }, | |
699 | }, | |
89d6c0b5 PZ |
700 | [ C(NODE) ] = { |
701 | [ C(OP_READ) ] = { | |
702 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
703 | [ C(RESULT_MISS) ] = 0x01b7, | |
704 | }, | |
705 | [ C(OP_WRITE) ] = { | |
706 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
707 | [ C(RESULT_MISS) ] = 0x01b7, | |
708 | }, | |
709 | [ C(OP_PREFETCH) ] = { | |
710 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
711 | [ C(RESULT_MISS) ] = 0x01b7, | |
712 | }, | |
713 | }, | |
f22f54f4 PZ |
714 | }; |
715 | ||
caaa8be3 | 716 | static __initconst const u64 core2_hw_cache_event_ids |
f22f54f4 PZ |
717 | [PERF_COUNT_HW_CACHE_MAX] |
718 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
719 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
720 | { | |
721 | [ C(L1D) ] = { | |
722 | [ C(OP_READ) ] = { | |
723 | [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI */ | |
724 | [ C(RESULT_MISS) ] = 0x0140, /* L1D_CACHE_LD.I_STATE */ | |
725 | }, | |
726 | [ C(OP_WRITE) ] = { | |
727 | [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI */ | |
728 | [ C(RESULT_MISS) ] = 0x0141, /* L1D_CACHE_ST.I_STATE */ | |
729 | }, | |
730 | [ C(OP_PREFETCH) ] = { | |
731 | [ C(RESULT_ACCESS) ] = 0x104e, /* L1D_PREFETCH.REQUESTS */ | |
732 | [ C(RESULT_MISS) ] = 0, | |
733 | }, | |
734 | }, | |
735 | [ C(L1I ) ] = { | |
736 | [ C(OP_READ) ] = { | |
737 | [ C(RESULT_ACCESS) ] = 0x0080, /* L1I.READS */ | |
738 | [ C(RESULT_MISS) ] = 0x0081, /* L1I.MISSES */ | |
739 | }, | |
740 | [ C(OP_WRITE) ] = { | |
741 | [ C(RESULT_ACCESS) ] = -1, | |
742 | [ C(RESULT_MISS) ] = -1, | |
743 | }, | |
744 | [ C(OP_PREFETCH) ] = { | |
745 | [ C(RESULT_ACCESS) ] = 0, | |
746 | [ C(RESULT_MISS) ] = 0, | |
747 | }, | |
748 | }, | |
749 | [ C(LL ) ] = { | |
750 | [ C(OP_READ) ] = { | |
751 | [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */ | |
752 | [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */ | |
753 | }, | |
754 | [ C(OP_WRITE) ] = { | |
755 | [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */ | |
756 | [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */ | |
757 | }, | |
758 | [ C(OP_PREFETCH) ] = { | |
759 | [ C(RESULT_ACCESS) ] = 0, | |
760 | [ C(RESULT_MISS) ] = 0, | |
761 | }, | |
762 | }, | |
763 | [ C(DTLB) ] = { | |
764 | [ C(OP_READ) ] = { | |
765 | [ C(RESULT_ACCESS) ] = 0x0f40, /* L1D_CACHE_LD.MESI (alias) */ | |
766 | [ C(RESULT_MISS) ] = 0x0208, /* DTLB_MISSES.MISS_LD */ | |
767 | }, | |
768 | [ C(OP_WRITE) ] = { | |
769 | [ C(RESULT_ACCESS) ] = 0x0f41, /* L1D_CACHE_ST.MESI (alias) */ | |
770 | [ C(RESULT_MISS) ] = 0x0808, /* DTLB_MISSES.MISS_ST */ | |
771 | }, | |
772 | [ C(OP_PREFETCH) ] = { | |
773 | [ C(RESULT_ACCESS) ] = 0, | |
774 | [ C(RESULT_MISS) ] = 0, | |
775 | }, | |
776 | }, | |
777 | [ C(ITLB) ] = { | |
778 | [ C(OP_READ) ] = { | |
779 | [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */ | |
780 | [ C(RESULT_MISS) ] = 0x1282, /* ITLBMISSES */ | |
781 | }, | |
782 | [ C(OP_WRITE) ] = { | |
783 | [ C(RESULT_ACCESS) ] = -1, | |
784 | [ C(RESULT_MISS) ] = -1, | |
785 | }, | |
786 | [ C(OP_PREFETCH) ] = { | |
787 | [ C(RESULT_ACCESS) ] = -1, | |
788 | [ C(RESULT_MISS) ] = -1, | |
789 | }, | |
790 | }, | |
791 | [ C(BPU ) ] = { | |
792 | [ C(OP_READ) ] = { | |
793 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */ | |
794 | [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */ | |
795 | }, | |
796 | [ C(OP_WRITE) ] = { | |
797 | [ C(RESULT_ACCESS) ] = -1, | |
798 | [ C(RESULT_MISS) ] = -1, | |
799 | }, | |
800 | [ C(OP_PREFETCH) ] = { | |
801 | [ C(RESULT_ACCESS) ] = -1, | |
802 | [ C(RESULT_MISS) ] = -1, | |
803 | }, | |
804 | }, | |
805 | }; | |
806 | ||
caaa8be3 | 807 | static __initconst const u64 atom_hw_cache_event_ids |
f22f54f4 PZ |
808 | [PERF_COUNT_HW_CACHE_MAX] |
809 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
810 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
811 | { | |
812 | [ C(L1D) ] = { | |
813 | [ C(OP_READ) ] = { | |
814 | [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE.LD */ | |
815 | [ C(RESULT_MISS) ] = 0, | |
816 | }, | |
817 | [ C(OP_WRITE) ] = { | |
818 | [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE.ST */ | |
819 | [ C(RESULT_MISS) ] = 0, | |
820 | }, | |
821 | [ C(OP_PREFETCH) ] = { | |
822 | [ C(RESULT_ACCESS) ] = 0x0, | |
823 | [ C(RESULT_MISS) ] = 0, | |
824 | }, | |
825 | }, | |
826 | [ C(L1I ) ] = { | |
827 | [ C(OP_READ) ] = { | |
828 | [ C(RESULT_ACCESS) ] = 0x0380, /* L1I.READS */ | |
829 | [ C(RESULT_MISS) ] = 0x0280, /* L1I.MISSES */ | |
830 | }, | |
831 | [ C(OP_WRITE) ] = { | |
832 | [ C(RESULT_ACCESS) ] = -1, | |
833 | [ C(RESULT_MISS) ] = -1, | |
834 | }, | |
835 | [ C(OP_PREFETCH) ] = { | |
836 | [ C(RESULT_ACCESS) ] = 0, | |
837 | [ C(RESULT_MISS) ] = 0, | |
838 | }, | |
839 | }, | |
840 | [ C(LL ) ] = { | |
841 | [ C(OP_READ) ] = { | |
842 | [ C(RESULT_ACCESS) ] = 0x4f29, /* L2_LD.MESI */ | |
843 | [ C(RESULT_MISS) ] = 0x4129, /* L2_LD.ISTATE */ | |
844 | }, | |
845 | [ C(OP_WRITE) ] = { | |
846 | [ C(RESULT_ACCESS) ] = 0x4f2A, /* L2_ST.MESI */ | |
847 | [ C(RESULT_MISS) ] = 0x412A, /* L2_ST.ISTATE */ | |
848 | }, | |
849 | [ C(OP_PREFETCH) ] = { | |
850 | [ C(RESULT_ACCESS) ] = 0, | |
851 | [ C(RESULT_MISS) ] = 0, | |
852 | }, | |
853 | }, | |
854 | [ C(DTLB) ] = { | |
855 | [ C(OP_READ) ] = { | |
856 | [ C(RESULT_ACCESS) ] = 0x2140, /* L1D_CACHE_LD.MESI (alias) */ | |
857 | [ C(RESULT_MISS) ] = 0x0508, /* DTLB_MISSES.MISS_LD */ | |
858 | }, | |
859 | [ C(OP_WRITE) ] = { | |
860 | [ C(RESULT_ACCESS) ] = 0x2240, /* L1D_CACHE_ST.MESI (alias) */ | |
861 | [ C(RESULT_MISS) ] = 0x0608, /* DTLB_MISSES.MISS_ST */ | |
862 | }, | |
863 | [ C(OP_PREFETCH) ] = { | |
864 | [ C(RESULT_ACCESS) ] = 0, | |
865 | [ C(RESULT_MISS) ] = 0, | |
866 | }, | |
867 | }, | |
868 | [ C(ITLB) ] = { | |
869 | [ C(OP_READ) ] = { | |
870 | [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */ | |
871 | [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */ | |
872 | }, | |
873 | [ C(OP_WRITE) ] = { | |
874 | [ C(RESULT_ACCESS) ] = -1, | |
875 | [ C(RESULT_MISS) ] = -1, | |
876 | }, | |
877 | [ C(OP_PREFETCH) ] = { | |
878 | [ C(RESULT_ACCESS) ] = -1, | |
879 | [ C(RESULT_MISS) ] = -1, | |
880 | }, | |
881 | }, | |
882 | [ C(BPU ) ] = { | |
883 | [ C(OP_READ) ] = { | |
884 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */ | |
885 | [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */ | |
886 | }, | |
887 | [ C(OP_WRITE) ] = { | |
888 | [ C(RESULT_ACCESS) ] = -1, | |
889 | [ C(RESULT_MISS) ] = -1, | |
890 | }, | |
891 | [ C(OP_PREFETCH) ] = { | |
892 | [ C(RESULT_ACCESS) ] = -1, | |
893 | [ C(RESULT_MISS) ] = -1, | |
894 | }, | |
895 | }, | |
896 | }; | |
897 | ||
1fa64180 YZ |
898 | static struct extra_reg intel_slm_extra_regs[] __read_mostly = |
899 | { | |
900 | /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ | |
901 | INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x768005ffff, RSP_0), | |
902 | INTEL_UEVENT_EXTRA_REG(0x02b7, MSR_OFFCORE_RSP_1, 0x768005ffff, RSP_1), | |
903 | EVENT_EXTRA_END | |
904 | }; | |
905 | ||
906 | #define SLM_DMND_READ SNB_DMND_DATA_RD | |
907 | #define SLM_DMND_WRITE SNB_DMND_RFO | |
908 | #define SLM_DMND_PREFETCH (SNB_PF_DATA_RD|SNB_PF_RFO) | |
909 | ||
910 | #define SLM_SNP_ANY (SNB_SNP_NONE|SNB_SNP_MISS|SNB_NO_FWD|SNB_HITM) | |
911 | #define SLM_LLC_ACCESS SNB_RESP_ANY | |
912 | #define SLM_LLC_MISS (SLM_SNP_ANY|SNB_NON_DRAM) | |
913 | ||
914 | static __initconst const u64 slm_hw_cache_extra_regs | |
915 | [PERF_COUNT_HW_CACHE_MAX] | |
916 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
917 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
918 | { | |
919 | [ C(LL ) ] = { | |
920 | [ C(OP_READ) ] = { | |
921 | [ C(RESULT_ACCESS) ] = SLM_DMND_READ|SLM_LLC_ACCESS, | |
922 | [ C(RESULT_MISS) ] = SLM_DMND_READ|SLM_LLC_MISS, | |
923 | }, | |
924 | [ C(OP_WRITE) ] = { | |
925 | [ C(RESULT_ACCESS) ] = SLM_DMND_WRITE|SLM_LLC_ACCESS, | |
926 | [ C(RESULT_MISS) ] = SLM_DMND_WRITE|SLM_LLC_MISS, | |
927 | }, | |
928 | [ C(OP_PREFETCH) ] = { | |
929 | [ C(RESULT_ACCESS) ] = SLM_DMND_PREFETCH|SLM_LLC_ACCESS, | |
930 | [ C(RESULT_MISS) ] = SLM_DMND_PREFETCH|SLM_LLC_MISS, | |
931 | }, | |
932 | }, | |
933 | }; | |
934 | ||
935 | static __initconst const u64 slm_hw_cache_event_ids | |
936 | [PERF_COUNT_HW_CACHE_MAX] | |
937 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
938 | [PERF_COUNT_HW_CACHE_RESULT_MAX] = | |
939 | { | |
940 | [ C(L1D) ] = { | |
941 | [ C(OP_READ) ] = { | |
942 | [ C(RESULT_ACCESS) ] = 0, | |
943 | [ C(RESULT_MISS) ] = 0x0104, /* LD_DCU_MISS */ | |
944 | }, | |
945 | [ C(OP_WRITE) ] = { | |
946 | [ C(RESULT_ACCESS) ] = 0, | |
947 | [ C(RESULT_MISS) ] = 0, | |
948 | }, | |
949 | [ C(OP_PREFETCH) ] = { | |
950 | [ C(RESULT_ACCESS) ] = 0, | |
951 | [ C(RESULT_MISS) ] = 0, | |
952 | }, | |
953 | }, | |
954 | [ C(L1I ) ] = { | |
955 | [ C(OP_READ) ] = { | |
956 | [ C(RESULT_ACCESS) ] = 0x0380, /* ICACHE.ACCESSES */ | |
957 | [ C(RESULT_MISS) ] = 0x0280, /* ICACGE.MISSES */ | |
958 | }, | |
959 | [ C(OP_WRITE) ] = { | |
960 | [ C(RESULT_ACCESS) ] = -1, | |
961 | [ C(RESULT_MISS) ] = -1, | |
962 | }, | |
963 | [ C(OP_PREFETCH) ] = { | |
964 | [ C(RESULT_ACCESS) ] = 0, | |
965 | [ C(RESULT_MISS) ] = 0, | |
966 | }, | |
967 | }, | |
968 | [ C(LL ) ] = { | |
969 | [ C(OP_READ) ] = { | |
970 | /* OFFCORE_RESPONSE.ANY_DATA.LOCAL_CACHE */ | |
971 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
972 | /* OFFCORE_RESPONSE.ANY_DATA.ANY_LLC_MISS */ | |
973 | [ C(RESULT_MISS) ] = 0x01b7, | |
974 | }, | |
975 | [ C(OP_WRITE) ] = { | |
976 | /* OFFCORE_RESPONSE.ANY_RFO.LOCAL_CACHE */ | |
977 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
978 | /* OFFCORE_RESPONSE.ANY_RFO.ANY_LLC_MISS */ | |
979 | [ C(RESULT_MISS) ] = 0x01b7, | |
980 | }, | |
981 | [ C(OP_PREFETCH) ] = { | |
982 | /* OFFCORE_RESPONSE.PREFETCH.LOCAL_CACHE */ | |
983 | [ C(RESULT_ACCESS) ] = 0x01b7, | |
984 | /* OFFCORE_RESPONSE.PREFETCH.ANY_LLC_MISS */ | |
985 | [ C(RESULT_MISS) ] = 0x01b7, | |
986 | }, | |
987 | }, | |
988 | [ C(DTLB) ] = { | |
989 | [ C(OP_READ) ] = { | |
990 | [ C(RESULT_ACCESS) ] = 0, | |
991 | [ C(RESULT_MISS) ] = 0x0804, /* LD_DTLB_MISS */ | |
992 | }, | |
993 | [ C(OP_WRITE) ] = { | |
994 | [ C(RESULT_ACCESS) ] = 0, | |
995 | [ C(RESULT_MISS) ] = 0, | |
996 | }, | |
997 | [ C(OP_PREFETCH) ] = { | |
998 | [ C(RESULT_ACCESS) ] = 0, | |
999 | [ C(RESULT_MISS) ] = 0, | |
1000 | }, | |
1001 | }, | |
1002 | [ C(ITLB) ] = { | |
1003 | [ C(OP_READ) ] = { | |
1004 | [ C(RESULT_ACCESS) ] = 0x00c0, /* INST_RETIRED.ANY_P */ | |
1005 | [ C(RESULT_MISS) ] = 0x0282, /* ITLB.MISSES */ | |
1006 | }, | |
1007 | [ C(OP_WRITE) ] = { | |
1008 | [ C(RESULT_ACCESS) ] = -1, | |
1009 | [ C(RESULT_MISS) ] = -1, | |
1010 | }, | |
1011 | [ C(OP_PREFETCH) ] = { | |
1012 | [ C(RESULT_ACCESS) ] = -1, | |
1013 | [ C(RESULT_MISS) ] = -1, | |
1014 | }, | |
1015 | }, | |
1016 | [ C(BPU ) ] = { | |
1017 | [ C(OP_READ) ] = { | |
1018 | [ C(RESULT_ACCESS) ] = 0x00c4, /* BR_INST_RETIRED.ANY */ | |
1019 | [ C(RESULT_MISS) ] = 0x00c5, /* BP_INST_RETIRED.MISPRED */ | |
1020 | }, | |
1021 | [ C(OP_WRITE) ] = { | |
1022 | [ C(RESULT_ACCESS) ] = -1, | |
1023 | [ C(RESULT_MISS) ] = -1, | |
1024 | }, | |
1025 | [ C(OP_PREFETCH) ] = { | |
1026 | [ C(RESULT_ACCESS) ] = -1, | |
1027 | [ C(RESULT_MISS) ] = -1, | |
1028 | }, | |
1029 | }, | |
1030 | }; | |
1031 | ||
60ce0fbd SE |
1032 | static inline bool intel_pmu_needs_lbr_smpl(struct perf_event *event) |
1033 | { | |
1034 | /* user explicitly requested branch sampling */ | |
1035 | if (has_branch_stack(event)) | |
1036 | return true; | |
1037 | ||
1038 | /* implicit branch sampling to correct PEBS skid */ | |
3044318f AK |
1039 | if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1 && |
1040 | x86_pmu.intel_cap.pebs_format < 2) | |
60ce0fbd SE |
1041 | return true; |
1042 | ||
1043 | return false; | |
1044 | } | |
1045 | ||
f22f54f4 PZ |
1046 | static void intel_pmu_disable_all(void) |
1047 | { | |
1048 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | |
1049 | ||
1050 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0); | |
1051 | ||
15c7ad51 | 1052 | if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) |
f22f54f4 | 1053 | intel_pmu_disable_bts(); |
ca037701 PZ |
1054 | |
1055 | intel_pmu_pebs_disable_all(); | |
caff2bef | 1056 | intel_pmu_lbr_disable_all(); |
f22f54f4 PZ |
1057 | } |
1058 | ||
11164cd4 | 1059 | static void intel_pmu_enable_all(int added) |
f22f54f4 PZ |
1060 | { |
1061 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | |
1062 | ||
d329527e PZ |
1063 | intel_pmu_pebs_enable_all(); |
1064 | intel_pmu_lbr_enable_all(); | |
144d31e6 GN |
1065 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, |
1066 | x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask); | |
f22f54f4 | 1067 | |
15c7ad51 | 1068 | if (test_bit(INTEL_PMC_IDX_FIXED_BTS, cpuc->active_mask)) { |
f22f54f4 | 1069 | struct perf_event *event = |
15c7ad51 | 1070 | cpuc->events[INTEL_PMC_IDX_FIXED_BTS]; |
f22f54f4 PZ |
1071 | |
1072 | if (WARN_ON_ONCE(!event)) | |
1073 | return; | |
1074 | ||
1075 | intel_pmu_enable_bts(event->hw.config); | |
1076 | } | |
1077 | } | |
1078 | ||
11164cd4 PZ |
1079 | /* |
1080 | * Workaround for: | |
1081 | * Intel Errata AAK100 (model 26) | |
1082 | * Intel Errata AAP53 (model 30) | |
40b91cd1 | 1083 | * Intel Errata BD53 (model 44) |
11164cd4 | 1084 | * |
351af072 ZY |
1085 | * The official story: |
1086 | * These chips need to be 'reset' when adding counters by programming the | |
1087 | * magic three (non-counting) events 0x4300B5, 0x4300D2, and 0x4300B1 either | |
1088 | * in sequence on the same PMC or on different PMCs. | |
1089 | * | |
1090 | * In practise it appears some of these events do in fact count, and | |
1091 | * we need to programm all 4 events. | |
11164cd4 | 1092 | */ |
351af072 | 1093 | static void intel_pmu_nhm_workaround(void) |
11164cd4 | 1094 | { |
351af072 ZY |
1095 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
1096 | static const unsigned long nhm_magic[4] = { | |
1097 | 0x4300B5, | |
1098 | 0x4300D2, | |
1099 | 0x4300B1, | |
1100 | 0x4300B1 | |
1101 | }; | |
1102 | struct perf_event *event; | |
1103 | int i; | |
11164cd4 | 1104 | |
351af072 ZY |
1105 | /* |
1106 | * The Errata requires below steps: | |
1107 | * 1) Clear MSR_IA32_PEBS_ENABLE and MSR_CORE_PERF_GLOBAL_CTRL; | |
1108 | * 2) Configure 4 PERFEVTSELx with the magic events and clear | |
1109 | * the corresponding PMCx; | |
1110 | * 3) set bit0~bit3 of MSR_CORE_PERF_GLOBAL_CTRL; | |
1111 | * 4) Clear MSR_CORE_PERF_GLOBAL_CTRL; | |
1112 | * 5) Clear 4 pairs of ERFEVTSELx and PMCx; | |
1113 | */ | |
11164cd4 | 1114 | |
351af072 ZY |
1115 | /* |
1116 | * The real steps we choose are a little different from above. | |
1117 | * A) To reduce MSR operations, we don't run step 1) as they | |
1118 | * are already cleared before this function is called; | |
1119 | * B) Call x86_perf_event_update to save PMCx before configuring | |
1120 | * PERFEVTSELx with magic number; | |
1121 | * C) With step 5), we do clear only when the PERFEVTSELx is | |
1122 | * not used currently. | |
1123 | * D) Call x86_perf_event_set_period to restore PMCx; | |
1124 | */ | |
11164cd4 | 1125 | |
351af072 ZY |
1126 | /* We always operate 4 pairs of PERF Counters */ |
1127 | for (i = 0; i < 4; i++) { | |
1128 | event = cpuc->events[i]; | |
1129 | if (event) | |
1130 | x86_perf_event_update(event); | |
1131 | } | |
11164cd4 | 1132 | |
351af072 ZY |
1133 | for (i = 0; i < 4; i++) { |
1134 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, nhm_magic[i]); | |
1135 | wrmsrl(MSR_ARCH_PERFMON_PERFCTR0 + i, 0x0); | |
1136 | } | |
1137 | ||
1138 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0xf); | |
1139 | wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0); | |
11164cd4 | 1140 | |
351af072 ZY |
1141 | for (i = 0; i < 4; i++) { |
1142 | event = cpuc->events[i]; | |
1143 | ||
1144 | if (event) { | |
1145 | x86_perf_event_set_period(event); | |
31fa58af | 1146 | __x86_pmu_enable_event(&event->hw, |
351af072 ZY |
1147 | ARCH_PERFMON_EVENTSEL_ENABLE); |
1148 | } else | |
1149 | wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + i, 0x0); | |
11164cd4 | 1150 | } |
351af072 ZY |
1151 | } |
1152 | ||
1153 | static void intel_pmu_nhm_enable_all(int added) | |
1154 | { | |
1155 | if (added) | |
1156 | intel_pmu_nhm_workaround(); | |
11164cd4 PZ |
1157 | intel_pmu_enable_all(added); |
1158 | } | |
1159 | ||
f22f54f4 PZ |
1160 | static inline u64 intel_pmu_get_status(void) |
1161 | { | |
1162 | u64 status; | |
1163 | ||
1164 | rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status); | |
1165 | ||
1166 | return status; | |
1167 | } | |
1168 | ||
1169 | static inline void intel_pmu_ack_status(u64 ack) | |
1170 | { | |
1171 | wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack); | |
1172 | } | |
1173 | ||
ca037701 | 1174 | static void intel_pmu_disable_fixed(struct hw_perf_event *hwc) |
f22f54f4 | 1175 | { |
15c7ad51 | 1176 | int idx = hwc->idx - INTEL_PMC_IDX_FIXED; |
f22f54f4 PZ |
1177 | u64 ctrl_val, mask; |
1178 | ||
1179 | mask = 0xfULL << (idx * 4); | |
1180 | ||
1181 | rdmsrl(hwc->config_base, ctrl_val); | |
1182 | ctrl_val &= ~mask; | |
7645a24c | 1183 | wrmsrl(hwc->config_base, ctrl_val); |
f22f54f4 PZ |
1184 | } |
1185 | ||
ca037701 | 1186 | static void intel_pmu_disable_event(struct perf_event *event) |
f22f54f4 | 1187 | { |
aff3d91a | 1188 | struct hw_perf_event *hwc = &event->hw; |
144d31e6 | 1189 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
aff3d91a | 1190 | |
15c7ad51 | 1191 | if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) { |
f22f54f4 PZ |
1192 | intel_pmu_disable_bts(); |
1193 | intel_pmu_drain_bts_buffer(); | |
1194 | return; | |
1195 | } | |
1196 | ||
144d31e6 GN |
1197 | cpuc->intel_ctrl_guest_mask &= ~(1ull << hwc->idx); |
1198 | cpuc->intel_ctrl_host_mask &= ~(1ull << hwc->idx); | |
1199 | ||
60ce0fbd SE |
1200 | /* |
1201 | * must disable before any actual event | |
1202 | * because any event may be combined with LBR | |
1203 | */ | |
1204 | if (intel_pmu_needs_lbr_smpl(event)) | |
1205 | intel_pmu_lbr_disable(event); | |
1206 | ||
f22f54f4 | 1207 | if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) { |
aff3d91a | 1208 | intel_pmu_disable_fixed(hwc); |
f22f54f4 PZ |
1209 | return; |
1210 | } | |
1211 | ||
aff3d91a | 1212 | x86_pmu_disable_event(event); |
ca037701 | 1213 | |
ab608344 | 1214 | if (unlikely(event->attr.precise_ip)) |
ef21f683 | 1215 | intel_pmu_pebs_disable(event); |
f22f54f4 PZ |
1216 | } |
1217 | ||
ca037701 | 1218 | static void intel_pmu_enable_fixed(struct hw_perf_event *hwc) |
f22f54f4 | 1219 | { |
15c7ad51 | 1220 | int idx = hwc->idx - INTEL_PMC_IDX_FIXED; |
f22f54f4 | 1221 | u64 ctrl_val, bits, mask; |
f22f54f4 PZ |
1222 | |
1223 | /* | |
1224 | * Enable IRQ generation (0x8), | |
1225 | * and enable ring-3 counting (0x2) and ring-0 counting (0x1) | |
1226 | * if requested: | |
1227 | */ | |
1228 | bits = 0x8ULL; | |
1229 | if (hwc->config & ARCH_PERFMON_EVENTSEL_USR) | |
1230 | bits |= 0x2; | |
1231 | if (hwc->config & ARCH_PERFMON_EVENTSEL_OS) | |
1232 | bits |= 0x1; | |
1233 | ||
1234 | /* | |
1235 | * ANY bit is supported in v3 and up | |
1236 | */ | |
1237 | if (x86_pmu.version > 2 && hwc->config & ARCH_PERFMON_EVENTSEL_ANY) | |
1238 | bits |= 0x4; | |
1239 | ||
1240 | bits <<= (idx * 4); | |
1241 | mask = 0xfULL << (idx * 4); | |
1242 | ||
1243 | rdmsrl(hwc->config_base, ctrl_val); | |
1244 | ctrl_val &= ~mask; | |
1245 | ctrl_val |= bits; | |
7645a24c | 1246 | wrmsrl(hwc->config_base, ctrl_val); |
f22f54f4 PZ |
1247 | } |
1248 | ||
aff3d91a | 1249 | static void intel_pmu_enable_event(struct perf_event *event) |
f22f54f4 | 1250 | { |
aff3d91a | 1251 | struct hw_perf_event *hwc = &event->hw; |
144d31e6 | 1252 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); |
aff3d91a | 1253 | |
15c7ad51 | 1254 | if (unlikely(hwc->idx == INTEL_PMC_IDX_FIXED_BTS)) { |
0a3aee0d | 1255 | if (!__this_cpu_read(cpu_hw_events.enabled)) |
f22f54f4 PZ |
1256 | return; |
1257 | ||
1258 | intel_pmu_enable_bts(hwc->config); | |
1259 | return; | |
1260 | } | |
60ce0fbd SE |
1261 | /* |
1262 | * must enabled before any actual event | |
1263 | * because any event may be combined with LBR | |
1264 | */ | |
1265 | if (intel_pmu_needs_lbr_smpl(event)) | |
1266 | intel_pmu_lbr_enable(event); | |
f22f54f4 | 1267 | |
144d31e6 GN |
1268 | if (event->attr.exclude_host) |
1269 | cpuc->intel_ctrl_guest_mask |= (1ull << hwc->idx); | |
1270 | if (event->attr.exclude_guest) | |
1271 | cpuc->intel_ctrl_host_mask |= (1ull << hwc->idx); | |
1272 | ||
f22f54f4 | 1273 | if (unlikely(hwc->config_base == MSR_ARCH_PERFMON_FIXED_CTR_CTRL)) { |
aff3d91a | 1274 | intel_pmu_enable_fixed(hwc); |
f22f54f4 PZ |
1275 | return; |
1276 | } | |
1277 | ||
ab608344 | 1278 | if (unlikely(event->attr.precise_ip)) |
ef21f683 | 1279 | intel_pmu_pebs_enable(event); |
ca037701 | 1280 | |
31fa58af | 1281 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); |
f22f54f4 PZ |
1282 | } |
1283 | ||
1284 | /* | |
1285 | * Save and restart an expired event. Called by NMI contexts, | |
1286 | * so it has to be careful about preempting normal event ops: | |
1287 | */ | |
de0428a7 | 1288 | int intel_pmu_save_and_restart(struct perf_event *event) |
f22f54f4 | 1289 | { |
cc2ad4ba PZ |
1290 | x86_perf_event_update(event); |
1291 | return x86_perf_event_set_period(event); | |
f22f54f4 PZ |
1292 | } |
1293 | ||
1294 | static void intel_pmu_reset(void) | |
1295 | { | |
0a3aee0d | 1296 | struct debug_store *ds = __this_cpu_read(cpu_hw_events.ds); |
f22f54f4 PZ |
1297 | unsigned long flags; |
1298 | int idx; | |
1299 | ||
948b1bb8 | 1300 | if (!x86_pmu.num_counters) |
f22f54f4 PZ |
1301 | return; |
1302 | ||
1303 | local_irq_save(flags); | |
1304 | ||
c767a54b | 1305 | pr_info("clearing PMU state on CPU#%d\n", smp_processor_id()); |
f22f54f4 | 1306 | |
948b1bb8 | 1307 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { |
715c85b1 PA |
1308 | wrmsrl_safe(x86_pmu_config_addr(idx), 0ull); |
1309 | wrmsrl_safe(x86_pmu_event_addr(idx), 0ull); | |
f22f54f4 | 1310 | } |
948b1bb8 | 1311 | for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) |
715c85b1 | 1312 | wrmsrl_safe(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull); |
948b1bb8 | 1313 | |
f22f54f4 PZ |
1314 | if (ds) |
1315 | ds->bts_index = ds->bts_buffer_base; | |
1316 | ||
1317 | local_irq_restore(flags); | |
1318 | } | |
1319 | ||
1320 | /* | |
1321 | * This handler is triggered by the local APIC, so the APIC IRQ handling | |
1322 | * rules apply: | |
1323 | */ | |
1324 | static int intel_pmu_handle_irq(struct pt_regs *regs) | |
1325 | { | |
1326 | struct perf_sample_data data; | |
1327 | struct cpu_hw_events *cpuc; | |
1328 | int bit, loops; | |
2e556b5b | 1329 | u64 status; |
b0b2072d | 1330 | int handled; |
f22f54f4 | 1331 | |
f22f54f4 PZ |
1332 | cpuc = &__get_cpu_var(cpu_hw_events); |
1333 | ||
2bce5dac | 1334 | /* |
72db5596 AK |
1335 | * No known reason to not always do late ACK, |
1336 | * but just in case do it opt-in. | |
2bce5dac | 1337 | */ |
72db5596 AK |
1338 | if (!x86_pmu.late_ack) |
1339 | apic_write(APIC_LVTPC, APIC_DM_NMI); | |
3fb2b8dd | 1340 | intel_pmu_disable_all(); |
b0b2072d | 1341 | handled = intel_pmu_drain_bts_buffer(); |
f22f54f4 PZ |
1342 | status = intel_pmu_get_status(); |
1343 | if (!status) { | |
11164cd4 | 1344 | intel_pmu_enable_all(0); |
b0b2072d | 1345 | return handled; |
f22f54f4 PZ |
1346 | } |
1347 | ||
1348 | loops = 0; | |
1349 | again: | |
2e556b5b | 1350 | intel_pmu_ack_status(status); |
f22f54f4 | 1351 | if (++loops > 100) { |
ae0def05 DH |
1352 | static bool warned = false; |
1353 | if (!warned) { | |
1354 | WARN(1, "perfevents: irq loop stuck!\n"); | |
1355 | perf_event_print_debug(); | |
1356 | warned = true; | |
1357 | } | |
f22f54f4 | 1358 | intel_pmu_reset(); |
3fb2b8dd | 1359 | goto done; |
f22f54f4 PZ |
1360 | } |
1361 | ||
1362 | inc_irq_stat(apic_perf_irqs); | |
ca037701 | 1363 | |
caff2bef PZ |
1364 | intel_pmu_lbr_read(); |
1365 | ||
ca037701 PZ |
1366 | /* |
1367 | * PEBS overflow sets bit 62 in the global status register | |
1368 | */ | |
de725dec PZ |
1369 | if (__test_and_clear_bit(62, (unsigned long *)&status)) { |
1370 | handled++; | |
ca037701 | 1371 | x86_pmu.drain_pebs(regs); |
de725dec | 1372 | } |
ca037701 | 1373 | |
984b3f57 | 1374 | for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) { |
f22f54f4 PZ |
1375 | struct perf_event *event = cpuc->events[bit]; |
1376 | ||
de725dec PZ |
1377 | handled++; |
1378 | ||
f22f54f4 PZ |
1379 | if (!test_bit(bit, cpuc->active_mask)) |
1380 | continue; | |
1381 | ||
1382 | if (!intel_pmu_save_and_restart(event)) | |
1383 | continue; | |
1384 | ||
fd0d000b | 1385 | perf_sample_data_init(&data, 0, event->hw.last_period); |
f22f54f4 | 1386 | |
60ce0fbd SE |
1387 | if (has_branch_stack(event)) |
1388 | data.br_stack = &cpuc->lbr_stack; | |
1389 | ||
a8b0ca17 | 1390 | if (perf_event_overflow(event, &data, regs)) |
a4eaf7f1 | 1391 | x86_pmu_stop(event, 0); |
f22f54f4 PZ |
1392 | } |
1393 | ||
f22f54f4 PZ |
1394 | /* |
1395 | * Repeat if there is more work to be done: | |
1396 | */ | |
1397 | status = intel_pmu_get_status(); | |
1398 | if (status) | |
1399 | goto again; | |
1400 | ||
3fb2b8dd | 1401 | done: |
11164cd4 | 1402 | intel_pmu_enable_all(0); |
72db5596 AK |
1403 | /* |
1404 | * Only unmask the NMI after the overflow counters | |
1405 | * have been reset. This avoids spurious NMIs on | |
1406 | * Haswell CPUs. | |
1407 | */ | |
1408 | if (x86_pmu.late_ack) | |
1409 | apic_write(APIC_LVTPC, APIC_DM_NMI); | |
de725dec | 1410 | return handled; |
f22f54f4 PZ |
1411 | } |
1412 | ||
f22f54f4 | 1413 | static struct event_constraint * |
ca037701 | 1414 | intel_bts_constraints(struct perf_event *event) |
f22f54f4 | 1415 | { |
ca037701 PZ |
1416 | struct hw_perf_event *hwc = &event->hw; |
1417 | unsigned int hw_event, bts_event; | |
f22f54f4 | 1418 | |
18a073a3 PZ |
1419 | if (event->attr.freq) |
1420 | return NULL; | |
1421 | ||
ca037701 PZ |
1422 | hw_event = hwc->config & INTEL_ARCH_EVENT_MASK; |
1423 | bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS); | |
f22f54f4 | 1424 | |
ca037701 | 1425 | if (unlikely(hw_event == bts_event && hwc->sample_period == 1)) |
f22f54f4 | 1426 | return &bts_constraint; |
ca037701 | 1427 | |
f22f54f4 PZ |
1428 | return NULL; |
1429 | } | |
1430 | ||
5a425294 | 1431 | static int intel_alt_er(int idx) |
b79e8941 PZ |
1432 | { |
1433 | if (!(x86_pmu.er_flags & ERF_HAS_RSP_1)) | |
5a425294 | 1434 | return idx; |
b79e8941 | 1435 | |
5a425294 PZ |
1436 | if (idx == EXTRA_REG_RSP_0) |
1437 | return EXTRA_REG_RSP_1; | |
1438 | ||
1439 | if (idx == EXTRA_REG_RSP_1) | |
1440 | return EXTRA_REG_RSP_0; | |
1441 | ||
1442 | return idx; | |
1443 | } | |
1444 | ||
1445 | static void intel_fixup_er(struct perf_event *event, int idx) | |
1446 | { | |
1447 | event->hw.extra_reg.idx = idx; | |
1448 | ||
1449 | if (idx == EXTRA_REG_RSP_0) { | |
b79e8941 | 1450 | event->hw.config &= ~INTEL_ARCH_EVENT_MASK; |
53ad0447 | 1451 | event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_0].event; |
b79e8941 | 1452 | event->hw.extra_reg.reg = MSR_OFFCORE_RSP_0; |
5a425294 PZ |
1453 | } else if (idx == EXTRA_REG_RSP_1) { |
1454 | event->hw.config &= ~INTEL_ARCH_EVENT_MASK; | |
53ad0447 | 1455 | event->hw.config |= x86_pmu.extra_regs[EXTRA_REG_RSP_1].event; |
5a425294 | 1456 | event->hw.extra_reg.reg = MSR_OFFCORE_RSP_1; |
b79e8941 | 1457 | } |
b79e8941 PZ |
1458 | } |
1459 | ||
efc9f05d SE |
1460 | /* |
1461 | * manage allocation of shared extra msr for certain events | |
1462 | * | |
1463 | * sharing can be: | |
1464 | * per-cpu: to be shared between the various events on a single PMU | |
1465 | * per-core: per-cpu + shared by HT threads | |
1466 | */ | |
a7e3ed1e | 1467 | static struct event_constraint * |
efc9f05d | 1468 | __intel_shared_reg_get_constraints(struct cpu_hw_events *cpuc, |
b36817e8 SE |
1469 | struct perf_event *event, |
1470 | struct hw_perf_event_extra *reg) | |
a7e3ed1e | 1471 | { |
efc9f05d | 1472 | struct event_constraint *c = &emptyconstraint; |
a7e3ed1e | 1473 | struct er_account *era; |
cd8a38d3 | 1474 | unsigned long flags; |
5a425294 | 1475 | int idx = reg->idx; |
a7e3ed1e | 1476 | |
5a425294 PZ |
1477 | /* |
1478 | * reg->alloc can be set due to existing state, so for fake cpuc we | |
1479 | * need to ignore this, otherwise we might fail to allocate proper fake | |
1480 | * state for this extra reg constraint. Also see the comment below. | |
1481 | */ | |
1482 | if (reg->alloc && !cpuc->is_fake) | |
b36817e8 | 1483 | return NULL; /* call x86_get_event_constraint() */ |
a7e3ed1e | 1484 | |
b79e8941 | 1485 | again: |
5a425294 | 1486 | era = &cpuc->shared_regs->regs[idx]; |
cd8a38d3 SE |
1487 | /* |
1488 | * we use spin_lock_irqsave() to avoid lockdep issues when | |
1489 | * passing a fake cpuc | |
1490 | */ | |
1491 | raw_spin_lock_irqsave(&era->lock, flags); | |
efc9f05d SE |
1492 | |
1493 | if (!atomic_read(&era->ref) || era->config == reg->config) { | |
1494 | ||
5a425294 PZ |
1495 | /* |
1496 | * If its a fake cpuc -- as per validate_{group,event}() we | |
1497 | * shouldn't touch event state and we can avoid doing so | |
1498 | * since both will only call get_event_constraints() once | |
1499 | * on each event, this avoids the need for reg->alloc. | |
1500 | * | |
1501 | * Not doing the ER fixup will only result in era->reg being | |
1502 | * wrong, but since we won't actually try and program hardware | |
1503 | * this isn't a problem either. | |
1504 | */ | |
1505 | if (!cpuc->is_fake) { | |
1506 | if (idx != reg->idx) | |
1507 | intel_fixup_er(event, idx); | |
1508 | ||
1509 | /* | |
1510 | * x86_schedule_events() can call get_event_constraints() | |
1511 | * multiple times on events in the case of incremental | |
1512 | * scheduling(). reg->alloc ensures we only do the ER | |
1513 | * allocation once. | |
1514 | */ | |
1515 | reg->alloc = 1; | |
1516 | } | |
1517 | ||
efc9f05d SE |
1518 | /* lock in msr value */ |
1519 | era->config = reg->config; | |
1520 | era->reg = reg->reg; | |
1521 | ||
1522 | /* one more user */ | |
1523 | atomic_inc(&era->ref); | |
1524 | ||
a7e3ed1e | 1525 | /* |
b36817e8 SE |
1526 | * need to call x86_get_event_constraint() |
1527 | * to check if associated event has constraints | |
a7e3ed1e | 1528 | */ |
b36817e8 | 1529 | c = NULL; |
5a425294 PZ |
1530 | } else { |
1531 | idx = intel_alt_er(idx); | |
1532 | if (idx != reg->idx) { | |
1533 | raw_spin_unlock_irqrestore(&era->lock, flags); | |
1534 | goto again; | |
1535 | } | |
a7e3ed1e | 1536 | } |
cd8a38d3 | 1537 | raw_spin_unlock_irqrestore(&era->lock, flags); |
a7e3ed1e | 1538 | |
efc9f05d SE |
1539 | return c; |
1540 | } | |
1541 | ||
1542 | static void | |
1543 | __intel_shared_reg_put_constraints(struct cpu_hw_events *cpuc, | |
1544 | struct hw_perf_event_extra *reg) | |
1545 | { | |
1546 | struct er_account *era; | |
1547 | ||
1548 | /* | |
5a425294 PZ |
1549 | * Only put constraint if extra reg was actually allocated. Also takes |
1550 | * care of event which do not use an extra shared reg. | |
1551 | * | |
1552 | * Also, if this is a fake cpuc we shouldn't touch any event state | |
1553 | * (reg->alloc) and we don't care about leaving inconsistent cpuc state | |
1554 | * either since it'll be thrown out. | |
efc9f05d | 1555 | */ |
5a425294 | 1556 | if (!reg->alloc || cpuc->is_fake) |
efc9f05d SE |
1557 | return; |
1558 | ||
1559 | era = &cpuc->shared_regs->regs[reg->idx]; | |
1560 | ||
1561 | /* one fewer user */ | |
1562 | atomic_dec(&era->ref); | |
1563 | ||
1564 | /* allocate again next time */ | |
1565 | reg->alloc = 0; | |
1566 | } | |
1567 | ||
1568 | static struct event_constraint * | |
1569 | intel_shared_regs_constraints(struct cpu_hw_events *cpuc, | |
1570 | struct perf_event *event) | |
1571 | { | |
b36817e8 SE |
1572 | struct event_constraint *c = NULL, *d; |
1573 | struct hw_perf_event_extra *xreg, *breg; | |
1574 | ||
1575 | xreg = &event->hw.extra_reg; | |
1576 | if (xreg->idx != EXTRA_REG_NONE) { | |
1577 | c = __intel_shared_reg_get_constraints(cpuc, event, xreg); | |
1578 | if (c == &emptyconstraint) | |
1579 | return c; | |
1580 | } | |
1581 | breg = &event->hw.branch_reg; | |
1582 | if (breg->idx != EXTRA_REG_NONE) { | |
1583 | d = __intel_shared_reg_get_constraints(cpuc, event, breg); | |
1584 | if (d == &emptyconstraint) { | |
1585 | __intel_shared_reg_put_constraints(cpuc, xreg); | |
1586 | c = d; | |
1587 | } | |
1588 | } | |
efc9f05d | 1589 | return c; |
a7e3ed1e AK |
1590 | } |
1591 | ||
de0428a7 KW |
1592 | struct event_constraint * |
1593 | x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |
1594 | { | |
1595 | struct event_constraint *c; | |
1596 | ||
1597 | if (x86_pmu.event_constraints) { | |
1598 | for_each_event_constraint(c, x86_pmu.event_constraints) { | |
9fac2cf3 | 1599 | if ((event->hw.config & c->cmask) == c->code) { |
9fac2cf3 | 1600 | event->hw.flags |= c->flags; |
de0428a7 | 1601 | return c; |
9fac2cf3 | 1602 | } |
de0428a7 KW |
1603 | } |
1604 | } | |
1605 | ||
1606 | return &unconstrained; | |
1607 | } | |
1608 | ||
f22f54f4 PZ |
1609 | static struct event_constraint * |
1610 | intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |
1611 | { | |
1612 | struct event_constraint *c; | |
1613 | ||
ca037701 PZ |
1614 | c = intel_bts_constraints(event); |
1615 | if (c) | |
1616 | return c; | |
1617 | ||
1618 | c = intel_pebs_constraints(event); | |
f22f54f4 PZ |
1619 | if (c) |
1620 | return c; | |
1621 | ||
efc9f05d | 1622 | c = intel_shared_regs_constraints(cpuc, event); |
a7e3ed1e AK |
1623 | if (c) |
1624 | return c; | |
1625 | ||
f22f54f4 PZ |
1626 | return x86_get_event_constraints(cpuc, event); |
1627 | } | |
1628 | ||
efc9f05d SE |
1629 | static void |
1630 | intel_put_shared_regs_event_constraints(struct cpu_hw_events *cpuc, | |
a7e3ed1e AK |
1631 | struct perf_event *event) |
1632 | { | |
efc9f05d | 1633 | struct hw_perf_event_extra *reg; |
a7e3ed1e | 1634 | |
efc9f05d SE |
1635 | reg = &event->hw.extra_reg; |
1636 | if (reg->idx != EXTRA_REG_NONE) | |
1637 | __intel_shared_reg_put_constraints(cpuc, reg); | |
b36817e8 SE |
1638 | |
1639 | reg = &event->hw.branch_reg; | |
1640 | if (reg->idx != EXTRA_REG_NONE) | |
1641 | __intel_shared_reg_put_constraints(cpuc, reg); | |
efc9f05d | 1642 | } |
a7e3ed1e | 1643 | |
efc9f05d SE |
1644 | static void intel_put_event_constraints(struct cpu_hw_events *cpuc, |
1645 | struct perf_event *event) | |
1646 | { | |
1647 | intel_put_shared_regs_event_constraints(cpuc, event); | |
a7e3ed1e AK |
1648 | } |
1649 | ||
0780c927 | 1650 | static void intel_pebs_aliases_core2(struct perf_event *event) |
b4cdc5c2 | 1651 | { |
0780c927 | 1652 | if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) { |
7639dae0 PZ |
1653 | /* |
1654 | * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P | |
1655 | * (0x003c) so that we can use it with PEBS. | |
1656 | * | |
1657 | * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't | |
1658 | * PEBS capable. However we can use INST_RETIRED.ANY_P | |
1659 | * (0x00c0), which is a PEBS capable event, to get the same | |
1660 | * count. | |
1661 | * | |
1662 | * INST_RETIRED.ANY_P counts the number of cycles that retires | |
1663 | * CNTMASK instructions. By setting CNTMASK to a value (16) | |
1664 | * larger than the maximum number of instructions that can be | |
1665 | * retired per cycle (4) and then inverting the condition, we | |
1666 | * count all cycles that retire 16 or less instructions, which | |
1667 | * is every cycle. | |
1668 | * | |
1669 | * Thereby we gain a PEBS capable cycle counter. | |
1670 | */ | |
f9b4eeb8 PZ |
1671 | u64 alt_config = X86_CONFIG(.event=0xc0, .inv=1, .cmask=16); |
1672 | ||
0780c927 PZ |
1673 | alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK); |
1674 | event->hw.config = alt_config; | |
1675 | } | |
1676 | } | |
1677 | ||
1678 | static void intel_pebs_aliases_snb(struct perf_event *event) | |
1679 | { | |
1680 | if ((event->hw.config & X86_RAW_EVENT_MASK) == 0x003c) { | |
1681 | /* | |
1682 | * Use an alternative encoding for CPU_CLK_UNHALTED.THREAD_P | |
1683 | * (0x003c) so that we can use it with PEBS. | |
1684 | * | |
1685 | * The regular CPU_CLK_UNHALTED.THREAD_P event (0x003c) isn't | |
1686 | * PEBS capable. However we can use UOPS_RETIRED.ALL | |
1687 | * (0x01c2), which is a PEBS capable event, to get the same | |
1688 | * count. | |
1689 | * | |
1690 | * UOPS_RETIRED.ALL counts the number of cycles that retires | |
1691 | * CNTMASK micro-ops. By setting CNTMASK to a value (16) | |
1692 | * larger than the maximum number of micro-ops that can be | |
1693 | * retired per cycle (4) and then inverting the condition, we | |
1694 | * count all cycles that retire 16 or less micro-ops, which | |
1695 | * is every cycle. | |
1696 | * | |
1697 | * Thereby we gain a PEBS capable cycle counter. | |
1698 | */ | |
1699 | u64 alt_config = X86_CONFIG(.event=0xc2, .umask=0x01, .inv=1, .cmask=16); | |
7639dae0 PZ |
1700 | |
1701 | alt_config |= (event->hw.config & ~X86_RAW_EVENT_MASK); | |
1702 | event->hw.config = alt_config; | |
1703 | } | |
0780c927 PZ |
1704 | } |
1705 | ||
1706 | static int intel_pmu_hw_config(struct perf_event *event) | |
1707 | { | |
1708 | int ret = x86_pmu_hw_config(event); | |
1709 | ||
1710 | if (ret) | |
1711 | return ret; | |
1712 | ||
1713 | if (event->attr.precise_ip && x86_pmu.pebs_aliases) | |
1714 | x86_pmu.pebs_aliases(event); | |
7639dae0 | 1715 | |
60ce0fbd SE |
1716 | if (intel_pmu_needs_lbr_smpl(event)) { |
1717 | ret = intel_pmu_setup_lbr_filter(event); | |
1718 | if (ret) | |
1719 | return ret; | |
1720 | } | |
1721 | ||
b4cdc5c2 PZ |
1722 | if (event->attr.type != PERF_TYPE_RAW) |
1723 | return 0; | |
1724 | ||
1725 | if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY)) | |
1726 | return 0; | |
1727 | ||
1728 | if (x86_pmu.version < 3) | |
1729 | return -EINVAL; | |
1730 | ||
1731 | if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN)) | |
1732 | return -EACCES; | |
1733 | ||
1734 | event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY; | |
1735 | ||
1736 | return 0; | |
1737 | } | |
1738 | ||
144d31e6 GN |
1739 | struct perf_guest_switch_msr *perf_guest_get_msrs(int *nr) |
1740 | { | |
1741 | if (x86_pmu.guest_get_msrs) | |
1742 | return x86_pmu.guest_get_msrs(nr); | |
1743 | *nr = 0; | |
1744 | return NULL; | |
1745 | } | |
1746 | EXPORT_SYMBOL_GPL(perf_guest_get_msrs); | |
1747 | ||
1748 | static struct perf_guest_switch_msr *intel_guest_get_msrs(int *nr) | |
1749 | { | |
1750 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | |
1751 | struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; | |
1752 | ||
1753 | arr[0].msr = MSR_CORE_PERF_GLOBAL_CTRL; | |
1754 | arr[0].host = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_guest_mask; | |
1755 | arr[0].guest = x86_pmu.intel_ctrl & ~cpuc->intel_ctrl_host_mask; | |
26a4f3c0 GN |
1756 | /* |
1757 | * If PMU counter has PEBS enabled it is not enough to disable counter | |
1758 | * on a guest entry since PEBS memory write can overshoot guest entry | |
1759 | * and corrupt guest memory. Disabling PEBS solves the problem. | |
1760 | */ | |
1761 | arr[1].msr = MSR_IA32_PEBS_ENABLE; | |
1762 | arr[1].host = cpuc->pebs_enabled; | |
1763 | arr[1].guest = 0; | |
144d31e6 | 1764 | |
26a4f3c0 | 1765 | *nr = 2; |
144d31e6 GN |
1766 | return arr; |
1767 | } | |
1768 | ||
1769 | static struct perf_guest_switch_msr *core_guest_get_msrs(int *nr) | |
1770 | { | |
1771 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | |
1772 | struct perf_guest_switch_msr *arr = cpuc->guest_switch_msrs; | |
1773 | int idx; | |
1774 | ||
1775 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | |
1776 | struct perf_event *event = cpuc->events[idx]; | |
1777 | ||
1778 | arr[idx].msr = x86_pmu_config_addr(idx); | |
1779 | arr[idx].host = arr[idx].guest = 0; | |
1780 | ||
1781 | if (!test_bit(idx, cpuc->active_mask)) | |
1782 | continue; | |
1783 | ||
1784 | arr[idx].host = arr[idx].guest = | |
1785 | event->hw.config | ARCH_PERFMON_EVENTSEL_ENABLE; | |
1786 | ||
1787 | if (event->attr.exclude_host) | |
1788 | arr[idx].host &= ~ARCH_PERFMON_EVENTSEL_ENABLE; | |
1789 | else if (event->attr.exclude_guest) | |
1790 | arr[idx].guest &= ~ARCH_PERFMON_EVENTSEL_ENABLE; | |
1791 | } | |
1792 | ||
1793 | *nr = x86_pmu.num_counters; | |
1794 | return arr; | |
1795 | } | |
1796 | ||
1797 | static void core_pmu_enable_event(struct perf_event *event) | |
1798 | { | |
1799 | if (!event->attr.exclude_host) | |
1800 | x86_pmu_enable_event(event); | |
1801 | } | |
1802 | ||
1803 | static void core_pmu_enable_all(int added) | |
1804 | { | |
1805 | struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events); | |
1806 | int idx; | |
1807 | ||
1808 | for (idx = 0; idx < x86_pmu.num_counters; idx++) { | |
1809 | struct hw_perf_event *hwc = &cpuc->events[idx]->hw; | |
1810 | ||
1811 | if (!test_bit(idx, cpuc->active_mask) || | |
1812 | cpuc->events[idx]->attr.exclude_host) | |
1813 | continue; | |
1814 | ||
1815 | __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE); | |
1816 | } | |
1817 | } | |
1818 | ||
3a632cb2 AK |
1819 | static int hsw_hw_config(struct perf_event *event) |
1820 | { | |
1821 | int ret = intel_pmu_hw_config(event); | |
1822 | ||
1823 | if (ret) | |
1824 | return ret; | |
1825 | if (!boot_cpu_has(X86_FEATURE_RTM) && !boot_cpu_has(X86_FEATURE_HLE)) | |
1826 | return 0; | |
1827 | event->hw.config |= event->attr.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED); | |
1828 | ||
1829 | /* | |
1830 | * IN_TX/IN_TX-CP filters are not supported by the Haswell PMU with | |
1831 | * PEBS or in ANY thread mode. Since the results are non-sensical forbid | |
1832 | * this combination. | |
1833 | */ | |
1834 | if ((event->hw.config & (HSW_IN_TX|HSW_IN_TX_CHECKPOINTED)) && | |
1835 | ((event->hw.config & ARCH_PERFMON_EVENTSEL_ANY) || | |
1836 | event->attr.precise_ip > 0)) | |
1837 | return -EOPNOTSUPP; | |
1838 | ||
1839 | return 0; | |
1840 | } | |
1841 | ||
1842 | static struct event_constraint counter2_constraint = | |
1843 | EVENT_CONSTRAINT(0, 0x4, 0); | |
1844 | ||
1845 | static struct event_constraint * | |
1846 | hsw_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event) | |
1847 | { | |
1848 | struct event_constraint *c = intel_get_event_constraints(cpuc, event); | |
1849 | ||
1850 | /* Handle special quirk on in_tx_checkpointed only in counter 2 */ | |
1851 | if (event->hw.config & HSW_IN_TX_CHECKPOINTED) { | |
1852 | if (c->idxmsk64 & (1U << 2)) | |
1853 | return &counter2_constraint; | |
1854 | return &emptyconstraint; | |
1855 | } | |
1856 | ||
1857 | return c; | |
1858 | } | |
1859 | ||
641cc938 JO |
1860 | PMU_FORMAT_ATTR(event, "config:0-7" ); |
1861 | PMU_FORMAT_ATTR(umask, "config:8-15" ); | |
1862 | PMU_FORMAT_ATTR(edge, "config:18" ); | |
1863 | PMU_FORMAT_ATTR(pc, "config:19" ); | |
1864 | PMU_FORMAT_ATTR(any, "config:21" ); /* v3 + */ | |
1865 | PMU_FORMAT_ATTR(inv, "config:23" ); | |
1866 | PMU_FORMAT_ATTR(cmask, "config:24-31" ); | |
3a632cb2 AK |
1867 | PMU_FORMAT_ATTR(in_tx, "config:32"); |
1868 | PMU_FORMAT_ATTR(in_tx_cp, "config:33"); | |
641cc938 JO |
1869 | |
1870 | static struct attribute *intel_arch_formats_attr[] = { | |
1871 | &format_attr_event.attr, | |
1872 | &format_attr_umask.attr, | |
1873 | &format_attr_edge.attr, | |
1874 | &format_attr_pc.attr, | |
1875 | &format_attr_inv.attr, | |
1876 | &format_attr_cmask.attr, | |
1877 | NULL, | |
1878 | }; | |
1879 | ||
0bf79d44 JO |
1880 | ssize_t intel_event_sysfs_show(char *page, u64 config) |
1881 | { | |
1882 | u64 event = (config & ARCH_PERFMON_EVENTSEL_EVENT); | |
1883 | ||
1884 | return x86_event_sysfs_show(page, config, event); | |
1885 | } | |
1886 | ||
caaa8be3 | 1887 | static __initconst const struct x86_pmu core_pmu = { |
f22f54f4 PZ |
1888 | .name = "core", |
1889 | .handle_irq = x86_pmu_handle_irq, | |
1890 | .disable_all = x86_pmu_disable_all, | |
144d31e6 GN |
1891 | .enable_all = core_pmu_enable_all, |
1892 | .enable = core_pmu_enable_event, | |
f22f54f4 | 1893 | .disable = x86_pmu_disable_event, |
b4cdc5c2 | 1894 | .hw_config = x86_pmu_hw_config, |
a072738e | 1895 | .schedule_events = x86_schedule_events, |
f22f54f4 PZ |
1896 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
1897 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | |
1898 | .event_map = intel_pmu_event_map, | |
f22f54f4 PZ |
1899 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
1900 | .apic = 1, | |
1901 | /* | |
1902 | * Intel PMCs cannot be accessed sanely above 32 bit width, | |
1903 | * so we install an artificial 1<<31 period regardless of | |
1904 | * the generic event period: | |
1905 | */ | |
1906 | .max_period = (1ULL << 31) - 1, | |
1907 | .get_event_constraints = intel_get_event_constraints, | |
a7e3ed1e | 1908 | .put_event_constraints = intel_put_event_constraints, |
f22f54f4 | 1909 | .event_constraints = intel_core_event_constraints, |
144d31e6 | 1910 | .guest_get_msrs = core_guest_get_msrs, |
641cc938 | 1911 | .format_attrs = intel_arch_formats_attr, |
0bf79d44 | 1912 | .events_sysfs_show = intel_event_sysfs_show, |
f22f54f4 PZ |
1913 | }; |
1914 | ||
de0428a7 | 1915 | struct intel_shared_regs *allocate_shared_regs(int cpu) |
efc9f05d SE |
1916 | { |
1917 | struct intel_shared_regs *regs; | |
1918 | int i; | |
1919 | ||
1920 | regs = kzalloc_node(sizeof(struct intel_shared_regs), | |
1921 | GFP_KERNEL, cpu_to_node(cpu)); | |
1922 | if (regs) { | |
1923 | /* | |
1924 | * initialize the locks to keep lockdep happy | |
1925 | */ | |
1926 | for (i = 0; i < EXTRA_REG_MAX; i++) | |
1927 | raw_spin_lock_init(®s->regs[i].lock); | |
1928 | ||
1929 | regs->core_id = -1; | |
1930 | } | |
1931 | return regs; | |
1932 | } | |
1933 | ||
a7e3ed1e AK |
1934 | static int intel_pmu_cpu_prepare(int cpu) |
1935 | { | |
1936 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); | |
1937 | ||
b36817e8 | 1938 | if (!(x86_pmu.extra_regs || x86_pmu.lbr_sel_map)) |
69092624 LM |
1939 | return NOTIFY_OK; |
1940 | ||
efc9f05d SE |
1941 | cpuc->shared_regs = allocate_shared_regs(cpu); |
1942 | if (!cpuc->shared_regs) | |
a7e3ed1e AK |
1943 | return NOTIFY_BAD; |
1944 | ||
a7e3ed1e AK |
1945 | return NOTIFY_OK; |
1946 | } | |
1947 | ||
74846d35 PZ |
1948 | static void intel_pmu_cpu_starting(int cpu) |
1949 | { | |
a7e3ed1e AK |
1950 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); |
1951 | int core_id = topology_core_id(cpu); | |
1952 | int i; | |
1953 | ||
69092624 LM |
1954 | init_debug_store_on_cpu(cpu); |
1955 | /* | |
1956 | * Deal with CPUs that don't clear their LBRs on power-up. | |
1957 | */ | |
1958 | intel_pmu_lbr_reset(); | |
1959 | ||
b36817e8 SE |
1960 | cpuc->lbr_sel = NULL; |
1961 | ||
1962 | if (!cpuc->shared_regs) | |
69092624 LM |
1963 | return; |
1964 | ||
b36817e8 SE |
1965 | if (!(x86_pmu.er_flags & ERF_NO_HT_SHARING)) { |
1966 | for_each_cpu(i, topology_thread_cpumask(cpu)) { | |
1967 | struct intel_shared_regs *pc; | |
a7e3ed1e | 1968 | |
b36817e8 SE |
1969 | pc = per_cpu(cpu_hw_events, i).shared_regs; |
1970 | if (pc && pc->core_id == core_id) { | |
1971 | cpuc->kfree_on_online = cpuc->shared_regs; | |
1972 | cpuc->shared_regs = pc; | |
1973 | break; | |
1974 | } | |
a7e3ed1e | 1975 | } |
b36817e8 SE |
1976 | cpuc->shared_regs->core_id = core_id; |
1977 | cpuc->shared_regs->refcnt++; | |
a7e3ed1e AK |
1978 | } |
1979 | ||
b36817e8 SE |
1980 | if (x86_pmu.lbr_sel_map) |
1981 | cpuc->lbr_sel = &cpuc->shared_regs->regs[EXTRA_REG_LBR]; | |
74846d35 PZ |
1982 | } |
1983 | ||
1984 | static void intel_pmu_cpu_dying(int cpu) | |
1985 | { | |
a7e3ed1e | 1986 | struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); |
efc9f05d | 1987 | struct intel_shared_regs *pc; |
a7e3ed1e | 1988 | |
efc9f05d | 1989 | pc = cpuc->shared_regs; |
a7e3ed1e AK |
1990 | if (pc) { |
1991 | if (pc->core_id == -1 || --pc->refcnt == 0) | |
1992 | kfree(pc); | |
efc9f05d | 1993 | cpuc->shared_regs = NULL; |
a7e3ed1e AK |
1994 | } |
1995 | ||
74846d35 PZ |
1996 | fini_debug_store_on_cpu(cpu); |
1997 | } | |
1998 | ||
d010b332 SE |
1999 | static void intel_pmu_flush_branch_stack(void) |
2000 | { | |
2001 | /* | |
2002 | * Intel LBR does not tag entries with the | |
2003 | * PID of the current task, then we need to | |
2004 | * flush it on ctxsw | |
2005 | * For now, we simply reset it | |
2006 | */ | |
2007 | if (x86_pmu.lbr_nr) | |
2008 | intel_pmu_lbr_reset(); | |
2009 | } | |
2010 | ||
641cc938 JO |
2011 | PMU_FORMAT_ATTR(offcore_rsp, "config1:0-63"); |
2012 | ||
a63fcab4 SE |
2013 | PMU_FORMAT_ATTR(ldlat, "config1:0-15"); |
2014 | ||
641cc938 JO |
2015 | static struct attribute *intel_arch3_formats_attr[] = { |
2016 | &format_attr_event.attr, | |
2017 | &format_attr_umask.attr, | |
2018 | &format_attr_edge.attr, | |
2019 | &format_attr_pc.attr, | |
2020 | &format_attr_any.attr, | |
2021 | &format_attr_inv.attr, | |
2022 | &format_attr_cmask.attr, | |
3a632cb2 AK |
2023 | &format_attr_in_tx.attr, |
2024 | &format_attr_in_tx_cp.attr, | |
641cc938 JO |
2025 | |
2026 | &format_attr_offcore_rsp.attr, /* XXX do NHM/WSM + SNB breakout */ | |
a63fcab4 | 2027 | &format_attr_ldlat.attr, /* PEBS load latency */ |
641cc938 JO |
2028 | NULL, |
2029 | }; | |
2030 | ||
caaa8be3 | 2031 | static __initconst const struct x86_pmu intel_pmu = { |
f22f54f4 PZ |
2032 | .name = "Intel", |
2033 | .handle_irq = intel_pmu_handle_irq, | |
2034 | .disable_all = intel_pmu_disable_all, | |
2035 | .enable_all = intel_pmu_enable_all, | |
2036 | .enable = intel_pmu_enable_event, | |
2037 | .disable = intel_pmu_disable_event, | |
b4cdc5c2 | 2038 | .hw_config = intel_pmu_hw_config, |
a072738e | 2039 | .schedule_events = x86_schedule_events, |
f22f54f4 PZ |
2040 | .eventsel = MSR_ARCH_PERFMON_EVENTSEL0, |
2041 | .perfctr = MSR_ARCH_PERFMON_PERFCTR0, | |
2042 | .event_map = intel_pmu_event_map, | |
f22f54f4 PZ |
2043 | .max_events = ARRAY_SIZE(intel_perfmon_event_map), |
2044 | .apic = 1, | |
2045 | /* | |
2046 | * Intel PMCs cannot be accessed sanely above 32 bit width, | |
2047 | * so we install an artificial 1<<31 period regardless of | |
2048 | * the generic event period: | |
2049 | */ | |
2050 | .max_period = (1ULL << 31) - 1, | |
3f6da390 | 2051 | .get_event_constraints = intel_get_event_constraints, |
a7e3ed1e | 2052 | .put_event_constraints = intel_put_event_constraints, |
0780c927 | 2053 | .pebs_aliases = intel_pebs_aliases_core2, |
3f6da390 | 2054 | |
641cc938 | 2055 | .format_attrs = intel_arch3_formats_attr, |
0bf79d44 | 2056 | .events_sysfs_show = intel_event_sysfs_show, |
641cc938 | 2057 | |
a7e3ed1e | 2058 | .cpu_prepare = intel_pmu_cpu_prepare, |
74846d35 PZ |
2059 | .cpu_starting = intel_pmu_cpu_starting, |
2060 | .cpu_dying = intel_pmu_cpu_dying, | |
144d31e6 | 2061 | .guest_get_msrs = intel_guest_get_msrs, |
d010b332 | 2062 | .flush_branch_stack = intel_pmu_flush_branch_stack, |
f22f54f4 PZ |
2063 | }; |
2064 | ||
c1d6f42f | 2065 | static __init void intel_clovertown_quirk(void) |
3c44780b PZ |
2066 | { |
2067 | /* | |
2068 | * PEBS is unreliable due to: | |
2069 | * | |
2070 | * AJ67 - PEBS may experience CPL leaks | |
2071 | * AJ68 - PEBS PMI may be delayed by one event | |
2072 | * AJ69 - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12] | |
2073 | * AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS | |
2074 | * | |
2075 | * AJ67 could be worked around by restricting the OS/USR flags. | |
2076 | * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI. | |
2077 | * | |
2078 | * AJ106 could possibly be worked around by not allowing LBR | |
2079 | * usage from PEBS, including the fixup. | |
2080 | * AJ68 could possibly be worked around by always programming | |
ec75a716 | 2081 | * a pebs_event_reset[0] value and coping with the lost events. |
3c44780b PZ |
2082 | * |
2083 | * But taken together it might just make sense to not enable PEBS on | |
2084 | * these chips. | |
2085 | */ | |
c767a54b | 2086 | pr_warn("PEBS disabled due to CPU errata\n"); |
3c44780b PZ |
2087 | x86_pmu.pebs = 0; |
2088 | x86_pmu.pebs_constraints = NULL; | |
2089 | } | |
2090 | ||
c93dc84c PZ |
2091 | static int intel_snb_pebs_broken(int cpu) |
2092 | { | |
2093 | u32 rev = UINT_MAX; /* default to broken for unknown models */ | |
2094 | ||
2095 | switch (cpu_data(cpu).x86_model) { | |
2096 | case 42: /* SNB */ | |
2097 | rev = 0x28; | |
2098 | break; | |
2099 | ||
2100 | case 45: /* SNB-EP */ | |
2101 | switch (cpu_data(cpu).x86_mask) { | |
2102 | case 6: rev = 0x618; break; | |
2103 | case 7: rev = 0x70c; break; | |
2104 | } | |
2105 | } | |
2106 | ||
2107 | return (cpu_data(cpu).microcode < rev); | |
2108 | } | |
2109 | ||
2110 | static void intel_snb_check_microcode(void) | |
2111 | { | |
2112 | int pebs_broken = 0; | |
2113 | int cpu; | |
2114 | ||
2115 | get_online_cpus(); | |
2116 | for_each_online_cpu(cpu) { | |
2117 | if ((pebs_broken = intel_snb_pebs_broken(cpu))) | |
2118 | break; | |
2119 | } | |
2120 | put_online_cpus(); | |
2121 | ||
2122 | if (pebs_broken == x86_pmu.pebs_broken) | |
2123 | return; | |
2124 | ||
2125 | /* | |
2126 | * Serialized by the microcode lock.. | |
2127 | */ | |
2128 | if (x86_pmu.pebs_broken) { | |
2129 | pr_info("PEBS enabled due to microcode update\n"); | |
2130 | x86_pmu.pebs_broken = 0; | |
2131 | } else { | |
2132 | pr_info("PEBS disabled due to CPU errata, please upgrade microcode\n"); | |
2133 | x86_pmu.pebs_broken = 1; | |
2134 | } | |
2135 | } | |
2136 | ||
c1d6f42f | 2137 | static __init void intel_sandybridge_quirk(void) |
6a600a8b | 2138 | { |
c93dc84c PZ |
2139 | x86_pmu.check_microcode = intel_snb_check_microcode; |
2140 | intel_snb_check_microcode(); | |
6a600a8b PZ |
2141 | } |
2142 | ||
c1d6f42f PZ |
2143 | static const struct { int id; char *name; } intel_arch_events_map[] __initconst = { |
2144 | { PERF_COUNT_HW_CPU_CYCLES, "cpu cycles" }, | |
2145 | { PERF_COUNT_HW_INSTRUCTIONS, "instructions" }, | |
2146 | { PERF_COUNT_HW_BUS_CYCLES, "bus cycles" }, | |
2147 | { PERF_COUNT_HW_CACHE_REFERENCES, "cache references" }, | |
2148 | { PERF_COUNT_HW_CACHE_MISSES, "cache misses" }, | |
2149 | { PERF_COUNT_HW_BRANCH_INSTRUCTIONS, "branch instructions" }, | |
2150 | { PERF_COUNT_HW_BRANCH_MISSES, "branch misses" }, | |
ffb871bc GN |
2151 | }; |
2152 | ||
c1d6f42f PZ |
2153 | static __init void intel_arch_events_quirk(void) |
2154 | { | |
2155 | int bit; | |
2156 | ||
2157 | /* disable event that reported as not presend by cpuid */ | |
2158 | for_each_set_bit(bit, x86_pmu.events_mask, ARRAY_SIZE(intel_arch_events_map)) { | |
2159 | intel_perfmon_event_map[intel_arch_events_map[bit].id] = 0; | |
c767a54b JP |
2160 | pr_warn("CPUID marked event: \'%s\' unavailable\n", |
2161 | intel_arch_events_map[bit].name); | |
c1d6f42f PZ |
2162 | } |
2163 | } | |
2164 | ||
2165 | static __init void intel_nehalem_quirk(void) | |
2166 | { | |
2167 | union cpuid10_ebx ebx; | |
2168 | ||
2169 | ebx.full = x86_pmu.events_maskl; | |
2170 | if (ebx.split.no_branch_misses_retired) { | |
2171 | /* | |
2172 | * Erratum AAJ80 detected, we work it around by using | |
2173 | * the BR_MISP_EXEC.ANY event. This will over-count | |
2174 | * branch-misses, but it's still much better than the | |
2175 | * architectural event which is often completely bogus: | |
2176 | */ | |
2177 | intel_perfmon_event_map[PERF_COUNT_HW_BRANCH_MISSES] = 0x7f89; | |
2178 | ebx.split.no_branch_misses_retired = 0; | |
2179 | x86_pmu.events_maskl = ebx.full; | |
c767a54b | 2180 | pr_info("CPU erratum AAJ80 worked around\n"); |
c1d6f42f PZ |
2181 | } |
2182 | } | |
2183 | ||
f9134f36 AK |
2184 | EVENT_ATTR_STR(mem-loads, mem_ld_hsw, "event=0xcd,umask=0x1,ldlat=3"); |
2185 | EVENT_ATTR_STR(mem-stores, mem_st_hsw, "event=0xd0,umask=0x82") | |
2186 | ||
2187 | static struct attribute *hsw_events_attrs[] = { | |
2188 | EVENT_PTR(mem_ld_hsw), | |
2189 | EVENT_PTR(mem_st_hsw), | |
2190 | NULL | |
2191 | }; | |
2192 | ||
de0428a7 | 2193 | __init int intel_pmu_init(void) |
f22f54f4 PZ |
2194 | { |
2195 | union cpuid10_edx edx; | |
2196 | union cpuid10_eax eax; | |
ffb871bc | 2197 | union cpuid10_ebx ebx; |
a1eac7ac | 2198 | struct event_constraint *c; |
f22f54f4 | 2199 | unsigned int unused; |
f22f54f4 PZ |
2200 | int version; |
2201 | ||
2202 | if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) { | |
a072738e CG |
2203 | switch (boot_cpu_data.x86) { |
2204 | case 0x6: | |
2205 | return p6_pmu_init(); | |
e717bf4e VW |
2206 | case 0xb: |
2207 | return knc_pmu_init(); | |
a072738e CG |
2208 | case 0xf: |
2209 | return p4_pmu_init(); | |
2210 | } | |
f22f54f4 | 2211 | return -ENODEV; |
f22f54f4 PZ |
2212 | } |
2213 | ||
2214 | /* | |
2215 | * Check whether the Architectural PerfMon supports | |
2216 | * Branch Misses Retired hw_event or not. | |
2217 | */ | |
ffb871bc GN |
2218 | cpuid(10, &eax.full, &ebx.full, &unused, &edx.full); |
2219 | if (eax.split.mask_length < ARCH_PERFMON_EVENTS_COUNT) | |
f22f54f4 PZ |
2220 | return -ENODEV; |
2221 | ||
2222 | version = eax.split.version_id; | |
2223 | if (version < 2) | |
2224 | x86_pmu = core_pmu; | |
2225 | else | |
2226 | x86_pmu = intel_pmu; | |
2227 | ||
2228 | x86_pmu.version = version; | |
948b1bb8 RR |
2229 | x86_pmu.num_counters = eax.split.num_counters; |
2230 | x86_pmu.cntval_bits = eax.split.bit_width; | |
2231 | x86_pmu.cntval_mask = (1ULL << eax.split.bit_width) - 1; | |
f22f54f4 | 2232 | |
c1d6f42f PZ |
2233 | x86_pmu.events_maskl = ebx.full; |
2234 | x86_pmu.events_mask_len = eax.split.mask_length; | |
2235 | ||
70ab7003 AK |
2236 | x86_pmu.max_pebs_events = min_t(unsigned, MAX_PEBS_EVENTS, x86_pmu.num_counters); |
2237 | ||
f22f54f4 PZ |
2238 | /* |
2239 | * Quirk: v2 perfmon does not report fixed-purpose events, so | |
2240 | * assume at least 3 events: | |
2241 | */ | |
2242 | if (version > 1) | |
948b1bb8 | 2243 | x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3); |
f22f54f4 | 2244 | |
8db909a7 PZ |
2245 | /* |
2246 | * v2 and above have a perf capabilities MSR | |
2247 | */ | |
2248 | if (version > 1) { | |
2249 | u64 capabilities; | |
2250 | ||
2251 | rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities); | |
2252 | x86_pmu.intel_cap.capabilities = capabilities; | |
2253 | } | |
2254 | ||
ca037701 PZ |
2255 | intel_ds_init(); |
2256 | ||
c1d6f42f PZ |
2257 | x86_add_quirk(intel_arch_events_quirk); /* Install first, so it runs last */ |
2258 | ||
f22f54f4 PZ |
2259 | /* |
2260 | * Install the hw-cache-events table: | |
2261 | */ | |
2262 | switch (boot_cpu_data.x86_model) { | |
2263 | case 14: /* 65 nm core solo/duo, "Yonah" */ | |
2264 | pr_cont("Core events, "); | |
2265 | break; | |
2266 | ||
2267 | case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */ | |
c1d6f42f | 2268 | x86_add_quirk(intel_clovertown_quirk); |
f22f54f4 PZ |
2269 | case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */ |
2270 | case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */ | |
2271 | case 29: /* six-core 45 nm xeon "Dunnington" */ | |
2272 | memcpy(hw_cache_event_ids, core2_hw_cache_event_ids, | |
2273 | sizeof(hw_cache_event_ids)); | |
2274 | ||
caff2bef PZ |
2275 | intel_pmu_lbr_init_core(); |
2276 | ||
f22f54f4 | 2277 | x86_pmu.event_constraints = intel_core2_event_constraints; |
17e31629 | 2278 | x86_pmu.pebs_constraints = intel_core2_pebs_event_constraints; |
f22f54f4 PZ |
2279 | pr_cont("Core2 events, "); |
2280 | break; | |
2281 | ||
2282 | case 26: /* 45 nm nehalem, "Bloomfield" */ | |
2283 | case 30: /* 45 nm nehalem, "Lynnfield" */ | |
134fbadf | 2284 | case 46: /* 45 nm nehalem-ex, "Beckton" */ |
f22f54f4 PZ |
2285 | memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids, |
2286 | sizeof(hw_cache_event_ids)); | |
e994d7d2 AK |
2287 | memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs, |
2288 | sizeof(hw_cache_extra_regs)); | |
f22f54f4 | 2289 | |
caff2bef PZ |
2290 | intel_pmu_lbr_init_nhm(); |
2291 | ||
f22f54f4 | 2292 | x86_pmu.event_constraints = intel_nehalem_event_constraints; |
17e31629 | 2293 | x86_pmu.pebs_constraints = intel_nehalem_pebs_event_constraints; |
11164cd4 | 2294 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
a7e3ed1e | 2295 | x86_pmu.extra_regs = intel_nehalem_extra_regs; |
ec75a716 | 2296 | |
f20093ee SE |
2297 | x86_pmu.cpu_events = nhm_events_attrs; |
2298 | ||
91fc4cc0 | 2299 | /* UOPS_ISSUED.STALLED_CYCLES */ |
f9b4eeb8 PZ |
2300 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = |
2301 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
91fc4cc0 | 2302 | /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */ |
f9b4eeb8 PZ |
2303 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = |
2304 | X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1); | |
94403f88 | 2305 | |
c1d6f42f | 2306 | x86_add_quirk(intel_nehalem_quirk); |
ec75a716 | 2307 | |
11164cd4 | 2308 | pr_cont("Nehalem events, "); |
f22f54f4 | 2309 | break; |
caff2bef | 2310 | |
b622d644 | 2311 | case 28: /* Atom */ |
0927b482 SL |
2312 | case 38: /* Lincroft */ |
2313 | case 39: /* Penwell */ | |
2314 | case 53: /* Cloverview */ | |
2315 | case 54: /* Cedarview */ | |
f22f54f4 PZ |
2316 | memcpy(hw_cache_event_ids, atom_hw_cache_event_ids, |
2317 | sizeof(hw_cache_event_ids)); | |
2318 | ||
caff2bef PZ |
2319 | intel_pmu_lbr_init_atom(); |
2320 | ||
f22f54f4 | 2321 | x86_pmu.event_constraints = intel_gen_event_constraints; |
17e31629 | 2322 | x86_pmu.pebs_constraints = intel_atom_pebs_event_constraints; |
f22f54f4 PZ |
2323 | pr_cont("Atom events, "); |
2324 | break; | |
2325 | ||
1fa64180 YZ |
2326 | case 55: /* Atom 22nm "Silvermont" */ |
2327 | memcpy(hw_cache_event_ids, slm_hw_cache_event_ids, | |
2328 | sizeof(hw_cache_event_ids)); | |
2329 | memcpy(hw_cache_extra_regs, slm_hw_cache_extra_regs, | |
2330 | sizeof(hw_cache_extra_regs)); | |
2331 | ||
2332 | intel_pmu_lbr_init_atom(); | |
2333 | ||
2334 | x86_pmu.event_constraints = intel_slm_event_constraints; | |
2335 | x86_pmu.pebs_constraints = intel_slm_pebs_event_constraints; | |
2336 | x86_pmu.extra_regs = intel_slm_extra_regs; | |
2337 | x86_pmu.er_flags |= ERF_HAS_RSP_1; | |
2338 | pr_cont("Silvermont events, "); | |
2339 | break; | |
2340 | ||
f22f54f4 PZ |
2341 | case 37: /* 32 nm nehalem, "Clarkdale" */ |
2342 | case 44: /* 32 nm nehalem, "Gulftown" */ | |
b2508e82 | 2343 | case 47: /* 32 nm Xeon E7 */ |
f22f54f4 PZ |
2344 | memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids, |
2345 | sizeof(hw_cache_event_ids)); | |
e994d7d2 AK |
2346 | memcpy(hw_cache_extra_regs, nehalem_hw_cache_extra_regs, |
2347 | sizeof(hw_cache_extra_regs)); | |
f22f54f4 | 2348 | |
caff2bef PZ |
2349 | intel_pmu_lbr_init_nhm(); |
2350 | ||
f22f54f4 | 2351 | x86_pmu.event_constraints = intel_westmere_event_constraints; |
40b91cd1 | 2352 | x86_pmu.enable_all = intel_pmu_nhm_enable_all; |
17e31629 | 2353 | x86_pmu.pebs_constraints = intel_westmere_pebs_event_constraints; |
a7e3ed1e | 2354 | x86_pmu.extra_regs = intel_westmere_extra_regs; |
b79e8941 | 2355 | x86_pmu.er_flags |= ERF_HAS_RSP_1; |
30112039 | 2356 | |
f20093ee SE |
2357 | x86_pmu.cpu_events = nhm_events_attrs; |
2358 | ||
30112039 | 2359 | /* UOPS_ISSUED.STALLED_CYCLES */ |
f9b4eeb8 PZ |
2360 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = |
2361 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
30112039 | 2362 | /* UOPS_EXECUTED.CORE_ACTIVE_CYCLES,c=1,i=1 */ |
f9b4eeb8 PZ |
2363 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = |
2364 | X86_CONFIG(.event=0xb1, .umask=0x3f, .inv=1, .cmask=1); | |
30112039 | 2365 | |
f22f54f4 PZ |
2366 | pr_cont("Westmere events, "); |
2367 | break; | |
b622d644 | 2368 | |
b06b3d49 | 2369 | case 42: /* SandyBridge */ |
a34668f6 | 2370 | case 45: /* SandyBridge, "Romely-EP" */ |
47a8863d | 2371 | x86_add_quirk(intel_sandybridge_quirk); |
b06b3d49 LM |
2372 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, |
2373 | sizeof(hw_cache_event_ids)); | |
74e6543f YZ |
2374 | memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs, |
2375 | sizeof(hw_cache_extra_regs)); | |
b06b3d49 | 2376 | |
c5cc2cd9 | 2377 | intel_pmu_lbr_init_snb(); |
b06b3d49 LM |
2378 | |
2379 | x86_pmu.event_constraints = intel_snb_event_constraints; | |
de0428a7 | 2380 | x86_pmu.pebs_constraints = intel_snb_pebs_event_constraints; |
0780c927 | 2381 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; |
f1923820 SE |
2382 | if (boot_cpu_data.x86_model == 45) |
2383 | x86_pmu.extra_regs = intel_snbep_extra_regs; | |
2384 | else | |
2385 | x86_pmu.extra_regs = intel_snb_extra_regs; | |
ee89cbc2 | 2386 | /* all extra regs are per-cpu when HT is on */ |
b79e8941 PZ |
2387 | x86_pmu.er_flags |= ERF_HAS_RSP_1; |
2388 | x86_pmu.er_flags |= ERF_NO_HT_SHARING; | |
e04d1b23 | 2389 | |
f20093ee SE |
2390 | x86_pmu.cpu_events = snb_events_attrs; |
2391 | ||
e04d1b23 | 2392 | /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */ |
f9b4eeb8 PZ |
2393 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = |
2394 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
e04d1b23 | 2395 | /* UOPS_DISPATCHED.THREAD,c=1,i=1 to count stall cycles*/ |
f9b4eeb8 PZ |
2396 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = |
2397 | X86_CONFIG(.event=0xb1, .umask=0x01, .inv=1, .cmask=1); | |
e04d1b23 | 2398 | |
b06b3d49 LM |
2399 | pr_cont("SandyBridge events, "); |
2400 | break; | |
20a36e39 | 2401 | case 58: /* IvyBridge */ |
923d8697 | 2402 | case 62: /* IvyBridge EP */ |
20a36e39 SE |
2403 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, |
2404 | sizeof(hw_cache_event_ids)); | |
2405 | memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs, | |
2406 | sizeof(hw_cache_extra_regs)); | |
2407 | ||
2408 | intel_pmu_lbr_init_snb(); | |
2409 | ||
69943182 | 2410 | x86_pmu.event_constraints = intel_ivb_event_constraints; |
20a36e39 SE |
2411 | x86_pmu.pebs_constraints = intel_ivb_pebs_event_constraints; |
2412 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; | |
f1923820 SE |
2413 | if (boot_cpu_data.x86_model == 62) |
2414 | x86_pmu.extra_regs = intel_snbep_extra_regs; | |
2415 | else | |
2416 | x86_pmu.extra_regs = intel_snb_extra_regs; | |
20a36e39 SE |
2417 | /* all extra regs are per-cpu when HT is on */ |
2418 | x86_pmu.er_flags |= ERF_HAS_RSP_1; | |
2419 | x86_pmu.er_flags |= ERF_NO_HT_SHARING; | |
2420 | ||
f20093ee SE |
2421 | x86_pmu.cpu_events = snb_events_attrs; |
2422 | ||
20a36e39 SE |
2423 | /* UOPS_ISSUED.ANY,c=1,i=1 to count stall cycles */ |
2424 | intel_perfmon_event_map[PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = | |
2425 | X86_CONFIG(.event=0x0e, .umask=0x01, .inv=1, .cmask=1); | |
2426 | ||
2427 | pr_cont("IvyBridge events, "); | |
2428 | break; | |
2429 | ||
b06b3d49 | 2430 | |
3a632cb2 AK |
2431 | case 60: /* Haswell Client */ |
2432 | case 70: | |
2433 | case 71: | |
2434 | case 63: | |
0499bd86 | 2435 | case 69: |
72db5596 | 2436 | x86_pmu.late_ack = true; |
3a632cb2 AK |
2437 | memcpy(hw_cache_event_ids, snb_hw_cache_event_ids, sizeof(hw_cache_event_ids)); |
2438 | memcpy(hw_cache_extra_regs, snb_hw_cache_extra_regs, sizeof(hw_cache_extra_regs)); | |
2439 | ||
2440 | intel_pmu_lbr_init_snb(); | |
2441 | ||
2442 | x86_pmu.event_constraints = intel_hsw_event_constraints; | |
3044318f | 2443 | x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints; |
3a632cb2 | 2444 | x86_pmu.extra_regs = intel_snb_extra_regs; |
3044318f | 2445 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; |
3a632cb2 AK |
2446 | /* all extra regs are per-cpu when HT is on */ |
2447 | x86_pmu.er_flags |= ERF_HAS_RSP_1; | |
2448 | x86_pmu.er_flags |= ERF_NO_HT_SHARING; | |
2449 | ||
2450 | x86_pmu.hw_config = hsw_hw_config; | |
2451 | x86_pmu.get_event_constraints = hsw_get_event_constraints; | |
f9134f36 | 2452 | x86_pmu.cpu_events = hsw_events_attrs; |
3a632cb2 AK |
2453 | pr_cont("Haswell events, "); |
2454 | break; | |
2455 | ||
f22f54f4 | 2456 | default: |
0af3ac1f AK |
2457 | switch (x86_pmu.version) { |
2458 | case 1: | |
2459 | x86_pmu.event_constraints = intel_v1_event_constraints; | |
2460 | pr_cont("generic architected perfmon v1, "); | |
2461 | break; | |
2462 | default: | |
2463 | /* | |
2464 | * default constraints for v2 and up | |
2465 | */ | |
2466 | x86_pmu.event_constraints = intel_gen_event_constraints; | |
2467 | pr_cont("generic architected perfmon, "); | |
2468 | break; | |
2469 | } | |
f22f54f4 | 2470 | } |
ffb871bc | 2471 | |
a1eac7ac RR |
2472 | if (x86_pmu.num_counters > INTEL_PMC_MAX_GENERIC) { |
2473 | WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!", | |
2474 | x86_pmu.num_counters, INTEL_PMC_MAX_GENERIC); | |
2475 | x86_pmu.num_counters = INTEL_PMC_MAX_GENERIC; | |
2476 | } | |
2477 | x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1; | |
2478 | ||
2479 | if (x86_pmu.num_counters_fixed > INTEL_PMC_MAX_FIXED) { | |
2480 | WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!", | |
2481 | x86_pmu.num_counters_fixed, INTEL_PMC_MAX_FIXED); | |
2482 | x86_pmu.num_counters_fixed = INTEL_PMC_MAX_FIXED; | |
2483 | } | |
2484 | ||
2485 | x86_pmu.intel_ctrl |= | |
2486 | ((1LL << x86_pmu.num_counters_fixed)-1) << INTEL_PMC_IDX_FIXED; | |
2487 | ||
2488 | if (x86_pmu.event_constraints) { | |
2489 | /* | |
2490 | * event on fixed counter2 (REF_CYCLES) only works on this | |
2491 | * counter, so do not extend mask to generic counters | |
2492 | */ | |
2493 | for_each_event_constraint(c, x86_pmu.event_constraints) { | |
3a632cb2 | 2494 | if (c->cmask != FIXED_EVENT_FLAGS |
a1eac7ac RR |
2495 | || c->idxmsk64 == INTEL_PMC_MSK_FIXED_REF_CYCLES) { |
2496 | continue; | |
2497 | } | |
2498 | ||
2499 | c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1; | |
2500 | c->weight += x86_pmu.num_counters; | |
2501 | } | |
2502 | } | |
2503 | ||
069e0c3c AK |
2504 | /* Support full width counters using alternative MSR range */ |
2505 | if (x86_pmu.intel_cap.full_width_write) { | |
2506 | x86_pmu.max_period = x86_pmu.cntval_mask; | |
2507 | x86_pmu.perfctr = MSR_IA32_PMC0; | |
2508 | pr_cont("full-width counters, "); | |
2509 | } | |
2510 | ||
f22f54f4 PZ |
2511 | return 0; |
2512 | } |