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