perf_event.h 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781
  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
  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. #include <asm/fpu/xstate.h>
  16. #include <asm/intel_ds.h>
  17. #include <asm/cpu.h>
  18. /* To enable MSR tracing please use the generic trace points. */
  19. /*
  20. * | NHM/WSM | SNB |
  21. * register -------------------------------
  22. * | HT | no HT | HT | no HT |
  23. *-----------------------------------------
  24. * offcore | core | core | cpu | core |
  25. * lbr_sel | core | core | cpu | core |
  26. * ld_lat | cpu | core | cpu | core |
  27. *-----------------------------------------
  28. *
  29. * Given that there is a small number of shared regs,
  30. * we can pre-allocate their slot in the per-cpu
  31. * per-core reg tables.
  32. */
  33. enum extra_reg_type {
  34. EXTRA_REG_NONE = -1, /* not used */
  35. EXTRA_REG_RSP_0 = 0, /* offcore_response_0 */
  36. EXTRA_REG_RSP_1 = 1, /* offcore_response_1 */
  37. EXTRA_REG_LBR = 2, /* lbr_select */
  38. EXTRA_REG_LDLAT = 3, /* ld_lat_threshold */
  39. EXTRA_REG_FE = 4, /* fe_* */
  40. EXTRA_REG_SNOOP_0 = 5, /* snoop response 0 */
  41. EXTRA_REG_SNOOP_1 = 6, /* snoop response 1 */
  42. EXTRA_REG_MAX /* number of entries needed */
  43. };
  44. struct event_constraint {
  45. union {
  46. unsigned long idxmsk[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  47. u64 idxmsk64;
  48. };
  49. u64 code;
  50. u64 cmask;
  51. int weight;
  52. int overlap;
  53. int flags;
  54. unsigned int size;
  55. };
  56. static inline bool constraint_match(struct event_constraint *c, u64 ecode)
  57. {
  58. return ((ecode & c->cmask) - c->code) <= (u64)c->size;
  59. }
  60. #define PERF_ARCH(name, val) \
  61. PERF_X86_EVENT_##name = val,
  62. /*
  63. * struct hw_perf_event.flags flags
  64. */
  65. enum {
  66. #include "perf_event_flags.h"
  67. };
  68. #undef PERF_ARCH
  69. #define PERF_ARCH(name, val) \
  70. static_assert((PERF_X86_EVENT_##name & PERF_EVENT_FLAG_ARCH) == \
  71. PERF_X86_EVENT_##name);
  72. #include "perf_event_flags.h"
  73. #undef PERF_ARCH
  74. static inline bool is_topdown_count(struct perf_event *event)
  75. {
  76. return event->hw.flags & PERF_X86_EVENT_TOPDOWN;
  77. }
  78. static inline bool is_metric_event(struct perf_event *event)
  79. {
  80. u64 config = event->attr.config;
  81. return ((config & ARCH_PERFMON_EVENTSEL_EVENT) == 0) &&
  82. ((config & INTEL_ARCH_EVENT_MASK) >= INTEL_TD_METRIC_RETIRING) &&
  83. ((config & INTEL_ARCH_EVENT_MASK) <= INTEL_TD_METRIC_MAX);
  84. }
  85. static inline bool is_slots_event(struct perf_event *event)
  86. {
  87. return (event->attr.config & INTEL_ARCH_EVENT_MASK) == INTEL_TD_SLOTS;
  88. }
  89. static inline bool is_topdown_event(struct perf_event *event)
  90. {
  91. return is_metric_event(event) || is_slots_event(event);
  92. }
  93. static inline bool is_branch_counters_group(struct perf_event *event)
  94. {
  95. return event->group_leader->hw.flags & PERF_X86_EVENT_BRANCH_COUNTERS;
  96. }
  97. struct amd_nb {
  98. int nb_id; /* NorthBridge id */
  99. int refcnt; /* reference count */
  100. struct perf_event *owners[X86_PMC_IDX_MAX];
  101. struct event_constraint event_constraints[X86_PMC_IDX_MAX];
  102. };
  103. #define PEBS_COUNTER_MASK ((1ULL << MAX_PEBS_EVENTS) - 1)
  104. #define PEBS_PMI_AFTER_EACH_RECORD BIT_ULL(60)
  105. #define PEBS_OUTPUT_OFFSET 61
  106. #define PEBS_OUTPUT_MASK (3ull << PEBS_OUTPUT_OFFSET)
  107. #define PEBS_OUTPUT_PT (1ull << PEBS_OUTPUT_OFFSET)
  108. #define PEBS_VIA_PT_MASK (PEBS_OUTPUT_PT | PEBS_PMI_AFTER_EACH_RECORD)
  109. /*
  110. * Flags PEBS can handle without an PMI.
  111. *
  112. * TID can only be handled by flushing at context switch.
  113. * REGS_USER can be handled for events limited to ring 3.
  114. *
  115. */
  116. #define LARGE_PEBS_FLAGS \
  117. (PERF_SAMPLE_IP | PERF_SAMPLE_TID | PERF_SAMPLE_ADDR | \
  118. PERF_SAMPLE_ID | PERF_SAMPLE_CPU | PERF_SAMPLE_STREAM_ID | \
  119. PERF_SAMPLE_DATA_SRC | PERF_SAMPLE_IDENTIFIER | \
  120. PERF_SAMPLE_TRANSACTION | PERF_SAMPLE_PHYS_ADDR | \
  121. PERF_SAMPLE_REGS_INTR | PERF_SAMPLE_REGS_USER | \
  122. PERF_SAMPLE_PERIOD | PERF_SAMPLE_CODE_PAGE_SIZE | \
  123. PERF_SAMPLE_WEIGHT_TYPE)
  124. #define PEBS_GP_REGS \
  125. ((1ULL << PERF_REG_X86_AX) | \
  126. (1ULL << PERF_REG_X86_BX) | \
  127. (1ULL << PERF_REG_X86_CX) | \
  128. (1ULL << PERF_REG_X86_DX) | \
  129. (1ULL << PERF_REG_X86_DI) | \
  130. (1ULL << PERF_REG_X86_SI) | \
  131. (1ULL << PERF_REG_X86_SP) | \
  132. (1ULL << PERF_REG_X86_BP) | \
  133. (1ULL << PERF_REG_X86_IP) | \
  134. (1ULL << PERF_REG_X86_FLAGS) | \
  135. (1ULL << PERF_REG_X86_R8) | \
  136. (1ULL << PERF_REG_X86_R9) | \
  137. (1ULL << PERF_REG_X86_R10) | \
  138. (1ULL << PERF_REG_X86_R11) | \
  139. (1ULL << PERF_REG_X86_R12) | \
  140. (1ULL << PERF_REG_X86_R13) | \
  141. (1ULL << PERF_REG_X86_R14) | \
  142. (1ULL << PERF_REG_X86_R15))
  143. /*
  144. * Per register state.
  145. */
  146. struct er_account {
  147. raw_spinlock_t lock; /* per-core: protect structure */
  148. u64 config; /* extra MSR config */
  149. u64 reg; /* extra MSR number */
  150. atomic_t ref; /* reference count */
  151. };
  152. /*
  153. * Per core/cpu state
  154. *
  155. * Used to coordinate shared registers between HT threads or
  156. * among events on a single PMU.
  157. */
  158. struct intel_shared_regs {
  159. struct er_account regs[EXTRA_REG_MAX];
  160. int refcnt; /* per-core: #HT threads */
  161. unsigned core_id; /* per-core: core id */
  162. };
  163. enum intel_excl_state_type {
  164. INTEL_EXCL_UNUSED = 0, /* counter is unused */
  165. INTEL_EXCL_SHARED = 1, /* counter can be used by both threads */
  166. INTEL_EXCL_EXCLUSIVE = 2, /* counter can be used by one thread only */
  167. };
  168. struct intel_excl_states {
  169. enum intel_excl_state_type state[X86_PMC_IDX_MAX];
  170. bool sched_started; /* true if scheduling has started */
  171. };
  172. struct intel_excl_cntrs {
  173. raw_spinlock_t lock;
  174. struct intel_excl_states states[2];
  175. union {
  176. u16 has_exclusive[2];
  177. u32 exclusive_present;
  178. };
  179. int refcnt; /* per-core: #HT threads */
  180. unsigned core_id; /* per-core: core id */
  181. };
  182. struct x86_perf_task_context;
  183. #define MAX_LBR_ENTRIES 32
  184. enum {
  185. LBR_FORMAT_32 = 0x00,
  186. LBR_FORMAT_LIP = 0x01,
  187. LBR_FORMAT_EIP = 0x02,
  188. LBR_FORMAT_EIP_FLAGS = 0x03,
  189. LBR_FORMAT_EIP_FLAGS2 = 0x04,
  190. LBR_FORMAT_INFO = 0x05,
  191. LBR_FORMAT_TIME = 0x06,
  192. LBR_FORMAT_INFO2 = 0x07,
  193. LBR_FORMAT_MAX_KNOWN = LBR_FORMAT_INFO2,
  194. };
  195. enum {
  196. X86_PERF_KFREE_SHARED = 0,
  197. X86_PERF_KFREE_EXCL = 1,
  198. X86_PERF_KFREE_MAX
  199. };
  200. struct cpu_hw_events {
  201. /*
  202. * Generic x86 PMC bits
  203. */
  204. struct perf_event *events[X86_PMC_IDX_MAX]; /* in counter order */
  205. unsigned long active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  206. unsigned long dirty[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  207. int enabled;
  208. int n_events; /* the # of events in the below arrays */
  209. int n_added; /* the # last events in the below arrays;
  210. they've never been enabled yet */
  211. int n_txn; /* the # last events in the below arrays;
  212. added in the current transaction */
  213. int n_txn_pair;
  214. int n_txn_metric;
  215. int assign[X86_PMC_IDX_MAX]; /* event to counter assignment */
  216. u64 tags[X86_PMC_IDX_MAX];
  217. struct perf_event *event_list[X86_PMC_IDX_MAX]; /* in enabled order */
  218. struct event_constraint *event_constraint[X86_PMC_IDX_MAX];
  219. int n_excl; /* the number of exclusive events */
  220. unsigned int txn_flags;
  221. int is_fake;
  222. /*
  223. * Intel DebugStore bits
  224. */
  225. struct debug_store *ds;
  226. void *ds_pebs_vaddr;
  227. void *ds_bts_vaddr;
  228. u64 pebs_enabled;
  229. int n_pebs;
  230. int n_large_pebs;
  231. int n_pebs_via_pt;
  232. int pebs_output;
  233. /* Current super set of events hardware configuration */
  234. u64 pebs_data_cfg;
  235. u64 active_pebs_data_cfg;
  236. int pebs_record_size;
  237. /* Intel Fixed counter configuration */
  238. u64 fixed_ctrl_val;
  239. u64 active_fixed_ctrl_val;
  240. /*
  241. * Intel LBR bits
  242. */
  243. int lbr_users;
  244. int lbr_pebs_users;
  245. struct perf_branch_stack lbr_stack;
  246. struct perf_branch_entry lbr_entries[MAX_LBR_ENTRIES];
  247. u64 lbr_counters[MAX_LBR_ENTRIES]; /* branch stack extra */
  248. union {
  249. struct er_account *lbr_sel;
  250. struct er_account *lbr_ctl;
  251. };
  252. u64 br_sel;
  253. void *last_task_ctx;
  254. int last_log_id;
  255. int lbr_select;
  256. void *lbr_xsave;
  257. /*
  258. * Intel host/guest exclude bits
  259. */
  260. u64 intel_ctrl_guest_mask;
  261. u64 intel_ctrl_host_mask;
  262. struct perf_guest_switch_msr guest_switch_msrs[X86_PMC_IDX_MAX];
  263. /*
  264. * Intel checkpoint mask
  265. */
  266. u64 intel_cp_status;
  267. /*
  268. * manage shared (per-core, per-cpu) registers
  269. * used on Intel NHM/WSM/SNB
  270. */
  271. struct intel_shared_regs *shared_regs;
  272. /*
  273. * manage exclusive counter access between hyperthread
  274. */
  275. struct event_constraint *constraint_list; /* in enable order */
  276. struct intel_excl_cntrs *excl_cntrs;
  277. int excl_thread_id; /* 0 or 1 */
  278. /*
  279. * SKL TSX_FORCE_ABORT shadow
  280. */
  281. u64 tfa_shadow;
  282. /*
  283. * Perf Metrics
  284. */
  285. /* number of accepted metrics events */
  286. int n_metric;
  287. /*
  288. * AMD specific bits
  289. */
  290. struct amd_nb *amd_nb;
  291. int brs_active; /* BRS is enabled */
  292. /* Inverted mask of bits to clear in the perf_ctr ctrl registers */
  293. u64 perf_ctr_virt_mask;
  294. int n_pair; /* Large increment events */
  295. void *kfree_on_online[X86_PERF_KFREE_MAX];
  296. struct pmu *pmu;
  297. };
  298. #define __EVENT_CONSTRAINT_RANGE(c, e, n, m, w, o, f) { \
  299. { .idxmsk64 = (n) }, \
  300. .code = (c), \
  301. .size = (e) - (c), \
  302. .cmask = (m), \
  303. .weight = (w), \
  304. .overlap = (o), \
  305. .flags = f, \
  306. }
  307. #define __EVENT_CONSTRAINT(c, n, m, w, o, f) \
  308. __EVENT_CONSTRAINT_RANGE(c, c, n, m, w, o, f)
  309. #define EVENT_CONSTRAINT(c, n, m) \
  310. __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 0, 0)
  311. /*
  312. * The constraint_match() function only works for 'simple' event codes
  313. * and not for extended (AMD64_EVENTSEL_EVENT) events codes.
  314. */
  315. #define EVENT_CONSTRAINT_RANGE(c, e, n, m) \
  316. __EVENT_CONSTRAINT_RANGE(c, e, n, m, HWEIGHT(n), 0, 0)
  317. #define INTEL_EXCLEVT_CONSTRAINT(c, n) \
  318. __EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT, HWEIGHT(n),\
  319. 0, PERF_X86_EVENT_EXCL)
  320. /*
  321. * The overlap flag marks event constraints with overlapping counter
  322. * masks. This is the case if the counter mask of such an event is not
  323. * a subset of any other counter mask of a constraint with an equal or
  324. * higher weight, e.g.:
  325. *
  326. * c_overlaps = EVENT_CONSTRAINT_OVERLAP(0, 0x09, 0);
  327. * c_another1 = EVENT_CONSTRAINT(0, 0x07, 0);
  328. * c_another2 = EVENT_CONSTRAINT(0, 0x38, 0);
  329. *
  330. * The event scheduler may not select the correct counter in the first
  331. * cycle because it needs to know which subsequent events will be
  332. * scheduled. It may fail to schedule the events then. So we set the
  333. * overlap flag for such constraints to give the scheduler a hint which
  334. * events to select for counter rescheduling.
  335. *
  336. * Care must be taken as the rescheduling algorithm is O(n!) which
  337. * will increase scheduling cycles for an over-committed system
  338. * dramatically. The number of such EVENT_CONSTRAINT_OVERLAP() macros
  339. * and its counter masks must be kept at a minimum.
  340. */
  341. #define EVENT_CONSTRAINT_OVERLAP(c, n, m) \
  342. __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n), 1, 0)
  343. /*
  344. * Constraint on the Event code.
  345. */
  346. #define INTEL_EVENT_CONSTRAINT(c, n) \
  347. EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT)
  348. /*
  349. * Constraint on a range of Event codes
  350. */
  351. #define INTEL_EVENT_CONSTRAINT_RANGE(c, e, n) \
  352. EVENT_CONSTRAINT_RANGE(c, e, n, ARCH_PERFMON_EVENTSEL_EVENT)
  353. /*
  354. * Constraint on the Event code + UMask + fixed-mask
  355. *
  356. * filter mask to validate fixed counter events.
  357. * the following filters disqualify for fixed counters:
  358. * - inv
  359. * - edge
  360. * - cnt-mask
  361. * - in_tx
  362. * - in_tx_checkpointed
  363. * The other filters are supported by fixed counters.
  364. * The any-thread option is supported starting with v3.
  365. */
  366. #define FIXED_EVENT_FLAGS (X86_RAW_EVENT_MASK|HSW_IN_TX|HSW_IN_TX_CHECKPOINTED)
  367. #define FIXED_EVENT_CONSTRAINT(c, n) \
  368. EVENT_CONSTRAINT(c, (1ULL << (32+n)), FIXED_EVENT_FLAGS)
  369. /*
  370. * The special metric counters do not actually exist. They are calculated from
  371. * the combination of the FxCtr3 + MSR_PERF_METRICS.
  372. *
  373. * The special metric counters are mapped to a dummy offset for the scheduler.
  374. * The sharing between multiple users of the same metric without multiplexing
  375. * is not allowed, even though the hardware supports that in principle.
  376. */
  377. #define METRIC_EVENT_CONSTRAINT(c, n) \
  378. EVENT_CONSTRAINT(c, (1ULL << (INTEL_PMC_IDX_METRIC_BASE + n)), \
  379. INTEL_ARCH_EVENT_MASK)
  380. /*
  381. * Constraint on the Event code + UMask
  382. */
  383. #define INTEL_UEVENT_CONSTRAINT(c, n) \
  384. EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK)
  385. /* Constraint on specific umask bit only + event */
  386. #define INTEL_UBIT_EVENT_CONSTRAINT(c, n) \
  387. EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT|(c))
  388. /* Like UEVENT_CONSTRAINT, but match flags too */
  389. #define INTEL_FLAGS_UEVENT_CONSTRAINT(c, n) \
  390. EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS)
  391. #define INTEL_EXCLUEVT_CONSTRAINT(c, n) \
  392. __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK, \
  393. HWEIGHT(n), 0, PERF_X86_EVENT_EXCL)
  394. #define INTEL_PLD_CONSTRAINT(c, n) \
  395. __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  396. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LDLAT)
  397. #define INTEL_PSD_CONSTRAINT(c, n) \
  398. __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  399. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_STLAT)
  400. #define INTEL_PST_CONSTRAINT(c, n) \
  401. __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  402. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST)
  403. #define INTEL_HYBRID_LAT_CONSTRAINT(c, n) \
  404. __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  405. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LAT_HYBRID)
  406. #define INTEL_HYBRID_LDLAT_CONSTRAINT(c, n) \
  407. __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  408. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LAT_HYBRID|PERF_X86_EVENT_PEBS_LD_HSW)
  409. #define INTEL_HYBRID_STLAT_CONSTRAINT(c, n) \
  410. __EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  411. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LAT_HYBRID|PERF_X86_EVENT_PEBS_ST_HSW)
  412. /* Event constraint, but match on all event flags too. */
  413. #define INTEL_FLAGS_EVENT_CONSTRAINT(c, n) \
  414. EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
  415. #define INTEL_FLAGS_EVENT_CONSTRAINT_RANGE(c, e, n) \
  416. EVENT_CONSTRAINT_RANGE(c, e, n, ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS)
  417. /* Check only flags, but allow all event/umask */
  418. #define INTEL_ALL_EVENT_CONSTRAINT(code, n) \
  419. EVENT_CONSTRAINT(code, n, X86_ALL_EVENT_FLAGS)
  420. /* Check flags and event code, and set the HSW store flag */
  421. #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_ST(code, n) \
  422. __EVENT_CONSTRAINT(code, n, \
  423. ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \
  424. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST_HSW)
  425. /* Check flags and event code, and set the HSW load flag */
  426. #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_LD(code, n) \
  427. __EVENT_CONSTRAINT(code, n, \
  428. ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \
  429. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LD_HSW)
  430. #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_LD_RANGE(code, end, n) \
  431. __EVENT_CONSTRAINT_RANGE(code, end, n, \
  432. ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \
  433. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LD_HSW)
  434. #define INTEL_FLAGS_EVENT_CONSTRAINT_DATALA_XLD(code, n) \
  435. __EVENT_CONSTRAINT(code, n, \
  436. ARCH_PERFMON_EVENTSEL_EVENT|X86_ALL_EVENT_FLAGS, \
  437. HWEIGHT(n), 0, \
  438. PERF_X86_EVENT_PEBS_LD_HSW|PERF_X86_EVENT_EXCL)
  439. /* Check flags and event code/umask, and set the HSW store flag */
  440. #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_ST(code, n) \
  441. __EVENT_CONSTRAINT(code, n, \
  442. INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  443. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_ST_HSW)
  444. #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XST(code, n) \
  445. __EVENT_CONSTRAINT(code, n, \
  446. INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  447. HWEIGHT(n), 0, \
  448. PERF_X86_EVENT_PEBS_ST_HSW|PERF_X86_EVENT_EXCL)
  449. /* Check flags and event code/umask, and set the HSW load flag */
  450. #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_LD(code, n) \
  451. __EVENT_CONSTRAINT(code, n, \
  452. INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  453. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_LD_HSW)
  454. #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_XLD(code, n) \
  455. __EVENT_CONSTRAINT(code, n, \
  456. INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  457. HWEIGHT(n), 0, \
  458. PERF_X86_EVENT_PEBS_LD_HSW|PERF_X86_EVENT_EXCL)
  459. /* Check flags and event code/umask, and set the HSW N/A flag */
  460. #define INTEL_FLAGS_UEVENT_CONSTRAINT_DATALA_NA(code, n) \
  461. __EVENT_CONSTRAINT(code, n, \
  462. INTEL_ARCH_EVENT_MASK|X86_ALL_EVENT_FLAGS, \
  463. HWEIGHT(n), 0, PERF_X86_EVENT_PEBS_NA_HSW)
  464. /*
  465. * We define the end marker as having a weight of -1
  466. * to enable blacklisting of events using a counter bitmask
  467. * of zero and thus a weight of zero.
  468. * The end marker has a weight that cannot possibly be
  469. * obtained from counting the bits in the bitmask.
  470. */
  471. #define EVENT_CONSTRAINT_END { .weight = -1 }
  472. /*
  473. * Check for end marker with weight == -1
  474. */
  475. #define for_each_event_constraint(e, c) \
  476. for ((e) = (c); (e)->weight != -1; (e)++)
  477. /*
  478. * Extra registers for specific events.
  479. *
  480. * Some events need large masks and require external MSRs.
  481. * Those extra MSRs end up being shared for all events on
  482. * a PMU and sometimes between PMU of sibling HT threads.
  483. * In either case, the kernel needs to handle conflicting
  484. * accesses to those extra, shared, regs. The data structure
  485. * to manage those registers is stored in cpu_hw_event.
  486. */
  487. struct extra_reg {
  488. unsigned int event;
  489. unsigned int msr;
  490. u64 config_mask;
  491. u64 valid_mask;
  492. int idx; /* per_xxx->regs[] reg index */
  493. bool extra_msr_access;
  494. };
  495. #define EVENT_EXTRA_REG(e, ms, m, vm, i) { \
  496. .event = (e), \
  497. .msr = (ms), \
  498. .config_mask = (m), \
  499. .valid_mask = (vm), \
  500. .idx = EXTRA_REG_##i, \
  501. .extra_msr_access = true, \
  502. }
  503. #define INTEL_EVENT_EXTRA_REG(event, msr, vm, idx) \
  504. EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT, vm, idx)
  505. #define INTEL_UEVENT_EXTRA_REG(event, msr, vm, idx) \
  506. EVENT_EXTRA_REG(event, msr, ARCH_PERFMON_EVENTSEL_EVENT | \
  507. ARCH_PERFMON_EVENTSEL_UMASK, vm, idx)
  508. #define INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(c) \
  509. INTEL_UEVENT_EXTRA_REG(c, \
  510. MSR_PEBS_LD_LAT_THRESHOLD, \
  511. 0xffff, \
  512. LDLAT)
  513. #define EVENT_EXTRA_END EVENT_EXTRA_REG(0, 0, 0, 0, RSP_0)
  514. union perf_capabilities {
  515. struct {
  516. u64 lbr_format:6;
  517. u64 pebs_trap:1;
  518. u64 pebs_arch_reg:1;
  519. u64 pebs_format:4;
  520. u64 smm_freeze:1;
  521. /*
  522. * PMU supports separate counter range for writing
  523. * values > 32bit.
  524. */
  525. u64 full_width_write:1;
  526. u64 pebs_baseline:1;
  527. u64 perf_metrics:1;
  528. u64 pebs_output_pt_available:1;
  529. u64 pebs_timing_info:1;
  530. u64 anythread_deprecated:1;
  531. };
  532. u64 capabilities;
  533. };
  534. struct x86_pmu_quirk {
  535. struct x86_pmu_quirk *next;
  536. void (*func)(void);
  537. };
  538. union x86_pmu_config {
  539. struct {
  540. u64 event:8,
  541. umask:8,
  542. usr:1,
  543. os:1,
  544. edge:1,
  545. pc:1,
  546. interrupt:1,
  547. __reserved1:1,
  548. en:1,
  549. inv:1,
  550. cmask:8,
  551. event2:4,
  552. __reserved2:4,
  553. go:1,
  554. ho:1;
  555. } bits;
  556. u64 value;
  557. };
  558. #define X86_CONFIG(args...) ((union x86_pmu_config){.bits = {args}}).value
  559. enum {
  560. x86_lbr_exclusive_lbr,
  561. x86_lbr_exclusive_bts,
  562. x86_lbr_exclusive_pt,
  563. x86_lbr_exclusive_max,
  564. };
  565. #define PERF_PEBS_DATA_SOURCE_MAX 0x100
  566. #define PERF_PEBS_DATA_SOURCE_MASK (PERF_PEBS_DATA_SOURCE_MAX - 1)
  567. #define PERF_PEBS_DATA_SOURCE_GRT_MAX 0x10
  568. #define PERF_PEBS_DATA_SOURCE_GRT_MASK (PERF_PEBS_DATA_SOURCE_GRT_MAX - 1)
  569. enum hybrid_cpu_type {
  570. HYBRID_INTEL_NONE,
  571. HYBRID_INTEL_ATOM = 0x20,
  572. HYBRID_INTEL_CORE = 0x40,
  573. };
  574. enum hybrid_pmu_type {
  575. not_hybrid,
  576. hybrid_small = BIT(0),
  577. hybrid_big = BIT(1),
  578. hybrid_big_small = hybrid_big | hybrid_small, /* only used for matching */
  579. };
  580. #define X86_HYBRID_PMU_ATOM_IDX 0
  581. #define X86_HYBRID_PMU_CORE_IDX 1
  582. #define X86_HYBRID_NUM_PMUS 2
  583. struct x86_hybrid_pmu {
  584. struct pmu pmu;
  585. const char *name;
  586. enum hybrid_pmu_type pmu_type;
  587. cpumask_t supported_cpus;
  588. union perf_capabilities intel_cap;
  589. u64 intel_ctrl;
  590. u64 pebs_events_mask;
  591. u64 config_mask;
  592. union {
  593. u64 cntr_mask64;
  594. unsigned long cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  595. };
  596. union {
  597. u64 fixed_cntr_mask64;
  598. unsigned long fixed_cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  599. };
  600. struct event_constraint unconstrained;
  601. u64 hw_cache_event_ids
  602. [PERF_COUNT_HW_CACHE_MAX]
  603. [PERF_COUNT_HW_CACHE_OP_MAX]
  604. [PERF_COUNT_HW_CACHE_RESULT_MAX];
  605. u64 hw_cache_extra_regs
  606. [PERF_COUNT_HW_CACHE_MAX]
  607. [PERF_COUNT_HW_CACHE_OP_MAX]
  608. [PERF_COUNT_HW_CACHE_RESULT_MAX];
  609. struct event_constraint *event_constraints;
  610. struct event_constraint *pebs_constraints;
  611. struct extra_reg *extra_regs;
  612. unsigned int late_ack :1,
  613. mid_ack :1,
  614. enabled_ack :1;
  615. u64 pebs_data_source[PERF_PEBS_DATA_SOURCE_MAX];
  616. };
  617. static __always_inline struct x86_hybrid_pmu *hybrid_pmu(struct pmu *pmu)
  618. {
  619. return container_of(pmu, struct x86_hybrid_pmu, pmu);
  620. }
  621. extern struct static_key_false perf_is_hybrid;
  622. #define is_hybrid() static_branch_unlikely(&perf_is_hybrid)
  623. #define hybrid(_pmu, _field) \
  624. (*({ \
  625. typeof(&x86_pmu._field) __Fp = &x86_pmu._field; \
  626. \
  627. if (is_hybrid() && (_pmu)) \
  628. __Fp = &hybrid_pmu(_pmu)->_field; \
  629. \
  630. __Fp; \
  631. }))
  632. #define hybrid_var(_pmu, _var) \
  633. (*({ \
  634. typeof(&_var) __Fp = &_var; \
  635. \
  636. if (is_hybrid() && (_pmu)) \
  637. __Fp = &hybrid_pmu(_pmu)->_var; \
  638. \
  639. __Fp; \
  640. }))
  641. #define hybrid_bit(_pmu, _field) \
  642. ({ \
  643. bool __Fp = x86_pmu._field; \
  644. \
  645. if (is_hybrid() && (_pmu)) \
  646. __Fp = hybrid_pmu(_pmu)->_field; \
  647. \
  648. __Fp; \
  649. })
  650. /*
  651. * struct x86_pmu - generic x86 pmu
  652. */
  653. struct x86_pmu {
  654. /*
  655. * Generic x86 PMC bits
  656. */
  657. const char *name;
  658. int version;
  659. int (*handle_irq)(struct pt_regs *);
  660. void (*disable_all)(void);
  661. void (*enable_all)(int added);
  662. void (*enable)(struct perf_event *);
  663. void (*disable)(struct perf_event *);
  664. void (*assign)(struct perf_event *event, int idx);
  665. void (*add)(struct perf_event *);
  666. void (*del)(struct perf_event *);
  667. void (*read)(struct perf_event *event);
  668. int (*set_period)(struct perf_event *event);
  669. u64 (*update)(struct perf_event *event);
  670. int (*hw_config)(struct perf_event *event);
  671. int (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign);
  672. unsigned eventsel;
  673. unsigned perfctr;
  674. unsigned fixedctr;
  675. int (*addr_offset)(int index, bool eventsel);
  676. int (*rdpmc_index)(int index);
  677. u64 (*event_map)(int);
  678. int max_events;
  679. u64 config_mask;
  680. union {
  681. u64 cntr_mask64;
  682. unsigned long cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  683. };
  684. union {
  685. u64 fixed_cntr_mask64;
  686. unsigned long fixed_cntr_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
  687. };
  688. int cntval_bits;
  689. u64 cntval_mask;
  690. union {
  691. unsigned long events_maskl;
  692. unsigned long events_mask[BITS_TO_LONGS(ARCH_PERFMON_EVENTS_COUNT)];
  693. };
  694. int events_mask_len;
  695. int apic;
  696. u64 max_period;
  697. struct event_constraint *
  698. (*get_event_constraints)(struct cpu_hw_events *cpuc,
  699. int idx,
  700. struct perf_event *event);
  701. void (*put_event_constraints)(struct cpu_hw_events *cpuc,
  702. struct perf_event *event);
  703. void (*start_scheduling)(struct cpu_hw_events *cpuc);
  704. void (*commit_scheduling)(struct cpu_hw_events *cpuc, int idx, int cntr);
  705. void (*stop_scheduling)(struct cpu_hw_events *cpuc);
  706. struct event_constraint *event_constraints;
  707. struct x86_pmu_quirk *quirks;
  708. void (*limit_period)(struct perf_event *event, s64 *l);
  709. /* PMI handler bits */
  710. unsigned int late_ack :1,
  711. mid_ack :1,
  712. enabled_ack :1;
  713. /*
  714. * sysfs attrs
  715. */
  716. int attr_rdpmc_broken;
  717. int attr_rdpmc;
  718. struct attribute **format_attrs;
  719. ssize_t (*events_sysfs_show)(char *page, u64 config);
  720. const struct attribute_group **attr_update;
  721. unsigned long attr_freeze_on_smi;
  722. /*
  723. * CPU Hotplug hooks
  724. */
  725. int (*cpu_prepare)(int cpu);
  726. void (*cpu_starting)(int cpu);
  727. void (*cpu_dying)(int cpu);
  728. void (*cpu_dead)(int cpu);
  729. void (*check_microcode)(void);
  730. void (*sched_task)(struct perf_event_pmu_context *pmu_ctx,
  731. bool sched_in);
  732. /*
  733. * Intel Arch Perfmon v2+
  734. */
  735. u64 intel_ctrl;
  736. union perf_capabilities intel_cap;
  737. /*
  738. * Intel DebugStore bits
  739. */
  740. unsigned int bts :1,
  741. bts_active :1,
  742. pebs :1,
  743. pebs_active :1,
  744. pebs_broken :1,
  745. pebs_prec_dist :1,
  746. pebs_no_tlb :1,
  747. pebs_no_isolation :1,
  748. pebs_block :1,
  749. pebs_ept :1;
  750. int pebs_record_size;
  751. int pebs_buffer_size;
  752. u64 pebs_events_mask;
  753. void (*drain_pebs)(struct pt_regs *regs, struct perf_sample_data *data);
  754. struct event_constraint *pebs_constraints;
  755. void (*pebs_aliases)(struct perf_event *event);
  756. u64 (*pebs_latency_data)(struct perf_event *event, u64 status);
  757. unsigned long large_pebs_flags;
  758. u64 rtm_abort_event;
  759. u64 pebs_capable;
  760. /*
  761. * Intel LBR
  762. */
  763. unsigned int lbr_tos, lbr_from, lbr_to,
  764. lbr_info, lbr_nr; /* LBR base regs and size */
  765. union {
  766. u64 lbr_sel_mask; /* LBR_SELECT valid bits */
  767. u64 lbr_ctl_mask; /* LBR_CTL valid bits */
  768. };
  769. union {
  770. const int *lbr_sel_map; /* lbr_select mappings */
  771. int *lbr_ctl_map; /* LBR_CTL mappings */
  772. };
  773. bool lbr_double_abort; /* duplicated lbr aborts */
  774. bool lbr_pt_coexist; /* (LBR|BTS) may coexist with PT */
  775. unsigned int lbr_has_info:1;
  776. unsigned int lbr_has_tsx:1;
  777. unsigned int lbr_from_flags:1;
  778. unsigned int lbr_to_cycles:1;
  779. /*
  780. * Intel Architectural LBR CPUID Enumeration
  781. */
  782. unsigned int lbr_depth_mask:8;
  783. unsigned int lbr_deep_c_reset:1;
  784. unsigned int lbr_lip:1;
  785. unsigned int lbr_cpl:1;
  786. unsigned int lbr_filter:1;
  787. unsigned int lbr_call_stack:1;
  788. unsigned int lbr_mispred:1;
  789. unsigned int lbr_timed_lbr:1;
  790. unsigned int lbr_br_type:1;
  791. unsigned int lbr_counters:4;
  792. void (*lbr_reset)(void);
  793. void (*lbr_read)(struct cpu_hw_events *cpuc);
  794. void (*lbr_save)(void *ctx);
  795. void (*lbr_restore)(void *ctx);
  796. /*
  797. * Intel PT/LBR/BTS are exclusive
  798. */
  799. atomic_t lbr_exclusive[x86_lbr_exclusive_max];
  800. /*
  801. * Intel perf metrics
  802. */
  803. int num_topdown_events;
  804. /*
  805. * perf task context (i.e. struct perf_event_pmu_context::task_ctx_data)
  806. * switch helper to bridge calls from perf/core to perf/x86.
  807. * See struct pmu::swap_task_ctx() usage for examples;
  808. */
  809. void (*swap_task_ctx)(struct perf_event_pmu_context *prev_epc,
  810. struct perf_event_pmu_context *next_epc);
  811. /*
  812. * AMD bits
  813. */
  814. unsigned int amd_nb_constraints : 1;
  815. u64 perf_ctr_pair_en;
  816. /*
  817. * Extra registers for events
  818. */
  819. struct extra_reg *extra_regs;
  820. unsigned int flags;
  821. /*
  822. * Intel host/guest support (KVM)
  823. */
  824. struct perf_guest_switch_msr *(*guest_get_msrs)(int *nr, void *data);
  825. /*
  826. * Check period value for PERF_EVENT_IOC_PERIOD ioctl.
  827. */
  828. int (*check_period) (struct perf_event *event, u64 period);
  829. int (*aux_output_match) (struct perf_event *event);
  830. void (*filter)(struct pmu *pmu, int cpu, bool *ret);
  831. /*
  832. * Hybrid support
  833. *
  834. * Most PMU capabilities are the same among different hybrid PMUs.
  835. * The global x86_pmu saves the architecture capabilities, which
  836. * are available for all PMUs. The hybrid_pmu only includes the
  837. * unique capabilities.
  838. */
  839. int num_hybrid_pmus;
  840. struct x86_hybrid_pmu *hybrid_pmu;
  841. enum hybrid_cpu_type (*get_hybrid_cpu_type) (void);
  842. };
  843. struct x86_perf_task_context_opt {
  844. int lbr_callstack_users;
  845. int lbr_stack_state;
  846. int log_id;
  847. };
  848. struct x86_perf_task_context {
  849. u64 lbr_sel;
  850. int tos;
  851. int valid_lbrs;
  852. struct x86_perf_task_context_opt opt;
  853. struct lbr_entry lbr[MAX_LBR_ENTRIES];
  854. };
  855. struct x86_perf_task_context_arch_lbr {
  856. struct x86_perf_task_context_opt opt;
  857. struct lbr_entry entries[];
  858. };
  859. /*
  860. * Add padding to guarantee the 64-byte alignment of the state buffer.
  861. *
  862. * The structure is dynamically allocated. The size of the LBR state may vary
  863. * based on the number of LBR registers.
  864. *
  865. * Do not put anything after the LBR state.
  866. */
  867. struct x86_perf_task_context_arch_lbr_xsave {
  868. struct x86_perf_task_context_opt opt;
  869. union {
  870. struct xregs_state xsave;
  871. struct {
  872. struct fxregs_state i387;
  873. struct xstate_header header;
  874. struct arch_lbr_state lbr;
  875. } __attribute__ ((packed, aligned (XSAVE_ALIGNMENT)));
  876. };
  877. };
  878. #define x86_add_quirk(func_) \
  879. do { \
  880. static struct x86_pmu_quirk __quirk __initdata = { \
  881. .func = func_, \
  882. }; \
  883. __quirk.next = x86_pmu.quirks; \
  884. x86_pmu.quirks = &__quirk; \
  885. } while (0)
  886. /*
  887. * x86_pmu flags
  888. */
  889. #define PMU_FL_NO_HT_SHARING 0x1 /* no hyper-threading resource sharing */
  890. #define PMU_FL_HAS_RSP_1 0x2 /* has 2 equivalent offcore_rsp regs */
  891. #define PMU_FL_EXCL_CNTRS 0x4 /* has exclusive counter requirements */
  892. #define PMU_FL_EXCL_ENABLED 0x8 /* exclusive counter active */
  893. #define PMU_FL_PEBS_ALL 0x10 /* all events are valid PEBS events */
  894. #define PMU_FL_TFA 0x20 /* deal with TSX force abort */
  895. #define PMU_FL_PAIR 0x40 /* merge counters for large incr. events */
  896. #define PMU_FL_INSTR_LATENCY 0x80 /* Support Instruction Latency in PEBS Memory Info Record */
  897. #define PMU_FL_MEM_LOADS_AUX 0x100 /* Require an auxiliary event for the complete memory info */
  898. #define PMU_FL_RETIRE_LATENCY 0x200 /* Support Retire Latency in PEBS */
  899. #define PMU_FL_BR_CNTR 0x400 /* Support branch counter logging */
  900. #define EVENT_VAR(_id) event_attr_##_id
  901. #define EVENT_PTR(_id) &event_attr_##_id.attr.attr
  902. #define EVENT_ATTR(_name, _id) \
  903. static struct perf_pmu_events_attr EVENT_VAR(_id) = { \
  904. .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \
  905. .id = PERF_COUNT_HW_##_id, \
  906. .event_str = NULL, \
  907. };
  908. #define EVENT_ATTR_STR(_name, v, str) \
  909. static struct perf_pmu_events_attr event_attr_##v = { \
  910. .attr = __ATTR(_name, 0444, events_sysfs_show, NULL), \
  911. .id = 0, \
  912. .event_str = str, \
  913. };
  914. #define EVENT_ATTR_STR_HT(_name, v, noht, ht) \
  915. static struct perf_pmu_events_ht_attr event_attr_##v = { \
  916. .attr = __ATTR(_name, 0444, events_ht_sysfs_show, NULL),\
  917. .id = 0, \
  918. .event_str_noht = noht, \
  919. .event_str_ht = ht, \
  920. }
  921. #define EVENT_ATTR_STR_HYBRID(_name, v, str, _pmu) \
  922. static struct perf_pmu_events_hybrid_attr event_attr_##v = { \
  923. .attr = __ATTR(_name, 0444, events_hybrid_sysfs_show, NULL),\
  924. .id = 0, \
  925. .event_str = str, \
  926. .pmu_type = _pmu, \
  927. }
  928. #define FORMAT_HYBRID_PTR(_id) (&format_attr_hybrid_##_id.attr.attr)
  929. #define FORMAT_ATTR_HYBRID(_name, _pmu) \
  930. static struct perf_pmu_format_hybrid_attr format_attr_hybrid_##_name = {\
  931. .attr = __ATTR_RO(_name), \
  932. .pmu_type = _pmu, \
  933. }
  934. struct pmu *x86_get_pmu(unsigned int cpu);
  935. extern struct x86_pmu x86_pmu __read_mostly;
  936. DECLARE_STATIC_CALL(x86_pmu_set_period, *x86_pmu.set_period);
  937. DECLARE_STATIC_CALL(x86_pmu_update, *x86_pmu.update);
  938. static __always_inline struct x86_perf_task_context_opt *task_context_opt(void *ctx)
  939. {
  940. if (static_cpu_has(X86_FEATURE_ARCH_LBR))
  941. return &((struct x86_perf_task_context_arch_lbr *)ctx)->opt;
  942. return &((struct x86_perf_task_context *)ctx)->opt;
  943. }
  944. static inline bool x86_pmu_has_lbr_callstack(void)
  945. {
  946. return x86_pmu.lbr_sel_map &&
  947. x86_pmu.lbr_sel_map[PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT] > 0;
  948. }
  949. DECLARE_PER_CPU(struct cpu_hw_events, cpu_hw_events);
  950. DECLARE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left);
  951. int x86_perf_event_set_period(struct perf_event *event);
  952. /*
  953. * Generalized hw caching related hw_event table, filled
  954. * in on a per model basis. A value of 0 means
  955. * 'not supported', -1 means 'hw_event makes no sense on
  956. * this CPU', any other value means the raw hw_event
  957. * ID.
  958. */
  959. #define C(x) PERF_COUNT_HW_CACHE_##x
  960. extern u64 __read_mostly hw_cache_event_ids
  961. [PERF_COUNT_HW_CACHE_MAX]
  962. [PERF_COUNT_HW_CACHE_OP_MAX]
  963. [PERF_COUNT_HW_CACHE_RESULT_MAX];
  964. extern u64 __read_mostly hw_cache_extra_regs
  965. [PERF_COUNT_HW_CACHE_MAX]
  966. [PERF_COUNT_HW_CACHE_OP_MAX]
  967. [PERF_COUNT_HW_CACHE_RESULT_MAX];
  968. u64 x86_perf_event_update(struct perf_event *event);
  969. static inline unsigned int x86_pmu_config_addr(int index)
  970. {
  971. return x86_pmu.eventsel + (x86_pmu.addr_offset ?
  972. x86_pmu.addr_offset(index, true) : index);
  973. }
  974. static inline unsigned int x86_pmu_event_addr(int index)
  975. {
  976. return x86_pmu.perfctr + (x86_pmu.addr_offset ?
  977. x86_pmu.addr_offset(index, false) : index);
  978. }
  979. static inline unsigned int x86_pmu_fixed_ctr_addr(int index)
  980. {
  981. return x86_pmu.fixedctr + (x86_pmu.addr_offset ?
  982. x86_pmu.addr_offset(index, false) : index);
  983. }
  984. static inline int x86_pmu_rdpmc_index(int index)
  985. {
  986. return x86_pmu.rdpmc_index ? x86_pmu.rdpmc_index(index) : index;
  987. }
  988. bool check_hw_exists(struct pmu *pmu, unsigned long *cntr_mask,
  989. unsigned long *fixed_cntr_mask);
  990. int x86_add_exclusive(unsigned int what);
  991. void x86_del_exclusive(unsigned int what);
  992. int x86_reserve_hardware(void);
  993. void x86_release_hardware(void);
  994. int x86_pmu_max_precise(void);
  995. void hw_perf_lbr_event_destroy(struct perf_event *event);
  996. int x86_setup_perfctr(struct perf_event *event);
  997. int x86_pmu_hw_config(struct perf_event *event);
  998. void x86_pmu_disable_all(void);
  999. static inline bool has_amd_brs(struct hw_perf_event *hwc)
  1000. {
  1001. return hwc->flags & PERF_X86_EVENT_AMD_BRS;
  1002. }
  1003. static inline bool is_counter_pair(struct hw_perf_event *hwc)
  1004. {
  1005. return hwc->flags & PERF_X86_EVENT_PAIR;
  1006. }
  1007. static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc,
  1008. u64 enable_mask)
  1009. {
  1010. u64 disable_mask = __this_cpu_read(cpu_hw_events.perf_ctr_virt_mask);
  1011. if (hwc->extra_reg.reg)
  1012. wrmsrl(hwc->extra_reg.reg, hwc->extra_reg.config);
  1013. /*
  1014. * Add enabled Merge event on next counter
  1015. * if large increment event being enabled on this counter
  1016. */
  1017. if (is_counter_pair(hwc))
  1018. wrmsrl(x86_pmu_config_addr(hwc->idx + 1), x86_pmu.perf_ctr_pair_en);
  1019. wrmsrl(hwc->config_base, (hwc->config | enable_mask) & ~disable_mask);
  1020. }
  1021. void x86_pmu_enable_all(int added);
  1022. int perf_assign_events(struct event_constraint **constraints, int n,
  1023. int wmin, int wmax, int gpmax, int *assign);
  1024. int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign);
  1025. void x86_pmu_stop(struct perf_event *event, int flags);
  1026. static inline void x86_pmu_disable_event(struct perf_event *event)
  1027. {
  1028. u64 disable_mask = __this_cpu_read(cpu_hw_events.perf_ctr_virt_mask);
  1029. struct hw_perf_event *hwc = &event->hw;
  1030. wrmsrl(hwc->config_base, hwc->config & ~disable_mask);
  1031. if (is_counter_pair(hwc))
  1032. wrmsrl(x86_pmu_config_addr(hwc->idx + 1), 0);
  1033. }
  1034. void x86_pmu_enable_event(struct perf_event *event);
  1035. int x86_pmu_handle_irq(struct pt_regs *regs);
  1036. void x86_pmu_show_pmu_cap(struct pmu *pmu);
  1037. static inline int x86_pmu_num_counters(struct pmu *pmu)
  1038. {
  1039. return hweight64(hybrid(pmu, cntr_mask64));
  1040. }
  1041. static inline int x86_pmu_max_num_counters(struct pmu *pmu)
  1042. {
  1043. return fls64(hybrid(pmu, cntr_mask64));
  1044. }
  1045. static inline int x86_pmu_num_counters_fixed(struct pmu *pmu)
  1046. {
  1047. return hweight64(hybrid(pmu, fixed_cntr_mask64));
  1048. }
  1049. static inline int x86_pmu_max_num_counters_fixed(struct pmu *pmu)
  1050. {
  1051. return fls64(hybrid(pmu, fixed_cntr_mask64));
  1052. }
  1053. static inline u64 x86_pmu_get_event_config(struct perf_event *event)
  1054. {
  1055. return event->attr.config & hybrid(event->pmu, config_mask);
  1056. }
  1057. extern struct event_constraint emptyconstraint;
  1058. extern struct event_constraint unconstrained;
  1059. static inline bool kernel_ip(unsigned long ip)
  1060. {
  1061. #ifdef CONFIG_X86_32
  1062. return ip > PAGE_OFFSET;
  1063. #else
  1064. return (long)ip < 0;
  1065. #endif
  1066. }
  1067. /*
  1068. * Not all PMUs provide the right context information to place the reported IP
  1069. * into full context. Specifically segment registers are typically not
  1070. * supplied.
  1071. *
  1072. * Assuming the address is a linear address (it is for IBS), we fake the CS and
  1073. * vm86 mode using the known zero-based code segment and 'fix up' the registers
  1074. * to reflect this.
  1075. *
  1076. * Intel PEBS/LBR appear to typically provide the effective address, nothing
  1077. * much we can do about that but pray and treat it like a linear address.
  1078. */
  1079. static inline void set_linear_ip(struct pt_regs *regs, unsigned long ip)
  1080. {
  1081. regs->cs = kernel_ip(ip) ? __KERNEL_CS : __USER_CS;
  1082. if (regs->flags & X86_VM_MASK)
  1083. regs->flags ^= (PERF_EFLAGS_VM | X86_VM_MASK);
  1084. regs->ip = ip;
  1085. }
  1086. /*
  1087. * x86control flow change classification
  1088. * x86control flow changes include branches, interrupts, traps, faults
  1089. */
  1090. enum {
  1091. X86_BR_NONE = 0, /* unknown */
  1092. X86_BR_USER = 1 << 0, /* branch target is user */
  1093. X86_BR_KERNEL = 1 << 1, /* branch target is kernel */
  1094. X86_BR_CALL = 1 << 2, /* call */
  1095. X86_BR_RET = 1 << 3, /* return */
  1096. X86_BR_SYSCALL = 1 << 4, /* syscall */
  1097. X86_BR_SYSRET = 1 << 5, /* syscall return */
  1098. X86_BR_INT = 1 << 6, /* sw interrupt */
  1099. X86_BR_IRET = 1 << 7, /* return from interrupt */
  1100. X86_BR_JCC = 1 << 8, /* conditional */
  1101. X86_BR_JMP = 1 << 9, /* jump */
  1102. X86_BR_IRQ = 1 << 10,/* hw interrupt or trap or fault */
  1103. X86_BR_IND_CALL = 1 << 11,/* indirect calls */
  1104. X86_BR_ABORT = 1 << 12,/* transaction abort */
  1105. X86_BR_IN_TX = 1 << 13,/* in transaction */
  1106. X86_BR_NO_TX = 1 << 14,/* not in transaction */
  1107. X86_BR_ZERO_CALL = 1 << 15,/* zero length call */
  1108. X86_BR_CALL_STACK = 1 << 16,/* call stack */
  1109. X86_BR_IND_JMP = 1 << 17,/* indirect jump */
  1110. X86_BR_TYPE_SAVE = 1 << 18,/* indicate to save branch type */
  1111. };
  1112. #define X86_BR_PLM (X86_BR_USER | X86_BR_KERNEL)
  1113. #define X86_BR_ANYTX (X86_BR_NO_TX | X86_BR_IN_TX)
  1114. #define X86_BR_ANY \
  1115. (X86_BR_CALL |\
  1116. X86_BR_RET |\
  1117. X86_BR_SYSCALL |\
  1118. X86_BR_SYSRET |\
  1119. X86_BR_INT |\
  1120. X86_BR_IRET |\
  1121. X86_BR_JCC |\
  1122. X86_BR_JMP |\
  1123. X86_BR_IRQ |\
  1124. X86_BR_ABORT |\
  1125. X86_BR_IND_CALL |\
  1126. X86_BR_IND_JMP |\
  1127. X86_BR_ZERO_CALL)
  1128. #define X86_BR_ALL (X86_BR_PLM | X86_BR_ANY)
  1129. #define X86_BR_ANY_CALL \
  1130. (X86_BR_CALL |\
  1131. X86_BR_IND_CALL |\
  1132. X86_BR_ZERO_CALL |\
  1133. X86_BR_SYSCALL |\
  1134. X86_BR_IRQ |\
  1135. X86_BR_INT)
  1136. int common_branch_type(int type);
  1137. int branch_type(unsigned long from, unsigned long to, int abort);
  1138. int branch_type_fused(unsigned long from, unsigned long to, int abort,
  1139. int *offset);
  1140. ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event);
  1141. ssize_t intel_event_sysfs_show(char *page, u64 config);
  1142. ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,
  1143. char *page);
  1144. ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,
  1145. char *page);
  1146. ssize_t events_hybrid_sysfs_show(struct device *dev,
  1147. struct device_attribute *attr,
  1148. char *page);
  1149. static inline bool fixed_counter_disabled(int i, struct pmu *pmu)
  1150. {
  1151. u64 intel_ctrl = hybrid(pmu, intel_ctrl);
  1152. return !(intel_ctrl >> (i + INTEL_PMC_IDX_FIXED));
  1153. }
  1154. #ifdef CONFIG_CPU_SUP_AMD
  1155. int amd_pmu_init(void);
  1156. int amd_pmu_lbr_init(void);
  1157. void amd_pmu_lbr_reset(void);
  1158. void amd_pmu_lbr_read(void);
  1159. void amd_pmu_lbr_add(struct perf_event *event);
  1160. void amd_pmu_lbr_del(struct perf_event *event);
  1161. void amd_pmu_lbr_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in);
  1162. void amd_pmu_lbr_enable_all(void);
  1163. void amd_pmu_lbr_disable_all(void);
  1164. int amd_pmu_lbr_hw_config(struct perf_event *event);
  1165. static __always_inline void __amd_pmu_lbr_disable(void)
  1166. {
  1167. u64 dbg_ctl, dbg_extn_cfg;
  1168. rdmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg);
  1169. wrmsrl(MSR_AMD_DBG_EXTN_CFG, dbg_extn_cfg & ~DBG_EXTN_CFG_LBRV2EN);
  1170. if (cpu_feature_enabled(X86_FEATURE_AMD_LBR_PMC_FREEZE)) {
  1171. rdmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl);
  1172. wrmsrl(MSR_IA32_DEBUGCTLMSR, dbg_ctl & ~DEBUGCTLMSR_FREEZE_LBRS_ON_PMI);
  1173. }
  1174. }
  1175. #ifdef CONFIG_PERF_EVENTS_AMD_BRS
  1176. #define AMD_FAM19H_BRS_EVENT 0xc4 /* RETIRED_TAKEN_BRANCH_INSTRUCTIONS */
  1177. int amd_brs_init(void);
  1178. void amd_brs_disable(void);
  1179. void amd_brs_enable(void);
  1180. void amd_brs_enable_all(void);
  1181. void amd_brs_disable_all(void);
  1182. void amd_brs_drain(void);
  1183. void amd_brs_lopwr_init(void);
  1184. int amd_brs_hw_config(struct perf_event *event);
  1185. void amd_brs_reset(void);
  1186. static inline void amd_pmu_brs_add(struct perf_event *event)
  1187. {
  1188. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1189. perf_sched_cb_inc(event->pmu);
  1190. cpuc->lbr_users++;
  1191. /*
  1192. * No need to reset BRS because it is reset
  1193. * on brs_enable() and it is saturating
  1194. */
  1195. }
  1196. static inline void amd_pmu_brs_del(struct perf_event *event)
  1197. {
  1198. struct cpu_hw_events *cpuc = this_cpu_ptr(&cpu_hw_events);
  1199. cpuc->lbr_users--;
  1200. WARN_ON_ONCE(cpuc->lbr_users < 0);
  1201. perf_sched_cb_dec(event->pmu);
  1202. }
  1203. void amd_pmu_brs_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in);
  1204. #else
  1205. static inline int amd_brs_init(void)
  1206. {
  1207. return 0;
  1208. }
  1209. static inline void amd_brs_disable(void) {}
  1210. static inline void amd_brs_enable(void) {}
  1211. static inline void amd_brs_drain(void) {}
  1212. static inline void amd_brs_lopwr_init(void) {}
  1213. static inline void amd_brs_disable_all(void) {}
  1214. static inline int amd_brs_hw_config(struct perf_event *event)
  1215. {
  1216. return 0;
  1217. }
  1218. static inline void amd_brs_reset(void) {}
  1219. static inline void amd_pmu_brs_add(struct perf_event *event)
  1220. {
  1221. }
  1222. static inline void amd_pmu_brs_del(struct perf_event *event)
  1223. {
  1224. }
  1225. static inline void amd_pmu_brs_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in)
  1226. {
  1227. }
  1228. static inline void amd_brs_enable_all(void)
  1229. {
  1230. }
  1231. #endif
  1232. #else /* CONFIG_CPU_SUP_AMD */
  1233. static inline int amd_pmu_init(void)
  1234. {
  1235. return 0;
  1236. }
  1237. static inline int amd_brs_init(void)
  1238. {
  1239. return -EOPNOTSUPP;
  1240. }
  1241. static inline void amd_brs_drain(void)
  1242. {
  1243. }
  1244. static inline void amd_brs_enable_all(void)
  1245. {
  1246. }
  1247. static inline void amd_brs_disable_all(void)
  1248. {
  1249. }
  1250. #endif /* CONFIG_CPU_SUP_AMD */
  1251. static inline int is_pebs_pt(struct perf_event *event)
  1252. {
  1253. return !!(event->hw.flags & PERF_X86_EVENT_PEBS_VIA_PT);
  1254. }
  1255. #ifdef CONFIG_CPU_SUP_INTEL
  1256. static inline bool intel_pmu_has_bts_period(struct perf_event *event, u64 period)
  1257. {
  1258. struct hw_perf_event *hwc = &event->hw;
  1259. unsigned int hw_event, bts_event;
  1260. if (event->attr.freq)
  1261. return false;
  1262. hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
  1263. bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
  1264. return hw_event == bts_event && period == 1;
  1265. }
  1266. static inline bool intel_pmu_has_bts(struct perf_event *event)
  1267. {
  1268. struct hw_perf_event *hwc = &event->hw;
  1269. return intel_pmu_has_bts_period(event, hwc->sample_period);
  1270. }
  1271. static __always_inline void __intel_pmu_pebs_disable_all(void)
  1272. {
  1273. wrmsrl(MSR_IA32_PEBS_ENABLE, 0);
  1274. }
  1275. static __always_inline void __intel_pmu_arch_lbr_disable(void)
  1276. {
  1277. wrmsrl(MSR_ARCH_LBR_CTL, 0);
  1278. }
  1279. static __always_inline void __intel_pmu_lbr_disable(void)
  1280. {
  1281. u64 debugctl;
  1282. rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
  1283. debugctl &= ~(DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI);
  1284. wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
  1285. }
  1286. int intel_pmu_save_and_restart(struct perf_event *event);
  1287. struct event_constraint *
  1288. x86_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
  1289. struct perf_event *event);
  1290. extern int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu);
  1291. extern void intel_cpuc_finish(struct cpu_hw_events *cpuc);
  1292. int intel_pmu_init(void);
  1293. void init_debug_store_on_cpu(int cpu);
  1294. void fini_debug_store_on_cpu(int cpu);
  1295. void release_ds_buffers(void);
  1296. void reserve_ds_buffers(void);
  1297. void release_lbr_buffers(void);
  1298. void reserve_lbr_buffers(void);
  1299. extern struct event_constraint bts_constraint;
  1300. extern struct event_constraint vlbr_constraint;
  1301. void intel_pmu_enable_bts(u64 config);
  1302. void intel_pmu_disable_bts(void);
  1303. int intel_pmu_drain_bts_buffer(void);
  1304. u64 grt_latency_data(struct perf_event *event, u64 status);
  1305. u64 cmt_latency_data(struct perf_event *event, u64 status);
  1306. u64 lnl_latency_data(struct perf_event *event, u64 status);
  1307. extern struct event_constraint intel_core2_pebs_event_constraints[];
  1308. extern struct event_constraint intel_atom_pebs_event_constraints[];
  1309. extern struct event_constraint intel_slm_pebs_event_constraints[];
  1310. extern struct event_constraint intel_glm_pebs_event_constraints[];
  1311. extern struct event_constraint intel_glp_pebs_event_constraints[];
  1312. extern struct event_constraint intel_grt_pebs_event_constraints[];
  1313. extern struct event_constraint intel_nehalem_pebs_event_constraints[];
  1314. extern struct event_constraint intel_westmere_pebs_event_constraints[];
  1315. extern struct event_constraint intel_snb_pebs_event_constraints[];
  1316. extern struct event_constraint intel_ivb_pebs_event_constraints[];
  1317. extern struct event_constraint intel_hsw_pebs_event_constraints[];
  1318. extern struct event_constraint intel_bdw_pebs_event_constraints[];
  1319. extern struct event_constraint intel_skl_pebs_event_constraints[];
  1320. extern struct event_constraint intel_icl_pebs_event_constraints[];
  1321. extern struct event_constraint intel_glc_pebs_event_constraints[];
  1322. extern struct event_constraint intel_lnc_pebs_event_constraints[];
  1323. struct event_constraint *intel_pebs_constraints(struct perf_event *event);
  1324. void intel_pmu_pebs_add(struct perf_event *event);
  1325. void intel_pmu_pebs_del(struct perf_event *event);
  1326. void intel_pmu_pebs_enable(struct perf_event *event);
  1327. void intel_pmu_pebs_disable(struct perf_event *event);
  1328. void intel_pmu_pebs_enable_all(void);
  1329. void intel_pmu_pebs_disable_all(void);
  1330. void intel_pmu_pebs_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in);
  1331. void intel_pmu_auto_reload_read(struct perf_event *event);
  1332. void intel_pmu_store_pebs_lbrs(struct lbr_entry *lbr);
  1333. void intel_ds_init(void);
  1334. void intel_pmu_lbr_save_brstack(struct perf_sample_data *data,
  1335. struct cpu_hw_events *cpuc,
  1336. struct perf_event *event);
  1337. void intel_pmu_lbr_swap_task_ctx(struct perf_event_pmu_context *prev_epc,
  1338. struct perf_event_pmu_context *next_epc);
  1339. void intel_pmu_lbr_sched_task(struct perf_event_pmu_context *pmu_ctx, bool sched_in);
  1340. u64 lbr_from_signext_quirk_wr(u64 val);
  1341. void intel_pmu_lbr_reset(void);
  1342. void intel_pmu_lbr_reset_32(void);
  1343. void intel_pmu_lbr_reset_64(void);
  1344. void intel_pmu_lbr_add(struct perf_event *event);
  1345. void intel_pmu_lbr_del(struct perf_event *event);
  1346. void intel_pmu_lbr_enable_all(bool pmi);
  1347. void intel_pmu_lbr_disable_all(void);
  1348. void intel_pmu_lbr_read(void);
  1349. void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc);
  1350. void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc);
  1351. void intel_pmu_lbr_save(void *ctx);
  1352. void intel_pmu_lbr_restore(void *ctx);
  1353. void intel_pmu_lbr_init_core(void);
  1354. void intel_pmu_lbr_init_nhm(void);
  1355. void intel_pmu_lbr_init_atom(void);
  1356. void intel_pmu_lbr_init_slm(void);
  1357. void intel_pmu_lbr_init_snb(void);
  1358. void intel_pmu_lbr_init_hsw(void);
  1359. void intel_pmu_lbr_init_skl(void);
  1360. void intel_pmu_lbr_init_knl(void);
  1361. void intel_pmu_lbr_init(void);
  1362. void intel_pmu_arch_lbr_init(void);
  1363. void intel_pmu_pebs_data_source_nhm(void);
  1364. void intel_pmu_pebs_data_source_skl(bool pmem);
  1365. void intel_pmu_pebs_data_source_adl(void);
  1366. void intel_pmu_pebs_data_source_grt(void);
  1367. void intel_pmu_pebs_data_source_mtl(void);
  1368. void intel_pmu_pebs_data_source_cmt(void);
  1369. void intel_pmu_pebs_data_source_lnl(void);
  1370. int intel_pmu_setup_lbr_filter(struct perf_event *event);
  1371. void intel_pt_interrupt(void);
  1372. int intel_bts_interrupt(void);
  1373. void intel_bts_enable_local(void);
  1374. void intel_bts_disable_local(void);
  1375. int p4_pmu_init(void);
  1376. int p6_pmu_init(void);
  1377. int knc_pmu_init(void);
  1378. static inline int is_ht_workaround_enabled(void)
  1379. {
  1380. return !!(x86_pmu.flags & PMU_FL_EXCL_ENABLED);
  1381. }
  1382. static inline u64 intel_pmu_pebs_mask(u64 cntr_mask)
  1383. {
  1384. return MAX_PEBS_EVENTS_MASK & cntr_mask;
  1385. }
  1386. static inline int intel_pmu_max_num_pebs(struct pmu *pmu)
  1387. {
  1388. static_assert(MAX_PEBS_EVENTS == 32);
  1389. return fls((u32)hybrid(pmu, pebs_events_mask));
  1390. }
  1391. #else /* CONFIG_CPU_SUP_INTEL */
  1392. static inline void reserve_ds_buffers(void)
  1393. {
  1394. }
  1395. static inline void release_ds_buffers(void)
  1396. {
  1397. }
  1398. static inline void release_lbr_buffers(void)
  1399. {
  1400. }
  1401. static inline void reserve_lbr_buffers(void)
  1402. {
  1403. }
  1404. static inline int intel_pmu_init(void)
  1405. {
  1406. return 0;
  1407. }
  1408. static inline int intel_cpuc_prepare(struct cpu_hw_events *cpuc, int cpu)
  1409. {
  1410. return 0;
  1411. }
  1412. static inline void intel_cpuc_finish(struct cpu_hw_events *cpuc)
  1413. {
  1414. }
  1415. static inline int is_ht_workaround_enabled(void)
  1416. {
  1417. return 0;
  1418. }
  1419. #endif /* CONFIG_CPU_SUP_INTEL */
  1420. #if ((defined CONFIG_CPU_SUP_CENTAUR) || (defined CONFIG_CPU_SUP_ZHAOXIN))
  1421. int zhaoxin_pmu_init(void);
  1422. #else
  1423. static inline int zhaoxin_pmu_init(void)
  1424. {
  1425. return 0;
  1426. }
  1427. #endif /*CONFIG_CPU_SUP_CENTAUR or CONFIG_CPU_SUP_ZHAOXIN*/