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