perf_event.h 39 KB

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