RE: [PATCH 1/4] x86/fpu: Add kernel_fpu_begin_mask() to selectively initialize state

From: David Laight
Date: Mon Jan 18 2021 - 09:05:33 EST


From: Andy Lutomirski
> Sent: 18 January 2021 06:21
>
> Currently, requesting kernel FPU access doesn't distinguish which parts of
> the extended ("FPU") state are needed. This is nice for simplicity, but
> there are a few cases in which it's suboptimal:
>
> - The vast majority of in-kernel FPU users want XMM/YMM/ZMM state but do
> not use legacy 387 state. These users want MXCSR initialized but don't
> care about the FPU control word. Skipping FNINIT would save time.
> (Empirically, FNINIT is several times slower than LDMXCSR.)
>
> - Code that wants MMX doesn't want need MXCSR or FCW initialized.
> _mmx_memcpy(), for example, can run before CR4.OSFXSR gets set, and
> initializing MXCSR will fail.
>
> - Any future in-kernel users of XFD (eXtended Feature Disable)-capable
> dynamic states will need special handling.
>
> This patch adds a more specific API that allows callers specify exactly
> what they want.

Is it worth returning whether the required fpu feature is available?
Or, maybe optionally, available cheaply?

There are also code fragments that really just want one or two
[xyx]mm registers to speed something up.
For instance PCIe reads can be a lot faster if a wide register
can be used.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)