Skip to contentSkip to conversation

perf tests: Add Intel CQM and arch tests

RFC PATCH In review Matt Fleming 3 participants 4 messages Jul 22, 2015 perf events

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 perf tests: Add Intel CQM and arch tests

From: Matt Fleming <[email protected]>

Peter reports that it's possible to trigger a WARN_ON_ONCE() in the Intel CQM code by combining a hardware event and an Intel CQM (software) event into a group. Unfortunately, the perf tools are not able to create this bundle and we need to manually construct a test case.

For posterity, record Peter's proof of concept test case in tools/perf so that it presents a model for how we can perform architecture-specific tests, or "arch tests", in perf in the future.

The particular issue triggered in the test case is that when the counter for the hardware event overflows and triggers a PMI we'll read both the hardware event and the software event counters. Unfortunately, for CQM that involves performing an IPI to read the CQM event counters on all sockets, which in NMI context triggers the WARN_ON_ONCE().

This patch is marked as RFC because I'd really like to solicit opinions on this approach and hear feedback on whether this is the correct way to structure these arch tests. I realise that we've already got tests for the TSC, etc that are x86-specific but I didn't want to change the order of the tests (say, by moving test__perf_time_to_tsc() into ARCH_TESTS) in case that broke some kind of ABI.

---
 tools/perf/arch/x86/Build                |   2 +-
 tools/perf/arch/x86/include/arch-tests.h |  13 ++++
 tools/perf/arch/x86/tests/Build          |   6 +-
 tools/perf/arch/x86/tests/intel-cqm.c    | 124 +++++++++++++++++++++++++++++++
 tools/perf/tests/builtin-test.c          |   7 ++
 5 files changed, 149 insertions(+), 3 deletions(-)
 create mode 100644 tools/perf/arch/x86/include/arch-tests.h
 create mode 100644 tools/perf/arch/x86/tests/intel-cqm.c
tools/perf/arch/x86/Build +1 -1
index 41bf61da476a..db52fa22d3a1 100644
@@ -1,2 +1,2 @@
 libperf-y += util/
-libperf-$(CONFIG_DWARF_UNWIND) += tests/
+libperf-y += tests/
tools/perf/arch/x86/include/arch-tests.h new file +13 -0
new file mode 100644
index 000000000000..9d43f759e014
@@ -0,0 +1,13 @@
+#ifndef ARCH_TESTS_H
+#define ARCH_TESTS_H
+
+/* Tests */
+int test__intel_cqm_count_nmi_context(void);
+
+#define ARCH_TESTS						\
+	{							\
+		.desc = "Test intel cqm nmi context read",	\
+		.func = test__intel_cqm_count_nmi_context,	\
+	},
+
+#endif
tools/perf/arch/x86/tests/Build +4 -2
index b30eff9bcc83..58469b91b49b 100644
@@ -1,2 +1,4 @@
-libperf-y += regs_load.o
-libperf-y += dwarf-unwind.o
+libperf-$(CONFIG_DWARF_UNWIND) += regs_load.o
+libperf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
+
+libperf-y += intel-cqm.o
tools/perf/arch/x86/tests/intel-cqm.c new file +124 -0

124 lines not on this page · raw message

tools/perf/tests/builtin-test.c +7 -0
index c1dde733c3a6..82e433340fda 100644
@@ -14,6 +14,10 @@
 #include "parse-options.h"
 #include "symbol.h"
 
+#if defined(__x86_64__)
+#include "arch-tests.h"
+#endif
+
 static struct test {
 	const char *desc;
 	int (*func)(void);
@@ -174,6 +178,9 @@ static struct test {
 		.desc = "Test thread map",
 		.func = test__thread_map,
 	},
+#if defined(__x86_64__)
+	ARCH_TESTS
+#endif
 	{
 		.func = NULL,
 	},
Signature · 1 line
2.1.0
#1 lore raw
Quoted 17 lines · Matt Fleming

From: Matt Fleming <[email protected]>

Peter reports that it's possible to trigger a WARN_ON_ONCE() in the Intel CQM code by combining a hardware event and an Intel CQM (software) event into a group. Unfortunately, the perf tools are not able to create this bundle and we need to manually construct a test case.

For posterity, record Peter's proof of concept test case in tools/perf so that it presents a model for how we can perform architecture-specific tests, or "arch tests", in perf in the future.

The particular issue triggered in the test case is that when the counter for the hardware event overflows and triggers a PMI we'll read both the hardware event and the software event counters. Unfortunately, for CQM that involves performing an IPI to read the CQM event counters on all sockets, which in NMI context triggers the WARN_ON_ONCE().

Quoted 6 lines

This patch is marked as RFC because I'd really like to solicit opinions on this approach and hear feedback on whether this is the correct way to structure these arch tests. I realise that we've already got tests for the TSC, etc that are x86-specific but I didn't want to change the order of the tests (say, by moving test__perf_time_to_tsc() into ARCH_TESTS) in case that broke some kind of ABI.

I wouldn't consider the order of tests being ABI,
let's break it and watch ;-)

SNIP

Quoted 8 lines
tools/perf/arch/x86/include/arch-tests.h new file +2 -0
new file mode 100644
index 000000000000..9d43f759e014
@@ -0,0 +1,13 @@
+#ifndef ARCH_TESTS_H
+#define ARCH_TESTS_H

tools/perf/arch/x86/include/arch-tests.h line 12

Quoted 10 lines
tools/perf/arch/x86/include/arch-tests.h new file +10 -0
+
+/* Tests */
+int test__intel_cqm_count_nmi_context(void);
+
+#define ARCH_TESTS						\
+	{							\
+		.desc = "Test intel cqm nmi context read",	\
+		.func = test__intel_cqm_count_nmi_context,	\
+	},
+

hum, I dont like much this being stuffed in macro, but dont have any technical reason against ;-)

