perf_event.h 19 KB

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