blob: 259ac3fddd9ee14943f18e3333262ca9929db6e8 [file] [log] [blame]
Kevin Winchesterde0428a2011-08-30 20:41:05 -03001/*
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
Peter Zijlstra1c2ac3f2012-05-14 15:25:34 +020017#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
Kevin Winchesterde0428a2011-08-30 20:41:05 -030029/*
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 */
Stephane Eranianb36817e2012-02-09 23:20:53 +010048 EXTRA_REG_LBR = 2, /* lbr_select */
Stephane Eranianf20093e2013-01-24 16:10:32 +010049 EXTRA_REG_LDLAT = 3, /* ld_lat_threshold */
Kevin Winchesterde0428a2011-08-30 20:41:05 -030050
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;
Robert Richterbc1738f2011-11-18 12:35:22 +010062 int overlap;
Stephane Eranian9fac2cf2013-01-24 16:10:27 +010063 int flags;
Kevin Winchesterde0428a2011-08-30 20:41:05 -030064};
Stephane Eranianf20093e2013-01-24 16:10:32 +010065/*
66 * struct event_constraint flags
67 */
68#define PERF_X86_EVENT_PEBS_LDLAT 0x1 /* ld+ldlat data address sampling */
Stephane Eranian9ad64c02013-01-24 16:10:34 +010069#define PERF_X86_EVENT_PEBS_ST 0x2 /* st data address sampling */
Kevin Winchesterde0428a2011-08-30 20:41:05 -030070
71struct 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: */
Andi Kleen70ab7002012-06-05 17:56:48 -070079#define MAX_PEBS_EVENTS 8
Kevin Winchesterde0428a2011-08-30 20:41:05 -030080
81/*
82 * A debug store configuration.
83 *
84 * We only support architectures that use 64bit fields.
85 */
86struct 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 */
101struct 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 */
114struct 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
122struct 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;
Peter Zijlstra5a4252942012-06-05 15:30:31 +0200139 int is_fake;
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300140
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];
Stephane Eranianb36817e2012-02-09 23:20:53 +0100154 struct er_account *lbr_sel;
Stephane Eranian3e702ff2012-02-09 23:20:58 +0100155 u64 br_sel;
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300156
157 /*
Gleb Natapov144d31e2011-10-05 14:01:21 +0200158 * 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
164 /*
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300165 * 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 */
Joerg Roedel1018faa2012-02-29 14:57:32 +0100173 struct amd_nb *amd_nb;
174 /* Inverted mask of bits to clear in the perf_ctr ctrl registers */
175 u64 perf_ctr_virt_mask;
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300176
177 void *kfree_on_online;
178};
179
Stephane Eranian9fac2cf2013-01-24 16:10:27 +0100180#define __EVENT_CONSTRAINT(c, n, m, w, o, f) {\
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300181 { .idxmsk64 = (n) }, \
182 .code = (c), \
183 .cmask = (m), \
184 .weight = (w), \
Robert Richterbc1738f2011-11-18 12:35:22 +0100185 .overlap = (o), \
Stephane Eranian9fac2cf2013-01-24 16:10:27 +0100186 .flags = f, \
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300187}
188
189#define EVENT_CONSTRAINT(c, n, m) \
Stephane Eranian9fac2cf2013-01-24 16:10:27 +0100190 __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 0, 0)
Robert Richterbc1738f2011-11-18 12:35:22 +0100191
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) \
Stephane Eranian9fac2cf2013-01-24 16:10:27 +0100214 __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 1, 0)
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300215
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
Andi Kleen3a632cb2013-06-17 17:36:48 -0700230 * - in_tx
231 * - in_tx_checkpointed
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300232 * The other filters are supported by fixed counters.
233 * The any-thread option is supported starting with v3.
234 */
Andi Kleen3a632cb2013-06-17 17:36:48 -0700235#define FIXED_EVENT_FLAGS (X86_RAW_EVENT_MASK|HSW_IN_TX|HSW_IN_TX_CHECKPOINTED)
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300236#define FIXED_EVENT_CONSTRAINT(c, n) \
Andi Kleen3a632cb2013-06-17 17:36:48 -0700237 EVENT_CONSTRAINT(c, (1ULL << (32+n)), FIXED_EVENT_FLAGS)
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300238
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
Stephane Eranianf20093e2013-01-24 16:10:32 +0100245#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
Stephane Eranian9ad64c02013-01-24 16:10:34 +0100249#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
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300253#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 */
269struct 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), \
Stephane Eranianf20093e2013-01-24 16:10:32 +0100282 .idx = EXTRA_REG_##i, \
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300283 }
284
285#define INTEL_EVENT_EXTRA_REG(event, msr, vm, idx) \
286 EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT, vm, idx)
287
Stephane Eranianf20093e2013-01-24 16:10:32 +0100288#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
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300298#define EVENT_EXTRA_END EVENT_EXTRA_REG(0, 0, 0, 0, RSP_0)
299
300union 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
Peter Zijlstrac1d6f422011-12-06 14:07:15 +0100311struct x86_pmu_quirk {
312 struct x86_pmu_quirk *next;
313 void (*func)(void);
314};
315
Peter Zijlstraf9b4eeb2012-03-12 12:44:35 +0100316union 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
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300339/*
340 * struct x86_pmu - generic x86 pmu
341 */
342struct 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;
Jacob Shin4c1fd172013-02-06 11:26:27 -0600357 int (*addr_offset)(int index, bool eventsel);
Jacob Shin0fbdad02013-02-06 11:26:28 -0600358 int (*rdpmc_index)(int index);
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300359 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;
Gleb Natapovffb871b2011-11-10 14:57:26 +0200365 union {
366 unsigned long events_maskl;
367 unsigned long events_mask[BITS_TO_LONGS(ARCH_PERFMON_EVENTS_COUNT)];
368 };
369 int events_mask_len;
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300370 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;
Peter Zijlstrac1d6f422011-12-06 14:07:15 +0100379 struct x86_pmu_quirk *quirks;
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300380 int perfctr_second_write;
381
Peter Zijlstra0c9d42e2011-11-20 23:30:47 +0100382 /*
383 * sysfs attrs
384 */
385 int attr_rdpmc;
Jiri Olsa641cc932012-03-15 20:09:14 +0100386 struct attribute **format_attrs;
Stephane Eranianf20093e2013-01-24 16:10:32 +0100387 struct attribute **event_attrs;
Peter Zijlstra0c9d42e2011-11-20 23:30:47 +0100388
Jiri Olsaa4747392012-10-10 14:53:11 +0200389 ssize_t (*events_sysfs_show)(char *page, u64 config);
Andi Kleen1a6461b2013-01-24 16:10:25 +0100390 struct attribute **cpu_events;
Jiri Olsaa4747392012-10-10 14:53:11 +0200391
Peter Zijlstra0c9d42e2011-11-20 23:30:47 +0100392 /*
393 * CPU Hotplug hooks
394 */
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300395 int (*cpu_prepare)(int cpu);
396 void (*cpu_starting)(int cpu);
397 void (*cpu_dying)(int cpu);
398 void (*cpu_dead)(int cpu);
Peter Zijlstrac93dc842012-06-08 14:50:50 +0200399
400 void (*check_microcode)(void);
Stephane Eraniand010b332012-02-09 23:21:00 +0100401 void (*flush_branch_stack)(void);
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300402
403 /*
404 * Intel Arch Perfmon v2+
405 */
406 u64 intel_ctrl;
407 union perf_capabilities intel_cap;
408
409 /*
410 * Intel DebugStore bits
411 */
Peter Zijlstra597ed952012-07-09 13:50:23 +0200412 unsigned int bts :1,
Peter Zijlstra3e0091e2012-06-26 23:38:39 +0200413 bts_active :1,
414 pebs :1,
415 pebs_active :1,
416 pebs_broken :1;
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300417 int pebs_record_size;
418 void (*drain_pebs)(struct pt_regs *regs);
419 struct event_constraint *pebs_constraints;
Peter Zijlstra0780c922012-06-05 10:26:43 +0200420 void (*pebs_aliases)(struct perf_event *event);
Andi Kleen70ab7002012-06-05 17:56:48 -0700421 int max_pebs_events;
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300422
423 /*
424 * Intel LBR
425 */
426 unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */
427 int lbr_nr; /* hardware stack size */
Stephane Eranianb36817e2012-02-09 23:20:53 +0100428 u64 lbr_sel_mask; /* LBR_SELECT valid bits */
429 const int *lbr_sel_map; /* lbr_select mappings */
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300430
431 /*
432 * Extra registers for events
433 */
434 struct extra_reg *extra_regs;
435 unsigned int er_flags;
Gleb Natapov144d31e2011-10-05 14:01:21 +0200436
437 /*
438 * Intel host/guest support (KVM)
439 */
440 struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr);
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300441};
442
Peter Zijlstrac1d6f422011-12-06 14:07:15 +0100443#define x86_add_quirk(func_) \
444do { \
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
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300452#define ERF_NO_HT_SHARING 1
453#define ERF_HAS_RSP_1 2
454
Stephane Eranian3a54aaa2013-01-24 16:10:26 +0100455#define EVENT_VAR(_id) event_attr_##_id
456#define EVENT_PTR(_id) &event_attr_##_id.attr.attr
457
458#define EVENT_ATTR(_name, _id) \
459static 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) \
466static 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
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300472extern struct x86_pmu x86_pmu __read_mostly;
473
474DECLARE_PER_CPU(struct cpu_hw_events, cpu_hw_events);
475
476int 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
488extern 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];
492extern 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
497u64 x86_perf_event_update(struct perf_event *event);
498
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300499static inline unsigned int x86_pmu_config_addr(int index)
500{
Jacob Shin4c1fd172013-02-06 11:26:27 -0600501 return x86_pmu.eventsel + (x86_pmu.addr_offset ?
502 x86_pmu.addr_offset(index, true) : index);
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300503}
504
505static inline unsigned int x86_pmu_event_addr(int index)
506{
Jacob Shin4c1fd172013-02-06 11:26:27 -0600507 return x86_pmu.perfctr + (x86_pmu.addr_offset ?
508 x86_pmu.addr_offset(index, false) : index);
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300509}
510
Jacob Shin0fbdad02013-02-06 11:26:28 -0600511static inline int x86_pmu_rdpmc_index(int index)
512{
513 return x86_pmu.rdpmc_index ? x86_pmu.rdpmc_index(index) : index;
514}
515
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300516int x86_setup_perfctr(struct perf_event *event);
517
518int x86_pmu_hw_config(struct perf_event *event);
519
520void x86_pmu_disable_all(void);
521
522static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc,
523 u64 enable_mask)
524{
Joerg Roedel1018faa2012-02-29 14:57:32 +0100525 u64 disable_mask = __this_cpu_read(cpu_hw_events.perf_ctr_virt_mask);
526
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300527 if (hwc->extra_reg.reg)
528 wrmsrl(hwc->extra_reg.reg, hwc->extra_reg.config);
Joerg Roedel1018faa2012-02-29 14:57:32 +0100529 wrmsrl(hwc->config_base, (hwc->config | enable_mask) & ~disable_mask);
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300530}
531
532void x86_pmu_enable_all(int added);
533
Andrew Hunter43b457802013-05-23 11:07:03 -0700534int perf_assign_events(struct perf_event **events, int n,
Yan, Zheng4b4969b2012-06-15 14:31:30 +0800535 int wmin, int wmax, int *assign);
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300536int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign);
537
538void x86_pmu_stop(struct perf_event *event, int flags);
539
540static 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
547void x86_pmu_enable_event(struct perf_event *event);
548
549int x86_pmu_handle_irq(struct pt_regs *regs);
550
551extern struct event_constraint emptyconstraint;
552
553extern struct event_constraint unconstrained;
554
Stephane Eranian3e702ff2012-02-09 23:20:58 +0100555static 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
Peter Zijlstrad07bdfd2012-07-10 09:42:15 +0200564/*
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 */
576static 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
Jiri Olsa0bf79d42012-10-10 14:53:14 +0200584ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event);
Jiri Olsa20550a42012-10-10 14:53:15 +0200585ssize_t intel_event_sysfs_show(char *page, u64 config);
Jiri Olsa43c032f2012-10-10 14:53:13 +0200586
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300587#ifdef CONFIG_CPU_SUP_AMD
588
589int amd_pmu_init(void);
590
591#else /* CONFIG_CPU_SUP_AMD */
592
593static 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
602int intel_pmu_save_and_restart(struct perf_event *event);
603
604struct event_constraint *
605x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event);
606
607struct intel_shared_regs *allocate_shared_regs(int cpu);
608
609int intel_pmu_init(void);
610
611void init_debug_store_on_cpu(int cpu);
612
613void fini_debug_store_on_cpu(int cpu);
614
615void release_ds_buffers(void);
616
617void reserve_ds_buffers(void);
618
619extern struct event_constraint bts_constraint;
620
621void intel_pmu_enable_bts(u64 config);
622
623void intel_pmu_disable_bts(void);
624
625int intel_pmu_drain_bts_buffer(void);
626
627extern struct event_constraint intel_core2_pebs_event_constraints[];
628
629extern struct event_constraint intel_atom_pebs_event_constraints[];
630
631extern struct event_constraint intel_nehalem_pebs_event_constraints[];
632
633extern struct event_constraint intel_westmere_pebs_event_constraints[];
634
635extern struct event_constraint intel_snb_pebs_event_constraints[];
636
Stephane Eranian20a36e32012-09-11 01:07:01 +0200637extern struct event_constraint intel_ivb_pebs_event_constraints[];
638
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300639struct event_constraint *intel_pebs_constraints(struct perf_event *event);
640
641void intel_pmu_pebs_enable(struct perf_event *event);
642
643void intel_pmu_pebs_disable(struct perf_event *event);
644
645void intel_pmu_pebs_enable_all(void);
646
647void intel_pmu_pebs_disable_all(void);
648
649void intel_ds_init(void);
650
651void intel_pmu_lbr_reset(void);
652
653void intel_pmu_lbr_enable(struct perf_event *event);
654
655void intel_pmu_lbr_disable(struct perf_event *event);
656
657void intel_pmu_lbr_enable_all(void);
658
659void intel_pmu_lbr_disable_all(void);
660
661void intel_pmu_lbr_read(void);
662
663void intel_pmu_lbr_init_core(void);
664
665void intel_pmu_lbr_init_nhm(void);
666
667void intel_pmu_lbr_init_atom(void);
668
Stephane Eranianc5cc2cd2012-02-09 23:20:55 +0100669void intel_pmu_lbr_init_snb(void);
670
Stephane Eranian60ce0fb2012-02-09 23:20:57 +0100671int intel_pmu_setup_lbr_filter(struct perf_event *event);
672
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300673int p4_pmu_init(void);
674
675int p6_pmu_init(void);
676
Vince Weavere717bf42012-09-26 14:12:52 -0400677int knc_pmu_init(void);
678
Stephane Eranianf20093e2013-01-24 16:10:32 +0100679ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,
680 char *page);
681
Kevin Winchesterde0428a2011-08-30 20:41:05 -0300682#else /* CONFIG_CPU_SUP_INTEL */
683
684static inline void reserve_ds_buffers(void)
685{
686}
687
688static inline void release_ds_buffers(void)
689{
690}
691
692static inline int intel_pmu_init(void)
693{
694 return 0;
695}
696
697static inline struct intel_shared_regs *allocate_shared_regs(int cpu)
698{
699 return NULL;
700}
701
702#endif /* CONFIG_CPU_SUP_INTEL */