Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
0007ecea XG |
2 | #ifndef __PERF_STATS_H |
3 | #define __PERF_STATS_H | |
4 | ||
d944c4ee | 5 | #include <linux/types.h> |
f87027b9 | 6 | #include <stdio.h> |
a8e02324 | 7 | #include "xyarray.h" |
e5fcc2ab | 8 | #include "rblist.h" |
728c0ee0 | 9 | #include "perf.h" |
0a4e64d3 | 10 | #include "event.h" |
0007ecea | 11 | |
e55c14af | 12 | struct stats { |
0007ecea | 13 | double n, mean, M2; |
ffe4f3c0 | 14 | u64 max, min; |
0007ecea XG |
15 | }; |
16 | ||
e2f56da1 JO |
17 | enum perf_stat_evsel_id { |
18 | PERF_STAT_EVSEL_ID__NONE = 0, | |
4c358d5c JO |
19 | PERF_STAT_EVSEL_ID__CYCLES_IN_TX, |
20 | PERF_STAT_EVSEL_ID__TRANSACTION_START, | |
21 | PERF_STAT_EVSEL_ID__ELISION_START, | |
22 | PERF_STAT_EVSEL_ID__CYCLES_IN_TX_CP, | |
239bd47f AK |
23 | PERF_STAT_EVSEL_ID__TOPDOWN_TOTAL_SLOTS, |
24 | PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_ISSUED, | |
25 | PERF_STAT_EVSEL_ID__TOPDOWN_SLOTS_RETIRED, | |
26 | PERF_STAT_EVSEL_ID__TOPDOWN_FETCH_BUBBLES, | |
27 | PERF_STAT_EVSEL_ID__TOPDOWN_RECOVERY_BUBBLES, | |
daefd0bc KL |
28 | PERF_STAT_EVSEL_ID__SMI_NUM, |
29 | PERF_STAT_EVSEL_ID__APERF, | |
e2f56da1 JO |
30 | PERF_STAT_EVSEL_ID__MAX, |
31 | }; | |
32 | ||
581cc8a2 | 33 | struct perf_stat_evsel { |
f7794d52 JO |
34 | struct stats res_stats[3]; |
35 | enum perf_stat_evsel_id id; | |
36 | u64 *group_data; | |
e2f56da1 JO |
37 | }; |
38 | ||
f87027b9 JO |
39 | enum aggr_mode { |
40 | AGGR_NONE, | |
41 | AGGR_GLOBAL, | |
42 | AGGR_SOCKET, | |
43 | AGGR_CORE, | |
32b8af82 | 44 | AGGR_THREAD, |
208df99e | 45 | AGGR_UNSET, |
f87027b9 JO |
46 | }; |
47 | ||
e5fcc2ab JY |
48 | enum { |
49 | CTX_BIT_USER = 1 << 0, | |
50 | CTX_BIT_KERNEL = 1 << 1, | |
51 | CTX_BIT_HV = 1 << 2, | |
52 | CTX_BIT_HOST = 1 << 3, | |
53 | CTX_BIT_IDLE = 1 << 4, | |
54 | CTX_BIT_MAX = 1 << 5, | |
55 | }; | |
56 | ||
57 | #define NUM_CTX CTX_BIT_MAX | |
58 | ||
59 | enum stat_type { | |
60 | STAT_NONE = 0, | |
61 | STAT_NSECS, | |
62 | STAT_CYCLES, | |
63 | STAT_STALLED_CYCLES_FRONT, | |
64 | STAT_STALLED_CYCLES_BACK, | |
65 | STAT_BRANCHES, | |
66 | STAT_CACHEREFS, | |
67 | STAT_L1_DCACHE, | |
68 | STAT_L1_ICACHE, | |
69 | STAT_LL_CACHE, | |
70 | STAT_ITLB_CACHE, | |
71 | STAT_DTLB_CACHE, | |
72 | STAT_CYCLES_IN_TX, | |
73 | STAT_TRANSACTION, | |
74 | STAT_ELISION, | |
75 | STAT_TOPDOWN_TOTAL_SLOTS, | |
76 | STAT_TOPDOWN_SLOTS_ISSUED, | |
77 | STAT_TOPDOWN_SLOTS_RETIRED, | |
78 | STAT_TOPDOWN_FETCH_BUBBLES, | |
79 | STAT_TOPDOWN_RECOVERY_BUBBLES, | |
80 | STAT_SMI_NUM, | |
81 | STAT_APERF, | |
82 | STAT_MAX | |
83 | }; | |
84 | ||
85 | struct runtime_stat { | |
86 | struct rblist value_list; | |
87 | }; | |
88 | ||
421a50f3 | 89 | struct perf_stat_config { |
728c0ee0 JO |
90 | enum aggr_mode aggr_mode; |
91 | bool scale; | |
5698f26b | 92 | bool no_inherit; |
7d9ad16a | 93 | bool identifier; |
fa7070a3 | 94 | bool csv_output; |
132c6ba3 | 95 | bool interval_clear; |
0ce5aa02 | 96 | bool metric_only; |
aea0dca1 | 97 | bool null_run; |
728c0ee0 JO |
98 | FILE *output; |
99 | unsigned int interval; | |
100 | unsigned int timeout; | |
101 | unsigned int initial_delay; | |
df4f7b4d | 102 | unsigned int unit_width; |
ee1760e2 | 103 | unsigned int metric_only_len; |
728c0ee0 | 104 | int times; |
d97ae04b | 105 | int run_count; |
31084123 | 106 | int print_free_counters_hint; |
3b3cd9a4 | 107 | int print_mixed_hw_group_error; |
728c0ee0 JO |
108 | struct runtime_stat *stats; |
109 | int stats_num; | |
fa7070a3 | 110 | const char *csv_sep; |
26893a60 | 111 | struct stats *walltime_nsecs_stats; |
421a50f3 JO |
112 | }; |
113 | ||
0007ecea XG |
114 | void update_stats(struct stats *stats, u64 val); |
115 | double avg_stats(struct stats *stats); | |
116 | double stddev_stats(struct stats *stats); | |
117 | double rel_stddev_stats(double stddev, double avg); | |
118 | ||
ffe4f3c0 DA |
119 | static inline void init_stats(struct stats *stats) |
120 | { | |
121 | stats->n = 0.0; | |
122 | stats->mean = 0.0; | |
123 | stats->M2 = 0.0; | |
124 | stats->min = (u64) -1; | |
125 | stats->max = 0; | |
126 | } | |
e2f56da1 JO |
127 | |
128 | struct perf_evsel; | |
24e34f68 JO |
129 | struct perf_evlist; |
130 | ||
29734550 JY |
131 | struct perf_aggr_thread_value { |
132 | struct perf_evsel *counter; | |
133 | int id; | |
134 | double uval; | |
135 | u64 val; | |
136 | u64 run; | |
137 | u64 ena; | |
138 | }; | |
139 | ||
e2f56da1 JO |
140 | bool __perf_evsel_stat__is(struct perf_evsel *evsel, |
141 | enum perf_stat_evsel_id id); | |
142 | ||
143 | #define perf_stat_evsel__is(evsel, id) \ | |
144 | __perf_evsel_stat__is(evsel, PERF_STAT_EVSEL_ID__ ## id) | |
145 | ||
8efb2df1 | 146 | extern struct runtime_stat rt_stat; |
f87027b9 JO |
147 | extern struct stats walltime_nsecs_stats; |
148 | ||
6ca9a082 JO |
149 | typedef void (*print_metric_t)(struct perf_stat_config *config, |
150 | void *ctx, const char *color, const char *unit, | |
140aeadc | 151 | const char *fmt, double val); |
6ca9a082 | 152 | typedef void (*new_line_t)(struct perf_stat_config *config, void *ctx); |
140aeadc | 153 | |
8efb2df1 JY |
154 | void runtime_stat__init(struct runtime_stat *st); |
155 | void runtime_stat__exit(struct runtime_stat *st); | |
fb4605ba | 156 | void perf_stat__init_shadow_stats(void); |
f87027b9 | 157 | void perf_stat__reset_shadow_stats(void); |
6a1e2c5c | 158 | void perf_stat__reset_shadow_per_stat(struct runtime_stat *st); |
54830dd0 | 159 | void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 count, |
1fcd0394 | 160 | int cpu, struct runtime_stat *st); |
140aeadc AK |
161 | struct perf_stat_output_ctx { |
162 | void *ctx; | |
163 | print_metric_t print_metric; | |
164 | new_line_t new_line; | |
37932c18 | 165 | bool force_header; |
140aeadc AK |
166 | }; |
167 | ||
6ca9a082 JO |
168 | void perf_stat__print_shadow_stats(struct perf_stat_config *config, |
169 | struct perf_evsel *evsel, | |
140aeadc | 170 | double avg, int cpu, |
b18f3e36 | 171 | struct perf_stat_output_ctx *out, |
e0128b30 JY |
172 | struct rblist *metric_events, |
173 | struct runtime_stat *st); | |
37932c18 | 174 | void perf_stat__collect_metric_expr(struct perf_evlist *); |
f87027b9 | 175 | |
24e34f68 JO |
176 | int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); |
177 | void perf_evlist__free_stats(struct perf_evlist *evlist); | |
178 | void perf_evlist__reset_stats(struct perf_evlist *evlist); | |
f80010eb JO |
179 | |
180 | int perf_stat_process_counter(struct perf_stat_config *config, | |
181 | struct perf_evsel *counter); | |
0ea0e355 JO |
182 | struct perf_tool; |
183 | union perf_event; | |
184 | struct perf_session; | |
185 | int perf_event__process_stat_event(struct perf_tool *tool, | |
186 | union perf_event *event, | |
187 | struct perf_session *session); | |
e08a4564 JO |
188 | |
189 | size_t perf_event__fprintf_stat(union perf_event *event, FILE *fp); | |
190 | size_t perf_event__fprintf_stat_round(union perf_event *event, FILE *fp); | |
191 | size_t perf_event__fprintf_stat_config(union perf_event *event, FILE *fp); | |
d09cefd2 JO |
192 | |
193 | int create_perf_stat_counter(struct perf_evsel *evsel, | |
194 | struct perf_stat_config *config, | |
195 | struct target *target); | |
0a4e64d3 JO |
196 | int perf_stat_synthesize_config(struct perf_stat_config *config, |
197 | struct perf_tool *tool, | |
198 | struct perf_evlist *evlist, | |
199 | perf_event__handler_t process, | |
200 | bool attrs); | |
0007ecea | 201 | #endif |