Skip to content

Commit c384c5d

Browse files
charlie-rivospalmer-dabbelt
authored andcommitted
selftests: riscv: Support xtheadvector in vector tests
Extend existing vector tests to be compatible with the xtheadvector instructions. Signed-off-by: Charlie Jenkins <[email protected]> Tested-by: Yangyu Chen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 57d7713 commit c384c5d

File tree

6 files changed

+113
-52
lines changed

6 files changed

+113
-52
lines changed

tools/testing/selftests/riscv/vector/v_exec_initval_nolibc.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ int main(int argc, char **argv)
1818
unsigned long vl;
1919
int first = 1;
2020

21-
asm volatile (
22-
".option push\n\t"
23-
".option arch, +v\n\t"
24-
"vsetvli %[vl], x0, e8, m1, ta, ma\n\t"
25-
".option pop\n\t"
26-
: [vl] "=r" (vl)
27-
);
21+
if (argc > 2 && strcmp(argv[2], "x"))
22+
asm volatile (
23+
// 0 | zimm[10:0] | rs1 | 1 1 1 | rd |1010111| vsetvli
24+
// vsetvli t4, x0, e8, m1, d1
25+
".4byte 0b00000000000000000111111011010111\n\t"
26+
"mv %[vl], t4\n\t"
27+
: [vl] "=r" (vl) : : "t4"
28+
);
29+
else
30+
asm volatile (
31+
".option push\n\t"
32+
".option arch, +v\n\t"
33+
"vsetvli %[vl], x0, e8, m1, ta, ma\n\t"
34+
".option pop\n\t"
35+
: [vl] "=r" (vl)
36+
);
2837

