1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBPERF_INTERNAL_EVLIST_H
3 #define __LIBPERF_INTERNAL_EVLIST_H
4 
5 #include <linux/list.h>
6 #include <api/fd/array.h>
7 #include <internal/cpumap.h>
8 #include <internal/evsel.h>
9 
10 #define PERF_EVLIST__HLIST_BITS 8
11 #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
12 
13 struct perf_cpu_map;
14 struct perf_thread_map;
15 struct perf_mmap_param;
16 
17 struct perf_evlist {
18 	struct list_head	 entries;
19 	int			 nr_entries;
20 	bool			 has_user_cpus;
21 	bool			 needs_map_propagation;
22 	/**
23 	 * The cpus passed from the command line or all online CPUs by
24 	 * default.
25 	 */
26 	struct perf_cpu_map	*user_requested_cpus;
27 	/** The union of all evsel cpu maps. */
28 	struct perf_cpu_map	*all_cpus;
29 	struct perf_thread_map	*threads;
30 	int			 nr_mmaps;
31 	size_t			 mmap_len;
32 	struct fdarray		 pollfd;
33 	struct hlist_head	 heads[PERF_EVLIST__HLIST_SIZE];
34 	struct perf_mmap	*mmap;
35 	struct perf_mmap	*mmap_ovw;
36 	struct perf_mmap	*mmap_first;
37 	struct perf_mmap	*mmap_ovw_first;
38 };
39 
40 typedef void
41 (*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_evsel*,
42 			      struct perf_mmap_param*, int);
43 typedef struct perf_mmap*
44 (*perf_evlist_mmap__cb_get_t)(struct perf_evlist*, bool, int);
45 typedef int
46 (*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, int, struct perf_cpu);
47 
48 struct perf_evlist_mmap_ops {
49 	perf_evlist_mmap__cb_idx_t	idx;
50 	perf_evlist_mmap__cb_get_t	get;
51 	perf_evlist_mmap__cb_mmap_t	mmap;
52 };
53 
54 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
55 int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
56 			    void *ptr, short revent, enum fdarray_flags flags);
57 
58 int perf_evlist__mmap_ops(struct perf_evlist *evlist,
59 			  struct perf_evlist_mmap_ops *ops,
60 			  struct perf_mmap_param *mp);
61 
62 void perf_evlist__init(struct perf_evlist *evlist);
63 void perf_evlist__exit(struct perf_evlist *evlist);
64 
65 /**
66  * __perf_evlist__for_each_entry - iterate thru all the evsels
67  * @list: list_head instance to iterate
68  * @evsel: struct perf_evsel iterator
69  */
70 #define __perf_evlist__for_each_entry(list, evsel) \
71 	list_for_each_entry(evsel, list, node)
72 
73 /**
74  * evlist__for_each_entry - iterate thru all the evsels
75  * @evlist: perf_evlist instance to iterate
76  * @evsel: struct perf_evsel iterator
77  */
78 #define perf_evlist__for_each_entry(evlist, evsel) \
79 	__perf_evlist__for_each_entry(&(evlist)->entries, evsel)
80 
81 /**
82  * __perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
83  * @list: list_head instance to iterate
84  * @evsel: struct evsel iterator
85  */
86 #define __perf_evlist__for_each_entry_reverse(list, evsel) \
87 	list_for_each_entry_reverse(evsel, list, node)
88 
89 /**
90  * perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
91  * @evlist: evlist instance to iterate
92  * @evsel: struct evsel iterator
93  */
94 #define perf_evlist__for_each_entry_reverse(evlist, evsel) \
95 	__perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
96 
97 /**
98  * __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
99  * @list: list_head instance to iterate
100  * @tmp: struct evsel temp iterator
101  * @evsel: struct evsel iterator
102  */
103 #define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \
104 	list_for_each_entry_safe(evsel, tmp, list, node)
105 
106 /**
107  * perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
108  * @evlist: evlist instance to iterate
109  * @evsel: struct evsel iterator
110  * @tmp: struct evsel temp iterator
111  */
112 #define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \
113 	__perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel)
114 
perf_evlist__first(struct perf_evlist * evlist)115 static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist)
116 {
117 	return list_entry(evlist->entries.next, struct perf_evsel, node);
118 }
119 
perf_evlist__last(struct perf_evlist * evlist)120 static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist)
121 {
122 	return list_entry(evlist->entries.prev, struct perf_evsel, node);
123 }
124 
125 u64 perf_evlist__read_format(struct perf_evlist *evlist);
126 
127 void perf_evlist__id_add(struct perf_evlist *evlist,
128 			 struct perf_evsel *evsel,
129 			 int cpu_map_idx, int thread, u64 id);
130 
131 int perf_evlist__id_add_fd(struct perf_evlist *evlist,
132 			   struct perf_evsel *evsel,
133 			   int cpu_map_idx, int thread, int fd);
134 
135 void perf_evlist__reset_id_hash(struct perf_evlist *evlist);
136 
137 void __perf_evlist__set_leader(struct list_head *list, struct perf_evsel *leader);
138 
139 void perf_evlist__go_system_wide(struct perf_evlist *evlist, struct perf_evsel *evsel);
140 #endif /* __LIBPERF_INTERNAL_EVLIST_H */
141