blob: 76fecec7b3f919b2d41be0c67d36ce977bdbd8dd [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jiri Olsacd82a322012-03-15 20:09:17 +01002#ifndef __PMU_H
3#define __PMU_H
4
Borislav Petkovd944c4e2014-04-25 21:31:02 +02005#include <linux/bitmap.h>
Arnaldo Carvalho de Melo3ee350f2017-06-16 11:57:54 -03006#include <linux/compiler.h>
David Howellsd2709c72012-11-19 22:21:03 +00007#include <linux/perf_event.h>
Andi Kleendc098b32013-04-20 11:02:29 -07008#include <stdbool.h>
Mathieu Poirier859442b2016-09-16 09:50:02 -06009#include "evsel.h"
Jiri Olsae64b0202015-04-22 21:10:21 +020010#include "parse-events.h"
Jiri Olsacd82a322012-03-15 20:09:17 +010011
12enum {
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 Hunterdc0a6202014-07-31 09:00:49 +030020struct perf_event_attr;
21
Jiri Olsacd82a322012-03-15 20:09:17 +010022struct perf_pmu {
23 char *name;
24 __u32 type;
Adrian Hunter42634bc2014-10-23 13:45:10 +030025 bool selectable;
Mark Rutland66ec11912017-10-06 19:38:22 +010026 bool is_uncore;
Adrian Hunterdc0a6202014-07-31 09:00:49 +030027 struct perf_event_attr *default_config;
Yan, Zheng7ae92e72012-09-10 15:53:50 +080028 struct cpu_map *cpus;
Cody P Schafer885b5932014-08-15 00:26:14 -070029 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 Poirier859442b2016-09-16 09:50:02 -060032 int (*set_drv_config) (struct perf_evsel_config_term *term);
Jiri Olsacd82a322012-03-15 20:09:17 +010033};
34
Matt Fleming46441bd2014-09-24 15:04:06 +010035struct perf_pmu_info {
36 const char *unit;
Andi Kleen37932c12017-03-20 13:17:08 -070037 const char *metric_expr;
Andi Kleen96284812017-03-20 13:17:10 -070038 const char *metric_name;
Matt Fleming46441bd2014-09-24 15:04:06 +010039 double scale;
Matt Fleming044330c2014-11-21 10:31:12 +010040 bool per_pkg;
Jiri Olsa1d9e4462014-11-21 10:31:13 +010041 bool snapshot;
Matt Fleming46441bd2014-09-24 15:04:06 +010042};
43
Kan Liangdcb4e102014-10-07 11:08:50 -040044#define UNIT_MAX_LEN 31 /* max length for event unit name */
45
46struct perf_pmu_alias {
47 char *name;
Andi Kleen08e60ed2016-09-15 15:24:43 -070048 char *desc;
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070049 char *long_desc;
Andi Kleendd5f1032016-09-15 15:24:50 -070050 char *topic;
Andi Kleenf2361022017-01-27 18:03:40 -080051 char *str;
Kan Liangdcb4e102014-10-07 11:08:50 -040052 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 Fleming044330c2014-11-21 10:31:12 +010056 bool per_pkg;
Jiri Olsa1d9e4462014-11-21 10:31:13 +010057 bool snapshot;
Andi Kleen00636c32017-03-20 13:17:07 -070058 char *metric_expr;
Andi Kleen96284812017-03-20 13:17:10 -070059 char *metric_name;
Kan Liangdcb4e102014-10-07 11:08:50 -040060};
61
Adrian Hunterb6b96fb2013-07-04 16:20:25 +030062struct perf_pmu *perf_pmu__find(const char *name);
Jiri Olsacd82a322012-03-15 20:09:17 +010063int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
Jiri Olsae64b0202015-04-22 21:10:21 +020064 struct list_head *head_terms,
65 struct parse_events_error *error);
Jiri Olsacff7f952012-11-10 01:46:50 +010066int perf_pmu__config_terms(struct list_head *formats,
67 struct perf_event_attr *attr,
Adrian Hunterdc0a6202014-07-31 09:00:49 +030068 struct list_head *head_terms,
Jiri Olsae64b0202015-04-22 21:10:21 +020069 bool zero, struct parse_events_error *error);
Adrian Hunter09ff6072015-07-17 19:33:49 +030070__u64 perf_pmu__format_bits(struct list_head *formats, const char *name);
Stephane Eranian410136f2013-11-12 17:58:49 +010071int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
Matt Fleming46441bd2014-09-24 15:04:06 +010072 struct perf_pmu_info *info);
Zheng Yana6146d52012-06-15 14:31:41 +080073struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
Arnaldo Carvalho de Melo5c6ccc32013-01-18 16:54:00 -030074 struct list_head *head_terms);
Jiri Olsacd82a322012-03-15 20:09:17 +010075int perf_pmu_wrap(void);
76void perf_pmu_error(struct list_head *list, char *name, char const *msg);
77
78int perf_pmu__new_format(struct list_head *list, char *name,
79 int config, unsigned long *bits);
80void perf_pmu__set_format(unsigned long *bits, long from, long to);
Jiri Olsacff7f952012-11-10 01:46:50 +010081int perf_pmu__format_parse(char *dir, struct list_head *head);
Jiri Olsacd82a322012-03-15 20:09:17 +010082
Robert Richter50a96672012-08-16 21:10:24 +020083struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu);
84
Sukadev Bhattiproluc8d68282016-09-15 15:24:48 -070085void print_pmu_events(const char *event_glob, bool name_only, bool quiet,
Andi Kleenbf874fc2017-03-20 13:17:11 -070086 bool long_desc, bool details_flag);
Andi Kleen4cabc3d2013-08-21 16:47:26 -070087bool pmu_have_event(const char *pname, const char *name);
Andi Kleendc098b32013-04-20 11:02:29 -070088
Arnaldo Carvalho de Melo3ee350f2017-06-16 11:57:54 -030089int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt, ...) __scanf(3, 4);
Adrian Hunter7d4bdab2014-07-31 09:00:50 +030090
Jiri Olsacd82a322012-03-15 20:09:17 +010091int perf_pmu__test(void);
Adrian Hunterdc0a6202014-07-31 09:00:49 +030092
93struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
94
Ganapatrao Kulkarni54e32dc2017-10-17 00:02:18 +053095struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu);
Andi Kleend77ade92017-08-31 12:40:30 -070096
Jiri Olsacd82a322012-03-15 20:09:17 +010097#endif /* __PMU_H */