Linux Audio

Check our new training course

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