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