Linux Audio

Check our new training course

Loading...
v6.2
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PERF_EVLIST_H
  3#define __PERF_EVLIST_H 1
  4
  5#include <linux/compiler.h>
  6#include <linux/kernel.h>
  7#include <linux/refcount.h>
  8#include <linux/list.h>
  9#include <api/fd/array.h>
 10#include <internal/evlist.h>
 11#include <internal/evsel.h>
 
 12#include "events_stats.h"
 13#include "evsel.h"
 14#include <pthread.h>
 15#include <signal.h>
 16#include <unistd.h>
 17
 18struct pollfd;
 19struct thread_map;
 20struct perf_cpu_map;
 21struct record_opts;
 
 22
 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
 51struct event_enable_timer;
 52
 53struct evlist {
 54	struct perf_evlist core;
 55	bool		 enabled;
 56	int		 id_pos;
 57	int		 is_pos;
 
 58	u64		 combined_sample_type;
 59	enum bkw_mmap_state bkw_mmap_state;
 60	struct {
 61		int	cork_fd;
 62		pid_t	pid;
 63	} workload;
 64	struct mmap *mmap;
 65	struct mmap *overwrite_mmap;
 66	struct evsel *selected;
 67	struct events_stats stats;
 68	struct perf_env	*env;
 69	const char *hybrid_pmu_name;
 70	void (*trace_event_sample_raw)(struct evlist *evlist,
 71				       union perf_event *event,
 72				       struct perf_sample *sample);
 73	u64		first_sample_time;
 74	u64		last_sample_time;
 75	struct {
 76		pthread_t		th;
 77		volatile int		done;
 78	} thread;
 79	struct {
 80		int	fd;	/* control file descriptor */
 81		int	ack;	/* ack file descriptor for control commands */
 82		int	pos;	/* index at evlist core object to check signals */
 83	} ctl_fd;
 84	struct event_enable_timer *eet;
 85};
 86
 87struct evsel_str_handler {
 88	const char *name;
 89	void	   *handler;
 90};
 91
 92struct evlist *evlist__new(void);
 93struct evlist *evlist__new_default(void);
 94struct evlist *evlist__new_dummy(void);
 95void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
 96		  struct perf_thread_map *threads);
 97void evlist__exit(struct evlist *evlist);
 98void evlist__delete(struct evlist *evlist);
 99
100void evlist__add(struct evlist *evlist, struct evsel *entry);
101void evlist__remove(struct evlist *evlist, struct evsel *evsel);
102
103int __evlist__add_default(struct evlist *evlist, bool precise);
104
105static inline int evlist__add_default(struct evlist *evlist)
106{
107	return __evlist__add_default(evlist, true);
108}
109
110int evlist__add_attrs(struct evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs);
111
112int __evlist__add_default_attrs(struct evlist *evlist,
113				     struct perf_event_attr *attrs, size_t nr_attrs);
114
115int arch_evlist__add_default_attrs(struct evlist *evlist,
116				   struct perf_event_attr *attrs,
117				   size_t nr_attrs);
118
119#define evlist__add_default_attrs(evlist, array) \
120	arch_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
121
122struct evsel *arch_evlist__leader(struct list_head *list);
123
124int evlist__add_dummy(struct evlist *evlist);
125struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wide);
126static inline struct evsel *evlist__add_dummy_on_all_cpus(struct evlist *evlist)
127{
128	return evlist__add_aux_dummy(evlist, true);
129}
130#ifdef HAVE_LIBTRACEEVENT
131struct evsel *evlist__add_sched_switch(struct evlist *evlist, bool system_wide);
132#endif
133
134int evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr,
135			 evsel__sb_cb_t cb, void *data);
136void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
137int evlist__start_sb_thread(struct evlist *evlist, struct target *target);
138void evlist__stop_sb_thread(struct evlist *evlist);
139
140#ifdef HAVE_LIBTRACEEVENT
141int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
142#endif
143
144int __evlist__set_tracepoints_handlers(struct evlist *evlist,
145				       const struct evsel_str_handler *assocs,
146				       size_t nr_assocs);
147
148#define evlist__set_tracepoints_handlers(evlist, array) \
149	__evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
150
151int evlist__set_tp_filter(struct evlist *evlist, const char *filter);
152int evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
153int evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
154
155int evlist__append_tp_filter(struct evlist *evlist, const char *filter);
156
157int evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
158int evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
159
160struct evsel *evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
161struct evsel *evlist__find_tracepoint_by_name(struct evlist *evlist, const char *name);
162
163int evlist__add_pollfd(struct evlist *evlist, int fd);
164int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
165
166#ifdef HAVE_EVENTFD_SUPPORT
167int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd);
168#endif
169
170int evlist__poll(struct evlist *evlist, int timeout);
171
172struct evsel *evlist__id2evsel(struct evlist *evlist, u64 id);
173struct evsel *evlist__id2evsel_strict(struct evlist *evlist, u64 id);
174
175struct perf_sample_id *evlist__id2sid(struct evlist *evlist, u64 id);
176
177void evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
178
179void evlist__mmap_consume(struct evlist *evlist, int idx);
180
181int evlist__open(struct evlist *evlist);
182void evlist__close(struct evlist *evlist);
183
184struct callchain_param;
185
186void evlist__set_id_pos(struct evlist *evlist);
187void evlist__config(struct evlist *evlist, struct record_opts *opts, struct callchain_param *callchain);
188int record_opts__config(struct record_opts *opts);
189
190int evlist__prepare_workload(struct evlist *evlist, struct target *target,
191			     const char *argv[], bool pipe_output,
192			     void (*exec_error)(int signo, siginfo_t *info, void *ucontext));
193int evlist__start_workload(struct evlist *evlist);
 
