^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include "math.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include "parse-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include "pmu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/zalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "../pmu-events/pmu-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "util/evlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "util/expr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "util/parse-events.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct perf_pmu_test_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct pmu_event event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) /* extra events for aliases */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) const char *alias_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Note: For when PublicDescription does not exist in the JSON, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * will have no long_desc in pmu_event.long_desc, but long_desc may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * be set in the alias.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) const char *alias_long_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static struct perf_pmu_test_event test_cpu_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) .name = "bp_l1_btb_correct",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .event = "event=0x8a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .desc = "L1 BTB Correction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) .topic = "branch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .alias_str = "event=0x8a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .alias_long_desc = "L1 BTB Correction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) .name = "bp_l2_btb_correct",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .event = "event=0x8b",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .desc = "L2 BTB Correction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) .topic = "branch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .alias_str = "event=0x8b",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .alias_long_desc = "L2 BTB Correction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .name = "segment_reg_loads.any",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .event = "umask=0x80,period=200000,event=0x6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) .desc = "Number of segment register loads",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .topic = "other",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .alias_str = "umask=0x80,(null)=0x30d40,event=0x6",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .alias_long_desc = "Number of segment register loads",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .name = "dispatch_blocked.any",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .event = "umask=0x20,period=200000,event=0x9",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .desc = "Memory cluster signals to block micro-op dispatch for any reason",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .topic = "other",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .alias_str = "umask=0x20,(null)=0x30d40,event=0x9",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .alias_long_desc = "Memory cluster signals to block micro-op dispatch for any reason",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .name = "eist_trans",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) .event = "umask=0x0,period=200000,event=0x3a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .topic = "other",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .alias_str = "umask=0,(null)=0x30d40,event=0x3a",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .alias_long_desc = "Number of Enhanced Intel SpeedStep(R) Technology (EIST) transitions",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) { /* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .name = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static struct perf_pmu_test_event test_uncore_events[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .name = "uncore_hisi_ddrc.flux_wcmd",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .event = "event=0x2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .desc = "DDRC write commands. Unit: hisi_sccl,ddrc ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .topic = "uncore",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .long_desc = "DDRC write commands",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .pmu = "hisi_sccl,ddrc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .alias_str = "event=0x2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .alias_long_desc = "DDRC write commands",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .name = "unc_cbo_xsnp_response.miss_eviction",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .event = "umask=0x81,event=0x22",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .desc = "Unit: uncore_cbox A cross-core snoop resulted from L3 Eviction which misses in some processor core",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .topic = "uncore",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .pmu = "uncore_cbox",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .alias_str = "umask=0x81,event=0x22",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .alias_long_desc = "A cross-core snoop resulted from L3 Eviction which misses in some processor core",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) { /* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .event = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .name = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) const int total_test_events_size = ARRAY_SIZE(test_uncore_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static bool is_same(const char *reference, const char *test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!reference && !test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (reference && !test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (!reference && test)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return !strcmp(reference, test);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static struct pmu_events_map *__test_pmu_get_events_map(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct pmu_events_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) for (map = &pmu_events_map[0]; map->cpuid; map++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (!strcmp(map->cpuid, "testcpu"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) pr_err("could not find test events map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* Verify generated events from pmu-events.c is as expected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static int test_pmu_event_table(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct pmu_events_map *map = __test_pmu_get_events_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct pmu_event *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int map_events = 0, expected_events;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* ignore 2x sentinels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) expected_events = ARRAY_SIZE(test_cpu_events) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ARRAY_SIZE(test_uncore_events) - 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (!map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) for (table = map->table; table->name; table++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct perf_pmu_test_event *test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct pmu_event *te;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) if (table->pmu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) test = &test_uncore_events[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) test = &test_cpu_events[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) te = &test->event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for (; te->name; test++, te = &test->event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (strcmp(table->name, te->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) map_events++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!is_same(table->desc, te->desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) pr_debug2("testing event table %s: mismatched desc, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) table->name, table->desc, te->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (!is_same(table->topic, te->topic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) pr_debug2("testing event table %s: mismatched topic, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) table->name, table->topic,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) te->topic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (!is_same(table->long_desc, te->long_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) pr_debug2("testing event table %s: mismatched long_desc, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) table->name, table->long_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) te->long_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (!is_same(table->unit, te->unit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) pr_debug2("testing event table %s: mismatched unit, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) table->name, table->unit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) te->unit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!is_same(table->perpkg, te->perpkg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pr_debug2("testing event table %s: mismatched perpkg, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) table->name, table->perpkg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) te->perpkg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (!is_same(table->metric_expr, te->metric_expr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) pr_debug2("testing event table %s: mismatched metric_expr, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) table->name, table->metric_expr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) te->metric_expr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (!is_same(table->metric_name, te->metric_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) pr_debug2("testing event table %s: mismatched metric_name, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) table->name, table->metric_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) te->metric_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (!is_same(table->deprecated, te->deprecated)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) pr_debug2("testing event table %s: mismatched deprecated, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) table->name, table->deprecated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) te->deprecated);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) pr_debug("testing event table %s: pass\n", table->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) pr_err("testing event table: could not find event %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) table->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (map_events != expected_events) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) pr_err("testing event table: found %d, but expected %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) map_events, expected_events);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static struct perf_pmu_alias *find_alias(const char *test_event, struct list_head *aliases)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct perf_pmu_alias *alias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) list_for_each_entry(alias, aliases, list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!strcmp(test_event, alias->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return alias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /* Verify aliases are as expected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int __test__pmu_event_aliases(char *pmu_name, int *count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct perf_pmu_test_event *test;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct pmu_event *te;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct perf_pmu *pmu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) LIST_HEAD(aliases);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) bool use_uncore_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) struct pmu_events_map *map = __test_pmu_get_events_map();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) struct perf_pmu_alias *a, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (!map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (is_pmu_core(pmu_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) test = &test_cpu_events[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) use_uncore_table = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) test = &test_uncore_events[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) use_uncore_table = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) pmu = zalloc(sizeof(*pmu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (!pmu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) pmu->name = pmu_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) pmu_add_cpu_aliases_map(&aliases, pmu, map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) for (te = &test->event; te->name; test++, te = &test->event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct perf_pmu_alias *alias = find_alias(te->name, &aliases);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (!alias) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) bool uncore_match = pmu_uncore_alias_match(pmu_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) te->pmu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (use_uncore_table && !uncore_match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) pr_debug3("testing aliases PMU %s: skip matching alias %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) pmu_name, te->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) pr_debug2("testing aliases PMU %s: no alias, alias_table->name=%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pmu_name, te->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) res = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (!is_same(alias->desc, te->desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) pr_debug2("testing aliases PMU %s: mismatched desc, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) pmu_name, alias->desc, te->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) res = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (!is_same(alias->long_desc, test->alias_long_desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) pr_debug2("testing aliases PMU %s: mismatched long_desc, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) pmu_name, alias->long_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) test->alias_long_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) res = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!is_same(alias->str, test->alias_str)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) pr_debug2("testing aliases PMU %s: mismatched str, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) pmu_name, alias->str, test->alias_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) res = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (!is_same(alias->topic, te->topic)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) pr_debug2("testing aliases PMU %s: mismatched topic, %s vs %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) pmu_name, alias->topic, te->topic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) res = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) (*count)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) pr_debug2("testing aliases PMU %s: matched event %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) pmu_name, alias->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) list_for_each_entry_safe(a, tmp, &aliases, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) list_del(&a->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) perf_pmu_free_alias(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) free(pmu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) static int test_aliases(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) struct perf_pmu *pmu = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) while ((pmu = perf_pmu__scan(pmu)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (list_empty(&pmu->format)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) pr_debug2("skipping testing PMU %s\n", pmu->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (__test__pmu_event_aliases(pmu->name, &count)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) pr_debug("testing PMU %s aliases: failed\n", pmu->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (count == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) pr_debug3("testing PMU %s aliases: no events to match\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) pmu->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) pr_debug("testing PMU %s aliases: pass\n", pmu->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static bool is_number(const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) char *end_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) double v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) errno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) v = strtod(str, &end_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) (void)v; // We're not interested in this value, only if it is valid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return errno == 0 && end_ptr != str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int check_parse_id(const char *id, struct parse_events_error *error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct perf_pmu *fake_pmu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct evlist *evlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* Numbers are always valid. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (is_number(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) evlist = evlist__new();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (!evlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) ret = __parse_events(evlist, id, error, fake_pmu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) evlist__delete(evlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static int check_parse_cpu(const char *id, bool same_cpu, struct pmu_event *pe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct parse_events_error error = { .idx = 0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int ret = check_parse_id(id, &error, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (ret && same_cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) pr_warning("Parse event failed metric '%s' id '%s' expr '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) pe->metric_name, id, pe->metric_expr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) pr_warning("Error string '%s' help '%s'\n", error.str,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) error.help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) } else if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) pr_debug3("Parse event failed, but for an event that may not be supported by this CPU.\nid '%s' metric '%s' expr '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) id, pe->metric_name, pe->metric_expr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) free(error.str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) free(error.help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) free(error.first_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) free(error.first_help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) static int check_parse_fake(const char *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) struct parse_events_error error = { .idx = 0, };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int ret = check_parse_id(id, &error, &perf_pmu__fake);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) free(error.str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) free(error.help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) free(error.first_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) free(error.first_help);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static void expr_failure(const char *msg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) const struct pmu_events_map *map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) const struct pmu_event *pe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) pr_debug("%s for map %s %s %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) msg, map->cpuid, map->version, map->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) pr_debug("On metric %s\n", pe->metric_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) pr_debug("On expression %s\n", pe->metric_expr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) static int test_parsing(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct pmu_events_map *cpus_map = perf_pmu__find_map(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct pmu_events_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) struct pmu_event *pe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) struct expr_parse_ctx ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) double result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) map = &pmu_events_map[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (!map->table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct hashmap_entry *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) size_t bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) pe = &map->table[j++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (!pe->name && !pe->metric_group && !pe->metric_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (!pe->metric_expr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) expr__ctx_init(&ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (expr__find_other(pe->metric_expr, NULL, &ctx, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) expr_failure("Parse other failed", map, pe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * Add all ids with a made up value. The value may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * trigger divide by zero when subtracted and so try to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) * make them unique.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) k = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) hashmap__for_each_entry((&ctx.ids), cur, bkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) expr__add_id_val(&ctx, strdup(cur->key), k++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) hashmap__for_each_entry((&ctx.ids), cur, bkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) if (check_parse_cpu(cur->key, map == cpus_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) pe))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (expr__parse(&result, &ctx, pe->metric_expr, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) expr_failure("Parse failed", map, pe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ret++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) expr__ctx_clear(&ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /* TODO: fail when not ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return ret == 0 ? TEST_OK : TEST_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct test_metric {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) const char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) static struct test_metric metrics[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) { "(unc_p_power_state_occupancy.cores_c0 / unc_p_clockticks) * 100." },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) { "imx8_ddr0@read\\-cycles@ * 4 * 4", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) { "imx8_ddr0@axid\\-read\\,axi_mask\\=0xffff\\,axi_id\\=0x0000@ * 4", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) { "(cstate_pkg@c2\\-residency@ / msr@tsc@) * 100", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) { "(imx8_ddr0@read\\-cycles@ + imx8_ddr0@write\\-cycles@)", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static int metric_parse_fake(const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct expr_parse_ctx ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct hashmap_entry *cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) double result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) int ret = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) size_t bkt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) pr_debug("parsing '%s'\n", str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) expr__ctx_init(&ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (expr__find_other(str, NULL, &ctx, 0) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) pr_err("expr__find_other failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) * Add all ids with a made up value. The value may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * trigger divide by zero when subtracted and so try to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * make them unique.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) hashmap__for_each_entry((&ctx.ids), cur, bkt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) expr__add_id_val(&ctx, strdup(cur->key), i++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) hashmap__for_each_entry((&ctx.ids), cur, bkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (check_parse_fake(cur->key)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) pr_err("check_parse_fake failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (expr__parse(&result, &ctx, str, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) pr_err("expr__parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) expr__ctx_clear(&ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * Parse all the metrics for current architecture,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * or all defined cpus via the 'fake_pmu'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * in parse_events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static int test_parsing_fake(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct pmu_events_map *map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct pmu_event *pe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) for (i = 0; i < ARRAY_SIZE(metrics); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) err = metric_parse_fake(metrics[i].str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) map = &pmu_events_map[i++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (!map->table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) pe = &map->table[j++];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (!pe->name && !pe->metric_group && !pe->metric_name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (!pe->metric_expr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) err = metric_parse_fake(pe->metric_expr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) static const struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) int (*func)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) const char *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) } pmu_events_testcase_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) .func = test_pmu_event_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) .desc = "PMU event table sanity",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) .func = test_aliases,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) .desc = "PMU event map aliases",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) .func = test_parsing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) .desc = "Parsing of PMU event table metrics",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) .func = test_parsing_fake,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .desc = "Parsing of PMU event table metrics with fake PMUs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) const char *test__pmu_events_subtest_get_desc(int subtest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (subtest < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) subtest >= (int)ARRAY_SIZE(pmu_events_testcase_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) return pmu_events_testcase_table[subtest].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) const char *test__pmu_events_subtest_skip_reason(int subtest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (subtest < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) subtest >= (int)ARRAY_SIZE(pmu_events_testcase_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (pmu_events_testcase_table[subtest].func != test_parsing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) return "some metrics failed";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) int test__pmu_events_subtest_get_nr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return (int)ARRAY_SIZE(pmu_events_testcase_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int test__pmu_events(struct test *test __maybe_unused, int subtest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (subtest < 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) subtest >= (int)ARRAY_SIZE(pmu_events_testcase_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) return TEST_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) return pmu_events_testcase_table[subtest].func();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }