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 256 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 }; 157 158 /* 159 * Array encoding of a perf_cpu_map where nr is the number of entries in cpu[] 160 * and each entry is a value for a CPU in the map. 161 */ 162 struct cpu_map_entries { 163 __u16 nr; 164 __u16 cpu[]; 165 }; 166 167 /* Bitmap encoding of a perf_cpu_map where bitmap entries are 32-bit. */ 168 struct perf_record_mask_cpu_map32 { 169 /* Number of mask values. */ 170 __u16 nr; 171 /* Constant 4. */ 172 __u16 long_size; 173 /* Bitmap data. */ 174 __u32 mask[]; 175 }; 176 177 /* Bitmap encoding of a perf_cpu_map where bitmap entries are 64-bit. */ 178 struct perf_record_mask_cpu_map64 { 179 /* Number of mask values. */ 180 __u16 nr; 181 /* Constant 8. */ 182 __u16 long_size; 183 /* Legacy padding. */ 184 char __pad[4]; 185 /* Bitmap data. */ 186 __u64 mask[]; 187 }; 188 189 /* 190 * 'struct perf_record_cpu_map_data' is packed as unfortunately an earlier 191 * version had unaligned data and we wish to retain file format compatibility. 192 * -irogers 193 */ 194 #pragma GCC diagnostic push 195 #pragma GCC diagnostic ignored "-Wpacked" 196 #pragma GCC diagnostic ignored "-Wattributes" 197 198 struct __packed perf_record_cpu_map_data { 199 __u16 type; 200 union { 201 /* Used when type == PERF_CPU_MAP__CPUS. */ 202 struct cpu_map_entries cpus_data; 203 /* Used when type == PERF_CPU_MAP__MASK and long_size == 4. */ 204 struct perf_record_mask_cpu_map32 mask32_data; 205 /* Used when type == PERF_CPU_MAP__MASK and long_size == 8. */ 206 struct perf_record_mask_cpu_map64 mask64_data; 207 }; 208 }; 209 210 #pragma GCC diagnostic pop 211 212 struct perf_record_cpu_map { 213 struct perf_event_header header; 214 struct perf_record_cpu_map_data data; 215 }; 216 217 enum { 218 PERF_EVENT_UPDATE__UNIT = 0, 219 PERF_EVENT_UPDATE__SCALE = 1, 220 PERF_EVENT_UPDATE__NAME = 2, 221 PERF_EVENT_UPDATE__CPUS = 3, 222 }; 223 224 struct perf_record_event_update_cpus { 225 struct perf_record_cpu_map_data cpus; 226 }; 227 228 struct perf_record_event_update_scale { 229 double scale; 230 }; 231 232 struct perf_record_event_update { 233 struct perf_event_header header; 234 __u64 type; 235 __u64 id; 236 char data[]; 237 }; 238 239 #define MAX_EVENT_NAME 64 240 241 struct perf_trace_event_type { 242 __u64 event_id; 243 char name[MAX_EVENT_NAME]; 244 }; 245 246 struct perf_record_header_event_type { 247 struct perf_event_header header; 248 struct perf_trace_event_type event_type; 249 }; 250 251 struct perf_record_header_tracing_data { 252 struct perf_event_header header; 253 __u32 size; 254 }; 255 256 #define PERF_RECORD_MISC_BUILD_ID_SIZE (1 << 15) 257 258 struct perf_record_header_build_id { 259 struct perf_event_header header; 260 pid_t pid; 261 union { 262 __u8 build_id[24]; 263 struct { 264 __u8 data[20]; 265 __u8 size; 266 __u8 reserved1__; 267 __u16 reserved2__; 268 }; 269 }; 270 char filename[]; 271 }; 272 273 struct id_index_entry { 274 __u64 id; 275 __u64 idx; 276 __u64 cpu; 277 __u64 tid; 278 }; 279 280 struct id_index_entry_2 { 281 __u64 machine_pid; 282 __u64 vcpu; 283 }; 284 285 struct perf_record_id_index { 286 struct perf_event_header header; 287 __u64 nr; 288 struct id_index_entry entries[]; 289 }; 290 291 struct perf_record_auxtrace_info { 292 struct perf_event_header header; 293 __u32 type; 294 __u32 reserved__; /* For alignment */ 295 __u64 priv[]; 296 }; 297 298 struct perf_record_auxtrace { 299 struct perf_event_header header; 300 __u64 size; 301 __u64 offset; 302 __u64 reference; 303 __u32 idx; 304 __u32 tid; 305 __u32 cpu; 306 __u32 reserved__; /* For alignment */ 307 }; 308 309 #define MAX_AUXTRACE_ERROR_MSG 64 310 311 struct perf_record_auxtrace_error { 312 struct perf_event_header header; 313 __u32 type; 314 __u32 code; 315 __u32 cpu; 316 __u32 pid; 317 __u32 tid; 318 __u32 fmt; 319 __u64 ip; 320 __u64 time; 321 char msg[MAX_AUXTRACE_ERROR_MSG]; 322 __u32 machine_pid; 323 __u32 vcpu; 324 }; 325 326 struct perf_record_aux { 327 struct perf_event_header header; 328 __u64 aux_offset; 329 __u64 aux_size; 330 __u64 flags; 331 }; 332 333 struct perf_record_itrace_start { 334 struct perf_event_header header; 335 __u32 pid; 336 __u32 tid; 337 }; 338 339 struct perf_record_aux_output_hw_id { 340 struct perf_event_header header; 341 __u64 hw_id; 342 }; 343 344 struct perf_record_thread_map_entry { 345 __u64 pid; 346 char comm[16]; 347 }; 348 349 struct perf_record_thread_map { 350 struct perf_event_header header; 351 __u64 nr; 352 struct perf_record_thread_map_entry entries[]; 353 }; 354 355 enum { 356 PERF_STAT_CONFIG_TERM__AGGR_MODE = 0, 357 PERF_STAT_CONFIG_TERM__INTERVAL = 1, 358 PERF_STAT_CONFIG_TERM__SCALE = 2, 359 PERF_STAT_CONFIG_TERM__MAX = 3, 360 }; 361 362 struct perf_record_stat_config_entry { 363 __u64 tag; 364 __u64 val; 365 }; 366 367 struct perf_record_stat_config { 368 struct perf_event_header header; 369 __u64 nr; 370 struct perf_record_stat_config_entry data[]; 371 }; 372 373 struct perf_record_stat { 374 struct perf_event_header header; 375 376 __u64 id; 377 __u32 cpu; 378 __u32 thread; 379 380 union { 381 struct { 382 __u64 val; 383 __u64 ena; 384 __u64 run; 385 }; 386 __u64 values[3]; 387 }; 388 }; 389 390 struct perf_record_stat_round { 391 struct perf_event_header header; 392 __u64 type; 393 __u64 time; 394 }; 395 396 struct perf_record_time_conv { 397 struct perf_event_header header; 398 __u64 time_shift; 399 __u64 time_mult; 400 __u64 time_zero; 401 __u64 time_cycles; 402 __u64 time_mask; 403 __u8 cap_user_time_zero; 404 __u8 cap_user_time_short; 405 __u8 reserved[6]; /* For alignment */ 406 }; 407 408 struct perf_record_header_feature { 409 struct perf_event_header header; 410 __u64 feat_id; 411 char data[]; 412 }; 413 414 struct perf_record_compressed { 415 struct perf_event_header header; 416 char data[]; 417 }; 418 419 enum perf_user_event_type { /* above any possible kernel type */ 420 PERF_RECORD_USER_TYPE_START = 64, 421 PERF_RECORD_HEADER_ATTR = 64, 422 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */ 423 PERF_RECORD_HEADER_TRACING_DATA = 66, 424 PERF_RECORD_HEADER_BUILD_ID = 67, 425 PERF_RECORD_FINISHED_ROUND = 68, 426 PERF_RECORD_ID_INDEX = 69, 427 PERF_RECORD_AUXTRACE_INFO = 70, 428 PERF_RECORD_AUXTRACE = 71, 429 PERF_RECORD_AUXTRACE_ERROR = 72, 430 PERF_RECORD_THREAD_MAP = 73, 431 PERF_RECORD_CPU_MAP = 74, 432 PERF_RECORD_STAT_CONFIG = 75, 433 PERF_RECORD_STAT = 76, 434 PERF_RECORD_STAT_ROUND = 77, 435 PERF_RECORD_EVENT_UPDATE = 78, 436 PERF_RECORD_TIME_CONV = 79, 437 PERF_RECORD_HEADER_FEATURE = 80, 438 PERF_RECORD_COMPRESSED = 81, 439 PERF_RECORD_FINISHED_INIT = 82, 440 PERF_RECORD_HEADER_MAX 441 }; 442 443 union perf_event { 444 struct perf_event_header header; 445 struct perf_record_mmap mmap; 446 struct perf_record_mmap2 mmap2; 447 struct perf_record_comm comm; 448 struct perf_record_namespaces namespaces; 449 struct perf_record_cgroup cgroup; 450 struct perf_record_fork fork; 451 struct perf_record_lost lost; 452 struct perf_record_lost_samples lost_samples; 453 struct perf_record_read read; 454 struct perf_record_throttle throttle; 455 struct perf_record_sample sample; 456 struct perf_record_bpf_event bpf; 457 struct perf_record_ksymbol ksymbol; 458 struct perf_record_text_poke_event text_poke; 459 struct perf_record_header_attr attr; 460 struct perf_record_event_update event_update; 461 struct perf_record_header_event_type event_type; 462 struct perf_record_header_tracing_data tracing_data; 463 struct perf_record_header_build_id build_id; 464 struct perf_record_id_index id_index; 465 struct perf_record_auxtrace_info auxtrace_info; 466 struct perf_record_auxtrace auxtrace; 467 struct perf_record_auxtrace_error auxtrace_error; 468 struct perf_record_aux aux; 469 struct perf_record_itrace_start itrace_start; 470 struct perf_record_aux_output_hw_id aux_output_hw_id; 471 struct perf_record_switch context_switch; 472 struct perf_record_thread_map thread_map; 473 struct perf_record_cpu_map cpu_map; 474 struct perf_record_stat_config stat_config; 475 struct perf_record_stat stat; 476 struct perf_record_stat_round stat_round; 477 struct perf_record_time_conv time_conv; 478 struct perf_record_header_feature feat; 479 struct perf_record_compressed pack; 480 }; 481 482 #endif /* __LIBPERF_EVENT_H */ 483