1 2 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PERF_PERF_EVENT_H_ 3 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_PERF_EVENT_H_ 4 5 #include <cstdint> 6 7 // Renaming the user space API types to fixed integer typedefs of C++. 8 9 enum perf_type_id { 10 PERF_TYPE_HARDWARE = 0, 11 PERF_TYPE_SOFTWARE = 1, 12 PERF_TYPE_TRACEPOINT = 2, 13 PERF_TYPE_HW_CACHE = 3, 14 PERF_TYPE_RAW = 4, 15 PERF_TYPE_BREAKPOINT = 5, 16 17 PERF_TYPE_MAX, /* non-ABI */ 18 }; 19 20 /* 21 * Hardware event_id to monitor via a performance monitoring event: 22 * 23 * @sample_max_stack: Max number of frame pointers in a callchain, 24 * should be < /proc/sys/kernel/perf_event_max_stack 25 */ 26 struct perf_event_attr { 27 /* 28 * Major type: hardware/software/tracepoint/etc. 29 */ 30 uint32_t type; 31 32 /* 33 * Size of the attr structure, for fwd/bwd compat. 34 */ 35 uint32_t size; 36 37 /* 38 * Type specific configuration information. 39 */ 40 uint64_t config; 41 42 union { 43 uint64_t sample_period; 44 uint64_t sample_freq; 45 }; 46 47 uint64_t sample_type; 48 uint64_t read_format; 49 50 uint64_t disabled : 1, /* off by default */ 51 inherit : 1, /* children inherit it */ 52 pinned : 1, /* must always be on PMU */ 53 exclusive : 1, /* only group on PMU */ 54 exclude_user : 1, /* don't count user */ 55 exclude_kernel : 1, /* ditto kernel */ 56 exclude_hv : 1, /* ditto hypervisor */ 57 exclude_idle : 1, /* don't count when idle */ 58 mmap : 1, /* include mmap data */ 59 comm : 1, /* include comm data */ 60 freq : 1, /* use freq, not period */ 61 inherit_stat : 1, /* per task counts */ 62 enable_on_exec : 1, /* next exec enables */ 63 task : 1, /* trace fork/exit */ 64 watermark : 1, /* wakeup_watermark */ 65 /* 66 * precise_ip: 67 * 68 * 0 - SAMPLE_IP can have arbitrary skid 69 * 1 - SAMPLE_IP must have constant skid 70 * 2 - SAMPLE_IP requested to have 0 skid 71 * 3 - SAMPLE_IP must have 0 skid 72 * 73 * See also PERF_RECORD_MISC_EXACT_IP 74 */ 75 precise_ip : 2, /* skid constraint */ 76 mmap_data : 1, /* non-exec mmap data */ 77 sample_id_all : 1, /* sample_type all events */ 78 79 exclude_host : 1, /* don't count in host */ 80 exclude_guest : 1, /* don't count in guest */ 81 82 exclude_callchain_kernel : 1, /* exclude kernel callchains */ 83 exclude_callchain_user : 1, /* exclude user callchains */ 84 mmap2 : 1, /* include mmap with inode data */ 85 comm_exec : 1, /* flag comm events that are due to an exec */ 86 use_clockid : 1, /* use @clockid for time fields */ 87 context_switch : 1, /* context switch data */ 88 write_backward : 1, /* Write ring buffer from end to beginning */ 89 namespaces : 1, /* include namespaces data */ 90 ksymbol : 1, /* include ksymbol events */ 91 bpf_event : 1, /* include bpf events */ 92 aux_output : 1, /* generate AUX records instead of events */ 93 cgroup : 1, /* include cgroup events */ 94 text_poke : 1, /* include text poke events */ 95 build_id : 1, /* use build id in mmap2 events */ 96 inherit_thread : 1, /* children only inherit if cloned with CLONE_THREAD 97 */ 98 remove_on_exec : 1, /* event is removed from task on exec */ 99 sigtrap : 1, /* send synchronous SIGTRAP on event */ 100 __reserved_1 : 26; 101 102 union { 103 uint32_t wakeup_events; /* wakeup every n events */ 104 uint32_t wakeup_watermark; /* bytes before wakeup */ 105 }; 106 107 uint32_t bp_type; 108 union { 109 uint64_t bp_addr; 110 uint64_t kprobe_func; /* for perf_kprobe */ 111 uint64_t uprobe_path; /* for perf_uprobe */ 112 uint64_t config1; /* extension of config */ 113 }; 114 union { 115 uint64_t bp_len; 116 uint64_t kprobe_addr; /* when kprobe_func == NULL */ 117 uint64_t probe_offset; /* for perf_[k,u]probe */ 118 uint64_t config2; /* extension of config1 */ 119 }; 120 uint64_t branch_sample_type; /* enum perf_branch_sample_type */ 121 122 /* 123 * Defines set of user regs to dump on samples. 124 * See asm/perf_regs.h for details. 125 */ 126 uint64_t sample_regs_user; 127 128 /* 129 * Defines size of the user stack to dump on samples. 130 */ 131 uint32_t sample_stack_user; 132 133 int32_t clockid; 134 /* 135 * Defines set of regs to dump for each sample 136 * state captured on: 137 * - precise = 0: PMU interrupt 138 * - precise > 0: sampled instruction 139 * 140 * See asm/perf_regs.h for details. 141 */ 142 uint64_t sample_regs_intr; 143 144 /* 145 * Wakeup watermark for AUX area 146 */ 147 uint32_t aux_watermark; 148 uint16_t sample_max_stack; 149 uint16_t __reserved_2; 150 uint32_t aux_sample_size; 151 uint32_t __reserved_3; 152 153 /* 154 * User provided data if sigtrap=1, passed back to user via 155 * siginfo_t::si_perf_data, e.g. to permit user to identify the event. 156 * Note, siginfo_t::si_perf_data is long-sized, and sig_data will be 157 * truncated accordingly on 32 bit architectures. 158 */ 159 uint64_t sig_data; 160 161 uint64_t config3; /* extension of config2 */ 162 }; 163 164 struct perf_event_header { 165 // Value from `perf_event_type` 166 uint32_t type; 167 uint16_t misc; 168 uint16_t size; 169 }; 170 171 enum perf_event_type { 172 PERF_RECORD_MMAP = 1, 173 PERF_RECORD_LOST = 2, 174 PERF_RECORD_COMM = 3, 175 PERF_RECORD_EXIT = 4, 176 PERF_RECORD_THROTTLE = 5, 177 PERF_RECORD_UNTHROTTLE = 6, 178 PERF_RECORD_FORK = 7, 179 PERF_RECORD_READ = 8, 180 PERF_RECORD_SAMPLE = 9, 181 PERF_RECORD_MMAP2 = 10, 182 PERF_RECORD_AUX = 11, 183 PERF_RECORD_ITRACE_START = 12, 184 PERF_RECORD_LOST_SAMPLES = 13, 185 PERF_RECORD_SWITCH = 14, 186 PERF_RECORD_SWITCH_CPU_WIDE = 15, 187 PERF_RECORD_NAMESPACES = 16, 188 PERF_RECORD_KSYMBOL = 17, 189 PERF_RECORD_BPF_EVENT = 18, 190 PERF_RECORD_CGROUP = 19, 191 PERF_RECORD_TEXT_POKE = 20, 192 PERF_RECORD_AUX_OUTPUT_HW_ID = 21, 193 194 PERF_RECORD_USER_TYPE_START = 64, 195 PERF_RECORD_AUXTRACE_INFO = 70, 196 PERF_RECORD_AUXTRACE = 71, 197 PERF_RECORD_TIME_CONV = 79, 198 PERF_RECORD_MAX, /* non-ABI */ 199 }; 200 201 enum perf_event_sample_format { 202 PERF_SAMPLE_IP = 1U << 0, 203 PERF_SAMPLE_TID = 1U << 1, 204 PERF_SAMPLE_TIME = 1U << 2, 205 PERF_SAMPLE_ADDR = 1U << 3, 206 PERF_SAMPLE_READ = 1U << 4, 207 PERF_SAMPLE_CALLCHAIN = 1U << 5, 208 PERF_SAMPLE_ID = 1U << 6, 209 PERF_SAMPLE_CPU = 1U << 7, 210 PERF_SAMPLE_PERIOD = 1U << 8, 211 PERF_SAMPLE_STREAM_ID = 1U << 9, 212 PERF_SAMPLE_RAW = 1U << 10, 213 PERF_SAMPLE_BRANCH_STACK = 1U << 11, 214 PERF_SAMPLE_REGS_USER = 1U << 12, 215 PERF_SAMPLE_STACK_USER = 1U << 13, 216 PERF_SAMPLE_WEIGHT = 1U << 14, 217 PERF_SAMPLE_DATA_SRC = 1U << 15, 218 PERF_SAMPLE_IDENTIFIER = 1U << 16, 219 PERF_SAMPLE_TRANSACTION = 1U << 17, 220 PERF_SAMPLE_REGS_INTR = 1U << 18, 221 PERF_SAMPLE_PHYS_ADDR = 1U << 19, 222 PERF_SAMPLE_AUX = 1U << 20, 223 PERF_SAMPLE_CGROUP = 1U << 21, 224 PERF_SAMPLE_DATA_PAGE_SIZE = 1U << 22, 225 PERF_SAMPLE_CODE_PAGE_SIZE = 1U << 23, 226 PERF_SAMPLE_WEIGHT_STRUCT = 1U << 24, 227 228 PERF_SAMPLE_MAX = 1U << 25, /* non-ABI */ 229 }; 230 231 constexpr auto kPerfRecordMiscCpumodeMask = 0x7; 232 233 enum perf_record_misc { 234 PERF_RECORD_MISC_CPUMODE_UNKNOWN = 0, 235 PERF_RECORD_MISC_KERNEL = 1, 236 PERF_RECORD_MISC_USER = 2, 237 PERF_RECORD_MISC_HYPERVISOR = 3, 238 PERF_RECORD_MISC_GUEST_KERNEL = 4, 239 PERF_RECORD_MISC_GUEST_USER = 5, 240 241 PERF_RECORD_MISC_MMAP_BUILD_ID = 1U << 14, 242 PERF_RECORD_MISC_EXT_RESERVED = 1U << 15, 243 }; 244 245 enum perf_event_read_format { 246 PERF_FORMAT_TOTAL_TIME_ENABLED = 1U << 0, 247 PERF_FORMAT_TOTAL_TIME_RUNNING = 1U << 1, 248 PERF_FORMAT_ID = 1U << 2, 249 PERF_FORMAT_GROUP = 1U << 3, 250 PERF_FORMAT_LOST = 1U << 4, 251 252 PERF_FORMAT_MAX = 1U << 5, /* non-ABI */ 253 }; 254 255 enum perf_callchain_context : uint64_t { 256 PERF_CONTEXT_HV = static_cast<uint64_t>(-32), 257 PERF_CONTEXT_KERNEL = static_cast<uint64_t>(-128), 258 PERF_CONTEXT_USER = static_cast<uint64_t>(-512), 259 260 PERF_CONTEXT_GUEST = static_cast<uint64_t>(-2048), 261 PERF_CONTEXT_GUEST_KERNEL = static_cast<uint64_t>(-2176), 262 PERF_CONTEXT_GUEST_USER = static_cast<uint64_t>(-2560), 263 264 PERF_CONTEXT_MAX = static_cast<uint64_t>(-4095), 265 }; 266 267 enum auxtrace_type { 268 PERF_AUXTRACE_UNKNOWN, 269 PERF_AUXTRACE_INTEL_PT, 270 PERF_AUXTRACE_INTEL_BTS, 271 PERF_AUXTRACE_CS_ETM, 272 PERF_AUXTRACE_ARM_SPE, 273 PERF_AUXTRACE_S390_CPUMSF, 274 PERF_AUXTRACE_HISI_PTT, 275 }; 276 277 enum perf_aux_flag { 278 PERF_AUX_FLAG_TRUNCATED = 1U << 0, 279 PERF_AUX_FLAG_OVERWRITE = 1U << 1, 280 PERF_AUX_FLAG_PARTIAL = 1U << 2, 281 PERF_AUX_FLAG_COLLISION = 1U << 3, 282 PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW = 1U << 8, 283 }; 284 285 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_PERF_EVENT_H_ 286