perf_counter.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /*
  2. * NOTE: this file will be removed in a future kernel release, it is
  3. * provided as a courtesy copy of user-space code that relies on the
  4. * old (pre-rename) symbols and constants.
  5. *
  6. * Performance events:
  7. *
  8. * Copyright (C) 2008-2009, Thomas Gleixner <tglx@linutronix.de>
  9. * Copyright (C) 2008-2009, Red Hat, Inc., Ingo Molnar
  10. * Copyright (C) 2008-2009, Red Hat, Inc., Peter Zijlstra
  11. *
  12. * Data type definitions, declarations, prototypes.
  13. *
  14. * Started by: Thomas Gleixner and Ingo Molnar
  15. *
  16. * For licencing details see kernel-base/COPYING
  17. */
  18. #ifndef _LINUX_PERF_COUNTER_H
  19. #define _LINUX_PERF_COUNTER_H
  20. #include <linux/types.h>
  21. #include <linux/ioctl.h>
  22. #include <asm/byteorder.h>
  23. /*
  24. * User-space ABI bits:
  25. */
  26. /*
  27. * attr.type
  28. */
  29. enum perf_type_id {
  30. PERF_TYPE_HARDWARE = 0,
  31. PERF_TYPE_SOFTWARE = 1,
  32. PERF_TYPE_TRACEPOINT = 2,
  33. PERF_TYPE_HW_CACHE = 3,
  34. PERF_TYPE_RAW = 4,
  35. PERF_TYPE_MAX, /* non-ABI */
  36. };
  37. /*
  38. * Generalized performance counter event types, used by the
  39. * attr.event_id parameter of the sys_perf_counter_open()
  40. * syscall:
  41. */
  42. enum perf_hw_id {
  43. /*
  44. * Common hardware events, generalized by the kernel:
  45. */
  46. PERF_COUNT_HW_CPU_CYCLES = 0,
  47. PERF_COUNT_HW_INSTRUCTIONS = 1,
  48. PERF_COUNT_HW_CACHE_REFERENCES = 2,
  49. PERF_COUNT_HW_CACHE_MISSES = 3,
  50. PERF_COUNT_HW_BRANCH_INSTRUCTIONS = 4,
  51. PERF_COUNT_HW_BRANCH_MISSES = 5,
  52. PERF_COUNT_HW_BUS_CYCLES = 6,
  53. PERF_COUNT_HW_MAX, /* non-ABI */
  54. };
  55. /*
  56. * Generalized hardware cache counters:
  57. *
  58. * { L1-D, L1-I, LLC, ITLB, DTLB, BPU } 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_MAX, /* non-ABI */
  70. };
  71. enum perf_hw_cache_op_id {
  72. PERF_COUNT_HW_CACHE_OP_READ = 0,
  73. PERF_COUNT_HW_CACHE_OP_WRITE = 1,
  74. PERF_COUNT_HW_CACHE_OP_PREFETCH = 2,
  75. PERF_COUNT_HW_CACHE_OP_MAX, /* non-ABI */
  76. };
  77. enum perf_hw_cache_op_result_id {
  78. PERF_COUNT_HW_CACHE_RESULT_ACCESS = 0,
  79. PERF_COUNT_HW_CACHE_RESULT_MISS = 1,
  80. PERF_COUNT_HW_CACHE_RESULT_MAX, /* non-ABI */
  81. };
  82. /*
  83. * Special "software" counters provided by the kernel, even if the hardware
  84. * does not support performance counters. These counters measure various
  85. * physical and sw events of the kernel (and allow the profiling of them as
  86. * well):
  87. */
  88. enum perf_sw_ids {
  89. PERF_COUNT_SW_CPU_CLOCK = 0,
  90. PERF_COUNT_SW_TASK_CLOCK = 1,
  91. PERF_COUNT_SW_PAGE_FAULTS = 2,
  92. PERF_COUNT_SW_CONTEXT_SWITCHES = 3,
  93. PERF_COUNT_SW_CPU_MIGRATIONS = 4,
  94. PERF_COUNT_SW_PAGE_FAULTS_MIN = 5,
  95. PERF_COUNT_SW_PAGE_FAULTS_MAJ = 6,
  96. PERF_COUNT_SW_ALIGNMENT_FAULTS = 7,
  97. PERF_COUNT_SW_EMULATION_FAULTS = 8,
  98. PERF_COUNT_SW_MAX, /* non-ABI */
  99. };
  100. /*
  101. * Bits that can be set in attr.sample_type to request information
  102. * in the overflow packets.
  103. */
  104. enum perf_counter_sample_format {
  105. PERF_SAMPLE_IP = 1U << 0,
  106. PERF_SAMPLE_TID = 1U << 1,
  107. PERF_SAMPLE_TIME = 1U << 2,
  108. PERF_SAMPLE_ADDR = 1U << 3,
  109. PERF_SAMPLE_READ = 1U << 4,
  110. PERF_SAMPLE_CALLCHAIN = 1U << 5,
  111. PERF_SAMPLE_ID = 1U << 6,
  112. PERF_SAMPLE_CPU = 1U << 7,
  113. PERF_SAMPLE_PERIOD = 1U << 8,
  114. PERF_SAMPLE_STREAM_ID = 1U << 9,
  115. PERF_SAMPLE_RAW = 1U << 10,
  116. PERF_SAMPLE_MAX = 1U << 11, /* non-ABI */
  117. };
  118. /*
  119. * The format of the data returned by read() on a perf counter fd,
  120. * as specified by attr.read_format:
  121. *
  122. * struct read_format {
  123. * { u64 value;
  124. * { u64 time_enabled; } && PERF_FORMAT_ENABLED
  125. * { u64 time_running; } && PERF_FORMAT_RUNNING
  126. * { u64 id; } && PERF_FORMAT_ID
  127. * } && !PERF_FORMAT_GROUP
  128. *
  129. * { u64 nr;
  130. * { u64 time_enabled; } && PERF_FORMAT_ENABLED
  131. * { u64 time_running; } && PERF_FORMAT_RUNNING
  132. * { u64 value;
  133. * { u64 id; } && PERF_FORMAT_ID
  134. * } cntr[nr];
  135. * } && PERF_FORMAT_GROUP
  136. * };
  137. */
  138. enum perf_counter_read_format {
  139. PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0,
  140. PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1,
  141. PERF_FORMAT_ID = 1U << 2,
  142. PERF_FORMAT_GROUP = 1U << 3,
  143. PERF_FORMAT_MAX = 1U << 4, /* non-ABI */
  144. };
  145. #define PERF_ATTR_SIZE_VER0 64 /* sizeof first published struct */
  146. /*
  147. * Hardware event to monitor via a performance monitoring counter:
  148. */
  149. struct perf_counter_attr {
  150. /*
  151. * Major type: hardware/software/tracepoint/etc.
  152. */
  153. __u32 type;
  154. /*
  155. * Size of the attr structure, for fwd/bwd compat.
  156. */
  157. __u32 size;
  158. /*
  159. * Type specific configuration information.
  160. */
  161. __u64 config;
  162. union {
  163. __u64 sample_period;
  164. __u64 sample_freq;
  165. };
  166. __u64 sample_type;
  167. __u64 read_format;
  168. __u64 disabled : 1, /* off by default */
  169. inherit : 1, /* children inherit it */
  170. pinned : 1, /* must always be on PMU */
  171. exclusive : 1, /* only group on PMU */
  172. exclude_user : 1, /* don't count user */
  173. exclude_kernel : 1, /* ditto kernel */
  174. exclude_hv : 1, /* ditto hypervisor */
  175. exclude_idle : 1, /* don't count when idle */
  176. mmap : 1, /* include mmap data */
  177. comm : 1, /* include comm data */
  178. freq : 1, /* use freq, not period */
  179. inherit_stat : 1, /* per task counts */
  180. enable_on_exec : 1, /* next exec enables */
  181. task : 1, /* trace fork/exit */
  182. watermark : 1, /* wakeup_watermark */
  183. __reserved_1 : 49;
  184. union {
  185. __u32 wakeup_events; /* wakeup every n events */
  186. __u32 wakeup_watermark; /* bytes before wakeup */
  187. };
  188. __u32 __reserved_2;
  189. __u64 __reserved_3;
  190. };
  191. /*
  192. * Ioctls that can be done on a perf counter fd:
  193. */
  194. #define PERF_COUNTER_IOC_ENABLE _IO ('$', 0)
  195. #define PERF_COUNTER_IOC_DISABLE _IO ('$', 1)
  196. #define PERF_COUNTER_IOC_REFRESH _IO ('$', 2)
  197. #define PERF_COUNTER_IOC_RESET _IO ('$', 3)
  198. #define PERF_COUNTER_IOC_PERIOD _IOW('$', 4, u64)
  199. #define PERF_COUNTER_IOC_SET_OUTPUT _IO ('$', 5)
  200. #define PERF_COUNTER_IOC_SET_FILTER _IOW('$', 6, char *)
  201. enum perf_counter_ioc_flags {
  202. PERF_IOC_FLAG_GROUP = 1U << 0,
  203. };
  204. /*
  205. * Structure of the page that can be mapped via mmap
  206. */
  207. struct perf_counter_mmap_page {
  208. __u32 version; /* version number of this structure */
  209. __u32 compat_version; /* lowest version this is compat with */
  210. /*
  211. * Bits needed to read the hw counters in user-space.
  212. *
  213. * u32 seq;
  214. * s64 count;
  215. *
  216. * do {
  217. * seq = pc->lock;
  218. *
  219. * barrier()
  220. * if (pc->index) {
  221. * count = pmc_read(pc->index - 1);
  222. * count += pc->offset;
  223. * } else
  224. * goto regular_read;
  225. *
  226. * barrier();
  227. * } while (pc->lock != seq);
  228. *
  229. * NOTE: for obvious reason this only works on self-monitoring
  230. * processes.
  231. */
  232. __u32 lock; /* seqlock for synchronization */
  233. __u32 index; /* hardware counter identifier */
  234. __s64 offset; /* add to hardware counter value */
  235. __u64 time_enabled; /* time counter active */
  236. __u64 time_running; /* time counter on cpu */
  237. /*
  238. * Hole for extension of the self monitor capabilities
  239. */
  240. __u64 __reserved[123]; /* align to 1k */
  241. /*
  242. * Control data for the mmap() data buffer.
  243. *
  244. * User-space reading the @data_head value should issue an rmb(), on
  245. * SMP capable platforms, after reading this value -- see
  246. * perf_counter_wakeup().
  247. *
  248. * When the mapping is PROT_WRITE the @data_tail value should be
  249. * written by userspace to reflect the last read data. In this case
  250. * the kernel will not over-write unread data.
  251. */
  252. __u64 data_head; /* head in the data section */
  253. __u64 data_tail; /* user-space written tail */
  254. };
  255. #define PERF_EVENT_MISC_CPUMODE_MASK (3 << 0)
  256. #define PERF_EVENT_MISC_CPUMODE_UNKNOWN (0 << 0)
  257. #define PERF_EVENT_MISC_KERNEL (1 << 0)
  258. #define PERF_EVENT_MISC_USER (2 << 0)
  259. #define PERF_EVENT_MISC_HYPERVISOR (3 << 0)
  260. struct perf_event_header {
  261. __u32 type;
  262. __u16 misc;
  263. __u16 size;
  264. };
  265. enum perf_event_type {
  266. /*
  267. * The MMAP events record the PROT_EXEC mappings so that we can
  268. * correlate userspace IPs to code. They have the following structure:
  269. *
  270. * struct {
  271. * struct perf_event_header header;
  272. *
  273. * u32 pid, tid;
  274. * u64 addr;
  275. * u64 len;
  276. * u64 pgoff;
  277. * char filename[];
  278. * };
  279. */
  280. PERF_EVENT_MMAP = 1,
  281. /*
  282. * struct {
  283. * struct perf_event_header header;
  284. * u64 id;
  285. * u64 lost;
  286. * };
  287. */
  288. PERF_EVENT_LOST = 2,
  289. /*
  290. * struct {
  291. * struct perf_event_header header;
  292. *
  293. * u32 pid, tid;
  294. * char comm[];
  295. * };
  296. */
  297. PERF_EVENT_COMM = 3,
  298. /*
  299. * struct {
  300. * struct perf_event_header header;
  301. * u32 pid, ppid;
  302. * u32 tid, ptid;
  303. * u64 time;
  304. * };
  305. */
  306. PERF_EVENT_EXIT = 4,
  307. /*
  308. * struct {
  309. * struct perf_event_header header;
  310. * u64 time;
  311. * u64 id;
  312. * u64 stream_id;
  313. * };
  314. */
  315. PERF_EVENT_THROTTLE = 5,
  316. PERF_EVENT_UNTHROTTLE = 6,
  317. /*
  318. * struct {
  319. * struct perf_event_header header;
  320. * u32 pid, ppid;
  321. * u32 tid, ptid;
  322. * u64 time;
  323. * };
  324. */
  325. PERF_EVENT_FORK = 7,
  326. /*
  327. * struct {
  328. * struct perf_event_header header;
  329. * u32 pid, tid;
  330. *
  331. * struct read_format values;
  332. * };
  333. */
  334. PERF_EVENT_READ = 8,
  335. /*
  336. * struct {
  337. * struct perf_event_header header;
  338. *
  339. * { u64 ip; } && PERF_SAMPLE_IP
  340. * { u32 pid, tid; } && PERF_SAMPLE_TID
  341. * { u64 time; } && PERF_SAMPLE_TIME
  342. * { u64 addr; } && PERF_SAMPLE_ADDR
  343. * { u64 id; } && PERF_SAMPLE_ID
  344. * { u64 stream_id;} && PERF_SAMPLE_STREAM_ID
  345. * { u32 cpu, res; } && PERF_SAMPLE_CPU
  346. * { u64 period; } && PERF_SAMPLE_PERIOD
  347. *
  348. * { struct read_format values; } && PERF_SAMPLE_READ
  349. *
  350. * { u64 nr,
  351. * u64 ips[nr]; } && PERF_SAMPLE_CALLCHAIN
  352. *
  353. * #
  354. * # The RAW record below is opaque data wrt the ABI
  355. * #
  356. * # That is, the ABI doesn't make any promises wrt to
  357. * # the stability of its content, it may vary depending
  358. * # on event, hardware, kernel version and phase of
  359. * # the moon.
  360. * #
  361. * # In other words, PERF_SAMPLE_RAW contents are not an ABI.
  362. * #
  363. *
  364. * { u32 size;
  365. * char data[size];}&& PERF_SAMPLE_RAW
  366. * };
  367. */
  368. PERF_EVENT_SAMPLE = 9,
  369. PERF_EVENT_MAX, /* non-ABI */
  370. };
  371. enum perf_callchain_context {
  372. PERF_CONTEXT_HV = (__u64)-32,
  373. PERF_CONTEXT_KERNEL = (__u64)-128,
  374. PERF_CONTEXT_USER = (__u64)-512,
  375. PERF_CONTEXT_GUEST = (__u64)-2048,
  376. PERF_CONTEXT_GUEST_KERNEL = (__u64)-2176,
  377. PERF_CONTEXT_GUEST_USER = (__u64)-2560,
  378. PERF_CONTEXT_MAX = (__u64)-4095,
  379. };
  380. #define PERF_FLAG_FD_NO_GROUP (1U << 0)
  381. #define PERF_FLAG_FD_OUTPUT (1U << 1)
  382. /*
  383. * In case some app still references the old symbols:
  384. */
  385. #define __NR_perf_counter_open __NR_perf_event_open
  386. #define PR_TASK_PERF_COUNTERS_DISABLE PR_TASK_PERF_EVENTS_DISABLE
  387. #define PR_TASK_PERF_COUNTERS_ENABLE PR_TASK_PERF_EVENTS_ENABLE
  388. #endif /* _LINUX_PERF_COUNTER_H */