194
195struct option;
196
197int __evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
198int evlist__parse_mmap_pages(const struct option *opt, const char *str, int unset);
199
200unsigned long perf_event_mlock_kb_in_pages(void);
201
202int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
203			 unsigned int auxtrace_pages,
204			 bool auxtrace_overwrite, int nr_cblocks,
205			 int affinity, int flush, int comp_level);
206int evlist__mmap(struct evlist *evlist, unsigned int pages);
207void evlist__munmap(struct evlist *evlist);
208
209size_t evlist__mmap_size(unsigned long pages);
210
211void evlist__disable(struct evlist *evlist);
212void evlist__enable(struct evlist *evlist);
213void evlist__toggle_enable(struct evlist *evlist);
214void evlist__disable_evsel(struct evlist *evlist, char *evsel_name);
215void evlist__enable_evsel(struct evlist *evlist, char *evsel_name);
216void evlist__disable_non_dummy(struct evlist *evlist);
217void evlist__enable_non_dummy(struct evlist *evlist);
218
219void evlist__set_selected(struct evlist *evlist, struct evsel *evsel);
220
221int evlist__create_maps(struct evlist *evlist, struct target *target);
222int evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
 
223
224u64 __evlist__combined_sample_type(struct evlist *evlist);
225u64 evlist__combined_sample_type(struct evlist *evlist);
226u64 evlist__combined_branch_type(struct evlist *evlist);
 
227bool evlist__sample_id_all(struct evlist *evlist);
228u16 evlist__id_hdr_size(struct evlist *evlist);
229
230int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct perf_sample *sample);
231int evlist__parse_sample_timestamp(struct evlist *evlist, union perf_event *event, u64 *timestamp);
232
233bool evlist__valid_sample_type(struct evlist *evlist);
234bool evlist__valid_sample_id_all(struct evlist *evlist);
235bool evlist__valid_read_format(struct evlist *evlist);
236
237void evlist__splice_list_tail(struct evlist *evlist, struct list_head *list);
238
239static inline bool evlist__empty(struct evlist *evlist)
240{
241	return list_empty(&evlist->core.entries);
242}
243
244static inline struct evsel *evlist__first(struct evlist *evlist)
245{
246	struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
247
248	return container_of(evsel, struct evsel, core);
249}
250
251static inline struct evsel *evlist__last(struct evlist *evlist)
252{
253	struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
254
255	return container_of(evsel, struct evsel, core);
256}
257
 
 
 
 
 
