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