1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PMU_EVENTS_H
3 #define PMU_EVENTS_H
4 
5 #include <stdbool.h>
6 
7 struct perf_pmu;
8 
9 enum aggr_mode_class {
10 	PerChip = 1,
11 	PerCore
12 };
13 
14 /**
15  * enum metric_event_groups - How events within a pmu_metric should be grouped.
16  */
17 enum metric_event_groups {
18 	/**
19 	 * @MetricGroupEvents: Default, group events within the metric.
20 	 */
21 	MetricGroupEvents = 0,
22 	/**
23 	 * @MetricNoGroupEvents: Don't group events for the metric.
24 	 */
25 	MetricNoGroupEvents = 1,
26 	/**
27 	 * @MetricNoGroupEventsNmi: Don't group events for the metric if the NMI
28 	 *                          watchdog is enabled.
29 	 */
30 	MetricNoGroupEventsNmi = 2,
31 	/**
32 	 * @MetricNoGroupEventsSmt: Don't group events for the metric if SMT is
33 	 *                          enabled.
34 	 */
35 	MetricNoGroupEventsSmt = 3,
36 };
37 /*
38  * Describe each PMU event. Each CPU has a table of PMU events.
39  */
40 struct pmu_event {
41 	const char *name;
42 	const char *compat;
43 	const char *event;
44 	const char *desc;
45 	const char *topic;
46 	const char *long_desc;
47 	const char *pmu;
48 	const char *unit;
49 	bool perpkg;
50 	bool deprecated;
51 };
52 
53 struct pmu_metric {
54 	const char *pmu;
55 	const char *metric_name;
56 	const char *metric_group;
57 	const char *metric_expr;
58 	const char *metric_threshold;
59 	const char *unit;
60 	const char *compat;
61 	const char *desc;
62 	const char *long_desc;
63 	const char *metricgroup_no_group;
64 	const char *default_metricgroup_name;
65 	enum aggr_mode_class aggr_mode;
66 	enum metric_event_groups event_grouping;
67 };
68 
69 struct pmu_events_table;
70 struct pmu_metrics_table;
71 
72 typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe,
73 				 const struct pmu_events_table *table,
74 				 void *data);
75 
76 typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm,
77 				  const struct pmu_metrics_table *table,
78 				  void *data);
79 
80 int pmu_events_table_for_each_event(const struct pmu_events_table *table, pmu_event_iter_fn fn,
81 				    void *data);
82 int pmu_metrics_table_for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn,
83 				     void *data);
84 
85 const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu);
86 const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu);
87 const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid);
88 const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid);
89 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data);
90 int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data);
91 
92 const struct pmu_events_table *find_sys_events_table(const char *name);
93 const struct pmu_metrics_table *find_sys_metrics_table(const char *name);
94 int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data);
95 int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data);
96 
97 const char *describe_metricgroup(const char *group);
98 
99 #endif
100