1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBPERF_INTERNAL_EVLIST_H
3 #define __LIBPERF_INTERNAL_EVLIST_H
5 #include <linux/list.h>
6 #include <api/fd/array.h>
7 #include <internal/evsel.h>
9 #define PERF_EVLIST__HLIST_BITS 8
10 #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS)
13 struct perf_thread_map
;
14 struct perf_mmap_param
;
17 struct list_head entries
;
20 struct perf_cpu_map
*cpus
;
21 struct perf_cpu_map
*all_cpus
;
22 struct perf_thread_map
*threads
;
25 struct fdarray pollfd
;
26 struct hlist_head heads
[PERF_EVLIST__HLIST_SIZE
];
27 struct perf_mmap
*mmap
;
28 struct perf_mmap
*mmap_ovw
;
29 struct perf_mmap
*mmap_first
;
30 struct perf_mmap
*mmap_ovw_first
;
34 (*perf_evlist_mmap__cb_idx_t
)(struct perf_evlist
*, struct perf_mmap_param
*, int, bool);
35 typedef struct perf_mmap
*
36 (*perf_evlist_mmap__cb_get_t
)(struct perf_evlist
*, bool, int);
38 (*perf_evlist_mmap__cb_mmap_t
)(struct perf_mmap
*, struct perf_mmap_param
*, int, int);
40 struct perf_evlist_mmap_ops
{
41 perf_evlist_mmap__cb_idx_t idx
;
42 perf_evlist_mmap__cb_get_t get
;
43 perf_evlist_mmap__cb_mmap_t mmap
;
46 int perf_evlist__alloc_pollfd(struct perf_evlist
*evlist
);
47 int perf_evlist__add_pollfd(struct perf_evlist
*evlist
, int fd
,
48 void *ptr
, short revent
, enum fdarray_flags flags
);
50 int perf_evlist__mmap_ops(struct perf_evlist
*evlist
,
51 struct perf_evlist_mmap_ops
*ops
,
52 struct perf_mmap_param
*mp
);
54 void perf_evlist__init(struct perf_evlist
*evlist
);
55 void perf_evlist__exit(struct perf_evlist
*evlist
);
58 * __perf_evlist__for_each_entry - iterate thru all the evsels
59 * @list: list_head instance to iterate
60 * @evsel: struct perf_evsel iterator
62 #define __perf_evlist__for_each_entry(list, evsel) \
63 list_for_each_entry(evsel, list, node)
66 * evlist__for_each_entry - iterate thru all the evsels
67 * @evlist: perf_evlist instance to iterate
68 * @evsel: struct perf_evsel iterator
70 #define perf_evlist__for_each_entry(evlist, evsel) \
71 __perf_evlist__for_each_entry(&(evlist)->entries, evsel)
74 * __perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
75 * @list: list_head instance to iterate
76 * @evsel: struct evsel iterator
78 #define __perf_evlist__for_each_entry_reverse(list, evsel) \
79 list_for_each_entry_reverse(evsel, list, node)
82 * perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order
83 * @evlist: evlist instance to iterate
84 * @evsel: struct evsel iterator
86 #define perf_evlist__for_each_entry_reverse(evlist, evsel) \
87 __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
90 * __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
91 * @list: list_head instance to iterate
92 * @tmp: struct evsel temp iterator
93 * @evsel: struct evsel iterator
95 #define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \
96 list_for_each_entry_safe(evsel, tmp, list, node)
99 * perf_evlist__for_each_entry_safe - safely iterate thru all the evsels
100 * @evlist: evlist instance to iterate
101 * @evsel: struct evsel iterator
102 * @tmp: struct evsel temp iterator
104 #define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \
105 __perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel)
107 static inline struct perf_evsel
*perf_evlist__first(struct perf_evlist
*evlist
)
109 return list_entry(evlist
->entries
.next
, struct perf_evsel
, node
);
112 static inline struct perf_evsel
*perf_evlist__last(struct perf_evlist
*evlist
)
114 return list_entry(evlist
->entries
.prev
, struct perf_evsel
, node
);
117 u64
perf_evlist__read_format(struct perf_evlist
*evlist
);
119 void perf_evlist__id_add(struct perf_evlist
*evlist
,
120 struct perf_evsel
*evsel
,
121 int cpu
, int thread
, u64 id
);
123 int perf_evlist__id_add_fd(struct perf_evlist
*evlist
,
124 struct perf_evsel
*evsel
,
125 int cpu
, int thread
, int fd
);
127 #endif /* __LIBPERF_INTERNAL_EVLIST_H */