xref: /linux/tools/lib/perf/include/internal/evsel.h (revision bdd1a21b52557ea8f61d0a5dc2f77151b576eb70)
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 
10 struct perf_cpu_map;
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 	int			 cpu;
31 	pid_t			 tid;
32 
33 	/* Holds total ID period value for PERF_SAMPLE_READ processing. */
34 	u64			 period;
35 };
36 
37 struct perf_evsel {
38 	struct list_head	 node;
39 	struct perf_event_attr	 attr;
40 	struct perf_cpu_map	*cpus;
41 	struct perf_cpu_map	*own_cpus;
42 	struct perf_thread_map	*threads;
43 	struct xyarray		*fd;
44 	struct xyarray		*mmap;
45 	struct xyarray		*sample_id;
46 	u64			*id;
47 	u32			 ids;
48 	struct perf_evsel	*leader;
49 
50 	/* parse modifier helper */
51 	int			 nr_members;
52 	bool			 system_wide;
53 	int			 idx;
54 };
55 
56 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
57 		      int idx);
58 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
59 void perf_evsel__close_fd(struct perf_evsel *evsel);
60 void perf_evsel__free_fd(struct perf_evsel *evsel);
61 int perf_evsel__read_size(struct perf_evsel *evsel);
62 int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
63 
64 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
65 void perf_evsel__free_id(struct perf_evsel *evsel);
66 
67 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
68