1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LIBPERF_INTERNAL_EVSEL_H 3 #define __LIBPERF_INTERNAL_EVSEL_H 4 5 #include <linux/types.h> 6 #include <linux/perf_event.h> 7 #include <stdbool.h> 8 #include <sys/types.h> 9 #include <internal/cpumap.h> 10 11 struct perf_thread_map; 12 struct xyarray; 13 14 /* 15 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are 16 * more than one entry in the evlist. 17 */ 18 struct perf_sample_id { 19 struct hlist_node node; 20 u64 id; 21 struct perf_evsel *evsel; 22 /* 23 * 'idx' will be used for AUX area sampling. A sample will have AUX area 24 * data that will be queued for decoding, where there are separate 25 * queues for each CPU (per-cpu tracing) or task (per-thread tracing). 26 * The sample ID can be used to lookup 'idx' which is effectively the 27 * queue number. 28 */ 29 int idx; 30 struct perf_cpu cpu; 31 pid_t tid; 32 33 /* Guest machine pid and VCPU, valid only if machine_pid is non-zero */ 34 pid_t machine_pid; 35 struct perf_cpu vcpu; 36 37 /* Holds total ID period value for PERF_SAMPLE_READ processing. */ 38 u64 period; 39 }; 40 41 struct perf_evsel { 42 struct list_head node; 43 struct perf_event_attr attr; 44 struct perf_cpu_map *cpus; 45 struct perf_cpu_map *own_cpus; 46 struct perf_thread_map *threads; 47 struct xyarray *fd; 48 struct xyarray *mmap; 49 struct xyarray *sample_id; 50 u64 *id; 51 u32 ids; 52 struct perf_evsel *leader; 53 54 /* parse modifier helper */ 55 int nr_members; 56 /* 57 * system_wide is for events that need to be on every CPU, irrespective 58 * of user requested CPUs or threads. Map propagation will set cpus to 59 * this event's own_cpus, whereby they will contribute to evlist 60 * all_cpus. 61 */ 62 bool system_wide; 63 /* 64 * Some events, for example uncore events, require a CPU. 65 * i.e. it cannot be the 'any CPU' value of -1. 66 */ 67 bool requires_cpu; 68 int idx; 69 }; 70 71 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr, 72 int idx); 73 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads); 74 void perf_evsel__close_fd(struct perf_evsel *evsel); 75 void perf_evsel__free_fd(struct perf_evsel *evsel); 76 int perf_evsel__read_size(struct perf_evsel *evsel); 77 int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter); 78 79 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads); 80 void perf_evsel__free_id(struct perf_evsel *evsel); 81 82 #endif /* __LIBPERF_INTERNAL_EVSEL_H */ 83