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