Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / util / evlist.h
blobc73f7f7f120b64afa554df33e7205abc6effad45
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"
13 #include "evsel.h"
14 #include <pthread.h>
15 #include <signal.h>
16 #include <unistd.h>
18 struct pollfd;
19 struct thread_map;
20 struct perf_cpu_map;
21 struct record_opts;
24 * State machine of bkw_mmap_state:
26 * .________________(forbid)_____________.
27 * | V
28 * NOTREADY --(0)--> RUNNING --(1)--> DATA_PENDING --(2)--> EMPTY
29 * ^ ^ | ^ |
30 * | |__(forbid)____/ |___(forbid)___/|
31 * | |
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
44 enum bkw_mmap_state {
45 BKW_MMAP_NOTREADY,
46 BKW_MMAP_RUNNING,
47 BKW_MMAP_DATA_PENDING,
48 BKW_MMAP_EMPTY,
51 struct evlist {
52 struct perf_evlist core;
53 int nr_groups;
54 bool enabled;
55 int id_pos;
56 int is_pos;
57 u64 combined_sample_type;
58 enum bkw_mmap_state bkw_mmap_state;
59 struct {
60 int cork_fd;
61 pid_t pid;
62 } workload;
63 struct mmap *mmap;
64 struct mmap *overwrite_mmap;
65 struct evsel *selected;
66 struct events_stats stats;
67 struct perf_env *env;
68 void (*trace_event_sample_raw)(struct evlist *evlist,
69 union perf_event *event,
70 struct perf_sample *sample);
71 u64 first_sample_time;
72 u64 last_sample_time;
73 struct {
74 pthread_t th;
75 volatile int done;
76 } thread;
77 struct {
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 */
81 } ctl_fd;
84 struct evsel_str_handler {
85 const char *name;
86 void *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 perf_evlist__add_sb_event(struct evlist *evlist,
116 struct perf_event_attr *attr,
117 evsel__sb_cb_t cb,
118 void *data);
119 void evlist__set_cb(struct evlist *evlist, evsel__sb_cb_t cb, void *data);
120 int perf_evlist__start_sb_thread(struct evlist *evlist,
121 struct target *target);
122 void perf_evlist__stop_sb_thread(struct evlist *evlist);
124 int evlist__add_newtp(struct evlist *evlist, const char *sys, const char *name, void *handler);
126 int __evlist__set_tracepoints_handlers(struct evlist *evlist,
127 const struct evsel_str_handler *assocs,
128 size_t nr_assocs);
130 #define evlist__set_tracepoints_handlers(evlist, array) \
131 __evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array))
133 void __perf_evlist__set_sample_bit(struct evlist *evlist,
134 enum perf_event_sample_format bit);
135 void __perf_evlist__reset_sample_bit(struct evlist *evlist,
136 enum perf_event_sample_format bit);
138 #define perf_evlist__set_sample_bit(evlist, bit) \
139 __perf_evlist__set_sample_bit(evlist, PERF_SAMPLE_##bit)
141 #define perf_evlist__reset_sample_bit(evlist, bit) \
142 __perf_evlist__reset_sample_bit(evlist, PERF_SAMPLE_##bit)
144 int perf_evlist__set_tp_filter(struct evlist *evlist, const char *filter);
145 int perf_evlist__set_tp_filter_pid(struct evlist *evlist, pid_t pid);
146 int perf_evlist__set_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
148 int perf_evlist__append_tp_filter(struct evlist *evlist, const char *filter);
150 int perf_evlist__append_tp_filter_pid(struct evlist *evlist, pid_t pid);
151 int perf_evlist__append_tp_filter_pids(struct evlist *evlist, size_t npids, pid_t *pids);
153 struct evsel *
154 perf_evlist__find_tracepoint_by_id(struct evlist *evlist, int id);
156 struct evsel *
157 perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
158 const char *name);
160 int evlist__add_pollfd(struct evlist *evlist, int fd);
161 int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
163 int evlist__poll(struct evlist *evlist, int timeout);
165 struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
166 struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
167 u64 id);
169 struct perf_sample_id *perf_evlist__id2sid(struct evlist *evlist, u64 id);
171 void perf_evlist__toggle_bkw_mmap(struct evlist *evlist, enum bkw_mmap_state state);
173 void evlist__mmap_consume(struct evlist *evlist, int idx);
175 int evlist__open(struct evlist *evlist);
176 void evlist__close(struct evlist *evlist);
178 struct callchain_param;
180 void perf_evlist__set_id_pos(struct evlist *evlist);
181 void perf_evlist__config(struct evlist *evlist, struct record_opts *opts,
182 struct callchain_param *callchain);
183 int record_opts__config(struct record_opts *opts);
185 int perf_evlist__prepare_workload(struct evlist *evlist,
186 struct target *target,
187 const char *argv[], bool pipe_output,
188 void (*exec_error)(int signo, siginfo_t *info,
189 void *ucontext));
190 int perf_evlist__start_workload(struct evlist *evlist);
192 struct option;
194 int __perf_evlist__parse_mmap_pages(unsigned int *mmap_pages, const char *str);
195 int perf_evlist__parse_mmap_pages(const struct option *opt,
196 const char *str,
197 int unset);
199 unsigned long perf_event_mlock_kb_in_pages(void);
201 int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
202 unsigned int auxtrace_pages,
203 bool auxtrace_overwrite, int nr_cblocks,
204 int affinity, int flush, int comp_level);
205 int evlist__mmap(struct evlist *evlist, unsigned int pages);
206 void evlist__munmap(struct evlist *evlist);
208 size_t evlist__mmap_size(unsigned long pages);
210 void evlist__disable(struct evlist *evlist);
211 void evlist__enable(struct evlist *evlist);
212 void perf_evlist__toggle_enable(struct evlist *evlist);
214 int perf_evlist__enable_event_idx(struct evlist *evlist,
215 struct evsel *evsel, int idx);
217 void perf_evlist__set_selected(struct evlist *evlist,
218 struct evsel *evsel);
220 int perf_evlist__create_maps(struct evlist *evlist, struct target *target);
221 int perf_evlist__apply_filters(struct evlist *evlist, struct evsel **err_evsel);
223 void __perf_evlist__set_leader(struct list_head *list);
224 void perf_evlist__set_leader(struct evlist *evlist);
226 u64 __evlist__combined_sample_type(struct evlist *evlist);
227 u64 evlist__combined_sample_type(struct evlist *evlist);
228 u64 evlist__combined_branch_type(struct evlist *evlist);
229 bool evlist__sample_id_all(struct evlist *evlist);
230 u16 perf_evlist__id_hdr_size(struct evlist *evlist);
232 int perf_evlist__parse_sample(struct evlist *evlist, union perf_event *event,
233 struct perf_sample *sample);
235 int perf_evlist__parse_sample_timestamp(struct evlist *evlist,
236 union perf_event *event,
237 u64 *timestamp);
239 bool evlist__valid_sample_type(struct evlist *evlist);
240 bool evlist__valid_sample_id_all(struct evlist *evlist);
241 bool perf_evlist__valid_read_format(struct evlist *evlist);
243 void perf_evlist__splice_list_tail(struct evlist *evlist,
244 struct list_head *list);
246 static inline bool perf_evlist__empty(struct evlist *evlist)
248 return list_empty(&evlist->core.entries);
251 static inline struct evsel *evlist__first(struct evlist *evlist)
253 struct perf_evsel *evsel = perf_evlist__first(&evlist->core);
255 return container_of(evsel, struct evsel, core);
258 static inline struct evsel *evlist__last(struct evlist *evlist)
260 struct perf_evsel *evsel = perf_evlist__last(&evlist->core);
262 return container_of(evsel, struct evsel, core);
265 int evlist__strerror_open(struct evlist *evlist, int err, char *buf, size_t size);
266 int evlist__strerror_mmap(struct evlist *evlist, int err, char *buf, size_t size);
268 bool perf_evlist__can_select_event(struct evlist *evlist, const char *str);
269 void perf_evlist__to_front(struct evlist *evlist,
270 struct evsel *move_evsel);
273 * __evlist__for_each_entry - iterate thru all the evsels
274 * @list: list_head instance to iterate
275 * @evsel: struct evsel iterator
277 #define __evlist__for_each_entry(list, evsel) \
278 list_for_each_entry(evsel, list, core.node)
281 * evlist__for_each_entry - iterate thru all the evsels
282 * @evlist: evlist instance to iterate
283 * @evsel: struct evsel iterator
285 #define evlist__for_each_entry(evlist, evsel) \
286 __evlist__for_each_entry(&(evlist)->core.entries, evsel)
289 * __evlist__for_each_entry_continue - continue iteration thru all the evsels
290 * @list: list_head instance to iterate
291 * @evsel: struct evsel iterator
293 #define __evlist__for_each_entry_continue(list, evsel) \
294 list_for_each_entry_continue(evsel, list, core.node)
297 * evlist__for_each_entry_continue - continue iteration thru all the evsels
298 * @evlist: evlist instance to iterate
299 * @evsel: struct evsel iterator
301 #define evlist__for_each_entry_continue(evlist, evsel) \
302 __evlist__for_each_entry_continue(&(evlist)->core.entries, evsel)
305 * __evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
306 * @list: list_head instance to iterate
307 * @evsel: struct evsel iterator
309 #define __evlist__for_each_entry_reverse(list, evsel) \
310 list_for_each_entry_reverse(evsel, list, core.node)
313 * evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
314 * @evlist: evlist instance to iterate
315 * @evsel: struct evsel iterator
317 #define evlist__for_each_entry_reverse(evlist, evsel) \
318 __evlist__for_each_entry_reverse(&(evlist)->core.entries, evsel)
321 * __evlist__for_each_entry_safe - safely iterate thru all the evsels
322 * @list: list_head instance to iterate
323 * @tmp: struct evsel temp iterator
324 * @evsel: struct evsel iterator
326 #define __evlist__for_each_entry_safe(list, tmp, evsel) \
327 list_for_each_entry_safe(evsel, tmp, list, core.node)
330 * evlist__for_each_entry_safe - safely iterate thru all the evsels
331 * @evlist: evlist instance to iterate
332 * @evsel: struct evsel iterator
333 * @tmp: struct evsel temp iterator
335 #define evlist__for_each_entry_safe(evlist, tmp, evsel) \
336 __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel)
338 #define evlist__for_each_cpu(evlist, index, cpu) \
339 evlist__cpu_iter_start(evlist); \
340 perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus)
342 struct evsel *perf_evlist__get_tracking_event(struct evlist *evlist);
343 void perf_evlist__set_tracking_event(struct evlist *evlist,
344 struct evsel *tracking_evsel);
346 void evlist__cpu_iter_start(struct evlist *evlist);
347 bool evsel__cpu_iter_skip(struct evsel *ev, int cpu);
348 bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu);
350 struct evsel *
351 perf_evlist__find_evsel_by_str(struct evlist *evlist, const char *str);
353 struct evsel *perf_evlist__event2evsel(struct evlist *evlist,
354 union perf_event *event);
356 bool perf_evlist__exclude_kernel(struct evlist *evlist);
358 void perf_evlist__force_leader(struct evlist *evlist);
360 struct evsel *perf_evlist__reset_weak_group(struct evlist *evlist,
361 struct evsel *evsel,
362 bool close);
363 #define EVLIST_CTL_CMD_ENABLE_TAG "enable"
364 #define EVLIST_CTL_CMD_DISABLE_TAG "disable"
365 #define EVLIST_CTL_CMD_ACK_TAG "ack\n"
367 #define EVLIST_CTL_CMD_MAX_LEN 64
369 enum evlist_ctl_cmd {
370 EVLIST_CTL_CMD_UNSUPPORTED = 0,
371 EVLIST_CTL_CMD_ENABLE,
372 EVLIST_CTL_CMD_DISABLE,
373 EVLIST_CTL_CMD_ACK
376 int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
377 int evlist__finalize_ctlfd(struct evlist *evlist);
378 bool evlist__ctlfd_initialized(struct evlist *evlist);
379 int evlist__ctlfd_process(struct evlist *evlist, enum evlist_ctl_cmd *cmd);
381 #define EVLIST_ENABLED_MSG "Events enabled\n"
382 #define EVLIST_DISABLED_MSG "Events disabled\n"
384 #endif /* __PERF_EVLIST_H */