public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: FPU-intensive programs crashing with floating point  exception on Cyrix MII
@ 2005-08-21  9:47 Chuck Ebbert
  2005-08-21 17:52 ` Linus Torvalds
  2005-08-22  7:19 ` FPU-intensive programs crashing with floating point Ingo Molnar
  0 siblings, 2 replies; 9+ messages in thread
From: Chuck Ebbert @ 2005-08-21  9:47 UTC (permalink / raw)
  To: Ondrej Zary; +Cc: linux-kernel, Linus Torvalds, Ingo Molnar

On Thu, 18 Aug 2005 12:37:30 +0200, Ondrej Zary wrote:

> >   Could you modify this to print the full values of cwd and swd like this?
> > 
> >         printk("MATH ERROR: cwd = 0x%hx, swd = 0x%hx\n", cwd, swd);
> > 
> > Then post the result.
> MATH ERROR: cwd = 0x37f, swd = 0x5020
> MATH ERROR: cwd = 0x37f, swd = 0x20
> MATH ERROR: cwd = 0x37f, swd = 0x20
> MATH ERROR: cwd = 0x37f, swd = 0x2020
> MATH ERROR: cwd = 0x37f, swd = 0x20
> MATH ERROR: cwd = 0x37f, swd = 0x1820
> MATH ERROR: cwd = 0x37f, swd = 0x1820
> MATH ERROR: cwd = 0x37f, swd = 0x2020
> MATH ERROR: cwd = 0x37f, swd = 0x20
> MATH ERROR: cwd = 0x37f, swd = 0x2800     <===========
> MATH ERROR: cwd = 0x37f, swd = 0x1820
> MATH ERROR: cwd = 0x37f, swd = 0x820
> MATH ERROR: cwd = 0x37f, swd = 0x2820
> MATH ERROR: cwd = 0x37f, swd = 0x2820
> MATH ERROR: cwd = 0x37f, swd = 0x1820
> MATH ERROR: cwd = 0x37f, swd = 0x820
> MATH ERROR: cwd = 0x37f, swd = 0x1a20

 The error I marked has no exception flags set.  The rest are all (masked)
denormal exceptions.  Why your Cyrix MII would cause an FPU exception in these
cases is beyond me.  Could you try the statically-linked mprime program?

 I had hoped someone who knew more about FPU error handling would jump in.
