perf_event.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. /*
  2. * Performance events:
  3. *
  4. * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
  5. * Copyright (C) 2008-2009, Red Hat, Inc., Ingo Molnar
  6. * Copyright (C) 2008-2009, 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 <linux/types.h>
  17. #include <linux/ioctl.h>
  18. #include <asm/byteorder.h>
  19. /*
  20. * User-space ABI bits:
  21. */
  22. /*
  23. * attr.type
  24. */
  25. enum perf_type_id {
  26. PERF_TYPE_HARDWARE = 0,
  27. PERF_TYPE_SOFTWARE = 1,
  28. PERF_TYPE_TRACEPOINT = 2,
  29. PERF_TYPE_HW_CACHE = 3,
  30. PERF_TYPE_RAW = 4,
  31. PERF_TYPE_MAX, /* non-ABI */
  32. };
  33. /*
  34. * Generalized performance event event_id types, used by the
  35. * attr.event_id parameter of the sys_perf_event_open()
  36. * syscall:
  37. */
  38. enum perf_hw_id {
  39. /*
  40. * Common hardware events, generalized by the kernel:
  41. */
  42. PERF_COUNT_HW_CPU_CYCLES = 0,
  43. PERF_COUNT_HW_INSTRUCTIONS = 1,
  44. PERF_COUNT_HW_CACHE_REFERENCES = 2,
  45. PERF_COUNT_HW_CACHE_MISSES = 3,
  46. PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4,
  47. PERF_COUNT_HW_BRANCH_MISSES = 5,
  48. PERF_COUNT_HW_BUS_CYCLES = 6,
  49. PERF_COUNT_HW_MAX, /* non-ABI */
  50. };
  51. /*
  52. * Generalized hardware cache events:
  53. *
  54. * { L1-D, L1-I, LLC, ITLB, DTLB, BPU } x
  55. * { read, write, prefetch } x
  56. * { accesses, misses }
  57. */
  58. enum perf_hw_cache_id {
  59. PERF_COUNT_HW_CACHE_L1D = 0,
  60. PERF_COUNT_HW_CACHE_L1I = 1,
  61. PERF_COUNT_HW_CACHE_LL = 2,
  62. PERF_COUNT_HW_CACHE_DTLB = 3,
  63. PERF_COUNT_HW_CACHE_ITLB = 4,
  64. PERF_COUNT_HW_CACHE_BPU = 5,
  65. PERF_COUNT_HW_CACHE_MAX, /* non-ABI */
  66. };
  67. enum perf_hw_cache_op_id {
  68. PERF_COUNT_HW_CACHE_OP_READ = 0,
  69. PERF_COUNT_HW_CACHE_OP_WRITE = 1,
  70. PERF_COUNT_HW_CACHE_OP_PREFETCH = 2,
  71. PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */
  72. };
  73. enum perf_hw_cache_op_result_id {
  74. PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0,
  75. PERF_COUNT_HW_CACHE_RESULT_MISS = 1,
  76. PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */
  77. };
  78. /*
  79. * Special "software" events provided by the kernel, even if the hardware
  80. * does not support performance events. These events measure various
  81. * physical and sw events of the kernel (and allow the profiling of them as
  82. * well):
  83. */
  84. enum perf_sw_ids {
  85. PERF_COUNT_SW_CPU_CLOCK = 0,
  86. PERF_COUNT_SW_TASK_CLOCK = 1,
  87. PERF_COUNT_SW_PAGE_FAULTS = 2,
  88. PERF_COUNT_SW_CONTEXT_SWITCHES = 3,
  89. PERF_COUNT_SW_CPU_MIGRATIONS = 4,
  90. PERF_COUNT_SW_PAGE_FAULTS_MIN = 5,
  91. PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6,
  92. PERF_COUNT_SW_MAX, /* non-ABI */
  93. };
  94. /*
  95. * Bits that can be set in attr.sample_type to request information
  96. * in the overflow packets.
  97. */
  98. enum perf_event_sample_format {
  99. PERF_SAMPLE_IP = 1U << 0,
  100. PERF_SAMPLE_TID = 1U << 1,
  101. PERF_SAMPLE_TIME = 1U << 2,
  102. PERF_SAMPLE_ADDR = 1U << 3,
  103. PERF_SAMPLE_READ = 1U << 4,
  104. PERF_SAMPLE_CALLCHAIN = 1U << 5,
  105. PERF_SAMPLE_ID = 1U << 6,
  106. PERF_SAMPLE_CPU = 1U << 7,
  107. PERF_SAMPLE_PERIOD = 1U << 8,
  108. PERF_SAMPLE_STREAM_ID = 1U << 9,
  109. PERF_SAMPLE_RAW = 1U << 10,
  110. PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */
  111. };
  112. /*
  113. * The format of the data returned by read() on a perf event fd,
  114. * as specified by attr.read_format:
  115. *
  116. * struct read_format {
  117. * { u64 value;
  118. * { u64 time_enabled; } && PERF_FORMAT_ENABLED
  119. * { u64 time_running; } && PERF_FORMAT_RUNNING
  120. * { u64 id; } && PERF_FORMAT_ID
  121. * } && !PERF_FORMAT_GROUP
  122. *
  123. * { u64 nr;
  124. * { u64 time_enabled; } && PERF_FORMAT_ENABLED
  125. * { u64 time_running; } && PERF_FORMAT_RUNNING
  126. * { u64 value;
  127. * { u64 id; } && PERF_FORMAT_ID
  128. * } cntr[nr];
  129. * } && PERF_FORMAT_GROUP
  130. * };
  131. */
  132. enum perf_event_read_format {
  133. PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
  134. PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
  135. PERF_FORMAT_ID = 1U << 2,
  136. PERF_FORMAT_GROUP = 1U << 3,
  137. PERF_FORMAT_MAX = 1U << 4, /* non-ABI */
  138. };
  139. #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
  140. /*
  141. * Hardware event_id to monitor via a performance monitoring event:
  142. */
  143. struct perf_event_attr {
  144. /*
  145. * Major type: hardware/software/tracepoint/etc.
  146. */
  147. __u32 type;
  148. /*
  149. * Size of the attr structure, for fwd/bwd compat.
  150. */
  151. __u32 size;
  152. /*
  153. * Type specific configuration information.
  154. */
  155. __u64 config;
  156. union {
  157. __u64 sample_period;
  158. __u64 sample_freq;
  159. };
  160. __u64 sample_type;
  161. __u64 read_format;
  162. __u64 disabled : 1, /* off by default */
  163. inherit : 1, /* children inherit it */
  164. pinned : 1, /* must always be on PMU */
  165. exclusive : 1, /* only group on PMU */
  166. exclude_user : 1, /* don't count user */
  167. exclude_kernel : 1, /* ditto kernel */
  168. exclude_hv : 1, /* ditto hypervisor */
  169. exclude_idle : 1, /* don't count when idle */
  170. mmap : 1, /* include mmap data */
  171. comm : 1, /* include comm data */
  172. freq : 1, /* use freq, not period */
  173. inherit_stat : 1, /* per task counts */
  174. enable_on_exec : 1, /* next exec enables */
  175. task : 1, /* trace fork/exit */
  176. watermark : 1, /* wakeup_watermark */
  177. __reserved_1 : 49;
  178. union {
  179. __u32 wakeup_events; /* wakeup every n events */
  180. __u32 wakeup_watermark; /* bytes before wakeup */
  181. };
  182. __u32 __reserved_2;
  183. __u64 __reserved_3;
  184. };
  185. /*
  186. * Ioctls that can be done on a perf event fd:
  187. */
  188. #define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
  189. #define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
  190. #define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
  191. #define PERF_EVENT_IOC_RESET _IO ('$', 3)
  192. #define PERF_EVENT_IOC_PERIOD _IOW('$', 4, u64)
  193. #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
  194. enum perf_event_ioc_flags {
  195. PERF_IOC_FLAG_GROUP = 1U << 0,
  196. };
  197. /*
  198. * Structure of the page that can be mapped via mmap
  199. */
  200. struct perf_event_mmap_page {
  201. __u32 version; /* version number of this structure */
  202. __u32 compat_version; /* lowest version this is compat with */
  203. /*
  204. * Bits needed to read the hw events in user-space.
  205. *
  206. * u32 seq;
  207. * s64 count;
  208. *
  209. * do {
  210. * seq = pc->lock;
  211. *
  212. * barrier()
  213. * if (pc->index) {
  214. * count = pmc_read(pc->index - 1);
  215. * count += pc->offset;
  216. * } else
  217. * goto regular_read;
  218. *
  219. * barrier();
  220. * } while (pc->lock != seq);
  221. *
  222. * NOTE: for obvious reason this only works on self-monitoring
  223. * processes.
  224. */
  225. __u32 lock; /* seqlock for synchronization */
  226. __u32 index; /* hardware event identifier */
  227. __s64 offset; /* add to hardware event value */
  228. __u64 time_enabled; /* time event active */
  229. __u64 time_running; /* time event on cpu */
  230. /*
  231. * Hole for extension of the self monitor capabilities
  232. */
  233. __u64 __reserved[123]; /* align to 1k */
  234. /*
  235. * Control data for the mmap() data buffer.
  236. *
  237. * User-space reading the @data_head value should issue an rmb(), on
  238. * SMP capable platforms, after reading this value -- see
  239. * perf_event_wakeup().
  240. *
  241. * When the mapping is PROT_WRITE the @data_tail value should be
  242. * written by userspace to reflect the last read data. In this case
  243. * the kernel will not over-write unread data.
  244. */
  245. __u64 data_head; /* head in the data section */
  246. __u64 data_tail; /* user-space written tail */
  247. };
  248. #define PERF_RECORD_MISC_CPUMODE_MASK (3 << 0)
  249. #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0)
  250. #define PERF_RECORD_MISC_KERNEL (1 << 0)
  251. #define PERF_RECORD_MISC_USER (2 << 0)
  252. #define PERF_RECORD_MISC_HYPERVISOR (3 << 0)
  253. struct perf_event_header {
  254. __u32 type;
  255. __u16 misc;
  256. __u16 size;
  257. };
  258. enum perf_event_type {
  259. /*
  260. * The MMAP events record the PROT_EXEC mappings so that we can
  261. * correlate userspace IPs to code. They have the following structure:
  262. *
  263. * struct {
  264. * struct perf_event_header header;
  265. *
  266. * u32 pid, tid;
  267. * u64 addr;
  268. * u64 len;
  269. * u64 pgoff;
  270. * char filename[];
  271. * };
  272. */
  273. PERF_RECORD_MMAP = 1,
  274. /*
  275. * struct {
  276. * struct perf_event_header header;
  277. * u64 id;
  278. * u64 lost;
  279. * };
  280. */
  281. PERF_RECORD_LOST = 2,
  282. /*
  283. * struct {
  284. * struct perf_event_header header;
  285. *
  286. * u32 pid, tid;
  287. * char comm[];
  288. * };
  289. */
  290. PERF_RECORD_COMM = 3,
  291. /*
  292. * struct {
  293. * struct perf_event_header header;
  294. * u32 pid, ppid;
  295. * u32 tid, ptid;
  296. * u64 time;
  297. * };
  298. */
  299. PERF_RECORD_EXIT = 4,
  300. /*
  301. * struct {
  302. * struct perf_event_header header;
  303. * u64 time;
  304. * u64 id;
  305. * u64 stream_id;
  306. * };
  307. */
  308. PERF_RECORD_THROTTLE = 5,
  309. PERF_RECORD_UNTHROTTLE = 6,
  310. /*
  311. * struct {
  312. * struct perf_event_header header;
  313. * u32 pid, ppid;
  314. * u32 tid, ptid;
  315. * u64 time;
  316. * };
  317. */
  318. PERF_RECORD_FORK = 7,
  319. /*
  320. * struct {
  321. * struct perf_event_header header;
  322. * u32 pid, tid;
  323. *
  324. * struct read_format values;
  325. * };
  326. */
  327. PERF_RECORD_READ = 8,
  328. /*
  329. * struct {
  330. * struct perf_event_header header;
  331. *
  332. * { u64 ip; } && PERF_SAMPLE_IP
  333. * { u32 pid, tid; } && PERF_SAMPLE_TID
  334. * { u64 time; } && PERF_SAMPLE_TIME
  335. * { u64 addr; } && PERF_SAMPLE_ADDR
  336. * { u64 id; } && PERF_SAMPLE_ID
  337. * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
  338. * { u32 cpu, res; } && PERF_SAMPLE_CPU
  339. * { u64 period; } && PERF_SAMPLE_PERIOD
  340. *
  341. * { struct read_format values; } && PERF_SAMPLE_READ
  342. *
  343. * { u64 nr,
  344. * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
  345. *
  346. * #
  347. * # The RAW record below is opaque data wrt the ABI
  348. * #
  349. * # That is, the ABI doesn't make any promises wrt to
  350. * # the stability of its content, it may vary depending
  351. * # on event, hardware, kernel version and phase of
  352. * # the moon.
  353. * #
  354. * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
  355. * #
  356. *
  357. * { u32 size;
  358. * char data[size];}&& PERF_SAMPLE_RAW
  359. * };
  360. */
  361. PERF_RECORD_SAMPLE = 9,
  362. PERF_RECORD_MAX, /* non-ABI */
  363. };
  364. enum perf_callchain_context {
  365. PERF_CONTEXT_HV = (__u64)-32,
  366. PERF_CONTEXT_KERNEL = (__u64)-128,
  367. PERF_CONTEXT_USER = (__u64)-512,
  368. PERF_CONTEXT_GUEST = (__u64)-2048,
  369. PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
  370. PERF_CONTEXT_GUEST_USER = (__u64)-2560,
  371. PERF_CONTEXT_MAX = (__u64)-4095,
  372. };
  373. #define PERF_FLAG_FD_NO_GROUP (1U << 0)
  374. #define PERF_FLAG_FD_OUTPUT (1U << 1)
  375. #ifdef __KERNEL__
  376. /*
  377. * Kernel-internal data types and definitions:
  378. */
  379. #ifdef CONFIG_PERF_EVENTS
  380. # include <asm/perf_event.h>
  381. #endif
  382. #include <linux/list.h>
  383. #include <linux/mutex.h>
  384. #include <linux/rculist.h>
  385. #include <linux/rcupdate.h>
  386. #include <linux/spinlock.h>
  387. #include <linux/hrtimer.h>
  388. #include <linux/fs.h>
  389. #include <linux/pid_namespace.h>
  390. #include <asm/atomic.h>
  391. #define PERF_MAX_STACK_DEPTH 255
  392. struct perf_callchain_entry {
  393. __u64 nr;
  394. __u64 ip[PERF_MAX_STACK_DEPTH];
  395. };
  396. struct perf_raw_record {
  397. u32 size;
  398. void *data;
  399. };
  400. struct task_struct;
  401. /**
  402. * struct hw_perf_event - performance event hardware details:
  403. */
  404. struct hw_perf_event {
  405. #ifdef CONFIG_PERF_EVENTS
  406. union {
  407. struct { /* hardware */
  408. u64 config;
  409. unsigned long config_base;
  410. unsigned long event_base;
  411. int idx;
  412. };
  413. union { /* software */
  414. atomic64_t count;
  415. struct hrtimer hrtimer;
  416. };
  417. };
  418. atomic64_t prev_count;
  419. u64 sample_period;
  420. u64 last_period;
  421. atomic64_t period_left;
  422. u64 interrupts;
  423. u64 freq_count;
  424. u64 freq_interrupts;
  425. u64 freq_stamp;
  426. #endif
  427. };
  428. struct perf_event;
  429. /**
  430. * struct pmu - generic performance monitoring unit
  431. */
  432. struct pmu {
  433. int (*enable) (struct perf_event *event);
  434. void (*disable) (struct perf_event *event);
  435. void (*read) (struct perf_event *event);
  436. void (*unthrottle) (struct perf_event *event);
  437. };
  438. /**
  439. * enum perf_event_active_state - the states of a event
  440. */
  441. enum perf_event_active_state {
  442. PERF_EVENT_STATE_ERROR = -2,
  443. PERF_EVENT_STATE_OFF = -1,
  444. PERF_EVENT_STATE_INACTIVE = 0,
  445. PERF_EVENT_STATE_ACTIVE = 1,
  446. };
  447. struct file;
  448. struct perf_mmap_data {
  449. struct rcu_head rcu_head;
  450. int nr_pages; /* nr of data pages */
  451. int writable; /* are we writable */
  452. int nr_locked; /* nr pages mlocked */
  453. atomic_t poll; /* POLL_ for wakeups */
  454. atomic_t events; /* event_id limit */
  455. atomic_long_t head; /* write position */
  456. atomic_long_t done_head; /* completed head */
  457. atomic_t lock; /* concurrent writes */
  458. atomic_t wakeup; /* needs a wakeup */
  459. atomic_t lost; /* nr records lost */
  460. long watermark; /* wakeup watermark */
  461. struct perf_event_mmap_page *user_page;
  462. void *data_pages[0];
  463. };
  464. struct perf_pending_entry {
  465. struct perf_pending_entry *next;
  466. void (*func)(struct perf_pending_entry *);
  467. };
  468. /**
  469. * struct perf_event - performance event kernel representation:
  470. */
  471. struct perf_event {
  472. #ifdef CONFIG_PERF_EVENTS
  473. struct list_head group_entry;
  474. struct list_head event_entry;
  475. struct list_head sibling_list;
  476. int nr_siblings;
  477. struct perf_event *group_leader;
  478. struct perf_event *output;
  479. const struct pmu *pmu;
  480. enum perf_event_active_state state;
  481. atomic64_t count;
  482. /*
  483. * These are the total time in nanoseconds that the event
  484. * has been enabled (i.e. eligible to run, and the task has
  485. * been scheduled in, if this is a per-task event)
  486. * and running (scheduled onto the CPU), respectively.
  487. *
  488. * They are computed from tstamp_enabled, tstamp_running and
  489. * tstamp_stopped when the event is in INACTIVE or ACTIVE state.
  490. */
  491. u64 total_time_enabled;
  492. u64 total_time_running;
  493. /*
  494. * These are timestamps used for computing total_time_enabled
  495. * and total_time_running when the event is in INACTIVE or
  496. * ACTIVE state, measured in nanoseconds from an arbitrary point
  497. * in time.
  498. * tstamp_enabled: the notional time when the event was enabled
  499. * tstamp_running: the notional time when the event was scheduled on
  500. * tstamp_stopped: in INACTIVE state, the notional time when the
  501. * event was scheduled off.
  502. */
  503. u64 tstamp_enabled;
  504. u64 tstamp_running;
  505. u64 tstamp_stopped;
  506. struct perf_event_attr attr;
  507. struct hw_perf_event hw;
  508. struct perf_event_context *ctx;
  509. struct file *filp;
  510. /*
  511. * These accumulate total time (in nanoseconds) that children
  512. * events have been enabled and running, respectively.
  513. */
  514. atomic64_t child_total_time_enabled;
  515. atomic64_t child_total_time_running;
  516. /*
  517. * Protect attach/detach and child_list:
  518. */
  519. struct mutex child_mutex;
  520. struct list_head child_list;
  521. struct perf_event *parent;
  522. int oncpu;
  523. int cpu;
  524. struct list_head owner_entry;
  525. struct task_struct *owner;
  526. /* mmap bits */
  527. struct mutex mmap_mutex;
  528. atomic_t mmap_count;
  529. struct perf_mmap_data *data;
  530. /* poll related */
  531. wait_queue_head_t waitq;
  532. struct fasync_struct *fasync;
  533. /* delayed work for NMIs and such */
  534. int pending_wakeup;
  535. int pending_kill;
  536. int pending_disable;
  537. struct perf_pending_entry pending;
  538. atomic_t event_limit;
  539. void (*destroy)(struct perf_event *);
  540. struct rcu_head rcu_head;
  541. struct pid_namespace *ns;
  542. u64 id;
  543. #endif
  544. };
  545. /**
  546. * struct perf_event_context - event context structure
  547. *
  548. * Used as a container for task events and CPU events as well:
  549. */
  550. struct perf_event_context {
  551. /*
  552. * Protect the states of the events in the list,
  553. * nr_active, and the list:
  554. */
  555. spinlock_t lock;
  556. /*
  557. * Protect the list of events. Locking either mutex or lock
  558. * is sufficient to ensure the list doesn't change; to change
  559. * the list you need to lock both the mutex and the spinlock.
  560. */
  561. struct mutex mutex;
  562. struct list_head group_list;
  563. struct list_head event_list;
  564. int nr_events;
  565. int nr_active;
  566. int is_active;
  567. int nr_stat;
  568. atomic_t refcount;
  569. struct task_struct *task;
  570. /*
  571. * Context clock, runs when context enabled.
  572. */
  573. u64 time;
  574. u64 timestamp;
  575. /*
  576. * These fields let us detect when two contexts have both
  577. * been cloned (inherited) from a common ancestor.
  578. */
  579. struct perf_event_context *parent_ctx;
  580. u64 parent_gen;
  581. u64 generation;
  582. int pin_count;
  583. struct rcu_head rcu_head;
  584. };
  585. /**
  586. * struct perf_event_cpu_context - per cpu event context structure
  587. */
  588. struct perf_cpu_context {
  589. struct perf_event_context ctx;
  590. struct perf_event_context *task_ctx;
  591. int active_oncpu;
  592. int max_pertask;
  593. int exclusive;
  594. /*
  595. * Recursion avoidance:
  596. *
  597. * task, softirq, irq, nmi context
  598. */
  599. int recursion[4];
  600. };
  601. struct perf_output_handle {
  602. struct perf_event *event;
  603. struct perf_mmap_data *data;
  604. unsigned long head;
  605. unsigned long offset;
  606. int nmi;
  607. int sample;
  608. int locked;
  609. unsigned long flags;
  610. };
  611. #ifdef CONFIG_PERF_EVENTS
  612. /*
  613. * Set by architecture code:
  614. */
  615. extern int perf_max_events;
  616. extern const struct pmu *hw_perf_event_init(struct perf_event *event);
  617. extern void perf_event_task_sched_in(struct task_struct *task, int cpu);
  618. extern void perf_event_task_sched_out(struct task_struct *task,
  619. struct task_struct *next, int cpu);
  620. extern void perf_event_task_tick(struct task_struct *task, int cpu);
  621. extern int perf_event_init_task(struct task_struct *child);
  622. extern void perf_event_exit_task(struct task_struct *child);
  623. extern void perf_event_free_task(struct task_struct *task);
  624. extern void set_perf_event_pending(void);
  625. extern void perf_event_do_pending(void);
  626. extern void perf_event_print_debug(void);
  627. extern void __perf_disable(void);
  628. extern bool __perf_enable(void);
  629. extern void perf_disable(void);
  630. extern void perf_enable(void);
  631. extern int perf_event_task_disable(void);
  632. extern int perf_event_task_enable(void);
  633. extern int hw_perf_group_sched_in(struct perf_event *group_leader,
  634. struct perf_cpu_context *cpuctx,
  635. struct perf_event_context *ctx, int cpu);
  636. extern void perf_event_update_userpage(struct perf_event *event);
  637. struct perf_sample_data {
  638. u64 type;
  639. u64 ip;
  640. struct {
  641. u32 pid;
  642. u32 tid;
  643. } tid_entry;
  644. u64 time;
  645. u64 addr;
  646. u64 id;
  647. u64 stream_id;
  648. struct {
  649. u32 cpu;
  650. u32 reserved;
  651. } cpu_entry;
  652. u64 period;
  653. struct perf_callchain_entry *callchain;
  654. struct perf_raw_record *raw;
  655. };
  656. extern void perf_output_sample(struct perf_output_handle *handle,
  657. struct perf_event_header *header,
  658. struct perf_sample_data *data,
  659. struct perf_event *event);
  660. extern void perf_prepare_sample(struct perf_event_header *header,
  661. struct perf_sample_data *data,
  662. struct perf_event *event,
  663. struct pt_regs *regs);
  664. extern int perf_event_overflow(struct perf_event *event, int nmi,
  665. struct perf_sample_data *data,
  666. struct pt_regs *regs);
  667. /*
  668. * Return 1 for a software event, 0 for a hardware event
  669. */
  670. static inline int is_software_event(struct perf_event *event)
  671. {
  672. return (event->attr.type != PERF_TYPE_RAW) &&
  673. (event->attr.type != PERF_TYPE_HARDWARE) &&
  674. (event->attr.type != PERF_TYPE_HW_CACHE);
  675. }
  676. extern atomic_t perf_swevent_enabled[PERF_COUNT_SW_MAX];
  677. extern void __perf_sw_event(u32, u64, int, struct pt_regs *, u64);
  678. static inline void
  679. perf_sw_event(u32 event_id, u64 nr, int nmi, struct pt_regs *regs, u64 addr)
  680. {
  681. if (atomic_read(&perf_swevent_enabled[event_id]))
  682. __perf_sw_event(event_id, nr, nmi, regs, addr);
  683. }
  684. extern void __perf_event_mmap(struct vm_area_struct *vma);
  685. static inline void perf_event_mmap(struct vm_area_struct *vma)
  686. {
  687. if (vma->vm_flags & VM_EXEC)
  688. __perf_event_mmap(vma);
  689. }
  690. extern void perf_event_comm(struct task_struct *tsk);
  691. extern void perf_event_fork(struct task_struct *tsk);
  692. extern struct perf_callchain_entry *perf_callchain(struct pt_regs *regs);
  693. extern int sysctl_perf_event_paranoid;
  694. extern int sysctl_perf_event_mlock;
  695. extern int sysctl_perf_event_sample_rate;
  696. extern void perf_event_init(void);
  697. extern void perf_tp_event(int event_id, u64 addr, u64 count,
  698. void *record, int entry_size);
  699. #ifndef perf_misc_flags
  700. #define perf_misc_flags(regs) (user_mode(regs) ? PERF_RECORD_MISC_USER : \
  701. PERF_RECORD_MISC_KERNEL)
  702. #define perf_instruction_pointer(regs) instruction_pointer(regs)
  703. #endif
  704. extern int perf_output_begin(struct perf_output_handle *handle,
  705. struct perf_event *event, unsigned int size,
  706. int nmi, int sample);
  707. extern void perf_output_end(struct perf_output_handle *handle);
  708. extern void perf_output_copy(struct perf_output_handle *handle,
  709. const void *buf, unsigned int len);
  710. #else
  711. static inline void
  712. perf_event_task_sched_in(struct task_struct *task, int cpu) { }
  713. static inline void
  714. perf_event_task_sched_out(struct task_struct *task,
  715. struct task_struct *next, int cpu) { }
  716. static inline void
  717. perf_event_task_tick(struct task_struct *task, int cpu) { }
  718. static inline int perf_event_init_task(struct task_struct *child) { return 0; }
  719. static inline void perf_event_exit_task(struct task_struct *child) { }
  720. static inline void perf_event_free_task(struct task_struct *task) { }
  721. static inline void perf_event_do_pending(void) { }
  722. static inline void perf_event_print_debug(void) { }
  723. static inline void perf_disable(void) { }
  724. static inline void perf_enable(void) { }
  725. static inline int perf_event_task_disable(void) { return -EINVAL; }
  726. static inline int perf_event_task_enable(void) { return -EINVAL; }
  727. static inline void
  728. perf_sw_event(u32 event_id, u64 nr, int nmi,
  729. struct pt_regs *regs, u64 addr) { }
  730. static inline void perf_event_mmap(struct vm_area_struct *vma) { }
  731. static inline void perf_event_comm(struct task_struct *tsk) { }
  732. static inline void perf_event_fork(struct task_struct *tsk) { }
  733. static inline void perf_event_init(void) { }
  734. #endif
  735. #define perf_output_put(handle, x) \
  736. perf_output_copy((handle), &(x), sizeof(x))
  737. #endif /* __KERNEL__ */
  738. #endif /* _LINUX_PERF_EVENT_H */