perf_event.h 38 KB

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