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

source code of linux/tools/perf/pmu-events/pmu-events.h