258int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
259int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
260
261bool evlist__can_select_event(struct evlist *evlist, const char *str);
262void evlist__to_front(struct evlist *evlist, struct evsel *move_evsel);
263
264/**
265 * __evlist__for_each_entry - iterate thru all the evsels
266 * @list: list_head instance to iterate
267 * @evsel: struct evsel iterator
268 */
269#define __evlist__for_each_entry(list, evsel) \
270        list_for_each_entry(evsel, list, core.node)
271
272/**
273 * evlist__for_each_entry - iterate thru all the evsels
274 * @evlist: evlist instance to iterate
275 * @evsel: struct evsel iterator
276 */
277#define evlist__for_each_entry(evlist, evsel) \
278	__evlist__for_each_entry(&(evlist)->core.entries, evsel)
279
280/**
281 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
282 * @list: list_head instance to iterate
283 * @evsel: struct evsel iterator
284 */
285#define __evlist__for_each_entry_continue(list, evsel) \
286        list_for_each_entry_continue(evsel, list, core.node)
287
288/**
289 * evlist__for_each_entry_continue - continue iteration thru all the evsels
290 * @evlist: evlist instance to iterate
291 * @evsel: struct evsel iterator
292 */
293#define evlist__for_each_entry_continue(evlist, evsel) \
294	__evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
295
296/**
297 * __evlist__for_each_entry_from - continue iteration from @evsel (included)
298 * @list: list_head instance to iterate
299 * @evsel: struct evsel iterator
300 */
301#define __evlist__for_each_entry_from(list, evsel) \
302	list_for_each_entry_from(evsel, list, core.node)
303
304/**
305 * evlist__for_each_entry_from - continue iteration from @evsel (included)
306 * @evlist: evlist instance to iterate
307 * @evsel: struct evsel iterator
308 */
309#define evlist__for_each_entry_from(evlist, evsel) \
310	__evlist__for_each_entry_from(&(evlist)->core.entries, evsel)
311
312/**
313 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
314 * @list: list_head instance to iterate
315 * @evsel: struct evsel iterator
316 */
317#define __evlist__for_each_entry_reverse(list, evsel) \
318        list_for_each_entry_reverse(evsel, list, core.node)
319
320/**
321 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
322 * @evlist: evlist instance to iterate
323 * @evsel: struct evsel iterator
324 */
325#define evlist__for_each_entry_reverse(evlist, evsel) \
326	__evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
327
328/**
329 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
330 * @list: list_head instance to iterate
331 * @tmp: struct evsel temp iterator
332 * @evsel: struct evsel iterator
333 */
334#define __evlist__for_each_entry_safe(list, tmp, evsel) \
335        list_for_each_entry_safe(evsel, tmp, list, core.node)
336
337/**
338 * evlist__for_each_entry_safe - safely iterate thru all the evsels
339 * @evlist: evlist instance to iterate
340 * @evsel: struct evsel iterator
341 * @tmp: struct evsel temp iterator
342 */
343#define evlist__for_each_entry_safe(evlist, tmp, evsel) \
344	__evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
345
346/** Iterator state for evlist__for_each_cpu */
347struct evlist_cpu_iterator {
348	/** The list being iterated through. */
349	struct evlist *container;
350	/** The current evsel of the iterator. */
351	struct evsel *evsel;
352	/** The CPU map index corresponding to the evsel->core.cpus for the current CPU. */
353	int cpu_map_idx;
354	/**
355	 * The CPU map index corresponding to evlist->core.all_cpus for the
356	 * current CPU.  Distinct from cpu_map_idx as the evsel's cpu map may
357	 * contain fewer entries.
358	 */
359	int evlist_cpu_map_idx;
360	/** The number of CPU map entries in evlist->core.all_cpus. */
361	int evlist_cpu_map_nr;
362	/** The current CPU of the iterator. */
363	struct perf_cpu cpu;
364	/** If present, used to set the affinity when switching between CPUs. */
365	struct affinity *affinity;
366};
367
368/**
369 * evlist__for_each_cpu - without affinity, iterate over the evlist. With
370 *                        affinity, iterate over all CPUs and then the evlist
371 *                        for each evsel on that CPU. When switching between
372 *                        CPUs the affinity is set to the CPU to avoid IPIs
373 *                        during syscalls.
374 * @evlist_cpu_itr: the iterator instance.
375 * @evlist: evlist instance to iterate.
376 * @affinity: NULL or used to set the affinity to the current CPU.
377 */
378#define evlist__for_each_cpu(evlist_cpu_itr, evlist, affinity)		\
379	for ((evlist_cpu_itr) = evlist__cpu_begin(evlist, affinity);	\
380	     !evlist_cpu_iterator__end(&evlist_cpu_itr);		\
381	     evlist_cpu_iterator__next(&evlist_cpu_itr))
382
383/** Returns an iterator set to the first CPU/evsel of evlist. */
384struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affinity *affinity);
385/** Move to next element in iterator, updating CPU, evsel and the affinity. */
386void evlist_cpu_iterator__next(struct evlist_cpu_iterator *evlist_cpu_itr);
387/** Returns true when iterator is at the end of the CPUs and evlist. */
388bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu_itr);
389
390struct evsel *evlist__get_tracking_event(struct evlist *evlist);
391void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel);
 
