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)
47 /* number of register is bound by the number of bits in regs_dump::mask (64) */
48 #define PERF_SAMPLE_REGS_CACHE_SIZE (8 * sizeof(u64))
55 /* Cached values/mask filled by first register access. */
56 u64 cache_regs[PERF_SAMPLE_REGS_CACHE_SIZE];
66 struct sample_read_value {
77 struct sample_read_value *values;
79 struct sample_read_value one;
91 PERF_IP_FLAG_BRANCH = 1ULL << 0,
92 PERF_IP_FLAG_CALL = 1ULL << 1,
93 PERF_IP_FLAG_RETURN = 1ULL << 2,
94 PERF_IP_FLAG_CONDITIONAL = 1ULL << 3,
95 PERF_IP_FLAG_SYSCALLRET = 1ULL << 4,
96 PERF_IP_FLAG_ASYNC = 1ULL << 5,
97 PERF_IP_FLAG_INTERRUPT = 1ULL << 6,
98 PERF_IP_FLAG_TX_ABORT = 1ULL << 7,
99 PERF_IP_FLAG_TRACE_BEGIN = 1ULL << 8,
100 PERF_IP_FLAG_TRACE_END = 1ULL << 9,
101 PERF_IP_FLAG_IN_TX = 1ULL << 10,
102 PERF_IP_FLAG_VMENTRY = 1ULL << 11,
103 PERF_IP_FLAG_VMEXIT = 1ULL << 12,
104 PERF_IP_FLAG_INTR_DISABLE = 1ULL << 13,
105 PERF_IP_FLAG_INTR_TOGGLE = 1ULL << 14,
108 #define PERF_IP_FLAG_CHARS "bcrosyiABExghDt"
110 #define PERF_BRANCH_MASK (\
111 PERF_IP_FLAG_BRANCH |\
113 PERF_IP_FLAG_RETURN |\
114 PERF_IP_FLAG_CONDITIONAL |\
115 PERF_IP_FLAG_SYSCALLRET |\
116 PERF_IP_FLAG_ASYNC |\
117 PERF_IP_FLAG_INTERRUPT |\
118 PERF_IP_FLAG_TX_ABORT |\
119 PERF_IP_FLAG_TRACE_BEGIN |\
120 PERF_IP_FLAG_TRACE_END |\
121 PERF_IP_FLAG_VMENTRY |\
158 bool no_hw_idx; /* No hw_idx collected in branch_stack */
161 struct ip_callchain *callchain;
162 struct branch_stack *branch_stack;
163 struct regs_dump user_regs;
164 struct regs_dump intr_regs;
165 struct stack_dump user_stack;
166 struct sample_read read;
167 struct aux_sample aux_sample;
170 #define PERF_MEM_DATA_SRC_NONE \
171 (PERF_MEM_S(OP, NA) |\
172 PERF_MEM_S(LVL, NA) |\
173 PERF_MEM_S(SNOOP, NA) |\
174 PERF_MEM_S(LOCK, NA) |\
177 /* Attribute type for custom synthesized events */
178 #define PERF_TYPE_SYNTH (INT_MAX + 1U)
180 /* Attribute config for custom synthesized events */
182 PERF_SYNTH_INTEL_PTWRITE,
183 PERF_SYNTH_INTEL_MWAIT,
184 PERF_SYNTH_INTEL_PWRE,
185 PERF_SYNTH_INTEL_EXSTOP,
186 PERF_SYNTH_INTEL_PWRX,
187 PERF_SYNTH_INTEL_CBR,
188 PERF_SYNTH_INTEL_PSB,
189 PERF_SYNTH_INTEL_EVT,
190 PERF_SYNTH_INTEL_IFLAG_CHG,
194 * Raw data formats for synthesized events. Note that 4 bytes of padding are
195 * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
196 * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
197 * Refer perf_sample__synth_ptr() and perf_synth__raw_data(). It also means the
198 * structure sizes are 4 bytes bigger than the raw_size, refer
199 * perf_synth__raw_size().
202 struct perf_synth_intel_ptwrite {
214 struct perf_synth_intel_mwait {
228 struct perf_synth_intel_pwre {
243 struct perf_synth_intel_exstop {
254 struct perf_synth_intel_pwrx {
259 u64 deepest_cstate : 4,
268 struct perf_synth_intel_cbr {
283 struct perf_synth_intel_psb {
289 struct perf_synth_intel_evd {
300 /* Intel PT Event Trace */
301 struct perf_synth_intel_evt {
313 struct perf_synth_intel_evd evd[0];
316 struct perf_synth_intel_iflag_chg {
325 u64 branch_ip; /* If via_branch */
329 * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
332 static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
334 return sample->raw_data - 4;
337 static inline void *perf_synth__raw_data(void *p)
342 #define perf_synth__raw_size(d) (sizeof(d) - 4)
344 #define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
347 PERF_STAT_ROUND_TYPE__INTERVAL = 0,
348 PERF_STAT_ROUND_TYPE__FINAL = 1,
351 void perf_event__print_totals(void);
354 struct perf_record_stat_config;
355 struct perf_stat_config;
358 void perf_event__read_stat_config(struct perf_stat_config *config,
359 struct perf_record_stat_config *event);
361 int perf_event__process_comm(struct perf_tool *tool,
362 union perf_event *event,
363 struct perf_sample *sample,
364 struct machine *machine);
365 int perf_event__process_lost(struct perf_tool *tool,
366 union perf_event *event,
367 struct perf_sample *sample,
368 struct machine *machine);
369 int perf_event__process_lost_samples(struct perf_tool *tool,
370 union perf_event *event,
371 struct perf_sample *sample,
372 struct machine *machine);
373 int perf_event__process_aux(struct perf_tool *tool,
374 union perf_event *event,
375 struct perf_sample *sample,
376 struct machine *machine);
377 int perf_event__process_itrace_start(struct perf_tool *tool,
378 union perf_event *event,
379 struct perf_sample *sample,
380 struct machine *machine);
381 int perf_event__process_aux_output_hw_id(struct perf_tool *tool,
382 union perf_event *event,
383 struct perf_sample *sample,
384 struct machine *machine);
385 int perf_event__process_switch(struct perf_tool *tool,
386 union perf_event *event,
387 struct perf_sample *sample,
388 struct machine *machine);
389 int perf_event__process_namespaces(struct perf_tool *tool,
390 union perf_event *event,
391 struct perf_sample *sample,
392 struct machine *machine);
393 int perf_event__process_cgroup(struct perf_tool *tool,
394 union perf_event *event,
395 struct perf_sample *sample,
396 struct machine *machine);
397 int perf_event__process_mmap(struct perf_tool *tool,
398 union perf_event *event,
399 struct perf_sample *sample,
400 struct machine *machine);
401 int perf_event__process_mmap2(struct perf_tool *tool,
402 union perf_event *event,
403 struct perf_sample *sample,
404 struct machine *machine);
405 int perf_event__process_fork(struct perf_tool *tool,
406 union perf_event *event,
407 struct perf_sample *sample,
408 struct machine *machine);
409 int perf_event__process_exit(struct perf_tool *tool,
410 union perf_event *event,
411 struct perf_sample *sample,
412 struct machine *machine);
413 int perf_event__process_ksymbol(struct perf_tool *tool,
414 union perf_event *event,
415 struct perf_sample *sample,
416 struct machine *machine);
417 int perf_event__process_bpf(struct perf_tool *tool,
418 union perf_event *event,
419 struct perf_sample *sample,
420 struct machine *machine);
421 int perf_event__process_text_poke(struct perf_tool *tool,
422 union perf_event *event,
423 struct perf_sample *sample,
424 struct machine *machine);
425 int perf_event__process(struct perf_tool *tool,
426 union perf_event *event,
427 struct perf_sample *sample,
428 struct machine *machine);
430 struct addr_location;
432 int machine__resolve(struct machine *machine, struct addr_location *al,
433 struct perf_sample *sample);
435 void addr_location__put(struct addr_location *al);
439 bool is_bts_event(struct perf_event_attr *attr);
440 bool sample_addr_correlates_sym(struct perf_event_attr *attr);
441 void thread__resolve(struct thread *thread, struct addr_location *al,
442 struct perf_sample *sample);
444 const char *perf_event__name(unsigned int id);
446 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
447 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
448 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
449 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
450 size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
451 size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
452 size_t perf_event__fprintf_aux_output_hw_id(union perf_event *event, FILE *fp);
453 size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
454 size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
455 size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
456 size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
457 size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
458 size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
459 size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
460 size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *machine,FILE *fp);
461 size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILE *fp);
463 int kallsyms__get_function_start(const char *kallsyms_filename,
464 const char *symbol_name, u64 *addr);
466 void *cpu_map_data__alloc(struct perf_cpu_map *map, size_t *size, u16 *type, int *max);
467 void cpu_map_data__synthesize(struct perf_record_cpu_map_data *data, struct perf_cpu_map *map,
470 void event_attr_init(struct perf_event_attr *attr);
472 int perf_event_paranoid(void);
473 bool perf_event_paranoid_check(int max_level);
475 extern int sysctl_perf_event_max_stack;
476 extern int sysctl_perf_event_max_contexts_per_stack;
477 extern unsigned int proc_map_timeout;
479 #define PAGE_SIZE_NAME_LEN 32
480 char *get_page_size_name(u64 size, char *str);
482 void arch_perf_parse_sample_weight(struct perf_sample *data, const __u64 *array, u64 type);
483 void arch_perf_synthesize_sample_weight(const struct perf_sample *data, __u64 *array, u64 type);
484 const char *arch_perf_header_entry(const char *se_header);
485 int arch_support_sort_key(const char *sort_key);
487 static inline bool perf_event_header__cpumode_is_guest(u8 cpumode)
489 return cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
490 cpumode == PERF_RECORD_MISC_GUEST_USER;
493 static inline bool perf_event_header__misc_is_guest(u16 misc)
495 return perf_event_header__cpumode_is_guest(misc & PERF_RECORD_MISC_CPUMODE_MASK);
498 static inline bool perf_event_header__is_guest(const struct perf_event_header *header)
500 return perf_event_header__misc_is_guest(header->misc);
503 static inline bool perf_event__is_guest(const union perf_event *event)
505 return perf_event_header__is_guest(&event->header);
508 #endif /* __PERF_RECORD_H */