maybe we could add 'struct test arch_tests[]' array, that'd be initialized by each arch and executed in addition to the current 'struct test tests[]'

jirka

#2 lore raw

Em Wed, Jul 22, 2015 at 03:24:44PM +0200, Jiri Olsa escreveu:

Quoted 10 lines · Matt Fleming
Quoted 6 lines

This patch is marked as RFC because I'd really like to solicit opinions on this approach and hear feedback on whether this is the correct way to structure these arch tests. I realise that we've already got tests for the TSC, etc that are x86-specific but I didn't want to change the order of the tests (say, by moving test__perf_time_to_tsc() into ARCH_TESTS) in case that broke some kind of ABI.

I wouldn't consider the order of tests being ABI,
let's break it and watch ;-)

yeah

Quoted 13 lines

SNIP

tools/perf/arch/x86/include/arch-tests.h line 12

Quoted 7 lines
tools/perf/arch/x86/include/arch-tests.h +6 -0
+#define ARCH_TESTS						\
+	{							\
+		.desc = "Test intel cqm nmi context read",	\
+		.func = test__intel_cqm_count_nmi_context,	\
+	},
+

hum, I dont like much this being stuffed in macro, but dont have any technical reason against ;-)

Quoted 3 lines

maybe we could add 'struct test arch_tests[]' array, that'd be initialized by each arch and executed in addition to the current 'struct test tests[]'

Agreed, that would be cleaner, and we need something like that anyway, i.e. some way to group tests that run only if certain requirements are met, i.e. tests that require root permission, arch specific ones, etc.

- Arnaldo

#3 lore raw
In reply to Jiri Olsa
Quoted 25 lines · Jiri Olsa
Quoted 17 lines · Matt Fleming

From: Matt Fleming <[email protected]>

Peter reports that it's possible to trigger a WARN_ON_ONCE() in the Intel CQM code by combining a hardware event and an Intel CQM (software) event into a group. Unfortunately, the perf tools are not able to create this bundle and we need to manually construct a test case.

For posterity, record Peter's proof of concept test case in tools/perf so that it presents a model for how we can perform architecture-specific tests, or "arch tests", in perf in the future.

The particular issue triggered in the test case is that when the counter for the hardware event overflows and triggers a PMI we'll read both the hardware event and the software event counters. Unfortunately, for CQM that involves performing an IPI to read the CQM event counters on all sockets, which in NMI context triggers the WARN_ON_ONCE().

Quoted 6 lines

This patch is marked as RFC because I'd really like to solicit opinions on this approach and hear feedback on whether this is the correct way to structure these arch tests. I realise that we've already got tests for the TSC, etc that are x86-specific but I didn't want to change the order of the tests (say, by moving test__perf_time_to_tsc() into ARCH_TESTS) in case that broke some kind of ABI.

Quoted 2 lines

I wouldn't consider the order of tests being ABI,
let's break it and watch ;-)

OK, that at least allows me to perform a litte more surgery on the current tests.

Quoted 22 lines
Quoted 8 lines
tools/perf/arch/x86/include/arch-tests.h new file +2 -0
new file mode 100644
index 000000000000..9d43f759e014
@@ -0,0 +1,13 @@
+#ifndef ARCH_TESTS_H
+#define ARCH_TESTS_H

tools/perf/arch/x86/include/arch-tests.h line 12

Quoted 10 lines
tools/perf/arch/x86/include/arch-tests.h new file +10 -0
+
+/* Tests */
+int test__intel_cqm_count_nmi_context(void);
+
+#define ARCH_TESTS						\
+	{							\
+		.desc = "Test intel cqm nmi context read",	\
+		.func = test__intel_cqm_count_nmi_context,	\
+	},
+

hum, I dont like much this being stuffed in macro, but dont have any technical reason against ;-)

Quoted 3 lines

maybe we could add 'struct test arch_tests[]' array, that'd be initialized by each arch and executed in addition to the current 'struct test tests[]'

Makes sense to me. I'll take that approach. Thanks.

Signature · 1 line
Matt Fleming, Intel Open Source Technology Center