]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - tools/perf/util/evlist.h
perf evlist: Adopt backwards ring buffer state enum
[mirror_ubuntu-focal-kernel.git] / tools / perf / util / evlist.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
361c99a6
ACM
2#ifndef __PERF_EVLIST_H
3#define __PERF_EVLIST_H 1
4
5c97cac6 5#include <linux/compiler.h>
877a7a11 6#include <linux/kernel.h>
25a3720c 7#include <linux/refcount.h>
361c99a6 8#include <linux/list.h>
1b85337d 9#include <api/fd/array.h>
50d08e47 10#include <stdio.h>
ce9036a6 11#include <internal/evlist.h>
47729258 12#include "events_stats.h"
0c21f736 13#include "evsel.h"
e0fcfb08 14#include <pthread.h>
9607ad3a 15#include <signal.h>
35b9d88e 16#include <unistd.h>
361c99a6 17
5c581041 18struct pollfd;
f8a95309 19struct thread_map;
f854839b 20struct perf_cpu_map;
b4006796 21struct record_opts;
5c581041 22
e0fcfb08
ACM
23/*
24 * State machine of bkw_mmap_state:
25 *
26 * .________________(forbid)_____________.
27 * | V
28 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
29 * ^ ^ | ^ |
30 * | |__(forbid)____/ |___(forbid)___/|
31 * | |
32 * \_________________(3)_______________/
33 *
34 * NOTREADY : Backward ring buffers are not ready
35 * RUNNING : Backward ring buffers are recording
36 * DATA_PENDING : We are required to collect data from backward ring buffers
37 * EMPTY : We have collected data from backward ring buffers.
38 *
39 * (0): Setup backward ring buffer
40 * (1): Pause ring buffers for reading
41 * (2): Read from ring buffers
42 * (3): Resume ring buffers for recording
43 */
44enum bkw_mmap_state {
45 BKW_MMAP_NOTREADY,
46 BKW_MMAP_RUNNING,
47 BKW_MMAP_DATA_PENDING,
48 BKW_MMAP_EMPTY,
49};
50
70db7533
ACM
51#define PERF_EVLIST__HLIST_BITS 8
52#define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
53
63503dba 54struct evlist {
ce9036a6 55 struct perf_evlist core;
70db7533 56 struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
97f63e4a 57 int nr_groups;
aece948f 58 int nr_mmaps;
2b56bcfb 59 bool enabled;
994a1f78 60 size_t mmap_len;
75562573
AH
61 int id_pos;
62 int is_pos;
63 u64 combined_sample_type;
54cc54de 64 enum bkw_mmap_state bkw_mmap_state;
35b9d88e
ACM
65 struct {
66 int cork_fd;
67 pid_t pid;
68 } workload;
1b85337d 69 struct fdarray pollfd;
a5830532
JO
70 struct mmap *mmap;
71 struct mmap *overwrite_mmap;
32dcd021 72 struct evsel *selected;
75be989a 73 struct events_stats stats;
2c07144d 74 struct perf_env *env;
63503dba 75 void (*trace_event_sample_raw)(struct evlist *evlist,
93115d32
TR
76 union perf_event *event,
77 struct perf_sample *sample);
6011518d
JY
78 u64 first_sample_time;
79 u64 last_sample_time;
657ee553
SL
80 struct {
81 pthread_t th;
82 volatile int done;
83 } thread;
361c99a6
ACM
84};
85
32dcd021 86struct evsel_str_handler {
ee29be62
ACM
87 const char *name;
88 void *handler;
89};
90
0f98b11c 91struct evlist *evlist__new(void);
63503dba
JO
92struct evlist *perf_evlist__new_default(void);
93struct evlist *perf_evlist__new_dummy(void);
52c86bca
JO
94void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
95 struct perf_thread_map *threads);
470579b0 96void evlist__exit(struct evlist *evlist);
c12995a5 97void evlist__delete(struct evlist *evlist);
361c99a6 98
a1cf3a75 99void evlist__add(struct evlist *evlist, struct evsel *entry);
16251027 100void evlist__remove(struct evlist *evlist, struct evsel *evsel);
db918acb 101
63503dba 102int __perf_evlist__add_default(struct evlist *evlist, bool precise);
db918acb 103
63503dba 104static inline int perf_evlist__add_default(struct evlist *evlist)
db918acb
ACM
105{
106 return __perf_evlist__add_default(evlist, true);
107}
108
63503dba 109int __perf_evlist__add_default_attrs(struct evlist *evlist,
79695e1b 110 struct perf_event_attr *attrs, size_t nr_attrs);
e60fc847 111
79695e1b
ACM
112#define perf_evlist__add_default_attrs(evlist, array) \
113 __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
361c99a6 114
63503dba 115int perf_evlist__add_dummy(struct evlist *evlist);
5bae0250 116
63503dba 117int perf_evlist__add_sb_event(struct evlist **evlist,
657ee553
SL
118 struct perf_event_attr *attr,
119 perf_evsel__sb_cb_t cb,
120 void *data);
63503dba 121int perf_evlist__start_sb_thread(struct evlist *evlist,
657ee553 122 struct target *target);
63503dba 123void perf_evlist__stop_sb_thread(struct evlist *evlist);
657ee553 124
63503dba 125int perf_evlist__add_newtp(struct evlist *evlist,
39876e7d
ACM
126 const char *sys, const char *name, void *handler);
127
63503dba 128void __perf_evlist__set_sample_bit(struct evlist *evlist,
22c8a376 129 enum perf_event_sample_format bit);
63503dba 130void __perf_evlist__reset_sample_bit(struct evlist *evlist,
22c8a376
ACM
131 enum perf_event_sample_format bit);
132
133#define perf_evlist__set_sample_bit(evlist, bit) \
134 __perf_evlist__set_sample_bit(evlist, PERF_SAMPLE_##bit)
135
136#define perf_evlist__reset_sample_bit(evlist, bit) \
137 __perf_evlist__reset_sample_bit(evlist, PERF_SAMPLE_##bit)
138
63503dba
JO
139int perf_evlist__set_tp_filter(struct evlist *evlist, const char *filter);
140int perf_evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
141int perf_evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
745cefc5 142
32dcd021 143struct evsel *
63503dba 144perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
da378962 145
32dcd021 146struct evsel *
63503dba 147perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
a2f2804a
DA
148 const char *name);
149
63503dba 150void perf_evlist__id_add(struct evlist *evlist, struct evsel *evsel,
a91e5431 151 int cpu, int thread, u64 id);
63503dba 152int perf_evlist__id_add_fd(struct evlist *evlist,
32dcd021 153 struct evsel *evsel,
1c59612d 154 int cpu, int thread, int fd);
3d3b5e95 155
63503dba
JO
156int perf_evlist__add_pollfd(struct evlist *evlist, int fd);
157int perf_evlist__alloc_pollfd(struct evlist *evlist);
158int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
1ddec7f0 159
63503dba 160int perf_evlist__poll(struct evlist *evlist, int timeout);
f66a889d 161
63503dba
JO
162struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
163struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
dddcf6ab 164 u64 id);
70db7533 165
63503dba 166struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id);
932a3594 167
63503dba 168void perf_evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
54cc54de 169
9521b5f2 170void evlist__mmap_consume(struct evlist *evlist, int idx);
8e50d384 171
474ddc4c 172int evlist__open(struct evlist *evlist);
750b4ede 173void evlist__close(struct evlist *evlist);
727ab04e 174
e68ae9cf
ACM
175struct callchain_param;
176
63503dba 177void perf_evlist__set_id_pos(struct evlist *evlist);
75562573 178bool perf_can_sample_identifier(void);
b757bb09 179bool perf_can_record_switch_events(void);
83509565 180bool perf_can_record_cpu_wide(void);
63503dba 181void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
e68ae9cf 182 struct callchain_param *callchain);
b4006796 183int record_opts__config(struct record_opts *opts);
0f82ebc4 184
63503dba 185int perf_evlist__prepare_workload(struct evlist *evlist,
602ad878 186 struct target *target,
55e162ea 187 const char *argv[], bool pipe_output,
735f7e0b
ACM
188 void (*exec_error)(int signo, siginfo_t *info,
189 void *ucontext));
63503dba 190int perf_evlist__start_workload(struct evlist *evlist);
35b9d88e 191
724ce97e
ACM
192struct option;
193
e9db1310 194int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
994a1f78
JO
195int perf_evlist__parse_mmap_pages(const struct option *opt,
196 const char *str,
197 int unset);
198
f5e7150c
ACM
199unsigned long perf_event_mlock_kb_in_pages(void);
200
9521b5f2 201int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
7a276ff6 202 unsigned int auxtrace_pages,
470530bb 203 bool auxtrace_overwrite, int nr_cblocks,
51255a8a 204 int affinity, int flush, int comp_level);
9521b5f2 205int evlist__mmap(struct evlist *evlist, unsigned int pages);
db6b7b13 206void evlist__munmap(struct evlist *evlist);
7e2ed097 207
9521b5f2 208size_t evlist__mmap_size(unsigned long pages);
0c582449 209
e74676de 210void evlist__disable(struct evlist *evlist);
1c87f165 211void evlist__enable(struct evlist *evlist);
63503dba 212void perf_evlist__toggle_enable(struct evlist *evlist);
4152ab37 213
63503dba 214int perf_evlist__enable_event_idx(struct evlist *evlist,
32dcd021 215 struct evsel *evsel, int idx);
395c3070 216
63503dba 217void perf_evlist__set_selected(struct evlist *evlist,
32dcd021 218 struct evsel *evsel);
81cce8de 219
63503dba
JO
220int perf_evlist__create_maps(struct evlist *evlist, struct target *target);
221int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
f8a95309 222
63dab225 223void __perf_evlist__set_leader(struct list_head *list);
63503dba 224void perf_evlist__set_leader(struct evlist *evlist);
63dab225 225
63503dba
JO
226u64 perf_evlist__read_format(struct evlist *evlist);
227u64 __perf_evlist__combined_sample_type(struct evlist *evlist);
228u64 perf_evlist__combined_sample_type(struct evlist *evlist);
229u64 perf_evlist__combined_branch_type(struct evlist *evlist);
230bool perf_evlist__sample_id_all(struct evlist *evlist);
231u16 perf_evlist__id_hdr_size(struct evlist *evlist);
74429964 232
63503dba 233int perf_evlist__parse_sample(struct evlist *evlist, union perf_event *event,
0807d2d8 234 struct perf_sample *sample);
cb0b29e0 235
63503dba 236int perf_evlist__parse_sample_timestamp(struct evlist *evlist,
01468120
JO
237 union perf_event *event,
238 u64 *timestamp);
239
63503dba
JO
240bool perf_evlist__valid_sample_type(struct evlist *evlist);
241bool perf_evlist__valid_sample_id_all(struct evlist *evlist);
242bool perf_evlist__valid_read_format(struct evlist *evlist);
0529bc1f 243
63503dba 244void perf_evlist__splice_list_tail(struct evlist *evlist,
f114d6ef 245 struct list_head *list);
0c21f736 246
63503dba 247static inline bool perf_evlist__empty(struct evlist *evlist)
64831a21 248{
ce9036a6 249 return list_empty(&evlist->core.entries);
64831a21
DCC
250}
251
63503dba 252static inline struct evsel *perf_evlist__first(struct evlist *evlist)
0c21f736 253{
ce9036a6 254 return list_entry(evlist->core.entries.next, struct evsel, core.node);
0c21f736
ACM
255}
256
63503dba 257static inline struct evsel *perf_evlist__last(struct evlist *evlist)
0c21f736 258{
ce9036a6 259 return list_entry(evlist->core.entries.prev, struct evsel, core.node);
0c21f736 260}
78f067b3 261
63503dba 262size_t perf_evlist__fprintf(struct evlist *evlist, FILE *fp);
0479b8b9 263
63503dba
JO
264int perf_evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
265int perf_evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
6ef068cb 266
63503dba
JO
267bool perf_evlist__can_select_event(struct evlist *evlist, const char *str);
268void perf_evlist__to_front(struct evlist *evlist,
32dcd021 269 struct evsel *move_evsel);
a025e4f0 270
0050f7aa 271/**
e5cadb93 272 * __evlist__for_each_entry - iterate thru all the evsels
0050f7aa
ACM
273 * @list: list_head instance to iterate
274 * @evsel: struct evsel iterator
275 */
e5cadb93 276#define __evlist__for_each_entry(list, evsel) \
b27c4ece 277 list_for_each_entry(evsel, list, core.node)
0050f7aa
ACM
278
279/**
e5cadb93 280 * evlist__for_each_entry - iterate thru all the evsels
0050f7aa
ACM
281 * @evlist: evlist instance to iterate
282 * @evsel: struct evsel iterator
283 */
e5cadb93 284#define evlist__for_each_entry(evlist, evsel) \
ce9036a6 285 __evlist__for_each_entry(&(evlist)->core.entries, evsel)
0050f7aa
ACM
286
287/**
e5cadb93 288 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
0050f7aa
ACM
289 * @list: list_head instance to iterate
290 * @evsel: struct evsel iterator
291 */
e5cadb93 292#define __evlist__for_each_entry_continue(list, evsel) \
b27c4ece 293 list_for_each_entry_continue(evsel, list, core.node)
0050f7aa
ACM
294
295/**
e5cadb93 296 * evlist__for_each_entry_continue - continue iteration thru all the evsels
0050f7aa
ACM
297 * @evlist: evlist instance to iterate
298 * @evsel: struct evsel iterator
299 */
e5cadb93 300#define evlist__for_each_entry_continue(evlist, evsel) \
ce9036a6 301 __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
0050f7aa
ACM
302
303/**
e5cadb93 304 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
0050f7aa
ACM
305 * @list: list_head instance to iterate
306 * @evsel: struct evsel iterator
307 */
e5cadb93 308#define __evlist__for_each_entry_reverse(list, evsel) \
b27c4ece 309 list_for_each_entry_reverse(evsel, list, core.node)
0050f7aa
ACM
310
311/**
e5cadb93 312 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
0050f7aa
ACM
313 * @evlist: evlist instance to iterate
314 * @evsel: struct evsel iterator
315 */
e5cadb93 316#define evlist__for_each_entry_reverse(evlist, evsel) \
ce9036a6 317 __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
0050f7aa
ACM
318
319/**
e5cadb93 320 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
0050f7aa
ACM
321 * @list: list_head instance to iterate
322 * @tmp: struct evsel temp iterator
323 * @evsel: struct evsel iterator
324 */
e5cadb93 325#define __evlist__for_each_entry_safe(list, tmp, evsel) \
b27c4ece 326 list_for_each_entry_safe(evsel, tmp, list, core.node)
0050f7aa
ACM
327
328/**
e5cadb93 329 * evlist__for_each_entry_safe - safely iterate thru all the evsels
0050f7aa
ACM
330 * @evlist: evlist instance to iterate
331 * @evsel: struct evsel iterator
332 * @tmp: struct evsel temp iterator
333 */
e5cadb93 334#define evlist__for_each_entry_safe(evlist, tmp, evsel) \
ce9036a6 335 __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
c09ec622 336
63503dba 337void perf_evlist__set_tracking_event(struct evlist *evlist,
32dcd021 338 struct evsel *tracking_evsel);
45cf6c33 339
32dcd021 340struct evsel *
63503dba 341perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
7cb5c5ac 342
63503dba 343struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
7cb5c5ac 344 union perf_event *event);
07d6f446 345
63503dba 346bool perf_evlist__exclude_kernel(struct evlist *evlist);
e2bdbe80 347
63503dba 348void perf_evlist__force_leader(struct evlist *evlist);
e2bdbe80 349
63503dba 350struct evsel *perf_evlist__reset_weak_group(struct evlist *evlist,
32dcd021 351 struct evsel *evsel);
361c99a6 352#endif /* __PERF_EVLIST_H */