Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 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 | |
Peter Zijlstra | 1c2ac3f | 2012-05-14 15:25:34 +0200 | [diff] [blame] | 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 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 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 */ |
Stephane Eranian | b36817e | 2012-02-09 23:20:53 +0100 | [diff] [blame] | 48 | EXTRA_REG_LBR = 2, /* lbr_select */ |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 49 | EXTRA_REG_LDLAT = 3, /* ld_lat_threshold */ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 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; |
Robert Richter | bc1738f | 2011-11-18 12:35:22 +0100 | [diff] [blame] | 62 | int overlap; |
Stephane Eranian | 9fac2cf | 2013-01-24 16:10:27 +0100 | [diff] [blame] | 63 | int flags; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 64 | }; |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 65 | /* |
Stephane Eranian | 2f7f73a | 2013-06-20 18:42:54 +0200 | [diff] [blame] | 66 | * struct hw_perf_event.flags flags |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 67 | */ |
| 68 | #define PERF_X86_EVENT_PEBS_LDLAT 0x1 /* ld+ldlat data address sampling */ |
Stephane Eranian | 9ad64c0 | 2013-01-24 16:10:34 +0100 | [diff] [blame] | 69 | #define PERF_X86_EVENT_PEBS_ST 0x2 /* st data address sampling */ |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 70 | #define PERF_X86_EVENT_PEBS_ST_HSW 0x4 /* haswell style datala, store */ |
Stephane Eranian | 2f7f73a | 2013-06-20 18:42:54 +0200 | [diff] [blame] | 71 | #define PERF_X86_EVENT_COMMITTED 0x8 /* event passed commit_txn */ |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 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 */ |
Maria Dimakopoulou | 6f6539c | 2014-11-17 20:06:57 +0100 | [diff] [blame] | 74 | #define PERF_X86_EVENT_EXCL 0x40 /* HT exclusivity on counter */ |
Maria Dimakopoulou | e979121 | 2014-11-17 20:06:58 +0100 | [diff] [blame] | 75 | #define PERF_X86_EVENT_DYNAMIC 0x80 /* dynamic alloc'd constraint */ |
Andy Lutomirski | 7911d3f | 2014-10-24 15:58:12 -0700 | [diff] [blame] | 76 | #define PERF_X86_EVENT_RDPMC_ALLOWED 0x40 /* grant rdpmc permission */ |
| 77 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 78 | |
| 79 | struct amd_nb { |
| 80 | int nb_id; /* NorthBridge id */ |
| 81 | int refcnt; /* reference count */ |
| 82 | struct perf_event *owners[X86_PMC_IDX_MAX]; |
| 83 | struct event_constraint event_constraints[X86_PMC_IDX_MAX]; |
| 84 | }; |
| 85 | |
| 86 | /* The maximal number of PEBS events: */ |
Andi Kleen | 70ab700 | 2012-06-05 17:56:48 -0700 | [diff] [blame] | 87 | #define MAX_PEBS_EVENTS 8 |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * A debug store configuration. |
| 91 | * |
| 92 | * We only support architectures that use 64bit fields. |
| 93 | */ |
| 94 | struct debug_store { |
| 95 | u64 bts_buffer_base; |
| 96 | u64 bts_index; |
| 97 | u64 bts_absolute_maximum; |
| 98 | u64 bts_interrupt_threshold; |
| 99 | u64 pebs_buffer_base; |
| 100 | u64 pebs_index; |
| 101 | u64 pebs_absolute_maximum; |
| 102 | u64 pebs_interrupt_threshold; |
| 103 | u64 pebs_event_reset[MAX_PEBS_EVENTS]; |
| 104 | }; |
| 105 | |
| 106 | /* |
| 107 | * Per register state. |
| 108 | */ |
| 109 | struct er_account { |
| 110 | raw_spinlock_t lock; /* per-core: protect structure */ |
| 111 | u64 config; /* extra MSR config */ |
| 112 | u64 reg; /* extra MSR number */ |
| 113 | atomic_t ref; /* reference count */ |
| 114 | }; |
| 115 | |
| 116 | /* |
| 117 | * Per core/cpu state |
| 118 | * |
| 119 | * Used to coordinate shared registers between HT threads or |
| 120 | * among events on a single PMU. |
| 121 | */ |
| 122 | struct intel_shared_regs { |
| 123 | struct er_account regs[EXTRA_REG_MAX]; |
| 124 | int refcnt; /* per-core: #HT threads */ |
| 125 | unsigned core_id; /* per-core: core id */ |
| 126 | }; |
| 127 | |
Maria Dimakopoulou | 6f6539c | 2014-11-17 20:06:57 +0100 | [diff] [blame] | 128 | enum intel_excl_state_type { |
| 129 | INTEL_EXCL_UNUSED = 0, /* counter is unused */ |
| 130 | INTEL_EXCL_SHARED = 1, /* counter can be used by both threads */ |
| 131 | INTEL_EXCL_EXCLUSIVE = 2, /* counter can be used by one thread only */ |
| 132 | }; |
| 133 | |
| 134 | struct intel_excl_states { |
| 135 | enum intel_excl_state_type init_state[X86_PMC_IDX_MAX]; |
| 136 | enum intel_excl_state_type state[X86_PMC_IDX_MAX]; |
Maria Dimakopoulou | e979121 | 2014-11-17 20:06:58 +0100 | [diff] [blame] | 137 | bool sched_started; /* true if scheduling has started */ |
Maria Dimakopoulou | 6f6539c | 2014-11-17 20:06:57 +0100 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | struct intel_excl_cntrs { |
| 141 | raw_spinlock_t lock; |
| 142 | |
| 143 | struct intel_excl_states states[2]; |
| 144 | |
| 145 | int refcnt; /* per-core: #HT threads */ |
| 146 | unsigned core_id; /* per-core: core id */ |
| 147 | }; |
| 148 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 149 | #define MAX_LBR_ENTRIES 16 |
| 150 | |
Stephane Eranian | 9041346 | 2014-11-17 20:06:54 +0100 | [diff] [blame] | 151 | enum { |
| 152 | X86_PERF_KFREE_SHARED = 0, |
| 153 | X86_PERF_KFREE_EXCL = 1, |
| 154 | X86_PERF_KFREE_MAX |
| 155 | }; |
| 156 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 157 | struct cpu_hw_events { |
| 158 | /* |
| 159 | * Generic x86 PMC bits |
| 160 | */ |
| 161 | struct perf_event *events[X86_PMC_IDX_MAX]; /* in counter order */ |
| 162 | unsigned long active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; |
| 163 | unsigned long running[BITS_TO_LONGS(X86_PMC_IDX_MAX)]; |
| 164 | int enabled; |
| 165 | |
Peter Zijlstra | c347a2f | 2014-02-24 12:26:21 +0100 | [diff] [blame] | 166 | int n_events; /* the # of events in the below arrays */ |
| 167 | int n_added; /* the # last events in the below arrays; |
| 168 | they've never been enabled yet */ |
| 169 | int n_txn; /* the # last events in the below arrays; |
| 170 | added in the current transaction */ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 171 | int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */ |
| 172 | u64 tags[X86_PMC_IDX_MAX]; |
| 173 | struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */ |
| 174 | |
| 175 | unsigned int group_flag; |
Peter Zijlstra | 5a425294 | 2012-06-05 15:30:31 +0200 | [diff] [blame] | 176 | int is_fake; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * Intel DebugStore bits |
| 180 | */ |
| 181 | struct debug_store *ds; |
| 182 | u64 pebs_enabled; |
| 183 | |
| 184 | /* |
| 185 | * Intel LBR bits |
| 186 | */ |
| 187 | int lbr_users; |
| 188 | void *lbr_context; |
| 189 | struct perf_branch_stack lbr_stack; |
| 190 | struct perf_branch_entry lbr_entries[MAX_LBR_ENTRIES]; |
Stephane Eranian | b36817e | 2012-02-09 23:20:53 +0100 | [diff] [blame] | 191 | struct er_account *lbr_sel; |
Stephane Eranian | 3e702ff | 2012-02-09 23:20:58 +0100 | [diff] [blame] | 192 | u64 br_sel; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 193 | |
| 194 | /* |
Gleb Natapov | 144d31e | 2011-10-05 14:01:21 +0200 | [diff] [blame] | 195 | * Intel host/guest exclude bits |
| 196 | */ |
| 197 | u64 intel_ctrl_guest_mask; |
| 198 | u64 intel_ctrl_host_mask; |
| 199 | struct perf_guest_switch_msr guest_switch_msrs[X86_PMC_IDX_MAX]; |
| 200 | |
| 201 | /* |
Peter Zijlstra | 2b9e344 | 2013-09-12 12:53:44 +0200 | [diff] [blame] | 202 | * Intel checkpoint mask |
| 203 | */ |
| 204 | u64 intel_cp_status; |
| 205 | |
| 206 | /* |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 207 | * manage shared (per-core, per-cpu) registers |
| 208 | * used on Intel NHM/WSM/SNB |
| 209 | */ |
| 210 | struct intel_shared_regs *shared_regs; |
Maria Dimakopoulou | 6f6539c | 2014-11-17 20:06:57 +0100 | [diff] [blame] | 211 | /* |
| 212 | * manage exclusive counter access between hyperthread |
| 213 | */ |
| 214 | struct event_constraint *constraint_list; /* in enable order */ |
| 215 | struct intel_excl_cntrs *excl_cntrs; |
| 216 | int excl_thread_id; /* 0 or 1 */ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 217 | |
| 218 | /* |
| 219 | * AMD specific bits |
| 220 | */ |
Joerg Roedel | 1018faa | 2012-02-29 14:57:32 +0100 | [diff] [blame] | 221 | struct amd_nb *amd_nb; |
| 222 | /* Inverted mask of bits to clear in the perf_ctr ctrl registers */ |
| 223 | u64 perf_ctr_virt_mask; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 224 | |
Stephane Eranian | 9041346 | 2014-11-17 20:06:54 +0100 | [diff] [blame] | 225 | void *kfree_on_online[X86_PERF_KFREE_MAX]; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 226 | }; |
| 227 | |
Stephane Eranian | 9fac2cf | 2013-01-24 16:10:27 +0100 | [diff] [blame] | 228 | #define __EVENT_CONSTRAINT(c, n, m, w, o, f) {\ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 229 | { .idxmsk64 = (n) }, \ |
| 230 | .code = (c), \ |
| 231 | .cmask = (m), \ |
| 232 | .weight = (w), \ |
Robert Richter | bc1738f | 2011-11-18 12:35:22 +0100 | [diff] [blame] | 233 | .overlap = (o), \ |
Stephane Eranian | 9fac2cf | 2013-01-24 16:10:27 +0100 | [diff] [blame] | 234 | .flags = f, \ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | #define EVENT_CONSTRAINT(c, n, m) \ |
Stephane Eranian | 9fac2cf | 2013-01-24 16:10:27 +0100 | [diff] [blame] | 238 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 0, 0) |
Robert Richter | bc1738f | 2011-11-18 12:35:22 +0100 | [diff] [blame] | 239 | |
Maria Dimakopoulou | 6f6539c | 2014-11-17 20:06:57 +0100 | [diff] [blame] | 240 | #define INTEL_EXCLEVT_CONSTRAINT(c, n) \ |
| 241 | __EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT, HWEIGHT(n),\ |
| 242 | 0, PERF_X86_EVENT_EXCL) |
| 243 | |
Robert Richter | bc1738f | 2011-11-18 12:35:22 +0100 | [diff] [blame] | 244 | /* |
| 245 | * The overlap flag marks event constraints with overlapping counter |
| 246 | * masks. This is the case if the counter mask of such an event is not |
| 247 | * a subset of any other counter mask of a constraint with an equal or |
| 248 | * higher weight, e.g.: |
| 249 | * |
| 250 | * c_overlaps = EVENT_CONSTRAINT_OVERLAP(0, 0x09, 0); |
| 251 | * c_another1 = EVENT_CONSTRAINT(0, 0x07, 0); |
| 252 | * c_another2 = EVENT_CONSTRAINT(0, 0x38, 0); |
| 253 | * |
| 254 | * The event scheduler may not select the correct counter in the first |
| 255 | * cycle because it needs to know which subsequent events will be |
| 256 | * scheduled. It may fail to schedule the events then. So we set the |
| 257 | * overlap flag for such constraints to give the scheduler a hint which |
| 258 | * events to select for counter rescheduling. |
| 259 | * |
| 260 | * Care must be taken as the rescheduling algorithm is O(n!) which |
| 261 | * will increase scheduling cycles for an over-commited system |
| 262 | * dramatically. The number of such EVENT_CONSTRAINT_OVERLAP() macros |
| 263 | * and its counter masks must be kept at a minimum. |
| 264 | */ |
| 265 | #define EVENT_CONSTRAINT_OVERLAP(c, n, m) \ |
Stephane Eranian | 9fac2cf | 2013-01-24 16:10:27 +0100 | [diff] [blame] | 266 | __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 1, 0) |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 267 | |
| 268 | /* |
| 269 | * Constraint on the Event code. |
| 270 | */ |
| 271 | #define INTEL_EVENT_CONSTRAINT(c, n) \ |
| 272 | EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT) |
| 273 | |
| 274 | /* |
| 275 | * Constraint on the Event code + UMask + fixed-mask |
| 276 | * |
| 277 | * filter mask to validate fixed counter events. |
| 278 | * the following filters disqualify for fixed counters: |
| 279 | * - inv |
| 280 | * - edge |
| 281 | * - cnt-mask |
Andi Kleen | 3a632cb | 2013-06-17 17:36:48 -0700 | [diff] [blame] | 282 | * - in_tx |
| 283 | * - in_tx_checkpointed |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 284 | * The other filters are supported by fixed counters. |
| 285 | * The any-thread option is supported starting with v3. |
| 286 | */ |
Andi Kleen | 3a632cb | 2013-06-17 17:36:48 -0700 | [diff] [blame] | 287 | #define FIXED_EVENT_FLAGS (X86_RAW_EVENT_MASK|HSW_IN_TX|HSW_IN_TX_CHECKPOINTED) |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 288 | #define FIXED_EVENT_CONSTRAINT(c, n) \ |
Andi Kleen | 3a632cb | 2013-06-17 17:36:48 -0700 | [diff] [blame] | 289 | EVENT_CONSTRAINT(c, (1ULL << (32+n)), FIXED_EVENT_FLAGS) |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * Constraint on the Event code + UMask |
| 293 | */ |
| 294 | #define INTEL_UEVENT_CONSTRAINT(c, n) \ |
| 295 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK) |
| 296 | |
Andi Kleen | 7550ddf | 2014-09-24 07:34:46 -0700 | [diff] [blame] | 297 | /* Like UEVENT_CONSTRAINT, but match flags too */ |
| 298 | #define INTEL_FLAGS_UEVENT_CONSTRAINT(c, n) \ |
| 299 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS) |
| 300 | |
Maria Dimakopoulou | e979121 | 2014-11-17 20:06:58 +0100 | [diff] [blame] | 301 | #define INTEL_EXCLUEVT_CONSTRAINT(c, n) \ |
| 302 | __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK, \ |
| 303 | HWEIGHT(n), 0, PERF_X86_EVENT_EXCL) |
| 304 | |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 305 | #define INTEL_PLD_CONSTRAINT(c, n) \ |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 306 | __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \ |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 307 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LDLAT) |
| 308 | |
Stephane Eranian | 9ad64c0 | 2013-01-24 16:10:34 +0100 | [diff] [blame] | 309 | #define INTEL_PST_CONSTRAINT(c, n) \ |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 310 | __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \ |
Stephane Eranian | 9ad64c0 | 2013-01-24 16:10:34 +0100 | [diff] [blame] | 311 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST) |
| 312 | |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 313 | /* Event constraint, but match on all event flags too. */ |
| 314 | #define INTEL_FLAGS_EVENT_CONSTRAINT(c, n) \ |
| 315 | EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS) |
| 316 | |
| 317 | /* Check only flags, but allow all event/umask */ |
| 318 | #define INTEL_ALL_EVENT_CONSTRAINT(code, n) \ |
| 319 | EVENT_CONSTRAINT(code, n, X86_ALL_EVENT_FLAGS) |
| 320 | |
| 321 | /* Check flags and event code, and set the HSW store flag */ |
| 322 | #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_ST(code, n) \ |
| 323 | __EVENT_CONSTRAINT(code, n, \ |
| 324 | ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \ |
Andi Kleen | f9134f3 | 2013-06-17 17:36:52 -0700 | [diff] [blame] | 325 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST_HSW) |
| 326 | |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 327 | /* Check flags and event code, and set the HSW load flag */ |
| 328 | #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_LD(code, n) \ |
Maria Dimakopoulou | b63b4b4 | 2014-11-17 20:07:00 +0100 | [diff] [blame^] | 329 | __EVENT_CONSTRAINT(code, n, \ |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 330 | ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \ |
| 331 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LD_HSW) |
| 332 | |
Maria Dimakopoulou | b63b4b4 | 2014-11-17 20:07:00 +0100 | [diff] [blame^] | 333 | #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_XLD(code, n) \ |
| 334 | __EVENT_CONSTRAINT(code, n, \ |
| 335 | ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \ |
| 336 | HWEIGHT(n), 0, \ |
| 337 | PERF_X86_EVENT_PEBS_LD_HSW|PERF_X86_EVENT_EXCL) |
| 338 | |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 339 | /* Check flags and event code/umask, and set the HSW store flag */ |
| 340 | #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST(code, n) \ |
| 341 | __EVENT_CONSTRAINT(code, n, \ |
| 342 | INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \ |
| 343 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST_HSW) |
| 344 | |
Maria Dimakopoulou | b63b4b4 | 2014-11-17 20:07:00 +0100 | [diff] [blame^] | 345 | #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XST(code, n) \ |
| 346 | __EVENT_CONSTRAINT(code, n, \ |
| 347 | INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \ |
| 348 | HWEIGHT(n), 0, \ |
| 349 | PERF_X86_EVENT_PEBS_ST_HSW|PERF_X86_EVENT_EXCL) |
| 350 | |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 351 | /* Check flags and event code/umask, and set the HSW load flag */ |
| 352 | #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD(code, n) \ |
| 353 | __EVENT_CONSTRAINT(code, n, \ |
| 354 | INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \ |
| 355 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LD_HSW) |
| 356 | |
Maria Dimakopoulou | b63b4b4 | 2014-11-17 20:07:00 +0100 | [diff] [blame^] | 357 | #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(code, n) \ |
| 358 | __EVENT_CONSTRAINT(code, n, \ |
| 359 | INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \ |
| 360 | HWEIGHT(n), 0, \ |
| 361 | PERF_X86_EVENT_PEBS_LD_HSW|PERF_X86_EVENT_EXCL) |
| 362 | |
Andi Kleen | 86a0446 | 2014-08-11 21:27:10 +0200 | [diff] [blame] | 363 | /* Check flags and event code/umask, and set the HSW N/A flag */ |
| 364 | #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(code, n) \ |
| 365 | __EVENT_CONSTRAINT(code, n, \ |
| 366 | INTEL_ARCH_EVENT_MASK|INTEL_ARCH_EVENT_MASK, \ |
| 367 | HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_NA_HSW) |
| 368 | |
| 369 | |
Maria Dimakopoulou | cf30d52 | 2013-12-05 01:24:37 +0200 | [diff] [blame] | 370 | /* |
| 371 | * We define the end marker as having a weight of -1 |
| 372 | * to enable blacklisting of events using a counter bitmask |
| 373 | * of zero and thus a weight of zero. |
| 374 | * The end marker has a weight that cannot possibly be |
| 375 | * obtained from counting the bits in the bitmask. |
| 376 | */ |
| 377 | #define EVENT_CONSTRAINT_END { .weight = -1 } |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 378 | |
Maria Dimakopoulou | cf30d52 | 2013-12-05 01:24:37 +0200 | [diff] [blame] | 379 | /* |
| 380 | * Check for end marker with weight == -1 |
| 381 | */ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 382 | #define for_each_event_constraint(e, c) \ |
Maria Dimakopoulou | cf30d52 | 2013-12-05 01:24:37 +0200 | [diff] [blame] | 383 | for ((e) = (c); (e)->weight != -1; (e)++) |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 384 | |
| 385 | /* |
| 386 | * Extra registers for specific events. |
| 387 | * |
| 388 | * Some events need large masks and require external MSRs. |
| 389 | * Those extra MSRs end up being shared for all events on |
| 390 | * a PMU and sometimes between PMU of sibling HT threads. |
| 391 | * In either case, the kernel needs to handle conflicting |
| 392 | * accesses to those extra, shared, regs. The data structure |
| 393 | * to manage those registers is stored in cpu_hw_event. |
| 394 | */ |
| 395 | struct extra_reg { |
| 396 | unsigned int event; |
| 397 | unsigned int msr; |
| 398 | u64 config_mask; |
| 399 | u64 valid_mask; |
| 400 | int idx; /* per_xxx->regs[] reg index */ |
Kan Liang | 338b522 | 2014-07-14 12:25:56 -0700 | [diff] [blame] | 401 | bool extra_msr_access; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 402 | }; |
| 403 | |
| 404 | #define EVENT_EXTRA_REG(e, ms, m, vm, i) { \ |
Kan Liang | 338b522 | 2014-07-14 12:25:56 -0700 | [diff] [blame] | 405 | .event = (e), \ |
| 406 | .msr = (ms), \ |
| 407 | .config_mask = (m), \ |
| 408 | .valid_mask = (vm), \ |
| 409 | .idx = EXTRA_REG_##i, \ |
| 410 | .extra_msr_access = true, \ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | #define INTEL_EVENT_EXTRA_REG(event, msr, vm, idx) \ |
| 414 | EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT, vm, idx) |
| 415 | |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 416 | #define INTEL_UEVENT_EXTRA_REG(event, msr, vm, idx) \ |
| 417 | EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT | \ |
| 418 | ARCH_PERFMON_EVENTSEL_UMASK, vm, idx) |
| 419 | |
| 420 | #define INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(c) \ |
| 421 | INTEL_UEVENT_EXTRA_REG(c, \ |
| 422 | MSR_PEBS_LD_LAT_THRESHOLD, \ |
| 423 | 0xffff, \ |
| 424 | LDLAT) |
| 425 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 426 | #define EVENT_EXTRA_END EVENT_EXTRA_REG(0, 0, 0, 0, RSP_0) |
| 427 | |
| 428 | union perf_capabilities { |
| 429 | struct { |
| 430 | u64 lbr_format:6; |
| 431 | u64 pebs_trap:1; |
| 432 | u64 pebs_arch_reg:1; |
| 433 | u64 pebs_format:4; |
| 434 | u64 smm_freeze:1; |
Andi Kleen | 069e0c3 | 2013-06-25 08:12:33 -0700 | [diff] [blame] | 435 | /* |
| 436 | * PMU supports separate counter range for writing |
| 437 | * values > 32bit. |
| 438 | */ |
| 439 | u64 full_width_write:1; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 440 | }; |
| 441 | u64 capabilities; |
| 442 | }; |
| 443 | |
Peter Zijlstra | c1d6f42 | 2011-12-06 14:07:15 +0100 | [diff] [blame] | 444 | struct x86_pmu_quirk { |
| 445 | struct x86_pmu_quirk *next; |
| 446 | void (*func)(void); |
| 447 | }; |
| 448 | |
Peter Zijlstra | f9b4eeb | 2012-03-12 12:44:35 +0100 | [diff] [blame] | 449 | union x86_pmu_config { |
| 450 | struct { |
| 451 | u64 event:8, |
| 452 | umask:8, |
| 453 | usr:1, |
| 454 | os:1, |
| 455 | edge:1, |
| 456 | pc:1, |
| 457 | interrupt:1, |
| 458 | __reserved1:1, |
| 459 | en:1, |
| 460 | inv:1, |
| 461 | cmask:8, |
| 462 | event2:4, |
| 463 | __reserved2:4, |
| 464 | go:1, |
| 465 | ho:1; |
| 466 | } bits; |
| 467 | u64 value; |
| 468 | }; |
| 469 | |
| 470 | #define X86_CONFIG(args...) ((union x86_pmu_config){.bits = {args}}).value |
| 471 | |
Alexander Shishkin | 4807034 | 2015-01-14 14:18:20 +0200 | [diff] [blame] | 472 | enum { |
| 473 | x86_lbr_exclusive_lbr, |
Alexander Shishkin | 8062382 | 2015-01-30 12:40:35 +0200 | [diff] [blame] | 474 | x86_lbr_exclusive_bts, |
Alexander Shishkin | 4807034 | 2015-01-14 14:18:20 +0200 | [diff] [blame] | 475 | x86_lbr_exclusive_pt, |
| 476 | x86_lbr_exclusive_max, |
| 477 | }; |
| 478 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 479 | /* |
| 480 | * struct x86_pmu - generic x86 pmu |
| 481 | */ |
| 482 | struct x86_pmu { |
| 483 | /* |
| 484 | * Generic x86 PMC bits |
| 485 | */ |
| 486 | const char *name; |
| 487 | int version; |
| 488 | int (*handle_irq)(struct pt_regs *); |
| 489 | void (*disable_all)(void); |
| 490 | void (*enable_all)(int added); |
| 491 | void (*enable)(struct perf_event *); |
| 492 | void (*disable)(struct perf_event *); |
| 493 | int (*hw_config)(struct perf_event *event); |
| 494 | int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign); |
| 495 | unsigned eventsel; |
| 496 | unsigned perfctr; |
Jacob Shin | 4c1fd17 | 2013-02-06 11:26:27 -0600 | [diff] [blame] | 497 | int (*addr_offset)(int index, bool eventsel); |
Jacob Shin | 0fbdad0 | 2013-02-06 11:26:28 -0600 | [diff] [blame] | 498 | int (*rdpmc_index)(int index); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 499 | u64 (*event_map)(int); |
| 500 | int max_events; |
| 501 | int num_counters; |
| 502 | int num_counters_fixed; |
| 503 | int cntval_bits; |
| 504 | u64 cntval_mask; |
Gleb Natapov | ffb871b | 2011-11-10 14:57:26 +0200 | [diff] [blame] | 505 | union { |
| 506 | unsigned long events_maskl; |
| 507 | unsigned long events_mask[BITS_TO_LONGS(ARCH_PERFMON_EVENTS_COUNT)]; |
| 508 | }; |
| 509 | int events_mask_len; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 510 | int apic; |
| 511 | u64 max_period; |
| 512 | struct event_constraint * |
| 513 | (*get_event_constraints)(struct cpu_hw_events *cpuc, |
Stephane Eranian | 79cba82 | 2014-11-17 20:06:56 +0100 | [diff] [blame] | 514 | int idx, |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 515 | struct perf_event *event); |
| 516 | |
| 517 | void (*put_event_constraints)(struct cpu_hw_events *cpuc, |
| 518 | struct perf_event *event); |
Maria Dimakopoulou | c5362c0 | 2014-11-17 20:06:55 +0100 | [diff] [blame] | 519 | |
| 520 | void (*commit_scheduling)(struct cpu_hw_events *cpuc, |
| 521 | struct perf_event *event, |
| 522 | int cntr); |
| 523 | |
| 524 | void (*start_scheduling)(struct cpu_hw_events *cpuc); |
| 525 | |
| 526 | void (*stop_scheduling)(struct cpu_hw_events *cpuc); |
| 527 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 528 | struct event_constraint *event_constraints; |
Peter Zijlstra | c1d6f42 | 2011-12-06 14:07:15 +0100 | [diff] [blame] | 529 | struct x86_pmu_quirk *quirks; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 530 | int perfctr_second_write; |
Andi Kleen | 72db559 | 2013-06-17 17:36:50 -0700 | [diff] [blame] | 531 | bool late_ack; |
Andi Kleen | 294fe0f | 2015-02-17 18:18:06 -0800 | [diff] [blame] | 532 | unsigned (*limit_period)(struct perf_event *event, unsigned l); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 533 | |
Peter Zijlstra | 0c9d42e | 2011-11-20 23:30:47 +0100 | [diff] [blame] | 534 | /* |
| 535 | * sysfs attrs |
| 536 | */ |
Peter Zijlstra | e97df76 | 2014-02-05 20:48:51 +0100 | [diff] [blame] | 537 | int attr_rdpmc_broken; |
Peter Zijlstra | 0c9d42e | 2011-11-20 23:30:47 +0100 | [diff] [blame] | 538 | int attr_rdpmc; |
Jiri Olsa | 641cc93 | 2012-03-15 20:09:14 +0100 | [diff] [blame] | 539 | struct attribute **format_attrs; |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 540 | struct attribute **event_attrs; |
Peter Zijlstra | 0c9d42e | 2011-11-20 23:30:47 +0100 | [diff] [blame] | 541 | |
Jiri Olsa | a474739 | 2012-10-10 14:53:11 +0200 | [diff] [blame] | 542 | ssize_t (*events_sysfs_show)(char *page, u64 config); |
Andi Kleen | 1a6461b | 2013-01-24 16:10:25 +0100 | [diff] [blame] | 543 | struct attribute **cpu_events; |
Jiri Olsa | a474739 | 2012-10-10 14:53:11 +0200 | [diff] [blame] | 544 | |
Peter Zijlstra | 0c9d42e | 2011-11-20 23:30:47 +0100 | [diff] [blame] | 545 | /* |
| 546 | * CPU Hotplug hooks |
| 547 | */ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 548 | int (*cpu_prepare)(int cpu); |
| 549 | void (*cpu_starting)(int cpu); |
| 550 | void (*cpu_dying)(int cpu); |
| 551 | void (*cpu_dead)(int cpu); |
Peter Zijlstra | c93dc84 | 2012-06-08 14:50:50 +0200 | [diff] [blame] | 552 | |
| 553 | void (*check_microcode)(void); |
Yan, Zheng | ba53250 | 2014-11-04 21:55:58 -0500 | [diff] [blame] | 554 | void (*sched_task)(struct perf_event_context *ctx, |
| 555 | bool sched_in); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 556 | |
| 557 | /* |
| 558 | * Intel Arch Perfmon v2+ |
| 559 | */ |
| 560 | u64 intel_ctrl; |
| 561 | union perf_capabilities intel_cap; |
| 562 | |
| 563 | /* |
| 564 | * Intel DebugStore bits |
| 565 | */ |
Peter Zijlstra | 597ed95 | 2012-07-09 13:50:23 +0200 | [diff] [blame] | 566 | unsigned int bts :1, |
Peter Zijlstra | 3e0091e | 2012-06-26 23:38:39 +0200 | [diff] [blame] | 567 | bts_active :1, |
| 568 | pebs :1, |
| 569 | pebs_active :1, |
| 570 | pebs_broken :1; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 571 | int pebs_record_size; |
| 572 | void (*drain_pebs)(struct pt_regs *regs); |
| 573 | struct event_constraint *pebs_constraints; |
Peter Zijlstra | 0780c92 | 2012-06-05 10:26:43 +0200 | [diff] [blame] | 574 | void (*pebs_aliases)(struct perf_event *event); |
Andi Kleen | 70ab700 | 2012-06-05 17:56:48 -0700 | [diff] [blame] | 575 | int max_pebs_events; |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 576 | |
| 577 | /* |
| 578 | * Intel LBR |
| 579 | */ |
| 580 | unsigned long lbr_tos, lbr_from, lbr_to; /* MSR base regs */ |
| 581 | int lbr_nr; /* hardware stack size */ |
Stephane Eranian | b36817e | 2012-02-09 23:20:53 +0100 | [diff] [blame] | 582 | u64 lbr_sel_mask; /* LBR_SELECT valid bits */ |
| 583 | const int *lbr_sel_map; /* lbr_select mappings */ |
Andi Kleen | b7af41a | 2013-09-20 07:40:44 -0700 | [diff] [blame] | 584 | bool lbr_double_abort; /* duplicated lbr aborts */ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 585 | |
| 586 | /* |
Alexander Shishkin | 4807034 | 2015-01-14 14:18:20 +0200 | [diff] [blame] | 587 | * Intel PT/LBR/BTS are exclusive |
| 588 | */ |
| 589 | atomic_t lbr_exclusive[x86_lbr_exclusive_max]; |
| 590 | |
| 591 | /* |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 592 | * Extra registers for events |
| 593 | */ |
| 594 | struct extra_reg *extra_regs; |
Stephane Eranian | 9a5e3fb | 2014-11-17 20:06:53 +0100 | [diff] [blame] | 595 | unsigned int flags; |
Gleb Natapov | 144d31e | 2011-10-05 14:01:21 +0200 | [diff] [blame] | 596 | |
| 597 | /* |
| 598 | * Intel host/guest support (KVM) |
| 599 | */ |
| 600 | struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 601 | }; |
| 602 | |
Yan, Zheng | e18bf52 | 2014-11-04 21:56:03 -0500 | [diff] [blame] | 603 | struct x86_perf_task_context { |
| 604 | u64 lbr_from[MAX_LBR_ENTRIES]; |
| 605 | u64 lbr_to[MAX_LBR_ENTRIES]; |
| 606 | int lbr_callstack_users; |
| 607 | int lbr_stack_state; |
| 608 | }; |
| 609 | |
Peter Zijlstra | c1d6f42 | 2011-12-06 14:07:15 +0100 | [diff] [blame] | 610 | #define x86_add_quirk(func_) \ |
| 611 | do { \ |
| 612 | static struct x86_pmu_quirk __quirk __initdata = { \ |
| 613 | .func = func_, \ |
| 614 | }; \ |
| 615 | __quirk.next = x86_pmu.quirks; \ |
| 616 | x86_pmu.quirks = &__quirk; \ |
| 617 | } while (0) |
| 618 | |
Stephane Eranian | 9a5e3fb | 2014-11-17 20:06:53 +0100 | [diff] [blame] | 619 | /* |
| 620 | * x86_pmu flags |
| 621 | */ |
| 622 | #define PMU_FL_NO_HT_SHARING 0x1 /* no hyper-threading resource sharing */ |
| 623 | #define PMU_FL_HAS_RSP_1 0x2 /* has 2 equivalent offcore_rsp regs */ |
Maria Dimakopoulou | 6f6539c | 2014-11-17 20:06:57 +0100 | [diff] [blame] | 624 | #define PMU_FL_EXCL_CNTRS 0x4 /* has exclusive counter requirements */ |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 625 | |
Stephane Eranian | 3a54aaa | 2013-01-24 16:10:26 +0100 | [diff] [blame] | 626 | #define EVENT_VAR(_id) event_attr_##_id |
| 627 | #define EVENT_PTR(_id) &event_attr_##_id.attr.attr |
| 628 | |
| 629 | #define EVENT_ATTR(_name, _id) \ |
| 630 | static struct perf_pmu_events_attr EVENT_VAR(_id) = { \ |
| 631 | .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \ |
| 632 | .id = PERF_COUNT_HW_##_id, \ |
| 633 | .event_str = NULL, \ |
| 634 | }; |
| 635 | |
| 636 | #define EVENT_ATTR_STR(_name, v, str) \ |
| 637 | static struct perf_pmu_events_attr event_attr_##v = { \ |
| 638 | .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \ |
| 639 | .id = 0, \ |
| 640 | .event_str = str, \ |
| 641 | }; |
| 642 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 643 | extern struct x86_pmu x86_pmu __read_mostly; |
| 644 | |
Yan, Zheng | e9d7f7cd | 2014-11-04 21:56:00 -0500 | [diff] [blame] | 645 | static inline bool x86_pmu_has_lbr_callstack(void) |
| 646 | { |
| 647 | return x86_pmu.lbr_sel_map && |
| 648 | x86_pmu.lbr_sel_map[PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT] > 0; |
| 649 | } |
| 650 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 651 | DECLARE_PER_CPU(struct cpu_hw_events, cpu_hw_events); |
| 652 | |
| 653 | int x86_perf_event_set_period(struct perf_event *event); |
| 654 | |
| 655 | /* |
| 656 | * Generalized hw caching related hw_event table, filled |
| 657 | * in on a per model basis. A value of 0 means |
| 658 | * 'not supported', -1 means 'hw_event makes no sense on |
| 659 | * this CPU', any other value means the raw hw_event |
| 660 | * ID. |
| 661 | */ |
| 662 | |
| 663 | #define C(x) PERF_COUNT_HW_CACHE_##x |
| 664 | |
| 665 | extern u64 __read_mostly hw_cache_event_ids |
| 666 | [PERF_COUNT_HW_CACHE_MAX] |
| 667 | [PERF_COUNT_HW_CACHE_OP_MAX] |
| 668 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; |
| 669 | extern u64 __read_mostly hw_cache_extra_regs |
| 670 | [PERF_COUNT_HW_CACHE_MAX] |
| 671 | [PERF_COUNT_HW_CACHE_OP_MAX] |
| 672 | [PERF_COUNT_HW_CACHE_RESULT_MAX]; |
| 673 | |
| 674 | u64 x86_perf_event_update(struct perf_event *event); |
| 675 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 676 | static inline unsigned int x86_pmu_config_addr(int index) |
| 677 | { |
Jacob Shin | 4c1fd17 | 2013-02-06 11:26:27 -0600 | [diff] [blame] | 678 | return x86_pmu.eventsel + (x86_pmu.addr_offset ? |
| 679 | x86_pmu.addr_offset(index, true) : index); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | static inline unsigned int x86_pmu_event_addr(int index) |
| 683 | { |
Jacob Shin | 4c1fd17 | 2013-02-06 11:26:27 -0600 | [diff] [blame] | 684 | return x86_pmu.perfctr + (x86_pmu.addr_offset ? |
| 685 | x86_pmu.addr_offset(index, false) : index); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 686 | } |
| 687 | |
Jacob Shin | 0fbdad0 | 2013-02-06 11:26:28 -0600 | [diff] [blame] | 688 | static inline int x86_pmu_rdpmc_index(int index) |
| 689 | { |
| 690 | return x86_pmu.rdpmc_index ? x86_pmu.rdpmc_index(index) : index; |
| 691 | } |
| 692 | |
Alexander Shishkin | 4807034 | 2015-01-14 14:18:20 +0200 | [diff] [blame] | 693 | int x86_add_exclusive(unsigned int what); |
| 694 | |
| 695 | void x86_del_exclusive(unsigned int what); |
| 696 | |
| 697 | void hw_perf_lbr_event_destroy(struct perf_event *event); |
| 698 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 699 | int x86_setup_perfctr(struct perf_event *event); |
| 700 | |
| 701 | int x86_pmu_hw_config(struct perf_event *event); |
| 702 | |
| 703 | void x86_pmu_disable_all(void); |
| 704 | |
| 705 | static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc, |
| 706 | u64 enable_mask) |
| 707 | { |
Joerg Roedel | 1018faa | 2012-02-29 14:57:32 +0100 | [diff] [blame] | 708 | u64 disable_mask = __this_cpu_read(cpu_hw_events.perf_ctr_virt_mask); |
| 709 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 710 | if (hwc->extra_reg.reg) |
| 711 | wrmsrl(hwc->extra_reg.reg, hwc->extra_reg.config); |
Joerg Roedel | 1018faa | 2012-02-29 14:57:32 +0100 | [diff] [blame] | 712 | wrmsrl(hwc->config_base, (hwc->config | enable_mask) & ~disable_mask); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | void x86_pmu_enable_all(int added); |
| 716 | |
Andrew Hunter | 43b45780 | 2013-05-23 11:07:03 -0700 | [diff] [blame] | 717 | int perf_assign_events(struct perf_event **events, int n, |
Yan, Zheng | 4b4969b | 2012-06-15 14:31:30 +0800 | [diff] [blame] | 718 | int wmin, int wmax, int *assign); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 719 | int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign); |
| 720 | |
| 721 | void x86_pmu_stop(struct perf_event *event, int flags); |
| 722 | |
| 723 | static inline void x86_pmu_disable_event(struct perf_event *event) |
| 724 | { |
| 725 | struct hw_perf_event *hwc = &event->hw; |
| 726 | |
| 727 | wrmsrl(hwc->config_base, hwc->config); |
| 728 | } |
| 729 | |
| 730 | void x86_pmu_enable_event(struct perf_event *event); |
| 731 | |
| 732 | int x86_pmu_handle_irq(struct pt_regs *regs); |
| 733 | |
| 734 | extern struct event_constraint emptyconstraint; |
| 735 | |
| 736 | extern struct event_constraint unconstrained; |
| 737 | |
Stephane Eranian | 3e702ff | 2012-02-09 23:20:58 +0100 | [diff] [blame] | 738 | static inline bool kernel_ip(unsigned long ip) |
| 739 | { |
| 740 | #ifdef CONFIG_X86_32 |
| 741 | return ip > PAGE_OFFSET; |
| 742 | #else |
| 743 | return (long)ip < 0; |
| 744 | #endif |
| 745 | } |
| 746 | |
Peter Zijlstra | d07bdfd | 2012-07-10 09:42:15 +0200 | [diff] [blame] | 747 | /* |
| 748 | * Not all PMUs provide the right context information to place the reported IP |
| 749 | * into full context. Specifically segment registers are typically not |
| 750 | * supplied. |
| 751 | * |
| 752 | * Assuming the address is a linear address (it is for IBS), we fake the CS and |
| 753 | * vm86 mode using the known zero-based code segment and 'fix up' the registers |
| 754 | * to reflect this. |
| 755 | * |
| 756 | * Intel PEBS/LBR appear to typically provide the effective address, nothing |
| 757 | * much we can do about that but pray and treat it like a linear address. |
| 758 | */ |
| 759 | static inline void set_linear_ip(struct pt_regs *regs, unsigned long ip) |
| 760 | { |
| 761 | regs->cs = kernel_ip(ip) ? __KERNEL_CS : __USER_CS; |
| 762 | if (regs->flags & X86_VM_MASK) |
| 763 | regs->flags ^= (PERF_EFLAGS_VM | X86_VM_MASK); |
| 764 | regs->ip = ip; |
| 765 | } |
| 766 | |
Jiri Olsa | 0bf79d4 | 2012-10-10 14:53:14 +0200 | [diff] [blame] | 767 | ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event); |
Jiri Olsa | 20550a4 | 2012-10-10 14:53:15 +0200 | [diff] [blame] | 768 | ssize_t intel_event_sysfs_show(char *page, u64 config); |
Jiri Olsa | 43c032f | 2012-10-10 14:53:13 +0200 | [diff] [blame] | 769 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 770 | #ifdef CONFIG_CPU_SUP_AMD |
| 771 | |
| 772 | int amd_pmu_init(void); |
| 773 | |
| 774 | #else /* CONFIG_CPU_SUP_AMD */ |
| 775 | |
| 776 | static inline int amd_pmu_init(void) |
| 777 | { |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | #endif /* CONFIG_CPU_SUP_AMD */ |
| 782 | |
| 783 | #ifdef CONFIG_CPU_SUP_INTEL |
| 784 | |
Alexander Shishkin | 4807034 | 2015-01-14 14:18:20 +0200 | [diff] [blame] | 785 | static inline bool intel_pmu_needs_lbr_smpl(struct perf_event *event) |
| 786 | { |
| 787 | /* user explicitly requested branch sampling */ |
| 788 | if (has_branch_stack(event)) |
| 789 | return true; |
| 790 | |
| 791 | /* implicit branch sampling to correct PEBS skid */ |
| 792 | if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1 && |
| 793 | x86_pmu.intel_cap.pebs_format < 2) |
| 794 | return true; |
| 795 | |
| 796 | return false; |
| 797 | } |
| 798 | |
| 799 | static inline bool intel_pmu_has_bts(struct perf_event *event) |
| 800 | { |
| 801 | if (event->attr.config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS && |
| 802 | !event->attr.freq && event->hw.sample_period == 1) |
| 803 | return true; |
| 804 | |
| 805 | return false; |
| 806 | } |
| 807 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 808 | int intel_pmu_save_and_restart(struct perf_event *event); |
| 809 | |
| 810 | struct event_constraint * |
Stephane Eranian | 79cba82 | 2014-11-17 20:06:56 +0100 | [diff] [blame] | 811 | x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx, |
| 812 | struct perf_event *event); |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 813 | |
| 814 | struct intel_shared_regs *allocate_shared_regs(int cpu); |
| 815 | |
| 816 | int intel_pmu_init(void); |
| 817 | |
| 818 | void init_debug_store_on_cpu(int cpu); |
| 819 | |
| 820 | void fini_debug_store_on_cpu(int cpu); |
| 821 | |
| 822 | void release_ds_buffers(void); |
| 823 | |
| 824 | void reserve_ds_buffers(void); |
| 825 | |
| 826 | extern struct event_constraint bts_constraint; |
| 827 | |
| 828 | void intel_pmu_enable_bts(u64 config); |
| 829 | |
| 830 | void intel_pmu_disable_bts(void); |
| 831 | |
| 832 | int intel_pmu_drain_bts_buffer(void); |
| 833 | |
| 834 | extern struct event_constraint intel_core2_pebs_event_constraints[]; |
| 835 | |
| 836 | extern struct event_constraint intel_atom_pebs_event_constraints[]; |
| 837 | |
Yan, Zheng | 1fa6418 | 2013-07-18 17:02:24 +0800 | [diff] [blame] | 838 | extern struct event_constraint intel_slm_pebs_event_constraints[]; |
| 839 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 840 | extern struct event_constraint intel_nehalem_pebs_event_constraints[]; |
| 841 | |
| 842 | extern struct event_constraint intel_westmere_pebs_event_constraints[]; |
| 843 | |
| 844 | extern struct event_constraint intel_snb_pebs_event_constraints[]; |
| 845 | |
Stephane Eranian | 20a36e3 | 2012-09-11 01:07:01 +0200 | [diff] [blame] | 846 | extern struct event_constraint intel_ivb_pebs_event_constraints[]; |
| 847 | |
Andi Kleen | 3044318 | 2013-06-17 17:36:49 -0700 | [diff] [blame] | 848 | extern struct event_constraint intel_hsw_pebs_event_constraints[]; |
| 849 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 850 | struct event_constraint *intel_pebs_constraints(struct perf_event *event); |
| 851 | |
| 852 | void intel_pmu_pebs_enable(struct perf_event *event); |
| 853 | |
| 854 | void intel_pmu_pebs_disable(struct perf_event *event); |
| 855 | |
| 856 | void intel_pmu_pebs_enable_all(void); |
| 857 | |
| 858 | void intel_pmu_pebs_disable_all(void); |
| 859 | |
| 860 | void intel_ds_init(void); |
| 861 | |
Yan, Zheng | 2a0ad3b | 2014-11-04 21:55:59 -0500 | [diff] [blame] | 862 | void intel_pmu_lbr_sched_task(struct perf_event_context *ctx, bool sched_in); |
| 863 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 864 | void intel_pmu_lbr_reset(void); |
| 865 | |
| 866 | void intel_pmu_lbr_enable(struct perf_event *event); |
| 867 | |
| 868 | void intel_pmu_lbr_disable(struct perf_event *event); |
| 869 | |
| 870 | void intel_pmu_lbr_enable_all(void); |
| 871 | |
| 872 | void intel_pmu_lbr_disable_all(void); |
| 873 | |
| 874 | void intel_pmu_lbr_read(void); |
| 875 | |
| 876 | void intel_pmu_lbr_init_core(void); |
| 877 | |
| 878 | void intel_pmu_lbr_init_nhm(void); |
| 879 | |
| 880 | void intel_pmu_lbr_init_atom(void); |
| 881 | |
Stephane Eranian | c5cc2cd | 2012-02-09 23:20:55 +0100 | [diff] [blame] | 882 | void intel_pmu_lbr_init_snb(void); |
| 883 | |
Yan, Zheng | e9d7f7cd | 2014-11-04 21:56:00 -0500 | [diff] [blame] | 884 | void intel_pmu_lbr_init_hsw(void); |
| 885 | |
Stephane Eranian | 60ce0fb | 2012-02-09 23:20:57 +0100 | [diff] [blame] | 886 | int intel_pmu_setup_lbr_filter(struct perf_event *event); |
| 887 | |
Alexander Shishkin | 52ca9ce | 2015-01-30 12:39:52 +0200 | [diff] [blame] | 888 | void intel_pt_interrupt(void); |
| 889 | |
Alexander Shishkin | 8062382 | 2015-01-30 12:40:35 +0200 | [diff] [blame] | 890 | int intel_bts_interrupt(void); |
| 891 | |
| 892 | void intel_bts_enable_local(void); |
| 893 | |
| 894 | void intel_bts_disable_local(void); |
| 895 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 896 | int p4_pmu_init(void); |
| 897 | |
| 898 | int p6_pmu_init(void); |
| 899 | |
Vince Weaver | e717bf4 | 2012-09-26 14:12:52 -0400 | [diff] [blame] | 900 | int knc_pmu_init(void); |
| 901 | |
Stephane Eranian | f20093e | 2013-01-24 16:10:32 +0100 | [diff] [blame] | 902 | ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, |
| 903 | char *page); |
| 904 | |
Kevin Winchester | de0428a | 2011-08-30 20:41:05 -0300 | [diff] [blame] | 905 | #else /* CONFIG_CPU_SUP_INTEL */ |
| 906 | |
| 907 | static inline void reserve_ds_buffers(void) |
| 908 | { |
| 909 | } |
| 910 | |
| 911 | static inline void release_ds_buffers(void) |
| 912 | { |
| 913 | } |
| 914 | |
| 915 | static inline int intel_pmu_init(void) |
| 916 | { |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static inline struct intel_shared_regs *allocate_shared_regs(int cpu) |
| 921 | { |
| 922 | return NULL; |
| 923 | } |
| 924 | |
| 925 | #endif /* CONFIG_CPU_SUP_INTEL */ |