xref: /linux/tools/perf/util/pmu.h (revision 6fdcba32711044c35c0e1b094cbd8f3f0b4472c9)
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 <stdbool.h>
9 #include "parse-events.h"
10 
11 struct perf_evsel_config_term;
12 
13 enum {
14 	PERF_PMU_FORMAT_VALUE_CONFIG,
15 	PERF_PMU_FORMAT_VALUE_CONFIG1,
16 	PERF_PMU_FORMAT_VALUE_CONFIG2,
17 };
18 
19 #define PERF_PMU_FORMAT_BITS 64
20 #define EVENT_SOURCE_DEVICE_PATH "/bus/event_source/devices/"
21 
22 struct perf_event_attr;
23 
24 struct perf_pmu {
25 	char *name;
26 	__u32 type;
27 	bool selectable;
28 	bool is_uncore;
29 	bool auxtrace;
30 	int max_precise;
31 	struct perf_event_attr *default_config;
32 	struct perf_cpu_map *cpus;
33 	struct list_head format;  /* HEAD struct perf_pmu_format -> list */
34 	struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */
35 	struct list_head list;    /* ELEM */
36 };
37 
38 struct perf_pmu_info {
39 	const char *unit;
40 	const char *metric_expr;
41 	const char *metric_name;
42 	double scale;
43 	bool per_pkg;
44 	bool snapshot;
45 };
46 
47 #define UNIT_MAX_LEN	31 /* max length for event unit name */
48 
49 struct perf_pmu_alias {
50 	char *name;
51 	char *desc;
52 	char *long_desc;
53 	char *topic;
54 	char *str;
55 	struct list_head terms; /* HEAD struct parse_events_term -> list */
56 	struct list_head list;  /* ELEM */
57 	char unit[UNIT_MAX_LEN+1];
58 	double scale;
59 	bool per_pkg;
60 	bool snapshot;
61 	bool deprecated;
62 	char *metric_expr;
63 	char *metric_name;
64 };
65 
66 struct perf_pmu *perf_pmu__find(const char *name);
67 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
68 		     struct list_head *head_terms,
69 		     struct parse_events_error *error);
70 int perf_pmu__config_terms(struct list_head *formats,
71 			   struct perf_event_attr *attr,
72 			   struct list_head *head_terms,
73 			   bool zero, struct parse_events_error *error);
74 __u64 perf_pmu__format_bits(struct list_head *formats, const char *name);
75 int perf_pmu__format_type(struct list_head *formats, const char *name);
76 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
77 			  struct perf_pmu_info *info);
78 struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
79 				  struct list_head *head_terms);
80 int perf_pmu_wrap(void);
81 void perf_pmu_error(struct list_head *list, char *name, char const *msg);
82 
83 int perf_pmu__new_format(struct list_head *list, char *name,
84 			 int config, unsigned long *bits);
85 void perf_pmu__set_format(unsigned long *bits, long from, long to);
86 int perf_pmu__format_parse(char *dir, struct list_head *head);
87 
88 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
89 
90 void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
91 		      bool long_desc, bool details_flag,
92 		      bool deprecated);
93 bool pmu_have_event(const char *pname, const char *name);
94 
95 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4);
96 
97 int perf_pmu__test(void);
98 
99 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
100 
101 struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu);
102 
103 int perf_pmu__convert_scale(const char *scale, char **end, double *sval);
104 
105 #endif /* __PMU_H */
106