Skip to content

Commit 48cf170

Browse files
mcmilkbehlendorf
authored andcommitted
Add PPC cpu feature tests for FreeBSD and Linux
Add needed cpu feature tests for powerpc architecture. Overview: zfs_altivec_available() - needed by RAID-Z zfs_vsx_available() - needed by BLAKE3 zfs_isa207_available() - needed by SHA2 Part 1 - Userspace - use getauxval() for Linux and elf_aux_info() for FreeBSD - direct including <sys/auxv.h> fails with double definitions - so we self define the needed functions and definitions Part 2 - Kernel space FreeBSD - use exported cpu_features of <powerpc/cpu.h> Part 3 - Kernel space Linux - use cpu_has_feature() function of <asm/cpufeature.h> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes #13725
1 parent eeca9d2 commit 48cf170

File tree

6 files changed

+200
-113
lines changed

6 files changed

+200
-113
lines changed

include/os/freebsd/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ noinst_HEADERS = \
5050
%D%/spl/sys/sid.h \
5151
%D%/spl/sys/sig.h \
5252
%D%/spl/sys/simd.h \
53+
%D%/spl/sys/simd_powerpc.h \
5354
%D%/spl/sys/simd_x86.h \
5455
%D%/spl/sys/spl_condvar.h \
5556
%D%/spl/sys/string.h \

include/os/freebsd/spl/sys/simd.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@
2626
* $FreeBSD$
2727
*/
2828

29-
3029
#ifndef _FREEBSD_SIMD_H
3130
#define _FREEBSD_SIMD_H
31+
3232
#if defined(__amd64__) || defined(__i386__)
3333
#include <sys/simd_x86.h>
34-
#else
3534

35+
#elif defined(__powerpc__)
36+
#include <sys/simd_powerpc.h>
37+
38+
#else
3639
#define kfpu_allowed() 0
3740
#define kfpu_initialize(tsk) do {} while (0)
3841
#define kfpu_begin() do {} while (0)
3942
#define kfpu_end() do {} while (0)
4043
#define kfpu_init() (0)
4144
#define kfpu_fini() do {} while (0)
4245
#endif
46+
4347
#endif
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or https://opensource.org/licenses/CDDL-1.0.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
22+
/*
23+
* Copyright (C) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
24+
*/
25+
26+
/*
27+
* USER API:
28+
*
29+
* Kernel fpu methods:
30+
* kfpu_allowed()
31+
* kfpu_begin()
32+
* kfpu_end()
33+
* kfpu_init()
34+
* kfpu_fini()
35+
*
36+
* SIMD support:
37+
*
38+
* Following functions should be called to determine whether CPU feature
39+
* is supported. All functions are usable in kernel and user space.
40+
* If a SIMD algorithm is using more than one instruction set
41+
* all relevant feature test functions should be called.
42+
*
43+
* Supported features:
44+
* zfs_altivec_available()
45+
* zfs_vsx_available()
46+
* zfs_isa207_available()
47+
*/
48+
49+
#ifndef _FREEBSD_SIMD_POWERPC_H
50+
#define _FREEBSD_SIMD_POWERPC_H
51+
52+
#include <sys/types.h>
53+
#include <sys/cdefs.h>
54+
55+
#include <machine/pcb.h>
56+
#include <powerpc/cpu.h>
57+
58+
#define kfpu_allowed() 1
59+
#define kfpu_initialize(tsk) do {} while (0)
60+
#define kfpu_begin() do {} while (0)
61+
#define kfpu_end() do {} while (0)
62+
#define kfpu_init() (0)
63+
#define kfpu_fini() do {} while (0)
64+
65+
/*
66+
* Check if Altivec is available
67+
*/
68+
static inline boolean_t
69+
zfs_altivec_available(void)
70+
{
71+
return ((cpu_features & PPC_FEATURE_HAS_ALTIVEC) != 0);
72+
}
73+
74+
/*
75+
* Check if VSX is available
76+
*/
77+
static inline boolean_t
78+
zfs_vsx_available(void)
79+
{
80+
return ((cpu_features & PPC_FEATURE_HAS_VSX) != 0);
81+
}
82+
83+
/*
84+
* Check if POWER ISA 2.07 is available (SHA2)
85+
*/
86+
static inline boolean_t
87+
zfs_isa207_available(void)
88+
{
89+
return ((cpu_features2 & PPC_FEATURE2_ARCH_2_07) != 0);
90+
}

include/os/freebsd/spl/sys/simd_x86.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ __simd_state_enabled(const uint64_t state)
7777
boolean_t has_osxsave;
7878
uint64_t xcr0;
7979

80-
has_osxsave = !!(cpu_feature2 & CPUID2_OSXSAVE);
80+
has_osxsave = (cpu_feature2 & CPUID2_OSXSAVE) != 0;
8181

8282
if (!has_osxsave)
8383
return (B_FALSE);
@@ -99,7 +99,7 @@ __simd_state_enabled(const uint64_t state)
9999
static inline boolean_t
100100
zfs_sse_available(void)
101101
{
102-
return (!!(cpu_feature & CPUID_SSE));
102+
return ((cpu_feature & CPUID_SSE) != 0);
103103
}
104104