2938
#define CHECK_VECTOR_REGISTER(register) ({ \
3039
for (int i = 0; i < vl; i++) { \

tools/testing/selftests/riscv/vector/v_helpers.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22

33
#include "../hwprobe/hwprobe.h"
4+
#include <asm/vendor/thead.h>
45
#include <stdbool.h>
56
#include <stdlib.h>
67
#include <stdio.h>
78
#include <unistd.h>
89
#include <sys/wait.h>
910

11+
bool is_xtheadvector_supported(void)
12+
{
13+
struct riscv_hwprobe pair;
14+
15+
pair.key = RISCV_HWPROBE_KEY_VENDOR_EXT_THEAD_0;
16+
riscv_hwprobe(&pair, 1, 0, NULL, 0);
17+
return pair.value & RISCV_HWPROBE_VENDOR_EXT_XTHEADVECTOR;
18+
}
19+
1020
bool is_vector_supported(void)
1121
{
1222
struct riscv_hwprobe pair;
@@ -16,9 +26,9 @@ bool is_vector_supported(void)
1626
return pair.value & RISCV_HWPROBE_EXT_ZVE32X;
1727
}
1828

19-
int launch_test(char *next_program, int test_inherit)
29+
int launch_test(char *next_program, int test_inherit, int xtheadvector)
2030
{
21-
char *exec_argv[3], *exec_envp[1];
31+
char *exec_argv[4], *exec_envp[1];
2232
int rc, pid, status;
2333

2434
pid = fork();
@@ -30,7 +40,8 @@ int launch_test(char *next_program, int test_inherit)
3040
if (!pid) {
3141
exec_argv[0] = next_program;
3242
exec_argv[1] = test_inherit != 0 ? "x" : NULL;
33-
exec_argv[2] = NULL;
43+
exec_argv[2] = xtheadvector != 0 ? "x" : NULL;
44+
exec_argv[3] = NULL;
3445
exec_envp[0] = NULL;
3546
/* launch the program again to check inherit */
3647
rc = execve(next_program, exec_argv, exec_envp);
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22
#include <stdbool.h>
33

4+
bool is_xtheadvector_supported(void);
5+
46
bool is_vector_supported(void);
57

6-
int launch_test(char *next_program, int test_inherit);
8+
int launch_test(char *next_program, int test_inherit, int xtheadvector);

tools/testing/selftests/riscv/vector/v_initval.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88
TEST(v_initval)
99
{
10-
if (!is_vector_supported())
11-
SKIP(return, "Vector not supported");
10+
int xtheadvector = 0;
1211

13-
ASSERT_EQ(0, launch_test(NEXT_PROGRAM, 0));
12+
if (!is_vector_supported()) {
13+
if (is_xtheadvector_supported())
14+
xtheadvector = 1;
15+
else
16+
SKIP(return, "Vector not supported");
17+
}
18+
19+
ASSERT_EQ(0, launch_test(NEXT_PROGRAM, 0, xtheadvector));
1420
}
1521

1622
TEST_HARNESS_MAIN

tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
int main(int argc, char **argv)
88
{
9-
int rc, pid, status, test_inherit = 0;
9+
int rc, pid, status, test_inherit = 0, xtheadvector = 0;
1010
long ctrl, ctrl_c;
1111
char *exec_argv[2], *exec_envp[2];
1212

13-
if (argc > 1)
13+
if (argc > 1 && strcmp(argv[1], "x"))
1414
test_inherit = 1;
1515

16+
if (argc > 2 && strcmp(argv[2], "x"))
17+
xtheadvector = 1;
18+
1619
ctrl = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL);
1720
if (ctrl < 0) {
1821
puts("PR_RISCV_V_GET_CONTROL is not supported\n");
@@ -53,11 +56,14 @@ int main(int argc, char **argv)
5356
puts("child's vstate_ctrl not equal to parent's\n");
5457
exit(-1);
5558
}
56-
asm volatile (".option push\n\t"
57-
".option arch, +v\n\t"
58-
"vsetvli x0, x0, e32, m8, ta, ma\n\t"
59-
".option pop\n\t"
60-
);
59+
if (xtheadvector)
60+
asm volatile (".4byte 0x00007ed7");
61+
else
62+
asm volatile (".option push\n\t"
63+
".option arch, +v\n\t"
64+
"vsetvli x0, x0, e32, m8, ta, ma\n\t"
65+
".option pop\n\t"
66+
);
6167
exit(ctrl);
6268
}
6369
}

tools/testing/selftests/riscv/vector/vstate_prctl.c

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#define NEXT_PROGRAM "./vstate_exec_nolibc"
1313

14-
int test_and_compare_child(long provided, long expected, int inherit)
14+
int test_and_compare_child(long provided, long expected, int inherit, int xtheadvector)
1515
{
1616
int rc;
1717

@@ -21,7 +21,7 @@ int test_and_compare_child(long provided, long expected, int inherit)
2121
provided, rc);
2222
return -1;
2323
}
24-
rc = launch_test(NEXT_PROGRAM, inherit);
24+
rc = launch_test(NEXT_PROGRAM, inherit, xtheadvector);
2525
if (rc != expected) {
2626
printf("Test failed, check %d != %ld\n", rc, expected);
2727
return -2;
@@ -36,7 +36,7 @@ TEST(get_control_no_v)
3636
{
3737
long rc;
3838

39-
if (is_vector_supported())
39+
if (is_vector_supported() || is_xtheadvector_supported())
4040
SKIP(return, "Test expects vector to be not supported");
4141

4242
rc = prctl(PR_RISCV_V_GET_CONTROL);
@@ -50,7 +50,7 @@ TEST(set_control_no_v)
5050
{
5151
long rc;
5252

53-
if (is_vector_supported())
53+
if (is_vector_supported() || is_xtheadvector_supported())
5454
SKIP(return, "Test expects vector to be not supported");
5555

5656
rc = prctl(PR_RISCV_V_SET_CONTROL, PR_RISCV_V_VSTATE_CTRL_ON);
@@ -65,20 +65,20 @@ TEST(vstate_on_current)
6565
long flag;
6666
long rc;
6767

68-
if (!is_vector_supported())
68+
if (!is_vector_supported() && !is_xtheadvector_supported())
6969
SKIP(return, "Vector not supported");
7070

7171
flag = PR_RISCV_V_VSTATE_CTRL_ON;
7272
rc = prctl(PR_RISCV_V_SET_CONTROL, flag);
73-
EXPECT_EQ(0, rc) TH_LOG("Enabling V for current should always success");
73+
EXPECT_EQ(0, rc) TH_LOG("Enabling V for current should always succeed");
7474
}
7575

7676
TEST(vstate_off_eperm)
7777
{
7878
long flag;
7979
long rc;
8080

81-
if (!is_vector_supported())
81+
if (!is_vector_supported() && !is_xtheadvector_supported())
8282
SKIP(return, "Vector not supported");
8383

8484
flag = PR_RISCV_V_VSTATE_CTRL_OFF;
@@ -92,97 +92,124 @@ TEST(vstate_off_eperm)
9292
TEST(vstate_on_no_nesting)
9393
{
9494
long flag;
95+
int xtheadvector = 0;
9596

96-
if (!is_vector_supported())
97-
SKIP(return, "Vector not supported");
97+
if (!is_vector_supported()) {
98+
if (is_xtheadvector_supported())
99+
xtheadvector = 1;
100+
else
101+
SKIP(return, "Vector not supported");
102+
}
98103

99104
/* Turn on next's vector explicitly and test */
100105
flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT;
101106

102-
EXPECT_EQ(0,
103-
test_and_compare_child(flag, PR_RISCV_V_VSTATE_CTRL_ON, 0));
107+
EXPECT_EQ(0, test_and_compare_child(flag, PR_RISCV_V_VSTATE_CTRL_ON, 0, xtheadvector));
104108
}
105109

106110
TEST(vstate_off_nesting)
107111
{
108112
long flag;
113+
int xtheadvector = 0;
109114

110-
if (!is_vector_supported())
111-
SKIP(return, "Vector not supported");
115+
if (!is_vector_supported()) {
116+
if (is_xtheadvector_supported())
117+
xtheadvector = 1;
118+
else
119+
SKIP(return, "Vector not supported");
120+
}
112121

113122
/* Turn off next's vector explicitly and test */
114123
flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT;
115124

116-
EXPECT_EQ(0,
117-
test_and_compare_child(flag, PR_RISCV_V_VSTATE_CTRL_OFF, 1));
125+
EXPECT_EQ(0, test_and_compare_child(flag, PR_RISCV_V_VSTATE_CTRL_OFF, 1, xtheadvector));
118126
}
119127

120128
TEST(vstate_on_inherit_no_nesting)
121129
{
122130
long flag, expected;
131+
int xtheadvector = 0;
123132

124-
if (!is_vector_supported())
125-
SKIP(return, "Vector not supported");
133+
if (!is_vector_supported()) {
134+
if (is_xtheadvector_supported())
135+
xtheadvector = 1;
136+
else
137+
SKIP(return, "Vector not supported");
138+
}
126139

127140
/* Turn on next's vector explicitly and test no inherit */
128141
flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT;
129142
flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT;
130143
expected = flag | PR_RISCV_V_VSTATE_CTRL_ON;
131144

132-
EXPECT_EQ(0, test_and_compare_child(flag, expected, 0));
145+
EXPECT_EQ(0, test_and_compare_child(flag, expected, 0, xtheadvector));
133146
}
134147

135148
TEST(vstate_on_inherit)
136149
{
137150
long flag, expected;
151+
int xtheadvector = 0;
138152

139-
if (!is_vector_supported())
140-
SKIP(return, "Vector not supported");
153+
if (!is_vector_supported()) {
154+
if (is_xtheadvector_supported())
155+
xtheadvector = 1;
156+
else
157+
SKIP(return, "Vector not supported");
158+
}
141159

142160
/* Turn on next's vector explicitly and test inherit */
143161
flag = PR_RISCV_V_VSTATE_CTRL_ON << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT;
144162
flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT;
145163
expected = flag | PR_RISCV_V_VSTATE_CTRL_ON;
146164

147-
EXPECT_EQ(0, test_and_compare_child(flag, expected, 1));
165+
EXPECT_EQ(0, test_and_compare_child(flag, expected, 1, xtheadvector));
148166
}
149167

150168
TEST(vstate_off_inherit_no_nesting)
151169
{
152170
long flag, expected;
171+
int xtheadvector = 0;
153172

154-
if (!is_vector_supported())
155-
SKIP(return, "Vector not supported");
156-
173+
if (!is_vector_supported()) {
174+
if (is_xtheadvector_supported())
175+
xtheadvector = 1;
176+
else
177+
SKIP(return, "Vector not supported");
178+
}
157179
/* Turn off next's vector explicitly and test no inherit */
158180
flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT;
159181
flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT;
160182
expected = flag | PR_RISCV_V_VSTATE_CTRL_OFF;
161183

162-
EXPECT_EQ(0, test_and_compare_child(flag, expected, 0));
184+
EXPECT_EQ(0, test_and_compare_child(flag, expected, 0, xtheadvector));
163185
}
164186

165187
TEST(vstate_off_inherit)
166188
{
167189
long flag, expected;
190+
int xtheadvector = 0;
168191

169-
if (!is_vector_supported())
170-
SKIP(return, "Vector not supported");
192+
if (!is_vector_supported()) {
193+
if (is_xtheadvector_supported())
194+
xtheadvector = 1;
195+
else
196+
SKIP(return, "Vector not supported");
197+
}
171198

172199
/* Turn off next's vector explicitly and test inherit */
173200
flag = PR_RISCV_V_VSTATE_CTRL_OFF << PR_RISCV_V_VSTATE_CTRL_NEXT_SHIFT;
174201
flag |= PR_RISCV_V_VSTATE_CTRL_INHERIT;
175202
expected = flag | PR_RISCV_V_VSTATE_CTRL_OFF;
176203

177-
EXPECT_EQ(0, test_and_compare_child(flag, expected, 1));
204+
EXPECT_EQ(0, test_and_compare_child(flag, expected, 1, xtheadvector));
178205
}
179206

180207
/* arguments should fail with EINVAL */
181208
TEST(inval_set_control_1)
182209
{
183210
int rc;
184211

185-
if (!is_vector_supported())
212+
if (!is_vector_supported() && !is_xtheadvector_supported())
186213
SKIP(return, "Vector not supported");
187214

188215
rc = prctl(PR_RISCV_V_SET_CONTROL, 0xff0);
@@ -195,7 +222,7 @@ TEST(inval_set_control_2)
195222
{
196223
int rc;
197224

198-
if (!is_vector_supported())
225+
if (!is_vector_supported() && !is_xtheadvector_supported())
199226
SKIP(return, "Vector not supported");
200227

201228
rc = prctl(PR_RISCV_V_SET_CONTROL, 0x3);
@@ -208,7 +235,7 @@ TEST(inval_set_control_3)
208235
{
209236
int rc;
210237

211-
if (!is_vector_supported())
238+
if (!is_vector_supported() && !is_xtheadvector_supported())
212239
SKIP(return, "Vector not supported");
213240

214241
rc = prctl(PR_RISCV_V_SET_CONTROL, 0xc);

0 commit comments

Comments
 (0)