Skip to contentSkip to conversation

Doing floating point calculations in kernel space

DISCUSSION Toni Van Remortel 3 participants 6 messages Oct 17, 2003

lore
Share & tools
lore
#0 lore raw

Hi all,

When I thought it was a /proc problem, it was a float problem. The CPU (405GP) has no FPU, but I need to calculate sin and cos in a kernel module.
Why? Well, we use a formula to draw figures (all deformed circles). Those figures can be defined with only 6 parameters, which are passed from the control-panel (in userspace) to the RTAI-powered kernel module. That module calculates the X and Y positions, creates PWM signals from it and outputs them to GPIO1 and 2.

I don't see another approach to get this working, because the control-panel isn't real time, while the kernel module is. So the module needs to calculate the X and Y positions from the 6 parameters.

To make it short: can I use floating points in kernel space? The info I've found just tells me 'no', but I'm wondering if there are any workarounds for this.
I did find some 'faster math functions' which don't require any sin or cos anymore, but they do require floating points.

A possible solution to me, is using 'unsinged long int' multiplied by some factor of 10.

Anybody a better solution?

PS: might be a bit off topic here, sorry about that.
--
Toni Van Remortel
Wetenschappelijk Medewerker - D-science lab
Real time Linux for embedded systems: http://linemb.d-sciencelab.com

              Tel: +32 3 205 61 72 - Fax: +32 3 205 61 95
                      E-mail: [email protected]

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#1 lore raw

Hi,

this has been discussed recently. For RTAI on MPC 8xx we provide the following example:

ftp://ftp.denx.de/pub/RTAI/contrib/fp_ppc_8xx.tar.bz2

It links statically with the libm and the soft-float library derived from libgcc.

Hope it's useful.

Quoted 35 lines

-- Original Message --
Subject: Doing floating point calculations in kernel space
From: Toni Van Remortel <[email protected]>
Reply-To: [email protected]
To: Linuxppc-Embedded <[email protected]>
Date: Fri, 17 Oct 2003 09:15:39 +0200

Hi all,

When I thought it was a /proc problem, it was a float problem. The CPU (405GP) has no FPU, but I need to calculate sin and cos in a kernel module.
Why? Well, we use a formula to draw figures (all deformed circles). Those figures can be defined with only 6 parameters, which are passed from the control-panel (in userspace) to the RTAI-powered kernel module. That module calculates the X and Y positions, creates PWM signals from it and outputs them to GPIO1 and 2.

I don't see another approach to get this working, because the control-panel isn't real time, while the kernel module is. So the module needs to calculate the X and Y positions from the 6 parameters.

To make it short: can I use floating points in kernel space? The info I've found just tells me 'no', but I'm wondering if there are any workarounds for this.
I did find some 'faster math functions' which don't require any sin or cos anymore, but they do require floating points.

A possible solution to me, is using 'unsinged long int' multiplied by some factor of 10.

Anybody a better solution?

Quoted 10 lines

PS: might be a bit off topic here, sorry about that.
--
Toni Van Remortel
Wetenschappelijk Medewerker - D-science lab
Real time Linux for embedded systems: http://linemb.d-sciencelab.com

             Tel: +32 3 205 61 72 - Fax: +32 3 205 61 95
                     E-mail: [email protected]


Wolfgang

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#2 lore raw

Op vr 17-10-2003, om 09:33 schreef Wolfgang Grandegger:

Quoted 11 lines

Hi,

this has been discussed recently. For RTAI on MPC 8xx we provide the following example:

ftp://ftp.denx.de/pub/RTAI/contrib/fp_ppc_8xx.tar.bz2

It links statically with the libm and the soft-float library derived from libgcc.

Hope it's useful.

Seems useful. Let's check it out deeper and implement it into my module.

I'll keep you informed.

Tnx!
--
Toni Van Remortel
Wetenschappelijk Medewerker - D-science lab
Real time Linux for embedded systems: http://linemb.d-sciencelab.com

              Tel: +32 3 205 61 72 - Fax: +32 3 205 61 95
                      E-mail: [email protected]

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#3 lore raw

Op vr 17-10-2003, om 09:52 schreef Toni Van Remortel:

