Question

Using FPU in Linux kernel supposes that FPU block encloses with kernel_fpu_begin and kernel_fpu_end functions. The first one looks like this:

 41 static inline void kernel_fpu_begin(void)
 42 {
 43         WARN_ON_ONCE(!irq_fpu_usable());
 44         preempt_disable();
 45         __kernel_fpu_begin();
 46 }

Kernel issues a warning if FPU can't be usable because of:

 64 bool irq_fpu_usable(void)
 65 {
 66         return !in_interrupt() ||
 67                 interrupted_user_mode() ||
 68                 interrupted_kernel_fpu_idle();
 69 }
 70 EXPORT_SYMBOL(irq_fpu_usable);

So, am I right that we can't use FPU in interrupt context?

And if it is I want to know why we can't?

Was it helpful?

Solution

The kernel has only one place to save the FPU state, so it is not allowed to have kernel FPU code that interrupts other kernel FPU code.

The irq_fpu_usable function prints a warning only for kernel FPU code that actually is interrupting other kernel FPU code, but in practice, it is not possible to control when your interrupt runs.

Therefore, using FPU in interrupt context is not really possible. (It does not make sense either, because FPU code is useful only as a performance optimization, and interrupts should never run for so long that such optimizations are needed.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top