perf_event.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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 <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_BREAKPOINT = 5,
  32. PERF_TYPE_MAX, /* non-ABI */
  33. };
  34. /*
  35. * Generalized performance event event_id types, used by the
  36. * attr.event_id parameter of the sys_perf_event_open()
  37. * syscall:
  38. */
  39. enum perf_hw_id {
  40. /*
  41. * Common hardware events, generalized by the kernel:
  42. */
  43. PERF_COUNT_HW_CPU_CYCLES = 0,
  44. PERF_COUNT_HW_INSTRUCTIONS = 1,
  45. PERF_COUNT_HW_CACHE_REFERENCES = 2,
  46. PERF_COUNT_HW_CACHE_MISSES = 3,
  47. PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4,
  48. PERF_COUNT_HW_BRANCH_MISSES = 5,
  49. PERF_COUNT_HW_BUS_CYCLES = 6,
  50. PERF_COUNT_HW_STALLED_CYCLES_FRONTEND = 7,
  51. PERF_COUNT_HW_STALLED_CYCLES_BACKEND = 8,
  52. PERF_COUNT_HW_REF_CPU_CYCLES = 9,
  53. PERF_COUNT_HW_MAX, /* non-ABI */
  54. };
  55. /*
  56. * Generalized hardware cache events:
  57. *
  58. * { L1-D, L1-I, LLC, ITLB, DTLB, BPU, NODE } x
  59. * { read, write, prefetch } x
  60. * { accesses, misses }
  61. */
  62. enum perf_hw_cache_id {
  63. PERF_COUNT_HW_CACHE_L1D = 0,
  64. PERF_COUNT_HW_CACHE_L1I = 1,
  65. PERF_COUNT_HW_CACHE_LL = 2,
  66. PERF_COUNT_HW_CACHE_DTLB = 3,
  67. PERF_COUNT_HW_CACHE_ITLB = 4,
  68. PERF_COUNT_HW_CACHE_BPU = 5,
  69. PERF_COUNT_HW_CACHE_NODE = 6,
  70. PERF_COUNT_HW_CACHE_MAX, /* non-ABI */
  71. };
  72. enum perf_hw_cache_op_id {
  73. PERF_COUNT_HW_CACHE_OP_READ = 0,
  74. PERF_COUNT_HW_CACHE_OP_WRITE = 1,
  75. PERF_COUNT_HW_CACHE_OP_PREFETCH = 2,
  76. PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */
  77. };
  78. enum perf_hw_cache_op_result_id {
  79. PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0,
  80. PERF_COUNT_HW_CACHE_RESULT_MISS = 1,
  81. PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */
  82. };
  83. /*
  84. * Special "software" events provided by the kernel, even if the hardware
  85. * does not support performance events. These events measure various
  86. * physical and sw events of the kernel (and allow the profiling of them as
  87. * well):
  88. */
  89. enum perf_sw_ids {
  90. PERF_COUNT_SW_CPU_CLOCK = 0,
  91. PERF_COUNT_SW_TASK_CLOCK = 1,
  92. PERF_COUNT_SW_PAGE_FAULTS = 2,
  93. PERF_COUNT_SW_CONTEXT_SWITCHES = 3,
  94. PERF_COUNT_SW_CPU_MIGRATIONS = 4,
  95. PERF_COUNT_SW_PAGE_FAULTS_MIN = 5,
  96. PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6,
  97. PERF_COUNT_SW_ALIGNMENT_FAULTS = 7,
  98. PERF_COUNT_SW_EMULATION_FAULTS = 8,
  99. PERF_COUNT_SW_MAX, /* non-ABI */
  100. };
  101. /*
  102. * Bits that can be set in attr.sample_type to request information
  103. * in the overflow packets.
  104. */
  105. enum perf_event_sample_format {
  106. PERF_SAMPLE_IP = 1U << 0,
  107. PERF_SAMPLE_TID = 1U << 1,
  108. PERF_SAMPLE_TIME = 1U << 2,
  109. PERF_SAMPLE_ADDR = 1U << 3,
  110. PERF_SAMPLE_READ = 1U << 4,
  111. PERF_SAMPLE_CALLCHAIN = 1U << 5,
  112. PERF_SAMPLE_ID = 1U << 6,
  113. PERF_SAMPLE_CPU = 1U << 7,
  114. PERF_SAMPLE_PERIOD = 1U << 8,
  115. PERF_SAMPLE_STREAM_ID = 1U << 9,
  116. PERF_SAMPLE_RAW = 1U << 10,
  117. PERF_SAMPLE_BRANCH_STACK = 1U << 11,
  118. PERF_SAMPLE_MAX = 1U << 12, /* non-ABI */
  119. };
  120. /*
  121. * values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set
  122. *
  123. * If the user does not pass priv level information via branch_sample_type,
  124. * the kernel uses the event's priv level. Branch and event priv levels do
  125. * not have to match. Branch priv level is checked for permissions.
  126. *
  127. * The branch types can be combined, however BRANCH_ANY covers all types
  128. * of branches and therefore it supersedes all the other types.
  129. */
  130. enum perf_branch_sample_type {
  131. PERF_SAMPLE_BRANCH_USER = 1U << 0, /* user branches */
  132. PERF_SAMPLE_BRANCH_KERNEL = 1U << 1, /* kernel branches */
  133. PERF_SAMPLE_BRANCH_HV = 1U << 2, /* hypervisor branches */
  134. PERF_SAMPLE_BRANCH_ANY = 1U << 3, /* any branch types */
  135. PERF_SAMPLE_BRANCH_ANY_CALL = 1U << 4, /* any call branch */
  136. PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << 5, /* any return branch */
  137. PERF_SAMPLE_BRANCH_IND_CALL = 1U << 6, /* indirect calls */
  138. PERF_SAMPLE_BRANCH_MAX = 1U << 7, /* non-ABI */
  139. };
  140. #define PERF_SAMPLE_BRANCH_PLM_ALL \
  141. (PERF_SAMPLE_BRANCH_USER|\
  142. PERF_SAMPLE_BRANCH_KERNEL|\
  143. PERF_SAMPLE_BRANCH_HV)
  144. /*
  145. * The format of the data returned by read() on a perf event fd,
  146. * as specified by attr.read_format:
  147. *
  148. * struct read_format {
  149. * { u64 value;
  150. * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED
  151. * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING
  152. * { u64 id; } && PERF_FORMAT_ID
  153. * } && !PERF_FORMAT_GROUP
  154. *
  155. * { u64 nr;
  156. * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED
  157. * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING
  158. * { u64 value;
  159. * { u64 id; } && PERF_FORMAT_ID
  160. * } cntr[nr];
  161. * } && PERF_FORMAT_GROUP
  162. * };
  163. */
  164. enum perf_event_read_format {
  165. PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
  166. PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
  167. PERF_FORMAT_ID = 1U << 2,
  168. PERF_FORMAT_GROUP = 1U << 3,
  169. PERF_FORMAT_MAX = 1U << 4, /* non-ABI */
  170. };
  171. #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
  172. #define PERF_ATTR_SIZE_VER1 72 /* add: config2 */
  173. #define PERF_ATTR_SIZE_VER2 80 /* add: branch_sample_type */
  174. /*
  175. * Hardware event_id to monitor via a performance monitoring event:
  176. */
  177. struct perf_event_attr {
  178. /*
  179. * Major type: hardware/software/tracepoint/etc.
  180. */
  181. __u32 type;
  182. /*
  183. * Size of the attr structure, for fwd/bwd compat.
  184. */
  185. __u32 size;
  186. /*
  187. * Type specific configuration information.
  188. */
  189. __u64 config;
  190. union {
  191. __u64 sample_period;
  192. __u64 sample_freq;
  193. };
  194. __u64 sample_type;
  195. __u64 read_format;
  196. __u64 disabled : 1, /* off by default */
  197. inherit : 1, /* children inherit it */
  198. pinned : 1, /* must always be on PMU */
  199. exclusive : 1, /* only group on PMU */
  200. exclude_user : 1, /* don't count user */
  201. exclude_kernel : 1, /* ditto kernel */
  202. exclude_hv : 1, /* ditto hypervisor */
  203. exclude_idle : 1, /* don't count when idle */
  204. mmap : 1, /* include mmap data */
  205. comm : 1, /* include comm data */
  206. freq : 1, /* use freq, not period */
  207. inherit_stat : 1, /* per task counts */
  208. enable_on_exec : 1, /* next exec enables */
  209. task : 1, /* trace fork/exit */
  210. watermark : 1, /* wakeup_watermark */
  211. /*
  212. * precise_ip:
  213. *
  214. * 0 - SAMPLE_IP can have arbitrary skid
  215. * 1 - SAMPLE_IP must have constant skid
  216. * 2 - SAMPLE_IP requested to have 0 skid
  217. * 3 - SAMPLE_IP must have 0 skid
  218. *
  219. * See also PERF_RECORD_MISC_EXACT_IP
  220. */
  221. precise_ip : 2, /* skid constraint */
  222. mmap_data : 1, /* non-exec mmap data */
  223. sample_id_all : 1, /* sample_type all events */
  224. exclude_host : 1, /* don't count in host */
  225. exclude_guest : 1, /* don't count in guest */
  226. __reserved_1 : 43;
  227. union {
  228. __u32 wakeup_events; /* wakeup every n events */
  229. __u32 wakeup_watermark; /* bytes before wakeup */
  230. };
  231. __u32 bp_type;
  232. union {
  233. __u64 bp_addr;
  234. __u64 config1; /* extension of config */
  235. };
  236. union {
  237. __u64 bp_len;
  238. __u64 config2; /* extension of config1 */
  239. };
  240. __u64 branch_sample_type; /* enum branch_sample_type */
  241. };
  242. /*
  243. * Ioctls that can be done on a perf event fd:
  244. */
  245. #define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
  246. #define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
  247. #define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
  248. #define PERF_EVENT_IOC_RESET _IO ('$', 3)
  249. #define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64)
  250. #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
  251. #define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
  252. enum perf_event_ioc_flags {
  253. PERF_IOC_FLAG_GROUP = 1U << 0,
  254. };
  255. /*
  256. * Structure of the page that can be mapped via mmap
  257. */
  258. struct perf_event_mmap_page {
  259. __u32 version; /* version number of this structure */
  260. __u32 compat_version; /* lowest version this is compat with */
  261. /*
  262. * Bits needed to read the hw events in user-space.
  263. *
  264. * u32 seq;
  265. * s64 count;
  266. *
  267. * do {
  268. * seq = pc->lock;
  269. *
  270. * barrier()
  271. * if (pc->index) {
  272. * count = pmc_read(pc->index - 1);
  273. * count += pc->offset;
  274. * } else
  275. * goto regular_read;
  276. *
  277. * barrier();
  278. * } while (pc->lock != seq);
  279. *
  280. * NOTE: for obvious reason this only works on self-monitoring
  281. * processes.
  282. */
  283. __u32 lock; /* seqlock for synchronization */
  284. __u32 index; /* hardware event identifier */
  285. __s64 offset; /* add to hardware event value */
  286. __u64 time_enabled; /* time event active */
  287. __u64 time_running; /* time event on cpu */
  288. __u32 time_mult, time_shift;
  289. __u64 time_offset;
  290. /*
  291. * Hole for extension of the self monitor capabilities
  292. */
  293. __u64 __reserved[121]; /* align to 1k */
  294. /*
  295. * Control data for the mmap() data buffer.
  296. *
  297. * User-space reading the @data_head value should issue an rmb(), on
  298. * SMP capable platforms, after reading this value -- see
  299. * perf_event_wakeup().
  300. *
  301. * When the mapping is PROT_WRITE the @data_tail value should be
  302. * written by userspace to reflect the last read data. In this case
  303. * the kernel will not over-write unread data.
  304. */
  305. __u64 data_head; /* head in the data section */
  306. __u64 data_tail; /* user-space written tail */
  307. };
  308. #define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
  309. #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0)
  310. #define PERF_RECORD_MISC_KERNEL (1 << 0)
  311. #define PERF_RECORD_MISC_USER (2 << 0)
  312. #define PERF_RECORD_MISC_HYPERVISOR (3 << 0)
  313. #define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0)
  314. #define PERF_RECORD_MISC_GUEST_USER (5 << 0)
  315. /*
  316. * Indicates that the content of PERF_SAMPLE_IP points to
  317. * the actual instruction that triggered the event. See also
  318. * perf_event_attr::precise_ip.
  319. */
  320. #define PERF_RECORD_MISC_EXACT_IP (1 << 14)
  321. /*
  322. * Reserve the last bit to indicate some extended misc field
  323. */
  324. #define PERF_RECORD_MISC_EXT_RESERVED (1 << 15)
  325. struct perf_event_header {
  326. __u32 type;
  327. __u16 misc;
  328. __u16 size;
  329. };
  330. enum perf_event_type {
  331. /*
  332. * If perf_event_attr.sample_id_all is set then all event types will
  333. * have the sample_type selected fields related to where/when
  334. * (identity) an event took place (TID, TIME, ID, CPU, STREAM_ID)
  335. * described in PERF_RECORD_SAMPLE below, it will be stashed just after
  336. * the perf_event_header and the fields already present for the existing
  337. * fields, i.e. at the end of the payload. That way a newer perf.data
  338. * file will be supported by older perf tools, with these new optional
  339. * fields being ignored.
  340. *
  341. * The MMAP events record the PROT_EXEC mappings so that we can
  342. * correlate userspace IPs to code. They have the following structure:
  343. *
  344. * struct {
  345. * struct perf_event_header header;
  346. *
  347. * u32 pid, tid;
  348. * u64 addr;
  349. * u64 len;
  350. * u64 pgoff;
  351. * char filename[];
  352. * };
  353. */
  354. PERF_RECORD_MMAP = 1,
  355. /*
  356. * struct {
  357. * struct perf_event_header header;
  358. * u64 id;
  359. * u64 lost;
  360. * };
  361. */
  362. PERF_RECORD_LOST = 2,
  363. /*
  364. * struct {
  365. * struct perf_event_header header;
  366. *
  367. * u32 pid, tid;
  368. * char comm[];
  369. * };
  370. */
  371. PERF_RECORD_COMM = 3,
  372. /*
  373. * struct {
  374. * struct perf_event_header header;
  375. * u32 pid, ppid;
  376. * u32 tid, ptid;
  377. * u64 time;
  378. * };
  379. */
  380. PERF_RECORD_EXIT = 4,
  381. /*
  382. * struct {
  383. * struct perf_event_header header;
  384. * u64 time;
  385. * u64 id;
  386. * u64 stream_id;
  387. * };
  388. */
  389. PERF_RECORD_THROTTLE = 5,
  390. PERF_RECORD_UNTHROTTLE = 6,
  391. /*
  392. * struct {
  393. * struct perf_event_header header;
  394. * u32 pid, ppid;
  395. * u32 tid, ptid;
  396. * u64 time;
  397. * };
  398. */
  399. PERF_RECORD_FORK = 7,
  400. /*
  401. * struct {
  402. * struct perf_event_header header;
  403. * u32 pid, tid;
  404. *
  405. * struct read_format values;
  406. * };
  407. */
  408. PERF_RECORD_READ = 8,
  409. /*
  410. * struct {
  411. * struct perf_event_header header;
  412. *
  413. * { u64 ip; } && PERF_SAMPLE_IP
  414. * { u32 pid, tid; } && PERF_SAMPLE_TID
  415. * { u64 time; } && PERF_SAMPLE_TIME
  416. * { u64 addr; } && PERF_SAMPLE_ADDR
  417. * { u64 id; } && PERF_SAMPLE_ID
  418. * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
  419. * { u32 cpu, res; } && PERF_SAMPLE_CPU
  420. * { u64 period; } && PERF_SAMPLE_PERIOD
  421. *
  422. * { struct read_format values; } && PERF_SAMPLE_READ
  423. *
  424. * { u64 nr,
  425. * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
  426. *
  427. * #
  428. * # The RAW record below is opaque data wrt the ABI
  429. * #
  430. * # That is, the ABI doesn't make any promises wrt to
  431. * # the stability of its content, it may vary depending
  432. * # on event, hardware, kernel version and phase of
  433. * # the moon.
  434. * #
  435. * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
  436. * #
  437. *
  438. * { u32 size;
  439. * char data[size];}&& PERF_SAMPLE_RAW
  440. *
  441. * { u64 from, to, flags } lbr[nr];} && PERF_SAMPLE_BRANCH_STACK
  442. * };
  443. */
  444. PERF_RECORD_SAMPLE = 9,
  445. PERF_RECORD_MAX, /* non-ABI */
  446. };
  447. enum perf_callchain_context {
  448. PERF_CONTEXT_HV = (__u64)-32,
  449. PERF_CONTEXT_KERNEL = (__u64)-128,
  450. PERF_CONTEXT_USER = (__u64)-512,
  451. PERF_CONTEXT_GUEST = (__u64)-2048,
  452. PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
  453. PERF_CONTEXT_GUEST_USER = (__u64)-2560,
  454. PERF_CONTEXT_MAX = (__u64)-4095,
  455. };
  456. #define PERF_FLAG_FD_NO_GROUP (1U << 0)
  457. #define PERF_FLAG_FD_OUTPUT (1U << 1)
  458. #define PERF_FLAG_PID_CGROUP (1U << 2) /* pid=cgroup id, per-cpu mode only */
  459. #ifdef __KERNEL__
  460. /*
  461. * Kernel-internal data types and definitions:
  462. */
  463. #ifdef CONFIG_PERF_EVENTS
  464. # include <linux/cgroup.h>
  465. # include <asm/perf_event.h>
  466. # include <asm/local64.h>
  467. #endif
  468. struct perf_guest_info_callbacks {
  469. int (*is_in_guest)(void);
  470. int (*is_user_mode)(void);
  471. unsigned long (*get_guest_ip)(void);
  472. };
  473. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  474. #include <asm/hw_breakpoint.h>
  475. #endif
  476. #include <linux/list.h>
  477. #include <linux/mutex.h>
  478. #include <linux/rculist.h>
  479. #include <linux/rcupdate.h>
  480. #include <linux/spinlock.h>
  481. #include <linux/hrtimer.h>
  482. #include <linux/fs.h>
  483. #include <linux/pid_namespace.h>
  484. #include <linux/workqueue.h>
  485. #include <linux/ftrace.h>
  486. #include <linux/cpu.h>
  487. #include <linux/irq_work.h>
  488. #include <linux/static_key.h>
  489. #include <linux/atomic.h>
  490. #include <linux/sysfs.h>
  491. #include <asm/local.h>
  492. #define PERF_MAX_STACK_DEPTH 255
  493. struct perf_callchain_entry {
  494. __u64 nr;
  495. __u64 ip[PERF_MAX_STACK_DEPTH];
  496. };
  497. struct perf_raw_record {
  498. u32 size;
  499. void *data;
  500. };
  501. /*
  502. * single taken branch record layout:
  503. *
  504. * from: source instruction (may not always be a branch insn)
  505. * to: branch target
  506. * mispred: branch target was mispredicted
  507. * predicted: branch target was predicted
  508. *
  509. * support for mispred, predicted is optional. In case it
  510. * is not supported mispred = predicted = 0.
  511. */
  512. struct perf_branch_entry {
  513. __u64 from;
  514. __u64 to;
  515. __u64 mispred:1, /* target mispredicted */
  516. predicted:1,/* target predicted */
  517. reserved:62;
  518. };
  519. /*
  520. * branch stack layout:
  521. * nr: number of taken branches stored in entries[]
  522. *
  523. * Note that nr can vary from sample to sample
  524. * branches (to, from) are stored from most recent
  525. * to least recent, i.e., entries[0] contains the most
  526. * recent branch.
  527. */
  528. struct perf_branch_stack {
  529. __u64 nr;
  530. struct perf_branch_entry entries[0];
  531. };
  532. struct task_struct;
  533. /*
  534. * extra PMU register associated with an event
  535. */
  536. struct hw_perf_event_extra {
  537. u64 config; /* register value */
  538. unsigned int reg; /* register address or index */
  539. int alloc; /* extra register already allocated */
  540. int idx; /* index in shared_regs->regs[] */
  541. };
  542. /**
  543. * struct hw_perf_event - performance event hardware details:
  544. */
  545. struct hw_perf_event {
  546. #ifdef CONFIG_PERF_EVENTS
  547. union {
  548. struct { /* hardware */
  549. u64 config;
  550. u64 last_tag;
  551. unsigned long config_base;
  552. unsigned long event_base;
  553. int idx;
  554. int last_cpu;
  555. struct hw_perf_event_extra extra_reg;
  556. struct hw_perf_event_extra branch_reg;
  557. };
  558. struct { /* software */
  559. struct hrtimer hrtimer;
  560. };
  561. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  562. struct { /* breakpoint */
  563. struct arch_hw_breakpoint info;
  564. struct list_head bp_list;
  565. /*
  566. * Crufty hack to avoid the chicken and egg
  567. * problem hw_breakpoint has with context
  568. * creation and event initalization.
  569. */
  570. struct task_struct *bp_target;
  571. };
  572. #endif
  573. };
  574. int state;
  575. local64_t prev_count;
  576. u64 sample_period;
  577. u64 last_period;
  578. local64_t period_left;
  579. u64 interrupts_seq;
  580. u64 interrupts;
  581. u64 freq_time_stamp;
  582. u64 freq_count_stamp;
  583. #endif
  584. };
  585. /*
  586. * hw_perf_event::state flags
  587. */
  588. #define PERF_HES_STOPPED 0x01 /* the counter is stopped */
  589. #define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
  590. #define PERF_HES_ARCH 0x04
  591. struct perf_event;
  592. /*
  593. * Common implementation detail of pmu::{start,commit,cancel}_txn
  594. */
  595. #define PERF_EVENT_TXN 0x1
  596. /**
  597. * struct pmu - generic performance monitoring unit
  598. */
  599. struct pmu {
  600. struct list_head entry;
  601. struct device *dev;
  602. const struct attribute_group **attr_groups;
  603. char *name;
  604. int type;
  605. int * __percpu pmu_disable_count;
  606. struct perf_cpu_context * __percpu pmu_cpu_context;
  607. int task_ctx_nr;
  608. /*
  609. * Fully disable/enable this PMU, can be used to protect from the PMI
  610. * as well as for lazy/batch writing of the MSRs.
  611. */
  612. void (*pmu_enable) (struct pmu *pmu); /* optional */
  613. void (*pmu_disable) (struct pmu *pmu); /* optional */
  614. /*
  615. * Try and initialize the event for this PMU.
  616. * Should return -ENOENT when the @event doesn't match this PMU.
  617. */
  618. int (*event_init) (struct perf_event *event);
  619. #define PERF_EF_START 0x01 /* start the counter when adding */
  620. #define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
  621. #define PERF_EF_UPDATE 0x04 /* update the counter when stopping */
  622. /*
  623. * Adds/Removes a counter to/from the PMU, can be done inside
  624. * a transaction, see the ->*_txn() methods.
  625. */
  626. int (*add) (struct perf_event *event, int flags);
  627. void (*del) (struct perf_event *event, int flags);
  628. /*
  629. * Starts/Stops a counter present on the PMU. The PMI handler
  630. * should stop the counter when perf_event_overflow() returns
  631. * !0. ->start() will be used to continue.
  632. */
  633. void (*start) (struct perf_event *event, int flags);
  634. void (*stop) (struct perf_event *event, int flags);
  635. /*
  636. * Updates the counter value of the event.
  637. */
  638. void (*read) (struct perf_event *event);
  639. /*
  640. * Group events scheduling is treated as a transaction, add
  641. * group events as a whole and perform one schedulability test.
  642. * If the test fails, roll back the whole group
  643. *
  644. * Start the transaction, after this ->add() doesn't need to
  645. * do schedulability tests.
  646. */
  647. void (*start_txn) (struct pmu *pmu); /* optional */
  648. /*
  649. * If ->start_txn() disabled the ->add() schedulability test
  650. * then ->commit_txn() is required to perform one. On success
  651. * the transaction is closed. On error the transaction is kept
  652. * open until ->cancel_txn() is called.
  653. */
  654. int (*commit_txn) (struct pmu *pmu); /* optional */
  655. /*
  656. * Will cancel the transaction, assumes ->del() is called
  657. * for each successful ->add() during the transaction.
  658. */
  659. void (*cancel_txn) (struct pmu *pmu); /* optional */
  660. /*
  661. * Will return the value for perf_event_mmap_page::index for this event,
  662. * if no implementation is provided it will default to: event->hw.idx + 1.
  663. */
  664. int (*event_idx) (struct perf_event *event); /*optional */
  665. /*
  666. * flush branch stack on context-switches (needed in cpu-wide mode)
  667. */
  668. void (*flush_branch_stack) (void);
  669. };
  670. /**
  671. * enum perf_event_active_state - the states of a event
  672. */
  673. enum perf_event_active_state {
  674. PERF_EVENT_STATE_ERROR = -2,
  675. PERF_EVENT_STATE_OFF = -1,
  676. PERF_EVENT_STATE_INACTIVE = 0,
  677. PERF_EVENT_STATE_ACTIVE = 1,
  678. };
  679. struct file;
  680. struct perf_sample_data;
  681. typedef void (*perf_overflow_handler_t)(struct perf_event *,
  682. struct perf_sample_data *,
  683. struct pt_regs *regs);
  684. enum perf_group_flag {
  685. PERF_GROUP_SOFTWARE = 0x1,
  686. };
  687. #define SWEVENT_HLIST_BITS 8
  688. #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)
  689. struct swevent_hlist {
  690. struct hlist_head heads[SWEVENT_HLIST_SIZE];
  691. struct rcu_head rcu_head;
  692. };
  693. #define PERF_ATTACH_CONTEXT 0x01
  694. #define PERF_ATTACH_GROUP 0x02
  695. #define PERF_ATTACH_TASK 0x04
  696. #ifdef CONFIG_CGROUP_PERF
  697. /*
  698. * perf_cgroup_info keeps track of time_enabled for a cgroup.
  699. * This is a per-cpu dynamically allocated data structure.
  700. */
  701. struct perf_cgroup_info {
  702. u64 time;
  703. u64 timestamp;
  704. };
  705. struct perf_cgroup {
  706. struct cgroup_subsys_state css;
  707. struct perf_cgroup_info *info; /* timing info, one per cpu */
  708. };
  709. #endif
  710. struct ring_buffer;
  711. /**
  712. * struct perf_event - performance event kernel representation:
  713. */
  714. struct perf_event {
  715. #ifdef CONFIG_PERF_EVENTS
  716. struct list_head group_entry;
  717. struct list_head event_entry;
  718. struct list_head sibling_list;
  719. struct hlist_node hlist_entry;
  720. int nr_siblings;
  721. int group_flags;
  722. struct perf_event *group_leader;
  723. struct pmu *pmu;
  724. enum perf_event_active_state state;
  725. unsigned int attach_state;
  726. local64_t count;
  727. atomic64_t child_count;
  728. /*
  729. * These are the total time in nanoseconds that the event
  730. * has been enabled (i.e. eligible to run, and the task has
  731. * been scheduled in, if this is a per-task event)
  732. * and running (scheduled onto the CPU), respectively.
  733. *
  734. * They are computed from tstamp_enabled, tstamp_running and
  735. * tstamp_stopped when the event is in INACTIVE or ACTIVE state.
  736. */
  737. u64 total_time_enabled;
  738. u64 total_time_running;
  739. /*
  740. * These are timestamps used for computing total_time_enabled
  741. * and total_time_running when the event is in INACTIVE or
  742. * ACTIVE state, measured in nanoseconds from an arbitrary point
  743. * in time.
  744. * tstamp_enabled: the notional time when the event was enabled
  745. * tstamp_running: the notional time when the event was scheduled on
  746. * tstamp_stopped: in INACTIVE state, the notional time when the
  747. * event was scheduled off.
  748. */
  749. u64 tstamp_enabled;
  750. u64 tstamp_running;
  751. u64 tstamp_stopped;
  752. /*
  753. * timestamp shadows the actual context timing but it can
  754. * be safely used in NMI interrupt context. It reflects the
  755. * context time as it was when the event was last scheduled in.
  756. *
  757. * ctx_time already accounts for ctx->timestamp. Therefore to
  758. * compute ctx_time for a sample, simply add perf_clock().
  759. */
  760. u64 shadow_ctx_time;
  761. struct perf_event_attr attr;
  762. u16 header_size;
  763. u16 id_header_size;
  764. u16 read_size;
  765. struct hw_perf_event hw;
  766. struct perf_event_context *ctx;
  767. struct file *filp;
  768. /*
  769. * These accumulate total time (in nanoseconds) that children
  770. * events have been enabled and running, respectively.
  771. */
  772. atomic64_t child_total_time_enabled;
  773. atomic64_t child_total_time_running;
  774. /*
  775. * Protect attach/detach and child_list:
  776. */
  777. struct mutex child_mutex;
  778. struct list_head child_list;
  779. struct perf_event *parent;
  780. int oncpu;
  781. int cpu;
  782. struct list_head owner_entry;
  783. struct task_struct *owner;
  784. /* mmap bits */
  785. struct mutex mmap_mutex;
  786. atomic_t mmap_count;
  787. int mmap_locked;
  788. struct user_struct *mmap_user;
  789. struct ring_buffer *rb;
  790. struct list_head rb_entry;
  791. /* poll related */
  792. wait_queue_head_t waitq;
  793. struct fasync_struct *fasync;
  794. /* delayed work for NMIs and such */
  795. int pending_wakeup;
  796. int pending_kill;
  797. int pending_disable;
  798. struct irq_work pending;
  799. atomic_t event_limit;
  800. void (*destroy)(struct perf_event *);
  801. struct rcu_head rcu_head;
  802. struct pid_namespace *ns;
  803. u64 id;
  804. perf_overflow_handler_t overflow_handler;
  805. void *overflow_handler_context;
  806. #ifdef CONFIG_EVENT_TRACING
  807. struct ftrace_event_call *tp_event;
  808. struct event_filter *filter;
  809. #ifdef CONFIG_FUNCTION_TRACER
  810. struct ftrace_ops ftrace_ops;
  811. #endif
  812. #endif
  813. #ifdef CONFIG_CGROUP_PERF
  814. struct perf_cgroup *cgrp; /* cgroup event is attach to */
  815. int cgrp_defer_enabled;
  816. #endif
  817. #endif /* CONFIG_PERF_EVENTS */
  818. };
  819. enum perf_event_context_type {
  820. task_context,
  821. cpu_context,
  822. };
  823. /**
  824. * struct perf_event_context - event context structure
  825. *
  826. * Used as a container for task events and CPU events as well:
  827. */
  828. struct perf_event_context {
  829. struct pmu *pmu;
  830. enum perf_event_context_type type;
  831. /*
  832. * Protect the states of the events in the list,
  833. * nr_active, and the list:
  834. */
  835. raw_spinlock_t lock;
  836. /*
  837. * Protect the list of events. Locking either mutex or lock
  838. * is sufficient to ensure the list doesn't change; to change
  839. * the list you need to lock both the mutex and the spinlock.
  840. */
  841. struct mutex mutex;
  842. struct list_head pinned_groups;
  843. struct list_head flexible_groups;
  844. struct list_head event_list;
  845. int nr_events;
  846. int nr_active;
  847. int is_active;
  848. int nr_stat;
  849. int nr_freq;
  850. int rotate_disable;
  851. atomic_t refcount;
  852. struct task_struct *task;
  853. /*
  854. * Context clock, runs when context enabled.
  855. */
  856. u64 time;
  857. u64 timestamp;
  858. /*
  859. * These fields let us detect when two contexts have both
  860. * been cloned (inherited) from a common ancestor.
  861. */
  862. struct perf_event_context *parent_ctx;
  863. u64 parent_gen;
  864. u64 generation;
  865. int pin_count;
  866. int nr_cgroups; /* cgroup evts */
  867. int nr_branch_stack; /* branch_stack evt */
  868. struct rcu_head rcu_head;
  869. };
  870. /*
  871. * Number of contexts where an event can trigger:
  872. * task, softirq, hardirq, nmi.
  873. */
  874. #define PERF_NR_CONTEXTS 4
  875. /**
  876. * struct perf_event_cpu_context - per cpu event context structure
  877. */
  878. struct perf_cpu_context {
  879. struct perf_event_context ctx;
  880. struct perf_event_context *task_ctx;
  881. int active_oncpu;
  882. int exclusive;
  883. struct list_head rotation_list;
  884. int jiffies_interval;
  885. struct pmu *active_pmu;
  886. struct perf_cgroup *cgrp;
  887. };
  888. struct perf_output_handle {
  889. struct perf_event *event;
  890. struct ring_buffer *rb;
  891. unsigned long wakeup;
  892. unsigned long size;
  893. void *addr;
  894. int page;
  895. };
  896. #ifdef CONFIG_PERF_EVENTS
  897. extern int perf_pmu_register(struct pmu *pmu, char *name, int type);
  898. extern void perf_pmu_unregister(struct pmu *pmu);
  899. extern int perf_num_counters(void);
  900. extern const char *perf_pmu_name(void);
  901. extern void __perf_event_task_sched_in(struct task_struct *prev,
  902. struct task_struct *task);
  903. extern void __perf_event_task_sched_out(struct task_struct *prev,
  904. struct task_struct *next);
  905. extern int perf_event_init_task(struct task_struct *child);
  906. extern void perf_event_exit_task(struct task_struct *child);
  907. extern void perf_event_free_task(struct task_struct *task);
  908. extern void perf_event_delayed_put(struct task_struct *task);
  909. extern void perf_event_print_debug(void);
  910. extern void perf_pmu_disable(struct pmu *pmu);
  911. extern void perf_pmu_enable(struct pmu *pmu);
  912. extern int perf_event_task_disable(void);
  913. extern int perf_event_task_enable(void);
  914. extern int perf_event_refresh(struct perf_event *event, int refresh);
  915. extern void perf_event_update_userpage(struct perf_event *event);
  916. extern int perf_event_release_kernel(struct perf_event *event);
  917. extern struct perf_event *
  918. perf_event_create_kernel_counter(struct perf_event_attr *attr,
  919. int cpu,
  920. struct task_struct *task,
  921. perf_overflow_handler_t callback,
  922. void *context);
  923. extern u64 perf_event_read_value(struct perf_event *event,
  924. u64 *enabled, u64 *running);
  925. struct perf_sample_data {
  926. u64 type;
  927. u64 ip;
  928. struct {
  929. u32 pid;
  930. u32 tid;
  931. } tid_entry;
  932. u64 time;
  933. u64 addr;
  934. u64 id;
  935. u64 stream_id;
  936. struct {
  937. u32 cpu;
  938. u32 reserved;
  939. } cpu_entry;
  940. u64 period;
  941. struct perf_callchain_entry *callchain;
  942. struct perf_raw_record *raw;
  943. struct perf_branch_stack *br_stack;
  944. };
  945. static inline void perf_sample_data_init(struct perf_sample_data *data, u64 addr)
  946. {
  947. data->addr = addr;
  948. data->raw = NULL;
  949. data->br_stack = NULL;
  950. }
  951. extern void perf_output_sample(struct perf_output_handle *handle,
  952. struct perf_event_header *header,
  953. struct perf_sample_data *data,
  954. struct perf_event *event);
  955. extern void perf_prepare_sample(struct perf_event_header *header,
  956. struct perf_sample_data *data,
  957. struct perf_event *event,
  958. struct pt_regs *regs);
  959. extern int perf_event_overflow(struct perf_event *event,
  960. struct perf_sample_data *data,
  961. struct pt_regs *regs);
  962. static inline bool is_sampling_event(struct perf_event *event)
  963. {
  964. return event->attr.sample_period != 0;
  965. }
  966. /*
  967. * Return 1 for a software event, 0 for a hardware event
  968. */
  969. static inline int is_software_event(struct perf_event *event)
  970. {
  971. return event->pmu->task_ctx_nr == perf_sw_context;
  972. }
  973. extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX];
  974. extern void __perf_sw_event(u32, u64, struct pt_regs *, u64);
  975. #ifndef perf_arch_fetch_caller_regs
  976. static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip) { }
  977. #endif
  978. /*
  979. * Take a snapshot of the regs. Skip ip and frame pointer to
  980. * the nth caller. We only need a few of the regs:
  981. * - ip for PERF_SAMPLE_IP
  982. * - cs for user_mode() tests
  983. * - bp for callchains
  984. * - eflags, for future purposes, just in case
  985. */
  986. static inline void perf_fetch_caller_regs(struct pt_regs *regs)
  987. {
  988. memset(regs, 0, sizeof(*regs));
  989. perf_arch_fetch_caller_regs(regs, CALLER_ADDR0);
  990. }
  991. static __always_inline void
  992. perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
  993. {
  994. struct pt_regs hot_regs;
  995. if (static_key_false(&perf_swevent_enabled[event_id])) {
  996. if (!regs) {
  997. perf_fetch_caller_regs(&hot_regs);
  998. regs = &hot_regs;
  999. }
  1000. __perf_sw_event(event_id, nr, regs, addr);
  1001. }
  1002. }
  1003. extern struct static_key_deferred perf_sched_events;
  1004. static inline void perf_event_task_sched_in(struct task_struct *prev,
  1005. struct task_struct *task)
  1006. {
  1007. if (static_key_false(&perf_sched_events.key))
  1008. __perf_event_task_sched_in(prev, task);
  1009. }
  1010. static inline void perf_event_task_sched_out(struct task_struct *prev,
  1011. struct task_struct *next)
  1012. {
  1013. perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, NULL, 0);
  1014. if (static_key_false(&perf_sched_events.key))
  1015. __perf_event_task_sched_out(prev, next);
  1016. }
  1017. extern void perf_event_mmap(struct vm_area_struct *vma);
  1018. extern struct perf_guest_info_callbacks *perf_guest_cbs;
  1019. extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
  1020. extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
  1021. extern void perf_event_comm(struct task_struct *tsk);
  1022. extern void perf_event_fork(struct task_struct *tsk);
  1023. /* Callchains */
  1024. DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry);
  1025. extern void perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs);
  1026. extern void perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs);
  1027. static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64 ip)
  1028. {
  1029. if (entry->nr < PERF_MAX_STACK_DEPTH)
  1030. entry->ip[entry->nr++] = ip;
  1031. }
  1032. extern int sysctl_perf_event_paranoid;
  1033. extern int sysctl_perf_event_mlock;
  1034. extern int sysctl_perf_event_sample_rate;
  1035. extern int perf_proc_update_handler(struct ctl_table *table, int write,
  1036. void __user *buffer, size_t *lenp,
  1037. loff_t *ppos);
  1038. static inline bool perf_paranoid_tracepoint_raw(void)
  1039. {
  1040. return sysctl_perf_event_paranoid > -1;
  1041. }
  1042. static inline bool perf_paranoid_cpu(void)
  1043. {
  1044. return sysctl_perf_event_paranoid > 0;
  1045. }
  1046. static inline bool perf_paranoid_kernel(void)
  1047. {
  1048. return sysctl_perf_event_paranoid > 1;
  1049. }
  1050. extern void perf_event_init(void);
  1051. extern void perf_tp_event(u64 addr, u64 count, void *record,
  1052. int entry_size, struct pt_regs *regs,
  1053. struct hlist_head *head, int rctx);
  1054. extern void perf_bp_event(struct perf_event *event, void *data);
  1055. #ifndef perf_misc_flags
  1056. # define perf_misc_flags(regs) \
  1057. (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
  1058. # define perf_instruction_pointer(regs) instruction_pointer(regs)
  1059. #endif
  1060. static inline bool has_branch_stack(struct perf_event *event)
  1061. {
  1062. return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
  1063. }
  1064. extern int perf_output_begin(struct perf_output_handle *handle,
  1065. struct perf_event *event, unsigned int size);
  1066. extern void perf_output_end(struct perf_output_handle *handle);
  1067. extern void perf_output_copy(struct perf_output_handle *handle,
  1068. const void *buf, unsigned int len);
  1069. extern int perf_swevent_get_recursion_context(void);
  1070. extern void perf_swevent_put_recursion_context(int rctx);
  1071. extern void perf_event_enable(struct perf_event *event);
  1072. extern void perf_event_disable(struct perf_event *event);
  1073. extern void perf_event_task_tick(void);
  1074. #else
  1075. static inline void
  1076. perf_event_task_sched_in(struct task_struct *prev,
  1077. struct task_struct *task) { }
  1078. static inline void
  1079. perf_event_task_sched_out(struct task_struct *prev,
  1080. struct task_struct *next) { }
  1081. static inline int perf_event_init_task(struct task_struct *child) { return 0; }
  1082. static inline void perf_event_exit_task(struct task_struct *child) { }
  1083. static inline void perf_event_free_task(struct task_struct *task) { }
  1084. static inline void perf_event_delayed_put(struct task_struct *task) { }
  1085. static inline void perf_event_print_debug(void) { }
  1086. static inline int perf_event_task_disable(void) { return -EINVAL; }
  1087. static inline int perf_event_task_enable(void) { return -EINVAL; }
  1088. static inline int perf_event_refresh(struct perf_event *event, int refresh)
  1089. {
  1090. return -EINVAL;
  1091. }
  1092. static inline void
  1093. perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { }
  1094. static inline void
  1095. perf_bp_event(struct perf_event *event, void *data) { }
  1096. static inline int perf_register_guest_info_callbacks
  1097. (struct perf_guest_info_callbacks *callbacks) { return 0; }
  1098. static inline int perf_unregister_guest_info_callbacks
  1099. (struct perf_guest_info_callbacks *callbacks) { return 0; }
  1100. static inline void perf_event_mmap(struct vm_area_struct *vma) { }
  1101. static inline void perf_event_comm(struct task_struct *tsk) { }
  1102. static inline void perf_event_fork(struct task_struct *tsk) { }
  1103. static inline void perf_event_init(void) { }
  1104. static inline int perf_swevent_get_recursion_context(void) { return -1; }
  1105. static inline void perf_swevent_put_recursion_context(int rctx) { }
  1106. static inline void perf_event_enable(struct perf_event *event) { }
  1107. static inline void perf_event_disable(struct perf_event *event) { }
  1108. static inline void perf_event_task_tick(void) { }
  1109. #endif
  1110. #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
  1111. /*
  1112. * This has to have a higher priority than migration_notifier in sched.c.
  1113. */
  1114. #define perf_cpu_notifier(fn) \
  1115. do { \
  1116. static struct notifier_block fn##_nb __cpuinitdata = \
  1117. { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
  1118. fn(&fn##_nb, (unsigned long)CPU_UP_PREPARE, \
  1119. (void *)(unsigned long)smp_processor_id()); \
  1120. fn(&fn##_nb, (unsigned long)CPU_STARTING, \
  1121. (void *)(unsigned long)smp_processor_id()); \
  1122. fn(&fn##_nb, (unsigned long)CPU_ONLINE, \
  1123. (void *)(unsigned long)smp_processor_id()); \
  1124. register_cpu_notifier(&fn##_nb); \
  1125. } while (0)
  1126. #define PMU_FORMAT_ATTR(_name, _format) \
  1127. static ssize_t \
  1128. _name##_show(struct device *dev, \
  1129. struct device_attribute *attr, \
  1130. char *page) \
  1131. { \
  1132. BUILD_BUG_ON(sizeof(_format) >= PAGE_SIZE); \
  1133. return sprintf(page, _format "\n"); \
  1134. } \
  1135. \
  1136. static struct device_attribute format_attr_##_name = __ATTR_RO(_name)
  1137. #endif /* __KERNEL__ */
  1138. #endif /* _LINUX_PERF_EVENT_H */