Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 2 | #ifndef __PMU_H |
| 3 | #define __PMU_H |
| 4 | |
Borislav Petkov | d944c4e | 2014-04-25 21:31:02 +0200 | [diff] [blame] | 5 | #include <linux/bitmap.h> |
Arnaldo Carvalho de Melo | 3ee350f | 2017-06-16 11:57:54 -0300 | [diff] [blame] | 6 | #include <linux/compiler.h> |
David Howells | d2709c7 | 2012-11-19 22:21:03 +0000 | [diff] [blame] | 7 | #include <linux/perf_event.h> |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 8 | #include <stdbool.h> |
Mathieu Poirier | 859442b | 2016-09-16 09:50:02 -0600 | [diff] [blame] | 9 | #include "evsel.h" |
Jiri Olsa | e64b020 | 2015-04-22 21:10:21 +0200 | [diff] [blame] | 10 | #include "parse-events.h" |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 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 | |
Adrian Hunter | dc0a620 | 2014-07-31 09:00:49 +0300 | [diff] [blame] | 20 | struct perf_event_attr; |
| 21 | |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 22 | struct perf_pmu { |
| 23 | char *name; |
| 24 | __u32 type; |
Adrian Hunter | 42634bc | 2014-10-23 13:45:10 +0300 | [diff] [blame] | 25 | bool selectable; |
Mark Rutland | 66ec1191 | 2017-10-06 19:38:22 +0100 | [diff] [blame] | 26 | bool is_uncore; |
Adrian Hunter | dc0a620 | 2014-07-31 09:00:49 +0300 | [diff] [blame] | 27 | struct perf_event_attr *default_config; |
Yan, Zheng | 7ae92e7 | 2012-09-10 15:53:50 +0800 | [diff] [blame] | 28 | struct cpu_map *cpus; |
Cody P Schafer | 885b593 | 2014-08-15 00:26:14 -0700 | [diff] [blame] | 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 */ |
Mathieu Poirier | 859442b | 2016-09-16 09:50:02 -0600 | [diff] [blame] | 32 | int (*set_drv_config) (struct perf_evsel_config_term *term); |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 33 | }; |
| 34 | |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 35 | struct perf_pmu_info { |
| 36 | const char *unit; |
Andi Kleen | 37932c1 | 2017-03-20 13:17:08 -0700 | [diff] [blame] | 37 | const char *metric_expr; |
Andi Kleen | 9628481 | 2017-03-20 13:17:10 -0700 | [diff] [blame] | 38 | const char *metric_name; |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 39 | double scale; |
Matt Fleming | 044330c | 2014-11-21 10:31:12 +0100 | [diff] [blame] | 40 | bool per_pkg; |
Jiri Olsa | 1d9e446 | 2014-11-21 10:31:13 +0100 | [diff] [blame] | 41 | bool snapshot; |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 44 | #define UNIT_MAX_LEN 31 /* max length for event unit name */ |
| 45 | |
| 46 | struct perf_pmu_alias { |
| 47 | char *name; |
Andi Kleen | 08e60ed | 2016-09-15 15:24:43 -0700 | [diff] [blame] | 48 | char *desc; |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 49 | char *long_desc; |
Andi Kleen | dd5f103 | 2016-09-15 15:24:50 -0700 | [diff] [blame] | 50 | char *topic; |
Andi Kleen | f236102 | 2017-01-27 18:03:40 -0800 | [diff] [blame] | 51 | char *str; |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 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; |
Matt Fleming | 044330c | 2014-11-21 10:31:12 +0100 | [diff] [blame] | 56 | bool per_pkg; |
Jiri Olsa | 1d9e446 | 2014-11-21 10:31:13 +0100 | [diff] [blame] | 57 | bool snapshot; |
Andi Kleen | 00636c3 | 2017-03-20 13:17:07 -0700 | [diff] [blame] | 58 | char *metric_expr; |
Andi Kleen | 9628481 | 2017-03-20 13:17:10 -0700 | [diff] [blame] | 59 | char *metric_name; |
Kan Liang | dcb4e10 | 2014-10-07 11:08:50 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
Adrian Hunter | b6b96fb | 2013-07-04 16:20:25 +0300 | [diff] [blame] | 62 | struct perf_pmu *perf_pmu__find(const char *name); |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 63 | int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, |
Jiri Olsa | e64b020 | 2015-04-22 21:10:21 +0200 | [diff] [blame] | 64 | struct list_head *head_terms, |
| 65 | struct parse_events_error *error); |
Jiri Olsa | cff7f95 | 2012-11-10 01:46:50 +0100 | [diff] [blame] | 66 | int perf_pmu__config_terms(struct list_head *formats, |
| 67 | struct perf_event_attr *attr, |
Adrian Hunter | dc0a620 | 2014-07-31 09:00:49 +0300 | [diff] [blame] | 68 | struct list_head *head_terms, |
Jiri Olsa | e64b020 | 2015-04-22 21:10:21 +0200 | [diff] [blame] | 69 | bool zero, struct parse_events_error *error); |
Adrian Hunter | 09ff607 | 2015-07-17 19:33:49 +0300 | [diff] [blame] | 70 | __u64 perf_pmu__format_bits(struct list_head *formats, const char *name); |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 71 | int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, |
Matt Fleming | 46441bd | 2014-09-24 15:04:06 +0100 | [diff] [blame] | 72 | struct perf_pmu_info *info); |
Zheng Yan | a6146d5 | 2012-06-15 14:31:41 +0800 | [diff] [blame] | 73 | struct list_head *perf_pmu__alias(struct perf_pmu *pmu, |
Arnaldo Carvalho de Melo | 5c6ccc3 | 2013-01-18 16:54:00 -0300 | [diff] [blame] | 74 | struct list_head *head_terms); |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 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); |
Jiri Olsa | cff7f95 | 2012-11-10 01:46:50 +0100 | [diff] [blame] | 81 | int perf_pmu__format_parse(char *dir, struct list_head *head); |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 82 | |
Robert Richter | 50a9667 | 2012-08-16 21:10:24 +0200 | [diff] [blame] | 83 | struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu); |
| 84 | |
Sukadev Bhattiprolu | c8d6828 | 2016-09-15 15:24:48 -0700 | [diff] [blame] | 85 | void print_pmu_events(const char *event_glob, bool name_only, bool quiet, |
Andi Kleen | bf874fc | 2017-03-20 13:17:11 -0700 | [diff] [blame] | 86 | bool long_desc, bool details_flag); |
Andi Kleen | 4cabc3d | 2013-08-21 16:47:26 -0700 | [diff] [blame] | 87 | bool pmu_have_event(const char *pname, const char *name); |
Andi Kleen | dc098b3 | 2013-04-20 11:02:29 -0700 | [diff] [blame] | 88 | |
Arnaldo Carvalho de Melo | 3ee350f | 2017-06-16 11:57:54 -0300 | [diff] [blame] | 89 | int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4); |
Adrian Hunter | 7d4bdab | 2014-07-31 09:00:50 +0300 | [diff] [blame] | 90 | |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 91 | int perf_pmu__test(void); |
Adrian Hunter | dc0a620 | 2014-07-31 09:00:49 +0300 | [diff] [blame] | 92 | |
| 93 | struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); |
| 94 | |
Ganapatrao Kulkarni | 54e32dc | 2017-10-17 00:02:18 +0530 | [diff] [blame] | 95 | struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu); |
Andi Kleen | d77ade9 | 2017-08-31 12:40:30 -0700 | [diff] [blame] | 96 | |
Jiri Olsa | cd82a32 | 2012-03-15 20:09:17 +0100 | [diff] [blame] | 97 | #endif /* __PMU_H */ |