]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - tools/perf/util/evlist.h
Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[mirror_ubuntu-jammy-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>
ce9036a6 10#include <internal/evlist.h>
515dbe48 11#include <internal/evsel.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
63503dba 51struct evlist {
ce9036a6 52 struct perf_evlist core;
97f63e4a 53 int nr_groups;
2b56bcfb 54 bool enabled;
75562573
AH
55 int id_pos;
56 int is_pos;
57 u64 combined_sample_type;
54cc54de 58 enum bkw_mmap_state bkw_mmap_state;
35b9d88e
ACM
59 struct {
60 int cork_fd;
61 pid_t pid;
62 } workload;
a5830532
JO
63 struct mmap *mmap;
64 struct mmap *overwrite_mmap;
32dcd021 65 struct evsel *selected;
75be989a 66 struct events_stats stats;
2c07144d 67 struct perf_env *env;
63503dba 68 void (*trace_event_sample_raw)(struct evlist *evlist,
93115d32
TR
69 union perf_event *event,
70 struct perf_sample *sample);
6011518d
JY
71 u64 first_sample_time;
72 u64 last_sample_time;
657ee553
SL
73 struct {
74 pthread_t th;
75 volatile int done;
76 } thread;
361c99a6
ACM
77};
78
32dcd021 79struct evsel_str_handler {
ee29be62
ACM
80 const char *name;
81 void *handler;
82};
83
0f98b11c 84struct evlist *evlist__new(void);
63503dba
JO
85struct evlist *perf_evlist__new_default(void);
86struct evlist *perf_evlist__new_dummy(void);
52c86bca
JO
87void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
88 struct perf_thread_map *threads);
470579b0 89void evlist__exit(struct evlist *evlist);
c12995a5 90void evlist__delete(struct evlist *evlist);
361c99a6 91
a1cf3a75 92void evlist__add(struct evlist *evlist, struct evsel *entry);
16251027 93void evlist__remove(struct evlist *evlist, struct evsel *evsel);
db918acb 94
63503dba 95int __perf_evlist__add_default(struct evlist *evlist, bool precise);
db918acb 96
63503dba 97static inline int perf_evlist__add_default(struct evlist *evlist)
db918acb
ACM
98{
99 return __perf_evlist__add_default(evlist, true);
100}
101
63503dba 102int __perf_evlist__add_default_attrs(struct evlist *evlist,
79695e1b 103 struct perf_event_attr *attrs, size_t nr_attrs);
e60fc847 104
79695e1b
ACM
105#define perf_evlist__add_default_attrs(evlist, array) \
106 __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
361c99a6 107
63503dba 108int perf_evlist__add_dummy(struct evlist *evlist);
5bae0250 109
63503dba 110int perf_evlist__add_sb_event(struct evlist **evlist,
657ee553
SL
111 struct perf_event_attr *attr,
112 perf_evsel__sb_cb_t cb,
113 void *data);
63503dba 114int perf_evlist__start_sb_thread(struct evlist *evlist,
657ee553 115 struct target *target);
63503dba 116void perf_evlist__stop_sb_thread(struct evlist *evlist);
657ee553 117
63503dba 118int perf_evlist__add_newtp(struct evlist *evlist,
39876e7d
ACM
119 const char *sys, const char *name, void *handler);
120
c0e53476
ACM
121int __evlist__set_tracepoints_handlers(struct evlist *evlist,
122 const struct evsel_str_handler *assocs,
123 size_t nr_assocs);
124
125#define evlist__set_tracepoints_handlers(evlist, array) \
126 __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
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
53c92f73
ACM
143int perf_evlist__append_tp_filter(struct evlist *evlist, const char *filter);
144
1827ab5b
ACM
145int perf_evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
146int perf_evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
147
32dcd021 148struct evsel *
63503dba 149perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
da378962 150
32dcd021 151struct evsel *
63503dba 152perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
a2f2804a
DA
153 const char *name);
154
f4009e7b
JO
155int evlist__add_pollfd(struct evlist *evlist, int fd);
156int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
1ddec7f0 157
80ab2987 158int evlist__poll(struct evlist *evlist, int timeout);
f66a889d 159
63503dba
JO
160struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
161struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
dddcf6ab 162 u64 id);
70db7533 163
63503dba 164struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id);
932a3594 165
63503dba 166void perf_evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
54cc54de 167
9521b5f2 168void evlist__mmap_consume(struct evlist *evlist, int idx);
8e50d384 169
474ddc4c 170int evlist__open(struct evlist *evlist);
750b4ede 171void evlist__close(struct evlist *evlist);
727ab04e 172
e68ae9cf
ACM
173struct callchain_param;
174
63503dba 175void perf_evlist__set_id_pos(struct evlist *evlist);
75562573 176bool perf_can_sample_identifier(void);
b757bb09 177bool perf_can_record_switch_events(void);
83509565 178bool perf_can_record_cpu_wide(void);
9bca1a4e 179bool perf_can_aux_sample(void);
63503dba 180void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
e68ae9cf 181 struct callchain_param *callchain);
b4006796 182int record_opts__config(struct record_opts *opts);
0f82ebc4 183
63503dba 184int perf_evlist__prepare_workload(struct evlist *evlist,
602ad878 185 struct target *target,
55e162ea 186 const char *argv[], bool pipe_output,
735f7e0b
ACM
187 void (*exec_error)(int signo, siginfo_t *info,
188 void *ucontext));
63503dba 189int perf_evlist__start_workload(struct evlist *evlist);
35b9d88e 190
724ce97e
ACM
191struct option;
192
e9db1310 193int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
994a1f78
JO
194int perf_evlist__parse_mmap_pages(const struct option *opt,
195 const char *str,
196 int unset);
197
f5e7150c
ACM
198unsigned long perf_event_mlock_kb_in_pages(void);
199
9521b5f2 200int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
7a276ff6 201 unsigned int auxtrace_pages,
470530bb 202 bool auxtrace_overwrite, int nr_cblocks,
51255a8a 203 int affinity, int flush, int comp_level);
9521b5f2 204int evlist__mmap(struct evlist *evlist, unsigned int pages);
db6b7b13 205void evlist__munmap(struct evlist *evlist);
7e2ed097 206
9521b5f2 207size_t evlist__mmap_size(unsigned long pages);
0c582449 208
e74676de 209void evlist__disable(struct evlist *evlist);
1c87f165 210void evlist__enable(struct evlist *evlist);
63503dba 211void perf_evlist__toggle_enable(struct evlist *evlist);
4152ab37 212
63503dba 213int perf_evlist__enable_event_idx(struct evlist *evlist,
32dcd021 214 struct evsel *evsel, int idx);
395c3070 215
63503dba 216void perf_evlist__set_selected(struct evlist *evlist,
32dcd021 217 struct evsel *evsel);
81cce8de 218
63503dba
JO
219int perf_evlist__create_maps(struct evlist *evlist, struct target *target);
220int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
f8a95309 221
63dab225 222void __perf_evlist__set_leader(struct list_head *list);
63503dba 223void perf_evlist__set_leader(struct evlist *evlist);
63dab225 224
63503dba
JO
225u64 __perf_evlist__combined_sample_type(struct evlist *evlist);
226u64 perf_evlist__combined_sample_type(struct evlist *evlist);
227u64 perf_evlist__combined_branch_type(struct evlist *evlist);
228bool perf_evlist__sample_id_all(struct evlist *evlist);
229u16 perf_evlist__id_hdr_size(struct evlist *evlist);
74429964 230
63503dba 231int perf_evlist__parse_sample(struct evlist *evlist, union perf_event *event,
0807d2d8 232 struct perf_sample *sample);
cb0b29e0 233
63503dba 234int perf_evlist__parse_sample_timestamp(struct evlist *evlist,
01468120
JO
235 union perf_event *event,
236 u64 *timestamp);
237
63503dba
JO
238bool perf_evlist__valid_sample_type(struct evlist *evlist);
239bool perf_evlist__valid_sample_id_all(struct evlist *evlist);
240bool perf_evlist__valid_read_format(struct evlist *evlist);
0529bc1f 241
63503dba 242void perf_evlist__splice_list_tail(struct evlist *evlist,
f114d6ef 243 struct list_head *list);
0c21f736 244
63503dba 245static inline bool perf_evlist__empty(struct evlist *evlist)
64831a21 246{
ce9036a6 247 return list_empty(&evlist->core.entries);
64831a21
DCC
248}
249
515dbe48 250static inline struct evsel *evlist__first(struct evlist *evlist)
0c21f736 251{
515dbe48
JO
252 struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
253
254 return container_of(evsel, struct evsel, core);
0c21f736
ACM
255}
256
515dbe48 257static inline struct evsel *evlist__last(struct evlist *evlist)
0c21f736 258{
515dbe48
JO
259 struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
260
261 return container_of(evsel, struct evsel, core);
0c21f736 262}
78f067b3 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
a8cbe40f
AK
337#define evlist__for_each_cpu(evlist, index, cpu) \
338 evlist__cpu_iter_start(evlist); \
339 perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
340
63503dba 341void perf_evlist__set_tracking_event(struct evlist *evlist,
32dcd021 342 struct evsel *tracking_evsel);
45cf6c33 343
a8cbe40f
AK
344void evlist__cpu_iter_start(struct evlist *evlist);
345bool evsel__cpu_iter_skip(struct evsel *ev, int cpu);
346bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu);
347
32dcd021 348struct evsel *
63503dba 349perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
7cb5c5ac 350
63503dba 351struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
7cb5c5ac 352 union perf_event *event);
07d6f446 353
63503dba 354bool perf_evlist__exclude_kernel(struct evlist *evlist);
e2bdbe80 355
63503dba 356void perf_evlist__force_leader(struct evlist *evlist);
e2bdbe80 357
63503dba 358struct evsel *perf_evlist__reset_weak_group(struct evlist *evlist,
4804e011
AK
359 struct evsel *evsel,
360 bool close);
361c99a6 361#endif /* __PERF_EVLIST_H */