xref: /linux/tools/perf/util/pmu.h (revision 4359a011e259a4608afc7fb3635370c9d4ba5943)
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 
13 struct evsel_config_term;
14 struct perf_cpu_map;
15 
16 enum {
17 	PERF_PMU_FORMAT_VALUE_CONFIG,
18 	PERF_PMU_FORMAT_VALUE_CONFIG1,
19 	PERF_PMU_FORMAT_VALUE_CONFIG2,
20 };
21 
22 #define PERF_PMU_FORMAT_BITS 64
23 #define EVENT_SOURCE_DEVICE_PATH "/bus/event_source/devices/"
24 #define CPUS_TEMPLATE_CPU	"%s/bus/event_source/devices/%s/cpus"
25 #define MAX_PMU_NAME_LEN 128
26 
27 struct perf_event_attr;
28 
29 struct perf_pmu_caps {
30 	char *name;
31 	char *value;
32 	struct list_head list;
33 };
34 
35 struct perf_pmu {
36 	char *name;
37 	char *alias_name;
38 	char *id;
39 	__u32 type;
40 	bool selectable;
41 	bool is_uncore;
42 	bool is_hybrid;
43 	bool auxtrace;
44 	int max_precise;
45 	struct perf_event_attr *default_config;
46 	struct perf_cpu_map *cpus;
47 	struct list_head format;  /* HEAD struct perf_pmu_format -> list */
48 	struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */
49 	bool caps_initialized;
50 	u32 nr_caps;
51 	struct list_head caps;    /* HEAD struct perf_pmu_caps -> list */
52 	struct list_head list;    /* ELEM */
53 	struct list_head hybrid_list;
54 
55 	struct {
56 		bool exclude_guest;
57 	} missing_features;
58 };
59 
60 extern struct perf_pmu perf_pmu__fake;
61 
62 struct perf_pmu_info {
63 	const char *unit;
64 	const char *metric_expr;
65 	const char *metric_name;
66 	double scale;
67 	bool per_pkg;
68 	bool snapshot;
69 };
70 
71 #define UNIT_MAX_LEN	31 /* max length for event unit name */
72 
73 struct perf_pmu_alias {
74 	char *name;
75 	char *desc;
76 	char *long_desc;
77 	char *topic;
78 	char *str;
79 	struct list_head terms; /* HEAD struct parse_events_term -> list */
80 	struct list_head list;  /* ELEM */
81 	char unit[UNIT_MAX_LEN+1];
82 	double scale;
83 	bool per_pkg;
84 	bool snapshot;
85 	bool deprecated;
86 	char *metric_expr;
87 	char *metric_name;
88 	char *pmu_name;
89 };
90 
91 struct perf_pmu *perf_pmu__find(const char *name);
92 struct perf_pmu *perf_pmu__find_by_type(unsigned int type);
93 void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu);
94 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
95 		     struct list_head *head_terms,
96 		     struct parse_events_error *error);
97 int perf_pmu__config_terms(const char *pmu_name, struct list_head *formats,
98 			   struct perf_event_attr *attr,
99 			   struct list_head *head_terms,
100 			   bool zero, struct parse_events_error *error);
101 __u64 perf_pmu__format_bits(struct list_head *formats, const char *name);
102 int perf_pmu__format_type(struct list_head *formats, const char *name);
103 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
104 			  struct perf_pmu_info *info);
105 struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
106 				  struct list_head *head_terms);
107 void perf_pmu_error(struct list_head *list, char *name, char const *msg);
108 
109 int perf_pmu__new_format(struct list_head *list, char *name,
110 			 int config, unsigned long *bits);
111 void perf_pmu__set_format(unsigned long *bits, long from, long to);
112 int perf_pmu__format_parse(char *dir, struct list_head *head);
113 void perf_pmu__del_formats(struct list_head *formats);
114 
115 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
116 
117 bool is_pmu_core(const char *name);
118 void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
119 		      bool long_desc, bool details_flag,
120 		      bool deprecated, const char *pmu_name);
121 bool pmu_have_event(const char *pname, const char *name);
122 
123 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4);
124 
125 int perf_pmu__test(void);
126 
127 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
128 void pmu_add_cpu_aliases_table(struct list_head *head, struct perf_pmu *pmu,
129 			       const struct pmu_events_table *table);
130 
131 char *perf_pmu__getcpuid(struct perf_pmu *pmu);
132 const struct pmu_events_table *pmu_events_table__find(void);
133 bool pmu_uncore_alias_match(const char *pmu_name, const char *name);
134 void perf_pmu_free_alias(struct perf_pmu_alias *alias);
135 
136 int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
137 
138 int perf_pmu__caps_parse(struct perf_pmu *pmu);
139 
140 void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config,
141 				   const char *name);
142 
143 bool perf_pmu__has_hybrid(void);
144 int perf_pmu__match(char *pattern, char *name, char *tok);
145 
146 int perf_pmu__cpus_match(struct perf_pmu *pmu, struct perf_cpu_map *cpus,
147 			 struct perf_cpu_map **mcpus_ptr,
148 			 struct perf_cpu_map **ucpus_ptr);
149 
150 char *pmu_find_real_name(const char *name);
151 char *pmu_find_alias_name(const char *name);
152 #endif /* __PMU_H */
153