Commit | Line | Data |
---|---|---|
de0428a7 KW |
1 | /* |
2 | * Performance events x86 architecture header | |
3 | * | |
4 | * Copyright (C) 2008 Thomas Gleixner <tglx@linutronix.de> | |
5 | * Copyright (C) 2008-2009 Red Hat, Inc., Ingo Molnar | |
6 | * Copyright (C) 2009 Jaswinder Singh Rajput | |
7 | * Copyright (C) 2009 Advanced Micro Devices, Inc., Robert Richter | |
8 | * Copyright (C) 2008-2009 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> | |
9 | * Copyright (C) 2009 Intel Corporation, <markus.t.metzger@intel.com> | |
10 | * Copyright (C) 2009 Google, Inc., Stephane Eranian | |
11 | * | |
12 | * For licencing details see kernel-base/COPYING | |
13 | */ | |
14 | ||
15 | #include <linux/perf_event.h> | |
16 | ||
1c2ac3fd PZ |
17 | #if 0 |
18 | #undef wrmsrl | |
19 | #define wrmsrl(msr, val) \ | |
20 | do { \ | |
21 | unsigned int _msr = (msr); \ | |
22 | u64 _val = (val); \ | |
23 | trace_printk("wrmsrl(%x, %Lx)\n", (unsigned int)(_msr), \ | |
24 | (unsigned long long)(_val)); \ | |
25 | native_write_msr((_msr), (u32)(_val), (u32)(_val >> 32)); \ | |
26 | } while (0) | |
27 | #endif | |
28 | ||
de0428a7 KW |
29 | /* |
30 | * | NHM/WSM | SNB | | |
31 | * register ------------------------------- | |
32 | * | HT | no HT | HT | no HT | | |
33 | *----------------------------------------- | |
34 | * offcore | core | core | cpu | core | | |
35 | * lbr_sel | core | core | cpu | core | | |
36 | * ld_lat | cpu | core | cpu | core | | |
37 | *----------------------------------------- | |
38 | * | |
39 | * Given that there is a small number of shared regs, | |
40 | * we can pre-allocate their slot in the per-cpu | |
41 | * per-core reg tables. | |
42 | */ | |
43 | enum extra_reg_type { | |
44 | EXTRA_REG_NONE = -1, /* not used */ | |
45 | ||
46 | EXTRA_REG_RSP_0 = 0, /* offcore_response_0 */ | |
47 | EXTRA_REG_RSP_1 = 1, /* offcore_response_1 */ | |
b36817e8 | 48 | EXTRA_REG_LBR = 2, /* lbr_select */ |
f20093ee | 49 | EXTRA_REG_LDLAT = 3, /* ld_lat_threshold */ |
de0428a7 KW |
50 | |
51 | EXTRA_REG_MAX /* number of entries needed */ | |
52 | }; | |
53 | ||
54 | struct event_constraint { | |
55 | union { | |
56 | unsigned long idxmsk[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | |
57 | u64 idxmsk64; | |
58 | }; | |
59 | u64 code; | |
60 | u64 cmask; | |
61 | int weight; | |
bc1738f6 | 62 | int overlap; |
9fac2cf3 | 63 | int flags; |
de0428a7 | 64 | }; |
f20093ee SE |
65 | /* |
66 | * struct event_constraint flags | |
67 | */ | |
68 | #define PERF_X86_EVENT_PEBS_LDLAT 0x1 /* ld+ldlat data address sampling */ | |
9ad64c0f | 69 | #define PERF_X86_EVENT_PEBS_ST 0x2 /* st data address sampling */ |
de0428a7 KW |
70 | |
71 | struct amd_nb { | |
72 | int nb_id; /* NorthBridge id */ | |
73 | int refcnt; /* reference count */ | |
74 | struct perf_event *owners[X86_PMC_IDX_MAX]; | |
75 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; | |
76 | }; | |
77 | ||
78 | /* The maximal number of PEBS events: */ | |
70ab7003 | 79 | #define MAX_PEBS_EVENTS 8 |
de0428a7 KW |
80 | |
81 | /* | |
82 | * A debug store configuration. | |
83 | * | |
84 | * We only support architectures that use 64bit fields. | |
85 | */ | |
86 | struct debug_store { | |
87 | u64 bts_buffer_base; | |
88 | u64 bts_index; | |
89 | u64 bts_absolute_maximum; | |
90 | u64 bts_interrupt_threshold; | |
91 | u64 pebs_buffer_base; | |
92 | u64 pebs_index; | |
93 | u64 pebs_absolute_maximum; | |
94 | u64 pebs_interrupt_threshold; | |
95 | u64 pebs_event_reset[MAX_PEBS_EVENTS]; | |
96 | }; | |
97 | ||
98 | /* | |
99 | * Per register state. | |
100 | */ | |
101 | struct er_account { | |
102 | raw_spinlock_t lock; /* per-core: protect structure */ | |
103 | u64 config; /* extra MSR config */ | |
104 | u64 reg; /* extra MSR number */ | |
105 | atomic_t ref; /* reference count */ | |
106 | }; | |
107 | ||
108 | /* | |
109 | * Per core/cpu state | |
110 | * | |
111 | * Used to coordinate shared registers between HT threads or | |
112 | * among events on a single PMU. | |
113 | */ | |
114 | struct intel_shared_regs { | |
115 | struct er_account regs[EXTRA_REG_MAX]; | |
116 | int refcnt; /* per-core: #HT threads */ | |
117 | unsigned core_id; /* per-core: core id */ | |
118 | }; | |
119 | ||
120 | #define MAX_LBR_ENTRIES 16 | |
121 | ||
122 | struct cpu_hw_events { | |
123 | /* | |
124 | * Generic x86 PMC bits | |
125 | */ | |
126 | struct perf_event *events[X86_PMC_IDX_MAX]; /* in counter order */ | |
127 | unsigned long active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | |
128 | unsigned long running[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; | |
129 | int enabled; | |
130 | ||
131 | int n_events; | |
132 | int n_added; | |
133 | int n_txn; | |
134 | int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */ | |
135 | u64 tags[X86_PMC_IDX_MAX]; | |
136 | struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */ | |
137 | ||
138 | unsigned int group_flag; | |
5a425294 | 139 | int is_fake; |
de0428a7 KW |
140 | |
141 | /* | |
142 | * Intel DebugStore bits | |
143 | */ | |
144 | struct debug_store *ds; | |
145 | u64 pebs_enabled; | |
146 | ||
147 | /* | |
148 | * Intel LBR bits | |
149 | */ | |
150 | int lbr_users; | |
151 | void *lbr_context; | |
152 | struct perf_branch_stack lbr_stack; | |
153 | struct perf_branch_entry lbr_entries[MAX_LBR_ENTRIES]; | |
b36817e8 | 154 | struct er_account *lbr_sel; |
3e702ff6 | 155 | u64 br_sel; |
de0428a7 | 156 | |
144d31e6 GN |
157 | /* |
158 | * Intel host/guest exclude bits | |
159 | */ | |
160 | u64 intel_ctrl_guest_mask; | |
161 | u64 intel_ctrl_host_mask; | |
162 | struct perf_guest_switch_msr guest_switch_msrs[X86_PMC_IDX_MAX]; | |
163 | ||
de0428a7 KW |
164 | /* |
165 | * manage shared (per-core, per-cpu) registers | |
166 | * used on Intel NHM/WSM/SNB | |
167 | */ | |
168 | struct intel_shared_regs *shared_regs; | |
169 | ||
170 | /* | |
171 | * AMD specific bits | |
172 | */ | |
1018faa6 JR |
173 | struct amd_nb *amd_nb; |
174 | /* Inverted mask of bits to clear in the perf_ctr ctrl registers */ | |
175 | u64 perf_ctr_virt_mask; | |
de0428a7 KW |
176 | |
177 | void *kfree_on_online; | |
178 | }; | |
179 | ||
9fac2cf3 | 180 | #define __EVENT_CONSTRAINT(c, n, m, w, o, f) {\ |
de0428a7 KW |
181 | { .idxmsk64 = (n) }, \ |
182 | .code = (c), \ | |
183 | .cmask = (m), \ | |
184 | .weight = (w), \ | |
bc1738f6 | 185 | .overlap = (o), \ |
9fac2cf3 | 186 | .flags = f, \ |
de0428a7 KW |
187 | } |
188 | ||
189 | #define EVENT_CONSTRAINT(c, n, m) \ | |
9fac2cf3 | 190 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 0, 0) |
bc1738f6 RR |
191 | |
192 | /* | |
193 | * The overlap flag marks event constraints with overlapping counter | |
194 | * masks. This is the case if the counter mask of such an event is not | |
195 | * a subset of any other counter mask of a constraint with an equal or | |
196 | * higher weight, e.g.: | |
197 | * | |
198 | * c_overlaps = EVENT_CONSTRAINT_OVERLAP(0, 0x09, 0); | |
199 | * c_another1 = EVENT_CONSTRAINT(0, 0x07, 0); | |
200 | * c_another2 = EVENT_CONSTRAINT(0, 0x38, 0); | |
201 | * | |
202 | * The event scheduler may not select the correct counter in the first | |
203 | * cycle because it needs to know which subsequent events will be | |
204 | * scheduled. It may fail to schedule the events then. So we set the | |
205 | * overlap flag for such constraints to give the scheduler a hint which | |
206 | * events to select for counter rescheduling. | |
207 | * | |
208 | * Care must be taken as the rescheduling algorithm is O(n!) which | |
209 | * will increase scheduling cycles for an over-commited system | |
210 | * dramatically. The number of such EVENT_CONSTRAINT_OVERLAP() macros | |
211 | * and its counter masks must be kept at a minimum. | |
212 | */ | |
213 | #define EVENT_CONSTRAINT_OVERLAP(c, n, m) \ | |
9fac2cf3 | 214 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 1, 0) |
de0428a7 KW |
215 | |
216 | /* | |
217 | * Constraint on the Event code. | |
218 | */ | |
219 | #define INTEL_EVENT_CONSTRAINT(c, n) \ | |
220 | EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT) | |
221 | ||
222 | /* | |
223 | * Constraint on the Event code + UMask + fixed-mask | |
224 | * | |
225 | * filter mask to validate fixed counter events. | |
226 | * the following filters disqualify for fixed counters: | |
227 | * - inv | |
228 | * - edge | |
229 | * - cnt-mask | |
3a632cb2 AK |
230 | * - in_tx |
231 | * - in_tx_checkpointed | |
de0428a7 KW |
232 | * The other filters are supported by fixed counters. |
233 | * The any-thread option is supported starting with v3. | |
234 | */ | |
3a632cb2 | 235 | #define FIXED_EVENT_FLAGS (X86_RAW_EVENT_MASK|HSW_IN_TX|HSW_IN_TX_CHECKPOINTED) |
de0428a7 | 236 | #define FIXED_EVENT_CONSTRAINT(c, n) \ |
3a632cb2 | 237 | EVENT_CONSTRAINT(c, (1ULL << (32+n)), FIXED_EVENT_FLAGS) |
de0428a7 KW |
238 | |
239 | /* | |
240 | * Constraint on the Event code + UMask | |
241 | */ | |
242 | #define INTEL_UEVENT_CONSTRAINT(c, n) \ | |
243 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK) | |
244 | ||
f20093ee SE |
245 | #define INTEL_PLD_CONSTRAINT(c, n) \ |
246 | __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK, \ | |
247 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LDLAT) | |
248 | ||
9ad64c0f SE |
249 | #define INTEL_PST_CONSTRAINT(c, n) \ |
250 | __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK, \ | |
251 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST) | |
252 | ||
de0428a7 KW |
253 | #define EVENT_CONSTRAINT_END \ |
254 | EVENT_CONSTRAINT(0, 0, 0) | |
255 | ||
256 | #define for_each_event_constraint(e, c) \ | |
257 | for ((e) = (c); (e)->weight; (e)++) | |
258 | ||
259 | /* | |
260 | * Extra registers for specific events. | |
261 | * | |
262 | * Some events need large masks and require external MSRs. | |
263 | * Those extra MSRs end up being shared for all events on | |
264 | * a PMU and sometimes between PMU of sibling HT threads. | |
265 | * In either case, the kernel needs to handle conflicting | |
266 | * accesses to those extra, shared, regs. The data structure | |
267 | * to manage those registers is stored in cpu_hw_event. | |
268 | */ | |
269 | struct extra_reg { | |
270 | unsigned int event; | |
271 | unsigned int msr; | |
272 | u64 config_mask; | |
273 | u64 valid_mask; | |
274 | int idx; /* per_xxx->regs[] reg index */ | |
275 | }; | |
276 | ||
277 | #define EVENT_EXTRA_REG(e, ms, m, vm, i) { \ | |
278 | .event = (e), \ | |
279 | .msr = (ms), \ | |
280 | .config_mask = (m), \ | |
281 | .valid_mask = (vm), \ | |
f20093ee | 282 | .idx = EXTRA_REG_##i, \ |
de0428a7 KW |
283 | } |
284 | ||
285 | #define INTEL_EVENT_EXTRA_REG(event, msr, vm, idx) \ | |
286 | EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT, vm, idx) | |
287 | ||
f20093ee SE |
288 | #define INTEL_UEVENT_EXTRA_REG(event, msr, vm, idx) \ |
289 | EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT | \ | |
290 | ARCH_PERFMON_EVENTSEL_UMASK, vm, idx) | |
291 | ||
292 | #define INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(c) \ | |
293 | INTEL_UEVENT_EXTRA_REG(c, \ | |
294 | MSR_PEBS_LD_LAT_THRESHOLD, \ | |
295 | 0xffff, \ | |
296 | LDLAT) | |
297 | ||
de0428a7 KW |
298 | #define EVENT_EXTRA_END EVENT_EXTRA_REG(0, 0, 0, 0, RSP_0) |
299 | ||
300 | union perf_capabilities { | |
301 | struct { | |
302 | u64 lbr_format:6; | |
303 | u64 pebs_trap:1; | |
304 | u64 pebs_arch_reg:1; | |
305 | u64 pebs_format:4; | |
306 | u64 smm_freeze:1; | |
307 | }; | |
308 | u64 capabilities; | |
309 | }; | |
310 | ||
c1d6f42f PZ |
311 | struct x86_pmu_quirk { |
312 | struct x86_pmu_quirk *next; | |
313 | void (*func)(void); | |
314 | }; | |
315 | ||
f9b4eeb8 PZ |
316 | union x86_pmu_config { |
317 | struct { | |
318 | u64 event:8, | |
319 | umask:8, | |
320 | usr:1, | |
321 | os:1, | |
322 | edge:1, | |
323 | pc:1, | |
324 | interrupt:1, | |
325 | __reserved1:1, | |
326 | en:1, | |
327 | inv:1, | |
328 | cmask:8, | |
329 | event2:4, | |
330 | __reserved2:4, | |
331 | go:1, | |
332 | ho:1; | |
333 | } bits; | |
334 | u64 value; | |
335 | }; | |
336 | ||
337 | #define X86_CONFIG(args...) ((union x86_pmu_config){.bits = {args}}).value | |
338 | ||
de0428a7 KW |
339 | /* |
340 | * struct x86_pmu - generic x86 pmu | |
341 | */ | |
342 | struct x86_pmu { | |
343 | /* | |
344 | * Generic x86 PMC bits | |
345 | */ | |
346 | const char *name; | |
347 | int version; | |
348 | int (*handle_irq)(struct pt_regs *); | |
349 | void (*disable_all)(void); | |
350 | void (*enable_all)(int added); | |
351 | void (*enable)(struct perf_event *); | |
352 | void (*disable)(struct perf_event *); | |
353 | int (*hw_config)(struct perf_event *event); | |
354 | int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign); | |
355 | unsigned eventsel; | |
356 | unsigned perfctr; | |
4c1fd17a | 357 | int (*addr_offset)(int index, bool eventsel); |
0fbdad07 | 358 | int (*rdpmc_index)(int index); |
de0428a7 KW |
359 | u64 (*event_map)(int); |
360 | int max_events; | |
361 | int num_counters; | |
362 | int num_counters_fixed; | |
363 | int cntval_bits; | |
364 | u64 cntval_mask; | |
ffb871bc GN |
365 | union { |
366 | unsigned long events_maskl; | |
367 | unsigned long events_mask[BITS_TO_LONGS(ARCH_PERFMON_EVENTS_COUNT)]; | |
368 | }; | |
369 | int events_mask_len; | |
de0428a7 KW |
370 | int apic; |
371 | u64 max_period; | |
372 | struct event_constraint * | |
373 | (*get_event_constraints)(struct cpu_hw_events *cpuc, | |
374 | struct perf_event *event); | |
375 | ||
376 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, | |
377 | struct perf_event *event); | |
378 | struct event_constraint *event_constraints; | |
c1d6f42f | 379 | struct x86_pmu_quirk *quirks; |
de0428a7 KW |
380 | int perfctr_second_write; |
381 | ||
0c9d42ed PZ |
382 | /* |
383 | * sysfs attrs | |
384 | */ | |
385 | int attr_rdpmc; | |
641cc938 | 386 | struct attribute **format_attrs; |
f20093ee | 387 | struct attribute **event_attrs; |
0c9d42ed | 388 | |
a4747393 | 389 | ssize_t (*events_sysfs_show)(char *page, u64 config); |
1a6461b1 | 390 | struct attribute **cpu_events; |
a4747393 | 391 | |
0c9d42ed PZ |
392 | /* |
393 | * CPU Hotplug hooks | |
394 | */ | |
de0428a7 KW |
395 | int (*cpu_prepare)(int cpu); |
396 | void (*cpu_starting)(int cpu); | |
397 | void (*cpu_dying)(int cpu); | |
398 | void (*cpu_dead)(int cpu); | |
c93dc84c PZ |
399 | |
400 | void (*check_microcode)(void); | |
d010b332 | 401 | void (*flush_branch_stack)(void); |
de0428a7 KW |
402 | |
403 | /* | |
404 | * Intel Arch Perfmon v2+ | |
405 | */ | |
406 | u64 intel_ctrl; | |
407 | union perf_capabilities intel_cap; | |
408 | ||
409 | /* | |
410 | * Intel DebugStore bits | |
411 | */ | |
597ed953 | 412 | unsigned int bts :1, |
3e0091e2 PZ |
413 | bts_active :1, |
414 | pebs :1, | |
415 | pebs_active :1, | |
416 | pebs_broken :1; | |
de0428a7 KW |
417 | int pebs_record_size; |
418 | void (*drain_pebs)(struct pt_regs *regs); | |
419 | struct event_constraint *pebs_constraints; | |
0780c927 | 420 | void (*pebs_aliases)(struct perf_event *event); |
70ab7003 | 421 | int max_pebs_events; |
de0428a7 KW |
422 | |
423 | /* | |
424 | * Intel LBR | |
425 | */ | |
426 | unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */ | |
427 | int lbr_nr; /* hardware stack size */ | |
b36817e8 SE |
428 | u64 lbr_sel_mask; /* LBR_SELECT valid bits */ |
429 | const int *lbr_sel_map; /* lbr_select mappings */ | |
de0428a7 KW |
430 | |
431 | /* | |
432 | * Extra registers for events | |
433 | */ | |
434 | struct extra_reg *extra_regs; | |
435 | unsigned int er_flags; | |
144d31e6 GN |
436 | |
437 | /* | |
438 | * Intel host/guest support (KVM) | |
439 | */ | |
440 | struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr); | |
de0428a7 KW |
441 | }; |
442 | ||
c1d6f42f PZ |
443 | #define x86_add_quirk(func_) \ |
444 | do { \ | |
445 | static struct x86_pmu_quirk __quirk __initdata = { \ | |
446 | .func = func_, \ | |
447 | }; \ | |
448 | __quirk.next = x86_pmu.quirks; \ | |
449 | x86_pmu.quirks = &__quirk; \ | |
450 | } while (0) | |
451 | ||
de0428a7 KW |
452 | #define ERF_NO_HT_SHARING 1 |
453 | #define ERF_HAS_RSP_1 2 | |
454 | ||
3a54aaa0 SE |
455 | #define EVENT_VAR(_id) event_attr_##_id |
456 | #define EVENT_PTR(_id) &event_attr_##_id.attr.attr | |
457 | ||
458 | #define EVENT_ATTR(_name, _id) \ | |
459 | static struct perf_pmu_events_attr EVENT_VAR(_id) = { \ | |
460 | .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \ | |
461 | .id = PERF_COUNT_HW_##_id, \ | |
462 | .event_str = NULL, \ | |
463 | }; | |
464 | ||
465 | #define EVENT_ATTR_STR(_name, v, str) \ | |
466 | static struct perf_pmu_events_attr event_attr_##v = { \ | |
467 | .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \ | |
468 | .id = 0, \ | |
469 | .event_str = str, \ | |
470 | }; | |
471 | ||
de0428a7 KW |
472 | extern struct x86_pmu x86_pmu __read_mostly; |
473 | ||
474 | DECLARE_PER_CPU(struct cpu_hw_events, cpu_hw_events); | |
475 | ||
476 | int x86_perf_event_set_period(struct perf_event *event); | |
477 | ||
478 | /* | |
479 | * Generalized hw caching related hw_event table, filled | |
480 | * in on a per model basis. A value of 0 means | |
481 | * 'not supported', -1 means 'hw_event makes no sense on | |
482 | * this CPU', any other value means the raw hw_event | |
483 | * ID. | |
484 | */ | |
485 | ||
486 | #define C(x) PERF_COUNT_HW_CACHE_##x | |
487 | ||
488 | extern u64 __read_mostly hw_cache_event_ids | |
489 | [PERF_COUNT_HW_CACHE_MAX] | |
490 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
491 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; | |
492 | extern u64 __read_mostly hw_cache_extra_regs | |
493 | [PERF_COUNT_HW_CACHE_MAX] | |
494 | [PERF_COUNT_HW_CACHE_OP_MAX] | |
495 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; | |
496 | ||
497 | u64 x86_perf_event_update(struct perf_event *event); | |
498 | ||
de0428a7 KW |
499 | static inline unsigned int x86_pmu_config_addr(int index) |
500 | { | |
4c1fd17a JS |
501 | return x86_pmu.eventsel + (x86_pmu.addr_offset ? |
502 | x86_pmu.addr_offset(index, true) : index); | |
de0428a7 KW |
503 | } |
504 | ||
505 | static inline unsigned int x86_pmu_event_addr(int index) | |
506 | { | |
4c1fd17a JS |
507 | return x86_pmu.perfctr + (x86_pmu.addr_offset ? |
508 | x86_pmu.addr_offset(index, false) : index); | |
de0428a7 KW |
509 | } |
510 | ||
0fbdad07 JS |
511 | static inline int x86_pmu_rdpmc_index(int index) |
512 | { | |
513 | return x86_pmu.rdpmc_index ? x86_pmu.rdpmc_index(index) : index; | |
514 | } | |
515 | ||
de0428a7 KW |
516 | int x86_setup_perfctr(struct perf_event *event); |
517 | ||
518 | int x86_pmu_hw_config(struct perf_event *event); | |
519 | ||
520 | void x86_pmu_disable_all(void); | |
521 | ||
522 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc, | |
523 | u64 enable_mask) | |
524 | { | |
1018faa6 JR |
525 | u64 disable_mask = __this_cpu_read(cpu_hw_events.perf_ctr_virt_mask); |
526 | ||
de0428a7 KW |
527 | if (hwc->extra_reg.reg) |
528 | wrmsrl(hwc->extra_reg.reg, hwc->extra_reg.config); | |
1018faa6 | 529 | wrmsrl(hwc->config_base, (hwc->config | enable_mask) & ~disable_mask); |
de0428a7 KW |
530 | } |
531 | ||
532 | void x86_pmu_enable_all(int added); | |
533 | ||
43b45780 | 534 | int perf_assign_events(struct perf_event **events, int n, |
4b4969b1 | 535 | int wmin, int wmax, int *assign); |
de0428a7 KW |
536 | int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign); |
537 | ||
538 | void x86_pmu_stop(struct perf_event *event, int flags); | |
539 | ||
540 | static inline void x86_pmu_disable_event(struct perf_event *event) | |
541 | { | |
542 | struct hw_perf_event *hwc = &event->hw; | |
543 | ||
544 | wrmsrl(hwc->config_base, hwc->config); | |
545 | } | |
546 | ||
547 | void x86_pmu_enable_event(struct perf_event *event); | |
548 | ||
549 | int x86_pmu_handle_irq(struct pt_regs *regs); | |
550 | ||
551 | extern struct event_constraint emptyconstraint; | |
552 | ||
553 | extern struct event_constraint unconstrained; | |
554 | ||
3e702ff6 SE |
555 | static inline bool kernel_ip(unsigned long ip) |
556 | { | |
557 | #ifdef CONFIG_X86_32 | |
558 | return ip > PAGE_OFFSET; | |
559 | #else | |
560 | return (long)ip < 0; | |
561 | #endif | |
562 | } | |
563 | ||
d07bdfd3 PZ |
564 | /* |
565 | * Not all PMUs provide the right context information to place the reported IP | |
566 | * into full context. Specifically segment registers are typically not | |
567 | * supplied. | |
568 | * | |
569 | * Assuming the address is a linear address (it is for IBS), we fake the CS and | |
570 | * vm86 mode using the known zero-based code segment and 'fix up' the registers | |
571 | * to reflect this. | |
572 | * | |
573 | * Intel PEBS/LBR appear to typically provide the effective address, nothing | |
574 | * much we can do about that but pray and treat it like a linear address. | |
575 | */ | |
576 | static inline void set_linear_ip(struct pt_regs *regs, unsigned long ip) | |
577 | { | |
578 | regs->cs = kernel_ip(ip) ? __KERNEL_CS : __USER_CS; | |
579 | if (regs->flags & X86_VM_MASK) | |
580 | regs->flags ^= (PERF_EFLAGS_VM | X86_VM_MASK); | |
581 | regs->ip = ip; | |
582 | } | |
583 | ||
0bf79d44 | 584 | ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event); |
20550a43 | 585 | ssize_t intel_event_sysfs_show(char *page, u64 config); |
43c032fe | 586 | |
de0428a7 KW |
587 | #ifdef CONFIG_CPU_SUP_AMD |
588 | ||
589 | int amd_pmu_init(void); | |
590 | ||
591 | #else /* CONFIG_CPU_SUP_AMD */ | |
592 | ||
593 | static inline int amd_pmu_init(void) | |
594 | { | |
595 | return 0; | |
596 | } | |
597 | ||
598 | #endif /* CONFIG_CPU_SUP_AMD */ | |
599 | ||
600 | #ifdef CONFIG_CPU_SUP_INTEL | |
601 | ||
602 | int intel_pmu_save_and_restart(struct perf_event *event); | |
603 | ||
604 | struct event_constraint * | |
605 | x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event); | |
606 | ||
607 | struct intel_shared_regs *allocate_shared_regs(int cpu); | |
608 | ||
609 | int intel_pmu_init(void); | |
610 | ||
611 | void init_debug_store_on_cpu(int cpu); | |
612 | ||
613 | void fini_debug_store_on_cpu(int cpu); | |
614 | ||
615 | void release_ds_buffers(void); | |
616 | ||
617 | void reserve_ds_buffers(void); | |
618 | ||
619 | extern struct event_constraint bts_constraint; | |
620 | ||
621 | void intel_pmu_enable_bts(u64 config); | |
622 | ||
623 | void intel_pmu_disable_bts(void); | |
624 | ||
625 | int intel_pmu_drain_bts_buffer(void); | |
626 | ||
627 | extern struct event_constraint intel_core2_pebs_event_constraints[]; | |
628 | ||
629 | extern struct event_constraint intel_atom_pebs_event_constraints[]; | |
630 | ||
631 | extern struct event_constraint intel_nehalem_pebs_event_constraints[]; | |
632 | ||
633 | extern struct event_constraint intel_westmere_pebs_event_constraints[]; | |
634 | ||
635 | extern struct event_constraint intel_snb_pebs_event_constraints[]; | |
636 | ||
20a36e39 SE |
637 | extern struct event_constraint intel_ivb_pebs_event_constraints[]; |
638 | ||
3044318f AK |
639 | extern struct event_constraint intel_hsw_pebs_event_constraints[]; |
640 | ||
de0428a7 KW |
641 | struct event_constraint *intel_pebs_constraints(struct perf_event *event); |
642 | ||
643 | void intel_pmu_pebs_enable(struct perf_event *event); | |
644 | ||
645 | void intel_pmu_pebs_disable(struct perf_event *event); | |
646 | ||
647 | void intel_pmu_pebs_enable_all(void); | |
648 | ||
649 | void intel_pmu_pebs_disable_all(void); | |
650 | ||
651 | void intel_ds_init(void); | |
652 | ||
653 | void intel_pmu_lbr_reset(void); | |
654 | ||
655 | void intel_pmu_lbr_enable(struct perf_event *event); | |
656 | ||
657 | void intel_pmu_lbr_disable(struct perf_event *event); | |
658 | ||
659 | void intel_pmu_lbr_enable_all(void); | |
660 | ||
661 | void intel_pmu_lbr_disable_all(void); | |
662 | ||
663 | void intel_pmu_lbr_read(void); | |
664 | ||
665 | void intel_pmu_lbr_init_core(void); | |
666 | ||
667 | void intel_pmu_lbr_init_nhm(void); | |
668 | ||
669 | void intel_pmu_lbr_init_atom(void); | |
670 | ||
c5cc2cd9 SE |
671 | void intel_pmu_lbr_init_snb(void); |
672 | ||
60ce0fbd SE |
673 | int intel_pmu_setup_lbr_filter(struct perf_event *event); |
674 | ||
de0428a7 KW |
675 | int p4_pmu_init(void); |
676 | ||
677 | int p6_pmu_init(void); | |
678 | ||
e717bf4e VW |
679 | int knc_pmu_init(void); |
680 | ||
f20093ee SE |
681 | ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, |
682 | char *page); | |
683 | ||
de0428a7 KW |
684 | #else /* CONFIG_CPU_SUP_INTEL */ |
685 | ||
686 | static inline void reserve_ds_buffers(void) | |
687 | { | |
688 | } | |
689 | ||
690 | static inline void release_ds_buffers(void) | |
691 | { | |
692 | } | |
693 | ||
694 | static inline int intel_pmu_init(void) | |
695 | { | |
696 | return 0; | |
697 | } | |
698 | ||
699 | static inline struct intel_shared_regs *allocate_shared_regs(int cpu) | |
700 | { | |
701 | return NULL; | |
702 | } | |
703 | ||
704 | #endif /* CONFIG_CPU_SUP_INTEL */ |