xref: /openbmc/linux/tools/perf/util/branch.h (revision fb71c86cc804b8f490fce1b9140014043ec41858)
1992c7e92SJin Yao #ifndef _PERF_BRANCH_H
2992c7e92SJin Yao #define _PERF_BRANCH_H 1
3*fb71c86cSArnaldo Carvalho de Melo /*
4*fb71c86cSArnaldo Carvalho de Melo  * The linux/stddef.h isn't need here, but is needed for __always_inline used
5*fb71c86cSArnaldo Carvalho de Melo  * in files included from uapi/linux/perf_event.h such as
6*fb71c86cSArnaldo Carvalho de Melo  * /usr/include/linux/swab.h and /usr/include/linux/byteorder/little_endian.h,
7*fb71c86cSArnaldo Carvalho de Melo  * detected in at least musl libc, used in Alpine Linux. -acme
8*fb71c86cSArnaldo Carvalho de Melo  */
9f1a397f3SArnaldo Carvalho de Melo #include <stdio.h>
10992c7e92SJin Yao #include <stdint.h>
11*fb71c86cSArnaldo Carvalho de Melo #include <linux/compiler.h>
12*fb71c86cSArnaldo Carvalho de Melo #include <linux/stddef.h>
13f1a397f3SArnaldo Carvalho de Melo #include <linux/perf_event.h>
14f1a397f3SArnaldo Carvalho de Melo #include <linux/types.h>
15f1a397f3SArnaldo Carvalho de Melo 
16f1a397f3SArnaldo Carvalho de Melo struct branch_flags {
17f1a397f3SArnaldo Carvalho de Melo 	u64 mispred:1;
18f1a397f3SArnaldo Carvalho de Melo 	u64 predicted:1;
19f1a397f3SArnaldo Carvalho de Melo 	u64 in_tx:1;
20f1a397f3SArnaldo Carvalho de Melo 	u64 abort:1;
21f1a397f3SArnaldo Carvalho de Melo 	u64 cycles:16;
22f1a397f3SArnaldo Carvalho de Melo 	u64 type:4;
23f1a397f3SArnaldo Carvalho de Melo 	u64 reserved:40;
24f1a397f3SArnaldo Carvalho de Melo };
25f1a397f3SArnaldo Carvalho de Melo 
26d3300a3cSArnaldo Carvalho de Melo struct branch_info {
27d3300a3cSArnaldo Carvalho de Melo 	struct addr_map_symbol from;
28d3300a3cSArnaldo Carvalho de Melo 	struct addr_map_symbol to;
29d3300a3cSArnaldo Carvalho de Melo 	struct branch_flags    flags;
30d3300a3cSArnaldo Carvalho de Melo 	char		       *srcline_from;
31d3300a3cSArnaldo Carvalho de Melo 	char		       *srcline_to;
32d3300a3cSArnaldo Carvalho de Melo };
33d3300a3cSArnaldo Carvalho de Melo 
34f1a397f3SArnaldo Carvalho de Melo struct branch_entry {
35f1a397f3SArnaldo Carvalho de Melo 	u64			from;
36f1a397f3SArnaldo Carvalho de Melo 	u64			to;
37f1a397f3SArnaldo Carvalho de Melo 	struct branch_flags	flags;
38f1a397f3SArnaldo Carvalho de Melo };
39f1a397f3SArnaldo Carvalho de Melo 
40f1a397f3SArnaldo Carvalho de Melo struct branch_stack {
41f1a397f3SArnaldo Carvalho de Melo 	u64			nr;
42f1a397f3SArnaldo Carvalho de Melo 	struct branch_entry	entries[0];
43f1a397f3SArnaldo Carvalho de Melo };
44992c7e92SJin Yao 
45992c7e92SJin Yao struct branch_type_stat {
46a1a8bed3SJin Yao 	bool	branch_to;
47992c7e92SJin Yao 	u64	counts[PERF_BR_MAX];
48992c7e92SJin Yao 	u64	cond_fwd;
49992c7e92SJin Yao 	u64	cond_bwd;
50992c7e92SJin Yao 	u64	cross_4k;
51992c7e92SJin Yao 	u64	cross_2m;
52992c7e92SJin Yao };
53992c7e92SJin Yao 
54992c7e92SJin Yao void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
55992c7e92SJin Yao 		       u64 from, u64 to);
56992c7e92SJin Yao 
57992c7e92SJin Yao const char *branch_type_name(int type);
58992c7e92SJin Yao void branch_type_stat_display(FILE *fp, struct branch_type_stat *st);
59992c7e92SJin Yao int branch_type_str(struct branch_type_stat *st, char *bf, int bfsize);
60992c7e92SJin Yao 
61992c7e92SJin Yao #endif /* _PERF_BRANCH_H */
62