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