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