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 struct perf_record_mmap {
12 	struct perf_event_header header;
13 	__u32			 pid, tid;
14 	__u64			 start;
15 	__u64			 len;
16 	__u64			 pgoff;
17 	char			 filename[PATH_MAX];
18 };
19 
20 struct perf_record_mmap2 {
21 	struct perf_event_header header;
22 	__u32			 pid, tid;
23 	__u64			 start;
24 	__u64			 len;
25 	__u64			 pgoff;
26 	__u32			 maj;
27 	__u32			 min;
28 	__u64			 ino;
29 	__u64			 ino_generation;
30 	__u32			 prot;
31 	__u32			 flags;
32 	char			 filename[PATH_MAX];
33 };
34 
35 struct perf_record_comm {
36 	struct perf_event_header header;
37 	__u32			 pid, tid;
38 	char			 comm[16];
39 };
40 
41 struct perf_record_namespaces {
42 	struct perf_event_header header;
43 	__u32			 pid, tid;
44 	__u64			 nr_namespaces;
45 	struct perf_ns_link_info link_info[];
46 };
47 
48 struct perf_record_fork {
49 	struct perf_event_header header;
50 	__u32			 pid, ppid;
51 	__u32			 tid, ptid;
52 	__u64			 time;
53 };
54 
55 struct perf_record_lost {
56 	struct perf_event_header header;
57 	__u64			 id;
58 	__u64			 lost;
59 };
60 
61 struct perf_record_lost_samples {
62 	struct perf_event_header header;
63 	__u64			 lost;
64 };
65 
66 /*
67  * PERF_FORMAT_ENABLED | PERF_FORMAT_RUNNING | PERF_FORMAT_ID
68  */
69 struct perf_record_read {
70 	struct perf_event_header header;
71 	__u32			 pid, tid;
72 	__u64			 value;
73 	__u64			 time_enabled;
74 	__u64			 time_running;
75 	__u64			 id;
76 };
77 
78 struct perf_record_throttle {
79 	struct perf_event_header header;
80 	__u64			 time;
81 	__u64			 id;
82 	__u64			 stream_id;
83 };
84 
85 #ifndef KSYM_NAME_LEN
86 #define KSYM_NAME_LEN 256
87 #endif
88 
89 struct perf_record_ksymbol {
90 	struct perf_event_header header;
91 	__u64			 addr;
92 	__u32			 len;
93 	__u16			 ksym_type;
94 	__u16			 flags;
95 	char			 name[KSYM_NAME_LEN];
96 };
97 
98 struct perf_record_bpf_event {
99 	struct perf_event_header header;
100 	__u16			 type;
101 	__u16			 flags;
102 	__u32			 id;
103 
104 	/* for bpf_prog types */
105 	__u8			 tag[BPF_TAG_SIZE];  // prog tag
106 };
107 
108 struct perf_record_cgroup {
109 	struct perf_event_header header;
110 	__u64			 id;
111 	char			 path[PATH_MAX];
112 };
113 
114 struct perf_record_text_poke_event {
115 	struct perf_event_header header;
116 	__u64			addr;
117 	__u16			old_len;
118 	__u16			new_len;
119 	__u8			bytes[];
120 };
121 
122 struct perf_record_sample {
123 	struct perf_event_header header;
124 	__u64			 array[];
125 };
126 
127 struct perf_record_switch {
128 	struct perf_event_header header;
129 	__u32			 next_prev_pid;
130 	__u32			 next_prev_tid;
131 };
132 
133 struct perf_record_header_attr {
134 	struct perf_event_header header;
135 	struct perf_event_attr	 attr;
136 	__u64			 id[];
137 };
138 
139 enum {
140 	PERF_CPU_MAP__CPUS = 0,
141 	PERF_CPU_MAP__MASK = 1,
142 };
143 
144 struct cpu_map_entries {
145 	__u16			 nr;
146 	__u16			 cpu[];
147 };
148 
149 struct perf_record_record_cpu_map {
150 	__u16			 nr;
151 	__u16			 long_size;
152 	unsigned long		 mask[];
153 };
154 
155 struct perf_record_cpu_map_data {
156 	__u16			 type;
157 	char			 data[];
158 };
159 
160 struct perf_record_cpu_map {
161 	struct perf_event_header	 header;
162 	struct perf_record_cpu_map_data	 data;
163 };
164 
165 enum {
166 	PERF_EVENT_UPDATE__UNIT  = 0,
167 	PERF_EVENT_UPDATE__SCALE = 1,
168 	PERF_EVENT_UPDATE__NAME  = 2,
169 	PERF_EVENT_UPDATE__CPUS  = 3,
170 };
171 
172 struct perf_record_event_update_cpus {
173 	struct perf_record_cpu_map_data	 cpus;
174 };
175 
176 struct perf_record_event_update_scale {
177 	double			 scale;
178 };
179 
180 struct perf_record_event_update {
181 	struct perf_event_header header;
182 	__u64			 type;
183 	__u64			 id;
184 	char			 data[];
185 };
186 
187 #define MAX_EVENT_NAME 64
188 
189 struct perf_trace_event_type {
190 	__u64			 event_id;
191 	char			 name[MAX_EVENT_NAME];
192 };
193 
194 struct perf_record_header_event_type {
195 	struct perf_event_header	 header;
196 	struct perf_trace_event_type	 event_type;
197 };
198 
199 struct perf_record_header_tracing_data {
200 	struct perf_event_header header;
201 	__u32			 size;
202 };
203 
204 #define PERF_RECORD_MISC_BUILD_ID_SIZE (1 << 15)
205 
206 struct perf_record_header_build_id {
207 	struct perf_event_header header;
208 	pid_t			 pid;
209 	union {
210 		__u8		 build_id[24];
211 		struct {
212 			__u8	 data[20];
213 			__u8	 size;
214 			__u8	 reserved1__;
215 			__u16	 reserved2__;
216 		};
217 	};
218 	char			 filename[];
219 };
220 
221 struct id_index_entry {
222 	__u64			 id;
223 	__u64			 idx;
224 	__u64			 cpu;
225 	__u64			 tid;
226 };
227 
228 struct perf_record_id_index {
229 	struct perf_event_header header;
230 	__u64			 nr;
231 	struct id_index_entry	 entries[0];
232 };
233 
234 struct perf_record_auxtrace_info {
235 	struct perf_event_header header;
236 	__u32			 type;
237 	__u32			 reserved__; /* For alignment */
238 	__u64			 priv[];
239 };
240 
241 struct perf_record_auxtrace {
242 	struct perf_event_header header;
243 	__u64			 size;
244 	__u64			 offset;
245 	__u64			 reference;
246 	__u32			 idx;
247 	__u32			 tid;
248 	__u32			 cpu;
249 	__u32			 reserved__; /* For alignment */
250 };
251 
252 #define MAX_AUXTRACE_ERROR_MSG 64
253 
254 struct perf_record_auxtrace_error {
255 	struct perf_event_header header;
256 	__u32			 type;
257 	__u32			 code;
258 	__u32			 cpu;
259 	__u32			 pid;
260 	__u32			 tid;
261 	__u32			 fmt;
262 	__u64			 ip;
263 	__u64			 time;
264 	char			 msg[MAX_AUXTRACE_ERROR_MSG];
265 };
266 
267 struct perf_record_aux {
268 	struct perf_event_header header;
269 	__u64			 aux_offset;
270 	__u64			 aux_size;
271 	__u64			 flags;
272 };
273 
274 struct perf_record_itrace_start {
275 	struct perf_event_header header;
276 	__u32			 pid;
277 	__u32			 tid;
278 };
279 
280 struct perf_record_thread_map_entry {
281 	__u64			 pid;
282 	char			 comm[16];
283 };
284 
285 struct perf_record_thread_map {
286 	struct perf_event_header		 header;
287 	__u64					 nr;
288 	struct perf_record_thread_map_entry	 entries[];
289 };
290 
291 enum {
292 	PERF_STAT_CONFIG_TERM__AGGR_MODE	= 0,
293 	PERF_STAT_CONFIG_TERM__INTERVAL		= 1,
294 	PERF_STAT_CONFIG_TERM__SCALE		= 2,
295 	PERF_STAT_CONFIG_TERM__MAX		= 3,
296 };
297 
298 struct perf_record_stat_config_entry {
299 	__u64			 tag;
300 	__u64			 val;
301 };
302 
303 struct perf_record_stat_config {
304 	struct perf_event_header		 header;
305 	__u64					 nr;
306 	struct perf_record_stat_config_entry	 data[];
307 };
308 
309 struct perf_record_stat {
310 	struct perf_event_header header;
311 
312 	__u64			 id;
313 	__u32			 cpu;
314 	__u32			 thread;
315 
316 	union {
317 		struct {
318 			__u64	 val;
319 			__u64	 ena;
320 			__u64	 run;
321 		};
322 		__u64		 values[3];
323 	};
324 };
325 
326 struct perf_record_stat_round {
327 	struct perf_event_header header;
328 	__u64			 type;
329 	__u64			 time;
330 };
331 
332 struct perf_record_time_conv {
333 	struct perf_event_header header;
334 	__u64			 time_shift;
335 	__u64			 time_mult;
336 	__u64			 time_zero;
337 	__u64			 time_cycles;
338 	__u64			 time_mask;
339 	bool			 cap_user_time_zero;
340 	bool			 cap_user_time_short;
341 };
342 
343 struct perf_record_header_feature {
344 	struct perf_event_header header;
345 	__u64			 feat_id;
346 	char			 data[];
347 };
348 
349 struct perf_record_compressed {
350 	struct perf_event_header header;
351 	char			 data[];
352 };
353 
354 enum perf_user_event_type { /* above any possible kernel type */
355 	PERF_RECORD_USER_TYPE_START		= 64,
356 	PERF_RECORD_HEADER_ATTR			= 64,
357 	PERF_RECORD_HEADER_EVENT_TYPE		= 65, /* deprecated */
358 	PERF_RECORD_HEADER_TRACING_DATA		= 66,
359 	PERF_RECORD_HEADER_BUILD_ID		= 67,
360 	PERF_RECORD_FINISHED_ROUND		= 68,
361 	PERF_RECORD_ID_INDEX			= 69,
362 	PERF_RECORD_AUXTRACE_INFO		= 70,
363 	PERF_RECORD_AUXTRACE			= 71,
364 	PERF_RECORD_AUXTRACE_ERROR		= 72,
365 	PERF_RECORD_THREAD_MAP			= 73,
366 	PERF_RECORD_CPU_MAP			= 74,
367 	PERF_RECORD_STAT_CONFIG			= 75,
368 	PERF_RECORD_STAT			= 76,
369 	PERF_RECORD_STAT_ROUND			= 77,
370 	PERF_RECORD_EVENT_UPDATE		= 78,
371 	PERF_RECORD_TIME_CONV			= 79,
372 	PERF_RECORD_HEADER_FEATURE		= 80,
373 	PERF_RECORD_COMPRESSED			= 81,
374 	PERF_RECORD_HEADER_MAX
375 };
376 
377 union perf_event {
378 	struct perf_event_header		header;
379 	struct perf_record_mmap			mmap;
380 	struct perf_record_mmap2		mmap2;
381 	struct perf_record_comm			comm;
382 	struct perf_record_namespaces		namespaces;
383 	struct perf_record_cgroup		cgroup;
384 	struct perf_record_fork			fork;
385 	struct perf_record_lost			lost;
386 	struct perf_record_lost_samples		lost_samples;
387 	struct perf_record_read			read;
388 	struct perf_record_throttle		throttle;
389 	struct perf_record_sample		sample;
390 	struct perf_record_bpf_event		bpf;
391 	struct perf_record_ksymbol		ksymbol;
392 	struct perf_record_text_poke_event	text_poke;
393 	struct perf_record_header_attr		attr;
394 	struct perf_record_event_update		event_update;
395 	struct perf_record_header_event_type	event_type;
396 	struct perf_record_header_tracing_data	tracing_data;
397 	struct perf_record_header_build_id	build_id;
398 	struct perf_record_id_index		id_index;
399 	struct perf_record_auxtrace_info	auxtrace_info;
400 	struct perf_record_auxtrace		auxtrace;
401 	struct perf_record_auxtrace_error	auxtrace_error;
402 	struct perf_record_aux			aux;
403 	struct perf_record_itrace_start		itrace_start;
404 	struct perf_record_switch		context_switch;
405 	struct perf_record_thread_map		thread_map;
406 	struct perf_record_cpu_map		cpu_map;
407 	struct perf_record_stat_config		stat_config;
408 	struct perf_record_stat			stat;
409 	struct perf_record_stat_round		stat_round;
410 	struct perf_record_time_conv		time_conv;
411 	struct perf_record_header_feature	feat;
412 	struct perf_record_compressed		pack;
413 };
414 
415 #endif /* __LIBPERF_EVENT_H */
416