|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +#include "parse-events.h" |
| 3 | +#include "pmu.h" |
| 4 | +#include "tests.h" |
| 5 | +#include <errno.h> |
| 6 | +#include <stdio.h> |
| 7 | +#include <linux/kernel.h> |
| 8 | + |
| 9 | +#include "debug.h" |
| 10 | +#include "../pmu-events/pmu-events.h" |
| 11 | + |
| 12 | +struct perf_pmu_test_event { |
| 13 | + struct pmu_event event; |
| 14 | +}; |
| 15 | +static struct perf_pmu_test_event test_cpu_events[] = { |
| 16 | + { |
| 17 | + .event = { |
| 18 | + .name = "bp_l1_btb_correct", |
| 19 | + .event = "event=0x8a", |
| 20 | + .desc = "L1 BTB Correction", |
| 21 | + .topic = "branch", |
| 22 | + }, |
| 23 | + }, |
| 24 | + { |
| 25 | + .event = { |
| 26 | + .name = "bp_l2_btb_correct", |
| 27 | + .event = "event=0x8b", |
| 28 | + .desc = "L2 BTB Correction", |
| 29 | + .topic = "branch", |
| 30 | + }, |
| 31 | + }, |
| 32 | + { |
| 33 | + .event = { |
| 34 | + .name = "segment_reg_loads.any", |
| 35 | + .event = "umask=0x80,period=200000,event=0x6", |
| 36 | + .desc = "Number of segment register loads", |
| 37 | + .topic = "other", |
| 38 | + }, |
| 39 | + }, |
| 40 | + { |
| 41 | + .event = { |
| 42 | + .name = "dispatch_blocked.any", |
| 43 | + .event = "umask=0x20,period=200000,event=0x9", |
| 44 | + .desc = "Memory cluster signals to block micro-op dispatch for any reason", |
| 45 | + .topic = "other", |
| 46 | + }, |
| 47 | + }, |
| 48 | + { |
| 49 | + .event = { |
| 50 | + .name = "eist_trans", |
| 51 | + .event = "umask=0x0,period=200000,event=0x3a", |
| 52 | + .desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions", |
| 53 | + .topic = "other", |
| 54 | + }, |
| 55 | + }, |
| 56 | + { /* sentinel */ |
| 57 | + .event = { |
| 58 | + .name = NULL, |
| 59 | + }, |
| 60 | + }, |
| 61 | +}; |
| 62 | + |
| 63 | +static struct perf_pmu_test_event test_uncore_events[] = { |
| 64 | + { |
| 65 | + .event = { |
| 66 | + .name = "uncore_hisi_ddrc.flux_wcmd", |
| 67 | + .event = "event=0x2", |
| 68 | + .desc = "DDRC write commands. Unit: hisi_sccl,ddrc ", |
| 69 | + .topic = "uncore", |
| 70 | + .long_desc = "DDRC write commands", |
| 71 | + .pmu = "hisi_sccl,ddrc", |
| 72 | + }, |
| 73 | + }, |
| 74 | + { |
| 75 | + .event = { |
| 76 | + .name = "unc_cbo_xsnp_response.miss_eviction", |
| 77 | + .event = "umask=0x81,event=0x22", |
| 78 | + .desc = "Unit: uncore_cbox A cross-core snoop resulted from L3 Eviction which misses in some processor core", |
| 79 | + .topic = "uncore", |
| 80 | + .long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core", |
| 81 | + .pmu = "uncore_cbox", |
| 82 | + }, |
| 83 | + }, |
| 84 | + { /* sentinel */ |
| 85 | + .event = { |
| 86 | + .name = NULL, |
| 87 | + }, |
| 88 | + } |
| 89 | +}; |
| 90 | + |
| 91 | +const int total_test_events_size = ARRAY_SIZE(test_uncore_events); |
| 92 | + |
| 93 | +static bool is_same(const char *reference, const char *test) |
| 94 | +{ |
| 95 | + if (!reference && !test) |
| 96 | + return true; |
| 97 | + |
| 98 | + if (reference && !test) |
| 99 | + return false; |
| 100 | + |
| 101 | + if (!reference && test) |
| 102 | + return false; |
| 103 | + |
| 104 | + return !strcmp(reference, test); |
| 105 | +} |
| 106 | + |
| 107 | +static struct pmu_events_map *__test_pmu_get_events_map(void) |
| 108 | +{ |
| 109 | + struct pmu_events_map *map; |
| 110 | + |
| 111 | + for (map = &pmu_events_map[0]; map->cpuid; map++) { |
| 112 | + if (!strcmp(map->cpuid, "testcpu")) |
| 113 | + return map; |
| 114 | + } |
| 115 | + |
| 116 | + pr_err("could not find test events map\n"); |
| 117 | + |
| 118 | + return NULL; |
| 119 | +} |
| 120 | + |
| 121 | +/* Verify generated events from pmu-events.c is as expected */ |
| 122 | +static int __test_pmu_event_table(void) |
| 123 | +{ |
| 124 | + struct pmu_events_map *map = __test_pmu_get_events_map(); |
| 125 | + struct pmu_event *table; |
| 126 | + int map_events = 0, expected_events; |
| 127 | + |
| 128 | + /* ignore 2x sentinels */ |
| 129 | + expected_events = ARRAY_SIZE(test_cpu_events) + |
| 130 | + ARRAY_SIZE(test_uncore_events) - 2; |
| 131 | + |
| 132 | + if (!map) |
| 133 | + return -1; |
| 134 | + |
| 135 | + for (table = map->table; table->name; table++) { |
| 136 | + struct perf_pmu_test_event *test; |
| 137 | + struct pmu_event *te; |
| 138 | + bool found = false; |
| 139 | + |
| 140 | + if (table->pmu) |
| 141 | + test = &test_uncore_events[0]; |
| 142 | + else |
| 143 | + test = &test_cpu_events[0]; |
| 144 | + |
| 145 | + te = &test->event; |
| 146 | + |
| 147 | + for (; te->name; test++, te = &test->event) { |
| 148 | + if (strcmp(table->name, te->name)) |
| 149 | + continue; |
| 150 | + found = true; |
| 151 | + map_events++; |
| 152 | + |
| 153 | + if (!is_same(table->desc, te->desc)) { |
| 154 | + pr_debug2("testing event table %s: mismatched desc, %s vs %s\n", |
| 155 | + table->name, table->desc, te->desc); |
| 156 | + return -1; |
| 157 | + } |
| 158 | + |
| 159 | + if (!is_same(table->topic, te->topic)) { |
| 160 | + pr_debug2("testing event table %s: mismatched topic, %s vs %s\n", |
| 161 | + table->name, table->topic, |
| 162 | + te->topic); |
| 163 | + return -1; |
| 164 | + } |
| 165 | + |
| 166 | + if (!is_same(table->long_desc, te->long_desc)) { |
| 167 | + pr_debug2("testing event table %s: mismatched long_desc, %s vs %s\n", |
| 168 | + table->name, table->long_desc, |
| 169 | + te->long_desc); |
| 170 | + return -1; |
| 171 | + } |
| 172 | + |
| 173 | + if (!is_same(table->unit, te->unit)) { |
| 174 | + pr_debug2("testing event table %s: mismatched unit, %s vs %s\n", |
| 175 | + table->name, table->unit, |
| 176 | + te->unit); |
| 177 | + return -1; |
| 178 | + } |
| 179 | + |
| 180 | + if (!is_same(table->perpkg, te->perpkg)) { |
| 181 | + pr_debug2("testing event table %s: mismatched perpkg, %s vs %s\n", |
| 182 | + table->name, table->perpkg, |
| 183 | + te->perpkg); |
| 184 | + return -1; |
| 185 | + } |
| 186 | + |
| 187 | + if (!is_same(table->metric_expr, te->metric_expr)) { |
| 188 | + pr_debug2("testing event table %s: mismatched metric_expr, %s vs %s\n", |
| 189 | + table->name, table->metric_expr, |
| 190 | + te->metric_expr); |
| 191 | + return -1; |
| 192 | + } |
| 193 | + |
| 194 | + if (!is_same(table->metric_name, te->metric_name)) { |
| 195 | + pr_debug2("testing event table %s: mismatched metric_name, %s vs %s\n", |
| 196 | + table->name, table->metric_name, |
| 197 | + te->metric_name); |
| 198 | + return -1; |
| 199 | + } |
| 200 | + |
| 201 | + if (!is_same(table->deprecated, te->deprecated)) { |
| 202 | + pr_debug2("testing event table %s: mismatched deprecated, %s vs %s\n", |
| 203 | + table->name, table->deprecated, |
| 204 | + te->deprecated); |
| 205 | + return -1; |
| 206 | + } |
| 207 | + |
| 208 | + pr_debug("testing event table %s: pass\n", table->name); |
| 209 | + } |
| 210 | + |
| 211 | + if (!found) { |
| 212 | + pr_err("testing event table: could not find event %s\n", |
| 213 | + table->name); |
| 214 | + return -1; |
| 215 | + } |
| 216 | + } |
| 217 | + |
| 218 | + if (map_events != expected_events) { |
| 219 | + pr_err("testing event table: found %d, but expected %d\n", |
| 220 | + map_events, expected_events); |
| 221 | + return -1; |
| 222 | + } |
| 223 | + |
| 224 | + return 0; |
| 225 | +} |
| 226 | +int test__pmu_events(struct test *test __maybe_unused, |
| 227 | + int subtest __maybe_unused) |
| 228 | +{ |
| 229 | + if (__test_pmu_event_table()) |
| 230 | + return -1; |
| 231 | + |
| 232 | + return 0; |
| 233 | +} |
0 commit comments