xref: /linux/tools/perf/util/evlist.h (revision ce7948448d99fcb5e8a564c46fbc96a9282b78eb)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_EVLIST_H
3 #define __PERF_EVLIST_H 1
4 
5 #include <signal.h>
6 
7 #include <linux/compiler.h>
8 #include <linux/kernel.h>
9 #include <linux/list.h>
10 #include <linux/refcount.h>
11 #include <pthread.h>
12 #include <unistd.h>
13 
14 #include <api/fd/array.h>
15 #include <internal/evlist.h>
16 #include <internal/evsel.h>
17 #include <internal/rc_check.h>
18 #include <perf/evlist.h>
19 
20 #include "affinity.h"
21 #include "events_stats.h"
22 #include "evsel.h"
23 #include "rblist.h"
24 
25 struct perf_cpu_map;
26 struct perf_stat_config;
27 struct pollfd;
28 struct record_opts;
29 struct strbuf;
30 struct target;
31 struct thread_map;
32 
33 /*
34  * State machine of bkw_mmap_state:
35  *
36  *                     .________________(forbid)_____________.
37  *                     |                                     V
38  * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
39  *                     ^  ^              |   ^               |
40  *                     |  |__(forbid)____/   |___(forbid)___/|
41  *                     |                                     |
42  *                      \_________________(3)_______________/
43  *
44  * NOTREADY     : Backward ring buffers are not ready
45  * RUNNING      : Backward ring buffers are recording
46  * DATA_PENDING : We are required to collect data from backward ring buffers
47  * EMPTY        : We have collected data from backward ring buffers.
48  *
49  * (0): Setup backward ring buffer
50  * (1): Pause ring buffers for reading
51  * (2): Read from ring buffers
52  * (3): Resume ring buffers for recording
53  */
54 enum bkw_mmap_state {
55 	BKW_MMAP_NOTREADY,
56 	BKW_MMAP_RUNNING,
57 	BKW_MMAP_DATA_PENDING,
58 	BKW_MMAP_EMPTY,
59 };
60 
61 struct event_enable_timer;
62 
63 DECLARE_RC_STRUCT(evlist) {
64 	struct perf_evlist core;
65 	refcount_t	 refcnt;
66 	bool		 enabled;
67 	bool		 no_affinity;
68 	int		 id_pos;
69 	int		 is_pos;
70 	int		 nr_br_cntr;
71 	u64		 combined_sample_type;
72 	enum bkw_mmap_state bkw_mmap_state;
73 	struct {
74 		int	cork_fd;
75 		pid_t	pid;
76 	} workload;
77 	struct mmap *mmap;
78 	struct mmap *overwrite_mmap;
79 	struct evsel *selected;
80 	struct events_stats stats;
81 	struct perf_session *session;
82 	void (*trace_event_sample_raw)(struct evlist *evlist,
83 				       union perf_event *event,
84 				       struct perf_sample *sample);
85 	u64		first_sample_time;
86 	u64		last_sample_time;
87 	struct {
88 		pthread_t		th;
89 		volatile int		done;
90 	} sb_thread;
91 	struct {
92 		int	fd;	/* control file descriptor */
93 		int	ack;	/* ack file descriptor for control commands */
94 		int	pos;	/* index at evlist core object to check signals */
95 	} ctl_fd;
96 	struct event_enable_timer *eet;
97 	/**
98 	 * @metric_events: A list of struct metric_event which each have a list
99 	 * of struct metric_expr.
100 	 */
101 	struct rblist	metric_events;
102 	/* samples with deferred_callchain would wait here. */
103 	struct list_head deferred_samples;
104 };
105 
106 struct evsel_str_handler {
107 	const char *name;
108 	void	   *handler;
109 };
110 
111 static inline struct perf_evlist *evlist__core(struct evlist *evlist)
112 {
113 	return &RC_CHK_ACCESS(evlist)->core;
114 }
115 
116 static inline const struct perf_evlist *evlist__const_core(const struct evlist *evlist)
117 {
118 	return &RC_CHK_ACCESS(evlist)->core;
119 }
120 
121 static inline int evlist__nr_entries(const struct evlist *evlist)
122 {
123 	return evlist__const_core(evlist)->nr_entries;
124 }
125 
126 static inline bool evlist__enabled(const struct evlist *evlist)
127 {
128 	return RC_CHK_ACCESS(evlist)->enabled;
129 }
130 
131 static inline void evlist__set_enabled(struct evlist *evlist, bool enabled)
132 {
133 	RC_CHK_ACCESS(evlist)->enabled = enabled;
134 }
135 
136 static inline bool evlist__no_affinity(const struct evlist *evlist)
137 {
138 	return RC_CHK_ACCESS(evlist)->no_affinity;
139 }
140 
141 static inline void evlist__set_no_affinity(struct evlist *evlist, bool no_affinity)
142 {
143 	RC_CHK_ACCESS(evlist)->no_affinity = no_affinity;
144 }
145 
146 static inline int evlist__sb_thread_done(const struct evlist *evlist)
147 {
148 	return RC_CHK_ACCESS(evlist)->sb_thread.done;
149 }
150 
151 static inline void evlist__set_sb_thread_done(struct evlist *evlist, int done)
152 {
153 	RC_CHK_ACCESS(evlist)->sb_thread.done = done;
154 }
155 
156 static inline pthread_t *evlist__sb_thread_th(struct evlist *evlist)
157 {
158 	return &RC_CHK_ACCESS(evlist)->sb_thread.th;
159 }
160 
161 static inline int evlist__id_pos(const struct evlist *evlist)
162 {
163 	return RC_CHK_ACCESS(evlist)->id_pos;
164 }
165 
166 static inline int evlist__is_pos(const struct evlist *evlist)
167 {
168 	return RC_CHK_ACCESS(evlist)->is_pos;
169 }
170 
171 static inline struct event_enable_timer *evlist__event_enable_timer(struct evlist *evlist)
172 {
173 	return RC_CHK_ACCESS(evlist)->eet;
174 }
175 
176 static inline enum bkw_mmap_state evlist__bkw_mmap_state(const struct evlist *evlist)
177 {
178 	return RC_CHK_ACCESS(evlist)->bkw_mmap_state;
179 }
180 
181 static inline void evlist__set_bkw_mmap_state(struct evlist *evlist, enum bkw_mmap_state state)
182 {
183 	RC_CHK_ACCESS(evlist)->bkw_mmap_state = state;
184 }
185 
186 static inline struct mmap *evlist__mmap(struct evlist *evlist)
187 {
188 	return RC_CHK_ACCESS(evlist)->mmap;
189 }
190 
191 static inline struct mmap *evlist__overwrite_mmap(struct evlist *evlist)
192 {
193 	return RC_CHK_ACCESS(evlist)->overwrite_mmap;
194 }
195 
196 static inline struct events_stats *evlist__stats(struct evlist *evlist)
197 {
198 	return &RC_CHK_ACCESS(evlist)->stats;
199 }
200 
201 static inline u64 evlist__first_sample_time(const struct evlist *evlist)
202 {
203 	return RC_CHK_ACCESS(evlist)->first_sample_time;
204 }
205 
206 static inline void evlist__set_first_sample_time(struct evlist *evlist, u64 first)
207 {
208 	RC_CHK_ACCESS(evlist)->first_sample_time = first;
209 }
210 
211 static inline u64 evlist__last_sample_time(const struct evlist *evlist)
212 {
213 	return RC_CHK_ACCESS(evlist)->last_sample_time;
214 }
215 
216 static inline void evlist__set_last_sample_time(struct evlist *evlist, u64 last)
217 {
218 	RC_CHK_ACCESS(evlist)->last_sample_time = last;
219 }
220 
221 static inline int evlist__nr_br_cntr(const struct evlist *evlist)
222 {
223 	return RC_CHK_ACCESS(evlist)->nr_br_cntr;
224 }
225 
226 static inline void evlist__set_nr_br_cntr(struct evlist *evlist, int nr)
227 {
228 	RC_CHK_ACCESS(evlist)->nr_br_cntr = nr;
229 }
230 
231 static inline struct perf_session *evlist__session(struct evlist *evlist)
232 {
233 	return RC_CHK_ACCESS(evlist)->session;
234 }
235 
236 static inline void evlist__set_session(struct evlist *evlist, struct perf_session *session)
237 {
238 	RC_CHK_ACCESS(evlist)->session = session;
239 }
240 
241 static inline void (*evlist__trace_event_sample_raw(struct evlist *evlist))
242 			(struct evlist *evlist,
243 			 union perf_event *event,
244 			 struct perf_sample *sample)
245 {
246 	return RC_CHK_ACCESS(evlist)->trace_event_sample_raw;
247 }
248 
249 static inline void evlist__set_trace_event_sample_raw(struct evlist *evlist,
250 						void (*fun)(struct evlist *evlist,
251 							union perf_event *event,
252 							struct perf_sample *sample))
253 {
254 	RC_CHK_ACCESS(evlist)->trace_event_sample_raw = fun;
255 }
256 
257 static inline pid_t evlist__workload_pid(const struct evlist *evlist)
258 {
259 	return RC_CHK_ACCESS(evlist)->workload.pid;
260 }
261 
262 static inline void evlist__set_workload_pid(struct evlist *evlist, pid_t pid)
263 {
264 	RC_CHK_ACCESS(evlist)->workload.pid = pid;
265 }
266 
267 static inline int evlist__workload_cork_fd(const struct evlist *evlist)
268 {
269 	return RC_CHK_ACCESS(evlist)->workload.cork_fd;
270 }
271 
272 static inline void evlist__set_workload_cork_fd(struct evlist *evlist, int cork_fd)
273 {
274 	RC_CHK_ACCESS(evlist)->workload.cork_fd = cork_fd;
275 }
276 
277 static inline int evlist__ctl_fd_fd(const struct evlist *evlist)
278 {
279 	return RC_CHK_ACCESS(evlist)->ctl_fd.fd;
280 }
281 
282 static inline void evlist__set_ctl_fd_fd(struct evlist *evlist, int fd)
283 {
284 	RC_CHK_ACCESS(evlist)->ctl_fd.fd = fd;
285 }
286 
287 static inline int evlist__ctl_fd_ack(const struct evlist *evlist)
288 {
289 	return RC_CHK_ACCESS(evlist)->ctl_fd.ack;
290 }
291 
292 static inline void evlist__set_ctl_fd_ack(struct evlist *evlist, int ack)
293 {
294 	RC_CHK_ACCESS(evlist)->ctl_fd.ack = ack;
295 }
296 
297 static inline int evlist__ctl_fd_pos(const struct evlist *evlist)
298 {
299 	return RC_CHK_ACCESS(evlist)->ctl_fd.pos;
300 }
301 
302 static inline void evlist__set_ctl_fd_pos(struct evlist *evlist, int pos)
303 {
304 	RC_CHK_ACCESS(evlist)->ctl_fd.pos = pos;
305 }
306 
307 static inline refcount_t *evlist__refcnt(struct evlist *evlist)
308 {
309 	return &RC_CHK_ACCESS(evlist)->refcnt;
310 }
311 
312 static inline struct rblist *evlist__metric_events(struct evlist *evlist)
313 {
314 	return &RC_CHK_ACCESS(evlist)->metric_events;
315 }
316 
317 static inline struct list_head *evlist__deferred_samples(struct evlist *evlist)
318 {
319 	return &RC_CHK_ACCESS(evlist)->deferred_samples;
320 }
321 
322 static inline struct evsel *evlist__selected(struct evlist *evlist)
323 {
324 	return RC_CHK_ACCESS(evlist)->selected;
325 }
326 
327 static inline void evlist__set_selected(struct evlist *evlist, struct evsel *evsel)
328 {
329 	RC_CHK_ACCESS(evlist)->selected = evsel;
330 }
331 
332 struct evlist *evlist__new(void);
333 struct evlist *evlist__new_default(const struct target *target, bool sample_callchains);
334 struct perf_env;
335 bool evlist__can_merge_hybrid(struct evlist *evlist, struct perf_env *env);
336 void evlist__merge_hybrid(struct evlist *evlist, struct perf_env *env);
337 struct evlist *evlist__new_dummy(void);
338 struct evlist *evlist__get(struct evlist *evlist);
339 void evlist__put(struct evlist *evlist);
340 
341 void evlist__add(struct evlist *evlist, struct evsel *entry);
342 void evlist__remove(struct evlist *evlist, struct evsel *evsel);
343 
344 int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs);
345 int arch_evlist__add_required_events(struct list_head *list);
346 
347 int evlist__add_dummy(struct evlist *evlist);
348 struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wide);
349 static inline struct evsel *evlist__add_dummy_on_all_cpus(struct evlist *evlist)
350 {
351 	return evlist__add_aux_dummy(evlist, true);
352 }
353 #ifdef HAVE_LIBTRACEEVENT
354 struct evsel *evlist__add_sched_switch(struct evlist *evlist, bool system_wide);
355 #endif
356 
357 int evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr,
358 			 evsel__sb_cb_t cb, void *data);
359 void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
360 int evlist__start_sb_thread(struct evlist *evlist, struct target *target);
361 void evlist__stop_sb_thread(struct evlist *evlist);
362 
363 #ifdef HAVE_LIBTRACEEVENT
364 int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
365 #endif
366 
367 int __evlist__set_tracepoints_handlers(struct evlist *evlist,
368 				       const struct evsel_str_handler *assocs,
369 				       size_t nr_assocs);
370 
371 #define evlist__set_tracepoints_handlers(evlist, array) \
372 	__evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
373 
374 int evlist__set_tp_filter(struct evlist *evlist, const char *filter);
375 int evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
376 
377 int evlist__append_tp_filter(struct evlist *evlist, const char *filter);
378 
379 int evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
380 int evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
381 
382 struct evsel *evlist__find_tracepoint_by_name(struct evlist *evlist, const char *name);
383 
384 int evlist__add_pollfd(struct evlist *evlist, int fd);
385 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
386 
387 #ifdef HAVE_EVENTFD_SUPPORT
388 int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd);
389 #endif
390 
391 int evlist__poll(struct evlist *evlist, int timeout);
392 
393 struct evsel *evlist__id2evsel(struct evlist *evlist, u64 id);
394 struct evsel *evlist__id2evsel_strict(struct evlist *evlist, u64 id);
395 
396 struct perf_sample_id *evlist__id2sid(struct evlist *evlist, u64 id);
397 
398 void evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
399 
400 void evlist__mmap_consume(struct evlist *evlist, int idx);
401 
402 int evlist__open(struct evlist *evlist);
403 void evlist__close(struct evlist *evlist);
404 
405 struct callchain_param;
406 
407 void evlist__set_id_pos(struct evlist *evlist);
408 void evlist__config(struct evlist *evlist, struct record_opts *opts, struct callchain_param *callchain);
409 int record_opts__config(struct record_opts *opts);
410 
411 int evlist__prepare_workload(struct evlist *evlist, struct target *target,
412 			     const char *argv[], bool pipe_output,
413 			     void (*exec_error)(int signo, siginfo_t *info, void *ucontext));
414 int evlist__start_workload(struct evlist *evlist);
415 void evlist__cancel_workload(struct evlist *evlist);
416 
417 struct option;
418 
419 int __evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
420 int evlist__parse_mmap_pages(const struct option *opt, const char *str, int unset);
421 
422 unsigned long perf_event_mlock_kb_in_pages(void);
423 
424 int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
425 			 unsigned int auxtrace_pages,
426 			 bool auxtrace_overwrite, int nr_cblocks,
427 			 int affinity, int flush, int comp_level);
428 int evlist__do_mmap(struct evlist *evlist, unsigned int pages);
429 void evlist__do_munmap(struct evlist *evlist);
430 
431 size_t evlist__mmap_size(unsigned long pages);
432 
433 void evlist__disable(struct evlist *evlist);
434 void evlist__enable(struct evlist *evlist);
435 void evlist__toggle_enable(struct evlist *evlist);
436 void evlist__disable_evsel(struct evlist *evlist, char *evsel_name);
437 void evlist__enable_evsel(struct evlist *evlist, char *evsel_name);
438 void evlist__disable_non_dummy(struct evlist *evlist);
439 void evlist__enable_non_dummy(struct evlist *evlist);
440 
441 int evlist__create_maps(struct evlist *evlist, struct target *target);
442 int evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel,
443 			  struct target *target);
444 
445 u64 __evlist__combined_sample_type(struct evlist *evlist);
446 u64 evlist__combined_sample_type(struct evlist *evlist);
447 u64 evlist__combined_branch_type(struct evlist *evlist);
448 void evlist__update_br_cntr(struct evlist *evlist);
449 bool evlist__sample_id_all(struct evlist *evlist);
450 u16 evlist__id_hdr_size(struct evlist *evlist);
451 
452 int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct perf_sample *sample);
453 int evlist__parse_sample_timestamp(struct evlist *evlist, union perf_event *event, u64 *timestamp);
454 
455 bool evlist__valid_sample_type(struct evlist *evlist);
456 bool evlist__valid_sample_id_all(struct evlist *evlist);
457 bool evlist__valid_read_format(struct evlist *evlist);
458 
459 void evlist__splice_list_tail(struct evlist *evlist, struct list_head *list);
460 
461 static inline bool evlist__empty(struct evlist *evlist)
462 {
463 	return list_empty(&evlist__core(evlist)->entries);
464 }
465 
466 static inline struct evsel *evlist__first(struct evlist *evlist)
467 {
468 	struct perf_evsel *evsel = perf_evlist__first(evlist__core(evlist));
469 
470 	return container_of(evsel, struct evsel, core);
471 }
472 
473 static inline struct evsel *evlist__last(struct evlist *evlist)
474 {
475 	struct perf_evsel *evsel = perf_evlist__last(evlist__core(evlist));
476 
477 	return container_of(evsel, struct evsel, core);
478 }
479 
480 static inline int evlist__nr_groups(struct evlist *evlist)
481 {
482 	return perf_evlist__nr_groups(evlist__core(evlist));
483 }
484 
485 int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
486 int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
487 
488 bool evlist__can_select_event(struct evlist *evlist, const char *str);
489 void evlist__to_front(struct evlist *evlist, struct evsel *move_evsel);
490 
491 /**
492  * __evlist__for_each_entry - iterate thru all the evsels
493  * @list: list_head instance to iterate
494  * @evsel: struct evsel iterator
495  */
496 #define __evlist__for_each_entry(list, evsel) \
497         list_for_each_entry(evsel, list, core.node)
498 
499 /**
500  * evlist__for_each_entry - iterate thru all the evsels
501  * @evlist: evlist instance to iterate
502  * @evsel: struct evsel iterator
503  */
504 #define evlist__for_each_entry(evlist, evsel) \
505 	__evlist__for_each_entry(&evlist__core(evlist)->entries, evsel)
506 
507 /**
508  * __evlist__for_each_entry_continue - continue iteration thru all the evsels
509  * @list: list_head instance to iterate
510  * @evsel: struct evsel iterator
511  */
512 #define __evlist__for_each_entry_continue(list, evsel) \
513         list_for_each_entry_continue(evsel, list, core.node)
514 
515 /**
516  * evlist__for_each_entry_continue - continue iteration thru all the evsels
517  * @evlist: evlist instance to iterate
518  * @evsel: struct evsel iterator
519  */
520 #define evlist__for_each_entry_continue(evlist, evsel) \
521 	__evlist__for_each_entry_continue(&evlist__core(evlist)->entries, evsel)
522 
523 /**
524  * __evlist__for_each_entry_from - continue iteration from @evsel (included)
525  * @list: list_head instance to iterate
526  * @evsel: struct evsel iterator
527  */
528 #define __evlist__for_each_entry_from(list, evsel) \
529 	list_for_each_entry_from(evsel, list, core.node)
530 
531 /**
532  * evlist__for_each_entry_from - continue iteration from @evsel (included)
533  * @evlist: evlist instance to iterate
534  * @evsel: struct evsel iterator
535  */
536 #define evlist__for_each_entry_from(evlist, evsel) \
537 	__evlist__for_each_entry_from(&evlist__core(evlist)->entries, evsel)
538 
539 /**
540  * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
541  * @list: list_head instance to iterate
542  * @evsel: struct evsel iterator
543  */
544 #define __evlist__for_each_entry_reverse(list, evsel) \
545         list_for_each_entry_reverse(evsel, list, core.node)
546 
547 /**
548  * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
549  * @evlist: evlist instance to iterate
550  * @evsel: struct evsel iterator
551  */
552 #define evlist__for_each_entry_reverse(evlist, evsel) \
553 	__evlist__for_each_entry_reverse(&evlist__core(evlist)->entries, evsel)
554 
555 /**
556  * __evlist__for_each_entry_safe - safely iterate thru all the evsels
557  * @list: list_head instance to iterate
558  * @tmp: struct evsel temp iterator
559  * @evsel: struct evsel iterator
560  */
561 #define __evlist__for_each_entry_safe(list, tmp, evsel) \
562         list_for_each_entry_safe(evsel, tmp, list, core.node)
563 
564 /**
565  * evlist__for_each_entry_safe - safely iterate thru all the evsels
566  * @evlist: evlist instance to iterate
567  * @evsel: struct evsel iterator
568  * @tmp: struct evsel temp iterator
569  */
570 #define evlist__for_each_entry_safe(evlist, tmp, evsel) \
571 	__evlist__for_each_entry_safe(&evlist__core(evlist)->entries, tmp, evsel)
572 
573 /** Iterator state for evlist__for_each_cpu */
574 struct evlist_cpu_iterator {
575 	/** The list being iterated through. */
576 	struct evlist *container;
577 	/** The current evsel of the iterator. */
578 	struct evsel *evsel;
579 	/** The CPU map index corresponding to the evsel->core.cpus for the current CPU. */
580 	int cpu_map_idx;
581 	/**
582 	 * The CPU map index corresponding to evlist->core.all_cpus for the
583 	 * current CPU.  Distinct from cpu_map_idx as the evsel's cpu map may
584 	 * contain fewer entries.
585 	 */
586 	int evlist_cpu_map_idx;
587 	/** The number of CPU map entries in evlist->core.all_cpus. */
588 	int evlist_cpu_map_nr;
589 	/** The current CPU of the iterator. */
590 	struct perf_cpu cpu;
591 	/** If present, used to set the affinity when switching between CPUs. */
592 	struct affinity *affinity;
593 	/** Maybe be used to hold affinity state prior to iterating. */
594 	struct affinity saved_affinity;
595 };
596 
597 /**
598  * evlist__for_each_cpu - without affinity, iterate over the evlist. With
599  *                        affinity, iterate over all CPUs and then the evlist
600  *                        for each evsel on that CPU. When switching between
601  *                        CPUs the affinity is set to the CPU to avoid IPIs
602  *                        during syscalls. The affinity is set up and removed
603  *                        automatically, if the loop is broken a call to
604  *                        evlist_cpu_iterator__exit is necessary.
605  * @evlist_cpu_itr: the iterator instance.
606  * @evlist: evlist instance to iterate.
607  */
608 #define evlist__for_each_cpu(evlist_cpu_itr, evlist)			\
609 	for (evlist_cpu_iterator__init(&(evlist_cpu_itr), evlist);	\
610 	     !evlist_cpu_iterator__end(&evlist_cpu_itr);		\
611 	     evlist_cpu_iterator__next(&evlist_cpu_itr))
612 
613 /** Setup an iterator set to the first CPU/evsel of evlist. */
614 void evlist_cpu_iterator__init(struct evlist_cpu_iterator *itr, struct evlist *evlist);
615 /**
616  * Cleans up the iterator, automatically done by evlist_cpu_iterator__next when
617  * the end of the list is reached. Multiple calls are safe.
618  */
619 void evlist_cpu_iterator__exit(struct evlist_cpu_iterator *itr);
620 /** Move to next element in iterator, updating CPU, evsel and the affinity. */
621 void evlist_cpu_iterator__next(struct evlist_cpu_iterator *evlist_cpu_itr);
622 /** Returns true when iterator is at the end of the CPUs and evlist. */
623 static inline bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu_itr)
624 {
625 	return evlist_cpu_itr->evlist_cpu_map_idx >= evlist_cpu_itr->evlist_cpu_map_nr;
626 }
627 
628 struct evsel *evlist__get_tracking_event(struct evlist *evlist);
629 void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel);
630 struct evsel *evlist__findnew_tracking_event(struct evlist *evlist, bool system_wide);
631 
632 struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
633 
634 struct evsel *evlist__event2evsel(struct evlist *evlist, union perf_event *event);
635 
636 bool evlist__exclude_kernel(struct evlist *evlist);
637 
638 void evlist__force_leader(struct evlist *evlist);
639 
640 struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evsel, bool close);
641 
642 #define EVLIST_CTL_CMD_ENABLE_TAG  "enable"
643 #define EVLIST_CTL_CMD_DISABLE_TAG "disable"
644 #define EVLIST_CTL_CMD_ACK_TAG     "ack\n"
645 #define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
646 #define EVLIST_CTL_CMD_EVLIST_TAG "evlist"
647 #define EVLIST_CTL_CMD_STOP_TAG "stop"
648 #define EVLIST_CTL_CMD_PING_TAG "ping"
649 
650 #define EVLIST_CTL_CMD_MAX_LEN 64
651 
652 enum evlist_ctl_cmd {
653 	EVLIST_CTL_CMD_UNSUPPORTED = 0,
654 	EVLIST_CTL_CMD_ENABLE,
655 	EVLIST_CTL_CMD_DISABLE,
656 	EVLIST_CTL_CMD_ACK,
657 	EVLIST_CTL_CMD_SNAPSHOT,
658 	EVLIST_CTL_CMD_EVLIST,
659 	EVLIST_CTL_CMD_STOP,
660 	EVLIST_CTL_CMD_PING,
661 };
662 
663 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
664 void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close);
665 int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
666 int evlist__finalize_ctlfd(struct evlist *evlist);
667 bool evlist__ctlfd_initialized(struct evlist *evlist);
668 int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd);
669 int evlist__ctlfd_ack(struct evlist *evlist);
670 
671 #define EVLIST_ENABLED_MSG "Events enabled\n"
672 #define EVLIST_DISABLED_MSG "Events disabled\n"
673 
674 int evlist__parse_event_enable_time(struct evlist *evlist, struct record_opts *opts,
675 				    const char *str, int unset);
676 int event_enable_timer__start(struct event_enable_timer *eet);
677 int event_enable_timer__process(struct event_enable_timer *eet);
678 
679 struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
680 
681 void evlist__format_evsels(struct evlist *evlist, struct strbuf *sb, size_t max_length);
682 void evlist__check_mem_load_aux(struct evlist *evlist);
683 void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_list);
684 void evlist__uniquify_evsel_names(struct evlist *evlist, const struct perf_stat_config *config);
685 bool evlist__has_bpf_output(struct evlist *evlist);
686 bool evlist__needs_bpf_sb_event(struct evlist *evlist);
687 
688 #endif /* __PERF_EVLIST_H */
689