392
393struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
394
395struct evsel *evlist__event2evsel(struct evlist *evlist, union perf_event *event);
396
397bool evlist__exclude_kernel(struct evlist *evlist);
398
399void evlist__force_leader(struct evlist *evlist);
400
401struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evsel, bool close);
402
403#define EVLIST_CTL_CMD_ENABLE_TAG  "enable"
404#define EVLIST_CTL_CMD_DISABLE_TAG "disable"
405#define EVLIST_CTL_CMD_ACK_TAG     "ack\n"
406#define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
407#define EVLIST_CTL_CMD_EVLIST_TAG "evlist"
408#define EVLIST_CTL_CMD_STOP_TAG "stop"
409#define EVLIST_CTL_CMD_PING_TAG "ping"
410
411#define EVLIST_CTL_CMD_MAX_LEN 64
412
413enum evlist_ctl_cmd {
414	EVLIST_CTL_CMD_UNSUPPORTED = 0,
415	EVLIST_CTL_CMD_ENABLE,
416	EVLIST_CTL_CMD_DISABLE,
417	EVLIST_CTL_CMD_ACK,
418	EVLIST_CTL_CMD_SNAPSHOT,
419	EVLIST_CTL_CMD_EVLIST,
420	EVLIST_CTL_CMD_STOP,
421	EVLIST_CTL_CMD_PING,
422};
423
424int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
425void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close);
426int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
427int evlist__finalize_ctlfd(struct evlist *evlist);
428bool evlist__ctlfd_initialized(struct evlist *evlist);
429int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd);
430int evlist__ctlfd_ack(struct evlist *evlist);
431
432#define EVLIST_ENABLED_MSG "Events enabled\n"
433#define EVLIST_DISABLED_MSG "Events disabled\n"
434
435int evlist__parse_event_enable_time(struct evlist *evlist, struct record_opts *opts,
436				    const char *str, int unset);
437int event_enable_timer__start(struct event_enable_timer *eet);
438void event_enable_timer__exit(struct event_enable_timer **ep);
439int event_enable_timer__process(struct event_enable_timer *eet);
440
441struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
442
443int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf);
444void evlist__check_mem_load_aux(struct evlist *evlist);
 
 
 
 
445#endif /* __PERF_EVLIST_H */
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PERF_EVLIST_H
  3#define __PERF_EVLIST_H 1
  4
  5#include <linux/compiler.h>
  6#include <linux/kernel.h>
  7#include <linux/refcount.h>
  8#include <linux/list.h>
  9#include <api/fd/array.h>
 10#include <internal/evlist.h>
 11#include <internal/evsel.h>
 12#include <perf/evlist.h>
 13#include "events_stats.h"
 14#include "evsel.h"
 15#include <pthread.h>
 16#include <signal.h>
 17#include <unistd.h>
 18
 19struct pollfd;
 20struct thread_map;
 21struct perf_cpu_map;
 22struct record_opts;
 23struct target;
 24
 25/*
 26 * State machine of bkw_mmap_state:
 27 *
 28 *                     .________________(forbid)_____________.
 29 *                     |                                     V
 30 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
 31 *                     ^  ^              |   ^               |
 32 *                     |  |__(forbid)____/   |___(forbid)___/|
 33 *                     |                                     |
 34 *                      \_________________(3)_______________/
 35 *
 36 * NOTREADY     : Backward ring buffers are not ready
 37 * RUNNING      : Backward ring buffers are recording
 38 * DATA_PENDING : We are required to collect data from backward ring buffers
 39 * EMPTY        : We have collected data from backward ring buffers.
 40 *
 41 * (0): Setup backward ring buffer
 42 * (1): Pause ring buffers for reading
 43 * (2): Read from ring buffers
 44 * (3): Resume ring buffers for recording
 45 */
 46enum bkw_mmap_state {
 47	BKW_MMAP_NOTREADY,
 48	BKW_MMAP_RUNNING,
 49	BKW_MMAP_DATA_PENDING,
 50	BKW_MMAP_EMPTY,
 51};
 52
 53struct event_enable_timer;
 54
 55struct evlist {
 56	struct perf_evlist core;
 57	bool		 enabled;
 58	int		 id_pos;
 59	int		 is_pos;
 60	int		 nr_br_cntr;
 61	u64		 combined_sample_type;
 62	enum bkw_mmap_state bkw_mmap_state;
 63	struct {
 64		int	cork_fd;
 65		pid_t	pid;
 66	} workload;
 67	struct mmap *mmap;
 68	struct mmap *overwrite_mmap;
 69	struct evsel *selected;
 70	struct events_stats stats;
 71	struct perf_env	*env;
 
 72	void (*trace_event_sample_raw)(struct evlist *evlist,
 73				       union perf_event *event,
 74				       struct perf_sample *sample);
 75	u64		first_sample_time;
 76	u64		last_sample_time;
 77	struct {
 78		pthread_t		th;
 79		volatile int		done;
 80	} thread;
 81	struct {
 82		int	fd;	/* control file descriptor */
 83		int	ack;	/* ack file descriptor for control commands */
 84		int	pos;	/* index at evlist core object to check signals */
 85	} ctl_fd;
 86	struct event_enable_timer *eet;
 87};
 88
 89struct evsel_str_handler {
 90	const char *name;
 91	void	   *handler;
 92};
 93
 94struct evlist *evlist__new(void);
 95struct evlist *evlist__new_default(void);
 96struct evlist *evlist__new_dummy(void);
 97void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
 98		  struct perf_thread_map *threads);
 99void evlist__exit(struct evlist *evlist);
