Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Linux kernel have its own SSE/AVX context?

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?

like image 394
Ilya Matveychikov Avatar asked Sep 03 '13 10:09

Ilya Matveychikov


1 Answers

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.

like image 154
Peter Avatar answered Nov 11 '22 22:11

Peter