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