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