xref: /linux/tools/perf/util/evsel.h (revision ee29be625bd7b115d45eba4b0526ff3e24bf3ca0)
169aad6f1SArnaldo Carvalho de Melo #ifndef __PERF_EVSEL_H
269aad6f1SArnaldo Carvalho de Melo #define __PERF_EVSEL_H 1
369aad6f1SArnaldo Carvalho de Melo 
469aad6f1SArnaldo Carvalho de Melo #include <linux/list.h>
5c52b12edSArnaldo Carvalho de Melo #include <stdbool.h>
6d030260aSStephane Eranian #include "../../../include/linux/perf_event.h"
769aad6f1SArnaldo Carvalho de Melo #include "types.h"
869aad6f1SArnaldo Carvalho de Melo #include "xyarray.h"
9023695d9SStephane Eranian #include "cgroup.h"
10e248de33SArnaldo Carvalho de Melo #include "hist.h"
1169aad6f1SArnaldo Carvalho de Melo 
12c52b12edSArnaldo Carvalho de Melo struct perf_counts_values {
13c52b12edSArnaldo Carvalho de Melo 	union {
14c52b12edSArnaldo Carvalho de Melo 		struct {
15c52b12edSArnaldo Carvalho de Melo 			u64 val;
16c52b12edSArnaldo Carvalho de Melo 			u64 ena;
17c52b12edSArnaldo Carvalho de Melo 			u64 run;
18c52b12edSArnaldo Carvalho de Melo 		};
19c52b12edSArnaldo Carvalho de Melo 		u64 values[3];
20c52b12edSArnaldo Carvalho de Melo 	};
21c52b12edSArnaldo Carvalho de Melo };
22c52b12edSArnaldo Carvalho de Melo 
23c52b12edSArnaldo Carvalho de Melo struct perf_counts {
24c52b12edSArnaldo Carvalho de Melo 	s8		   	  scaled;
25c52b12edSArnaldo Carvalho de Melo 	struct perf_counts_values aggr;
26c52b12edSArnaldo Carvalho de Melo 	struct perf_counts_values cpu[];
27c52b12edSArnaldo Carvalho de Melo };
28c52b12edSArnaldo Carvalho de Melo 
2970db7533SArnaldo Carvalho de Melo struct perf_evsel;
3070db7533SArnaldo Carvalho de Melo 
3170db7533SArnaldo Carvalho de Melo /*
3270db7533SArnaldo Carvalho de Melo  * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
3370db7533SArnaldo Carvalho de Melo  * more than one entry in the evlist.
3470db7533SArnaldo Carvalho de Melo  */
3570db7533SArnaldo Carvalho de Melo struct perf_sample_id {
3670db7533SArnaldo Carvalho de Melo 	struct hlist_node 	node;
3770db7533SArnaldo Carvalho de Melo 	u64		 	id;
3870db7533SArnaldo Carvalho de Melo 	struct perf_evsel	*evsel;
3970db7533SArnaldo Carvalho de Melo };
4070db7533SArnaldo Carvalho de Melo 
41f0c55bcfSStephane Eranian /** struct perf_evsel - event selector
42f0c55bcfSStephane Eranian  *
43f0c55bcfSStephane Eranian  * @name - Can be set to retain the original event name passed by the user,
44f0c55bcfSStephane Eranian  *         so that when showing results in tools such as 'perf stat', we
45f0c55bcfSStephane Eranian  *         show the name used, not some alias.
46f0c55bcfSStephane Eranian  */
4769aad6f1SArnaldo Carvalho de Melo struct perf_evsel {
4869aad6f1SArnaldo Carvalho de Melo 	struct list_head	node;
4969aad6f1SArnaldo Carvalho de Melo 	struct perf_event_attr	attr;
5069aad6f1SArnaldo Carvalho de Melo 	char			*filter;
5169aad6f1SArnaldo Carvalho de Melo 	struct xyarray		*fd;
52a91e5431SArnaldo Carvalho de Melo 	struct xyarray		*sample_id;
53a91e5431SArnaldo Carvalho de Melo 	u64			*id;
54c52b12edSArnaldo Carvalho de Melo 	struct perf_counts	*counts;
5569aad6f1SArnaldo Carvalho de Melo 	int			idx;
56a91e5431SArnaldo Carvalho de Melo 	int			ids;
57e248de33SArnaldo Carvalho de Melo 	struct hists		hists;
58f0c55bcfSStephane Eranian 	char			*name;
59a91e5431SArnaldo Carvalho de Melo 	union {
6069aad6f1SArnaldo Carvalho de Melo 		void		*priv;
61a91e5431SArnaldo Carvalho de Melo 		off_t		id_offset;
62a91e5431SArnaldo Carvalho de Melo 	};
63023695d9SStephane Eranian 	struct cgroup_sel	*cgrp;
64*ee29be62SArnaldo Carvalho de Melo 	struct {
65*ee29be62SArnaldo Carvalho de Melo 		void		*func;
66*ee29be62SArnaldo Carvalho de Melo 		void		*data;
67*ee29be62SArnaldo Carvalho de Melo 	} handler;
682cee77c4SDavid Ahern 	bool 			supported;
6969aad6f1SArnaldo Carvalho de Melo };
7069aad6f1SArnaldo Carvalho de Melo 
7186bd5e86SArnaldo Carvalho de Melo struct cpu_map;
7286bd5e86SArnaldo Carvalho de Melo struct thread_map;
7370082dd9SArnaldo Carvalho de Melo struct perf_evlist;
740f82ebc4SArnaldo Carvalho de Melo struct perf_record_opts;
7586bd5e86SArnaldo Carvalho de Melo 
7623a2f3abSLin Ming struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
77ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__init(struct perf_evsel *evsel,
78ef1d1af2SArnaldo Carvalho de Melo 		      struct perf_event_attr *attr, int idx);
79ef1d1af2SArnaldo Carvalho de Melo void perf_evsel__exit(struct perf_evsel *evsel);
8069aad6f1SArnaldo Carvalho de Melo void perf_evsel__delete(struct perf_evsel *evsel);
8169aad6f1SArnaldo Carvalho de Melo 
820f82ebc4SArnaldo Carvalho de Melo void perf_evsel__config(struct perf_evsel *evsel,
830f82ebc4SArnaldo Carvalho de Melo 			struct perf_record_opts *opts);
840f82ebc4SArnaldo Carvalho de Melo 
8569aad6f1SArnaldo Carvalho de Melo int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
8670db7533SArnaldo Carvalho de Melo int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
87c52b12edSArnaldo Carvalho de Melo int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
8869aad6f1SArnaldo Carvalho de Melo void perf_evsel__free_fd(struct perf_evsel *evsel);
8970db7533SArnaldo Carvalho de Melo void perf_evsel__free_id(struct perf_evsel *evsel);
90c52b12edSArnaldo Carvalho de Melo void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
9169aad6f1SArnaldo Carvalho de Melo 
92f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_cpu(struct perf_evsel *evsel,
93727ab04eSArnaldo Carvalho de Melo 			     struct cpu_map *cpus, bool group,
94727ab04eSArnaldo Carvalho de Melo 			     struct xyarray *group_fds);
95f08199d3SArnaldo Carvalho de Melo int perf_evsel__open_per_thread(struct perf_evsel *evsel,
96727ab04eSArnaldo Carvalho de Melo 				struct thread_map *threads, bool group,
97727ab04eSArnaldo Carvalho de Melo 				struct xyarray *group_fds);
98f08199d3SArnaldo Carvalho de Melo int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus,
99727ab04eSArnaldo Carvalho de Melo 		     struct thread_map *threads, bool group,
100727ab04eSArnaldo Carvalho de Melo 		     struct xyarray *group_fds);
101727ab04eSArnaldo Carvalho de Melo void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads);
10248290609SArnaldo Carvalho de Melo 
103daec78a0SArnaldo Carvalho de Melo #define perf_evsel__match(evsel, t, c)		\
104daec78a0SArnaldo Carvalho de Melo 	(evsel->attr.type == PERF_TYPE_##t &&	\
105daec78a0SArnaldo Carvalho de Melo 	 evsel->attr.config == PERF_COUNT_##c)
106daec78a0SArnaldo Carvalho de Melo 
107c52b12edSArnaldo Carvalho de Melo int __perf_evsel__read_on_cpu(struct perf_evsel *evsel,
108c52b12edSArnaldo Carvalho de Melo 			      int cpu, int thread, bool scale);
109c52b12edSArnaldo Carvalho de Melo 
110c52b12edSArnaldo Carvalho de Melo /**
111c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu - Read out the results on a CPU and thread
112c52b12edSArnaldo Carvalho de Melo  *
113c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
114c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
115c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
116c52b12edSArnaldo Carvalho de Melo  */
117c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu(struct perf_evsel *evsel,
118c52b12edSArnaldo Carvalho de Melo 					  int cpu, int thread)
119c52b12edSArnaldo Carvalho de Melo {
120c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, false);
121c52b12edSArnaldo Carvalho de Melo }
122c52b12edSArnaldo Carvalho de Melo 
123c52b12edSArnaldo Carvalho de Melo /**
124c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled
125c52b12edSArnaldo Carvalho de Melo  *
126c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
127c52b12edSArnaldo Carvalho de Melo  * @cpu - CPU of interest
128c52b12edSArnaldo Carvalho de Melo  * @thread - thread of interest
129c52b12edSArnaldo Carvalho de Melo  */
130c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_on_cpu_scaled(struct perf_evsel *evsel,
131c52b12edSArnaldo Carvalho de Melo 						 int cpu, int thread)
132c52b12edSArnaldo Carvalho de Melo {
133c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read_on_cpu(evsel, cpu, thread, true);
134c52b12edSArnaldo Carvalho de Melo }
135c52b12edSArnaldo Carvalho de Melo 
136c52b12edSArnaldo Carvalho de Melo int __perf_evsel__read(struct perf_evsel *evsel, int ncpus, int nthreads,
137c52b12edSArnaldo Carvalho de Melo 		       bool scale);
138c52b12edSArnaldo Carvalho de Melo 
139c52b12edSArnaldo Carvalho de Melo /**
140c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read - Read the aggregate results on all CPUs
141c52b12edSArnaldo Carvalho de Melo  *
142c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
143c52b12edSArnaldo Carvalho de Melo  * @ncpus - Number of cpus affected, from zero
144c52b12edSArnaldo Carvalho de Melo  * @nthreads - Number of threads affected, from zero
145c52b12edSArnaldo Carvalho de Melo  */
146c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read(struct perf_evsel *evsel,
147c52b12edSArnaldo Carvalho de Melo 				    int ncpus, int nthreads)
148c52b12edSArnaldo Carvalho de Melo {
149c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read(evsel, ncpus, nthreads, false);
150c52b12edSArnaldo Carvalho de Melo }
151c52b12edSArnaldo Carvalho de Melo 
152c52b12edSArnaldo Carvalho de Melo /**
153c52b12edSArnaldo Carvalho de Melo  * perf_evsel__read_scaled - Read the aggregate results on all CPUs, scaled
154c52b12edSArnaldo Carvalho de Melo  *
155c52b12edSArnaldo Carvalho de Melo  * @evsel - event selector to read value
156c52b12edSArnaldo Carvalho de Melo  * @ncpus - Number of cpus affected, from zero
157c52b12edSArnaldo Carvalho de Melo  * @nthreads - Number of threads affected, from zero
158c52b12edSArnaldo Carvalho de Melo  */
159c52b12edSArnaldo Carvalho de Melo static inline int perf_evsel__read_scaled(struct perf_evsel *evsel,
160c52b12edSArnaldo Carvalho de Melo 					  int ncpus, int nthreads)
161c52b12edSArnaldo Carvalho de Melo {
162c52b12edSArnaldo Carvalho de Melo 	return __perf_evsel__read(evsel, ncpus, nthreads, true);
163c52b12edSArnaldo Carvalho de Melo }
164c52b12edSArnaldo Carvalho de Melo 
165c2a70653SArnaldo Carvalho de Melo int __perf_evsel__sample_size(u64 sample_type);
166c2a70653SArnaldo Carvalho de Melo 
167c2a70653SArnaldo Carvalho de Melo static inline int perf_evsel__sample_size(struct perf_evsel *evsel)
168c2a70653SArnaldo Carvalho de Melo {
169c2a70653SArnaldo Carvalho de Melo 	return __perf_evsel__sample_size(evsel->attr.sample_type);
170c2a70653SArnaldo Carvalho de Melo }
171c2a70653SArnaldo Carvalho de Melo 
17269aad6f1SArnaldo Carvalho de Melo #endif /* __PERF_EVSEL_H */
173