100void evlist__delete(struct evlist *evlist);
101
102void evlist__add(struct evlist *evlist, struct evsel *entry);
103void evlist__remove(struct evlist *evlist, struct evsel *evsel);
104
105int arch_evlist__cmp(const struct evsel *lhs, const struct evsel *rhs);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
107int evlist__add_dummy(struct evlist *evlist);
108struct evsel *evlist__add_aux_dummy(struct evlist *evlist, bool system_wide);
109static inline struct evsel *evlist__add_dummy_on_all_cpus(struct evlist *evlist)
110{
111	return evlist__add_aux_dummy(evlist, true);
112}
113#ifdef HAVE_LIBTRACEEVENT
114struct evsel *evlist__add_sched_switch(struct evlist *evlist, bool system_wide);
115#endif
116
117int evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr,
118			 evsel__sb_cb_t cb, void *data);
119void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
120int evlist__start_sb_thread(struct evlist *evlist, struct target *target);
121void evlist__stop_sb_thread(struct evlist *evlist);
122
123#ifdef HAVE_LIBTRACEEVENT
124int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
125#endif
126
127int __evlist__set_tracepoints_handlers(struct evlist *evlist,
128				       const struct evsel_str_handler *assocs,
129				       size_t nr_assocs);
130
131#define evlist__set_tracepoints_handlers(evlist, array) \
132	__evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
133
134int evlist__set_tp_filter(struct evlist *evlist, const char *filter);
 
