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