Linux Audio

Check our new training course

Loading...
v5.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PMU_H
  3#define __PMU_H
  4
  5#include <linux/bitmap.h>
  6#include <linux/compiler.h>
  7#include <linux/perf_event.h>
 
  8#include <stdbool.h>
 
  9#include "parse-events.h"
 10
 11struct perf_evsel_config_term;
 
 
 
 
 
 12
 13enum {
 14	PERF_PMU_FORMAT_VALUE_CONFIG,
 15	PERF_PMU_FORMAT_VALUE_CONFIG1,
 16	PERF_PMU_FORMAT_VALUE_CONFIG2,
 
 
 17};
 18
 19#define PERF_PMU_FORMAT_BITS 64
 20#define EVENT_SOURCE_DEVICE_PATH "/bus/event_source/devices/"
 21
 22struct perf_event_attr;
 23
 24struct perf_pmu {
 25	char *name;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 26	__u32 type;
 
 
 
 27	bool selectable;
 
 
 
 
 
 
 
 
 
 
 
 28	bool is_uncore;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 29	int max_precise;
 30	struct perf_event_attr *default_config;
 
 
 
 
 
 
 
 
 
 
 31	struct perf_cpu_map *cpus;
 32	struct list_head format;  /* HEAD struct perf_pmu_format -> list */
 33	struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */
 34	struct list_head list;    /* ELEM */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 35};
 36
 
 
 
 37struct perf_pmu_info {
 38	const char *unit;
 39	const char *metric_expr;
 40	const char *metric_name;
 41	double scale;
 42	bool per_pkg;
 43	bool snapshot;
 44};
 45
 46#define UNIT_MAX_LEN	31 /* max length for event unit name */
 47
 48struct perf_pmu_alias {
 49	char *name;
 50	char *desc;
 51	char *long_desc;
 52	char *topic;
 53	char *str;
 54	struct list_head terms; /* HEAD struct parse_events_term -> list */
 55	struct list_head list;  /* ELEM */
 56	char unit[UNIT_MAX_LEN+1];
 57	double scale;
 58	bool per_pkg;
 59	bool snapshot;
 60	char *metric_expr;
 61	char *metric_name;
 62};
 63
 64struct perf_pmu *perf_pmu__find(const char *name);
 
 
 65int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
 66		     struct list_head *head_terms,
 67		     struct parse_events_error *error);
 68int perf_pmu__config_terms(struct list_head *formats,
 69			   struct perf_event_attr *attr,
 70			   struct list_head *head_terms,
 71			   bool zero, struct parse_events_error *error);
 72__u64 perf_pmu__format_bits(struct list_head *formats, const char *name);
 73int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
 74			  struct perf_pmu_info *info);
 75struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
 76				  struct list_head *head_terms);
 77int perf_pmu_wrap(void);
 78void perf_pmu_error(struct list_head *list, char *name, char const *msg);
 79
 80int perf_pmu__new_format(struct list_head *list, char *name,
 81			 int config, unsigned long *bits);
 82void perf_pmu__set_format(unsigned long *bits, long from, long to);
 83int perf_pmu__format_parse(char *dir, struct list_head *head);
 84
 85struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
 86
 87void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
 88		      bool long_desc, bool details_flag);
 89bool pmu_have_event(const char *pname, const char *name);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 90
 91int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4);
 92
 93int perf_pmu__test(void);
 94
 95struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
 96
 97struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu);
 
 
 
 
 98
 99int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
