File Index
Files and directories
Sign in
FILE

branch.h

File preview with syntax highlighting.

linux-6.19.14/tools/perf/util/branch.h C
 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 <linux/perf_event.h>
11#include <linux/types.h>
12#include "util/map_symbol.h"
13#include "util/sample.h"
14
15struct branch_flags {
16	union {
17		u64 value;
18		struct {
19			u64 mispred:1;
20			u64 predicted:1;
21			u64 in_tx:1;
22			u64 abort:1;
23			u64 cycles:16;
24			u64 type:4;
25			u64 spec:2;
26			u64 new_type:4;
27			u64 priv:3;
28			u64 not_taken:1;
29			u64 reserved:30;
30		};
31	};
32};
33
34struct branch_info {
35	struct addr_map_symbol from;
36	struct addr_map_symbol to;
37	struct branch_flags    flags;
38	u64		       branch_stack_cntr;
39	char		       *srcline_from;
40	char		       *srcline_to;
41};
42
43struct branch_entry {
44	u64			from;
45	u64			to;
46	struct branch_flags	flags;
47};
48
49struct branch_stack {
50	u64			nr;
51	u64			hw_idx;
52	struct branch_entry	entries[];
53};
54
55/*
56 * The hw_idx is only available when PERF_SAMPLE_BRANCH_HW_INDEX is applied.
57 * Otherwise, the output format of a sample with branch stack is
58 * struct branch_stack {
59 *	u64			nr;
60 *	struct branch_entry	entries[0];
61 * }
62 * Check whether the hw_idx is available,
63 * and return the corresponding pointer of entries[0].
64 */
65static inline struct branch_entry *perf_sample__branch_entries(struct perf_sample *sample)
66{
67	u64 *entry = (u64 *)sample->branch_stack;
68
69	entry++;
70	if (sample->no_hw_idx)
71		return (struct branch_entry *)entry;
72	return (struct branch_entry *)(++entry);
73}
74
75struct branch_type_stat {
76	bool	branch_to;
77	u64	counts[PERF_BR_MAX];
78	u64	new_counts[PERF_BR_NEW_MAX];
79	u64	cond_fwd;
80	u64	cond_bwd;
81	u64	cross_4k;
82	u64	cross_2m;
83};
84
85void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
86		       u64 from, u64 to);
87
88const char *branch_type_name(int type);
89const char *branch_new_type_name(int new_type);
90const char *get_branch_type(struct branch_entry *e);
91void branch_type_stat_display(FILE *fp, const struct branch_type_stat *st);
92int branch_type_str(const struct branch_type_stat *st, char *bf, int bfsize);
93
94const char *branch_spec_desc(int spec);
95
96#endif /* _PERF_BRANCH_H */
~/ Read-only file preview.