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