101#endif /* __PMU_H */
v6.9.4
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef __PMU_H
  3#define __PMU_H
  4
  5#include <linux/bitmap.h>
  6#include <linux/compiler.h>
  7#include <linux/perf_event.h>
  8#include <linux/list.h>
  9#include <stdbool.h>
 10#include <stdio.h>
 11#include "parse-events.h"
 12#include "pmu-events/pmu-events.h"
 13#include "map_symbol.h"
 14#include "mem-events.h"
 15
 16struct evsel_config_term;
 17struct perf_cpu_map;
 18struct print_callbacks;
 19
 20enum {
 21	PERF_PMU_FORMAT_VALUE_CONFIG,
 22	PERF_PMU_FORMAT_VALUE_CONFIG1,
 23	PERF_PMU_FORMAT_VALUE_CONFIG2,
 24	PERF_PMU_FORMAT_VALUE_CONFIG3,
 25	PERF_PMU_FORMAT_VALUE_CONFIG_END,
 26};
 27
 28#define PERF_PMU_FORMAT_BITS 64
 29#define MAX_PMU_NAME_LEN 128
 30
 31struct perf_event_attr;
 32
 33struct perf_pmu_caps {
 34	char *name;
 35	char *value;
 36	struct list_head list;
 37};
 38
 39/**
 40 * struct perf_pmu
 41 */
 42struct perf_pmu {
 43	/** @name: The name of the PMU such as "cpu". */
 44	const char *name;
 45	/**
 46	 * @alias_name: Optional alternate name for the PMU determined in
 47	 * architecture specific code.
 48	 */
 49	char *alias_name;
 50	/**
 51	 * @id: Optional PMU identifier read from
 52	 * <sysfs>/bus/event_source/devices/<name>/identifier.
 53	 */
 54	const char *id;
 55	/**
 56	 * @type: Perf event attributed type value, read from
 57	 * <sysfs>/bus/event_source/devices/<name>/type.
 58	 */
 59	__u32 type;
 60	/**
 61	 * @selectable: Can the PMU name be selected as if it were an event?
 62	 */
 63	bool selectable;
 64	/**
 65	 * @is_core: Is the PMU the core CPU PMU? Determined by the name being
 66	 * "cpu" or by the presence of
 67	 * <sysfs>/bus/event_source/devices/<name>/cpus. There may be >1 core
 68	 * PMU on systems like Intel hybrid.
 69	 */
 70	bool is_core;
 71	/**
 72	 * @is_uncore: Is the PMU not within the CPU core? Determined by the
 73	 * presence of <sysfs>/bus/event_source/devices/<name>/cpumask.
 74	 */
 75	bool is_uncore;
 76	/**
 77	 * @auxtrace: Are events auxiliary events? Determined in architecture
 78	 * specific code.
 79	 */
 80	bool auxtrace;
 81	/**
 82	 * @formats_checked: Only check PMU's formats are valid for
 83	 * perf_event_attr once.
 84	 */
 85	bool formats_checked;
 86	/** @config_masks_present: Are there config format values? */
 87	bool config_masks_present;
 88	/** @config_masks_computed: Set when masks are lazily computed. */
 89	bool config_masks_computed;
 90	/**
 91	 * @max_precise: Number of levels of :ppp precision supported by the
 92	 * PMU, read from
 93	 * <sysfs>/bus/event_source/devices/<name>/caps/max_precise.
 94	 */
 95	int max_precise;
 96	/**
 97	 * @perf_event_attr_init_default: Optional function to default
 98	 * initialize PMU specific parts of the perf_event_attr.
 99	 */
100	void (*perf_event_attr_init_default)(const struct perf_pmu *pmu,
101					     struct perf_event_attr *attr);
102	/**
103	 * @cpus: Empty or the contents of either of:
104	 * <sysfs>/bus/event_source/devices/<name>/cpumask.
105	 * <sysfs>/bus/event_source/devices/<cpu>/cpus.
106	 */
107	struct perf_cpu_map *cpus;
108	/**
109	 * @format: Holds the contents of files read from
110	 * <sysfs>/bus/event_source/devices/<name>/format/. The contents specify
111	 * which event parameter changes what config, config1 or config2 bits.
112	 */
113	struct list_head format;
114	/**
115	 * @aliases: List of struct perf_pmu_alias. Each alias corresponds to an
116	 * event read from <sysfs>/bus/event_source/devices/<name>/events/ or
117	 * from json events in pmu-events.c.
118	 */
119	struct list_head aliases;
120	/**
121	 * @events_table: The events table for json events in pmu-events.c.
122	 */
123	const struct pmu_events_table *events_table;
124	/** @sysfs_aliases: Number of sysfs aliases loaded. */
125	uint32_t sysfs_aliases;
126	/** @cpu_json_aliases: Number of json event aliases loaded specific to the CPUID. */
127	uint32_t cpu_json_aliases;
128	/** @sys_json_aliases: Number of json event aliases loaded matching the PMU's identifier. */
129	uint32_t sys_json_aliases;
130	/** @sysfs_aliases_loaded: Are sysfs aliases loaded from disk? */
131	bool sysfs_aliases_loaded;
132	/**
133	 * @cpu_aliases_added: Have all json events table entries for the PMU
134	 * been added?
135	 */
136	bool cpu_aliases_added;
137	/** @caps_initialized: Has the list caps been initialized? */
138	bool caps_initialized;
139	/** @nr_caps: The length of the list caps. */
140	u32 nr_caps;
141	/**
142	 * @caps: Holds the contents of files read from
143	 * <sysfs>/bus/event_source/devices/<name>/caps/.
144	 *
145	 * The contents are pairs of the filename with the value of its
146	 * contents, for example, max_precise (see above) may have a value of 3.
147	 */
148	struct list_head caps;
149	/** @list: Element on pmus list in pmu.c. */
150	struct list_head list;
151
152	/**
153	 * @config_masks: Derived from the PMU's format data, bits that are
154	 * valid within the config value.
155	 */
156	__u64 config_masks[PERF_PMU_FORMAT_VALUE_CONFIG_END];
157
158	/**
159	 * @missing_features: Features to inhibit when events on this PMU are
160	 * opened.
161	 */
162	struct {
163		/**
164		 * @exclude_guest: Disables perf_event_attr exclude_guest and
165		 * exclude_host.
166		 */
167		bool exclude_guest;
168	} missing_features;
169
170	/**
171	 * @mem_events: List of the supported mem events
172	 */
173	struct perf_mem_event *mem_events;
174};
175
176/** @perf_pmu__fake: A special global PMU used for testing. */
177extern struct perf_pmu perf_pmu__fake;
178
179struct perf_pmu_info {
180	const char *unit;
 
 
181	double scale;
182	bool per_pkg;
183	bool snapshot;
184};
185
186struct pmu_event_info {
187	const struct perf_pmu *pmu;
188	const char *name;
189	const char* alias;
190	const char *scale_unit;
191	const char *desc;
192	const char *long_desc;
193	const char *encoding_desc;
194	const char *topic;
195	const char *pmu_name;
196	const char *str;
197	bool deprecated;
 
 
 
 
198};
199
200typedef int (*pmu_event_callback)(void *state, struct pmu_event_info *info);
201
202void pmu_add_sys_aliases(struct perf_pmu *pmu);
203int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
204		     struct parse_events_terms *head_terms,
205		     struct parse_events_error *error);
206int perf_pmu__config_terms(const struct perf_pmu *pmu,
207			   struct perf_event_attr *attr,
208			   struct parse_events_terms *terms,
209			   bool zero, struct parse_events_error *error);
210__u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name);
211int perf_pmu__format_type(struct perf_pmu *pmu, const char *name);
212int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_terms,
213			  struct perf_pmu_info *info, bool *rewrote_terms,
214			  struct parse_events_error *err);
215int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, pmu_event_callback cb);
216
217int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool eager_load);
218void perf_pmu_format__set_value(void *format, int config, unsigned long *bits);
219bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name);
220
221bool is_pmu_core(const char *name);
222bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu);
223bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu);
224bool perf_pmu__have_event(struct perf_pmu *pmu, const char *name);
225size_t perf_pmu__num_events(struct perf_pmu *pmu);
226int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
227			     void *state, pmu_event_callback cb);
228bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name);
229
230/**
231 * perf_pmu_is_software - is the PMU a software PMU as in it uses the
232 *                        perf_sw_context in the kernel?
233 */
234bool perf_pmu__is_software(const struct perf_pmu *pmu);
235
236FILE *perf_pmu__open_file(const struct perf_pmu *pmu, const char *name);
237FILE *perf_pmu__open_file_at(const struct perf_pmu *pmu, int dirfd, const char *name);
238
239int perf_pmu__scan_file(const struct perf_pmu *pmu, const char *name, const char *fmt, ...)
240	__scanf(3, 4);
241int perf_pmu__scan_file_at(const struct perf_pmu *pmu, int dirfd, const char *name,
242			   const char *fmt, ...) __scanf(4, 5);
243
244bool perf_pmu__file_exists(const struct perf_pmu *pmu, const char *name);
245
246int perf_pmu__test(void);
247
248void perf_pmu__arch_init(struct perf_pmu *pmu);
249void pmu_add_cpu_aliases_table(struct perf_pmu *pmu,
250			       const struct pmu_events_table *table);
251
252char *perf_pmu__getcpuid(struct perf_pmu *pmu);
253const struct pmu_metrics_table *pmu_metrics_table__find(void);
254bool pmu_uncore_identifier_match(const char *compat, const char *id);
255
256int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
257
258int perf_pmu__caps_parse(struct perf_pmu *pmu);
259
260void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
261				   const char *name, int config_num,
262				   const char *config_name);
263void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu);
264
265int perf_pmu__match(const char *pattern, const char *name, const char *tok);
266
267double perf_pmu__cpu_slots_per_cycle(void);
268int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size);
269int perf_pmu__pathname_scnprintf(char *buf, size_t size,
270				 const char *pmu_name, const char *filename);
271int perf_pmu__event_source_devices_fd(void);
272int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename, int flags);
273
274struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name);
275struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pmus);
276void perf_pmu__delete(struct perf_pmu *pmu);
277struct perf_pmu *perf_pmus__find_core_pmu(void);
278const char *perf_pmu__name_from_config(struct perf_pmu *pmu, u64 config);
279
280#endif /* __PMU_H */