1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_RECORD_H
3 #define __PERF_RECORD_H
5 * The linux/stddef.h isn't need here, but is needed for __always_inline used
6 * in files included from uapi/linux/perf_event.h such as
7 * /usr/include/linux/swab.h and /usr/include/linux/byteorder/little_endian.h,
8 * detected in at least musl libc, used in Alpine Linux. -acme
11 #include <linux/stddef.h>
12 #include <perf/event.h>
13 #include <linux/types.h>
15 #include "perf_regs.h"
19 struct perf_event_attr;
23 * /usr/include/inttypes.h uses just 'lu' for PRIu64, but we end up defining
24 * __u64 as long long unsigned int, and then -Werror=format= kicks in and
25 * complains of the mismatched types, so use these two special extra PRI
26 * macros to overcome that.
28 #define PRI_lu64 "l" PRIu64
29 #define PRI_lx64 "l" PRIx64
30 #define PRI_ld64 "l" PRId64
32 #define PRI_lu64 PRIu64
33 #define PRI_lx64 PRIx64
34 #define PRI_ld64 PRId64
37 #define PERF_SAMPLE_MASK \
38 (PERF_SAMPLE_IP | PERF_SAMPLE_TID | \
39 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR | \
40 PERF_SAMPLE_ID | PERF_SAMPLE_STREAM_ID | \
41 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD | \
42 PERF_SAMPLE_IDENTIFIER)
44 /* perf sample has 16 bits size limit */
45 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
52 /* Cached values/mask filled by first register access. */
53 u64 cache_regs[PERF_REGS_MAX];
63 struct sample_read_value {
74 struct sample_read_value *values;
76 struct sample_read_value one;
88 PERF_IP_FLAG_BRANCH = 1ULL << 0,
89 PERF_IP_FLAG_CALL = 1ULL << 1,
90 PERF_IP_FLAG_RETURN = 1ULL << 2,
91 PERF_IP_FLAG_CONDITIONAL = 1ULL << 3,
92 PERF_IP_FLAG_SYSCALLRET = 1ULL << 4,
93 PERF_IP_FLAG_ASYNC = 1ULL << 5,
94 PERF_IP_FLAG_INTERRUPT = 1ULL << 6,
95 PERF_IP_FLAG_TX_ABORT = 1ULL << 7,
96 PERF_IP_FLAG_TRACE_BEGIN = 1ULL << 8,
97 PERF_IP_FLAG_TRACE_END = 1ULL << 9,
98 PERF_IP_FLAG_IN_TX = 1ULL << 10,
101 #define PERF_IP_FLAG_CHARS "bcrosyiABEx"
103 #define PERF_BRANCH_MASK (\
104 PERF_IP_FLAG_BRANCH |\
106 PERF_IP_FLAG_RETURN |\
107 PERF_IP_FLAG_CONDITIONAL |\
108 PERF_IP_FLAG_SYSCALLRET |\
109 PERF_IP_FLAG_ASYNC |\
110 PERF_IP_FLAG_INTERRUPT |\
111 PERF_IP_FLAG_TX_ABORT |\
112 PERF_IP_FLAG_TRACE_BEGIN |\
113 PERF_IP_FLAG_TRACE_END)
139 struct ip_callchain *callchain;
140 struct branch_stack *branch_stack;
141 struct regs_dump user_regs;
142 struct regs_dump intr_regs;
143 struct stack_dump user_stack;
144 struct sample_read read;
147 #define PERF_MEM_DATA_SRC_NONE \
148 (PERF_MEM_S(OP, NA) |\
149 PERF_MEM_S(LVL, NA) |\
150 PERF_MEM_S(SNOOP, NA) |\
151 PERF_MEM_S(LOCK, NA) |\
154 /* Attribute type for custom synthesized events */
155 #define PERF_TYPE_SYNTH (INT_MAX + 1U)
157 /* Attribute config for custom synthesized events */
159 PERF_SYNTH_INTEL_PTWRITE,
160 PERF_SYNTH_INTEL_MWAIT,
161 PERF_SYNTH_INTEL_PWRE,
162 PERF_SYNTH_INTEL_EXSTOP,
163 PERF_SYNTH_INTEL_PWRX,
164 PERF_SYNTH_INTEL_CBR,
168 * Raw data formats for synthesized events. Note that 4 bytes of padding are
169 * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
170 * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
171 * Refer perf_sample__synth_ptr() and perf_synth__raw_data(). It also means the
172 * structure sizes are 4 bytes bigger than the raw_size, refer
173 * perf_synth__raw_size().
176 struct perf_synth_intel_ptwrite {
188 struct perf_synth_intel_mwait {
202 struct perf_synth_intel_pwre {
217 struct perf_synth_intel_exstop {
228 struct perf_synth_intel_pwrx {
233 u64 deepest_cstate : 4,
242 struct perf_synth_intel_cbr {
258 * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
261 static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
263 return sample->raw_data - 4;
266 static inline void *perf_synth__raw_data(void *p)
271 #define perf_synth__raw_size(d) (sizeof(d) - 4)
273 #define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
276 PERF_STAT_ROUND_TYPE__INTERVAL = 0,
277 PERF_STAT_ROUND_TYPE__FINAL = 1,
280 void perf_event__print_totals(void);
283 struct perf_thread_map;
285 struct perf_stat_config;
286 struct perf_counts_values;
288 typedef int (*perf_event__handler_t)(struct perf_tool *tool,
289 union perf_event *event,
290 struct perf_sample *sample,
291 struct machine *machine);
293 int perf_event__synthesize_thread_map(struct perf_tool *tool,
294 struct perf_thread_map *threads,
295 perf_event__handler_t process,
296 struct machine *machine, bool mmap_data);
297 int perf_event__synthesize_thread_map2(struct perf_tool *tool,
298 struct perf_thread_map *threads,
299 perf_event__handler_t process,
300 struct machine *machine);
301 int perf_event__synthesize_cpu_map(struct perf_tool *tool,
302 struct perf_cpu_map *cpus,
303 perf_event__handler_t process,
304 struct machine *machine);
305 int perf_event__synthesize_threads(struct perf_tool *tool,
306 perf_event__handler_t process,
307 struct machine *machine, bool mmap_data,
308 unsigned int nr_threads_synthesize);
309 int perf_event__synthesize_kernel_mmap(struct perf_tool *tool,
310 perf_event__handler_t process,
311 struct machine *machine);
312 int perf_event__synthesize_stat_config(struct perf_tool *tool,
313 struct perf_stat_config *config,
314 perf_event__handler_t process,
315 struct machine *machine);
316 void perf_event__read_stat_config(struct perf_stat_config *config,
317 struct perf_record_stat_config *event);
318 int perf_event__synthesize_stat(struct perf_tool *tool,
319 u32 cpu, u32 thread, u64 id,
320 struct perf_counts_values *count,
321 perf_event__handler_t process,
322 struct machine *machine);
323 int perf_event__synthesize_stat_round(struct perf_tool *tool,
325 perf_event__handler_t process,
326 struct machine *machine);
327 int perf_event__synthesize_modules(struct perf_tool *tool,
328 perf_event__handler_t process,
329 struct machine *machine);
331 int perf_event__process_comm(struct perf_tool *tool,
332 union perf_event *event,
333 struct perf_sample *sample,
334 struct machine *machine);
335 int perf_event__process_lost(struct perf_tool *tool,
336 union perf_event *event,
337 struct perf_sample *sample,
338 struct machine *machine);
339 int perf_event__process_lost_samples(struct perf_tool *tool,
340 union perf_event *event,
341 struct perf_sample *sample,
342 struct machine *machine);
343 int perf_event__process_aux(struct perf_tool *tool,
344 union perf_event *event,
345 struct perf_sample *sample,
346 struct machine *machine);
347 int perf_event__process_itrace_start(struct perf_tool *tool,
348 union perf_event *event,
349 struct perf_sample *sample,
350 struct machine *machine);
351 int perf_event__process_switch(struct perf_tool *tool,
352 union perf_event *event,
353 struct perf_sample *sample,
354 struct machine *machine);
355 int perf_event__process_namespaces(struct perf_tool *tool,
356 union perf_event *event,
357 struct perf_sample *sample,
358 struct machine *machine);
359 int perf_event__process_mmap(struct perf_tool *tool,
360 union perf_event *event,
361 struct perf_sample *sample,
362 struct machine *machine);
363 int perf_event__process_mmap2(struct perf_tool *tool,
364 union perf_event *event,
365 struct perf_sample *sample,
366 struct machine *machine);
367 int perf_event__process_fork(struct perf_tool *tool,
368 union perf_event *event,
369 struct perf_sample *sample,
370 struct machine *machine);
371 int perf_event__process_exit(struct perf_tool *tool,
372 union perf_event *event,
373 struct perf_sample *sample,
374 struct machine *machine);
375 int perf_event__process_ksymbol(struct perf_tool *tool,
376 union perf_event *event,
377 struct perf_sample *sample,
378 struct machine *machine);
379 int perf_event__process_bpf(struct perf_tool *tool,
380 union perf_event *event,
381 struct perf_sample *sample,
382 struct machine *machine);
383 int perf_tool__process_synth_event(struct perf_tool *tool,
384 union perf_event *event,
385 struct machine *machine,
386 perf_event__handler_t process);
387 int perf_event__process(struct perf_tool *tool,
388 union perf_event *event,
389 struct perf_sample *sample,
390 struct machine *machine);
392 struct addr_location;
394 int machine__resolve(struct machine *machine, struct addr_location *al,
395 struct perf_sample *sample);
397 void addr_location__put(struct addr_location *al);
401 bool is_bts_event(struct perf_event_attr *attr);
402 bool sample_addr_correlates_sym(struct perf_event_attr *attr);
403 void thread__resolve(struct thread *thread, struct addr_location *al,
404 struct perf_sample *sample);
406 const char *perf_event__name(unsigned int id);
408 size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type,
410 int perf_event__synthesize_sample(union perf_event *event, u64 type,
412 const struct perf_sample *sample);
414 pid_t perf_event__synthesize_comm(struct perf_tool *tool,
415 union perf_event *event, pid_t pid,
416 perf_event__handler_t process,
417 struct machine *machine);
419 int perf_event__synthesize_namespaces(struct perf_tool *tool,
420 union perf_event *event,
421 pid_t pid, pid_t tgid,
422 perf_event__handler_t process,
423 struct machine *machine);
425 int perf_event__synthesize_mmap_events(struct perf_tool *tool,
426 union perf_event *event,
427 pid_t pid, pid_t tgid,
428 perf_event__handler_t process,
429 struct machine *machine,
432 int perf_event__synthesize_extra_kmaps(struct perf_tool *tool,
433 perf_event__handler_t process,
434 struct machine *machine);
436 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
437 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
438 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
439 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
440 size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
441 size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
442 size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
443 size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
444 size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
445 size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
446 size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
447 size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
448 size_t perf_event__fprintf(union perf_event *event, FILE *fp);
450 int kallsyms__get_function_start(const char *kallsyms_filename,
451 const char *symbol_name, u64 *addr);
453 void *cpu_map_data__alloc(struct perf_cpu_map *map, size_t *size, u16 *type, int *max);
454 void cpu_map_data__synthesize(struct perf_record_cpu_map_data *data, struct perf_cpu_map *map,
457 void event_attr_init(struct perf_event_attr *attr);
459 int perf_event_paranoid(void);
460 bool perf_event_paranoid_check(int max_level);
462 extern int sysctl_perf_event_max_stack;
463 extern int sysctl_perf_event_max_contexts_per_stack;
464 extern unsigned int proc_map_timeout;
466 #endif /* __PERF_RECORD_H */