1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LIBPERF_INTERNAL_EVSEL_H
3 #define __LIBPERF_INTERNAL_EVSEL_H
5 #include <linux/types.h>
6 #include <linux/perf_event.h>
9 #include <internal/cpumap.h>
11 struct perf_thread_map;
15 * The per-thread accumulated period storage node.
17 struct perf_sample_id_period {
18 struct list_head node;
19 struct hlist_node hnode;
20 /* Holds total ID period value for PERF_SAMPLE_READ processing. */
22 /* The TID that the values belongs to */
27 * perf_evsel_for_each_per_thread_period_safe - safely iterate thru all the
29 * @evlist:perf_evsel instance to iterate
30 * @item: struct perf_sample_id_period iterator
31 * @tmp: struct perf_sample_id_period temp iterator
33 #define perf_evsel_for_each_per_thread_period_safe(evsel, tmp, item) \
34 list_for_each_entry_safe(item, tmp, &(evsel)->per_stream_periods, node)
37 #define PERF_SAMPLE_ID__HLIST_BITS 4
38 #define PERF_SAMPLE_ID__HLIST_SIZE (1 << PERF_SAMPLE_ID__HLIST_BITS)
41 * Per fd, to map back from PERF_SAMPLE_ID to evsel, only used when there are
42 * more than one entry in the evlist.
44 struct perf_sample_id {
45 struct hlist_node node;
47 struct perf_evsel *evsel;
49 * 'idx' will be used for AUX area sampling. A sample will have AUX area
50 * data that will be queued for decoding, where there are separate
51 * queues for each CPU (per-cpu tracing) or task (per-thread tracing).
52 * The sample ID can be used to lookup 'idx' which is effectively the
59 /* Guest machine pid and VCPU, valid only if machine_pid is non-zero */
64 * Per-thread, and global event counts are mutually exclusive:
65 * Whilst it is possible to combine events into a group with differing
66 * values of PERF_SAMPLE_READ, it is not valid to have inconsistent
67 * values for `inherit`. Therefore it is not possible to have a
68 * situation where a per-thread event is sampled as a global event;
69 * all !inherit groups are global, and all groups where the sampling
70 * event is inherit + PERF_SAMPLE_READ will be per-thread. Any event
71 * that is part of such a group that is inherit but not PERF_SAMPLE_READ
72 * will be read as per-thread. If such an event can also trigger a
73 * sample (such as with sample_period > 0) then it will not cause
74 * `read_format` to be included in its PERF_RECORD_SAMPLE, and
75 * therefore will not expose the per-thread group members as global.
79 * Holds total ID period value for PERF_SAMPLE_READ processing
80 * (when period is not per-thread).
84 * Holds total ID period value for PERF_SAMPLE_READ processing
85 * (when period is per-thread).
87 struct hlist_head periods[PERF_SAMPLE_ID__HLIST_SIZE];
92 struct list_head node;
93 struct perf_event_attr attr;
94 /** The commonly used cpu map of CPUs the event should be opened upon, etc. */
95 struct perf_cpu_map *cpus;
97 * The cpu map read from the PMU. For core PMUs this is the list of all
98 * CPUs the event can be opened upon. For other PMUs this is the default
99 * cpu map for opening the event on, for example, the first CPU on a
100 * socket for an uncore event.
102 struct perf_cpu_map *own_cpus;
103 struct perf_thread_map *threads;
105 struct xyarray *mmap;
106 struct xyarray *sample_id;
109 struct perf_evsel *leader;
111 /* For events where the read_format value is per-thread rather than
112 * global, stores the per-thread cumulative period */
113 struct list_head per_stream_periods;
115 /* parse modifier helper */
118 * system_wide is for events that need to be on every CPU, irrespective
119 * of user requested CPUs or threads. Tha main example of this is the
120 * dummy event. Map propagation will set cpus for this event to all CPUs
121 * as software PMU events like dummy, have a CPU map that is empty.
125 * Some events, for example uncore events, require a CPU.
126 * i.e. it cannot be the 'any CPU' value of -1.
129 /** Is the PMU for the event a core one? Effects the handling of own_cpus. */
134 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr,
136 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
137 void perf_evsel__close_fd(struct perf_evsel *evsel);
138 void perf_evsel__free_fd(struct perf_evsel *evsel);
139 int perf_evsel__read_size(struct perf_evsel *evsel);
140 int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
142 int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads);
143 void perf_evsel__free_id(struct perf_evsel *evsel);
145 bool perf_evsel__attr_has_per_thread_sample_period(struct perf_evsel *evsel);
147 u64 *perf_sample_id__get_period_storage(struct perf_sample_id *sid, u32 tid,
150 #endif /* __LIBPERF_INTERNAL_EVSEL_H */