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