^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #ifndef _PERF_BRANCH_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #define _PERF_BRANCH_H 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * The linux/stddef.h isn't need here, but is needed for __always_inline used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * in files included from uapi/linux/perf_event.h such as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * /usr/include/linux/swab.h and /usr/include/linux/byteorder/little_endian.h,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * detected in at least musl libc, used in Alpine Linux. -acme
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <stdint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "event.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct branch_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) u64 value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) u64 mispred:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u64 predicted:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u64 in_tx:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) u64 abort:1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u64 cycles:16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) u64 type:4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u64 reserved:40;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct branch_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct addr_map_symbol from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct addr_map_symbol to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct branch_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) char *srcline_from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) char *srcline_to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct branch_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u64 from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u64 to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct branch_flags flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct branch_stack {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u64 nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u64 hw_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct branch_entry entries[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * The hw_idx is only available when PERF_SAMPLE_BRANCH_HW_INDEX is applied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * Otherwise, the output format of a sample with branch stack is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * struct branch_stack {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * u64 nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * struct branch_entry entries[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * Check whether the hw_idx is available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * and return the corresponding pointer of entries[0].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static inline struct branch_entry *perf_sample__branch_entries(struct perf_sample *sample)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u64 *entry = (u64 *)sample->branch_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) entry++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (sample->no_hw_idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return (struct branch_entry *)entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return (struct branch_entry *)(++entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct branch_type_stat {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) bool branch_to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u64 counts[PERF_BR_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) u64 cond_fwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) u64 cond_bwd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u64 cross_4k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) u64 cross_2m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u64 from, u64 to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) const char *branch_type_name(int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) void branch_type_stat_display(FILE *fp, struct branch_type_stat *st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int branch_type_str(struct branch_type_stat *st, char *bf, int bfsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #endif /* _PERF_BRANCH_H */