perf_event.h 37 KB

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