xref: /linux/tools/perf/pmu-events/pmu-events.h (revision df9c299371054cb725eef730fd0f1d0fe2ed6bb0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PMU_EVENTS_H
3 #define PMU_EVENTS_H
4 
5 #include <stdbool.h>
6 #include <stddef.h>
7 
8 struct perf_pmu;
9 
10 enum aggr_mode_class {
11 	PerChip = 1,
12 	PerCore
13 };
14 
15 /**
16  * enum metric_event_groups - How events within a pmu_metric should be grouped.
17  */
18 enum metric_event_groups {
19 	/**
20 	 * @MetricGroupEvents: Default, group events within the metric.
21 	 */
22 	MetricGroupEvents = 0,
23 	/**
24 	 * @MetricNoGroupEvents: Don't group events for the metric.
25 	 */
26 	MetricNoGroupEvents = 1,
27 	/**
28 	 * @MetricNoGroupEventsNmi: Don't group events for the metric if the NMI
29 	 *                          watchdog is enabled.
30 	 */
31 	MetricNoGroupEventsNmi = 2,
32 	/**
33 	 * @MetricNoGroupEventsSmt: Don't group events for the metric if SMT is
34 	 *                          enabled.
35 	 */
36 	MetricNoGroupEventsSmt = 3,
37 };
38 /*
39  * Describe each PMU event. Each CPU has a table of PMU events.
40  */
41 struct pmu_event {
42 	const char *name;
43 	const char *compat;
44 	const char *event;
45 	const char *desc;
46 	const char *topic;
47 	const char *long_desc;
48 	const char *pmu;
49 	const char *unit;
50 	const char *retirement_latency_mean;
51 	const char *retirement_latency_min;
52 	const char *retirement_latency_max;
53 	bool perpkg;
54 	bool deprecated;
55 };
56 
57 struct pmu_metric {
58 	const char *pmu;
59 	const char *metric_name;
60 	const char *metric_group;
61 	const char *metric_expr;
62 	const char *metric_threshold;
63 	const char *unit;
64 	const char *compat;
65 	const char *desc;
66 	const char *long_desc;
67 	const char *metricgroup_no_group;
68 	const char *default_metricgroup_name;
69 	enum aggr_mode_class aggr_mode;
70 	enum metric_event_groups event_grouping;
71 };
72 
73 struct pmu_events_table;
74 struct pmu_metrics_table;
75 
76 #define PMU_EVENTS__NOT_FOUND -1000
77 #define PMU_METRICS__NOT_FOUND -1000
78 
79 typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe,
80 				 const struct pmu_events_table *table,
81 				 void *data);
82 
83 typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm,
84 				  const struct pmu_metrics_table *table,
85 				  void *data);
86 
87 int pmu_events_table__for_each_event(const struct pmu_events_table *table,
88 				    struct perf_pmu *pmu,
89 				    pmu_event_iter_fn fn,
90 				    void *data);
91 /*
92  * Search for a table and entry matching with pmu__name_wildcard_match or any
93  * tables if pmu is NULL. Each matching event has fn called on it. 0 implies to
94  * success/continue the search while non-zero means to terminate. The special
95  * value PMU_EVENTS__NOT_FOUND is used to indicate no event was found in one of
96  * the tables which doesn't terminate the search of all tables.
97  */
98 int pmu_events_table__find_event(const struct pmu_events_table *table,
99                                  struct perf_pmu *pmu,
100                                  const char *name,
101                                  pmu_event_iter_fn fn,
102 				 void *data);
103 size_t pmu_events_table__num_events(const struct pmu_events_table *table,
104 				    struct perf_pmu *pmu);
105 
106 int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn,
107 				     void *data);
108 /*
109  * Search for a table and entry matching with pmu__name_wildcard_match or any
110  * tables if pmu is NULL. Each matching metric has fn called on it. 0 implies to
111  * success/continue the search while non-zero means to terminate. The special
112  * value PMU_METRICS__NOT_FOUND is used to indicate no metric was found in one
113  * of the tables which doesn't terminate the search of all tables.
114  */
115 int pmu_metrics_table__find_metric(const struct pmu_metrics_table *table,
116 				   struct perf_pmu *pmu,
117 				   const char *metric,
118 				   pmu_metric_iter_fn fn,
119 				   void *data);
120 
121 const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu);
122 const struct pmu_metrics_table *pmu_metrics_table__find(void);
123 const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid);
124 const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid);
125 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data);
126 int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data);
127 
128 const struct pmu_events_table *find_sys_events_table(const char *name);
129 const struct pmu_metrics_table *find_sys_metrics_table(const char *name);
130 int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data);
131 int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data);
132 
133 const char *describe_metricgroup(const char *group);
134 
135 #endif
136