135int evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
136
137int evlist__append_tp_filter(struct evlist *evlist, const char *filter);
138
139int evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
140int evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
141
 
142struct evsel *evlist__find_tracepoint_by_name(struct evlist *evlist, const char *name);
143
144int evlist__add_pollfd(struct evlist *evlist, int fd);
145int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
146
147#ifdef HAVE_EVENTFD_SUPPORT
148int evlist__add_wakeup_eventfd(struct evlist *evlist, int fd);
149#endif
150
151int evlist__poll(struct evlist *evlist, int timeout);
152
153struct evsel *evlist__id2evsel(struct evlist *evlist, u64 id);
154struct evsel *evlist__id2evsel_strict(struct evlist *evlist, u64 id);
155
156struct perf_sample_id *evlist__id2sid(struct evlist *evlist, u64 id);
157
158void evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
159
160void evlist__mmap_consume(struct evlist *evlist, int idx);
161
162int evlist__open(struct evlist *evlist);
163void evlist__close(struct evlist *evlist);
164
165struct callchain_param;
166
167void evlist__set_id_pos(struct evlist *evlist);
168void evlist__config(struct evlist *evlist, struct record_opts *opts, struct callchain_param *callchain);
169int record_opts__config(struct record_opts *opts);
170
171int evlist__prepare_workload(struct evlist *evlist, struct target *target,
172			     const char *argv[], bool pipe_output,
173			     void (*exec_error)(int signo, siginfo_t *info, void *ucontext));
174int evlist__start_workload(struct evlist *evlist);
175void evlist__cancel_workload(struct evlist *evlist);
176
177struct option;
178
179int __evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
180int evlist__parse_mmap_pages(const struct option *opt, const char *str, int unset);
181
182unsigned long perf_event_mlock_kb_in_pages(void);
183
184int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
185			 unsigned int auxtrace_pages,
186			 bool auxtrace_overwrite, int nr_cblocks,
187			 int affinity, int flush, int comp_level);
188int evlist__mmap(struct evlist *evlist, unsigned int pages);
189void evlist__munmap(struct evlist *evlist);
190
191size_t evlist__mmap_size(unsigned long pages);
192
193void evlist__disable(struct evlist *evlist);
194void evlist__enable(struct evlist *evlist);
195void evlist__toggle_enable(struct evlist *evlist);
196void evlist__disable_evsel(struct evlist *evlist, char *evsel_name);
197void evlist__enable_evsel(struct evlist *evlist, char *evsel_name);
198void evlist__disable_non_dummy(struct evlist *evlist);
199void evlist__enable_non_dummy(struct evlist *evlist);
200
201void evlist__set_selected(struct evlist *evlist, struct evsel *evsel);
202
203int evlist__create_maps(struct evlist *evlist, struct target *target);
204int evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel,
205			  struct target *target);
206
207u64 __evlist__combined_sample_type(struct evlist *evlist);
208u64 evlist__combined_sample_type(struct evlist *evlist);
209u64 evlist__combined_branch_type(struct evlist *evlist);
210void evlist__update_br_cntr(struct evlist *evlist);
211bool evlist__sample_id_all(struct evlist *evlist);
212u16 evlist__id_hdr_size(struct evlist *evlist);
213
214int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct perf_sample *sample);
215int evlist__parse_sample_timestamp(struct evlist *evlist, union perf_event *event, u64 *timestamp);
216
217bool evlist__valid_sample_type(struct evlist *evlist);
218bool evlist__valid_sample_id_all(struct evlist *evlist);
219bool evlist__valid_read_format(struct evlist *evlist);
220
221void evlist__splice_list_tail(struct evlist *evlist, struct list_head *list);
222
223static inline bool evlist__empty(struct evlist *evlist)
224{
225	return list_empty(&evlist->core.entries);
226}
227
228static inline struct evsel *evlist__first(struct evlist *evlist)
229{
230	struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
231
232	return container_of(evsel, struct evsel, core);
233}
234
235static inline struct evsel *evlist__last(struct evlist *evlist)
236{
237	struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
238
239	return container_of(evsel, struct evsel, core);
240}
241
242static inline int evlist__nr_groups(struct evlist *evlist)
243{
244	return perf_evlist__nr_groups(&evlist->core);
245}
246
247int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
248int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
249
250bool evlist__can_select_event(struct evlist *evlist, const char *str);
251void evlist__to_front(struct evlist *evlist, struct evsel *move_evsel);
252
253/**
254 * __evlist__for_each_entry - iterate thru all the evsels
255 * @list: list_head instance to iterate
256 * @evsel: struct evsel iterator
257 */
258#define __evlist__for_each_entry(list, evsel) \
259        list_for_each_entry(evsel, list, core.node)
260
261/**
262 * evlist__for_each_entry - iterate thru all the evsels
263 * @evlist: evlist instance to iterate
264 * @evsel: struct evsel iterator
265 */
266#define evlist__for_each_entry(evlist, evsel) \
267	__evlist__for_each_entry(&(evlist)->core.entries, evsel)
268
269/**
270 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
271 * @list: list_head instance to iterate
272 * @evsel: struct evsel iterator
273 */
274#define __evlist__for_each_entry_continue(list, evsel) \
275        list_for_each_entry_continue(evsel, list, core.node)
276
277/**
278 * evlist__for_each_entry_continue - continue iteration thru all the evsels
279 * @evlist: evlist instance to iterate
280 * @evsel: struct evsel iterator
281 */
282#define evlist__for_each_entry_continue(evlist, evsel) \
283	__evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
284
285/**
286 * __evlist__for_each_entry_from - continue iteration from @evsel (included)
287 * @list: list_head instance to iterate
288 * @evsel: struct evsel iterator
289 */
290#define __evlist__for_each_entry_from(list, evsel) \
291	list_for_each_entry_from(evsel, list, core.node)
292
293/**
294 * evlist__for_each_entry_from - continue iteration from @evsel (included)
295 * @evlist: evlist instance to iterate
296 * @evsel: struct evsel iterator
297 */
298#define evlist__for_each_entry_from(evlist, evsel) \
299	__evlist__for_each_entry_from(&(evlist)->core.entries, evsel)
300
301/**
302 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
303 * @list: list_head instance to iterate
304 * @evsel: struct evsel iterator
305 */
306#define __evlist__for_each_entry_reverse(list, evsel) \
307        list_for_each_entry_reverse(evsel, list, core.node)
308
309/**
310 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
311 * @evlist: evlist instance to iterate
312 * @evsel: struct evsel iterator
313 */
314#define evlist__for_each_entry_reverse(evlist, evsel) \
315	__evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
316
317/**
318 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
319 * @list: list_head instance to iterate
320 * @tmp: struct evsel temp iterator
321 * @evsel: struct evsel iterator
322 */
323#define __evlist__for_each_entry_safe(list, tmp, evsel) \
324        list_for_each_entry_safe(evsel, tmp, list, core.node)
325
326/**
327 * evlist__for_each_entry_safe - safely iterate thru all the evsels
328 * @evlist: evlist instance to iterate
329 * @evsel: struct evsel iterator
330 * @tmp: struct evsel temp iterator
331 */
332#define evlist__for_each_entry_safe(evlist, tmp, evsel) \
333	__evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
334
335/** Iterator state for evlist__for_each_cpu */
336struct evlist_cpu_iterator {
337	/** The list being iterated through. */
338	struct evlist *container;
339	/** The current evsel of the iterator. */
340	struct evsel *evsel;
341	/** The CPU map index corresponding to the evsel->core.cpus for the current CPU. */
342	int cpu_map_idx;
343	/**
344	 * The CPU map index corresponding to evlist->core.all_cpus for the
345	 * current CPU.  Distinct from cpu_map_idx as the evsel's cpu map may
346	 * contain fewer entries.
347	 */
348	int evlist_cpu_map_idx;
349	/** The number of CPU map entries in evlist->core.all_cpus. */
350	int evlist_cpu_map_nr;
351	/** The current CPU of the iterator. */
352	struct perf_cpu cpu;
353	/** If present, used to set the affinity when switching between CPUs. */
354	struct affinity *affinity;
355};
356
357/**
358 * evlist__for_each_cpu - without affinity, iterate over the evlist. With
359 *                        affinity, iterate over all CPUs and then the evlist
360 *                        for each evsel on that CPU. When switching between
361 *                        CPUs the affinity is set to the CPU to avoid IPIs
362 *                        during syscalls.
363 * @evlist_cpu_itr: the iterator instance.
364 * @evlist: evlist instance to iterate.
365 * @affinity: NULL or used to set the affinity to the current CPU.
366 */
367#define evlist__for_each_cpu(evlist_cpu_itr, evlist, affinity)		\
368	for ((evlist_cpu_itr) = evlist__cpu_begin(evlist, affinity);	\
369	     !evlist_cpu_iterator__end(&evlist_cpu_itr);		\
370	     evlist_cpu_iterator__next(&evlist_cpu_itr))
371
372/** Returns an iterator set to the first CPU/evsel of evlist. */
373struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affinity *affinity);
374/** Move to next element in iterator, updating CPU, evsel and the affinity. */
375void evlist_cpu_iterator__next(struct evlist_cpu_iterator *evlist_cpu_itr);
376/** Returns true when iterator is at the end of the CPUs and evlist. */
377bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu_itr);
378
379struct evsel *evlist__get_tracking_event(struct evlist *evlist);
380void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel);
381struct evsel *evlist__findnew_tracking_event(struct evlist *evlist, bool system_wide);
382
383struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
384
385struct evsel *evlist__event2evsel(struct evlist *evlist, union perf_event *event);
386
387bool evlist__exclude_kernel(struct evlist *evlist);
388
389void evlist__force_leader(struct evlist *evlist);
390
391struct evsel *evlist__reset_weak_group(struct evlist *evlist, struct evsel *evsel, bool close);
392
393#define EVLIST_CTL_CMD_ENABLE_TAG  "enable"
394#define EVLIST_CTL_CMD_DISABLE_TAG "disable"
395#define EVLIST_CTL_CMD_ACK_TAG     "ack\n"
396#define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
397#define EVLIST_CTL_CMD_EVLIST_TAG "evlist"
398#define EVLIST_CTL_CMD_STOP_TAG "stop"
399#define EVLIST_CTL_CMD_PING_TAG "ping"
400
401#define EVLIST_CTL_CMD_MAX_LEN 64
402
403enum evlist_ctl_cmd {
404	EVLIST_CTL_CMD_UNSUPPORTED = 0,
405	EVLIST_CTL_CMD_ENABLE,
406	EVLIST_CTL_CMD_DISABLE,
407	EVLIST_CTL_CMD_ACK,
408	EVLIST_CTL_CMD_SNAPSHOT,
409	EVLIST_CTL_CMD_EVLIST,
410	EVLIST_CTL_CMD_STOP,
411	EVLIST_CTL_CMD_PING,
412};
413
414int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
415void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close);
416int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
417int evlist__finalize_ctlfd(struct evlist *evlist);
418bool evlist__ctlfd_initialized(struct evlist *evlist);
419int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd);
420int evlist__ctlfd_ack(struct evlist *evlist);
421
422#define EVLIST_ENABLED_MSG "Events enabled\n"
423#define EVLIST_DISABLED_MSG "Events disabled\n"
424
425int evlist__parse_event_enable_time(struct evlist *evlist, struct record_opts *opts,
426				    const char *str, int unset);
427int event_enable_timer__start(struct event_enable_timer *eet);
428void event_enable_timer__exit(struct event_enable_timer **ep);
429int event_enable_timer__process(struct event_enable_timer *eet);
430
431struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
432
433int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf);
434void evlist__check_mem_load_aux(struct evlist *evlist);
435void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_list);
436void evlist__uniquify_name(struct evlist *evlist);
437bool evlist__has_bpf_output(struct evlist *evlist);
438
439#endif /* __PERF_EVLIST_H */