hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/tools/perf/util/branch.h
....@@ -1,8 +1,73 @@
11 #ifndef _PERF_BRANCH_H
22 #define _PERF_BRANCH_H 1
3
-
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>
410 #include <stdint.h>
5
-#include "../perf.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
+ union {
19
+ u64 value;
20
+ struct {
21
+ u64 mispred:1;
22
+ u64 predicted:1;
23
+ u64 in_tx:1;
24
+ u64 abort:1;
25
+ u64 cycles:16;
26
+ u64 type:4;
27
+ u64 reserved:40;
28
+ };
29
+ };
30
+};
31
+
32
+struct branch_info {
33
+ struct addr_map_symbol from;
34
+ struct addr_map_symbol to;
35
+ struct branch_flags flags;
36
+ char *srcline_from;
37
+ char *srcline_to;
38
+};
39
+
40
+struct branch_entry {
41
+ u64 from;
42
+ u64 to;
43
+ struct branch_flags flags;
44
+};
45
+
46
+struct branch_stack {
47
+ u64 nr;
48
+ u64 hw_idx;
49
+ struct branch_entry entries[];
50
+};
51
+
52
+/*
53
+ * The hw_idx is only available when PERF_SAMPLE_BRANCH_HW_INDEX is applied.
54
+ * Otherwise, the output format of a sample with branch stack is
55
+ * struct branch_stack {
56
+ * u64 nr;
57
+ * struct branch_entry entries[0];
58
+ * }
59
+ * Check whether the hw_idx is available,
60
+ * and return the corresponding pointer of entries[0].
61
+ */
62
+static inline struct branch_entry *perf_sample__branch_entries(struct perf_sample *sample)
63
+{
64
+ u64 *entry = (u64 *)sample->branch_stack;
65
+
66
+ entry++;
67
+ if (sample->no_hw_idx)
68
+ return (struct branch_entry *)entry;
69
+ return (struct branch_entry *)(++entry);
70
+}
671
772 struct branch_type_stat {
873 bool branch_to;
....@@ -12,8 +77,6 @@
1277 u64 cross_4k;
1378 u64 cross_2m;
1479 };
15
-
16
-struct branch_flags;
1780
1881 void branch_type_count(struct branch_type_stat *st, struct branch_flags *flags,
1982 u64 from, u64 to);