Skip to content

Commit a6c925f

Browse files
John Garryacmel
authored andcommitted
perf test: Add pmu-events test
The initial test will verify that the test tables in generated pmu-events.c match against known, expected values. For known events added in pmu-events/arch/test, we need to add an entry in test_cpu_aliases_events[] or test_uncore_events[]. A sample run is as follows for x86: john@linux-3c19:~/linux> tools/perf/perf test -vv 10 10: PMU event aliases : --- start --- test child forked, pid 5316 testing event table bp_l1_btb_correct: pass testing event table bp_l2_btb_correct: pass testing event table segment_reg_loads.any: pass testing event table dispatch_blocked.any: pass testing event table eist_trans: pass testing event table uncore_hisi_ddrc.flux_wcmd: pass testing event table unc_cbo_xsnp_response.miss_eviction: pass test child finished with 0 ---- end ---- PMU event aliases: Ok Signed-off-by: John Garry <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: James Clark <[email protected]> Cc: Joakim Zhang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] [ Fixup test_cpu_events[] and test_uncore_events[] sentinels to initialize one of its members to NULL, fixing the build in older compilers ] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent e45ad70 commit a6c925f

File tree

4 files changed

+239
-0
lines changed

4 files changed

+239
-0
lines changed

tools/perf/tests/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ perf-y += evsel-roundtrip-name.o
1414
perf-y += evsel-tp-sched.o
1515
perf-y += fdarray.o
1616
perf-y += pmu.o
17+
perf-y += pmu-events.o
1718
perf-y += hists_common.o
1819
perf-y += hists_link.o
1920
perf-y += hists_filter.o

tools/perf/tests/builtin-test.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ static struct test generic_tests[] = {
7272
.desc = "Parse perf pmu format",
7373
.func = test__pmu,
7474
},
75+
{
76+
.desc = "PMU events",
77+
.func = test__pmu_events,
78+
},
7579
{
7680
.desc = "DSO data read",
7781
.func = test__dso_data,

tools/perf/tests/pmu-events.c

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
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+
}

tools/perf/tests/tests.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int test__perf_evsel__roundtrip_name_test(struct test *test, int subtest);
4949
int test__perf_evsel__tp_sched_test(struct test *test, int subtest);
5050
int test__syscall_openat_tp_fields(struct test *test, int subtest);
5151
int test__pmu(struct test *test, int subtest);
52+
int test__pmu_events(struct test *test, int subtest);
5253
int test__attr(struct test *test, int subtest);
5354
int test__dso_data(struct test *test, int subtest);
5455
int test__dso_data_cache(struct test *test, int subtest);

0 commit comments

Comments
 (0)