2 .\" Konstantin Belousov <kib@FreeBSD.org>. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 .Nd "facility to use the FPU in the kernel"
33 .Ft struct fpu_kern_ctx *
34 .Fn fpu_kern_alloc_ctx "u_int flags"
36 .Fn fpu_kern_free_ctx "struct fpu_kern_ctx *ctx"
38 .Fn fpu_kern_enter "struct thread *td" "struct fpu_kern_ctx *ctx" "u_int flags"
40 .Fn fpu_kern_leave "struct thread *td" "struct fpu_kern_ctx *ctx"
42 .Fn fpu_kern_thread "u_int flags"
44 .Fn is_fpu_kern_thread "u_int flags"
48 family of functions allows the use of FPU hardware in kernel code.
49 Modern FPUs are not limited to providing hardware implementation for
50 floating point arithmetic; they offer advanced accelerators for cryptography
51 and other computational-intensive algorithms.
52 These facilities share registers with the FPU hardware.
54 Typical kernel code does not need access to the FPU.
55 Saving a large register file on each entry to the kernel would waste
57 When kernel code uses the FPU, the current FPU state must be saved to
58 avoid corrupting the user-mode state, and vice versa.
60 The management of the save and restore is automatic.
61 The processor catches accesses to the FPU registers
62 when the non-current context tries to access them.
63 Explicit calls are required for the allocation of the save area and
64 the notification of the start and end of the code using the FPU.
67 .Fn fpu_kern_alloc_ctx
68 function allocates the memory used by
70 to track the use of the FPU hardware state and the related software state.
72 .Fn fpu_kern_alloc_ctx
75 argument, which currently accepts the following flags:
76 .Bl -tag -width ".Dv FPU_KERN_NOWAIT" -offset indent
77 .It Dv FPU_KERN_NOWAIT
78 Do not wait for the available memory if the request could not be satisfied
81 No special handling is required.
84 The function returns the allocated context area, or
86 if the allocation failed.
90 function frees the context previously allocated by
91 .Fn fpu_kern_alloc_ctx .
95 function designates the start of the region of kernel code where the
96 use of the FPU is allowed.
98 .Bl -tag -width ".Fa ctx" -offset indent
103 The context save area previously allocated by
104 .Fn fpu_kern_alloc_ctx
105 and not currently in use by another call to
108 This argument currently accepts the following flags:
109 .Bl -tag -width ".Dv FPU_KERN_NORMAL" -offset indent
110 .It Dv FPU_KERN_NORMAL
111 Indicates that the caller intends to access the full FPU state.
112 Must be specified currently.
114 Indicates that no saving of the current FPU state should be performed,
116 .Xr fpu_kern_thread 9
118 This is intended to minimize code duplication in callers which
119 could be used from both kernel thread and syscall contexts.
122 function correctly handles such contexts.
126 The function does not sleep or block.
128 .Nm Device Not Available
129 exception during execution, and on the first FPU access after the
130 function returns, as well as after each context switch
131 (see Intel Software Developer Manual for the reference).
132 Currently, no errors are defined which can be returned by
138 function ends the region started by
140 The uses of FPU in the kernel after the call to
142 are erronous until the next call to
145 The function takes the
147 thread argument, which currently must be
151 context pointer, previously passed to
153 After the function returns, the context may be freed or reused
154 by other invocation of
156 There are no errors defined for the function, it always returns 0.
160 function provides an optimization for threads which never leave to
162 Such thread can reuse the usermode save area for the FPU state,
163 which is allowed by the function call.
164 There is no flags defined for the function, and no error states
165 that the function returns.
168 .Fn is_fpu_kern_thread
169 function returns the boolean indicating whether the current thread
170 entered the mode enabled by
171 .Fn fpu_kern_thread .
172 There is currently no flags defined for the function, the return
173 value is true if the current thread have the permanent FPU save area,
178 is currently implemented only for the i386 and amd64 architectures.
180 There is no way to handle floating point exceptions raised from
188 functions are to be extended to allow specification of the
189 set of the FPU hardware state used by the code region.
190 This would allow optimizations of saving and restoring the state.
194 facitily and this manual page were written by
195 .An Konstantin Belousov Aq Mt kib@FreeBSD.org .