perf_event.h 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Performance events:
  4. *
  5. * Copyright (C) 2008-2009, Linutronix GmbH, Thomas Gleixner <tglx@kernel.org>
  6. * Copyright (C) 2008-2011, Red Hat, Inc., Ingo Molnar
  7. * Copyright (C) 2008-2011, Red Hat, Inc., Peter Zijlstra
  8. *
  9. * Data type definitions, declarations, prototypes.
  10. *
  11. * Started by: Thomas Gleixner and Ingo Molnar
  12. *
  13. * For licencing details see kernel-base/COPYING
  14. */
  15. #ifndef _UAPI_LINUX_PERF_EVENT_H
  16. #define _UAPI_LINUX_PERF_EVENT_H
  17. #include <linux/types.h>
  18. #include <linux/ioctl.h>
  19. #include <asm/byteorder.h>
  20. /*
  21. * User-space ABI bits:
  22. */
  23. /*
  24. * attr.type
  25. */
  26. enum perf_type_id {
  27. PERF_TYPE_HARDWARE = 0,
  28. PERF_TYPE_SOFTWARE = 1,
  29. PERF_TYPE_TRACEPOINT = 2,
  30. PERF_TYPE_HW_CACHE = 3,
  31. PERF_TYPE_RAW = 4,
  32. PERF_TYPE_BREAKPOINT = 5,
  33. PERF_TYPE_MAX, /* non-ABI */
  34. };
  35. /*
  36. * attr.config layout for type PERF_TYPE_HARDWARE and PERF_TYPE_HW_CACHE
  37. *
  38. * PERF_TYPE_HARDWARE: 0xEEEEEEEE000000AA
  39. * AA: hardware event ID
  40. * EEEEEEEE: PMU type ID
  41. *
  42. * PERF_TYPE_HW_CACHE: 0xEEEEEEEE00DDCCBB
  43. * BB: hardware cache ID
  44. * CC: hardware cache op ID
  45. * DD: hardware cache op result ID
  46. * EEEEEEEE: PMU type ID
  47. *
  48. * If the PMU type ID is 0, PERF_TYPE_RAW will be applied.
  49. */
  50. #define PERF_PMU_TYPE_SHIFT 32
  51. #define PERF_HW_EVENT_MASK 0xffffffff
  52. /*
  53. * Generalized performance event event_id types, used by the
  54. * attr.event_id parameter of the sys_perf_event_open()
  55. * syscall:
  56. */
  57. enum perf_hw_id {
  58. /*
  59. * Common hardware events, generalized by the kernel:
  60. */
  61. PERF_COUNT_HW_CPU_CYCLES = 0,
  62. PERF_COUNT_HW_INSTRUCTIONS = 1,
  63. PERF_COUNT_HW_CACHE_REFERENCES = 2,
  64. PERF_COUNT_HW_CACHE_MISSES = 3,
  65. PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4,
  66. PERF_COUNT_HW_BRANCH_MISSES = 5,
  67. PERF_COUNT_HW_BUS_CYCLES = 6,
  68. PERF_COUNT_HW_STALLED_CYCLES_FRONTEND = 7,
  69. PERF_COUNT_HW_STALLED_CYCLES_BACKEND = 8,
  70. PERF_COUNT_HW_REF_CPU_CYCLES = 9,
  71. PERF_COUNT_HW_MAX, /* non-ABI */
  72. };
  73. /*
  74. * Generalized hardware cache events:
  75. *
  76. * { L1-D, L1-I, LLC, ITLB, DTLB, BPU, NODE } x
  77. * { read, write, prefetch } x
  78. * { accesses, misses }
  79. */
  80. enum perf_hw_cache_id {
  81. PERF_COUNT_HW_CACHE_L1D = 0,
  82. PERF_COUNT_HW_CACHE_L1I = 1,
  83. PERF_COUNT_HW_CACHE_LL = 2,
  84. PERF_COUNT_HW_CACHE_DTLB = 3,
  85. PERF_COUNT_HW_CACHE_ITLB = 4,
  86. PERF_COUNT_HW_CACHE_BPU = 5,
  87. PERF_COUNT_HW_CACHE_NODE = 6,
  88. PERF_COUNT_HW_CACHE_MAX, /* non-ABI */
  89. };
  90. enum perf_hw_cache_op_id {
  91. PERF_COUNT_HW_CACHE_OP_READ = 0,
  92. PERF_COUNT_HW_CACHE_OP_WRITE = 1,
  93. PERF_COUNT_HW_CACHE_OP_PREFETCH = 2,
  94. PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */
  95. };
  96. enum perf_hw_cache_op_result_id {
  97. PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0,
  98. PERF_COUNT_HW_CACHE_RESULT_MISS = 1,
  99. PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */
  100. };
  101. /*
  102. * Special "software" events provided by the kernel, even if the hardware
  103. * does not support performance events. These events measure various
  104. * physical and SW events of the kernel (and allow the profiling of them as
  105. * well):
  106. */
  107. enum perf_sw_ids {
  108. PERF_COUNT_SW_CPU_CLOCK = 0,
  109. PERF_COUNT_SW_TASK_CLOCK = 1,
  110. PERF_COUNT_SW_PAGE_FAULTS = 2,
  111. PERF_COUNT_SW_CONTEXT_SWITCHES = 3,
  112. PERF_COUNT_SW_CPU_MIGRATIONS = 4,
  113. PERF_COUNT_SW_PAGE_FAULTS_MIN = 5,
  114. PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6,
  115. PERF_COUNT_SW_ALIGNMENT_FAULTS = 7,
  116. PERF_COUNT_SW_EMULATION_FAULTS = 8,
  117. PERF_COUNT_SW_DUMMY = 9,
  118. PERF_COUNT_SW_BPF_OUTPUT = 10,
  119. PERF_COUNT_SW_CGROUP_SWITCHES = 11,
  120. PERF_COUNT_SW_MAX, /* non-ABI */
  121. };
  122. /*
  123. * Bits that can be set in attr.sample_type to request information
  124. * in the overflow packets.
  125. */
  126. enum perf_event_sample_format {
  127. PERF_SAMPLE_IP = 1U << 0,
  128. PERF_SAMPLE_TID = 1U << 1,
  129. PERF_SAMPLE_TIME = 1U << 2,
  130. PERF_SAMPLE_ADDR = 1U << 3,
  131. PERF_SAMPLE_READ = 1U << 4,
  132. PERF_SAMPLE_CALLCHAIN = 1U << 5,
  133. PERF_SAMPLE_ID = 1U << 6,
  134. PERF_SAMPLE_CPU = 1U << 7,
  135. PERF_SAMPLE_PERIOD = 1U << 8,
  136. PERF_SAMPLE_STREAM_ID = 1U << 9,
  137. PERF_SAMPLE_RAW = 1U << 10,
  138. PERF_SAMPLE_BRANCH_STACK = 1U << 11,
  139. PERF_SAMPLE_REGS_USER = 1U << 12,
  140. PERF_SAMPLE_STACK_USER = 1U << 13,
  141. PERF_SAMPLE_WEIGHT = 1U << 14,
  142. PERF_SAMPLE_DATA_SRC = 1U << 15,
  143. PERF_SAMPLE_IDENTIFIER = 1U << 16,
  144. PERF_SAMPLE_TRANSACTION = 1U << 17,
  145. PERF_SAMPLE_REGS_INTR = 1U << 18,
  146. PERF_SAMPLE_PHYS_ADDR = 1U << 19,
  147. PERF_SAMPLE_AUX = 1U << 20,
  148. PERF_SAMPLE_CGROUP = 1U << 21,
  149. PERF_SAMPLE_DATA_PAGE_SIZE = 1U << 22,
  150. PERF_SAMPLE_CODE_PAGE_SIZE = 1U << 23,
  151. PERF_SAMPLE_WEIGHT_STRUCT = 1U << 24,
  152. PERF_SAMPLE_MAX = 1U << 25, /* non-ABI */
  153. };
  154. #define PERF_SAMPLE_WEIGHT_TYPE (PERF_SAMPLE_WEIGHT | PERF_SAMPLE_WEIGHT_STRUCT)
  155. /*
  156. * Values to program into branch_sample_type when PERF_SAMPLE_BRANCH is set.
  157. *
  158. * If the user does not pass priv level information via branch_sample_type,
  159. * the kernel uses the event's priv level. Branch and event priv levels do
  160. * not have to match. Branch priv level is checked for permissions.
  161. *
  162. * The branch types can be combined, however BRANCH_ANY covers all types
  163. * of branches and therefore it supersedes all the other types.
  164. */
  165. enum perf_branch_sample_type_shift {
  166. PERF_SAMPLE_BRANCH_USER_SHIFT = 0, /* user branches */
  167. PERF_SAMPLE_BRANCH_KERNEL_SHIFT = 1, /* kernel branches */
  168. PERF_SAMPLE_BRANCH_HV_SHIFT = 2, /* hypervisor branches */
  169. PERF_SAMPLE_BRANCH_ANY_SHIFT = 3, /* any branch types */
  170. PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT = 4, /* any call branch */
  171. PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT = 5, /* any return branch */
  172. PERF_SAMPLE_BRANCH_IND_CALL_SHIFT = 6, /* indirect calls */
  173. PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT = 7, /* transaction aborts */
  174. PERF_SAMPLE_BRANCH_IN_TX_SHIFT = 8, /* in transaction */
  175. PERF_SAMPLE_BRANCH_NO_TX_SHIFT = 9, /* not in transaction */
  176. PERF_SAMPLE_BRANCH_COND_SHIFT = 10, /* conditional branches */
  177. PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT = 11, /* CALL/RET stack */
  178. PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT = 12, /* indirect jumps */
  179. PERF_SAMPLE_BRANCH_CALL_SHIFT = 13, /* direct call */
  180. PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT = 14, /* no flags */
  181. PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT = 15, /* no cycles */
  182. PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT = 16, /* save branch type */
  183. PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT = 17, /* save low level index of raw branch records */
  184. PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT = 18, /* save privilege mode */
  185. PERF_SAMPLE_BRANCH_COUNTERS_SHIFT = 19, /* save occurrences of events on a branch */
  186. PERF_SAMPLE_BRANCH_MAX_SHIFT /* non-ABI */
  187. };
  188. enum perf_branch_sample_type {
  189. PERF_SAMPLE_BRANCH_USER = 1U << PERF_SAMPLE_BRANCH_USER_SHIFT,
  190. PERF_SAMPLE_BRANCH_KERNEL = 1U << PERF_SAMPLE_BRANCH_KERNEL_SHIFT,
  191. PERF_SAMPLE_BRANCH_HV = 1U << PERF_SAMPLE_BRANCH_HV_SHIFT,
  192. PERF_SAMPLE_BRANCH_ANY = 1U << PERF_SAMPLE_BRANCH_ANY_SHIFT,
  193. PERF_SAMPLE_BRANCH_ANY_CALL = 1U << PERF_SAMPLE_BRANCH_ANY_CALL_SHIFT,
  194. PERF_SAMPLE_BRANCH_ANY_RETURN = 1U << PERF_SAMPLE_BRANCH_ANY_RETURN_SHIFT,
  195. PERF_SAMPLE_BRANCH_IND_CALL = 1U << PERF_SAMPLE_BRANCH_IND_CALL_SHIFT,
  196. PERF_SAMPLE_BRANCH_ABORT_TX = 1U << PERF_SAMPLE_BRANCH_ABORT_TX_SHIFT,
  197. PERF_SAMPLE_BRANCH_IN_TX = 1U << PERF_SAMPLE_BRANCH_IN_TX_SHIFT,
  198. PERF_SAMPLE_BRANCH_NO_TX = 1U << PERF_SAMPLE_BRANCH_NO_TX_SHIFT,
  199. PERF_SAMPLE_BRANCH_COND = 1U << PERF_SAMPLE_BRANCH_COND_SHIFT,
  200. PERF_SAMPLE_BRANCH_CALL_STACK = 1U << PERF_SAMPLE_BRANCH_CALL_STACK_SHIFT,
  201. PERF_SAMPLE_BRANCH_IND_JUMP = 1U << PERF_SAMPLE_BRANCH_IND_JUMP_SHIFT,
  202. PERF_SAMPLE_BRANCH_CALL = 1U << PERF_SAMPLE_BRANCH_CALL_SHIFT,
  203. PERF_SAMPLE_BRANCH_NO_FLAGS = 1U << PERF_SAMPLE_BRANCH_NO_FLAGS_SHIFT,
  204. PERF_SAMPLE_BRANCH_NO_CYCLES = 1U << PERF_SAMPLE_BRANCH_NO_CYCLES_SHIFT,
  205. PERF_SAMPLE_BRANCH_TYPE_SAVE = 1U << PERF_SAMPLE_BRANCH_TYPE_SAVE_SHIFT,
  206. PERF_SAMPLE_BRANCH_HW_INDEX = 1U << PERF_SAMPLE_BRANCH_HW_INDEX_SHIFT,
  207. PERF_SAMPLE_BRANCH_PRIV_SAVE = 1U << PERF_SAMPLE_BRANCH_PRIV_SAVE_SHIFT,
  208. PERF_SAMPLE_BRANCH_COUNTERS = 1U << PERF_SAMPLE_BRANCH_COUNTERS_SHIFT,
  209. PERF_SAMPLE_BRANCH_MAX = 1U << PERF_SAMPLE_BRANCH_MAX_SHIFT,
  210. };
  211. /*
  212. * Common control flow change classifications:
  213. */
  214. enum {
  215. PERF_BR_UNKNOWN = 0, /* Unknown */
  216. PERF_BR_COND = 1, /* Conditional */
  217. PERF_BR_UNCOND = 2, /* Unconditional */
  218. PERF_BR_IND = 3, /* Indirect */
  219. PERF_BR_CALL = 4, /* Function call */
  220. PERF_BR_IND_CALL = 5, /* Indirect function call */
  221. PERF_BR_RET = 6, /* Function return */
  222. PERF_BR_SYSCALL = 7, /* Syscall */
  223. PERF_BR_SYSRET = 8, /* Syscall return */
  224. PERF_BR_COND_CALL = 9, /* Conditional function call */
  225. PERF_BR_COND_RET = 10, /* Conditional function return */
  226. PERF_BR_ERET = 11, /* Exception return */
  227. PERF_BR_IRQ = 12, /* IRQ */
  228. PERF_BR_SERROR = 13, /* System error */
  229. PERF_BR_NO_TX = 14, /* Not in transaction */
  230. PERF_BR_EXTEND_ABI = 15, /* Extend ABI */
  231. PERF_BR_MAX,
  232. };
  233. /*
  234. * Common branch speculation outcome classifications:
  235. */
  236. enum {
  237. PERF_BR_SPEC_NA = 0, /* Not available */
  238. PERF_BR_SPEC_WRONG_PATH = 1, /* Speculative but on wrong path */
  239. PERF_BR_NON_SPEC_CORRECT_PATH = 2, /* Non-speculative but on correct path */
  240. PERF_BR_SPEC_CORRECT_PATH = 3, /* Speculative and on correct path */
  241. PERF_BR_SPEC_MAX,
  242. };
  243. enum {
  244. PERF_BR_NEW_FAULT_ALGN = 0, /* Alignment fault */
  245. PERF_BR_NEW_FAULT_DATA = 1, /* Data fault */
  246. PERF_BR_NEW_FAULT_INST = 2, /* Inst fault */
  247. PERF_BR_NEW_ARCH_1 = 3, /* Architecture specific */
  248. PERF_BR_NEW_ARCH_2 = 4, /* Architecture specific */
  249. PERF_BR_NEW_ARCH_3 = 5, /* Architecture specific */
  250. PERF_BR_NEW_ARCH_4 = 6, /* Architecture specific */
  251. PERF_BR_NEW_ARCH_5 = 7, /* Architecture specific */
  252. PERF_BR_NEW_MAX,
  253. };
  254. enum {
  255. PERF_BR_PRIV_UNKNOWN = 0,
  256. PERF_BR_PRIV_USER = 1,
  257. PERF_BR_PRIV_KERNEL = 2,
  258. PERF_BR_PRIV_HV = 3,
  259. };
  260. #define PERF_BR_ARM64_FIQ PERF_BR_NEW_ARCH_1
  261. #define PERF_BR_ARM64_DEBUG_HALT PERF_BR_NEW_ARCH_2
  262. #define PERF_BR_ARM64_DEBUG_EXIT PERF_BR_NEW_ARCH_3
  263. #define PERF_BR_ARM64_DEBUG_INST PERF_BR_NEW_ARCH_4
  264. #define PERF_BR_ARM64_DEBUG_DATA PERF_BR_NEW_ARCH_5
  265. #define PERF_SAMPLE_BRANCH_PLM_ALL \
  266. (PERF_SAMPLE_BRANCH_USER|\
  267. PERF_SAMPLE_BRANCH_KERNEL|\
  268. PERF_SAMPLE_BRANCH_HV)
  269. /*
  270. * Values to determine ABI of the registers dump.
  271. */
  272. enum perf_sample_regs_abi {
  273. PERF_SAMPLE_REGS_ABI_NONE = 0,
  274. PERF_SAMPLE_REGS_ABI_32 = 1,
  275. PERF_SAMPLE_REGS_ABI_64 = 2,
  276. };
  277. /*
  278. * Values for the memory transaction event qualifier, mostly for
  279. * abort events. Multiple bits can be set.
  280. */
  281. enum {
  282. PERF_TXN_ELISION = (1 << 0), /* From elision */
  283. PERF_TXN_TRANSACTION = (1 << 1), /* From transaction */
  284. PERF_TXN_SYNC = (1 << 2), /* Instruction is related */
  285. PERF_TXN_ASYNC = (1 << 3), /* Instruction is not related */
  286. PERF_TXN_RETRY = (1 << 4), /* Retry possible */
  287. PERF_TXN_CONFLICT = (1 << 5), /* Conflict abort */
  288. PERF_TXN_CAPACITY_WRITE = (1 << 6), /* Capacity write abort */
  289. PERF_TXN_CAPACITY_READ = (1 << 7), /* Capacity read abort */
  290. PERF_TXN_MAX = (1 << 8), /* non-ABI */
  291. /* Bits 32..63 are reserved for the abort code */
  292. PERF_TXN_ABORT_MASK = (0xffffffffULL << 32),
  293. PERF_TXN_ABORT_SHIFT = 32,
  294. };
  295. /*
  296. * The format of the data returned by read() on a perf event fd,
  297. * as specified by attr.read_format:
  298. *
  299. * struct read_format {
  300. * { u64 value;
  301. * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED
  302. * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING
  303. * { u64 id; } && PERF_FORMAT_ID
  304. * { u64 lost; } && PERF_FORMAT_LOST
  305. * } && !PERF_FORMAT_GROUP
  306. *
  307. * { u64 nr;
  308. * { u64 time_enabled; } && PERF_FORMAT_TOTAL_TIME_ENABLED
  309. * { u64 time_running; } && PERF_FORMAT_TOTAL_TIME_RUNNING
  310. * { u64 value;
  311. * { u64 id; } && PERF_FORMAT_ID
  312. * { u64 lost; } && PERF_FORMAT_LOST
  313. * } cntr[nr];
  314. * } && PERF_FORMAT_GROUP
  315. * };
  316. */
  317. enum perf_event_read_format {
  318. PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
  319. PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
  320. PERF_FORMAT_ID = 1U << 2,
  321. PERF_FORMAT_GROUP = 1U << 3,
  322. PERF_FORMAT_LOST = 1U << 4,
  323. PERF_FORMAT_MAX = 1U << 5, /* non-ABI */
  324. };
  325. #define PERF_ATTR_SIZE_VER0 64 /* Size of first published 'struct perf_event_attr' */
  326. #define PERF_ATTR_SIZE_VER1 72 /* Add: config2 */
  327. #define PERF_ATTR_SIZE_VER2 80 /* Add: branch_sample_type */
  328. #define PERF_ATTR_SIZE_VER3 96 /* Add: sample_regs_user */
  329. /* Add: sample_stack_user */
  330. #define PERF_ATTR_SIZE_VER4 104 /* Add: sample_regs_intr */
  331. #define PERF_ATTR_SIZE_VER5 112 /* Add: aux_watermark */
  332. #define PERF_ATTR_SIZE_VER6 120 /* Add: aux_sample_size */
  333. #define PERF_ATTR_SIZE_VER7 128 /* Add: sig_data */
  334. #define PERF_ATTR_SIZE_VER8 136 /* Add: config3 */
  335. #define PERF_ATTR_SIZE_VER9 144 /* add: config4 */
  336. /*
  337. * 'struct perf_event_attr' contains various attributes that define
  338. * a performance event - most of them hardware related configuration
  339. * details, but also a lot of behavioral switches and values implemented
  340. * by the kernel.
  341. */
  342. struct perf_event_attr {
  343. /*
  344. * Major type: hardware/software/tracepoint/etc.
  345. */
  346. __u32 type;
  347. /*
  348. * Size of the attr structure, for forward/backwards compatibility.
  349. */
  350. __u32 size;
  351. /*
  352. * Type specific configuration information.
  353. */
  354. __u64 config;
  355. union {
  356. __u64 sample_period;
  357. __u64 sample_freq;
  358. };
  359. __u64 sample_type;
  360. __u64 read_format;
  361. __u64 disabled : 1, /* off by default */
  362. inherit : 1, /* children inherit it */
  363. pinned : 1, /* must always be on PMU */
  364. exclusive : 1, /* only group on PMU */
  365. exclude_user : 1, /* don't count user */
  366. exclude_kernel : 1, /* ditto kernel */
  367. exclude_hv : 1, /* ditto hypervisor */
  368. exclude_idle : 1, /* don't count when idle */
  369. mmap : 1, /* include mmap data */
  370. comm : 1, /* include comm data */
  371. freq : 1, /* use freq, not period */
  372. inherit_stat : 1, /* per task counts */
  373. enable_on_exec : 1, /* next exec enables */
  374. task : 1, /* trace fork/exit */
  375. watermark : 1, /* wakeup_watermark */
  376. /*
  377. * precise_ip:
  378. *
  379. * 0 - SAMPLE_IP can have arbitrary skid
  380. * 1 - SAMPLE_IP must have constant skid
  381. * 2 - SAMPLE_IP requested to have 0 skid
  382. * 3 - SAMPLE_IP must have 0 skid
  383. *
  384. * See also PERF_RECORD_MISC_EXACT_IP
  385. */
  386. precise_ip : 2, /* skid constraint */
  387. mmap_data : 1, /* non-exec mmap data */
  388. sample_id_all : 1, /* sample_type all events */
  389. exclude_host : 1, /* don't count in host */
  390. exclude_guest : 1, /* don't count in guest */
  391. exclude_callchain_kernel : 1, /* exclude kernel callchains */
  392. exclude_callchain_user : 1, /* exclude user callchains */
  393. mmap2 : 1, /* include mmap with inode data */
  394. comm_exec : 1, /* flag comm events that are due to an exec */
  395. use_clockid : 1, /* use @clockid for time fields */
  396. context_switch : 1, /* context switch data */
  397. write_backward : 1, /* write ring buffer from end to beginning */
  398. namespaces : 1, /* include namespaces data */
  399. ksymbol : 1, /* include ksymbol events */
  400. bpf_event : 1, /* include BPF events */
  401. aux_output : 1, /* generate AUX records instead of events */
  402. cgroup : 1, /* include cgroup events */
  403. text_poke : 1, /* include text poke events */
  404. build_id : 1, /* use build ID in mmap2 events */
  405. inherit_thread : 1, /* children only inherit if cloned with CLONE_THREAD */
  406. remove_on_exec : 1, /* event is removed from task on exec */
  407. sigtrap : 1, /* send synchronous SIGTRAP on event */
  408. defer_callchain: 1, /* request PERF_RECORD_CALLCHAIN_DEFERRED records */
  409. defer_output : 1, /* output PERF_RECORD_CALLCHAIN_DEFERRED records */
  410. __reserved_1 : 24;
  411. union {
  412. __u32 wakeup_events; /* wake up every n events */
  413. __u32 wakeup_watermark; /* bytes before wakeup */
  414. };
  415. __u32 bp_type;
  416. union {
  417. __u64 bp_addr;
  418. __u64 kprobe_func; /* for perf_kprobe */
  419. __u64 uprobe_path; /* for perf_uprobe */
  420. __u64 config1; /* extension of config */
  421. };
  422. union {
  423. __u64 bp_len;
  424. __u64 kprobe_addr; /* when kprobe_func == NULL */
  425. __u64 probe_offset; /* for perf_[k,u]probe */
  426. __u64 config2; /* extension of config1 */
  427. };
  428. __u64 branch_sample_type; /* enum perf_branch_sample_type */
  429. /*
  430. * Defines set of user regs to dump on samples.
  431. * See asm/perf_regs.h for details.
  432. */
  433. __u64 sample_regs_user;
  434. /*
  435. * Defines size of the user stack to dump on samples.
  436. */
  437. __u32 sample_stack_user;
  438. __s32 clockid;
  439. /*
  440. * Defines set of regs to dump for each sample
  441. * state captured on:
  442. * - precise = 0: PMU interrupt
  443. * - precise > 0: sampled instruction
  444. *
  445. * See asm/perf_regs.h for details.
  446. */
  447. __u64 sample_regs_intr;
  448. /*
  449. * Wakeup watermark for AUX area
  450. */
  451. __u32 aux_watermark;
  452. /*
  453. * Max number of frame pointers in a callchain, should be
  454. * lower than /proc/sys/kernel/perf_event_max_stack.
  455. *
  456. * Max number of entries of branch stack should be lower
  457. * than the hardware limit.
  458. */
  459. __u16 sample_max_stack;
  460. __u16 __reserved_2;
  461. __u32 aux_sample_size;
  462. union {
  463. __u32 aux_action;
  464. struct {
  465. __u32 aux_start_paused : 1, /* start AUX area tracing paused */
  466. aux_pause : 1, /* on overflow, pause AUX area tracing */
  467. aux_resume : 1, /* on overflow, resume AUX area tracing */
  468. __reserved_3 : 29;
  469. };
  470. };
  471. /*
  472. * User provided data if sigtrap=1, passed back to user via
  473. * siginfo_t::si_perf_data, e.g. to permit user to identify the event.
  474. * Note, siginfo_t::si_perf_data is long-sized, and sig_data will be
  475. * truncated accordingly on 32 bit architectures.
  476. */
  477. __u64 sig_data;
  478. __u64 config3; /* extension of config2 */
  479. __u64 config4; /* extension of config3 */
  480. };
  481. /*
  482. * Structure used by below PERF_EVENT_IOC_QUERY_BPF command
  483. * to query BPF programs attached to the same perf tracepoint
  484. * as the given perf event.
  485. */
  486. struct perf_event_query_bpf {
  487. /*
  488. * The below ids array length
  489. */
  490. __u32 ids_len;
  491. /*
  492. * Set by the kernel to indicate the number of
  493. * available programs
  494. */
  495. __u32 prog_cnt;
  496. /*
  497. * User provided buffer to store program ids
  498. */
  499. __u32 ids[];
  500. };
  501. /*
  502. * Ioctls that can be done on a perf event fd:
  503. */
  504. #define PERF_EVENT_IOC_ENABLE _IO ('$', 0)
  505. #define PERF_EVENT_IOC_DISABLE _IO ('$', 1)
  506. #define PERF_EVENT_IOC_REFRESH _IO ('$', 2)
  507. #define PERF_EVENT_IOC_RESET _IO ('$', 3)
  508. #define PERF_EVENT_IOC_PERIOD _IOW ('$', 4, __u64)
  509. #define PERF_EVENT_IOC_SET_OUTPUT _IO ('$', 5)
  510. #define PERF_EVENT_IOC_SET_FILTER _IOW ('$', 6, char *)
  511. #define PERF_EVENT_IOC_ID _IOR ('$', 7, __u64 *)
  512. #define PERF_EVENT_IOC_SET_BPF _IOW ('$', 8, __u32)
  513. #define PERF_EVENT_IOC_PAUSE_OUTPUT _IOW ('$', 9, __u32)
  514. #define PERF_EVENT_IOC_QUERY_BPF _IOWR('$', 10, struct perf_event_query_bpf *)
  515. #define PERF_EVENT_IOC_MODIFY_ATTRIBUTES _IOW ('$', 11, struct perf_event_attr *)
  516. enum perf_event_ioc_flags {
  517. PERF_IOC_FLAG_GROUP = 1U << 0,
  518. };
  519. /*
  520. * Structure of the page that can be mapped via mmap
  521. */
  522. struct perf_event_mmap_page {
  523. __u32 version; /* version number of this structure */
  524. __u32 compat_version; /* lowest version this is compat with */
  525. /*
  526. * Bits needed to read the HW events in user-space.
  527. *
  528. * u32 seq, time_mult, time_shift, index, width;
  529. * u64 count, enabled, running;
  530. * u64 cyc, time_offset;
  531. * s64 pmc = 0;
  532. *
  533. * do {
  534. * seq = pc->lock;
  535. * barrier()
  536. *
  537. * enabled = pc->time_enabled;
  538. * running = pc->time_running;
  539. *
  540. * if (pc->cap_usr_time && enabled != running) {
  541. * cyc = rdtsc();
  542. * time_offset = pc->time_offset;
  543. * time_mult = pc->time_mult;
  544. * time_shift = pc->time_shift;
  545. * }
  546. *
  547. * index = pc->index;
  548. * count = pc->offset;
  549. * if (pc->cap_user_rdpmc && index) {
  550. * width = pc->pmc_width;
  551. * pmc = rdpmc(index - 1);
  552. * }
  553. *
  554. * barrier();
  555. * } while (pc->lock != seq);
  556. *
  557. * NOTE: for obvious reason this only works on self-monitoring
  558. * processes.
  559. */
  560. __u32 lock; /* seqlock for synchronization */
  561. __u32 index; /* hardware event identifier */
  562. __s64 offset; /* add to hardware event value */
  563. __u64 time_enabled; /* time event active */
  564. __u64 time_running; /* time event on CPU */
  565. union {
  566. __u64 capabilities;
  567. struct {
  568. __u64 cap_bit0 : 1, /* Always 0, deprecated, see commit 860f085b74e9 */
  569. cap_bit0_is_deprecated : 1, /* Always 1, signals that bit 0 is zero */
  570. cap_user_rdpmc : 1, /* The RDPMC instruction can be used to read counts */
  571. cap_user_time : 1, /* The time_{shift,mult,offset} fields are used */
  572. cap_user_time_zero : 1, /* The time_zero field is used */
  573. cap_user_time_short : 1, /* the time_{cycle,mask} fields are used */
  574. cap_____res : 58;
  575. };
  576. };
  577. /*
  578. * If cap_user_rdpmc this field provides the bit-width of the value
  579. * read using the rdpmc() or equivalent instruction. This can be used
  580. * to sign extend the result like:
  581. *
  582. * pmc <<= 64 - width;
  583. * pmc >>= 64 - width; // signed shift right
  584. * count += pmc;
  585. */
  586. __u16 pmc_width;
  587. /*
  588. * If cap_usr_time the below fields can be used to compute the time
  589. * delta since time_enabled (in ns) using RDTSC or similar.
  590. *
  591. * u64 quot, rem;
  592. * u64 delta;
  593. *
  594. * quot = (cyc >> time_shift);
  595. * rem = cyc & (((u64)1 << time_shift) - 1);
  596. * delta = time_offset + quot * time_mult +
  597. * ((rem * time_mult) >> time_shift);
  598. *
  599. * Where time_offset,time_mult,time_shift and cyc are read in the
  600. * seqcount loop described above. This delta can then be added to
  601. * enabled and possible running (if index), improving the scaling:
  602. *
  603. * enabled += delta;
  604. * if (index)
  605. * running += delta;
  606. *
  607. * quot = count / running;
  608. * rem = count % running;
  609. * count = quot * enabled + (rem * enabled) / running;
  610. */
  611. __u16 time_shift;
  612. __u32 time_mult;
  613. __u64 time_offset;
  614. /*
  615. * If cap_usr_time_zero, the hardware clock (e.g. TSC) can be calculated
  616. * from sample timestamps.
  617. *
  618. * time = timestamp - time_zero;
  619. * quot = time / time_mult;
  620. * rem = time % time_mult;
  621. * cyc = (quot << time_shift) + (rem << time_shift) / time_mult;
  622. *
  623. * And vice versa:
  624. *
  625. * quot = cyc >> time_shift;
  626. * rem = cyc & (((u64)1 << time_shift) - 1);
  627. * timestamp = time_zero + quot * time_mult +
  628. * ((rem * time_mult) >> time_shift);
  629. */
  630. __u64 time_zero;
  631. __u32 size; /* Header size up to __reserved[] fields. */
  632. __u32 __reserved_1;
  633. /*
  634. * If cap_usr_time_short, the hardware clock is less than 64bit wide
  635. * and we must compute the 'cyc' value, as used by cap_usr_time, as:
  636. *
  637. * cyc = time_cycles + ((cyc - time_cycles) & time_mask)
  638. *
  639. * NOTE: this form is explicitly chosen such that cap_usr_time_short
  640. * is a correction on top of cap_usr_time, and code that doesn't
  641. * know about cap_usr_time_short still works under the assumption
  642. * the counter doesn't wrap.
  643. */
  644. __u64 time_cycles;
  645. __u64 time_mask;
  646. /*
  647. * Hole for extension of the self monitor capabilities
  648. */
  649. __u8 __reserved[116*8]; /* align to 1k. */
  650. /*
  651. * Control data for the mmap() data buffer.
  652. *
  653. * User-space reading the @data_head value should issue an smp_rmb(),
  654. * after reading this value.
  655. *
  656. * When the mapping is PROT_WRITE the @data_tail value should be
  657. * written by user-space to reflect the last read data, after issuing
  658. * an smp_mb() to separate the data read from the ->data_tail store.
  659. * In this case the kernel will not over-write unread data.
  660. *
  661. * See perf_output_put_handle() for the data ordering.
  662. *
  663. * data_{offset,size} indicate the location and size of the perf record
  664. * buffer within the mmapped area.
  665. */
  666. __u64 data_head; /* head in the data section */
  667. __u64 data_tail; /* user-space written tail */
  668. __u64 data_offset; /* where the buffer starts */
  669. __u64 data_size; /* data buffer size */
  670. /*
  671. * AUX area is defined by aux_{offset,size} fields that should be set
  672. * by the user-space, so that
  673. *
  674. * aux_offset >= data_offset + data_size
  675. *
  676. * prior to mmap()ing it. Size of the mmap()ed area should be aux_size.
  677. *
  678. * Ring buffer pointers aux_{head,tail} have the same semantics as
  679. * data_{head,tail} and same ordering rules apply.
  680. */
  681. __u64 aux_head;
  682. __u64 aux_tail;
  683. __u64 aux_offset;
  684. __u64 aux_size;
  685. };
  686. /*
  687. * The current state of perf_event_header::misc bits usage:
  688. * ('|' used bit, '-' unused bit)
  689. *
  690. * 012 CDEF
  691. * |||---------||||
  692. *
  693. * Where:
  694. * 0-2 CPUMODE_MASK
  695. *
  696. * C PROC_MAP_PARSE_TIMEOUT
  697. * D MMAP_DATA / COMM_EXEC / FORK_EXEC / SWITCH_OUT
  698. * E MMAP_BUILD_ID / EXACT_IP / SCHED_OUT_PREEMPT
  699. * F (reserved)
  700. */
  701. #define PERF_RECORD_MISC_CPUMODE_MASK (7 << 0)
  702. #define PERF_RECORD_MISC_CPUMODE_UNKNOWN (0 << 0)
  703. #define PERF_RECORD_MISC_KERNEL (1 << 0)
  704. #define PERF_RECORD_MISC_USER (2 << 0)
  705. #define PERF_RECORD_MISC_HYPERVISOR (3 << 0)
  706. #define PERF_RECORD_MISC_GUEST_KERNEL (4 << 0)
  707. #define PERF_RECORD_MISC_GUEST_USER (5 << 0)
  708. /*
  709. * Indicates that /proc/PID/maps parsing are truncated by time out.
  710. */
  711. #define PERF_RECORD_MISC_PROC_MAP_PARSE_TIMEOUT (1 << 12)
  712. /*
  713. * Following PERF_RECORD_MISC_* are used on different
  714. * events, so can reuse the same bit position:
  715. *
  716. * PERF_RECORD_MISC_MMAP_DATA - PERF_RECORD_MMAP* events
  717. * PERF_RECORD_MISC_COMM_EXEC - PERF_RECORD_COMM event
  718. * PERF_RECORD_MISC_FORK_EXEC - PERF_RECORD_FORK event (perf internal)
  719. * PERF_RECORD_MISC_SWITCH_OUT - PERF_RECORD_SWITCH* events
  720. */
  721. #define PERF_RECORD_MISC_MMAP_DATA (1 << 13)
  722. #define PERF_RECORD_MISC_COMM_EXEC (1 << 13)
  723. #define PERF_RECORD_MISC_FORK_EXEC (1 << 13)
  724. #define PERF_RECORD_MISC_SWITCH_OUT (1 << 13)
  725. /*
  726. * These PERF_RECORD_MISC_* flags below are safely reused
  727. * for the following events:
  728. *
  729. * PERF_RECORD_MISC_EXACT_IP - PERF_RECORD_SAMPLE of precise events
  730. * PERF_RECORD_MISC_SWITCH_OUT_PREEMPT - PERF_RECORD_SWITCH* events
  731. * PERF_RECORD_MISC_MMAP_BUILD_ID - PERF_RECORD_MMAP2 event
  732. *
  733. *
  734. * PERF_RECORD_MISC_EXACT_IP:
  735. * Indicates that the content of PERF_SAMPLE_IP points to
  736. * the actual instruction that triggered the event. See also
  737. * perf_event_attr::precise_ip.
  738. *
  739. * PERF_RECORD_MISC_SWITCH_OUT_PREEMPT:
  740. * Indicates that thread was preempted in TASK_RUNNING state.
  741. *
  742. * PERF_RECORD_MISC_MMAP_BUILD_ID:
  743. * Indicates that mmap2 event carries build ID data.
  744. */
  745. #define PERF_RECORD_MISC_EXACT_IP (1 << 14)
  746. #define PERF_RECORD_MISC_SWITCH_OUT_PREEMPT (1 << 14)
  747. #define PERF_RECORD_MISC_MMAP_BUILD_ID (1 << 14)
  748. /*
  749. * Reserve the last bit to indicate some extended misc field
  750. */
  751. #define PERF_RECORD_MISC_EXT_RESERVED (1 << 15)
  752. struct perf_event_header {
  753. __u32 type;
  754. __u16 misc;
  755. __u16 size;
  756. };
  757. struct perf_ns_link_info {
  758. __u64 dev;
  759. __u64 ino;
  760. };
  761. enum {
  762. NET_NS_INDEX = 0,
  763. UTS_NS_INDEX = 1,
  764. IPC_NS_INDEX = 2,
  765. PID_NS_INDEX = 3,
  766. USER_NS_INDEX = 4,
  767. MNT_NS_INDEX = 5,
  768. CGROUP_NS_INDEX = 6,
  769. NR_NAMESPACES, /* number of available namespaces */
  770. };
  771. enum perf_event_type {
  772. /*
  773. * If perf_event_attr.sample_id_all is set then all event types will
  774. * have the sample_type selected fields related to where/when
  775. * (identity) an event took place (TID, TIME, ID, STREAM_ID, CPU,
  776. * IDENTIFIER) described in PERF_RECORD_SAMPLE below, it will be stashed
  777. * just after the perf_event_header and the fields already present for
  778. * the existing fields, i.e. at the end of the payload. That way a newer
  779. * perf.data file will be supported by older perf tools, with these new
  780. * optional fields being ignored.
  781. *
  782. * struct sample_id {
  783. * { u32 pid, tid; } && PERF_SAMPLE_TID
  784. * { u64 time; } && PERF_SAMPLE_TIME
  785. * { u64 id; } && PERF_SAMPLE_ID
  786. * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
  787. * { u32 cpu, res; } && PERF_SAMPLE_CPU
  788. * { u64 id; } && PERF_SAMPLE_IDENTIFIER
  789. * } && perf_event_attr::sample_id_all
  790. *
  791. * Note that PERF_SAMPLE_IDENTIFIER duplicates PERF_SAMPLE_ID. The
  792. * advantage of PERF_SAMPLE_IDENTIFIER is that its position is fixed
  793. * relative to header.size.
  794. */
  795. /*
  796. * The MMAP events record the PROT_EXEC mappings so that we can
  797. * correlate user-space IPs to code. They have the following structure:
  798. *
  799. * struct {
  800. * struct perf_event_header header;
  801. *
  802. * u32 pid, tid;
  803. * u64 addr;
  804. * u64 len;
  805. * u64 pgoff;
  806. * char filename[];
  807. * struct sample_id sample_id;
  808. * };
  809. */
  810. PERF_RECORD_MMAP = 1,
  811. /*
  812. * struct {
  813. * struct perf_event_header header;
  814. * u64 id;
  815. * u64 lost;
  816. * struct sample_id sample_id;
  817. * };
  818. */
  819. PERF_RECORD_LOST = 2,
  820. /*
  821. * struct {
  822. * struct perf_event_header header;
  823. *
  824. * u32 pid, tid;
  825. * char comm[];
  826. * struct sample_id sample_id;
  827. * };
  828. */
  829. PERF_RECORD_COMM = 3,
  830. /*
  831. * struct {
  832. * struct perf_event_header header;
  833. * u32 pid, ppid;
  834. * u32 tid, ptid;
  835. * u64 time;
  836. * struct sample_id sample_id;
  837. * };
  838. */
  839. PERF_RECORD_EXIT = 4,
  840. /*
  841. * struct {
  842. * struct perf_event_header header;
  843. * u64 time;
  844. * u64 id;
  845. * u64 stream_id;
  846. * struct sample_id sample_id;
  847. * };
  848. */
  849. PERF_RECORD_THROTTLE = 5,
  850. PERF_RECORD_UNTHROTTLE = 6,
  851. /*
  852. * struct {
  853. * struct perf_event_header header;
  854. * u32 pid, ppid;
  855. * u32 tid, ptid;
  856. * u64 time;
  857. * struct sample_id sample_id;
  858. * };
  859. */
  860. PERF_RECORD_FORK = 7,
  861. /*
  862. * struct {
  863. * struct perf_event_header header;
  864. * u32 pid, tid;
  865. *
  866. * struct read_format values;
  867. * struct sample_id sample_id;
  868. * };
  869. */
  870. PERF_RECORD_READ = 8,
  871. /*
  872. * struct {
  873. * struct perf_event_header header;
  874. *
  875. * #
  876. * # Note that PERF_SAMPLE_IDENTIFIER duplicates PERF_SAMPLE_ID.
  877. * # The advantage of PERF_SAMPLE_IDENTIFIER is that its position
  878. * # is fixed relative to header.
  879. * #
  880. *
  881. * { u64 id; } && PERF_SAMPLE_IDENTIFIER
  882. * { u64 ip; } && PERF_SAMPLE_IP
  883. * { u32 pid, tid; } && PERF_SAMPLE_TID
  884. * { u64 time; } && PERF_SAMPLE_TIME
  885. * { u64 addr; } && PERF_SAMPLE_ADDR
  886. * { u64 id; } && PERF_SAMPLE_ID
  887. * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
  888. * { u32 cpu, res; } && PERF_SAMPLE_CPU
  889. * { u64 period; } && PERF_SAMPLE_PERIOD
  890. *
  891. * { struct read_format values; } && PERF_SAMPLE_READ
  892. *
  893. * { u64 nr,
  894. * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
  895. *
  896. * #
  897. * # The RAW record below is opaque data wrt the ABI
  898. * #
  899. * # That is, the ABI doesn't make any promises wrt to
  900. * # the stability of its content, it may vary depending
  901. * # on event, hardware, kernel version and phase of
  902. * # the moon.
  903. * #
  904. * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
  905. * #
  906. *
  907. * { u32 size;
  908. * char data[size];}&& PERF_SAMPLE_RAW
  909. *
  910. * { u64 nr;
  911. * { u64 hw_idx; } && PERF_SAMPLE_BRANCH_HW_INDEX
  912. * { u64 from, to, flags } lbr[nr];
  913. * #
  914. * # The format of the counters is decided by the
  915. * # "branch_counter_nr" and "branch_counter_width",
  916. * # which are defined in the ABI.
  917. * #
  918. * { u64 counters; } cntr[nr] && PERF_SAMPLE_BRANCH_COUNTERS
  919. * } && PERF_SAMPLE_BRANCH_STACK
  920. *
  921. * { u64 abi; # enum perf_sample_regs_abi
  922. * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_USER
  923. *
  924. * { u64 size;
  925. * char data[size];
  926. * u64 dyn_size; } && PERF_SAMPLE_STACK_USER
  927. *
  928. * { union perf_sample_weight
  929. * {
  930. * u64 full; && PERF_SAMPLE_WEIGHT
  931. * #if defined(__LITTLE_ENDIAN_BITFIELD)
  932. * struct {
  933. * u32 var1_dw;
  934. * u16 var2_w;
  935. * u16 var3_w;
  936. * } && PERF_SAMPLE_WEIGHT_STRUCT
  937. * #elif defined(__BIG_ENDIAN_BITFIELD)
  938. * struct {
  939. * u16 var3_w;
  940. * u16 var2_w;
  941. * u32 var1_dw;
  942. * } && PERF_SAMPLE_WEIGHT_STRUCT
  943. * #endif
  944. * }
  945. * }
  946. * { u64 data_src; } && PERF_SAMPLE_DATA_SRC
  947. * { u64 transaction; } && PERF_SAMPLE_TRANSACTION
  948. * { u64 abi; # enum perf_sample_regs_abi
  949. * u64 regs[weight(mask)]; } && PERF_SAMPLE_REGS_INTR
  950. * { u64 phys_addr;} && PERF_SAMPLE_PHYS_ADDR
  951. * { u64 cgroup;} && PERF_SAMPLE_CGROUP
  952. * { u64 data_page_size;} && PERF_SAMPLE_DATA_PAGE_SIZE
  953. * { u64 code_page_size;} && PERF_SAMPLE_CODE_PAGE_SIZE
  954. * { u64 size;
  955. * char data[size]; } && PERF_SAMPLE_AUX
  956. * };
  957. */
  958. PERF_RECORD_SAMPLE = 9,
  959. /*
  960. * The MMAP2 records are an augmented version of MMAP, they add
  961. * maj, min, ino numbers to be used to uniquely identify each mapping
  962. *
  963. * struct {
  964. * struct perf_event_header header;
  965. *
  966. * u32 pid, tid;
  967. * u64 addr;
  968. * u64 len;
  969. * u64 pgoff;
  970. * union {
  971. * struct {
  972. * u32 maj;
  973. * u32 min;
  974. * u64 ino;
  975. * u64 ino_generation;
  976. * };
  977. * struct {
  978. * u8 build_id_size;
  979. * u8 __reserved_1;
  980. * u16 __reserved_2;
  981. * u8 build_id[20];
  982. * };
  983. * };
  984. * u32 prot, flags;
  985. * char filename[];
  986. * struct sample_id sample_id;
  987. * };
  988. */
  989. PERF_RECORD_MMAP2 = 10,
  990. /*
  991. * Records that new data landed in the AUX buffer part.
  992. *
  993. * struct {
  994. * struct perf_event_header header;
  995. *
  996. * u64 aux_offset;
  997. * u64 aux_size;
  998. * u64 flags;
  999. * struct sample_id sample_id;
  1000. * };
  1001. */
  1002. PERF_RECORD_AUX = 11,
  1003. /*
  1004. * Indicates that instruction trace has started
  1005. *
  1006. * struct {
  1007. * struct perf_event_header header;
  1008. * u32 pid;
  1009. * u32 tid;
  1010. * struct sample_id sample_id;
  1011. * };
  1012. */
  1013. PERF_RECORD_ITRACE_START = 12,
  1014. /*
  1015. * Records the dropped/lost sample number.
  1016. *
  1017. * struct {
  1018. * struct perf_event_header header;
  1019. *
  1020. * u64 lost;
  1021. * struct sample_id sample_id;
  1022. * };
  1023. */
  1024. PERF_RECORD_LOST_SAMPLES = 13,
  1025. /*
  1026. * Records a context switch in or out (flagged by
  1027. * PERF_RECORD_MISC_SWITCH_OUT). See also
  1028. * PERF_RECORD_SWITCH_CPU_WIDE.
  1029. *
  1030. * struct {
  1031. * struct perf_event_header header;
  1032. * struct sample_id sample_id;
  1033. * };
  1034. */
  1035. PERF_RECORD_SWITCH = 14,
  1036. /*
  1037. * CPU-wide version of PERF_RECORD_SWITCH with next_prev_pid and
  1038. * next_prev_tid that are the next (switching out) or previous
  1039. * (switching in) pid/tid.
  1040. *
  1041. * struct {
  1042. * struct perf_event_header header;
  1043. * u32 next_prev_pid;
  1044. * u32 next_prev_tid;
  1045. * struct sample_id sample_id;
  1046. * };
  1047. */
  1048. PERF_RECORD_SWITCH_CPU_WIDE = 15,
  1049. /*
  1050. * struct {
  1051. * struct perf_event_header header;
  1052. * u32 pid;
  1053. * u32 tid;
  1054. * u64 nr_namespaces;
  1055. * { u64 dev, inode; } [nr_namespaces];
  1056. * struct sample_id sample_id;
  1057. * };
  1058. */
  1059. PERF_RECORD_NAMESPACES = 16,
  1060. /*
  1061. * Record ksymbol register/unregister events:
  1062. *
  1063. * struct {
  1064. * struct perf_event_header header;
  1065. * u64 addr;
  1066. * u32 len;
  1067. * u16 ksym_type;
  1068. * u16 flags;
  1069. * char name[];
  1070. * struct sample_id sample_id;
  1071. * };
  1072. */
  1073. PERF_RECORD_KSYMBOL = 17,
  1074. /*
  1075. * Record BPF events:
  1076. * enum perf_bpf_event_type {
  1077. * PERF_BPF_EVENT_UNKNOWN = 0,
  1078. * PERF_BPF_EVENT_PROG_LOAD = 1,
  1079. * PERF_BPF_EVENT_PROG_UNLOAD = 2,
  1080. * };
  1081. *
  1082. * struct {
  1083. * struct perf_event_header header;
  1084. * u16 type;
  1085. * u16 flags;
  1086. * u32 id;
  1087. * u8 tag[BPF_TAG_SIZE];
  1088. * struct sample_id sample_id;
  1089. * };
  1090. */
  1091. PERF_RECORD_BPF_EVENT = 18,
  1092. /*
  1093. * struct {
  1094. * struct perf_event_header header;
  1095. * u64 id;
  1096. * char path[];
  1097. * struct sample_id sample_id;
  1098. * };
  1099. */
  1100. PERF_RECORD_CGROUP = 19,
  1101. /*
  1102. * Records changes to kernel text i.e. self-modified code. 'old_len' is
  1103. * the number of old bytes, 'new_len' is the number of new bytes. Either
  1104. * 'old_len' or 'new_len' may be zero to indicate, for example, the
  1105. * addition or removal of a trampoline. 'bytes' contains the old bytes
  1106. * followed immediately by the new bytes.
  1107. *
  1108. * struct {
  1109. * struct perf_event_header header;
  1110. * u64 addr;
  1111. * u16 old_len;
  1112. * u16 new_len;
  1113. * u8 bytes[];
  1114. * struct sample_id sample_id;
  1115. * };
  1116. */
  1117. PERF_RECORD_TEXT_POKE = 20,
  1118. /*
  1119. * Data written to the AUX area by hardware due to aux_output, may need
  1120. * to be matched to the event by an architecture-specific hardware ID.
  1121. * This records the hardware ID, but requires sample_id to provide the
  1122. * event ID. e.g. Intel PT uses this record to disambiguate PEBS-via-PT
  1123. * records from multiple events.
  1124. *
  1125. * struct {
  1126. * struct perf_event_header header;
  1127. * u64 hw_id;
  1128. * struct sample_id sample_id;
  1129. * };
  1130. */
  1131. PERF_RECORD_AUX_OUTPUT_HW_ID = 21,
  1132. /*
  1133. * This user callchain capture was deferred until shortly before
  1134. * returning to user space. Previous samples would have kernel
  1135. * callchains only and they need to be stitched with this to make full
  1136. * callchains.
  1137. *
  1138. * struct {
  1139. * struct perf_event_header header;
  1140. * u64 cookie;
  1141. * u64 nr;
  1142. * u64 ips[nr];
  1143. * struct sample_id sample_id;
  1144. * };
  1145. */
  1146. PERF_RECORD_CALLCHAIN_DEFERRED = 22,
  1147. PERF_RECORD_MAX, /* non-ABI */
  1148. };
  1149. enum perf_record_ksymbol_type {
  1150. PERF_RECORD_KSYMBOL_TYPE_UNKNOWN = 0,
  1151. PERF_RECORD_KSYMBOL_TYPE_BPF = 1,
  1152. /*
  1153. * Out of line code such as kprobe-replaced instructions or optimized
  1154. * kprobes or ftrace trampolines.
  1155. */
  1156. PERF_RECORD_KSYMBOL_TYPE_OOL = 2,
  1157. PERF_RECORD_KSYMBOL_TYPE_MAX /* non-ABI */
  1158. };
  1159. #define PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER (1 << 0)
  1160. enum perf_bpf_event_type {
  1161. PERF_BPF_EVENT_UNKNOWN = 0,
  1162. PERF_BPF_EVENT_PROG_LOAD = 1,
  1163. PERF_BPF_EVENT_PROG_UNLOAD = 2,
  1164. PERF_BPF_EVENT_MAX, /* non-ABI */
  1165. };
  1166. #define PERF_MAX_STACK_DEPTH 127
  1167. #define PERF_MAX_CONTEXTS_PER_STACK 8
  1168. enum perf_callchain_context {
  1169. PERF_CONTEXT_HV = (__u64)-32,
  1170. PERF_CONTEXT_KERNEL = (__u64)-128,
  1171. PERF_CONTEXT_USER = (__u64)-512,
  1172. PERF_CONTEXT_USER_DEFERRED = (__u64)-640,
  1173. PERF_CONTEXT_GUEST = (__u64)-2048,
  1174. PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
  1175. PERF_CONTEXT_GUEST_USER = (__u64)-2560,
  1176. PERF_CONTEXT_MAX = (__u64)-4095,
  1177. };
  1178. /**
  1179. * PERF_RECORD_AUX::flags bits
  1180. */
  1181. #define PERF_AUX_FLAG_TRUNCATED 0x0001 /* Record was truncated to fit */
  1182. #define PERF_AUX_FLAG_OVERWRITE 0x0002 /* Snapshot from overwrite mode */
  1183. #define PERF_AUX_FLAG_PARTIAL 0x0004 /* Record contains gaps */
  1184. #define PERF_AUX_FLAG_COLLISION 0x0008 /* Sample collided with another */
  1185. #define PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK 0xff00 /* PMU specific trace format type */
  1186. /* CoreSight PMU AUX buffer formats */
  1187. #define PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT 0x0000 /* Default for backward compatibility */
  1188. #define PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW 0x0100 /* Raw format of the source */
  1189. #define PERF_FLAG_FD_NO_GROUP (1UL << 0)
  1190. #define PERF_FLAG_FD_OUTPUT (1UL << 1)
  1191. #define PERF_FLAG_PID_CGROUP (1UL << 2) /* pid=cgroup ID, per-CPU mode only */
  1192. #define PERF_FLAG_FD_CLOEXEC (1UL << 3) /* O_CLOEXEC */
  1193. #if defined(__LITTLE_ENDIAN_BITFIELD)
  1194. union perf_mem_data_src {
  1195. __u64 val;
  1196. struct {
  1197. __u64 mem_op : 5, /* Type of opcode */
  1198. mem_lvl : 14, /* Memory hierarchy level */
  1199. mem_snoop : 5, /* Snoop mode */
  1200. mem_lock : 2, /* Lock instr */
  1201. mem_dtlb : 7, /* TLB access */
  1202. mem_lvl_num : 4, /* Memory hierarchy level number */
  1203. mem_remote : 1, /* Remote */
  1204. mem_snoopx : 2, /* Snoop mode, ext */
  1205. mem_blk : 3, /* Access blocked */
  1206. mem_hops : 3, /* Hop level */
  1207. mem_region : 5, /* cache/memory regions */
  1208. mem_rsvd : 13;
  1209. };
  1210. };
  1211. #elif defined(__BIG_ENDIAN_BITFIELD)
  1212. union perf_mem_data_src {
  1213. __u64 val;
  1214. struct {
  1215. __u64 mem_rsvd : 13,
  1216. mem_region : 5, /* cache/memory regions */
  1217. mem_hops : 3, /* Hop level */
  1218. mem_blk : 3, /* Access blocked */
  1219. mem_snoopx : 2, /* Snoop mode, ext */
  1220. mem_remote : 1, /* Remote */
  1221. mem_lvl_num : 4, /* Memory hierarchy level number */
  1222. mem_dtlb : 7, /* TLB access */
  1223. mem_lock : 2, /* Lock instr */
  1224. mem_snoop : 5, /* Snoop mode */
  1225. mem_lvl : 14, /* Memory hierarchy level */
  1226. mem_op : 5; /* Type of opcode */
  1227. };
  1228. };
  1229. #else
  1230. # error "Unknown endianness"
  1231. #endif
  1232. /* Type of memory opcode: */
  1233. #define PERF_MEM_OP_NA 0x0001 /* Not available */
  1234. #define PERF_MEM_OP_LOAD 0x0002 /* Load instruction */
  1235. #define PERF_MEM_OP_STORE 0x0004 /* Store instruction */
  1236. #define PERF_MEM_OP_PFETCH 0x0008 /* Prefetch */
  1237. #define PERF_MEM_OP_EXEC 0x0010 /* Code (execution) */
  1238. #define PERF_MEM_OP_SHIFT 0
  1239. /*
  1240. * The PERF_MEM_LVL_* namespace is being deprecated to some extent in
  1241. * favour of newer composite PERF_MEM_{LVLNUM_,REMOTE_,SNOOPX_} fields.
  1242. * We support this namespace in order to not break defined ABIs.
  1243. *
  1244. * Memory hierarchy (memory level, hit or miss)
  1245. */
  1246. #define PERF_MEM_LVL_NA 0x0001 /* Not available */
  1247. #define PERF_MEM_LVL_HIT 0x0002 /* Hit level */
  1248. #define PERF_MEM_LVL_MISS 0x0004 /* Miss level */
  1249. #define PERF_MEM_LVL_L1 0x0008 /* L1 */
  1250. #define PERF_MEM_LVL_LFB 0x0010 /* Line Fill Buffer */
  1251. #define PERF_MEM_LVL_L2 0x0020 /* L2 */
  1252. #define PERF_MEM_LVL_L3 0x0040 /* L3 */
  1253. #define PERF_MEM_LVL_LOC_RAM 0x0080 /* Local DRAM */
  1254. #define PERF_MEM_LVL_REM_RAM1 0x0100 /* Remote DRAM (1 hop) */
  1255. #define PERF_MEM_LVL_REM_RAM2 0x0200 /* Remote DRAM (2 hops) */
  1256. #define PERF_MEM_LVL_REM_CCE1 0x0400 /* Remote Cache (1 hop) */
  1257. #define PERF_MEM_LVL_REM_CCE2 0x0800 /* Remote Cache (2 hops) */
  1258. #define PERF_MEM_LVL_IO 0x1000 /* I/O memory */
  1259. #define PERF_MEM_LVL_UNC 0x2000 /* Uncached memory */
  1260. #define PERF_MEM_LVL_SHIFT 5
  1261. #define PERF_MEM_REMOTE_REMOTE 0x0001 /* Remote */
  1262. #define PERF_MEM_REMOTE_SHIFT 37
  1263. #define PERF_MEM_LVLNUM_L1 0x0001 /* L1 */
  1264. #define PERF_MEM_LVLNUM_L2 0x0002 /* L2 */
  1265. #define PERF_MEM_LVLNUM_L3 0x0003 /* L3 */
  1266. #define PERF_MEM_LVLNUM_L4 0x0004 /* L4 */
  1267. #define PERF_MEM_LVLNUM_L2_MHB 0x0005 /* L2 Miss Handling Buffer */
  1268. #define PERF_MEM_LVLNUM_MSC 0x0006 /* Memory-side Cache */
  1269. #define PERF_MEM_LVLNUM_L0 0x0007 /* L0 */
  1270. #define PERF_MEM_LVLNUM_UNC 0x0008 /* Uncached */
  1271. #define PERF_MEM_LVLNUM_CXL 0x0009 /* CXL */
  1272. #define PERF_MEM_LVLNUM_IO 0x000a /* I/O */
  1273. #define PERF_MEM_LVLNUM_ANY_CACHE 0x000b /* Any cache */
  1274. #define PERF_MEM_LVLNUM_LFB 0x000c /* LFB / L1 Miss Handling Buffer */
  1275. #define PERF_MEM_LVLNUM_RAM 0x000d /* RAM */
  1276. #define PERF_MEM_LVLNUM_PMEM 0x000e /* PMEM */
  1277. #define PERF_MEM_LVLNUM_NA 0x000f /* N/A */
  1278. #define PERF_MEM_LVLNUM_SHIFT 33
  1279. /* Snoop mode */
  1280. #define PERF_MEM_SNOOP_NA 0x0001 /* Not available */
  1281. #define PERF_MEM_SNOOP_NONE 0x0002 /* No snoop */
  1282. #define PERF_MEM_SNOOP_HIT 0x0004 /* Snoop hit */
  1283. #define PERF_MEM_SNOOP_MISS 0x0008 /* Snoop miss */
  1284. #define PERF_MEM_SNOOP_HITM 0x0010 /* Snoop hit modified */
  1285. #define PERF_MEM_SNOOP_SHIFT 19
  1286. #define PERF_MEM_SNOOPX_FWD 0x0001 /* Forward */
  1287. #define PERF_MEM_SNOOPX_PEER 0x0002 /* Transfer from peer */
  1288. #define PERF_MEM_SNOOPX_SHIFT 38
  1289. /* Locked instruction */
  1290. #define PERF_MEM_LOCK_NA 0x0001 /* Not available */
  1291. #define PERF_MEM_LOCK_LOCKED 0x0002 /* Locked transaction */
  1292. #define PERF_MEM_LOCK_SHIFT 24
  1293. /* TLB access */
  1294. #define PERF_MEM_TLB_NA 0x0001 /* Not available */
  1295. #define PERF_MEM_TLB_HIT 0x0002 /* Hit level */
  1296. #define PERF_MEM_TLB_MISS 0x0004 /* Miss level */
  1297. #define PERF_MEM_TLB_L1 0x0008 /* L1 */
  1298. #define PERF_MEM_TLB_L2 0x0010 /* L2 */
  1299. #define PERF_MEM_TLB_WK 0x0020 /* Hardware Walker*/
  1300. #define PERF_MEM_TLB_OS 0x0040 /* OS fault handler */
  1301. #define PERF_MEM_TLB_SHIFT 26
  1302. /* Access blocked */
  1303. #define PERF_MEM_BLK_NA 0x0001 /* Not available */
  1304. #define PERF_MEM_BLK_DATA 0x0002 /* Data could not be forwarded */
  1305. #define PERF_MEM_BLK_ADDR 0x0004 /* Address conflict */
  1306. #define PERF_MEM_BLK_SHIFT 40
  1307. /* Hop level */
  1308. #define PERF_MEM_HOPS_0 0x0001 /* Remote core, same node */
  1309. #define PERF_MEM_HOPS_1 0x0002 /* Remote node, same socket */
  1310. #define PERF_MEM_HOPS_2 0x0003 /* Remote socket, same board */
  1311. #define PERF_MEM_HOPS_3 0x0004 /* Remote board */
  1312. /* 5-7 available */
  1313. #define PERF_MEM_HOPS_SHIFT 43
  1314. /* Cache/Memory region */
  1315. #define PERF_MEM_REGION_NA 0x0 /* Invalid */
  1316. #define PERF_MEM_REGION_RSVD 0x01 /* Reserved */
  1317. #define PERF_MEM_REGION_L_SHARE 0x02 /* Local CA shared cache */
  1318. #define PERF_MEM_REGION_L_NON_SHARE 0x03 /* Local CA non-shared cache */
  1319. #define PERF_MEM_REGION_O_IO 0x04 /* Other CA IO agent */
  1320. #define PERF_MEM_REGION_O_SHARE 0x05 /* Other CA shared cache */
  1321. #define PERF_MEM_REGION_O_NON_SHARE 0x06 /* Other CA non-shared cache */
  1322. #define PERF_MEM_REGION_MMIO 0x07 /* MMIO */
  1323. #define PERF_MEM_REGION_MEM0 0x08 /* Memory region 0 */
  1324. #define PERF_MEM_REGION_MEM1 0x09 /* Memory region 1 */
  1325. #define PERF_MEM_REGION_MEM2 0x0a /* Memory region 2 */
  1326. #define PERF_MEM_REGION_MEM3 0x0b /* Memory region 3 */
  1327. #define PERF_MEM_REGION_MEM4 0x0c /* Memory region 4 */
  1328. #define PERF_MEM_REGION_MEM5 0x0d /* Memory region 5 */
  1329. #define PERF_MEM_REGION_MEM6 0x0e /* Memory region 6 */
  1330. #define PERF_MEM_REGION_MEM7 0x0f /* Memory region 7 */
  1331. #define PERF_MEM_REGION_SHIFT 46
  1332. #define PERF_MEM_S(a, s) \
  1333. (((__u64)PERF_MEM_##a##_##s) << PERF_MEM_##a##_SHIFT)
  1334. /*
  1335. * Layout of single taken branch records:
  1336. *
  1337. * from: source instruction (may not always be a branch insn)
  1338. * to: branch target
  1339. * mispred: branch target was mispredicted
  1340. * predicted: branch target was predicted
  1341. *
  1342. * support for mispred, predicted is optional. In case it
  1343. * is not supported mispred = predicted = 0.
  1344. *
  1345. * in_tx: running in a hardware transaction
  1346. * abort: aborting a hardware transaction
  1347. * cycles: cycles from last branch (or 0 if not supported)
  1348. * type: branch type
  1349. * spec: branch speculation info (or 0 if not supported)
  1350. */
  1351. struct perf_branch_entry {
  1352. __u64 from;
  1353. __u64 to;
  1354. __u64 mispred : 1, /* target mispredicted */
  1355. predicted : 1, /* target predicted */
  1356. in_tx : 1, /* in transaction */
  1357. abort : 1, /* transaction abort */
  1358. cycles : 16, /* cycle count to last branch */
  1359. type : 4, /* branch type */
  1360. spec : 2, /* branch speculation info */
  1361. new_type : 4, /* additional branch type */
  1362. priv : 3, /* privilege level */
  1363. reserved : 31;
  1364. };
  1365. /* Size of used info bits in struct perf_branch_entry */
  1366. #define PERF_BRANCH_ENTRY_INFO_BITS_MAX 33
  1367. union perf_sample_weight {
  1368. __u64 full;
  1369. #if defined(__LITTLE_ENDIAN_BITFIELD)
  1370. struct {
  1371. __u32 var1_dw;
  1372. __u16 var2_w;
  1373. __u16 var3_w;
  1374. };
  1375. #elif defined(__BIG_ENDIAN_BITFIELD)
  1376. struct {
  1377. __u16 var3_w;
  1378. __u16 var2_w;
  1379. __u32 var1_dw;
  1380. };
  1381. #else
  1382. # error "Unknown endianness"
  1383. #endif
  1384. };
  1385. #endif /* _UAPI_LINUX_PERF_EVENT_H */