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 perf_record_id_index { 241 struct perf_event_header header; 242 __u64 nr; 243 struct id_index_entry entries[]; 244 }; 245 246 struct perf_record_auxtrace_info { 247 struct perf_event_header header; 248 __u32 type; 249 __u32 reserved__; /* For alignment */ 250 __u64 priv[]; 251 }; 252 253 struct perf_record_auxtrace { 254 struct perf_event_header header; 255 __u64 size; 256 __u64 offset; 257 __u64 reference; 258 __u32 idx; 259 __u32 tid; 260 __u32 cpu; 261 __u32 reserved__; /* For alignment */ 262 }; 263 264 #define MAX_AUXTRACE_ERROR_MSG 64 265 266 struct perf_record_auxtrace_error { 267 struct perf_event_header header; 268 __u32 type; 269 __u32 code; 270 __u32 cpu; 271 __u32 pid; 272 __u32 tid; 273 __u32 fmt; 274 __u64 ip; 275 __u64 time; 276 char msg[MAX_AUXTRACE_ERROR_MSG]; 277 }; 278 279 struct perf_record_aux { 280 struct perf_event_header header; 281 __u64 aux_offset; 282 __u64 aux_size; 283 __u64 flags; 284 }; 285 286 struct perf_record_itrace_start { 287 struct perf_event_header header; 288 __u32 pid; 289 __u32 tid; 290 }; 291 292 struct perf_record_aux_output_hw_id { 293 struct perf_event_header header; 294 __u64 hw_id; 295 }; 296 297 struct perf_record_thread_map_entry { 298 __u64 pid; 299 char comm[16]; 300 }; 301 302 struct perf_record_thread_map { 303 struct perf_event_header header; 304 __u64 nr; 305 struct perf_record_thread_map_entry entries[]; 306 }; 307 308 enum { 309 PERF_STAT_CONFIG_TERM__AGGR_MODE = 0, 310 PERF_STAT_CONFIG_TERM__INTERVAL = 1, 311 PERF_STAT_CONFIG_TERM__SCALE = 2, 312 PERF_STAT_CONFIG_TERM__MAX = 3, 313 }; 314 315 struct perf_record_stat_config_entry { 316 __u64 tag; 317 __u64 val; 318 }; 319 320 struct perf_record_stat_config { 321 struct perf_event_header header; 322 __u64 nr; 323 struct perf_record_stat_config_entry data[]; 324 }; 325 326 struct perf_record_stat { 327 struct perf_event_header header; 328 329 __u64 id; 330 __u32 cpu; 331 __u32 thread; 332 333 union { 334 struct { 335 __u64 val; 336 __u64 ena; 337 __u64 run; 338 }; 339 __u64 values[3]; 340 }; 341 }; 342 343 struct perf_record_stat_round { 344 struct perf_event_header header; 345 __u64 type; 346 __u64 time; 347 }; 348 349 struct perf_record_time_conv { 350 struct perf_event_header header; 351 __u64 time_shift; 352 __u64 time_mult; 353 __u64 time_zero; 354 __u64 time_cycles; 355 __u64 time_mask; 356 __u8 cap_user_time_zero; 357 __u8 cap_user_time_short; 358 __u8 reserved[6]; /* For alignment */ 359 }; 360 361 struct perf_record_header_feature { 362 struct perf_event_header header; 363 __u64 feat_id; 364 char data[]; 365 }; 366 367 struct perf_record_compressed { 368 struct perf_event_header header; 369 char data[]; 370 }; 371 372 enum perf_user_event_type { /* above any possible kernel type */ 373 PERF_RECORD_USER_TYPE_START = 64, 374 PERF_RECORD_HEADER_ATTR = 64, 375 PERF_RECORD_HEADER_EVENT_TYPE = 65, /* deprecated */ 376 PERF_RECORD_HEADER_TRACING_DATA = 66, 377 PERF_RECORD_HEADER_BUILD_ID = 67, 378 PERF_RECORD_FINISHED_ROUND = 68, 379 PERF_RECORD_ID_INDEX = 69, 380 PERF_RECORD_AUXTRACE_INFO = 70, 381 PERF_RECORD_AUXTRACE = 71, 382 PERF_RECORD_AUXTRACE_ERROR = 72, 383 PERF_RECORD_THREAD_MAP = 73, 384 PERF_RECORD_CPU_MAP = 74, 385 PERF_RECORD_STAT_CONFIG = 75, 386 PERF_RECORD_STAT = 76, 387 PERF_RECORD_STAT_ROUND = 77, 388 PERF_RECORD_EVENT_UPDATE = 78, 389 PERF_RECORD_TIME_CONV = 79, 390 PERF_RECORD_HEADER_FEATURE = 80, 391 PERF_RECORD_COMPRESSED = 81, 392 PERF_RECORD_HEADER_MAX 393 }; 394 395 union perf_event { 396 struct perf_event_header header; 397 struct perf_record_mmap mmap; 398 struct perf_record_mmap2 mmap2; 399 struct perf_record_comm comm; 400 struct perf_record_namespaces namespaces; 401 struct perf_record_cgroup cgroup; 402 struct perf_record_fork fork; 403 struct perf_record_lost lost; 404 struct perf_record_lost_samples lost_samples; 405 struct perf_record_read read; 406 struct perf_record_throttle throttle; 407 struct perf_record_sample sample; 408 struct perf_record_bpf_event bpf; 409 struct perf_record_ksymbol ksymbol; 410 struct perf_record_text_poke_event text_poke; 411 struct perf_record_header_attr attr; 412 struct perf_record_event_update event_update; 413 struct perf_record_header_event_type event_type; 414 struct perf_record_header_tracing_data tracing_data; 415 struct perf_record_header_build_id build_id; 416 struct perf_record_id_index id_index; 417 struct perf_record_auxtrace_info auxtrace_info; 418 struct perf_record_auxtrace auxtrace; 419 struct perf_record_auxtrace_error auxtrace_error; 420 struct perf_record_aux aux; 421 struct perf_record_itrace_start itrace_start; 422 struct perf_record_aux_output_hw_id aux_output_hw_id; 423 struct perf_record_switch context_switch; 424 struct perf_record_thread_map thread_map; 425 struct perf_record_cpu_map cpu_map; 426 struct perf_record_stat_config stat_config; 427 struct perf_record_stat stat; 428 struct perf_record_stat_round stat_round; 429 struct perf_record_time_conv time_conv; 430 struct perf_record_header_feature feat; 431 struct perf_record_compressed pack; 432 }; 433 434 #endif /* __LIBPERF_EVENT_H */ 435