Re: Double or float in kernel modules

Richard B. Johnson (root@chaos.analogic.com)
Sun, 25 Apr 1999 20:36:16 -0400 (EDT)


On Sun, 25 Apr 1999, Ravi Wijayaratne wrote:

> Hi,
>
> Can "double" or "float" be used in kernel modules ?
> Is there a significan performance penalty in using them inside
> the kernel?
>
> Some information is much appreciated
>
> Ravi

This is becoming a FAQ.

You can't use the floating point unit inside the kernel. The reason is
that the state of the FPU is undefined within the kernel. Of course,
in principle, anything is possible, however, you would have to:

(1) Lock the kernel.
(2) Save the current FPU state (this also does 'finit').
(3) Do the math.
(4) restore the FPU state.
(5) Ulock the kernel.

I don't have the ix86 book here, but it's about 130 or so clocks to
save the FPU state and slightly less to restore it. You can do a
lot of integer math in those clocks.

It is also difficult to have the 'C' compiler do what you want when
you want it, so to make sure the FPU state was safe, you probably
would have to do everything in inline-asm. There is the additional
problem of handling FPU exceptions within the kernel.

So, as you can see, you don't want to use the FPU within the kernel.
Also, some ix86 processors don't have FPU units. When encountering
a FPU opcode, the kernel traps to an exception handler which emulates
the FPU.

Cheers,
Dick Johnson
***** FILE SYSTEM WAS MODIFIED *****
Penguin : Linux version 2.2.6 on an i686 machine (400.59 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/