Does the Linux kernel have its own SSE/AVX context?
I mean, from the point of view of a kernel module, can I use SSE/AVX instructions without worrying about user-space applications which may use it too? Or do I need to use some locks or do some context saving manually?
The Linux kernel does not save FPU or vector registers by default to improve the speed of context switches. However, you can make use of them under certain circumstances.
Section 6.3 of http://agner.org/optimize/calling_conventions.pdf describes very well the use of vector registers in kernel mode, both in Windows and in Linux. Here's one important quote:
A device driver that needs to use vector registers must first save these registers by calling the function kernel_fpu_begin() and restore the registers by calling kernel_fpu_end() before returning or sleeping.
There's more, like the fact that you can't use them at all in interrupt context, so I suggest reading the entire section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With