1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_EVLIST_H
3 #define __PERF_EVLIST_H 1
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"
24 * State machine of bkw_mmap_state:
26 * .________________(forbid)_____________.
28 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
30 * | |__(forbid)____/ |___(forbid)___/|
32 * \_________________(3)_______________/
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.
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
47 BKW_MMAP_DATA_PENDING,
52 struct perf_evlist core;
57 u64 combined_sample_type;
58 enum bkw_mmap_state bkw_mmap_state;
64 struct mmap *overwrite_mmap;
65 struct evsel *selected;
66 struct events_stats stats;
68 void (*trace_event_sample_raw)(struct evlist *evlist,
69 union perf_event *event,
70 struct perf_sample *sample);
71 u64 first_sample_time;
78 int fd; /* control file descriptor */
79 int ack; /* ack file descriptor for control commands */
80 int pos; /* index at evlist core object to check signals */
84 struct evsel_str_handler {
89 struct evlist *evlist__new(void);
90 struct evlist *perf_evlist__new_default(void);
91 struct evlist *perf_evlist__new_dummy(void);
92 void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
93 struct perf_thread_map *threads);
94 void evlist__exit(struct evlist *evlist);
95 void evlist__delete(struct evlist *evlist);
97 void evlist__add(struct evlist *evlist, struct evsel *entry);
98 void evlist__remove(struct evlist *evlist, struct evsel *evsel);
100 int __evlist__add_default(struct evlist *evlist, bool precise);
102 static inline int evlist__add_default(struct evlist *evlist)
104 return __evlist__add_default(evlist, true);
107 int __evlist__add_default_attrs(struct evlist *evlist,
108 struct perf_event_attr *attrs, size_t nr_attrs);
110 #define evlist__add_default_attrs(evlist, array) \
111 __evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array))
113 int evlist__add_dummy(struct evlist *evlist);
115 int evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr,
116 evsel__sb_cb_t cb, void *data);
117 void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
118 int evlist__start_sb_thread(struct evlist *evlist, struct target *target);
119 void evlist__stop_sb_thread(struct evlist *evlist);
121 int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
123 int __evlist__set_tracepoints_handlers(struct evlist *evlist,
124 const struct evsel_str_handler *assocs,
127 #define evlist__set_tracepoints_handlers(evlist, array) \
128 __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
130 void __perf_evlist__set_sample_bit(struct evlist *evlist,
131 enum perf_event_sample_format bit);
132 void __perf_evlist__reset_sample_bit(struct evlist *evlist,
133 enum perf_event_sample_format bit);
135 #define perf_evlist__set_sample_bit(evlist, bit) \
136 __perf_evlist__set_sample_bit(evlist, PERF_SAMPLE_##bit)
138 #define perf_evlist__reset_sample_bit(evlist, bit) \
139 __perf_evlist__reset_sample_bit(evlist, PERF_SAMPLE_##bit)
141 int evlist__set_tp_filter(struct evlist *evlist, const char *filter);
142 int evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
143 int evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
145 int evlist__append_tp_filter(struct evlist *evlist, const char *filter);
147 int evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
148 int evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
151 perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
154 perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
157 int evlist__add_pollfd(struct evlist *evlist, int fd);
158 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
160 int evlist__poll(struct evlist *evlist, int timeout);
162 struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
163 struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
166 struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id);
168 void evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
170 void evlist__mmap_consume(struct evlist *evlist, int idx);
172 int evlist__open(struct evlist *evlist);
173 void evlist__close(struct evlist *evlist);
175 struct callchain_param;
177 void perf_evlist__set_id_pos(struct evlist *evlist);
178 void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
179 struct callchain_param *callchain);
180 int record_opts__config(struct record_opts *opts);
182 int evlist__prepare_workload(struct evlist *evlist, struct target *target,
183 const char *argv[], bool pipe_output,
184 void (*exec_error)(int signo, siginfo_t *info, void *ucontext));
185 int evlist__start_workload(struct evlist *evlist);
189 int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
190 int perf_evlist__parse_mmap_pages(const struct option *opt,
194 unsigned long perf_event_mlock_kb_in_pages(void);
196 int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
197 unsigned int auxtrace_pages,
198 bool auxtrace_overwrite, int nr_cblocks,
199 int affinity, int flush, int comp_level);
200 int evlist__mmap(struct evlist *evlist, unsigned int pages);
201 void evlist__munmap(struct evlist *evlist);
203 size_t evlist__mmap_size(unsigned long pages);
205 void evlist__disable(struct evlist *evlist);
206 void evlist__enable(struct evlist *evlist);
207 void evlist__toggle_enable(struct evlist *evlist);
209 int perf_evlist__enable_event_idx(struct evlist *evlist,
210 struct evsel *evsel, int idx);
212 void perf_evlist__set_selected(struct evlist *evlist,
213 struct evsel *evsel);
215 int perf_evlist__create_maps(struct evlist *evlist, struct target *target);
216 int evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
218 void __evlist__set_leader(struct list_head *list);
219 void evlist__set_leader(struct evlist *evlist);
221 u64 __evlist__combined_sample_type(struct evlist *evlist);
222 u64 evlist__combined_sample_type(struct evlist *evlist);
223 u64 evlist__combined_branch_type(struct evlist *evlist);
224 bool evlist__sample_id_all(struct evlist *evlist);
225 u16 perf_evlist__id_hdr_size(struct evlist *evlist);
227 int perf_evlist__parse_sample(struct evlist *evlist, union perf_event *event,
228 struct perf_sample *sample);
230 int perf_evlist__parse_sample_timestamp(struct evlist *evlist,
231 union perf_event *event,
234 bool evlist__valid_sample_type(struct evlist *evlist);
235 bool evlist__valid_sample_id_all(struct evlist *evlist);
236 bool perf_evlist__valid_read_format(struct evlist *evlist);
238 void perf_evlist__splice_list_tail(struct evlist *evlist,
239 struct list_head *list);
241 static inline bool perf_evlist__empty(struct evlist *evlist)
243 return list_empty(&evlist->core.entries);
246 static inline struct evsel *evlist__first(struct evlist *evlist)
248 struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
250 return container_of(evsel, struct evsel, core);
253 static inline struct evsel *evlist__last(struct evlist *evlist)
255 struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
257 return container_of(evsel, struct evsel, core);
260 int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
261 int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
263 bool perf_evlist__can_select_event(struct evlist *evlist, const char *str);
264 void perf_evlist__to_front(struct evlist *evlist,
265 struct evsel *move_evsel);
268 * __evlist__for_each_entry - iterate thru all the evsels
269 * @list: list_head instance to iterate
270 * @evsel: struct evsel iterator
272 #define __evlist__for_each_entry(list, evsel) \
273 list_for_each_entry(evsel, list, core.node)
276 * evlist__for_each_entry - iterate thru all the evsels
277 * @evlist: evlist instance to iterate
278 * @evsel: struct evsel iterator
280 #define evlist__for_each_entry(evlist, evsel) \
281 __evlist__for_each_entry(&(evlist)->core.entries, evsel)
284 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
285 * @list: list_head instance to iterate
286 * @evsel: struct evsel iterator
288 #define __evlist__for_each_entry_continue(list, evsel) \
289 list_for_each_entry_continue(evsel, list, core.node)
292 * evlist__for_each_entry_continue - continue iteration thru all the evsels
293 * @evlist: evlist instance to iterate
294 * @evsel: struct evsel iterator
296 #define evlist__for_each_entry_continue(evlist, evsel) \
297 __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
300 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
301 * @list: list_head instance to iterate
302 * @evsel: struct evsel iterator
304 #define __evlist__for_each_entry_reverse(list, evsel) \
305 list_for_each_entry_reverse(evsel, list, core.node)
308 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
309 * @evlist: evlist instance to iterate
310 * @evsel: struct evsel iterator
312 #define evlist__for_each_entry_reverse(evlist, evsel) \
313 __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
316 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
317 * @list: list_head instance to iterate
318 * @tmp: struct evsel temp iterator
319 * @evsel: struct evsel iterator
321 #define __evlist__for_each_entry_safe(list, tmp, evsel) \
322 list_for_each_entry_safe(evsel, tmp, list, core.node)
325 * evlist__for_each_entry_safe - safely iterate thru all the evsels
326 * @evlist: evlist instance to iterate
327 * @evsel: struct evsel iterator
328 * @tmp: struct evsel temp iterator
330 #define evlist__for_each_entry_safe(evlist, tmp, evsel) \
331 __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
333 #define evlist__for_each_cpu(evlist, index, cpu) \
334 evlist__cpu_iter_start(evlist); \
335 perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
337 struct evsel *perf_evlist__get_tracking_event(struct evlist *evlist);
338 void perf_evlist__set_tracking_event(struct evlist *evlist,
339 struct evsel *tracking_evsel);
341 void evlist__cpu_iter_start(struct evlist *evlist);
342 bool evsel__cpu_iter_skip(struct evsel *ev, int cpu);
343 bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu);
346 perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
348 struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
349 union perf_event *event);
351 bool perf_evlist__exclude_kernel(struct evlist *evlist);
353 void perf_evlist__force_leader(struct evlist *evlist);
355 struct evsel *perf_evlist__reset_weak_group(struct evlist *evlist,
358 #define EVLIST_CTL_CMD_ENABLE_TAG "enable"
359 #define EVLIST_CTL_CMD_DISABLE_TAG "disable"
360 #define EVLIST_CTL_CMD_ACK_TAG "ack\n"
361 #define EVLIST_CTL_CMD_SNAPSHOT_TAG "snapshot"
363 #define EVLIST_CTL_CMD_MAX_LEN 64
365 enum evlist_ctl_cmd {
366 EVLIST_CTL_CMD_UNSUPPORTED = 0,
367 EVLIST_CTL_CMD_ENABLE,
368 EVLIST_CTL_CMD_DISABLE,
370 EVLIST_CTL_CMD_SNAPSHOT,
373 int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
374 void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close);
375 int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
376 int evlist__finalize_ctlfd(struct evlist *evlist);
377 bool evlist__ctlfd_initialized(struct evlist *evlist);
378 int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd);
379 int evlist__ctlfd_ack(struct evlist *evlist);
381 #define EVLIST_ENABLED_MSG "Events enabled\n"
382 #define EVLIST_DISABLED_MSG "Events disabled\n"
384 struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
385 #endif /* __PERF_EVLIST_H */