perf_event.h 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397
  1. /*
  2. * Performance events:
  3. *
  4. * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
  5. * Copyright (C) 2008-2011, Red Hat, Inc., Ingo Molnar
  6. * Copyright (C) 2008-2011, Red Hat, Inc., Peter Zijlstra
  7. *
  8. * Data type definitions, declarations, prototypes.
  9. *
  10. * Started by: Thomas Gleixner and Ingo Molnar
  11. *
  12. * For licencing details see kernel-base/COPYING
  13. */
  14. #ifndef _LINUX_PERF_EVENT_H
  15. #define _LINUX_PERF_EVENT_H
  16. #include <uapi/linux/perf_event.h>
  17. /*
  18. * Kernel-internal data types and definitions:
  19. */
  20. #ifdef CONFIG_PERF_EVENTS
  21. # include <asm/perf_event.h>
  22. # include <asm/local64.h>
  23. #endif
  24. struct perf_guest_info_callbacks {
  25. int (*is_in_guest)(void);
  26. int (*is_user_mode)(void);
  27. unsigned long (*get_guest_ip)(void);
  28. };
  29. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  30. #include <asm/hw_breakpoint.h>
  31. #endif
  32. #include <linux/list.h>
  33. #include <linux/mutex.h>
  34. #include <linux/rculist.h>
  35. #include <linux/rcupdate.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/hrtimer.h>
  38. #include <linux/fs.h>
  39. #include <linux/pid_namespace.h>
  40. #include <linux/workqueue.h>
  41. #include <linux/ftrace.h>
  42. #include <linux/cpu.h>
  43. #include <linux/irq_work.h>
  44. #include <linux/static_key.h>
  45. #include <linux/jump_label_ratelimit.h>
  46. #include <linux/atomic.h>
  47. #include <linux/sysfs.h>
  48. #include <linux/perf_regs.h>
  49. #include <linux/workqueue.h>
  50. #include <linux/cgroup.h>
  51. #include <asm/local.h>
  52. struct perf_callchain_entry {
  53. __u64 nr;
  54. __u64 ip[0]; /* /proc/sys/kernel/perf_event_max_stack */
  55. };
  56. struct perf_callchain_entry_ctx {
  57. struct perf_callchain_entry *entry;
  58. u32 max_stack;
  59. u32 nr;
  60. short contexts;
  61. bool contexts_maxed;
  62. };
  63. typedef unsigned long (*perf_copy_f)(void *dst, const void *src,
  64. unsigned long off, unsigned long len);
  65. struct perf_raw_frag {
  66. union {
  67. struct perf_raw_frag *next;
  68. unsigned long pad;
  69. };
  70. perf_copy_f copy;
  71. void *data;
  72. u32 size;
  73. } __packed;
  74. struct perf_raw_record {
  75. struct perf_raw_frag frag;
  76. u32 size;
  77. };
  78. /*
  79. * branch stack layout:
  80. * nr: number of taken branches stored in entries[]
  81. *
  82. * Note that nr can vary from sample to sample
  83. * branches (to, from) are stored from most recent
  84. * to least recent, i.e., entries[0] contains the most
  85. * recent branch.
  86. */
  87. struct perf_branch_stack {
  88. __u64 nr;
  89. struct perf_branch_entry entries[0];
  90. };
  91. struct task_struct;
  92. /*
  93. * extra PMU register associated with an event
  94. */
  95. struct hw_perf_event_extra {
  96. u64 config; /* register value */
  97. unsigned int reg; /* register address or index */
  98. int alloc; /* extra register already allocated */
  99. int idx; /* index in shared_regs->regs[] */
  100. };
  101. /**
  102. * struct hw_perf_event - performance event hardware details:
  103. */
  104. struct hw_perf_event {
  105. #ifdef CONFIG_PERF_EVENTS
  106. union {
  107. struct { /* hardware */
  108. u64 config;
  109. u64 last_tag;
  110. unsigned long config_base;
  111. unsigned long event_base;
  112. int event_base_rdpmc;
  113. int idx;
  114. int last_cpu;
  115. int flags;
  116. struct hw_perf_event_extra extra_reg;
  117. struct hw_perf_event_extra branch_reg;
  118. };
  119. struct { /* software */
  120. struct hrtimer hrtimer;
  121. };
  122. struct { /* tracepoint */
  123. /* for tp_event->class */
  124. struct list_head tp_list;
  125. };
  126. struct { /* intel_cqm */
  127. int cqm_state;
  128. u32 cqm_rmid;
  129. int is_group_event;
  130. struct list_head cqm_events_entry;
  131. struct list_head cqm_groups_entry;
  132. struct list_head cqm_group_entry;
  133. };
  134. struct { /* itrace */
  135. int itrace_started;
  136. };
  137. struct { /* amd_power */
  138. u64 pwr_acc;
  139. u64 ptsc;
  140. };
  141. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  142. struct { /* breakpoint */
  143. /*
  144. * Crufty hack to avoid the chicken and egg
  145. * problem hw_breakpoint has with context
  146. * creation and event initalization.
  147. */
  148. struct arch_hw_breakpoint info;
  149. struct list_head bp_list;
  150. };
  151. #endif
  152. };
  153. /*
  154. * If the event is a per task event, this will point to the task in
  155. * question. See the comment in perf_event_alloc().
  156. */
  157. struct task_struct *target;
  158. /*
  159. * PMU would store hardware filter configuration
  160. * here.
  161. */
  162. void *addr_filters;
  163. /* Last sync'ed generation of filters */
  164. unsigned long addr_filters_gen;
  165. /*
  166. * hw_perf_event::state flags; used to track the PERF_EF_* state.
  167. */
  168. #define PERF_HES_STOPPED 0x01 /* the counter is stopped */
  169. #define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
  170. #define PERF_HES_ARCH 0x04
  171. int state;
  172. /*
  173. * The last observed hardware counter value, updated with a
  174. * local64_cmpxchg() such that pmu::read() can be called nested.
  175. */
  176. local64_t prev_count;
  177. /*
  178. * The period to start the next sample with.
  179. */
  180. u64 sample_period;
  181. /*
  182. * The period we started this sample with.
  183. */
  184. u64 last_period;
  185. /*
  186. * However much is left of the current period; note that this is
  187. * a full 64bit value and allows for generation of periods longer
  188. * than hardware might allow.
  189. */
  190. local64_t period_left;
  191. /*
  192. * State for throttling the event, see __perf_event_overflow() and
  193. * perf_adjust_freq_unthr_context().
  194. */
  195. u64 interrupts_seq;
  196. u64 interrupts;
  197. /*
  198. * State for freq target events, see __perf_event_overflow() and
  199. * perf_adjust_freq_unthr_context().
  200. */
  201. u64 freq_time_stamp;
  202. u64 freq_count_stamp;
  203. #endif
  204. };
  205. struct perf_event;
  206. /*
  207. * Common implementation detail of pmu::{start,commit,cancel}_txn
  208. */
  209. #define PERF_PMU_TXN_ADD 0x1 /* txn to add/schedule event on PMU */
  210. #define PERF_PMU_TXN_READ 0x2 /* txn to read event group from PMU */
  211. /**
  212. * pmu::capabilities flags
  213. */
  214. #define PERF_PMU_CAP_NO_INTERRUPT 0x01
  215. #define PERF_PMU_CAP_NO_NMI 0x02
  216. #define PERF_PMU_CAP_AUX_NO_SG 0x04
  217. #define PERF_PMU_CAP_AUX_SW_DOUBLEBUF 0x08
  218. #define PERF_PMU_CAP_EXCLUSIVE 0x10
  219. #define PERF_PMU_CAP_ITRACE 0x20
  220. #define PERF_PMU_CAP_HETEROGENEOUS_CPUS 0x40
  221. /**
  222. * struct pmu - generic performance monitoring unit
  223. */
  224. struct pmu {
  225. struct list_head entry;
  226. struct module *module;
  227. struct device *dev;
  228. const struct attribute_group **attr_groups;
  229. const char *name;
  230. int type;
  231. /*
  232. * various common per-pmu feature flags
  233. */
  234. int capabilities;
  235. int * __percpu pmu_disable_count;
  236. struct perf_cpu_context * __percpu pmu_cpu_context;
  237. atomic_t exclusive_cnt; /* < 0: cpu; > 0: tsk */
  238. int task_ctx_nr;
  239. int hrtimer_interval_ms;
  240. /* number of address filters this PMU can do */
  241. unsigned int nr_addr_filters;
  242. /*
  243. * Fully disable/enable this PMU, can be used to protect from the PMI
  244. * as well as for lazy/batch writing of the MSRs.
  245. */
  246. void (*pmu_enable) (struct pmu *pmu); /* optional */
  247. void (*pmu_disable) (struct pmu *pmu); /* optional */
  248. /*
  249. * Try and initialize the event for this PMU.
  250. *
  251. * Returns:
  252. * -ENOENT -- @event is not for this PMU
  253. *
  254. * -ENODEV -- @event is for this PMU but PMU not present
  255. * -EBUSY -- @event is for this PMU but PMU temporarily unavailable
  256. * -EINVAL -- @event is for this PMU but @event is not valid
  257. * -EOPNOTSUPP -- @event is for this PMU, @event is valid, but not supported
  258. * -EACCESS -- @event is for this PMU, @event is valid, but no privilidges
  259. *
  260. * 0 -- @event is for this PMU and valid
  261. *
  262. * Other error return values are allowed.
  263. */
  264. int (*event_init) (struct perf_event *event);
  265. /*
  266. * Notification that the event was mapped or unmapped. Called
  267. * in the context of the mapping task.
  268. */
  269. void (*event_mapped) (struct perf_event *event); /*optional*/
  270. void (*event_unmapped) (struct perf_event *event); /*optional*/
  271. /*
  272. * Flags for ->add()/->del()/ ->start()/->stop(). There are
  273. * matching hw_perf_event::state flags.
  274. */
  275. #define PERF_EF_START 0x01 /* start the counter when adding */
  276. #define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
  277. #define PERF_EF_UPDATE 0x04 /* update the counter when stopping */
  278. /*
  279. * Adds/Removes a counter to/from the PMU, can be done inside a
  280. * transaction, see the ->*_txn() methods.
  281. *
  282. * The add/del callbacks will reserve all hardware resources required
  283. * to service the event, this includes any counter constraint
  284. * scheduling etc.
  285. *
  286. * Called with IRQs disabled and the PMU disabled on the CPU the event
  287. * is on.
  288. *
  289. * ->add() called without PERF_EF_START should result in the same state
  290. * as ->add() followed by ->stop().
  291. *
  292. * ->del() must always PERF_EF_UPDATE stop an event. If it calls
  293. * ->stop() that must deal with already being stopped without
  294. * PERF_EF_UPDATE.
  295. */
  296. int (*add) (struct perf_event *event, int flags);
  297. void (*del) (struct perf_event *event, int flags);
  298. /*
  299. * Starts/Stops a counter present on the PMU.
  300. *
  301. * The PMI handler should stop the counter when perf_event_overflow()
  302. * returns !0. ->start() will be used to continue.
  303. *
  304. * Also used to change the sample period.
  305. *
  306. * Called with IRQs disabled and the PMU disabled on the CPU the event
  307. * is on -- will be called from NMI context with the PMU generates
  308. * NMIs.
  309. *
  310. * ->stop() with PERF_EF_UPDATE will read the counter and update
  311. * period/count values like ->read() would.
  312. *
  313. * ->start() with PERF_EF_RELOAD will reprogram the the counter
  314. * value, must be preceded by a ->stop() with PERF_EF_UPDATE.
  315. */
  316. void (*start) (struct perf_event *event, int flags);
  317. void (*stop) (struct perf_event *event, int flags);
  318. /*
  319. * Updates the counter value of the event.
  320. *
  321. * For sampling capable PMUs this will also update the software period
  322. * hw_perf_event::period_left field.
  323. */
  324. void (*read) (struct perf_event *event);
  325. /*
  326. * Group events scheduling is treated as a transaction, add
  327. * group events as a whole and perform one schedulability test.
  328. * If the test fails, roll back the whole group
  329. *
  330. * Start the transaction, after this ->add() doesn't need to
  331. * do schedulability tests.
  332. *
  333. * Optional.
  334. */
  335. void (*start_txn) (struct pmu *pmu, unsigned int txn_flags);
  336. /*
  337. * If ->start_txn() disabled the ->add() schedulability test
  338. * then ->commit_txn() is required to perform one. On success
  339. * the transaction is closed. On error the transaction is kept
  340. * open until ->cancel_txn() is called.
  341. *
  342. * Optional.
  343. */
  344. int (*commit_txn) (struct pmu *pmu);
  345. /*
  346. * Will cancel the transaction, assumes ->del() is called
  347. * for each successful ->add() during the transaction.
  348. *
  349. * Optional.
  350. */
  351. void (*cancel_txn) (struct pmu *pmu);
  352. /*
  353. * Will return the value for perf_event_mmap_page::index for this event,
  354. * if no implementation is provided it will default to: event->hw.idx + 1.
  355. */
  356. int (*event_idx) (struct perf_event *event); /*optional */
  357. /*
  358. * context-switches callback
  359. */
  360. void (*sched_task) (struct perf_event_context *ctx,
  361. bool sched_in);
  362. /*
  363. * PMU specific data size
  364. */
  365. size_t task_ctx_size;
  366. /*
  367. * Return the count value for a counter.
  368. */
  369. u64 (*count) (struct perf_event *event); /*optional*/
  370. /*
  371. * Set up pmu-private data structures for an AUX area
  372. */
  373. void *(*setup_aux) (int cpu, void **pages,
  374. int nr_pages, bool overwrite);
  375. /* optional */
  376. /*
  377. * Free pmu-private AUX data structures
  378. */
  379. void (*free_aux) (void *aux); /* optional */
  380. /*
  381. * Validate address range filters: make sure the HW supports the
  382. * requested configuration and number of filters; return 0 if the
  383. * supplied filters are valid, -errno otherwise.
  384. *
  385. * Runs in the context of the ioctl()ing process and is not serialized
  386. * with the rest of the PMU callbacks.
  387. */
  388. int (*addr_filters_validate) (struct list_head *filters);
  389. /* optional */
  390. /*
  391. * Synchronize address range filter configuration:
  392. * translate hw-agnostic filters into hardware configuration in
  393. * event::hw::addr_filters.
  394. *
  395. * Runs as a part of filter sync sequence that is done in ->start()
  396. * callback by calling perf_event_addr_filters_sync().
  397. *
  398. * May (and should) traverse event::addr_filters::list, for which its
  399. * caller provides necessary serialization.
  400. */
  401. void (*addr_filters_sync) (struct perf_event *event);
  402. /* optional */
  403. /*
  404. * Filter events for PMU-specific reasons.
  405. */
  406. int (*filter_match) (struct perf_event *event); /* optional */
  407. };
  408. /**
  409. * struct perf_addr_filter - address range filter definition
  410. * @entry: event's filter list linkage
  411. * @inode: object file's inode for file-based filters
  412. * @offset: filter range offset
  413. * @size: filter range size
  414. * @range: 1: range, 0: address
  415. * @filter: 1: filter/start, 0: stop
  416. *
  417. * This is a hardware-agnostic filter configuration as specified by the user.
  418. */
  419. struct perf_addr_filter {
  420. struct list_head entry;
  421. struct inode *inode;
  422. unsigned long offset;
  423. unsigned long size;
  424. unsigned int range : 1,
  425. filter : 1;
  426. };
  427. /**
  428. * struct perf_addr_filters_head - container for address range filters
  429. * @list: list of filters for this event
  430. * @lock: spinlock that serializes accesses to the @list and event's
  431. * (and its children's) filter generations.
  432. * @nr_file_filters: number of file-based filters
  433. *
  434. * A child event will use parent's @list (and therefore @lock), so they are
  435. * bundled together; see perf_event_addr_filters().
  436. */
  437. struct perf_addr_filters_head {
  438. struct list_head list;
  439. raw_spinlock_t lock;
  440. unsigned int nr_file_filters;
  441. };
  442. /**
  443. * enum perf_event_active_state - the states of a event
  444. */
  445. enum perf_event_active_state {
  446. PERF_EVENT_STATE_DEAD = -4,
  447. PERF_EVENT_STATE_EXIT = -3,
  448. PERF_EVENT_STATE_ERROR = -2,
  449. PERF_EVENT_STATE_OFF = -1,
  450. PERF_EVENT_STATE_INACTIVE = 0,
  451. PERF_EVENT_STATE_ACTIVE = 1,
  452. };
  453. struct file;
  454. struct perf_sample_data;
  455. typedef void (*perf_overflow_handler_t)(struct perf_event *,
  456. struct perf_sample_data *,
  457. struct pt_regs *regs);
  458. /*
  459. * Event capabilities. For event_caps and groups caps.
  460. *
  461. * PERF_EV_CAP_SOFTWARE: Is a software event.
  462. * PERF_EV_CAP_READ_ACTIVE_PKG: A CPU event (or cgroup event) that can be read
  463. * from any CPU in the package where it is active.
  464. */
  465. #define PERF_EV_CAP_SOFTWARE BIT(0)
  466. #define PERF_EV_CAP_READ_ACTIVE_PKG BIT(1)
  467. #define SWEVENT_HLIST_BITS 8
  468. #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)
  469. struct swevent_hlist {
  470. struct hlist_head heads[SWEVENT_HLIST_SIZE];
  471. struct rcu_head rcu_head;
  472. };
  473. #define PERF_ATTACH_CONTEXT 0x01
  474. #define PERF_ATTACH_GROUP 0x02
  475. #define PERF_ATTACH_TASK 0x04
  476. #define PERF_ATTACH_TASK_DATA 0x08
  477. struct perf_cgroup;
  478. struct ring_buffer;
  479. struct pmu_event_list {
  480. raw_spinlock_t lock;
  481. struct list_head list;
  482. };
  483. /**
  484. * struct perf_event - performance event kernel representation:
  485. */
  486. struct perf_event {
  487. #ifdef CONFIG_PERF_EVENTS
  488. /*
  489. * entry onto perf_event_context::event_list;
  490. * modifications require ctx->lock
  491. * RCU safe iterations.
  492. */
  493. struct list_head event_entry;
  494. /*
  495. * XXX: group_entry and sibling_list should be mutually exclusive;
  496. * either you're a sibling on a group, or you're the group leader.
  497. * Rework the code to always use the same list element.
  498. *
  499. * Locked for modification by both ctx->mutex and ctx->lock; holding
  500. * either sufficies for read.
  501. */
  502. struct list_head group_entry;
  503. struct list_head sibling_list;
  504. /*
  505. * We need storage to track the entries in perf_pmu_migrate_context; we
  506. * cannot use the event_entry because of RCU and we want to keep the
  507. * group in tact which avoids us using the other two entries.
  508. */
  509. struct list_head migrate_entry;
  510. struct hlist_node hlist_entry;
  511. struct list_head active_entry;
  512. int nr_siblings;
  513. /* Not serialized. Only written during event initialization. */
  514. int event_caps;
  515. /* The cumulative AND of all event_caps for events in this group. */
  516. int group_caps;
  517. struct perf_event *group_leader;
  518. struct pmu *pmu;
  519. void *pmu_private;
  520. enum perf_event_active_state state;
  521. unsigned int attach_state;
  522. local64_t count;
  523. atomic64_t child_count;
  524. /*
  525. * These are the total time in nanoseconds that the event
  526. * has been enabled (i.e. eligible to run, and the task has
  527. * been scheduled in, if this is a per-task event)
  528. * and running (scheduled onto the CPU), respectively.
  529. *
  530. * They are computed from tstamp_enabled, tstamp_running and
  531. * tstamp_stopped when the event is in INACTIVE or ACTIVE state.
  532. */
  533. u64 total_time_enabled;
  534. u64 total_time_running;
  535. /*
  536. * These are timestamps used for computing total_time_enabled
  537. * and total_time_running when the event is in INACTIVE or
  538. * ACTIVE state, measured in nanoseconds from an arbitrary point
  539. * in time.
  540. * tstamp_enabled: the notional time when the event was enabled
  541. * tstamp_running: the notional time when the event was scheduled on
  542. * tstamp_stopped: in INACTIVE state, the notional time when the
  543. * event was scheduled off.
  544. */
  545. u64 tstamp_enabled;
  546. u64 tstamp_running;
  547. u64 tstamp_stopped;
  548. /*
  549. * timestamp shadows the actual context timing but it can
  550. * be safely used in NMI interrupt context. It reflects the
  551. * context time as it was when the event was last scheduled in.
  552. *
  553. * ctx_time already accounts for ctx->timestamp. Therefore to
  554. * compute ctx_time for a sample, simply add perf_clock().
  555. */
  556. u64 shadow_ctx_time;
  557. struct perf_event_attr attr;
  558. u16 header_size;
  559. u16 id_header_size;
  560. u16 read_size;
  561. struct hw_perf_event hw;
  562. struct perf_event_context *ctx;
  563. atomic_long_t refcount;
  564. /*
  565. * These accumulate total time (in nanoseconds) that children
  566. * events have been enabled and running, respectively.
  567. */
  568. atomic64_t child_total_time_enabled;
  569. atomic64_t child_total_time_running;
  570. /*
  571. * Protect attach/detach and child_list:
  572. */
  573. struct mutex child_mutex;
  574. struct list_head child_list;
  575. struct perf_event *parent;
  576. int oncpu;
  577. int cpu;
  578. struct list_head owner_entry;
  579. struct task_struct *owner;
  580. /* mmap bits */
  581. struct mutex mmap_mutex;
  582. atomic_t mmap_count;
  583. struct ring_buffer *rb;
  584. struct list_head rb_entry;
  585. unsigned long rcu_batches;
  586. int rcu_pending;
  587. /* poll related */
  588. wait_queue_head_t waitq;
  589. struct fasync_struct *fasync;
  590. /* delayed work for NMIs and such */
  591. int pending_wakeup;
  592. int pending_kill;
  593. int pending_disable;
  594. struct irq_work pending;
  595. atomic_t event_limit;
  596. /* address range filters */
  597. struct perf_addr_filters_head addr_filters;
  598. /* vma address array for file-based filders */
  599. unsigned long *addr_filters_offs;
  600. unsigned long addr_filters_gen;
  601. void (*destroy)(struct perf_event *);
  602. struct rcu_head rcu_head;
  603. struct pid_namespace *ns;
  604. u64 id;
  605. u64 (*clock)(void);
  606. perf_overflow_handler_t overflow_handler;
  607. void *overflow_handler_context;
  608. #ifdef CONFIG_BPF_SYSCALL
  609. perf_overflow_handler_t orig_overflow_handler;
  610. struct bpf_prog *prog;
  611. #endif
  612. #ifdef CONFIG_EVENT_TRACING
  613. struct trace_event_call *tp_event;
  614. struct event_filter *filter;
  615. #ifdef CONFIG_FUNCTION_TRACER
  616. struct ftrace_ops ftrace_ops;
  617. #endif
  618. #endif
  619. #ifdef CONFIG_CGROUP_PERF
  620. struct perf_cgroup *cgrp; /* cgroup event is attach to */
  621. int cgrp_defer_enabled;
  622. #endif
  623. struct list_head sb_list;
  624. #endif /* CONFIG_PERF_EVENTS */
  625. };
  626. /**
  627. * struct perf_event_context - event context structure
  628. *
  629. * Used as a container for task events and CPU events as well:
  630. */
  631. struct perf_event_context {
  632. struct pmu *pmu;
  633. /*
  634. * Protect the states of the events in the list,
  635. * nr_active, and the list:
  636. */
  637. raw_spinlock_t lock;
  638. /*
  639. * Protect the list of events. Locking either mutex or lock
  640. * is sufficient to ensure the list doesn't change; to change
  641. * the list you need to lock both the mutex and the spinlock.
  642. */
  643. struct mutex mutex;
  644. struct list_head active_ctx_list;
  645. struct list_head pinned_groups;
  646. struct list_head flexible_groups;
  647. struct list_head event_list;
  648. int nr_events;
  649. int nr_active;
  650. int is_active;
  651. int nr_stat;
  652. int nr_freq;
  653. int rotate_disable;
  654. atomic_t refcount;
  655. struct task_struct *task;
  656. /*
  657. * Context clock, runs when context enabled.
  658. */
  659. u64 time;
  660. u64 timestamp;
  661. /*
  662. * These fields let us detect when two contexts have both
  663. * been cloned (inherited) from a common ancestor.
  664. */
  665. struct perf_event_context *parent_ctx;
  666. u64 parent_gen;
  667. u64 generation;
  668. int pin_count;
  669. #ifdef CONFIG_CGROUP_PERF
  670. int nr_cgroups; /* cgroup evts */
  671. #endif
  672. void *task_ctx_data; /* pmu specific data */
  673. struct rcu_head rcu_head;
  674. };
  675. /*
  676. * Number of contexts where an event can trigger:
  677. * task, softirq, hardirq, nmi.
  678. */
  679. #define PERF_NR_CONTEXTS 4
  680. /**
  681. * struct perf_event_cpu_context - per cpu event context structure
  682. */
  683. struct perf_cpu_context {
  684. struct perf_event_context ctx;
  685. struct perf_event_context *task_ctx;
  686. int active_oncpu;
  687. int exclusive;
  688. raw_spinlock_t hrtimer_lock;
  689. struct hrtimer hrtimer;
  690. ktime_t hrtimer_interval;
  691. unsigned int hrtimer_active;
  692. #ifdef CONFIG_CGROUP_PERF
  693. struct perf_cgroup *cgrp;
  694. struct list_head cgrp_cpuctx_entry;
  695. #endif
  696. struct list_head sched_cb_entry;
  697. int sched_cb_usage;
  698. };
  699. struct perf_output_handle {
  700. struct perf_event *event;
  701. struct ring_buffer *rb;
  702. unsigned long wakeup;
  703. unsigned long size;
  704. u64 aux_flags;
  705. union {
  706. void *addr;
  707. unsigned long head;
  708. };
  709. int page;
  710. };
  711. struct bpf_perf_event_data_kern {
  712. struct pt_regs *regs;
  713. struct perf_sample_data *data;
  714. };
  715. #ifdef CONFIG_CGROUP_PERF
  716. /*
  717. * perf_cgroup_info keeps track of time_enabled for a cgroup.
  718. * This is a per-cpu dynamically allocated data structure.
  719. */
  720. struct perf_cgroup_info {
  721. u64 time;
  722. u64 timestamp;
  723. };
  724. struct perf_cgroup {
  725. struct cgroup_subsys_state css;
  726. struct perf_cgroup_info __percpu *info;
  727. };
  728. /*
  729. * Must ensure cgroup is pinned (css_get) before calling
  730. * this function. In other words, we cannot call this function
  731. * if there is no cgroup event for the current CPU context.
  732. */
  733. static inline struct perf_cgroup *
  734. perf_cgroup_from_task(struct task_struct *task, struct perf_event_context *ctx)
  735. {
  736. return container_of(task_css_check(task, perf_event_cgrp_id,
  737. ctx ? lockdep_is_held(&ctx->lock)
  738. : true),
  739. struct perf_cgroup, css);
  740. }
  741. #endif /* CONFIG_CGROUP_PERF */
  742. #ifdef CONFIG_PERF_EVENTS
  743. extern void *perf_aux_output_begin(struct perf_output_handle *handle,
  744. struct perf_event *event);
  745. extern void perf_aux_output_end(struct perf_output_handle *handle,
  746. unsigned long size);
  747. extern int perf_aux_output_skip(struct perf_output_handle *handle,
  748. unsigned long size);
  749. extern void *perf_get_aux(struct perf_output_handle *handle);
  750. extern void perf_aux_output_flag(struct perf_output_handle *handle, u64 flags);
  751. extern int perf_pmu_register(struct pmu *pmu, const char *name, int type);
  752. extern void perf_pmu_unregister(struct pmu *pmu);
  753. extern int perf_num_counters(void);
  754. extern const char *perf_pmu_name(void);
  755. extern void __perf_event_task_sched_in(struct task_struct *prev,
  756. struct task_struct *task);
  757. extern void __perf_event_task_sched_out(struct task_struct *prev,
  758. struct task_struct *next);
  759. extern int perf_event_init_task(struct task_struct *child);
  760. extern void perf_event_exit_task(struct task_struct *child);
  761. extern void perf_event_free_task(struct task_struct *task);
  762. extern void perf_event_delayed_put(struct task_struct *task);
  763. extern struct file *perf_event_get(unsigned int fd);
  764. extern const struct perf_event_attr *perf_event_attrs(struct perf_event *event);
  765. extern void perf_event_print_debug(void);
  766. extern void perf_pmu_disable(struct pmu *pmu);
  767. extern void perf_pmu_enable(struct pmu *pmu);
  768. extern void perf_sched_cb_dec(struct pmu *pmu);
  769. extern void perf_sched_cb_inc(struct pmu *pmu);
  770. extern int perf_event_task_disable(void);
  771. extern int perf_event_task_enable(void);
  772. extern int perf_event_refresh(struct perf_event *event, int refresh);
  773. extern void perf_event_update_userpage(struct perf_event *event);
  774. extern int perf_event_release_kernel(struct perf_event *event);
  775. extern struct perf_event *
  776. perf_event_create_kernel_counter(struct perf_event_attr *attr,
  777. int cpu,
  778. struct task_struct *task,
  779. perf_overflow_handler_t callback,
  780. void *context);
  781. extern void perf_pmu_migrate_context(struct pmu *pmu,
  782. int src_cpu, int dst_cpu);
  783. extern u64 perf_event_read_local(struct perf_event *event);
  784. extern u64 perf_event_read_value(struct perf_event *event,
  785. u64 *enabled, u64 *running);
  786. struct perf_sample_data {
  787. /*
  788. * Fields set by perf_sample_data_init(), group so as to
  789. * minimize the cachelines touched.
  790. */
  791. u64 addr;
  792. struct perf_raw_record *raw;
  793. struct perf_branch_stack *br_stack;
  794. u64 period;
  795. u64 weight;
  796. u64 txn;
  797. union perf_mem_data_src data_src;
  798. /*
  799. * The other fields, optionally {set,used} by
  800. * perf_{prepare,output}_sample().
  801. */
  802. u64 type;
  803. u64 ip;
  804. struct {
  805. u32 pid;
  806. u32 tid;
  807. } tid_entry;
  808. u64 time;
  809. u64 id;
  810. u64 stream_id;
  811. struct {
  812. u32 cpu;
  813. u32 reserved;
  814. } cpu_entry;
  815. struct perf_callchain_entry *callchain;
  816. /*
  817. * regs_user may point to task_pt_regs or to regs_user_copy, depending
  818. * on arch details.
  819. */
  820. struct perf_regs regs_user;
  821. struct pt_regs regs_user_copy;
  822. struct perf_regs regs_intr;
  823. u64 stack_user_size;
  824. } ____cacheline_aligned;
  825. /* default value for data source */
  826. #define PERF_MEM_NA (PERF_MEM_S(OP, NA) |\
  827. PERF_MEM_S(LVL, NA) |\
  828. PERF_MEM_S(SNOOP, NA) |\
  829. PERF_MEM_S(LOCK, NA) |\
  830. PERF_MEM_S(TLB, NA))
  831. static inline void perf_sample_data_init(struct perf_sample_data *data,
  832. u64 addr, u64 period)
  833. {
  834. /* remaining struct members initialized in perf_prepare_sample() */
  835. data->addr = addr;
  836. data->raw = NULL;
  837. data->br_stack = NULL;
  838. data->period = period;
  839. data->weight = 0;
  840. data->data_src.val = PERF_MEM_NA;
  841. data->txn = 0;
  842. }
  843. extern void perf_output_sample(struct perf_output_handle *handle,
  844. struct perf_event_header *header,
  845. struct perf_sample_data *data,
  846. struct perf_event *event);
  847. extern void perf_prepare_sample(struct perf_event_header *header,
  848. struct perf_sample_data *data,
  849. struct perf_event *event,
  850. struct pt_regs *regs);
  851. extern int perf_event_overflow(struct perf_event *event,
  852. struct perf_sample_data *data,
  853. struct pt_regs *regs);
  854. extern void perf_event_output_forward(struct perf_event *event,
  855. struct perf_sample_data *data,
  856. struct pt_regs *regs);
  857. extern void perf_event_output_backward(struct perf_event *event,
  858. struct perf_sample_data *data,
  859. struct pt_regs *regs);
  860. extern void perf_event_output(struct perf_event *event,
  861. struct perf_sample_data *data,
  862. struct pt_regs *regs);
  863. static inline bool
  864. is_default_overflow_handler(struct perf_event *event)
  865. {
  866. if (likely(event->overflow_handler == perf_event_output_forward))
  867. return true;
  868. if (unlikely(event->overflow_handler == perf_event_output_backward))
  869. return true;
  870. return false;
  871. }
  872. extern void
  873. perf_event_header__init_id(struct perf_event_header *header,
  874. struct perf_sample_data *data,
  875. struct perf_event *event);
  876. extern void
  877. perf_event__output_id_sample(struct perf_event *event,
  878. struct perf_output_handle *handle,
  879. struct perf_sample_data *sample);
  880. extern void
  881. perf_log_lost_samples(struct perf_event *event, u64 lost);
  882. static inline bool is_sampling_event(struct perf_event *event)
  883. {
  884. return event->attr.sample_period != 0;
  885. }
  886. /*
  887. * Return 1 for a software event, 0 for a hardware event
  888. */
  889. static inline int is_software_event(struct perf_event *event)
  890. {
  891. return event->event_caps & PERF_EV_CAP_SOFTWARE;
  892. }
  893. extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX];
  894. extern void ___perf_sw_event(u32, u64, struct pt_regs *, u64);
  895. extern void __perf_sw_event(u32, u64, struct pt_regs *, u64);
  896. #ifndef perf_arch_fetch_caller_regs
  897. static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip) { }
  898. #endif
  899. /*
  900. * Take a snapshot of the regs. Skip ip and frame pointer to
  901. * the nth caller. We only need a few of the regs:
  902. * - ip for PERF_SAMPLE_IP
  903. * - cs for user_mode() tests
  904. * - bp for callchains
  905. * - eflags, for future purposes, just in case
  906. */
  907. static inline void perf_fetch_caller_regs(struct pt_regs *regs)
  908. {
  909. perf_arch_fetch_caller_regs(regs, CALLER_ADDR0);
  910. }
  911. static __always_inline void
  912. perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
  913. {
  914. if (static_key_false(&perf_swevent_enabled[event_id]))
  915. __perf_sw_event(event_id, nr, regs, addr);
  916. }
  917. DECLARE_PER_CPU(struct pt_regs, __perf_regs[4]);
  918. /*
  919. * 'Special' version for the scheduler, it hard assumes no recursion,
  920. * which is guaranteed by us not actually scheduling inside other swevents
  921. * because those disable preemption.
  922. */
  923. static __always_inline void
  924. perf_sw_event_sched(u32 event_id, u64 nr, u64 addr)
  925. {
  926. if (static_key_false(&perf_swevent_enabled[event_id])) {
  927. struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]);
  928. perf_fetch_caller_regs(regs);
  929. ___perf_sw_event(event_id, nr, regs, addr);
  930. }
  931. }
  932. extern struct static_key_false perf_sched_events;
  933. static __always_inline bool
  934. perf_sw_migrate_enabled(void)
  935. {
  936. if (static_key_false(&perf_swevent_enabled[PERF_COUNT_SW_CPU_MIGRATIONS]))
  937. return true;
  938. return false;
  939. }
  940. static inline void perf_event_task_migrate(struct task_struct *task)
  941. {
  942. if (perf_sw_migrate_enabled())
  943. task->sched_migrated = 1;
  944. }
  945. static inline void perf_event_task_sched_in(struct task_struct *prev,
  946. struct task_struct *task)
  947. {
  948. if (static_branch_unlikely(&perf_sched_events))
  949. __perf_event_task_sched_in(prev, task);
  950. if (perf_sw_migrate_enabled() && task->sched_migrated) {
  951. struct pt_regs *regs = this_cpu_ptr(&__perf_regs[0]);
  952. perf_fetch_caller_regs(regs);
  953. ___perf_sw_event(PERF_COUNT_SW_CPU_MIGRATIONS, 1, regs, 0);
  954. task->sched_migrated = 0;
  955. }
  956. }
  957. static inline void perf_event_task_sched_out(struct task_struct *prev,
  958. struct task_struct *next)
  959. {
  960. perf_sw_event_sched(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 0);
  961. if (static_branch_unlikely(&perf_sched_events))
  962. __perf_event_task_sched_out(prev, next);
  963. }
  964. static inline u64 __perf_event_count(struct perf_event *event)
  965. {
  966. return local64_read(&event->count) + atomic64_read(&event->child_count);
  967. }
  968. extern void perf_event_mmap(struct vm_area_struct *vma);
  969. extern struct perf_guest_info_callbacks *perf_guest_cbs;
  970. extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
  971. extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
  972. extern void perf_event_exec(void);
  973. extern void perf_event_comm(struct task_struct *tsk, bool exec);
  974. extern void perf_event_namespaces(struct task_struct *tsk);
  975. extern void perf_event_fork(struct task_struct *tsk);
  976. /* Callchains */
  977. DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry);
  978. extern void perf_callchain_user(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs);
  979. extern void perf_callchain_kernel(struct perf_callchain_entry_ctx *entry, struct pt_regs *regs);
  980. extern struct perf_callchain_entry *
  981. get_perf_callchain(struct pt_regs *regs, u32 init_nr, bool kernel, bool user,
  982. u32 max_stack, bool crosstask, bool add_mark);
  983. extern int get_callchain_buffers(int max_stack);
  984. extern void put_callchain_buffers(void);
  985. extern int sysctl_perf_event_max_stack;
  986. extern int sysctl_perf_event_max_contexts_per_stack;
  987. static inline int perf_callchain_store_context(struct perf_callchain_entry_ctx *ctx, u64 ip)
  988. {
  989. if (ctx->contexts < sysctl_perf_event_max_contexts_per_stack) {
  990. struct perf_callchain_entry *entry = ctx->entry;
  991. entry->ip[entry->nr++] = ip;
  992. ++ctx->contexts;
  993. return 0;
  994. } else {
  995. ctx->contexts_maxed = true;
  996. return -1; /* no more room, stop walking the stack */
  997. }
  998. }
  999. static inline int perf_callchain_store(struct perf_callchain_entry_ctx *ctx, u64 ip)
  1000. {
  1001. if (ctx->nr < ctx->max_stack && !ctx->contexts_maxed) {
  1002. struct perf_callchain_entry *entry = ctx->entry;
  1003. entry->ip[entry->nr++] = ip;
  1004. ++ctx->nr;
  1005. return 0;
  1006. } else {
  1007. return -1; /* no more room, stop walking the stack */
  1008. }
  1009. }
  1010. extern int sysctl_perf_event_paranoid;
  1011. extern int sysctl_perf_event_mlock;
  1012. extern int sysctl_perf_event_sample_rate;
  1013. extern int sysctl_perf_cpu_time_max_percent;
  1014. extern void perf_sample_event_took(u64 sample_len_ns);
  1015. extern int perf_proc_update_handler(struct ctl_table *table, int write,
  1016. void __user *buffer, size_t *lenp,
  1017. loff_t *ppos);
  1018. extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
  1019. void __user *buffer, size_t *lenp,
  1020. loff_t *ppos);
  1021. int perf_event_max_stack_handler(struct ctl_table *table, int write,
  1022. void __user *buffer, size_t *lenp, loff_t *ppos);
  1023. static inline bool perf_paranoid_tracepoint_raw(void)
  1024. {
  1025. return sysctl_perf_event_paranoid > -1;
  1026. }
  1027. static inline bool perf_paranoid_cpu(void)
  1028. {
  1029. return sysctl_perf_event_paranoid > 0;
  1030. }
  1031. static inline bool perf_paranoid_kernel(void)
  1032. {
  1033. return sysctl_perf_event_paranoid > 1;
  1034. }
  1035. extern void perf_event_init(void);
  1036. extern void perf_tp_event(u16 event_type, u64 count, void *record,
  1037. int entry_size, struct pt_regs *regs,
  1038. struct hlist_head *head, int rctx,
  1039. struct task_struct *task);
  1040. extern void perf_bp_event(struct perf_event *event, void *data);
  1041. #ifndef perf_misc_flags
  1042. # define perf_misc_flags(regs) \
  1043. (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
  1044. # define perf_instruction_pointer(regs) instruction_pointer(regs)
  1045. #endif
  1046. static inline bool has_branch_stack(struct perf_event *event)
  1047. {
  1048. return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
  1049. }
  1050. static inline bool needs_branch_stack(struct perf_event *event)
  1051. {
  1052. return event->attr.branch_sample_type != 0;
  1053. }
  1054. static inline bool has_aux(struct perf_event *event)
  1055. {
  1056. return event->pmu->setup_aux;
  1057. }
  1058. static inline bool is_write_backward(struct perf_event *event)
  1059. {
  1060. return !!event->attr.write_backward;
  1061. }
  1062. static inline bool has_addr_filter(struct perf_event *event)
  1063. {
  1064. return event->pmu->nr_addr_filters;
  1065. }
  1066. /*
  1067. * An inherited event uses parent's filters
  1068. */
  1069. static inline struct perf_addr_filters_head *
  1070. perf_event_addr_filters(struct perf_event *event)
  1071. {
  1072. struct perf_addr_filters_head *ifh = &event->addr_filters;
  1073. if (event->parent)
  1074. ifh = &event->parent->addr_filters;
  1075. return ifh;
  1076. }
  1077. extern void perf_event_addr_filters_sync(struct perf_event *event);
  1078. extern int perf_output_begin(struct perf_output_handle *handle,
  1079. struct perf_event *event, unsigned int size);
  1080. extern int perf_output_begin_forward(struct perf_output_handle *handle,
  1081. struct perf_event *event,
  1082. unsigned int size);
  1083. extern int perf_output_begin_backward(struct perf_output_handle *handle,
  1084. struct perf_event *event,
  1085. unsigned int size);
  1086. extern void perf_output_end(struct perf_output_handle *handle);
  1087. extern unsigned int perf_output_copy(struct perf_output_handle *handle,
  1088. const void *buf, unsigned int len);
  1089. extern unsigned int perf_output_skip(struct perf_output_handle *handle,
  1090. unsigned int len);
  1091. extern int perf_swevent_get_recursion_context(void);
  1092. extern void perf_swevent_put_recursion_context(int rctx);
  1093. extern u64 perf_swevent_set_period(struct perf_event *event);
  1094. extern void perf_event_enable(struct perf_event *event);
  1095. extern void perf_event_disable(struct perf_event *event);
  1096. extern void perf_event_disable_local(struct perf_event *event);
  1097. extern void perf_event_disable_inatomic(struct perf_event *event);
  1098. extern void perf_event_task_tick(void);
  1099. extern int perf_event_account_interrupt(struct perf_event *event);
  1100. #else /* !CONFIG_PERF_EVENTS: */
  1101. static inline void *
  1102. perf_aux_output_begin(struct perf_output_handle *handle,
  1103. struct perf_event *event) { return NULL; }
  1104. static inline void
  1105. perf_aux_output_end(struct perf_output_handle *handle, unsigned long size)
  1106. { }
  1107. static inline int
  1108. perf_aux_output_skip(struct perf_output_handle *handle,
  1109. unsigned long size) { return -EINVAL; }
  1110. static inline void *
  1111. perf_get_aux(struct perf_output_handle *handle) { return NULL; }
  1112. static inline void
  1113. perf_event_task_migrate(struct task_struct *task) { }
  1114. static inline void
  1115. perf_event_task_sched_in(struct task_struct *prev,
  1116. struct task_struct *task) { }
  1117. static inline void
  1118. perf_event_task_sched_out(struct task_struct *prev,
  1119. struct task_struct *next) { }
  1120. static inline int perf_event_init_task(struct task_struct *child) { return 0; }
  1121. static inline void perf_event_exit_task(struct task_struct *child) { }
  1122. static inline void perf_event_free_task(struct task_struct *task) { }
  1123. static inline void perf_event_delayed_put(struct task_struct *task) { }
  1124. static inline struct file *perf_event_get(unsigned int fd) { return ERR_PTR(-EINVAL); }
  1125. static inline const struct perf_event_attr *perf_event_attrs(struct perf_event *event)
  1126. {
  1127. return ERR_PTR(-EINVAL);
  1128. }
  1129. static inline u64 perf_event_read_local(struct perf_event *event) { return -EINVAL; }
  1130. static inline void perf_event_print_debug(void) { }
  1131. static inline int perf_event_task_disable(void) { return -EINVAL; }
  1132. static inline int perf_event_task_enable(void) { return -EINVAL; }
  1133. static inline int perf_event_refresh(struct perf_event *event, int refresh)
  1134. {
  1135. return -EINVAL;
  1136. }
  1137. static inline void
  1138. perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { }
  1139. static inline void
  1140. perf_sw_event_sched(u32 event_id, u64 nr, u64 addr) { }
  1141. static inline void
  1142. perf_bp_event(struct perf_event *event, void *data) { }
  1143. static inline int perf_register_guest_info_callbacks
  1144. (struct perf_guest_info_callbacks *callbacks) { return 0; }
  1145. static inline int perf_unregister_guest_info_callbacks
  1146. (struct perf_guest_info_callbacks *callbacks) { return 0; }
  1147. static inline void perf_event_mmap(struct vm_area_struct *vma) { }
  1148. static inline void perf_event_exec(void) { }
  1149. static inline void perf_event_comm(struct task_struct *tsk, bool exec) { }
  1150. static inline void perf_event_namespaces(struct task_struct *tsk) { }
  1151. static inline void perf_event_fork(struct task_struct *tsk) { }
  1152. static inline void perf_event_init(void) { }
  1153. static inline int perf_swevent_get_recursion_context(void) { return -1; }
  1154. static inline void perf_swevent_put_recursion_context(int rctx) { }
  1155. static inline u64 perf_swevent_set_period(struct perf_event *event) { return 0; }
  1156. static inline void perf_event_enable(struct perf_event *event) { }
  1157. static inline void perf_event_disable(struct perf_event *event) { }
  1158. static inline int __perf_event_disable(void *info) { return -1; }
  1159. static inline void perf_event_task_tick(void) { }
  1160. static inline int perf_event_release_kernel(struct perf_event *event) { return 0; }
  1161. #endif
  1162. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
  1163. extern void perf_restore_debug_store(void);
  1164. #else
  1165. static inline void perf_restore_debug_store(void) { }
  1166. #endif
  1167. static __always_inline bool perf_raw_frag_last(const struct perf_raw_frag *frag)
  1168. {
  1169. return frag->pad < sizeof(u64);
  1170. }
  1171. #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
  1172. struct perf_pmu_events_attr {
  1173. struct device_attribute attr;
  1174. u64 id;
  1175. const char *event_str;
  1176. };
  1177. struct perf_pmu_events_ht_attr {
  1178. struct device_attribute attr;
  1179. u64 id;
  1180. const char *event_str_ht;
  1181. const char *event_str_noht;
  1182. };
  1183. ssize_t perf_event_sysfs_show(struct device *dev, struct device_attribute *attr,
  1184. char *page);
  1185. #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
  1186. static struct perf_pmu_events_attr _var = { \
  1187. .attr = __ATTR(_name, 0444, _show, NULL), \
  1188. .id = _id, \
  1189. };
  1190. #define PMU_EVENT_ATTR_STRING(_name, _var, _str) \
  1191. static struct perf_pmu_events_attr _var = { \
  1192. .attr = __ATTR(_name, 0444, perf_event_sysfs_show, NULL), \
  1193. .id = 0, \
  1194. .event_str = _str, \
  1195. };
  1196. #define PMU_FORMAT_ATTR(_name, _format) \
  1197. static ssize_t \
  1198. _name##_show(struct device *dev, \
  1199. struct device_attribute *attr, \
  1200. char *page) \
  1201. { \
  1202. BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
  1203. return sprintf(page, _format "\n"); \
  1204. } \
  1205. \
  1206. static struct device_attribute format_attr_##_name = __ATTR_RO(_name)
  1207. /* Performance counter hotplug functions */
  1208. #ifdef CONFIG_PERF_EVENTS
  1209. int perf_event_init_cpu(unsigned int cpu);
  1210. int perf_event_exit_cpu(unsigned int cpu);
  1211. #else
  1212. #define perf_event_init_cpu NULL
  1213. #define perf_event_exit_cpu NULL
  1214. #endif
  1215. #endif /* _LINUX_PERF_EVENT_H */