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