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 int nr_groups; 21 bool has_user_cpus; 22 struct perf_cpu_map *cpus; 23 struct perf_cpu_map *all_cpus; 24 struct perf_thread_map *threads; 25 int nr_mmaps; 26 size_t mmap_len; 27 struct fdarray pollfd; 28 struct hlist_head heads[PERF_EVLIST__HLIST_SIZE]; 29 struct perf_mmap *mmap; 30 struct perf_mmap *mmap_ovw; 31 struct perf_mmap *mmap_first; 32 struct perf_mmap *mmap_ovw_first; 33 }; 34 35 typedef void 36 (*perf_evlist_mmap__cb_idx_t)(struct perf_evlist*, struct perf_mmap_param*, int, bool); 37 typedef struct perf_mmap* 38 (*perf_evlist_mmap__cb_get_t)(struct perf_evlist*, bool, int); 39 typedef int 40 (*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*, int, struct perf_cpu); 41 42 struct perf_evlist_mmap_ops { 43 perf_evlist_mmap__cb_idx_t idx; 44 perf_evlist_mmap__cb_get_t get; 45 perf_evlist_mmap__cb_mmap_t mmap; 46 }; 47 48 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); 49 int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, 50 void *ptr, short revent, enum fdarray_flags flags); 51 52 int perf_evlist__mmap_ops(struct perf_evlist *evlist, 53 struct perf_evlist_mmap_ops *ops, 54 struct perf_mmap_param *mp); 55 56 void perf_evlist__init(struct perf_evlist *evlist); 57 void perf_evlist__exit(struct perf_evlist *evlist); 58 59 /** 60 * __perf_evlist__for_each_entry - iterate thru all the evsels 61 * @list: list_head instance to iterate 62 * @evsel: struct perf_evsel iterator 63 */ 64 #define __perf_evlist__for_each_entry(list, evsel) \ 65 list_for_each_entry(evsel, list, node) 66 67 /** 68 * evlist__for_each_entry - iterate thru all the evsels 69 * @evlist: perf_evlist instance to iterate 70 * @evsel: struct perf_evsel iterator 71 */ 72 #define perf_evlist__for_each_entry(evlist, evsel) \ 73 __perf_evlist__for_each_entry(&(evlist)->entries, evsel) 74 75 /** 76 * __perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order 77 * @list: list_head instance to iterate 78 * @evsel: struct evsel iterator 79 */ 80 #define __perf_evlist__for_each_entry_reverse(list, evsel) \ 81 list_for_each_entry_reverse(evsel, list, node) 82 83 /** 84 * perf_evlist__for_each_entry_reverse - iterate thru all the evsels in reverse order 85 * @evlist: evlist instance to iterate 86 * @evsel: struct evsel iterator 87 */ 88 #define perf_evlist__for_each_entry_reverse(evlist, evsel) \ 89 __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel) 90 91 /** 92 * __perf_evlist__for_each_entry_safe - safely iterate thru all the evsels 93 * @list: list_head instance to iterate 94 * @tmp: struct evsel temp iterator 95 * @evsel: struct evsel iterator 96 */ 97 #define __perf_evlist__for_each_entry_safe(list, tmp, evsel) \ 98 list_for_each_entry_safe(evsel, tmp, list, node) 99 100 /** 101 * perf_evlist__for_each_entry_safe - safely iterate thru all the evsels 102 * @evlist: evlist instance to iterate 103 * @evsel: struct evsel iterator 104 * @tmp: struct evsel temp iterator 105 */ 106 #define perf_evlist__for_each_entry_safe(evlist, tmp, evsel) \ 107 __perf_evlist__for_each_entry_safe(&(evlist)->entries, tmp, evsel) 108 109 static inline struct perf_evsel *perf_evlist__first(struct perf_evlist *evlist) 110 { 111 return list_entry(evlist->entries.next, struct perf_evsel, node); 112 } 113 114 static inline struct perf_evsel *perf_evlist__last(struct perf_evlist *evlist) 115 { 116 return list_entry(evlist->entries.prev, struct perf_evsel, node); 117 } 118 119 u64 perf_evlist__read_format(struct perf_evlist *evlist); 120 121 void perf_evlist__id_add(struct perf_evlist *evlist, 122 struct perf_evsel *evsel, 123 int cpu, int thread, u64 id); 124 125 int perf_evlist__id_add_fd(struct perf_evlist *evlist, 126 struct perf_evsel *evsel, 127 int cpu, int thread, int fd); 128 129 void perf_evlist__reset_id_hash(struct perf_evlist *evlist); 130 131 void __perf_evlist__set_leader(struct list_head *list, struct perf_evsel *leader); 132 #endif /* __LIBPERF_INTERNAL_EVLIST_H */ 133