105105
/*
@@ -108,7 +108,7 @@ zfs_sse_available(void)
108108
static inline boolean_t
109109
zfs_sse2_available(void)
110110
{
111-
return (!!(cpu_feature & CPUID_SSE2));
111+
return ((cpu_feature & CPUID_SSE2) != 0);
112112
}
113113

114114
/*
@@ -117,7 +117,7 @@ zfs_sse2_available(void)
117117
static inline boolean_t
118118
zfs_sse3_available(void)
119119
{
120-
return (!!(cpu_feature2 & CPUID2_SSE3));
120+
return ((cpu_feature2 & CPUID2_SSE3) != 0);
121121
}
122122

123123
/*
@@ -126,7 +126,7 @@ zfs_sse3_available(void)
126126
static inline boolean_t
127127
zfs_ssse3_available(void)
128128
{
129-
return (!!(cpu_feature2 & CPUID2_SSSE3));
129+
return ((cpu_feature2 & CPUID2_SSSE3) != 0);
130130
}
131131

132132
/*
@@ -135,7 +135,7 @@ zfs_ssse3_available(void)
135135
static inline boolean_t
136136
zfs_sse4_1_available(void)
137137
{
138-
return (!!(cpu_feature2 & CPUID2_SSE41));
138+
return ((cpu_feature2 & CPUID2_SSE41) != 0);
139139
}
140140

141141
/*
@@ -144,7 +144,7 @@ zfs_sse4_1_available(void)
144144
static inline boolean_t
145145
zfs_sse4_2_available(void)
146146
{
147-
return (!!(cpu_feature2 & CPUID2_SSE42));
147+
return ((cpu_feature2 & CPUID2_SSE42) != 0);
148148
}
149149

150150
/*
@@ -155,7 +155,7 @@ zfs_avx_available(void)
155155
{
156156
boolean_t has_avx;
157157

158-
has_avx = !!(cpu_feature2 & CPUID2_AVX);
158+
has_avx = (cpu_feature2 & CPUID2_AVX) != 0;
159159

160160
return (has_avx && __ymm_enabled());
161161
}
@@ -168,7 +168,7 @@ zfs_avx2_available(void)
168168
{
169169
boolean_t has_avx2;
170170

171-
has_avx2 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX2);
171+
has_avx2 = (cpu_stdext_feature & CPUID_STDEXT_AVX2) != 0;
172172

173173
return (has_avx2 && __ymm_enabled());
174174
}
@@ -196,7 +196,7 @@ zfs_avx512f_available(void)
196196
{
197197
boolean_t has_avx512;
198198

199-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F);
199+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0;
200200

201201
return (has_avx512 && __zmm_enabled());
202202
}
@@ -207,8 +207,8 @@ zfs_avx512cd_available(void)
207207
{
208208
boolean_t has_avx512;
209209

210-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F) &&
211-
!!(cpu_stdext_feature & CPUID_STDEXT_AVX512CD);
210+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0 &&
211+
(cpu_stdext_feature & CPUID_STDEXT_AVX512CD) != 0;
212212

213213
return (has_avx512 && __zmm_enabled());
214214
}
@@ -219,8 +219,8 @@ zfs_avx512er_available(void)
219219
{
220220
boolean_t has_avx512;
221221

222-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F) &&
223-
!!(cpu_stdext_feature & CPUID_STDEXT_AVX512CD);
222+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0 &&
223+
(cpu_stdext_feature & CPUID_STDEXT_AVX512CD) != 0;
224224

225225
return (has_avx512 && __zmm_enabled());
226226
}
@@ -231,8 +231,8 @@ zfs_avx512pf_available(void)
231231
{
232232
boolean_t has_avx512;
233233

234-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F) &&
235-
!!(cpu_stdext_feature & CPUID_STDEXT_AVX512PF);
234+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0 &&
235+
(cpu_stdext_feature & CPUID_STDEXT_AVX512PF) != 0;
236236

237237
return (has_avx512 && __zmm_enabled());
238238
}
@@ -243,7 +243,7 @@ zfs_avx512bw_available(void)
243243
{
244244
boolean_t has_avx512 = B_FALSE;
245245

246-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512BW);
246+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512BW) != 0;
247247

248248
return (has_avx512 && __zmm_enabled());
249249
}
@@ -254,8 +254,8 @@ zfs_avx512dq_available(void)
254254
{
255255
boolean_t has_avx512;
256256

257-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F) &&
258-
!!(cpu_stdext_feature & CPUID_STDEXT_AVX512DQ);
257+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0 &&
258+
(cpu_stdext_feature & CPUID_STDEXT_AVX512DQ) != 0;
259259

260260
return (has_avx512 && __zmm_enabled());
261261
}
@@ -266,8 +266,8 @@ zfs_avx512vl_available(void)
266266
{
267267
boolean_t has_avx512;
268268

269-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F) &&
270-
!!(cpu_stdext_feature & CPUID_STDEXT_AVX512VL);
269+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0 &&
270+
(cpu_stdext_feature & CPUID_STDEXT_AVX512VL) != 0;
271271

272272
return (has_avx512 && __zmm_enabled());
273273
}
@@ -278,8 +278,8 @@ zfs_avx512ifma_available(void)
278278
{
279279
boolean_t has_avx512;
280280

281-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F) &&
282-
!!(cpu_stdext_feature & CPUID_STDEXT_AVX512IFMA);
281+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0 &&
282+
(cpu_stdext_feature & CPUID_STDEXT_AVX512IFMA) != 0;
283283

284284
return (has_avx512 && __zmm_enabled());
285285
}
@@ -290,8 +290,8 @@ zfs_avx512vbmi_available(void)
290290
{
291291
boolean_t has_avx512;
292292

293-
has_avx512 = !!(cpu_stdext_feature & CPUID_STDEXT_AVX512F) &&
294-
!!(cpu_stdext_feature & CPUID_STDEXT_BMI1);
293+
has_avx512 = (cpu_stdext_feature & CPUID_STDEXT_AVX512F) != 0 &&
294+
(cpu_stdext_feature & CPUID_STDEXT_BMI1) != 0;
295295

296296
return (has_avx512 && __zmm_enabled());
297297
}

0 commit comments

Comments
 (0)