From: Linus Torvalds <torvalds@osdl.org>
To: "Måns Rullgård" <mru@kth.se>
Cc: linux-kernel@vger.kernel.org
Subject: Re: How to use floating point in a module?
Date: Sun, 30 May 2004 21:28:09 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0405302121440.1730@ppc970.osdl.org> (raw)
In-Reply-To: <yw1xbrk5baq3.fsf@kth.se>
On Mon, 31 May 2004, Måns Rullgård wrote:
>
> Floating point is forbidden in kernel code since the floating point
> registers (and other floating point context) is not saved/restored
> during system calls, for efficiency. I'm speculating here, but it
> might be possible to manually save the floating point context while
> doing some floating point operations. The problem arises if this code
> is interrupted midway. Using a preemptive 2.6 kernel would easily
> break here.
You can do it "safely" on x86 using
kernel_fpu_begin();
...
kernel_fpu_end();
and make sure that _all_ the FP stuff is in between those two things, and
that you don't do _anything_ that might fault or sleep.
The kernel_fpu_xxx() macros make sure that preemption is turned off etc,
so the above should always be safe.
Even then, of course, using FP in the kernel assumes that you actually
_have_ an FPU, of course. The in-kernel FP emulation package is _not_
supposed to work with kernel FP instructions.
Oh, and since the kernel doesn't link with libc, you can't use anything
even remotely fancy. It all has to be stuff that gcc can do in-line,
without any function calls.
In other words: the rule is that you really shouldn't use FP in the
kernel. There are ways to do it, but they tend to be for some _real_
special cases, notably for doing MMX/XMM work. Ie the only "proper" FPU
user is actually the RAID checksumming MMX stuff.
Linus
next prev parent reply other threads:[~2004-05-31 4:28 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-31 1:52 ndiamond
2004-05-31 2:18 ` Måns Rullgård
2004-05-30 22:39 ` Calvin Spealman
2004-05-31 4:28 ` Linus Torvalds [this message]
2004-05-31 3:57 ` Calvin Spealman
2004-05-31 3:59 ` Matt Mackall
2004-05-31 4:11 ` Stephen Smoogen
2004-05-31 14:55 ` Scott Robert Ladd
2004-06-01 2:11 ` Richard B. Johnson
2004-05-31 2:50 ndiamond
2004-05-31 4:02 ` Chris Friesen
2004-05-31 5:44 ` Ian Kent
2004-05-31 6:13 ` Peter Williams
2004-05-31 13:39 ` Horst von Brand
2004-05-31 20:12 ` Michal Jaegermann
2004-05-31 20:23 ` Hugo Mills
2004-05-31 22:43 ` Peter Williams
2004-05-31 20:38 Manfred Spraul
2004-05-31 21:11 ` Horst von Brand
2004-06-01 0:38 ndiamond
2004-06-01 20:52 ` H. Peter Anvin
2004-06-01 2:27 ndiamond
2004-06-02 5:52 ndiamond
2004-06-02 19:31 ` Valdis.Kletnieks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.58.0405302121440.1730@ppc970.osdl.org \
--to=torvalds@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mru@kth.se \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®