perf_event.h 20 KB

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