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