xref: /openbmc/linux/tools/lib/perf/include/perf/event.h (revision c091c78b)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBPERF_EVENT_H
3 #define __LIBPERF_EVENT_H
4 
5 #include <linux/perf_event.h>
6 #include <linux/types.h>
7 #include <linux/limits.h>
8 #include <linux/bpf.h>
9 #include <sys/types.h> /* pid_t */
10 
11 #define event_contains(obj, mem) ((obj).header.size > offsetof(typeof(obj), mem))
12 
13 struct perf_record_mmap {
14 	struct perf_event_header header;
15 	__u32			 pid, tid;
16 	__u64			 start;
17 	__u64			 len;
18 	__u64			 pgoff;
19 	char			 filename[PATH_MAX];
20 };
21 
22 struct perf_record_mmap2 {
23 	struct perf_event_header header;
24 	__u32			 pid, tid;
25 	__u64			 start;
26 	__u64			 len;
27 	__u64			 pgoff;
28 	union {
29 		struct {
30 			__u32	 maj;
31 			__u32	 min;
32 			__u64	 ino;
33 			__u64	 ino_generation;
34 		};
35 		struct {
36 			__u8	 build_id_size;
37 			__u8	 __reserved_1;
38 			__u16	 __reserved_2;
39 			__u8	 build_id[20];
40 		};
41 	};
42 	__u32			 prot;
43 	__u32			 flags;
44 	char			 filename[PATH_MAX];
45 };
46 
47 struct perf_record_comm {
48 	struct perf_event_header header;
49 	__u32			 pid, tid;
50 	char			 comm[16];
51 };
52 
53 struct perf_record_namespaces {
54 	struct perf_event_header header;
55 	__u32			 pid, tid;
56 	__u64			 nr_namespaces;
57 	struct perf_ns_link_info link_info[];
58 };
59 
60 struct perf_record_fork {
61 	struct perf_event_header header;
62 	__u32			 pid, ppid;
63 	__u32			 tid, ptid;
64 	__u64			 time;
65 };
66 
67 struct perf_record_lost {
68 	struct perf_event_header header;
69 	__u64			 id;
70 	__u64			 lost;
71 };
72 
73 #define PERF_RECORD_MISC_LOST_SAMPLES_BPF (1 << 15)
74 
75 struct perf_record_lost_samples {
76 	struct perf_event_header header;
77 	__u64			 lost;
78 };
79 
80 /*
81  * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID | PERF_FORMAT_LOST
82  */
83 struct perf_record_read {
84 	struct perf_event_header header;
85 	__u32			 pid, tid;
86 	__u64			 value;
87 	__u64			 time_enabled;
88 	__u64			 time_running;
89 	__u64			 id;
90 	__u64			 lost;
91 };
92 
93 struct perf_record_throttle {
94 	struct perf_event_header header;
95 	__u64			 time;
96 	__u64			 id;
97 	__u64			 stream_id;
98 };
99 
100 #ifndef KSYM_NAME_LEN
101 #define KSYM_NAME_LEN 512
102 #endif
103 
104 struct perf_record_ksymbol {
105 	struct perf_event_header header;
106 	__u64			 addr;
107 	__u32			 len;
108 	__u16			 ksym_type;
109 	__u16			 flags;
110 	char			 name[KSYM_NAME_LEN];
111 };
112 
113 struct perf_record_bpf_event {
114 	struct perf_event_header header;
115 	__u16			 type;
116 	__u16			 flags;
117 	__u32			 id;
118 
119 	/* for bpf_prog types */
120 	__u8			 tag[BPF_TAG_SIZE];  // prog tag
121 };
122 
123 struct perf_record_cgroup {
124 	struct perf_event_header header;
125 	__u64			 id;
126 	char			 path[PATH_MAX];
127 };
128 
129 struct perf_record_text_poke_event {
130 	struct perf_event_header header;
131 	__u64			addr;
132 	__u16			old_len;
133 	__u16			new_len;
134 	__u8			bytes[];
135 };
136 
137 struct perf_record_sample {
138 	struct perf_event_header header;
139 	__u64			 array[];
140 };
141 
142 struct perf_record_switch {
143 	struct perf_event_header header;
144 	__u32			 next_prev_pid;
145 	__u32			 next_prev_tid;
146 };
147 
148 struct perf_record_header_attr {
149 	struct perf_event_header header;
150 	struct perf_event_attr	 attr;
151 	/*
152 	 * Array of u64 id follows here but we cannot use a flexible array
153 	 * because size of attr in the data can be different then current
154 	 * version.  Please use perf_record_header_attr_id() below.
155 	 *
156 	 * __u64		 id[];  // do not use this
157 	 */
158 };
159 
160 /* Returns the pointer to id array based on the actual attr size. */
161 #define perf_record_header_attr_id(evt)			\
162 	((void *)&(evt)->attr.attr + (evt)->attr.attr.size)
163 
164 enum {
165 	PERF_CPU_MAP__CPUS = 0,
166 	PERF_CPU_MAP__MASK = 1,
167 	PERF_CPU_MAP__RANGE_CPUS = 2,
168 };
169 
170 /*
171  * Array encoding of a perf_cpu_map where nr is the number of entries in cpu[]
172  * and each entry is a value for a CPU in the map.
173  */
174 struct cpu_map_entries {
175 	__u16			 nr;
176 	__u16			 cpu[];
177 };
178 
179 /* Bitmap encoding of a perf_cpu_map where bitmap entries are 32-bit. */
180 struct perf_record_mask_cpu_map32 {
181 	/* Number of mask values. */
182 	__u16			 nr;
183 	/* Constant 4. */
184 	__u16			 long_size;
185 	/* Bitmap data. */
186 	__u32			 mask[];
187 };
188 
189 /* Bitmap encoding of a perf_cpu_map where bitmap entries are 64-bit. */
190 struct perf_record_mask_cpu_map64 {
191 	/* Number of mask values. */
192 	__u16			 nr;
193 	/* Constant 8. */
194 	__u16			 long_size;
195 	/* Legacy padding. */
196 	char                     __pad[4];
197 	/* Bitmap data. */
198 	__u64			 mask[];
199 };
200 
201 /*
202  * 'struct perf_record_cpu_map_data' is packed as unfortunately an earlier
203  * version had unaligned data and we wish to retain file format compatibility.
204  * -irogers
205  */
206 #pragma GCC diagnostic push
207 #pragma GCC diagnostic ignored "-Wpacked"
208 #pragma GCC diagnostic ignored "-Wattributes"
209 
210 /*
211  * An encoding of a CPU map for a range starting at start_cpu through to
212  * end_cpu. If any_cpu is 1, an any CPU (-1) value (aka dummy value) is present.
213  */
214 struct perf_record_range_cpu_map {
215 	__u8 any_cpu;
216 	__u8 __pad;
217 	__u16 start_cpu;
218 	__u16 end_cpu;
219 };
220 
221 struct perf_record_cpu_map_data {
222 	__u16			 type;
223 	union {
224 		/* Used when type == PERF_CPU_MAP__CPUS. */
225 		struct cpu_map_entries cpus_data;
226 		/* Used when type == PERF_CPU_MAP__MASK and long_size == 4. */
227 		struct perf_record_mask_cpu_map32 mask32_data;
228 		/* Used when type == PERF_CPU_MAP__MASK and long_size == 8. */
229 		struct perf_record_mask_cpu_map64 mask64_data;
230 		/* Used when type == PERF_CPU_MAP__RANGE_CPUS. */
231 		struct perf_record_range_cpu_map range_cpu_data;
232 	};
233 } __attribute__((packed));
234 
235 #pragma GCC diagnostic pop
236 
237 struct perf_record_cpu_map {
238 	struct perf_event_header	 header;
239 	struct perf_record_cpu_map_data	 data;
240 };
241 
242 enum {
243 	PERF_EVENT_UPDATE__UNIT  = 0,
244 	PERF_EVENT_UPDATE__SCALE = 1,
245 	PERF_EVENT_UPDATE__NAME  = 2,
246 	PERF_EVENT_UPDATE__CPUS  = 3,
247 };
248 
249 struct perf_record_event_update_cpus {
250 	struct perf_record_cpu_map_data	 cpus;
251 };
252 
253 struct perf_record_event_update_scale {
254 	double			 scale;
255 };
256 
257 struct perf_record_event_update {
258 	struct perf_event_header header;
259 	__u64			 type;
260 	__u64			 id;
261 	union {
262 		/* Used when type == PERF_EVENT_UPDATE__SCALE. */
263 		struct perf_record_event_update_scale scale;
264 		/* Used when type == PERF_EVENT_UPDATE__UNIT. */
265 		char unit[0];
266 		/* Used when type == PERF_EVENT_UPDATE__NAME. */
267 		char name[0];
268 		/* Used when type == PERF_EVENT_UPDATE__CPUS. */
269 		struct perf_record_event_update_cpus cpus;
270 	};
271 };
272 
273 #define MAX_EVENT_NAME 64
274 
275 struct perf_trace_event_type {
276 	__u64			 event_id;
277 	char			 name[MAX_EVENT_NAME];
278 };
279 
280 struct perf_record_header_event_type {
281 	struct perf_event_header	 header;
282 	struct perf_trace_event_type	 event_type;
283 };
284 
285 struct perf_record_header_tracing_data {
286 	struct perf_event_header header;
287 	__u32			 size;
288 };
289 
290 #define PERF_RECORD_MISC_BUILD_ID_SIZE (1 << 15)
291 
292 struct perf_record_header_build_id {
293 	struct perf_event_header header;
294 	pid_t			 pid;
295 	union {
296 		__u8		 build_id[24];
297 		struct {
298 			__u8	 data[20];
299 			__u8	 size;
300 			__u8	 reserved1__;
301 			__u16	 reserved2__;
302 		};
303 	};
304 	char			 filename[];
305 };
306 
307 struct id_index_entry {
308 	__u64			 id;
309 	__u64			 idx;
310 	__u64			 cpu;
311 	__u64			 tid;
312 };
313 
314 struct id_index_entry_2 {
315 	__u64			 machine_pid;
316 	__u64			 vcpu;
317 };
318 
319 struct perf_record_id_index {
320 	struct perf_event_header header;
321 	__u64			 nr;
322 	struct id_index_entry	 entries[];
323 };
324 
325 struct perf_record_auxtrace_info {
326 	struct perf_event_header header;
327 	__u32			 type;
328 	__u32			 reserved__; /* For alignment */
329 	__u64			 priv[];
330 };
331 
332 struct perf_record_auxtrace {
333 	struct perf_event_header header;
334 	__u64			 size;
335 	__u64			 offset;
336 	__u64			 reference;
337 	__u32			 idx;
338 	__u32			 tid;
339 	__u32			 cpu;
340 	__u32			 reserved__; /* For alignment */
341 };
342 
343 #define MAX_AUXTRACE_ERROR_MSG 64
344 
345 struct perf_record_auxtrace_error {
346 	struct perf_event_header header;
347 	__u32			 type;
348 	__u32			 code;
349 	__u32			 cpu;
350 	__u32			 pid;
351 	__u32			 tid;
352 	__u32			 fmt;
353 	__u64			 ip;
354 	__u64			 time;
355 	char			 msg[MAX_AUXTRACE_ERROR_MSG];
356 	__u32			 machine_pid;
357 	__u32			 vcpu;
358 };
359 
360 struct perf_record_aux {
361 	struct perf_event_header header;
362 	__u64			 aux_offset;
363 	__u64			 aux_size;
364 	__u64			 flags;
365 };
366 
367 struct perf_record_itrace_start {
368 	struct perf_event_header header;
369 	__u32			 pid;
370 	__u32			 tid;
371 };
372 
373 struct perf_record_aux_output_hw_id {
374 	struct perf_event_header header;
375 	__u64			hw_id;
376 };
377 
378 struct perf_record_thread_map_entry {
379 	__u64			 pid;
380 	char			 comm[16];
381 };
382 
383 struct perf_record_thread_map {
384 	struct perf_event_header		 header;
385 	__u64					 nr;
386 	struct perf_record_thread_map_entry	 entries[];
387 };
388 
389 enum {
390 	PERF_STAT_CONFIG_TERM__AGGR_MODE	= 0,
391 	PERF_STAT_CONFIG_TERM__INTERVAL		= 1,
392 	PERF_STAT_CONFIG_TERM__SCALE		= 2,
393 	PERF_STAT_CONFIG_TERM__AGGR_LEVEL	= 3,
394 	PERF_STAT_CONFIG_TERM__MAX		= 4,
395 };
396 
397 struct perf_record_stat_config_entry {
398 	__u64			 tag;
399 	__u64			 val;
400 };
401 
402 struct perf_record_stat_config {
403 	struct perf_event_header		 header;
404 	__u64					 nr;
405 	struct perf_record_stat_config_entry	 data[];
406 };
407 
408 struct perf_record_stat {
409 	struct perf_event_header header;
410 
411 	__u64			 id;
412 	__u32			 cpu;
413 	__u32			 thread;
414 
415 	union {
416 		struct {
417 			__u64	 val;
418 			__u64	 ena;
419 			__u64	 run;
420 		};
421 		__u64		 values[3];
422 	};
423 };
424 
425 struct perf_record_stat_round {
426 	struct perf_event_header header;
427 	__u64			 type;
428 	__u64			 time;
429 };
430 
431 struct perf_record_time_conv {
432 	struct perf_event_header header;
433 	__u64			 time_shift;
434 	__u64			 time_mult;
435 	__u64			 time_zero;
436 	__u64			 time_cycles;
437 	__u64			 time_mask;
438 	__u8			 cap_user_time_zero;
439 	__u8			 cap_user_time_short;
440 	__u8			 reserved[6];	/* For alignment */
441 };
442 
443 struct perf_record_header_feature {
444 	struct perf_event_header header;
445 	__u64			 feat_id;
446 	char			 data[];
447 };
448 
449 struct perf_record_compressed {
450 	struct perf_event_header header;
451 	char			 data[];
452 };
453 
454 enum perf_user_event_type { /* above any possible kernel type */
455 	PERF_RECORD_USER_TYPE_START		= 64,
456 	PERF_RECORD_HEADER_ATTR			= 64,
457 	PERF_RECORD_HEADER_EVENT_TYPE		= 65, /* deprecated */
458 	PERF_RECORD_HEADER_TRACING_DATA		= 66,
459 	PERF_RECORD_HEADER_BUILD_ID		= 67,
460 	PERF_RECORD_FINISHED_ROUND		= 68,
461 	PERF_RECORD_ID_INDEX			= 69,
462 	PERF_RECORD_AUXTRACE_INFO		= 70,
463 	PERF_RECORD_AUXTRACE			= 71,
464 	PERF_RECORD_AUXTRACE_ERROR		= 72,
465 	PERF_RECORD_THREAD_MAP			= 73,
466 	PERF_RECORD_CPU_MAP			= 74,
467 	PERF_RECORD_STAT_CONFIG			= 75,
468 	PERF_RECORD_STAT			= 76,
469 	PERF_RECORD_STAT_ROUND			= 77,
470 	PERF_RECORD_EVENT_UPDATE		= 78,
471 	PERF_RECORD_TIME_CONV			= 79,
472 	PERF_RECORD_HEADER_FEATURE		= 80,
473 	PERF_RECORD_COMPRESSED			= 81,
474 	PERF_RECORD_FINISHED_INIT		= 82,
475 	PERF_RECORD_HEADER_MAX
476 };
477 
478 union perf_event {
479 	struct perf_event_header		header;
480 	struct perf_record_mmap			mmap;
481 	struct perf_record_mmap2		mmap2;
482 	struct perf_record_comm			comm;
483 	struct perf_record_namespaces		namespaces;
484 	struct perf_record_cgroup		cgroup;
485 	struct perf_record_fork			fork;
486 	struct perf_record_lost			lost;
487 	struct perf_record_lost_samples		lost_samples;
488 	struct perf_record_read			read;
489 	struct perf_record_throttle		throttle;
490 	struct perf_record_sample		sample;
491 	struct perf_record_bpf_event		bpf;
492 	struct perf_record_ksymbol		ksymbol;
493 	struct perf_record_text_poke_event	text_poke;
494 	struct perf_record_header_attr		attr;
495 	struct perf_record_event_update		event_update;
496 	struct perf_record_header_event_type	event_type;
497 	struct perf_record_header_tracing_data	tracing_data;
498 	struct perf_record_header_build_id	build_id;
499 	struct perf_record_id_index		id_index;
500 	struct perf_record_auxtrace_info	auxtrace_info;
501 	struct perf_record_auxtrace		auxtrace;
502 	struct perf_record_auxtrace_error	auxtrace_error;
503 	struct perf_record_aux			aux;
504 	struct perf_record_itrace_start		itrace_start;
505 	struct perf_record_aux_output_hw_id	aux_output_hw_id;
506 	struct perf_record_switch		context_switch;
507 	struct perf_record_thread_map		thread_map;
508 	struct perf_record_cpu_map		cpu_map;
509 	struct perf_record_stat_config		stat_config;
510 	struct perf_record_stat			stat;
511 	struct perf_record_stat_round		stat_round;
512 	struct perf_record_time_conv		time_conv;
513 	struct perf_record_header_feature	feat;
514 	struct perf_record_compressed		pack;
515 };
516 
517 #endif /* __LIBPERF_EVENT_H */
518