AVX
Kostik Belousov
kostikbel at gmail.com
Mon Dec 26 22:28:15 UTC 2011
Hello,
The patch at
http://people.freebsd.org/~kib/misc/avx.1.patch
is the preliminary version, i.e. WIP, of the implementation of
variable-sized extended FPU states, as defined by Intel SDM. The
architecture (sometimes referred to as XSAVE) allows CPU to provide
additional context state data and report the details of context save
area layout to OS in the extendable form. AVX with it 256-bit YMM
register file is the first application of the architecture.
Due to extensibility and self-description of XSAVE area, by default
kernel allows all CPU extensions, i.e. also possible future features
of FPU. The tunable 'hw.xsave_allow_unknown' is provided, which
disables CPU features not known to the kernel. The tunable
'hw.use_xsave' may be used to disable XSAVE support at all.
The 'struct fpusave fpu_user_save' member was removed from amd64 pcb,
the save area is chopped from the top of the thread kernel kernel
stack (fpu_user_save was located there previously). I moved thread0
pcb set up after first stage of FPU initialization is done. Also,
there is a silent change in fpu init code, now we explicitely clear
XMM register file in the initial FPU state. At least on my
SandyBridge, XMM init state is garbage, could be some vacuum tubes
they stuff into chip were broken when machine crashed from 1 meter
down.
Since YMM file is part of the FPU state, it must be added to
mcontext_t. Unfortunately, it is impossible to extend mcontext_t
in-place and not break present ABI without duplicating all syscalls
and libraries entries that use ucontext_t. The cause is that
ucontext_t layout puts mcontext_t into the middle of the structure,
frozing its size. The solution in the patch is to put extended save
area outside the mcontext_t, and place a pointer to area in
mcontext_t. Pointer validity is specified by _MC_HASFPXSTATE
mcontext_t flag.
Signal post provides the extended area on the signal stack frame
automagically. If pointers to area are in context, setcontext(2) uses
it. For getcontext(2), no easy solution exists. I tried to play with
providing libc wrapper for getcontext(2) that hides mcontext_t size
increase, but gave up due to ucontext_t embedding. Instead,
getcontextx(3) API is implemented that allocates the needed memory.
The patch defines ABI for both i386 and amd64 FreeBSD processes, but
the implementation is provided for amd64 kernel only for both ABIs. I
do not see any reason to run i386 kernel on machines capable of AVX.
The fpu_kern KPI has to be changed to accomodate for variable size
TODO items:
- I think we are eligible for XSAVEOPT use, but did not looked
into details yet;
- benchmark the cost for context switches and signal handlers
entry/sigreturn;
- makecontextx(3) ?;
- padlock(4) testing;
- make i386 fpu_kern KPI changes;
- implement (trivial) getcontextx(3) for other architectures.
Patch in the present form only usable on amd64 machine for both amd64
and i386 userspace.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-amd64/attachments/20111226/89229c33/attachment.pgp
More information about the freebsd-amd64
mailing list