1 /* SPDX-License-Identifier: GPL-2.0 */
5 #include <linux/bitmap.h>
6 #include <linux/compiler.h>
7 #include <linux/perf_event.h>
8 #include <linux/list.h>
11 #include "parse-events.h"
12 #include "pmu-events/pmu-events.h"
14 struct evsel_config_term;
16 struct print_callbacks;
19 PERF_PMU_FORMAT_VALUE_CONFIG,
20 PERF_PMU_FORMAT_VALUE_CONFIG1,
21 PERF_PMU_FORMAT_VALUE_CONFIG2,
22 PERF_PMU_FORMAT_VALUE_CONFIG3,
23 PERF_PMU_FORMAT_VALUE_CONFIG_END,
26 #define PERF_PMU_FORMAT_BITS 64
27 #define MAX_PMU_NAME_LEN 128
29 struct perf_event_attr;
31 struct perf_pmu_caps {
34 struct list_head list;
41 /** @name: The name of the PMU such as "cpu". */
44 * @alias_name: Optional alternate name for the PMU determined in
45 * architecture specific code.
49 * @id: Optional PMU identifier read from
50 * <sysfs>/bus/event_source/devices/<name>/identifier.
54 * @type: Perf event attributed type value, read from
55 * <sysfs>/bus/event_source/devices/<name>/type.
59 * @selectable: Can the PMU name be selected as if it were an event?
63 * @is_core: Is the PMU the core CPU PMU? Determined by the name being
64 * "cpu" or by the presence of
65 * <sysfs>/bus/event_source/devices/<name>/cpus. There may be >1 core
66 * PMU on systems like Intel hybrid.
70 * @is_uncore: Is the PMU not within the CPU core? Determined by the
71 * presence of <sysfs>/bus/event_source/devices/<name>/cpumask.
75 * @auxtrace: Are events auxiliary events? Determined in architecture
80 * @formats_checked: Only check PMU's formats are valid for
81 * perf_event_attr once.
84 /** @config_masks_present: Are there config format values? */
85 bool config_masks_present;
86 /** @config_masks_computed: Set when masks are lazily computed. */
87 bool config_masks_computed;
89 * @max_precise: Number of levels of :ppp precision supported by the
91 * <sysfs>/bus/event_source/devices/<name>/caps/max_precise.
95 * @default_config: Optional default perf_event_attr determined in
96 * architecture specific code.
98 struct perf_event_attr *default_config;
100 * @cpus: Empty or the contents of either of:
101 * <sysfs>/bus/event_source/devices/<name>/cpumask.
102 * <sysfs>/bus/event_source/devices/<cpu>/cpus.
104 struct perf_cpu_map *cpus;
106 * @format: Holds the contents of files read from
107 * <sysfs>/bus/event_source/devices/<name>/format/. The contents specify
108 * which event parameter changes what config, config1 or config2 bits.
110 struct list_head format;
112 * @aliases: List of struct perf_pmu_alias. Each alias corresponds to an
113 * event read from <sysfs>/bus/event_source/devices/<name>/events/ or
114 * from json events in pmu-events.c.
116 struct list_head aliases;
118 * @events_table: The events table for json events in pmu-events.c.
120 const struct pmu_events_table *events_table;
121 /** @sysfs_aliases: Number of sysfs aliases loaded. */
122 uint32_t sysfs_aliases;
123 /** @sysfs_aliases: Number of json event aliases loaded. */
124 uint32_t loaded_json_aliases;
125 /** @sysfs_aliases_loaded: Are sysfs aliases loaded from disk? */
126 bool sysfs_aliases_loaded;
128 * @cpu_aliases_added: Have all json events table entries for the PMU
131 bool cpu_aliases_added;
132 /** @caps_initialized: Has the list caps been initialized? */
133 bool caps_initialized;
134 /** @nr_caps: The length of the list caps. */
137 * @caps: Holds the contents of files read from
138 * <sysfs>/bus/event_source/devices/<name>/caps/.
140 * The contents are pairs of the filename with the value of its
141 * contents, for example, max_precise (see above) may have a value of 3.
143 struct list_head caps;
144 /** @list: Element on pmus list in pmu.c. */
145 struct list_head list;
148 * @config_masks: Derived from the PMU's format data, bits that are
149 * valid within the config value.
151 __u64 config_masks[PERF_PMU_FORMAT_VALUE_CONFIG_END];
154 * @missing_features: Features to inhibit when events on this PMU are
159 * @exclude_guest: Disables perf_event_attr exclude_guest and
166 /** @perf_pmu__fake: A special global PMU used for testing. */
167 extern struct perf_pmu perf_pmu__fake;
169 struct perf_pmu_info {
176 struct pmu_event_info {
177 const struct perf_pmu *pmu;
180 const char *scale_unit;
182 const char *long_desc;
183 const char *encoding_desc;
185 const char *pmu_name;
190 typedef int (*pmu_event_callback)(void *state, struct pmu_event_info *info);
192 void pmu_add_sys_aliases(struct perf_pmu *pmu);
193 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
194 struct list_head *head_terms,
195 struct parse_events_error *error);
196 int perf_pmu__config_terms(struct perf_pmu *pmu,
197 struct perf_event_attr *attr,
198 struct list_head *head_terms,
199 bool zero, struct parse_events_error *error);
200 __u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name);
201 int perf_pmu__format_type(struct perf_pmu *pmu, const char *name);
202 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
203 struct perf_pmu_info *info, struct parse_events_error *err);
204 int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, pmu_event_callback cb);
206 int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool eager_load);
207 void perf_pmu_format__set_value(void *format, int config, unsigned long *bits);
208 bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name);
210 bool is_pmu_core(const char *name);
211 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu);
212 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu);
213 bool perf_pmu__have_event(struct perf_pmu *pmu, const char *name);
214 size_t perf_pmu__num_events(struct perf_pmu *pmu);
215 int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
216 void *state, pmu_event_callback cb);
217 bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name);
220 * perf_pmu_is_software - is the PMU a software PMU as in it uses the
221 * perf_sw_context in the kernel?
223 bool perf_pmu__is_software(const struct perf_pmu *pmu);
225 FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name);
226 FILE *perf_pmu__open_file_at(struct perf_pmu *pmu, int dirfd, const char *name);
228 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4);
229 int perf_pmu__scan_file_at(struct perf_pmu *pmu, int dirfd, const char *name,
230 const char *fmt, ...) __scanf(4, 5);
232 bool perf_pmu__file_exists(struct perf_pmu *pmu, const char *name);
234 int perf_pmu__test(void);
236 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
237 void pmu_add_cpu_aliases_table(struct perf_pmu *pmu,
238 const struct pmu_events_table *table);
240 char *perf_pmu__getcpuid(struct perf_pmu *pmu);
241 const struct pmu_events_table *pmu_events_table__find(void);
242 const struct pmu_metrics_table *pmu_metrics_table__find(void);
244 int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
246 int perf_pmu__caps_parse(struct perf_pmu *pmu);
248 void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
249 const char *name, int config_num,
250 const char *config_name);
251 void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu);
253 int perf_pmu__match(const char *pattern, const char *name, const char *tok);
255 const char *pmu_find_real_name(const char *name);
256 const char *pmu_find_alias_name(const char *name);
257 double perf_pmu__cpu_slots_per_cycle(void);
258 int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size);
259 int perf_pmu__pathname_scnprintf(char *buf, size_t size,
260 const char *pmu_name, const char *filename);
261 int perf_pmu__event_source_devices_fd(void);
262 int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename, int flags);
264 struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name);
265 struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pmus);
266 void perf_pmu__delete(struct perf_pmu *pmu);
267 struct perf_pmu *pmu__find_core_pmu(void);