Merge tag 'dlm-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm
[linux-2.6-block.git] / tools / perf / util / pmu.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
cd82a32e
JO
2#ifndef __PMU_H
3#define __PMU_H
4
d944c4ee 5#include <linux/bitmap.h>
3ee350fb 6#include <linux/compiler.h>
d2709c7c 7#include <linux/perf_event.h>
44462430 8#include <linux/list.h>
dc098b35 9#include <stdbool.h>
d50a79cd 10#include <stdio.h>
e64b020b 11#include "parse-events.h"
e45ad701 12#include "pmu-events/pmu-events.h"
bb65acdc
KL
13#include "map_symbol.h"
14#include "mem-events.h"
cd82a32e 15
35ac0cad 16struct evsel_config_term;
1d3351e6 17struct perf_cpu_map;
e5c6109f 18struct print_callbacks;
eb563d66 19
cd82a32e
JO
20enum {
21 PERF_PMU_FORMAT_VALUE_CONFIG,
22 PERF_PMU_FORMAT_VALUE_CONFIG1,
23 PERF_PMU_FORMAT_VALUE_CONFIG2,
204e7c49 24 PERF_PMU_FORMAT_VALUE_CONFIG3,
e552b7be 25 PERF_PMU_FORMAT_VALUE_CONFIG_END,
cd82a32e
JO
26};
27
28#define PERF_PMU_FORMAT_BITS 64
13d60ba0 29#define MAX_PMU_NAME_LEN 128
cd82a32e 30
dc0a6202
AH
31struct perf_event_attr;
32
9fbc61f8
KL
33struct perf_pmu_caps {
34 char *name;
35 char *value;
36 struct list_head list;
37};
38
fe13d43d 39/**
240e6fd0 40 * struct perf_pmu
fe13d43d 41 */
cd82a32e 42struct perf_pmu {
fe13d43d 43 /** @name: The name of the PMU such as "cpu". */
c091ee90 44 const char *name;
fe13d43d
IR
45 /**
46 * @alias_name: Optional alternate name for the PMU determined in
47 * architecture specific code.
48 */
13d60ba0 49 char *alias_name;
fe13d43d
IR
50 /**
51 * @id: Optional PMU identifier read from
52 * <sysfs>/bus/event_source/devices/<name>/identifier.
53 */
b7823045 54 const char *id;
fe13d43d
IR
55 /**
56 * @type: Perf event attributed type value, read from
57 * <sysfs>/bus/event_source/devices/<name>/type.
58 */
cd82a32e 59 __u32 type;
fe13d43d
IR
60 /**
61 * @selectable: Can the PMU name be selected as if it were an event?
62 */
42634bc7 63 bool selectable;
e20d1f2f
IR
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;
fe13d43d
IR
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 */
66ec1191 75 bool is_uncore;
fe13d43d
IR
76 /**
77 * @auxtrace: Are events auxiliary events? Determined in architecture
78 * specific code.
79 */
f0bb7ee8 80 bool auxtrace;
68c25043
IR
81 /**
82 * @formats_checked: Only check PMU's formats are valid for
83 * perf_event_attr once.
84 */
85 bool formats_checked;
b9f01032
IR
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;
fe13d43d
IR
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 */
90a86bde 95 int max_precise;
fe13d43d 96 /**
0197da7a
IR
97 * @perf_event_attr_init_default: Optional function to default
98 * initialize PMU specific parts of the perf_event_attr.
fe13d43d 99 */
0197da7a
IR
100 void (*perf_event_attr_init_default)(const struct perf_pmu *pmu,
101 struct perf_event_attr *attr);
fe13d43d
IR
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 */
f854839b 107 struct perf_cpu_map *cpus;
fe13d43d
IR
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;
7c52f10c
IR
120 /**
121 * @events_table: The events table for json events in pmu-events.c.
122 */
123 const struct pmu_events_table *events_table;
e6ff1eed
IR
124 /** @sysfs_aliases: Number of sysfs aliases loaded. */
125 uint32_t sysfs_aliases;
126 /** @sysfs_aliases: Number of json event aliases loaded. */
127 uint32_t loaded_json_aliases;
8d4b6d37
IR
128 /** @sysfs_aliases_loaded: Are sysfs aliases loaded from disk? */
129 bool sysfs_aliases_loaded;
e6ff1eed
IR
130 /**
131 * @cpu_aliases_added: Have all json events table entries for the PMU
132 * been added?
133 */
134 bool cpu_aliases_added;
fe13d43d 135 /** @caps_initialized: Has the list caps been initialized? */
3339ec44 136 bool caps_initialized;
fe13d43d 137 /** @nr_caps: The length of the list caps. */
3339ec44 138 u32 nr_caps;
fe13d43d
IR
139 /**
140 * @caps: Holds the contents of files read from
141 * <sysfs>/bus/event_source/devices/<name>/caps/.
142 *
143 * The contents are pairs of the filename with the value of its
144 * contents, for example, max_precise (see above) may have a value of 3.
145 */
146 struct list_head caps;
147 /** @list: Element on pmus list in pmu.c. */
148 struct list_head list;
3500eeeb 149
b9f01032
IR
150 /**
151 * @config_masks: Derived from the PMU's format data, bits that are
152 * valid within the config value.
153 */
154 __u64 config_masks[PERF_PMU_FORMAT_VALUE_CONFIG_END];
155
fe13d43d
IR
156 /**
157 * @missing_features: Features to inhibit when events on this PMU are
158 * opened.
159 */
3500eeeb 160 struct {
fe13d43d
IR
161 /**
162 * @exclude_guest: Disables perf_event_attr exclude_guest and
163 * exclude_host.
164 */
3500eeeb
NK
165 bool exclude_guest;
166 } missing_features;
bb65acdc
KL
167
168 /**
169 * @mem_events: List of the supported mem events
170 */
171 struct perf_mem_event *mem_events;
cd82a32e
JO
172};
173
fe13d43d 174/** @perf_pmu__fake: A special global PMU used for testing. */
e46fc8d9
ACM
175extern struct perf_pmu perf_pmu__fake;
176
46441bdc
MF
177struct perf_pmu_info {
178 const char *unit;
179 double scale;
044330c1 180 bool per_pkg;
1d9e446b 181 bool snapshot;
46441bdc
MF
182};
183
c3245d20
IR
184struct pmu_event_info {
185 const struct perf_pmu *pmu;
186 const char *name;
187 const char* alias;
188 const char *scale_unit;
189 const char *desc;
190 const char *long_desc;
191 const char *encoding_desc;
192 const char *topic;
193 const char *pmu_name;
194 const char *str;
a7f6c8c8 195 bool deprecated;
dcb4e102
KL
196};
197
c3245d20
IR
198typedef int (*pmu_event_callback)(void *state, struct pmu_event_info *info);
199
838a8c5f 200void pmu_add_sys_aliases(struct perf_pmu *pmu);
cd82a32e 201int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
0d3f0e6f 202 struct parse_events_terms *head_terms,
e64b020b 203 struct parse_events_error *error);
63883cb0 204int perf_pmu__config_terms(const struct perf_pmu *pmu,
cff7f956 205 struct perf_event_attr *attr,
0d3f0e6f 206 struct parse_events_terms *terms,
e64b020b 207 bool zero, struct parse_events_error *error);
da6a5afd 208__u64 perf_pmu__format_bits(struct perf_pmu *pmu, const char *name);
7eb54733 209int perf_pmu__format_type(struct perf_pmu *pmu, const char *name);
0d3f0e6f 210int perf_pmu__check_alias(struct perf_pmu *pmu, struct parse_events_terms *head_terms,
a24d9d9d
IR
211 struct perf_pmu_info *info, bool *rewrote_terms,
212 struct parse_events_error *err);
c3245d20 213int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *state, pmu_event_callback cb);
cd82a32e 214
50402641
IR
215int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool eager_load);
216void perf_pmu_format__set_value(void *format, int config, unsigned long *bits);
07d2b820 217bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name);
cd82a32e 218
d504fae9 219bool is_pmu_core(const char *name);
6fd1e519 220bool perf_pmu__supports_legacy_cache(const struct perf_pmu *pmu);
52c7b4d3 221bool perf_pmu__auto_merge_stats(const struct perf_pmu *pmu);
e6ff1eed
IR
222bool perf_pmu__have_event(struct perf_pmu *pmu, const char *name);
223size_t perf_pmu__num_events(struct perf_pmu *pmu);
cd4e1efb
IR
224int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus,
225 void *state, pmu_event_callback cb);
e3edd6cf 226bool pmu__name_match(const struct perf_pmu *pmu, const char *pmu_name);
c3245d20 227
251aa040
IR
228/**
229 * perf_pmu_is_software - is the PMU a software PMU as in it uses the
230 * perf_sw_context in the kernel?
231 */
232bool perf_pmu__is_software(const struct perf_pmu *pmu);
dc098b35 233
3a42f4c7
IR
234FILE *perf_pmu__open_file(const struct perf_pmu *pmu, const char *name);
235FILE *perf_pmu__open_file_at(const struct perf_pmu *pmu, int dirfd, const char *name);
3a69672e 236
3a42f4c7
IR
237int perf_pmu__scan_file(const struct perf_pmu *pmu, const char *name, const char *fmt, ...)
238 __scanf(3, 4);
239int perf_pmu__scan_file_at(const struct perf_pmu *pmu, int dirfd, const char *name,
3a69672e 240 const char *fmt, ...) __scanf(4, 5);
7d4bdab5 241
3a42f4c7 242bool perf_pmu__file_exists(const struct perf_pmu *pmu, const char *name);
c2b6a896 243
cd82a32e 244int perf_pmu__test(void);
dc0a6202 245
aa613601 246void perf_pmu__arch_init(struct perf_pmu *pmu);
838a8c5f 247void pmu_add_cpu_aliases_table(struct perf_pmu *pmu,
1ba3752a 248 const struct pmu_events_table *table);
dc0a6202 249
29be2fe0 250char *perf_pmu__getcpuid(struct perf_pmu *pmu);
f8ea2c15 251const struct pmu_metrics_table *pmu_metrics_table__find(void);
2879ff36 252bool pmu_uncore_identifier_match(const char *compat, const char *id);
d77ade9f 253
a55ab7c4
JY
254int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
255
9fbc61f8
KL
256int perf_pmu__caps_parse(struct perf_pmu *pmu);
257
e4064776 258void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
b9f01032
IR
259 const char *name, int config_num,
260 const char *config_name);
e552b7be 261void perf_pmu__warn_invalid_formats(struct perf_pmu *pmu);
e4064776 262
c091ee90 263int perf_pmu__match(const char *pattern, const char *name, const char *tok);
c5a26ea4 264
acef233b 265double perf_pmu__cpu_slots_per_cycle(void);
f8ad6018
JC
266int perf_pmu__event_source_devices_scnprintf(char *pathname, size_t size);
267int perf_pmu__pathname_scnprintf(char *buf, size_t size,
268 const char *pmu_name, const char *filename);
e293a5e8
NK
269int perf_pmu__event_source_devices_fd(void);
270int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename, int flags);
f8ad6018 271
1eaf496e 272struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name);
628eaa4e 273struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pmus);
1eaf496e 274void perf_pmu__delete(struct perf_pmu *pmu);
3d0f5f45 275struct perf_pmu *perf_pmus__find_core_pmu(void);
eec11310 276
cd82a32e 277#endif /* __PMU_H */