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 |\
156 bool no_hw_idx; /* No hw_idx collected in branch_stack */
159 struct ip_callchain *callchain;
160 struct branch_stack *branch_stack;
161 struct regs_dump user_regs;
162 struct regs_dump intr_regs;
163 struct stack_dump user_stack;
164 struct sample_read read;
165 struct aux_sample aux_sample;
168 #define PERF_MEM_DATA_SRC_NONE \
169 (PERF_MEM_S(OP, NA) |\
170 PERF_MEM_S(LVL, NA) |\
171 PERF_MEM_S(SNOOP, NA) |\
172 PERF_MEM_S(LOCK, NA) |\
175 /* Attribute type for custom synthesized events */
176 #define PERF_TYPE_SYNTH (INT_MAX + 1U)
178 /* Attribute config for custom synthesized events */
180 PERF_SYNTH_INTEL_PTWRITE,
181 PERF_SYNTH_INTEL_MWAIT,
182 PERF_SYNTH_INTEL_PWRE,
183 PERF_SYNTH_INTEL_EXSTOP,
184 PERF_SYNTH_INTEL_PWRX,
185 PERF_SYNTH_INTEL_CBR,
186 PERF_SYNTH_INTEL_PSB,
187 PERF_SYNTH_INTEL_EVT,
188 PERF_SYNTH_INTEL_IFLAG_CHG,
192 * Raw data formats for synthesized events. Note that 4 bytes of padding are
193 * present to match the 'size' member of PERF_SAMPLE_RAW data which is always
194 * 8-byte aligned. That means we must dereference raw_data with an offset of 4.
195 * Refer perf_sample__synth_ptr() and perf_synth__raw_data(). It also means the
196 * structure sizes are 4 bytes bigger than the raw_size, refer
197 * perf_synth__raw_size().
200 struct perf_synth_intel_ptwrite {
212 struct perf_synth_intel_mwait {
226 struct perf_synth_intel_pwre {
241 struct perf_synth_intel_exstop {
252 struct perf_synth_intel_pwrx {
257 u64 deepest_cstate : 4,
266 struct perf_synth_intel_cbr {
281 struct perf_synth_intel_psb {
287 struct perf_synth_intel_evd {
298 /* Intel PT Event Trace */
299 struct perf_synth_intel_evt {
311 struct perf_synth_intel_evd evd[0];
314 struct perf_synth_intel_iflag_chg {
323 u64 branch_ip; /* If via_branch */
327 * raw_data is always 4 bytes from an 8-byte boundary, so subtract 4 to get
330 static inline void *perf_sample__synth_ptr(struct perf_sample *sample)
332 return sample->raw_data - 4;
335 static inline void *perf_synth__raw_data(void *p)
340 #define perf_synth__raw_size(d) (sizeof(d) - 4)
342 #define perf_sample__bad_synth_size(s, d) ((s)->raw_size < sizeof(d) - 4)
345 PERF_STAT_ROUND_TYPE__INTERVAL = 0,
346 PERF_STAT_ROUND_TYPE__FINAL = 1,
349 void perf_event__print_totals(void);
352 struct perf_record_stat_config;
353 struct perf_stat_config;
356 void perf_event__read_stat_config(struct perf_stat_config *config,
357 struct perf_record_stat_config *event);
359 int perf_event__process_comm(struct perf_tool *tool,
360 union perf_event *event,
361 struct perf_sample *sample,
362 struct machine *machine);
363 int perf_event__process_lost(struct perf_tool *tool,
364 union perf_event *event,
365 struct perf_sample *sample,
366 struct machine *machine);
367 int perf_event__process_lost_samples(struct perf_tool *tool,
368 union perf_event *event,
369 struct perf_sample *sample,
370 struct machine *machine);
371 int perf_event__process_aux(struct perf_tool *tool,
372 union perf_event *event,
373 struct perf_sample *sample,
374 struct machine *machine);
375 int perf_event__process_itrace_start(struct perf_tool *tool,
376 union perf_event *event,
377 struct perf_sample *sample,
378 struct machine *machine);
379 int perf_event__process_aux_output_hw_id(struct perf_tool *tool,
380 union perf_event *event,
381 struct perf_sample *sample,
382 struct machine *machine);
383 int perf_event__process_switch(struct perf_tool *tool,
384 union perf_event *event,
385 struct perf_sample *sample,
386 struct machine *machine);
387 int perf_event__process_namespaces(struct perf_tool *tool,
388 union perf_event *event,
389 struct perf_sample *sample,
390 struct machine *machine);
391 int perf_event__process_cgroup(struct perf_tool *tool,
392 union perf_event *event,
393 struct perf_sample *sample,
394 struct machine *machine);
395 int perf_event__process_mmap(struct perf_tool *tool,
396 union perf_event *event,
397 struct perf_sample *sample,
398 struct machine *machine);
399 int perf_event__process_mmap2(struct perf_tool *tool,
400 union perf_event *event,
401 struct perf_sample *sample,
402 struct machine *machine);
403 int perf_event__process_fork(struct perf_tool *tool,
404 union perf_event *event,
405 struct perf_sample *sample,
406 struct machine *machine);
407 int perf_event__process_exit(struct perf_tool *tool,
408 union perf_event *event,
409 struct perf_sample *sample,
410 struct machine *machine);
411 int perf_event__process_ksymbol(struct perf_tool *tool,
412 union perf_event *event,
413 struct perf_sample *sample,
414 struct machine *machine);
415 int perf_event__process_bpf(struct perf_tool *tool,
416 union perf_event *event,
417 struct perf_sample *sample,
418 struct machine *machine);
419 int perf_event__process_text_poke(struct perf_tool *tool,
420 union perf_event *event,
421 struct perf_sample *sample,
422 struct machine *machine);
423 int perf_event__process(struct perf_tool *tool,
424 union perf_event *event,
425 struct perf_sample *sample,
426 struct machine *machine);
428 struct addr_location;
430 int machine__resolve(struct machine *machine, struct addr_location *al,
431 struct perf_sample *sample);
433 void addr_location__put(struct addr_location *al);
437 bool is_bts_event(struct perf_event_attr *attr);
438 bool sample_addr_correlates_sym(struct perf_event_attr *attr);
439 void thread__resolve(struct thread *thread, struct addr_location *al,
440 struct perf_sample *sample);
442 const char *perf_event__name(unsigned int id);
444 size_t perf_event__fprintf_comm(union perf_event *event, FILE *fp);
445 size_t perf_event__fprintf_mmap(union perf_event *event, FILE *fp);
446 size_t perf_event__fprintf_mmap2(union perf_event *event, FILE *fp);
447 size_t perf_event__fprintf_task(union perf_event *event, FILE *fp);
448 size_t perf_event__fprintf_aux(union perf_event *event, FILE *fp);
449 size_t perf_event__fprintf_itrace_start(union perf_event *event, FILE *fp);
450 size_t perf_event__fprintf_aux_output_hw_id(union perf_event *event, FILE *fp);
451 size_t perf_event__fprintf_switch(union perf_event *event, FILE *fp);
452 size_t perf_event__fprintf_thread_map(union perf_event *event, FILE *fp);
453 size_t perf_event__fprintf_cpu_map(union perf_event *event, FILE *fp);
454 size_t perf_event__fprintf_namespaces(union perf_event *event, FILE *fp);
455 size_t perf_event__fprintf_cgroup(union perf_event *event, FILE *fp);
456 size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp);
457 size_t perf_event__fprintf_bpf(union perf_event *event, FILE *fp);
458 size_t perf_event__fprintf_text_poke(union perf_event *event, struct machine *machine,FILE *fp);
459 size_t perf_event__fprintf(union perf_event *event, struct machine *machine, FILE *fp);
461 int kallsyms__get_function_start(const char *kallsyms_filename,
462 const char *symbol_name, u64 *addr);
464 void *cpu_map_data__alloc(struct perf_cpu_map *map, size_t *size, u16 *type, int *max);
465 void cpu_map_data__synthesize(struct perf_record_cpu_map_data *data, struct perf_cpu_map *map,
468 void event_attr_init(struct perf_event_attr *attr);
470 int perf_event_paranoid(void);
471 bool perf_event_paranoid_check(int max_level);
473 extern int sysctl_perf_event_max_stack;
474 extern int sysctl_perf_event_max_contexts_per_stack;
475 extern unsigned int proc_map_timeout;
477 #define PAGE_SIZE_NAME_LEN 32
478 char *get_page_size_name(u64 size, char *str);
480 void arch_perf_parse_sample_weight(struct perf_sample *data, const __u64 *array, u64 type);
481 void arch_perf_synthesize_sample_weight(const struct perf_sample *data, __u64 *array, u64 type);
482 const char *arch_perf_header_entry(const char *se_header);
483 int arch_support_sort_key(const char *sort_key);
485 #endif /* __PERF_RECORD_H */