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