The below code from arch/i386/kernel/traps.c sends a signal back to
userspace even when the status word shows a masked (or no) exception has
occurred.  The 'case 0x000' strongly suggests this is deliberate but I
don't know why.


        /*
         * (~cwd & swd) will mask out exceptions that are not set to unmasked
         * status.  0x3f is the exception bits in these regs, 0x200 is the
         * C1 reg you need in case of a stack fault, 0x040 is the stack
         * fault bit.  We should only be taking one exception at a time,
         * so if this combination doesn't produce any single exception,
         * then we have a bad program that isn't syncronizing its FPU usage
         * and it will suffer the consequences since we won't be able to
         * fully reproduce the context of the exception
         */
        cwd = get_fpu_cwd(task);
        swd = get_fpu_swd(task);
        switch (((~cwd) & swd & 0x3f) | (swd & 0x240)) {
                case 0x000:
                default:
                        break;
                case 0x001: /* Invalid Op */
                case 0x041: /* Stack Fault */
                case 0x241: /* Stack Fault | Direction */
                        info.si_code = FPE_FLTINV;
                        /* Should we clear the SF or let user space do it ???? */
                        break;


(And it looks like there is a small bug in there.  The switch should be:

        switch (((~cwd) & swd & 0x3f) | (swd & 1 ? swd & 0x240 : 0)) {

because the SF and CC1 bits are only relevant when IE is set.)

__
Chuck

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: FPU-intensive programs crashing with floating point exception on Cyrix MII
@ 2005-08-17 18:49 Chuck Ebbert
  2005-08-18 10:37 ` Ondrej Zary
  0 siblings, 1 reply; 9+ messages in thread
From: Chuck Ebbert @ 2005-08-17 18:49 UTC (permalink / raw)
  To: Ondrej Zary; +Cc: linux-kernel

On Wed, 17 Aug 2005 at 18:13:55 +0200, Ondrej Zary wrote:

> When I run a program that uses FPU, it sometimes crashes with "flaoting 
> point exception"


> +     printk("MATH ERROR %d\n",((~cwd) & swd & 0x3f) | (swd & 0x240));

  Could you modify this to print the full values of cwd and swd like this?

        printk("MATH ERROR: cwd = 0x%hx, swd = 0x%hx\n", cwd, swd);

Then post the result.


__
Chuck

^ permalink raw reply	[flat|nested] 9+ messages in thread
* FPU-intensive programs crashing with floating point exception on Cyrix MII
@ 2005-08-17 16:13 Ondrej Zary
  2005-08-17 17:08 ` linux-os (Dick Johnson)
  0 siblings, 1 reply; 9+ messages in thread
From: Ondrej Zary @ 2005-08-17 16:13 UTC (permalink / raw)
  To: Linux Kernel Mailing List

[-- Attachment #1: Type: text/plain, Size: 1081 bytes --]

My machine (Cyrix MII PR300 CPU, PCPartner TXB820DS board with i430TX 
chipset) exhibits a really weird problem:
When I run a program that uses FPU, it sometimes crashes with "flaoting 
point exception" - for example, when playing MP3 files using any player. 
Or with Prime95 - http://www.mersenne.org/freesoft.htm - the "torture 
test" does not crash but shows "fatal error" in less than 10 minutes.
It might be something like this:
http://lists.suse.com/archive/suse-linux-e/2000-Sep/1080.html
or this
http://lists.slug.org.au/archives/slug/2000/11/msg00343.html

The problem appears on 2.4.x kernels and 2.6.x kernels. It works fine in 
Windows 98 - it can play MP3s and run Prime95 for hours without any 
problems.
I've tracked it down to math_error() in arch/i386/kernel/traps.c and 
"fixed" it (I really don't know anything about FPU programming). The 
patch is attached. It fixes my system - with the patch, I can play MP3s 
fine and Prime95 runs without any problems too.

Does anyone know why these exceptions happen and/or what's the correct 
solution?

-- 
Ondrej Zary


[-- Attachment #2: cyrix-math.patch --]
[-- Type: text/plain, Size: 530 bytes --]

--- linux-2.6.10/arch/i386/kernel/traps.c~	2004-12-25 12:02:03.000000000 +0100
+++ linux-2.6.10/arch/i386/kernel/traps.c	2004-12-25 12:02:03.000000000 +0100
@@ -790,8 +790,11 @@
 	 */
 	cwd = get_fpu_cwd(task);
 	swd = get_fpu_swd(task);
+	printk("MATH ERROR %d\n",((~cwd) & swd & 0x3f) | (swd & 0x240));
 	switch (((~cwd) & swd & 0x3f) | (swd & 0x240)) {
-		case 0x000:
+		case 0x000: /* Hack for Cyrix problems */
+		case 0x200:
+			return;                                
 		default:
 			break;
 		case 0x001: /* Invalid Op */

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-08-22 22:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-21  9:47 FPU-intensive programs crashing with floating point exception on Cyrix MII Chuck Ebbert
2005-08-21 17:52 ` Linus Torvalds
2005-08-21 21:28   ` Ondrej Zary
2005-08-21 23:10     ` Linus Torvalds
2005-08-22  7:19 ` FPU-intensive programs crashing with floating point Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2005-08-17 18:49 FPU-intensive programs crashing with floating point exception on Cyrix MII Chuck Ebbert
2005-08-18 10:37 ` Ondrej Zary
2005-08-17 16:13 Ondrej Zary
2005-08-17 17:08 ` linux-os (Dick Johnson)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox