1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2020 Joyent, Inc.
*/
#ifndef _SIMD_H
#define _SIMD_H
#if defined(__amd64__) || defined(__i386__)
#define kfpu_initialize(tsk) do {} while (0)
#define kfpu_init() (0)
#define kfpu_fini() do {} while (0)
#ifdef _KERNEL
#include <sys/x86_archext.h>
#include <sys/archsystm.h>
#include <sys/kfpu.h>
#include <sys/proc.h>
#include <sys/disp.h>
#include <sys/cpuvar.h>
static inline int
kfpu_allowed(void)
{
extern int zfs_fpu_enabled;
return (zfs_fpu_enabled != 0 ? 1 : 0);
}
static inline void
kfpu_begin(void)
{
if (curthread->t_lwp != NULL && (curthread->t_procp->p_flag & SSYS)) {
kernel_fpu_begin(NULL, KFPU_USE_LWP);
} else {
kpreempt_disable();
kernel_fpu_begin(NULL, KFPU_NO_STATE);
}
}
static inline void
kfpu_end(void)
{
if (curthread->t_lwp != NULL && (curthread->t_procp->p_flag & SSYS)) {
kernel_fpu_end(NULL, KFPU_USE_LWP);
} else {
kernel_fpu_end(NULL, KFPU_NO_STATE);
kpreempt_enable();
}
}
/*
* Check if various vector instruction sets are available.
*/
static inline boolean_t
zfs_sse_available(void)
{
return (is_x86_feature(x86_featureset, X86FSET_SSE));
}
static inline boolean_t
zfs_sse2_available(void)
{
return (is_x86_feature(x86_featureset, X86FSET_SSE2));
}
static inline boolean_t
zfs_sse3_available(void)
{
return (is_x86_feature(x86_featureset, X86FSET_SSE3));
}
static inline boolean_t
zfs_ssse3_available(void)
{
return (is_x86_feature(x86_featureset, X86FSET_SSSE3));
}
static inline boolean_t
zfs_avx_available(void)
{
return (is_x86_feature(x86_featureset, X86FSET_AVX));
}
static inline boolean_t
zfs_avx2_available(void)
{
return (is_x86_feature(x86_featureset, X86FSET_AVX2));
}
#else /* ! _KERNEL */
#include <sys/auxv.h>
#include <sys/auxv_386.h>
#define kfpu_allowed() 1
#define kfpu_begin() do {} while (0)
#define kfpu_end() do {} while (0)
/*
* User-level check if various vector instruction sets are available.
*/
static inline boolean_t
zfs_sse_available(void)
{
uint32_t u = 0;
(void) getisax(&u, 1);
return ((u & AV_386_SSE) != 0);
}
static inline boolean_t
zfs_sse2_available(void)
{
uint32_t u = 0;
(void) getisax(&u, 1);
return ((u & AV_386_SSE2) != 0);
}
static inline boolean_t
zfs_sse3_available(void)
{
uint32_t u = 0;
(void) getisax(&u, 1);
return ((u & AV_386_SSE3) != 0);
}
static inline boolean_t
zfs_ssse3_available(void)
{
uint32_t u = 0;
(void) getisax(&u, 1);
return ((u & AV_386_SSSE3) != 0);
}
static inline boolean_t
zfs_avx_available(void)
{
uint_t u = 0;
(void) getisax(&u, 1);
return ((u & AV_386_AVX) != 0);
}
static inline boolean_t
zfs_avx2_available(void)
{
uint32_t u[2] = { 0 };
(void) getisax((uint32_t *)&u, 2);
return ((u[1] & AV_386_2_AVX2) != 0);
}
#endif /* _KERNEL */
#else
/* Non-x86 CPUs currently always disallow kernel FPU support */
#define kfpu_allowed() 0
#define kfpu_initialize(tsk) do {} while (0)
#define kfpu_begin() do {} while (0)
#define kfpu_end() do {} while (0)
#define kfpu_init() (0)
#define kfpu_fini() do {} while (0)
#endif
#endif /* _SIMD_H */
|