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: 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 */ 47 struct 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 63 struct 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 }; 78 79 struct pmu_events_table; 80 struct pmu_metrics_table; 81 82 #define PMU_EVENTS__NOT_FOUND -1000 83 #define PMU_METRICS__NOT_FOUND -1000 84 85 typedef int (*pmu_event_iter_fn)(const struct pmu_event *pe, 86 const struct pmu_events_table *table, 87 void *data); 88 89 typedef int (*pmu_metric_iter_fn)(const struct pmu_metric *pm, 90 const struct pmu_metrics_table *table, 91 void *data); 92 93 int pmu_events_table__for_each_event(const struct pmu_events_table *table, 94 struct perf_pmu *pmu, 95 pmu_event_iter_fn fn, 96 void *data); 97 /* 98 * Search for a table and entry matching with pmu__name_wildcard_match or any 99 * tables if pmu is NULL. Each matching event has fn called on it. 0 implies to 100 * success/continue the search while non-zero means to terminate. The special 101 * value PMU_EVENTS__NOT_FOUND is used to indicate no event was found in one of 102 * the tables which doesn't terminate the search of all tables. 103 */ 104 int pmu_events_table__find_event(const struct pmu_events_table *table, 105 struct perf_pmu *pmu, 106 const char *name, 107 pmu_event_iter_fn fn, 108 void *data); 109 size_t pmu_events_table__num_events(const struct pmu_events_table *table, 110 struct perf_pmu *pmu); 111 112 int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, pmu_metric_iter_fn fn, 113 void *data); 114 /* 115 * Search for a table and entry matching with pmu__name_wildcard_match or any 116 * tables if pmu is NULL. Each matching metric has fn called on it. 0 implies to 117 * success/continue the search while non-zero means to terminate. The special 118 * value PMU_METRICS__NOT_FOUND is used to indicate no metric was found in one 119 * of the tables which doesn't terminate the search of all tables. 120 */ 121 int pmu_metrics_table__find_metric(const struct pmu_metrics_table *table, 122 struct perf_pmu *pmu, 123 const char *metric, 124 pmu_metric_iter_fn fn, 125 void *data); 126 127 const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu); 128 const struct pmu_metrics_table *pmu_metrics_table__find(void); 129 const struct pmu_events_table *find_core_events_table(const char *arch, const char *cpuid); 130 const struct pmu_metrics_table *find_core_metrics_table(const char *arch, const char *cpuid); 131 int pmu_for_each_core_event(pmu_event_iter_fn fn, void *data); 132 int pmu_for_each_core_metric(pmu_metric_iter_fn fn, void *data); 133 134 const struct pmu_events_table *find_sys_events_table(const char *name); 135 const struct pmu_metrics_table *find_sys_metrics_table(const char *name); 136 int pmu_for_each_sys_event(pmu_event_iter_fn fn, void *data); 137 int pmu_for_each_sys_metric(pmu_metric_iter_fn fn, void *data); 138 139 const char *describe_metricgroup(const char *group); 140 141 #endif 142