Quoted 9 lines

Op vr 17-10-2003, om 09:33 schreef Wolfgang Grandegger:

Quoted 5 lines

ftp://ftp.denx.de/pub/RTAI/contrib/fp_ppc_8xx.tar.bz2
It links statically with the libm and the soft-float library derived from libgcc.

Hope it's useful.

Seems useful. Let's check it out deeper and implement it into my module. I'll keep you informed.

It compiles, it runs. Very nice. Thank you a lot for the example. I had only to add the extra linking to my compile command.

Regards,

--
Toni Van Remortel
Wetenschappelijk Medewerker - D-science lab
Real time Linux for embedded systems: http://linemb.d-sciencelab.com

              Tel: +32 3 205 61 72 - Fax: +32 3 205 61 95
                      E-mail: [email protected]

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#4 lore raw
Quoted 16 lines

-- Original Message --
Subject: RE: Doing floating point calculations in kernel space
From: Toni Van Remortel <[email protected]>
Reply-To: [email protected]
To: Wolfgang Grandegger <[email protected]>
Cc: Linuxppc-Embedded <[email protected]>
Date: Fri, 17 Oct 2003 10:59:29 +0200

Op vr 17-10-2003, om 09:52 schreef Toni Van Remortel:

Quoted 5 lines

Op vr 17-10-2003, om 09:33 schreef Wolfgang Grandegger:

Quoted 4 lines

ftp://ftp.denx.de/pub/RTAI/contrib/fp_ppc_8xx.tar.bz2
It links statically with the libm and the soft-float library derived from libgcc.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Hope it's useful.

Seems useful. Let's check it out deeper and implement it into my module. I'll keep you informed.

It compiles, it runs. Very nice. Thank you a lot for the example. I had only to add the extra linking to my compile command.

Unfortunately, this soft-float implementation from GCC is very very slow :-(. I'm just doing some benchmarking with soft-float on IBM 405 and compare the result with the soft-float library provided by VxWorks. And a simple add (__adddf3) is approx. 5 times faster on VxWorks. And a look to the assembler code makes clear why. Has anybody else on this list made similar experience or it there a better free implementation? Has this been improved in GCC >= 3.2.

Thanks.

Wolfgang.

Wolfgang

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/

#5 lore raw
Quoted 23 lines · Wolfgang Grandegger
Quoted 15 lines

-- Original Message --
Subject: RE: Doing floating point calculations in kernel space
From: Toni Van Remortel <[email protected]>
Reply-To: [email protected]
To: Wolfgang Grandegger <[email protected]>
Cc: Linuxppc-Embedded <[email protected]>
Date: Fri, 17 Oct 2003 10:59:29 +0200

Op vr 17-10-2003, om 09:52 schreef Toni Van Remortel:

Quoted 5 lines

Op vr 17-10-2003, om 09:33 schreef Wolfgang Grandegger:

Quoted 4 lines

ftp://ftp.denx.de/pub/RTAI/contrib/fp_ppc_8xx.tar.bz2
It links statically with the libm and the soft-float library derived from libgcc.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Hope it's useful.

Seems useful. Let's check it out deeper and implement it into my module. I'll keep you informed.

It compiles, it runs. Very nice. Thank you a lot for the example. I had only to add the extra linking to my compile command.

Quoted 9 lines

Unfortunately, this soft-float implementation from GCC is very very slow :-(. I'm just doing some benchmarking with soft-float on IBM 405 and compare the result with the soft-float library provided by VxWorks. And a simple add (__adddf3) is approx. 5 times faster on VxWorks. And a look to the assembler code makes clear why. Has anybody else on this list made similar experience or it there a better free implementation? Has this been improved in GCC >= 3.2.

A long time ago (circa 1995, when I first started the Linux/PPC port), Motorola volunteered a very fast floating point library. I tested it (in user applications) and found the results to be quite good. There was never any impetuous to try and put this in the kernel, but it should work OK. The [more immediate] problem might be licensing issues, as IIRC, they didn't want the sources to be public.

Maybe there are some Motorola "lurkers" who could comment.

--
Gary Thomas <[email protected]>
MLB Associates

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/