aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing
diff options
context:
space:
mode:
authorJack Miller <jack@codezen.org>2016-06-08 22:31:10 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2016-06-21 01:30:50 -0400
commit16c19a2e983346c547501795aadffde1977b058d (patch)
tree42a926653bd231df7ff29dab555bf4c007a28b10 /tools/testing
parentbd3ea317fddfd0f2044f94bed294b90c4bc8e69e (diff)
selftests/powerpc: Load Monitor Register Tests
Adds two tests. One is a simple test to ensure that the new registers LMRR and LMSER are properly maintained. The other actually uses the existing EBB test infrastructure to test that LMRR and LMSER behave as documented. Signed-off-by: Jack Miller <jack@codezen.org> Signed-off-by: Michael Neuling <mikey@neuling.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/.gitignore2
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/Makefile2
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.c143
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.h39
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr_regs.c37
-rw-r--r--tools/testing/selftests/powerpc/reg.h5
6 files changed, 227 insertions, 1 deletions
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/.gitignore b/tools/testing/selftests/powerpc/pmu/ebb/.gitignore
index 42bddbed8b64..44b7df14a936 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/.gitignore
+++ b/tools/testing/selftests/powerpc/pmu/ebb/.gitignore
@@ -20,3 +20,5 @@ back_to_back_ebbs_test
20lost_exception_test 20lost_exception_test
21no_handler_test 21no_handler_test
22cycles_with_mmcr2_test 22cycles_with_mmcr2_test
23ebb_lmr
24ebb_lmr_regs \ No newline at end of file
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/Makefile b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
index 8d2279c4bb4b..6b0453e60d53 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
@@ -14,7 +14,7 @@ TEST_PROGS := reg_access_test event_attributes_test cycles_test \
14 fork_cleanup_test ebb_on_child_test \ 14 fork_cleanup_test ebb_on_child_test \
15 ebb_on_willing_child_test back_to_back_ebbs_test \ 15 ebb_on_willing_child_test back_to_back_ebbs_test \
16 lost_exception_test no_handler_test \ 16 lost_exception_test no_handler_test \
17 cycles_with_mmcr2_test 17 cycles_with_mmcr2_test ebb_lmr ebb_lmr_regs
18 18
19all: $(TEST_PROGS) 19all: $(TEST_PROGS)
20 20
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.c b/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.c
new file mode 100644
index 000000000000..c47ebd55ba4d
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.c
@@ -0,0 +1,143 @@
1/*
2 * Copyright 2016, Jack Miller, IBM Corp.
3 * Licensed under GPLv2.
4 */
5
6#include <stdlib.h>
7#include <stdio.h>
8
9#include "ebb.h"
10#include "ebb_lmr.h"
11
12#define SIZE (32 * 1024 * 1024) /* 32M */
13#define LM_SIZE 0 /* Smallest encoding, 32M */
14
15#define SECTIONS 64 /* 1 per bit in LMSER */
16#define SECTION_SIZE (SIZE / SECTIONS)
17#define SECTION_LONGS (SECTION_SIZE / sizeof(long))
18
19static unsigned long *test_mem;
20
21static int lmr_count = 0;
22
23void ebb_lmr_handler(void)
24{
25 lmr_count++;
26}
27
28void ldmx_full_section(unsigned long *mem, int section)
29{
30 unsigned long *ptr;
31 int i;
32
33 for (i = 0; i < SECTION_LONGS; i++) {
34 ptr = &mem[(SECTION_LONGS * section) + i];
35 ldmx((unsigned long) &ptr);
36 ebb_lmr_reset();
37 }
38}
39
40unsigned long section_masks[] = {
41 0x8000000000000000,
42 0xFF00000000000000,
43 0x0000000F70000000,
44 0x8000000000000001,
45 0xF0F0F0F0F0F0F0F0,
46 0x0F0F0F0F0F0F0F0F,
47 0x0
48};
49
50int ebb_lmr_section_test(unsigned long *mem)
51{
52 unsigned long *mask = section_masks;
53 int i;
54
55 for (; *mask; mask++) {
56 mtspr(SPRN_LMSER, *mask);
57 printf("Testing mask 0x%016lx\n", mfspr(SPRN_LMSER));
58
59 for (i = 0; i < 64; i++) {
60 lmr_count = 0;
61 ldmx_full_section(mem, i);
62 if (*mask & (1UL << (63 - i)))
63 FAIL_IF(lmr_count != SECTION_LONGS);
64 else
65 FAIL_IF(lmr_count);
66 }
67 }
68
69 return 0;
70}
71
72int ebb_lmr(void)
73{
74 int i;
75
76 SKIP_IF(!lmr_is_supported());
77
78 setup_ebb_handler(ebb_lmr_handler);
79
80 ebb_global_enable();
81
82 FAIL_IF(posix_memalign((void **)&test_mem, SIZE, SIZE) != 0);
83
84 mtspr(SPRN_LMSER, 0);
85
86 FAIL_IF(mfspr(SPRN_LMSER) != 0);
87
88 mtspr(SPRN_LMRR, ((unsigned long)test_mem | LM_SIZE));
89
90 FAIL_IF(mfspr(SPRN_LMRR) != ((unsigned long)test_mem | LM_SIZE));
91
92 /* Read every single byte to ensure we get no false positives */
93 for (i = 0; i < SECTIONS; i++)
94 ldmx_full_section(test_mem, i);
95
96 FAIL_IF(lmr_count != 0);
97
98 /* Turn on the first section */
99
100 mtspr(SPRN_LMSER, (1UL << 63));
101 FAIL_IF(mfspr(SPRN_LMSER) != (1UL << 63));
102
103 /* Enable LM (BESCR) */
104
105 mtspr(SPRN_BESCR, mfspr(SPRN_BESCR) | BESCR_LME);
106 FAIL_IF(!(mfspr(SPRN_BESCR) & BESCR_LME));
107
108 ldmx((unsigned long)&test_mem);
109
110 FAIL_IF(lmr_count != 1); // exactly one exception
111 FAIL_IF(mfspr(SPRN_BESCR) & BESCR_LME); // LM now disabled
112 FAIL_IF(!(mfspr(SPRN_BESCR) & BESCR_LMEO)); // occurred bit set
113
114 printf("Simple LMR EBB OK\n");
115
116 /* This shouldn't cause an EBB since it's been disabled */
117 ldmx((unsigned long)&test_mem);
118 FAIL_IF(lmr_count != 1);
119
120 printf("LMR disable on EBB OK\n");
121
122 ebb_lmr_reset();
123
124 /* This should cause an EBB or reset is broken */
125 ldmx((unsigned long)&test_mem);
126 FAIL_IF(lmr_count != 2);
127
128 printf("LMR reset EBB OK\n");
129
130 ebb_lmr_reset();
131
132 return ebb_lmr_section_test(test_mem);
133}
134
135int main(void)
136{
137 int ret = test_harness(ebb_lmr, "ebb_lmr");
138
139 if (test_mem)
140 free(test_mem);
141
142 return ret;
143}
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.h b/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.h
new file mode 100644
index 000000000000..ef50abd557cd
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr.h
@@ -0,0 +1,39 @@
1#ifndef _SELFTESTS_POWERPC_PMU_EBB_LMR_H
2#define _SELFTESTS_POWERPC_PMU_EBB_LMR_H
3
4#include "reg.h"
5
6#ifndef PPC_FEATURE2_ARCH_3_00
7#define PPC_FEATURE2_ARCH_3_00 0x00800000
8#endif
9
10#define lmr_is_supported() have_hwcap2(PPC_FEATURE2_ARCH_3_00)
11
12static inline void ebb_lmr_reset(void)
13{
14 unsigned long bescr = mfspr(SPRN_BESCR);
15 bescr &= ~(BESCR_LMEO);
16 bescr |= BESCR_LME;
17 mtspr(SPRN_BESCR, bescr);
18}
19
20#define LDMX(t, a, b)\
21 (0x7c00026a | \
22 (((t) & 0x1f) << 21) | \
23 (((a) & 0x1f) << 16) | \
24 (((b) & 0x1f) << 11))
25
26static inline unsigned long ldmx(unsigned long address)
27{
28 unsigned long ret;
29
30 asm volatile ("mr 9, %1\r\n"
31 ".long " __stringify(LDMX(9, 0, 9)) "\r\n"
32 "mr %0, 9\r\n":"=r"(ret)
33 :"r"(address)
34 :"r9");
35
36 return ret;
37}
38
39#endif
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr_regs.c b/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr_regs.c
new file mode 100644
index 000000000000..aff4241fd88a
--- /dev/null
+++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb_lmr_regs.c
@@ -0,0 +1,37 @@
1/*
2 * Copyright 2016, Jack Miller, IBM Corp.
3 * Licensed under GPLv2.
4 */
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <unistd.h>
9
10#include "ebb.h"
11#include "ebb_lmr.h"
12
13#define CHECKS 10000
14
15int ebb_lmr_regs(void)
16{
17 int i;
18
19 SKIP_IF(!lmr_is_supported());
20
21 ebb_global_enable();
22
23 for (i = 0; i < CHECKS; i++) {
24 mtspr(SPRN_LMRR, i << 25); // skip size and rsvd bits
25 mtspr(SPRN_LMSER, i);
26
27 FAIL_IF(mfspr(SPRN_LMRR) != (i << 25));
28 FAIL_IF(mfspr(SPRN_LMSER) != i);
29 }
30
31 return 0;
32}
33
34int main(void)
35{
36 return test_harness(ebb_lmr_regs, "ebb_lmr_regs");
37}
diff --git a/tools/testing/selftests/powerpc/reg.h b/tools/testing/selftests/powerpc/reg.h
index 65bfdeeebdee..fddf368ed82f 100644
--- a/tools/testing/selftests/powerpc/reg.h
+++ b/tools/testing/selftests/powerpc/reg.h
@@ -34,6 +34,11 @@
34 34
35#define BESCR_PMEO 0x1 /* PMU Event-based exception Occurred */ 35#define BESCR_PMEO 0x1 /* PMU Event-based exception Occurred */
36#define BESCR_PME (0x1ul << 32) /* PMU Event-based exception Enable */ 36#define BESCR_PME (0x1ul << 32) /* PMU Event-based exception Enable */
37#define BESCR_LME (0x1ul << 34) /* Load Monitor Enable */
38#define BESCR_LMEO (0x1ul << 2) /* Load Monitor Exception Occurred */
39
40#define SPRN_LMRR 813 /* Load Monitor Region Register */
41#define SPRN_LMSER 814 /* Load Monitor Section Enable Register */
37 42
38#define SPRN_PMC1 771 43#define SPRN_PMC1 771
39#define SPRN_PMC2 772 44#define SPRN_PMC2 772