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/evsel.h> 8 9 #define PERF_EVLIST__HLIST_BITS 8 10 #define PERF_EVLIST__HLIST_SIZE (1 << PERF_EVLIST__HLIST_BITS) 11 12 struct perf_cpu_map; 13 struct perf_thread_map; 14 struct perf_mmap_param; 15 16 struct perf_evlist { 17 struct list_head entries; 18 int nr_entries; 19 bool has_user_cpus; 20 struct perf_cpu_map *cpus; 21 struct perf_cpu_map *all_cpus; 22 struct perf_thread_map *threads; 23 int nr_mmaps; 24 size_t mmap_len; 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; 31 }; 32 33 typedef void 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); 37 typedef int 38 (*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, int, int); 39 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; 44 }; 45 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); 49 50 int perf_evlist__mmap_ops(struct perf_evlist *evlist, 51 struct perf_evlist_mmap_ops *ops, 52 struct perf_mmap_param *mp); 53 54 void perf_evlist__init(struct perf_evlist *evlist); 55 void perf_evlist__exit(struct perf_evlist *evlist); 56 57 /** 58 * __perf_evlist__for_each_entry - iterate thru all the evsels 59 * @list: list_head instance to iterate 60 * @evsel: struct perf_evsel iterator 61 */ 62 #define __perf_evlist__for_each_entry(list, evsel) \ 63 list_for_each_entry(evsel, list, node) 64 65 /** 66 * evlist__for_each_entry - iterate thru all the evsels 67 * @evlist: perf_evlist instance to iterate 68 * @evsel: struct perf_evsel iterator 69 */ 70 #define perf_evlist__for_each_entry(evlist, evsel) \ 71 __perf_evlist__for_each_entry(&(evlist)->entries, evsel) 72 73 /** 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 77 */ 78 #define __perf_evlist__for_each_entry_reverse(list, evsel) \ 79 list_for_each_entry_reverse(evsel, list, node) 80 81 /** 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 85 */ 86 #define perf_evlist__for_each_entry_reverse(evlist, evsel) \ 87 __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel) 88 89 /** 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 94 */ 95 #define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \ 96 list_for_each_entry_safe(evsel, tmp, list, node) 97 98 /** 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 103 */ 104 #define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \ 105 __perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel) 106 107 static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist) 108 { 109 return list_entry(evlist->entries.next, struct perf_evsel, node); 110 } 111 112 static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist) 113 { 114 return list_entry(evlist->entries.prev, struct perf_evsel, node); 115 } 116 117 u64 perf_evlist__read_format(struct perf_evlist *evlist); 118 119 void perf_evlist__id_add(struct perf_evlist *evlist, 120 struct perf_evsel *evsel, 121 int cpu, int thread, u64 id); 122 123 int perf_evlist__id_add_fd(struct perf_evlist *evlist, 124 struct perf_evsel *evsel, 125 int cpu, int thread, int fd); 126 127 #endif /* __LIBPERF_INTERNAL_EVLIST_H */ 128