perf_event.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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. constraint_duplicate : 1,
  227. __reserved_1 : 42;
  228. union {
  229. __u32 wakeup_events; /* wakeup every n events */
  230. __u32 wakeup_watermark; /* bytes before wakeup */
  231. };
  232. __u32 bp_type;
  233. union {
  234. __u64 bp_addr;
  235. __u64 config1; /* extension of config */
  236. };
  237. union {
  238. __u64 bp_len;
  239. __u64 config2; /* extension of config1 */
  240. };
  241. __u64 branch_sample_type; /* enum branch_sample_type */
  242. };
  243. /*
  244. * Ioctls that can be done on a perf event fd:
  245. */
  246. #define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
  247. #define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
  248. #define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
  249. #define PERF_EVENT_IOC_RESET _IO ('$', 3)
  250. #define PERF_EVENT_IOC_PERIOD _IOW('$', 4, __u64)
  251. #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
  252. #define PERF_EVENT_IOC_SET_FILTER _IOW('$', 6, char *)
  253. enum perf_event_ioc_flags {
  254. PERF_IOC_FLAG_GROUP = 1U << 0,
  255. };
  256. /*
  257. * Structure of the page that can be mapped via mmap
  258. */
  259. struct perf_event_mmap_page {
  260. __u32 version; /* version number of this structure */
  261. __u32 compat_version; /* lowest version this is compat with */
  262. /*
  263. * Bits needed to read the hw events in user-space.
  264. *
  265. * u32 seq, time_mult, time_shift, idx, width;
  266. * u64 count, enabled, running;
  267. * u64 cyc, time_offset;
  268. * s64 pmc = 0;
  269. *
  270. * do {
  271. * seq = pc->lock;
  272. * barrier()
  273. *
  274. * enabled = pc->time_enabled;
  275. * running = pc->time_running;
  276. *
  277. * if (pc->cap_usr_time && enabled != running) {
  278. * cyc = rdtsc();
  279. * time_offset = pc->time_offset;
  280. * time_mult = pc->time_mult;
  281. * time_shift = pc->time_shift;
  282. * }
  283. *
  284. * idx = pc->index;
  285. * count = pc->offset;
  286. * if (pc->cap_usr_rdpmc && idx) {
  287. * width = pc->pmc_width;
  288. * pmc = rdpmc(idx - 1);
  289. * }
  290. *
  291. * barrier();
  292. * } while (pc->lock != seq);
  293. *
  294. * NOTE: for obvious reason this only works on self-monitoring
  295. * processes.
  296. */
  297. __u32 lock; /* seqlock for synchronization */
  298. __u32 index; /* hardware event identifier */
  299. __s64 offset; /* add to hardware event value */
  300. __u64 time_enabled; /* time event active */
  301. __u64 time_running; /* time event on cpu */
  302. union {
  303. __u64 capabilities;
  304. __u64 cap_usr_time : 1,
  305. cap_usr_rdpmc : 1,
  306. cap_____res : 62;
  307. };
  308. /*
  309. * If cap_usr_rdpmc this field provides the bit-width of the value
  310. * read using the rdpmc() or equivalent instruction. This can be used
  311. * to sign extend the result like:
  312. *
  313. * pmc <<= 64 - width;
  314. * pmc >>= 64 - width; // signed shift right
  315. * count += pmc;
  316. */
  317. __u16 pmc_width;
  318. /*
  319. * If cap_usr_time the below fields can be used to compute the time
  320. * delta since time_enabled (in ns) using rdtsc or similar.
  321. *
  322. * u64 quot, rem;
  323. * u64 delta;
  324. *
  325. * quot = (cyc >> time_shift);
  326. * rem = cyc & ((1 << time_shift) - 1);
  327. * delta = time_offset + quot * time_mult +
  328. * ((rem * time_mult) >> time_shift);
  329. *
  330. * Where time_offset,time_mult,time_shift and cyc are read in the
  331. * seqcount loop described above. This delta can then be added to
  332. * enabled and possible running (if idx), improving the scaling:
  333. *
  334. * enabled += delta;
  335. * if (idx)
  336. * running += delta;
  337. *
  338. * quot = count / running;
  339. * rem = count % running;
  340. * count = quot * enabled + (rem * enabled) / running;
  341. */
  342. __u16 time_shift;
  343. __u32 time_mult;
  344. __u64 time_offset;
  345. /*
  346. * Hole for extension of the self monitor capabilities
  347. */
  348. __u64 __reserved[120]; /* align to 1k */
  349. /*
  350. * Control data for the mmap() data buffer.
  351. *
  352. * User-space reading the @data_head value should issue an smp_rmb(),
  353. * after reading this value.
  354. *
  355. * When the mapping is PROT_WRITE the @data_tail value should be
  356. * written by userspace to reflect the last read data, after issueing
  357. * an smp_mb() to separate the data read from the ->data_tail store.
  358. * In this case the kernel will not over-write unread data.
  359. *
  360. * See perf_output_put_handle() for the data ordering.
  361. */
  362. __u64 data_head; /* head in the data section */
  363. __u64 data_tail; /* user-space written tail */
  364. };
  365. #define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
  366. #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0)
  367. #define PERF_RECORD_MISC_KERNEL (1 << 0)
  368. #define PERF_RECORD_MISC_USER (2 << 0)
  369. #define PERF_RECORD_MISC_HYPERVISOR (3 << 0)
  370. #define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0)
  371. #define PERF_RECORD_MISC_GUEST_USER (5 << 0)
  372. /*
  373. * Indicates that the content of PERF_SAMPLE_IP points to
  374. * the actual instruction that triggered the event. See also
  375. * perf_event_attr::precise_ip.
  376. */
  377. #define PERF_RECORD_MISC_EXACT_IP (1 << 14)
  378. /*
  379. * Reserve the last bit to indicate some extended misc field
  380. */
  381. #define PERF_RECORD_MISC_EXT_RESERVED (1 << 15)
  382. struct perf_event_header {
  383. __u32 type;
  384. __u16 misc;
  385. __u16 size;
  386. };
  387. enum perf_event_type {
  388. /*
  389. * If perf_event_attr.sample_id_all is set then all event types will
  390. * have the sample_type selected fields related to where/when
  391. * (identity) an event took place (TID, TIME, ID, CPU, STREAM_ID)
  392. * described in PERF_RECORD_SAMPLE below, it will be stashed just after
  393. * the perf_event_header and the fields already present for the existing
  394. * fields, i.e. at the end of the payload. That way a newer perf.data
  395. * file will be supported by older perf tools, with these new optional
  396. * fields being ignored.
  397. *
  398. * The MMAP events record the PROT_EXEC mappings so that we can
  399. * correlate userspace IPs to code. They have the following structure:
  400. *
  401. * struct {
  402. * struct perf_event_header header;
  403. *
  404. * u32 pid, tid;
  405. * u64 addr;
  406. * u64 len;
  407. * u64 pgoff;
  408. * char filename[];
  409. * };
  410. */
  411. PERF_RECORD_MMAP = 1,
  412. /*
  413. * struct {
  414. * struct perf_event_header header;
  415. * u64 id;
  416. * u64 lost;
  417. * };
  418. */
  419. PERF_RECORD_LOST = 2,
  420. /*
  421. * struct {
  422. * struct perf_event_header header;
  423. *
  424. * u32 pid, tid;
  425. * char comm[];
  426. * };
  427. */
  428. PERF_RECORD_COMM = 3,
  429. /*
  430. * struct {
  431. * struct perf_event_header header;
  432. * u32 pid, ppid;
  433. * u32 tid, ptid;
  434. * u64 time;
  435. * };
  436. */
  437. PERF_RECORD_EXIT = 4,
  438. /*
  439. * struct {
  440. * struct perf_event_header header;
  441. * u64 time;
  442. * u64 id;
  443. * u64 stream_id;
  444. * };
  445. */
  446. PERF_RECORD_THROTTLE = 5,
  447. PERF_RECORD_UNTHROTTLE = 6,
  448. /*
  449. * struct {
  450. * struct perf_event_header header;
  451. * u32 pid, ppid;
  452. * u32 tid, ptid;
  453. * u64 time;
  454. * };
  455. */
  456. PERF_RECORD_FORK = 7,
  457. /*
  458. * struct {
  459. * struct perf_event_header header;
  460. * u32 pid, tid;
  461. *
  462. * struct read_format values;
  463. * };
  464. */
  465. PERF_RECORD_READ = 8,
  466. /*
  467. * struct {
  468. * struct perf_event_header header;
  469. *
  470. * { u64 ip; } && PERF_SAMPLE_IP
  471. * { u32 pid, tid; } && PERF_SAMPLE_TID
  472. * { u64 time; } && PERF_SAMPLE_TIME
  473. * { u64 addr; } && PERF_SAMPLE_ADDR
  474. * { u64 id; } && PERF_SAMPLE_ID
  475. * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
  476. * { u32 cpu, res; } && PERF_SAMPLE_CPU
  477. * { u64 period; } && PERF_SAMPLE_PERIOD
  478. *
  479. * { struct read_format values; } && PERF_SAMPLE_READ
  480. *
  481. * { u64 nr,
  482. * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
  483. *
  484. * #
  485. * # The RAW record below is opaque data wrt the ABI
  486. * #
  487. * # That is, the ABI doesn't make any promises wrt to
  488. * # the stability of its content, it may vary depending
  489. * # on event, hardware, kernel version and phase of
  490. * # the moon.
  491. * #
  492. * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
  493. * #
  494. *
  495. * { u32 size;
  496. * char data[size];}&& PERF_SAMPLE_RAW
  497. *
  498. * { u64 from, to, flags } lbr[nr];} && PERF_SAMPLE_BRANCH_STACK
  499. * };
  500. */
  501. PERF_RECORD_SAMPLE = 9,
  502. PERF_RECORD_MAX, /* non-ABI */
  503. };
  504. enum perf_callchain_context {
  505. PERF_CONTEXT_HV = (__u64)-32,
  506. PERF_CONTEXT_KERNEL = (__u64)-128,
  507. PERF_CONTEXT_USER = (__u64)-512,
  508. PERF_CONTEXT_GUEST = (__u64)-2048,
  509. PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
  510. PERF_CONTEXT_GUEST_USER = (__u64)-2560,
  511. PERF_CONTEXT_MAX = (__u64)-4095,
  512. };
  513. #define PERF_FLAG_FD_NO_GROUP (1U << 0)
  514. #define PERF_FLAG_FD_OUTPUT (1U << 1)
  515. #define PERF_FLAG_PID_CGROUP (1U << 2) /* pid=cgroup id, per-cpu mode only */
  516. #ifdef __KERNEL__
  517. /*
  518. * Kernel-internal data types and definitions:
  519. */
  520. #ifdef CONFIG_PERF_EVENTS
  521. # include <linux/cgroup.h>
  522. # include <asm/perf_event.h>
  523. # include <asm/local64.h>
  524. #endif
  525. struct perf_guest_info_callbacks {
  526. int (*is_in_guest)(void);
  527. int (*is_user_mode)(void);
  528. unsigned long (*get_guest_ip)(void);
  529. };
  530. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  531. #include <asm/hw_breakpoint.h>
  532. #endif
  533. #include <linux/list.h>
  534. #include <linux/mutex.h>
  535. #include <linux/rculist.h>
  536. #include <linux/rcupdate.h>
  537. #include <linux/spinlock.h>
  538. #include <linux/hrtimer.h>
  539. #include <linux/fs.h>
  540. #include <linux/pid_namespace.h>
  541. #include <linux/workqueue.h>
  542. #include <linux/ftrace.h>
  543. #include <linux/cpu.h>
  544. #include <linux/irq_work.h>
  545. #include <linux/static_key.h>
  546. #include <linux/atomic.h>
  547. #include <linux/sysfs.h>
  548. #include <asm/local.h>
  549. #define PERF_MAX_STACK_DEPTH 255
  550. struct perf_callchain_entry {
  551. __u64 nr;
  552. __u64 ip[PERF_MAX_STACK_DEPTH];
  553. };
  554. struct perf_raw_record {
  555. u32 size;
  556. void *data;
  557. };
  558. /*
  559. * single taken branch record layout:
  560. *
  561. * from: source instruction (may not always be a branch insn)
  562. * to: branch target
  563. * mispred: branch target was mispredicted
  564. * predicted: branch target was predicted
  565. *
  566. * support for mispred, predicted is optional. In case it
  567. * is not supported mispred = predicted = 0.
  568. */
  569. struct perf_branch_entry {
  570. __u64 from;
  571. __u64 to;
  572. __u64 mispred:1, /* target mispredicted */
  573. predicted:1,/* target predicted */
  574. reserved:62;
  575. };
  576. /*
  577. * branch stack layout:
  578. * nr: number of taken branches stored in entries[]
  579. *
  580. * Note that nr can vary from sample to sample
  581. * branches (to, from) are stored from most recent
  582. * to least recent, i.e., entries[0] contains the most
  583. * recent branch.
  584. */
  585. struct perf_branch_stack {
  586. __u64 nr;
  587. struct perf_branch_entry entries[0];
  588. };
  589. struct task_struct;
  590. /*
  591. * extra PMU register associated with an event
  592. */
  593. struct hw_perf_event_extra {
  594. u64 config; /* register value */
  595. unsigned int reg; /* register address or index */
  596. int alloc; /* extra register already allocated */
  597. int idx; /* index in shared_regs->regs[] */
  598. };
  599. /**
  600. * struct hw_perf_event - performance event hardware details:
  601. */
  602. struct hw_perf_event {
  603. #ifdef CONFIG_PERF_EVENTS
  604. union {
  605. struct { /* hardware */
  606. u64 config;
  607. u64 last_tag;
  608. unsigned long config_base;
  609. unsigned long event_base;
  610. int idx;
  611. int last_cpu;
  612. struct hw_perf_event_extra extra_reg;
  613. struct hw_perf_event_extra branch_reg;
  614. };
  615. struct { /* software */
  616. struct hrtimer hrtimer;
  617. };
  618. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  619. struct { /* breakpoint */
  620. struct arch_hw_breakpoint info;
  621. struct list_head bp_list;
  622. /*
  623. * Crufty hack to avoid the chicken and egg
  624. * problem hw_breakpoint has with context
  625. * creation and event initalization.
  626. */
  627. struct task_struct *bp_target;
  628. };
  629. #endif
  630. };
  631. int state;
  632. local64_t prev_count;
  633. u64 sample_period;
  634. u64 last_period;
  635. local64_t period_left;
  636. u64 interrupts_seq;
  637. u64 interrupts;
  638. u64 freq_time_stamp;
  639. u64 freq_count_stamp;
  640. #endif
  641. };
  642. /*
  643. * hw_perf_event::state flags
  644. */
  645. #define PERF_HES_STOPPED 0x01 /* the counter is stopped */
  646. #define PERF_HES_UPTODATE 0x02 /* event->count up-to-date */
  647. #define PERF_HES_ARCH 0x04
  648. struct perf_event;
  649. /*
  650. * Common implementation detail of pmu::{start,commit,cancel}_txn
  651. */
  652. #define PERF_EVENT_TXN 0x1
  653. /**
  654. * struct pmu - generic performance monitoring unit
  655. */
  656. struct pmu {
  657. struct list_head entry;
  658. struct device *dev;
  659. const struct attribute_group **attr_groups;
  660. char *name;
  661. int type;
  662. int * __percpu pmu_disable_count;
  663. struct perf_cpu_context * __percpu pmu_cpu_context;
  664. int task_ctx_nr;
  665. u32 events_across_hotplug:1,
  666. reserved:31;
  667. /*
  668. * Fully disable/enable this PMU, can be used to protect from the PMI
  669. * as well as for lazy/batch writing of the MSRs.
  670. */
  671. void (*pmu_enable) (struct pmu *pmu); /* optional */
  672. void (*pmu_disable) (struct pmu *pmu); /* optional */
  673. /*
  674. * Try and initialize the event for this PMU.
  675. * Should return -ENOENT when the @event doesn't match this PMU.
  676. */
  677. int (*event_init) (struct perf_event *event);
  678. #define PERF_EF_START 0x01 /* start the counter when adding */
  679. #define PERF_EF_RELOAD 0x02 /* reload the counter when starting */
  680. #define PERF_EF_UPDATE 0x04 /* update the counter when stopping */
  681. /*
  682. * Adds/Removes a counter to/from the PMU, can be done inside
  683. * a transaction, see the ->*_txn() methods.
  684. */
  685. int (*add) (struct perf_event *event, int flags);
  686. void (*del) (struct perf_event *event, int flags);
  687. /*
  688. * Starts/Stops a counter present on the PMU. The PMI handler
  689. * should stop the counter when perf_event_overflow() returns
  690. * !0. ->start() will be used to continue.
  691. */
  692. void (*start) (struct perf_event *event, int flags);
  693. void (*stop) (struct perf_event *event, int flags);
  694. /*
  695. * Updates the counter value of the event.
  696. */
  697. void (*read) (struct perf_event *event);
  698. /*
  699. * Group events scheduling is treated as a transaction, add
  700. * group events as a whole and perform one schedulability test.
  701. * If the test fails, roll back the whole group
  702. *
  703. * Start the transaction, after this ->add() doesn't need to
  704. * do schedulability tests.
  705. */
  706. void (*start_txn) (struct pmu *pmu); /* optional */
  707. /*
  708. * If ->start_txn() disabled the ->add() schedulability test
  709. * then ->commit_txn() is required to perform one. On success
  710. * the transaction is closed. On error the transaction is kept
  711. * open until ->cancel_txn() is called.
  712. */
  713. int (*commit_txn) (struct pmu *pmu); /* optional */
  714. /*
  715. * Will cancel the transaction, assumes ->del() is called
  716. * for each successful ->add() during the transaction.
  717. */
  718. void (*cancel_txn) (struct pmu *pmu); /* optional */
  719. /*
  720. * Will return the value for perf_event_mmap_page::index for this event,
  721. * if no implementation is provided it will default to: event->hw.idx + 1.
  722. */
  723. int (*event_idx) (struct perf_event *event); /*optional */
  724. /*
  725. * flush branch stack on context-switches (needed in cpu-wide mode)
  726. */
  727. void (*flush_branch_stack) (void);
  728. };
  729. /**
  730. * enum perf_event_active_state - the states of a event
  731. */
  732. enum perf_event_active_state {
  733. PERF_EVENT_STATE_ERROR = -2,
  734. PERF_EVENT_STATE_OFF = -1,
  735. PERF_EVENT_STATE_INACTIVE = 0,
  736. PERF_EVENT_STATE_ACTIVE = 1,
  737. };
  738. struct file;
  739. struct perf_sample_data;
  740. typedef void (*perf_overflow_handler_t)(struct perf_event *,
  741. struct perf_sample_data *,
  742. struct pt_regs *regs);
  743. enum perf_group_flag {
  744. PERF_GROUP_SOFTWARE = 0x1,
  745. };
  746. #define SWEVENT_HLIST_BITS 8
  747. #define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)
  748. struct swevent_hlist {
  749. struct hlist_head heads[SWEVENT_HLIST_SIZE];
  750. struct rcu_head rcu_head;
  751. };
  752. #define PERF_ATTACH_CONTEXT 0x01
  753. #define PERF_ATTACH_GROUP 0x02
  754. #define PERF_ATTACH_TASK 0x04
  755. #ifdef CONFIG_CGROUP_PERF
  756. /*
  757. * perf_cgroup_info keeps track of time_enabled for a cgroup.
  758. * This is a per-cpu dynamically allocated data structure.
  759. */
  760. struct perf_cgroup_info {
  761. u64 time;
  762. u64 timestamp;
  763. };
  764. struct perf_cgroup {
  765. struct cgroup_subsys_state css;
  766. struct perf_cgroup_info *info; /* timing info, one per cpu */
  767. };
  768. #endif
  769. struct ring_buffer;
  770. /**
  771. * struct perf_event - performance event kernel representation:
  772. */
  773. struct perf_event {
  774. #ifdef CONFIG_PERF_EVENTS
  775. struct list_head group_entry;
  776. struct list_head event_entry;
  777. struct list_head sibling_list;
  778. struct hlist_node hlist_entry;
  779. int nr_siblings;
  780. int group_flags;
  781. struct perf_event *group_leader;
  782. struct pmu *pmu;
  783. enum perf_event_active_state state;
  784. unsigned int attach_state;
  785. local64_t count;
  786. atomic64_t child_count;
  787. /*
  788. * These are the total time in nanoseconds that the event
  789. * has been enabled (i.e. eligible to run, and the task has
  790. * been scheduled in, if this is a per-task event)
  791. * and running (scheduled onto the CPU), respectively.
  792. *
  793. * They are computed from tstamp_enabled, tstamp_running and
  794. * tstamp_stopped when the event is in INACTIVE or ACTIVE state.
  795. */
  796. u64 total_time_enabled;
  797. u64 total_time_running;
  798. /*
  799. * These are timestamps used for computing total_time_enabled
  800. * and total_time_running when the event is in INACTIVE or
  801. * ACTIVE state, measured in nanoseconds from an arbitrary point
  802. * in time.
  803. * tstamp_enabled: the notional time when the event was enabled
  804. * tstamp_running: the notional time when the event was scheduled on
  805. * tstamp_stopped: in INACTIVE state, the notional time when the
  806. * event was scheduled off.
  807. */
  808. u64 tstamp_enabled;
  809. u64 tstamp_running;
  810. u64 tstamp_stopped;
  811. /*
  812. * timestamp shadows the actual context timing but it can
  813. * be safely used in NMI interrupt context. It reflects the
  814. * context time as it was when the event was last scheduled in.
  815. *
  816. * ctx_time already accounts for ctx->timestamp. Therefore to
  817. * compute ctx_time for a sample, simply add perf_clock().
  818. */
  819. u64 shadow_ctx_time;
  820. struct perf_event_attr attr;
  821. u16 header_size;
  822. u16 id_header_size;
  823. u16 read_size;
  824. struct hw_perf_event hw;
  825. struct perf_event_context *ctx;
  826. atomic_long_t refcount;
  827. /*
  828. * These accumulate total time (in nanoseconds) that children
  829. * events have been enabled and running, respectively.
  830. */
  831. atomic64_t child_total_time_enabled;
  832. atomic64_t child_total_time_running;
  833. /*
  834. * Protect attach/detach and child_list:
  835. */
  836. struct mutex child_mutex;
  837. struct list_head child_list;
  838. struct perf_event *parent;
  839. int oncpu;
  840. int cpu;
  841. struct list_head owner_entry;
  842. struct task_struct *owner;
  843. /* mmap bits */
  844. struct mutex mmap_mutex;
  845. atomic_t mmap_count;
  846. struct ring_buffer *rb;
  847. struct list_head rb_entry;
  848. /* poll related */
  849. wait_queue_head_t waitq;
  850. struct fasync_struct *fasync;
  851. /* delayed work for NMIs and such */
  852. int pending_wakeup;
  853. int pending_kill;
  854. int pending_disable;
  855. struct irq_work pending;
  856. atomic_t event_limit;
  857. void (*destroy)(struct perf_event *);
  858. struct rcu_head rcu_head;
  859. struct pid_namespace *ns;
  860. u64 id;
  861. perf_overflow_handler_t overflow_handler;
  862. void *overflow_handler_context;
  863. #ifdef CONFIG_EVENT_TRACING
  864. struct ftrace_event_call *tp_event;
  865. struct event_filter *filter;
  866. #ifdef CONFIG_FUNCTION_TRACER
  867. struct ftrace_ops ftrace_ops;
  868. #endif
  869. #endif
  870. #ifdef CONFIG_CGROUP_PERF
  871. struct perf_cgroup *cgrp; /* cgroup event is attach to */
  872. int cgrp_defer_enabled;
  873. #endif
  874. #endif /* CONFIG_PERF_EVENTS */
  875. };
  876. /**
  877. * struct perf_event_context - event context structure
  878. *
  879. * Used as a container for task events and CPU events as well:
  880. */
  881. struct perf_event_context {
  882. struct pmu *pmu;
  883. /*
  884. * Protect the states of the events in the list,
  885. * nr_active, and the list:
  886. */
  887. raw_spinlock_t lock;
  888. /*
  889. * Protect the list of events. Locking either mutex or lock
  890. * is sufficient to ensure the list doesn't change; to change
  891. * the list you need to lock both the mutex and the spinlock.
  892. */
  893. struct mutex mutex;
  894. struct list_head pinned_groups;
  895. struct list_head flexible_groups;
  896. struct list_head event_list;
  897. int nr_events;
  898. int nr_active;
  899. int is_active;
  900. int nr_stat;
  901. int nr_freq;
  902. int rotate_disable;
  903. atomic_t refcount;
  904. struct task_struct *task;
  905. /*
  906. * Context clock, runs when context enabled.
  907. */
  908. u64 time;
  909. u64 timestamp;
  910. /*
  911. * These fields let us detect when two contexts have both
  912. * been cloned (inherited) from a common ancestor.
  913. */
  914. struct perf_event_context *parent_ctx;
  915. u64 parent_gen;
  916. u64 generation;
  917. int pin_count;
  918. int nr_cgroups; /* cgroup evts */
  919. int nr_branch_stack; /* branch_stack evt */
  920. struct rcu_head rcu_head;
  921. };
  922. /*
  923. * Number of contexts where an event can trigger:
  924. * task, softirq, hardirq, nmi.
  925. */
  926. #define PERF_NR_CONTEXTS 4
  927. /**
  928. * struct perf_event_cpu_context - per cpu event context structure
  929. */
  930. struct perf_cpu_context {
  931. struct perf_event_context ctx;
  932. struct perf_event_context *task_ctx;
  933. int active_oncpu;
  934. int exclusive;
  935. struct list_head rotation_list;
  936. int jiffies_interval;
  937. struct pmu *unique_pmu;
  938. struct perf_cgroup *cgrp;
  939. };
  940. struct perf_output_handle {
  941. struct perf_event *event;
  942. struct ring_buffer *rb;
  943. unsigned long wakeup;
  944. unsigned long size;
  945. void *addr;
  946. int page;
  947. };
  948. #ifdef CONFIG_PERF_EVENTS
  949. extern int perf_pmu_register(struct pmu *pmu, char *name, int type);
  950. extern void perf_pmu_unregister(struct pmu *pmu);
  951. extern int perf_num_counters(void);
  952. extern const char *perf_pmu_name(void);
  953. extern void __perf_event_task_sched_in(struct task_struct *prev,
  954. struct task_struct *task);
  955. extern void __perf_event_task_sched_out(struct task_struct *prev,
  956. struct task_struct *next);
  957. extern int perf_event_init_task(struct task_struct *child);
  958. extern void perf_event_exit_task(struct task_struct *child);
  959. extern void perf_event_free_task(struct task_struct *task);
  960. extern void perf_event_delayed_put(struct task_struct *task);
  961. extern void perf_event_print_debug(void);
  962. extern void perf_pmu_disable(struct pmu *pmu);
  963. extern void perf_pmu_enable(struct pmu *pmu);
  964. extern int perf_event_task_disable(void);
  965. extern int perf_event_task_enable(void);
  966. extern int perf_event_refresh(struct perf_event *event, int refresh);
  967. extern void perf_event_update_userpage(struct perf_event *event);
  968. extern int perf_event_release_kernel(struct perf_event *event);
  969. extern struct perf_event *
  970. perf_event_create_kernel_counter(struct perf_event_attr *attr,
  971. int cpu,
  972. struct task_struct *task,
  973. perf_overflow_handler_t callback,
  974. void *context);
  975. extern u64 perf_event_read_value(struct perf_event *event,
  976. u64 *enabled, u64 *running);
  977. struct perf_sample_data {
  978. u64 type;
  979. u64 ip;
  980. struct {
  981. u32 pid;
  982. u32 tid;
  983. } tid_entry;
  984. u64 time;
  985. u64 addr;
  986. u64 id;
  987. u64 stream_id;
  988. struct {
  989. u32 cpu;
  990. u32 reserved;
  991. } cpu_entry;
  992. u64 period;
  993. struct perf_callchain_entry *callchain;
  994. struct perf_raw_record *raw;
  995. struct perf_branch_stack *br_stack;
  996. };
  997. static inline void perf_sample_data_init(struct perf_sample_data *data, u64 addr)
  998. {
  999. data->addr = addr;
  1000. data->raw = NULL;
  1001. data->br_stack = NULL;
  1002. }
  1003. extern void perf_output_sample(struct perf_output_handle *handle,
  1004. struct perf_event_header *header,
  1005. struct perf_sample_data *data,
  1006. struct perf_event *event);
  1007. extern void perf_prepare_sample(struct perf_event_header *header,
  1008. struct perf_sample_data *data,
  1009. struct perf_event *event,
  1010. struct pt_regs *regs);
  1011. extern int perf_event_overflow(struct perf_event *event,
  1012. struct perf_sample_data *data,
  1013. struct pt_regs *regs);
  1014. static inline bool is_sampling_event(struct perf_event *event)
  1015. {
  1016. return event->attr.sample_period != 0;
  1017. }
  1018. /*
  1019. * Return 1 for a software event, 0 for a hardware event
  1020. */
  1021. static inline int is_software_event(struct perf_event *event)
  1022. {
  1023. return event->pmu->task_ctx_nr == perf_sw_context;
  1024. }
  1025. extern struct static_key perf_swevent_enabled[PERF_COUNT_SW_MAX];
  1026. extern void __perf_sw_event(u32, u64, struct pt_regs *, u64);
  1027. #ifndef perf_arch_fetch_caller_regs
  1028. static inline void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip) { }
  1029. #endif
  1030. /*
  1031. * Take a snapshot of the regs. Skip ip and frame pointer to
  1032. * the nth caller. We only need a few of the regs:
  1033. * - ip for PERF_SAMPLE_IP
  1034. * - cs for user_mode() tests
  1035. * - bp for callchains
  1036. * - eflags, for future purposes, just in case
  1037. */
  1038. static inline void perf_fetch_caller_regs(struct pt_regs *regs)
  1039. {
  1040. memset(regs, 0, sizeof(*regs));
  1041. perf_arch_fetch_caller_regs(regs, CALLER_ADDR0);
  1042. }
  1043. static __always_inline void
  1044. perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr)
  1045. {
  1046. struct pt_regs hot_regs;
  1047. if (static_key_false(&perf_swevent_enabled[event_id])) {
  1048. if (!regs) {
  1049. perf_fetch_caller_regs(&hot_regs);
  1050. regs = &hot_regs;
  1051. }
  1052. __perf_sw_event(event_id, nr, regs, addr);
  1053. }
  1054. }
  1055. extern struct static_key_deferred perf_sched_events;
  1056. static inline void perf_event_task_sched_in(struct task_struct *prev,
  1057. struct task_struct *task)
  1058. {
  1059. if (static_key_false(&perf_sched_events.key))
  1060. __perf_event_task_sched_in(prev, task);
  1061. }
  1062. static inline void perf_event_task_sched_out(struct task_struct *prev,
  1063. struct task_struct *next)
  1064. {
  1065. perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, NULL, 0);
  1066. if (static_key_false(&perf_sched_events.key))
  1067. __perf_event_task_sched_out(prev, next);
  1068. }
  1069. extern void perf_event_mmap(struct vm_area_struct *vma);
  1070. extern struct perf_guest_info_callbacks *perf_guest_cbs;
  1071. extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
  1072. extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
  1073. extern void perf_event_comm(struct task_struct *tsk);
  1074. extern void perf_event_fork(struct task_struct *tsk);
  1075. /* Callchains */
  1076. DECLARE_PER_CPU(struct perf_callchain_entry, perf_callchain_entry);
  1077. extern void perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs);
  1078. extern void perf_callchain_kernel(struct perf_callchain_entry *entry, struct pt_regs *regs);
  1079. static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64 ip)
  1080. {
  1081. if (entry->nr < PERF_MAX_STACK_DEPTH)
  1082. entry->ip[entry->nr++] = ip;
  1083. }
  1084. extern int sysctl_perf_event_paranoid;
  1085. extern int sysctl_perf_event_mlock;
  1086. extern int sysctl_perf_event_sample_rate;
  1087. extern int perf_proc_update_handler(struct ctl_table *table, int write,
  1088. void __user *buffer, size_t *lenp,
  1089. loff_t *ppos);
  1090. static inline bool perf_paranoid_any(void)
  1091. {
  1092. return sysctl_perf_event_paranoid > 2;
  1093. }
  1094. static inline bool perf_paranoid_tracepoint_raw(void)
  1095. {
  1096. return sysctl_perf_event_paranoid > -1;
  1097. }
  1098. static inline bool perf_paranoid_cpu(void)
  1099. {
  1100. return sysctl_perf_event_paranoid > 0;
  1101. }
  1102. static inline bool perf_paranoid_kernel(void)
  1103. {
  1104. return sysctl_perf_event_paranoid > 1;
  1105. }
  1106. extern void perf_event_init(void);
  1107. extern void perf_tp_event(u64 addr, u64 count, void *record,
  1108. int entry_size, struct pt_regs *regs,
  1109. struct hlist_head *head, int rctx);
  1110. extern void perf_bp_event(struct perf_event *event, void *data);
  1111. #ifndef perf_misc_flags
  1112. # define perf_misc_flags(regs) \
  1113. (user_mode(regs) ? PERF_RECORD_MISC_USER : PERF_RECORD_MISC_KERNEL)
  1114. # define perf_instruction_pointer(regs) instruction_pointer(regs)
  1115. #endif
  1116. static inline bool has_branch_stack(struct perf_event *event)
  1117. {
  1118. return event->attr.sample_type & PERF_SAMPLE_BRANCH_STACK;
  1119. }
  1120. extern int perf_output_begin(struct perf_output_handle *handle,
  1121. struct perf_event *event, unsigned int size);
  1122. extern void perf_output_end(struct perf_output_handle *handle);
  1123. extern void perf_output_copy(struct perf_output_handle *handle,
  1124. const void *buf, unsigned int len);
  1125. extern int perf_swevent_get_recursion_context(void);
  1126. extern void perf_swevent_put_recursion_context(int rctx);
  1127. extern void perf_event_enable(struct perf_event *event);
  1128. extern void perf_event_disable(struct perf_event *event);
  1129. extern int __perf_event_disable(void *info);
  1130. extern void perf_event_task_tick(void);
  1131. #else
  1132. static inline void
  1133. perf_event_task_sched_in(struct task_struct *prev,
  1134. struct task_struct *task) { }
  1135. static inline void
  1136. perf_event_task_sched_out(struct task_struct *prev,
  1137. struct task_struct *next) { }
  1138. static inline int perf_event_init_task(struct task_struct *child) { return 0; }
  1139. static inline void perf_event_exit_task(struct task_struct *child) { }
  1140. static inline void perf_event_free_task(struct task_struct *task) { }
  1141. static inline void perf_event_delayed_put(struct task_struct *task) { }
  1142. static inline void perf_event_print_debug(void) { }
  1143. static inline int perf_event_task_disable(void) { return -EINVAL; }
  1144. static inline int perf_event_task_enable(void) { return -EINVAL; }
  1145. static inline int perf_event_refresh(struct perf_event *event, int refresh)
  1146. {
  1147. return -EINVAL;
  1148. }
  1149. static inline void
  1150. perf_sw_event(u32 event_id, u64 nr, struct pt_regs *regs, u64 addr) { }
  1151. static inline void
  1152. perf_bp_event(struct perf_event *event, void *data) { }
  1153. static inline int perf_register_guest_info_callbacks
  1154. (struct perf_guest_info_callbacks *callbacks) { return 0; }
  1155. static inline int perf_unregister_guest_info_callbacks
  1156. (struct perf_guest_info_callbacks *callbacks) { return 0; }
  1157. static inline void perf_event_mmap(struct vm_area_struct *vma) { }
  1158. static inline void perf_event_comm(struct task_struct *tsk) { }
  1159. static inline void perf_event_fork(struct task_struct *tsk) { }
  1160. static inline void perf_event_init(void) { }
  1161. static inline int perf_swevent_get_recursion_context(void) { return -1; }
  1162. static inline void perf_swevent_put_recursion_context(int rctx) { }
  1163. static inline void perf_event_enable(struct perf_event *event) { }
  1164. static inline void perf_event_disable(struct perf_event *event) { }
  1165. static inline int __perf_event_disable(void *info) { return -1; }
  1166. static inline void perf_event_task_tick(void) { }
  1167. #endif
  1168. #if defined(CONFIG_PERF_EVENTS) && defined(CONFIG_CPU_SUP_INTEL)
  1169. extern void perf_restore_debug_store(void);
  1170. #else
  1171. static inline void perf_restore_debug_store(void) { }
  1172. #endif
  1173. #define perf_output_put(handle, x) perf_output_copy((handle), &(x), sizeof(x))
  1174. /*
  1175. * This has to have a higher priority than migration_notifier in sched.c.
  1176. */
  1177. #define perf_cpu_notifier(fn) \
  1178. do { \
  1179. static struct notifier_block fn##_nb __cpuinitdata = \
  1180. { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
  1181. fn(&fn##_nb, (unsigned long)CPU_UP_PREPARE, \
  1182. (void *)(unsigned long)smp_processor_id()); \
  1183. fn(&fn##_nb, (unsigned long)CPU_STARTING, \
  1184. (void *)(unsigned long)smp_processor_id()); \
  1185. fn(&fn##_nb, (unsigned long)CPU_ONLINE, \
  1186. (void *)(unsigned long)smp_processor_id()); \
  1187. register_cpu_notifier(&fn##_nb); \
  1188. } while (0)
  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. #endif /* __KERNEL__ */
  1201. #endif /* _LINUX_PERF_EVENT_H */