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;
117 /** @caps_initialized: Has the list caps been initialized? */
118 bool caps_initialized;
119 /** @nr_caps: The length of the list caps. */
122 * @caps: Holds the contents of files read from
123 * <sysfs>/bus/event_source/devices/<name>/caps/.
125 * The contents are pairs of the filename with the value of its
126 * contents, for example, max_precise (see above) may have a value of 3.
128 struct list_head caps;
129 /** @list: Element on pmus list in pmu.c. */
130 struct list_head list;
133 * @config_masks: Derived from the PMU's format data, bits that are
134 * valid within the config value.
136 __u64 config_masks[PERF_PMU_FORMAT_VALUE_CONFIG_END];
139 * @missing_features: Features to inhibit when events on this PMU are
144 * @exclude_guest: Disables perf_event_attr exclude_guest and
151 /** @perf_pmu__fake: A special global PMU used for testing. */
152 extern struct perf_pmu perf_pmu__fake;
154 struct perf_pmu_info {
161 #define UNIT_MAX_LEN 31 /* max length for event unit name */
164 * struct perf_pmu_alias - An event either read from sysfs or builtin in
165 * pmu-events.c, created by parsing the pmu-events json files.
167 struct perf_pmu_alias {
168 /** @name: Name of the event like "mem-loads". */
170 /** @desc: Optional short description of the event. */
172 /** @long_desc: Optional long description. */
175 * @topic: Optional topic such as cache or pipeline, particularly for
180 * @str: Comma separated parameter list like
181 * "event=0xcd,umask=0x1,ldlat=0x3".
184 /** @terms: Owned list of the original parsed parameters. */
185 struct list_head terms;
186 /** @list: List element of struct perf_pmu aliases. */
187 struct list_head list;
188 /** @unit: Units for the event, such as bytes or cache lines. */
189 char unit[UNIT_MAX_LEN+1];
190 /** @scale: Value to scale read counter values by. */
193 * @per_pkg: Does the file
194 * <sysfs>/bus/event_source/devices/<pmu_name>/events/<name>.per-pkg or
195 * equivalent json value exist and have the value 1.
199 * @snapshot: Does the file
200 * <sysfs>/bus/event_source/devices/<pmu_name>/events/<name>.snapshot
201 * exist and have the value 1.
205 * @deprecated: Is the event hidden and so not shown in perf list by
210 * @pmu_name: The name copied from the json struct pmu_event. This can
211 * differ from the PMU name as it won't have suffixes.
216 void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu);
217 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
218 struct list_head *head_terms,
219 struct parse_events_error *error);
220 int perf_pmu__config_terms(const char *pmu_name, struct list_head *formats,
221 struct perf_event_attr *attr,
222 struct list_head *head_terms,
223 bool zero, struct parse_events_error *error);
224 __u64 perf_pmu__format_bits(struct list_head *formats, const char *name);
225 int perf_pmu__format_type(struct list_head *formats, const char *name);
226 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
227 struct perf_pmu_info *info);
228 struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
229 struct list_head *head_terms);
230 void perf_pmu_error(struct list_head *list, char *name, void *scanner, char const *msg);
232 int perf_pmu__new_format(struct list_head *list, char *name,
233 int config, unsigned long *bits);
234 void perf_pmu__set_format(unsigned long *bits, long from, long to);
235 int perf_pmu__format_parse(int dirfd, struct list_head *head);
236 void perf_pmu__del_formats(struct list_head *formats);
238 bool is_pmu_core(const char *name);
239 bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu);
240 bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu);
241 bool perf_pmu__have_event(const struct perf_pmu *pmu, const char *name);
243 * perf_pmu_is_software - is the PMU a software PMU as in it uses the
244 * perf_sw_context in the kernel?
246 bool perf_pmu__is_software(const struct perf_pmu *pmu);
248 FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name);
249 FILE *perf_pmu__open_file_at(struct perf_pmu *pmu, int dirfd, const char *name);
251 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4);
252 int perf_pmu__scan_file_at(struct perf_pmu *pmu, int dirfd, const char *name,
253 const char *fmt, ...) __scanf(4, 5);
255 bool perf_pmu__file_exists(struct perf_pmu *pmu, const char *name);
257 int perf_pmu__test(void);
259 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
260 void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
261 const struct pmu_events_table *table);
263 char *perf_pmu__getcpuid(struct perf_pmu *pmu);
264 const struct pmu_events_table *pmu_events_table__find(void);
265 const struct pmu_metrics_table *pmu_metrics_table__find(void);
266 void perf_pmu_free_alias(struct perf_pmu_alias *alias);
268 int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
270 int perf_pmu__caps_parse(struct perf_pmu *pmu);
272 void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
273 const char *name, int config_num,
274 const char *config_name);
275 void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu);
277 int perf_pmu__match(char *pattern, char *name, char *tok);
279 char *pmu_find_real_name(const char *name);
280 char *pmu_find_alias_name(const char *name);
281 double perf_pmu__cpu_slots_per_cycle(void);
282 int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size);
283 int perf_pmu__pathname_scnprintf(char *buf, size_t size,
284 const char *pmu_name, const char *filename);
285 int perf_pmu__event_source_devices_fd(void);
286 int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename, int flags);
288 struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name);
289 void perf_pmu__delete(struct perf_pmu *pmu);