perf_event.h 39 KB

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