All of lore.kernel.org
 help / color / mirror / Atom feed
* FPU context switching fix for SMP
@ 2005-01-26  8:24 Krzysztof Helt
  2005-01-26  8:26 ` William Lee Irwin III
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Krzysztof Helt @ 2005-01-26  8:24 UTC (permalink / raw)
  To: sparclinux

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

Here is a patch for FPU context switching in SMP.

A copy_thread() function clears PF_USEDFPU flag for a new thread,
but it does not clear the PSR_EF bit. Thus, a first FPU exception
called from the child thread is not handled properly. I made the
patch after PPC and MIPS architectures - both clear a similar bit
in copy_thread.
This bug does not exist in the UP kernel, probably because it
does not rely on PF_USEDFPU flag.

The patch below should be applied for both 2.4 and 2.6 branches.

I tested it with a test-fenv program from  glibc testsuite. The
test fails the same test cases in both SMP and UP with  the patch
applied. Without the patch, the test on SMP kernel failes in
almost two times more testcases.

Regards,
Krzysztof

----------------------------------------------------
Reklama Twojej strony WWW już od 20 groszy? - Oczywiście!
To nie jest żadna ściema! - Sprawdź:
http://klik.wp.pl/?adr=http%3A%2F%2Fbiznes.szukaj.wp.pl%2Fboksy.html&sid=299

[-- Attachment #2: copy_thread-fpu.24.patch --]
[-- Type: application/octet-stream, Size: 655 bytes --]

--- linux-2.4.29/arch/sparc/kernel/process.c.orig	2005-01-26 08:38:01.000000000 +0100
+++ linux-2.4.29/arch/sparc/kernel/process.c	2005-01-26 08:38:54.000000000 +0100
@@ -3,6 +3,8 @@
  *
  *  Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  *  Copyright (C) 1996 Eddie C. Dost   (ecd@skynet.be)
+ *
+ *	2005-01-26	Krzysztof Helt	-	cleared PSR_EF in copy_thread
  */
 
 /*
@@ -512,6 +514,10 @@
 		}
 	}
 
+  	/* FPU must be disabled in SMP. */
+  	/* It does not hurt in UP either. */
+  	childregs->psr &= ~PSR_EF;
+  
 	/* Set the return value for the child. */
 	childregs->u_regs[UREG_I0] = current->pid;
 	childregs->u_regs[UREG_I1] = 1;

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

* Re: FPU context switching fix for SMP
  2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
@ 2005-01-26  8:26 ` William Lee Irwin III
  2005-01-26  8:57 ` Krzysztof Helt
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: William Lee Irwin III @ 2005-01-26  8:26 UTC (permalink / raw)
  To: sparclinux

On Wed, Jan 26, 2005 at 09:24:42AM +0100, Krzysztof Helt wrote:
> Here is a patch for FPU context switching in SMP.
> A copy_thread() function clears PF_USEDFPU flag for a new thread,
> but it does not clear the PSR_EF bit. Thus, a first FPU exception
> called from the child thread is not handled properly. I made the
> patch after PPC and MIPS architectures - both clear a similar bit
> in copy_thread.
> This bug does not exist in the UP kernel, probably because it
> does not rely on PF_USEDFPU flag.
> The patch below should be applied for both 2.4 and 2.6 branches.
> I tested it with a test-fenv program from  glibc testsuite. The
> test fails the same test cases in both SMP and UP with  the patch
> applied. Without the patch, the test on SMP kernel failes in
> almost two times more testcases.

Are you sure a bugfix merits a copyright attribution? It's atypical
elsewhere...


-- wli

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

* Re: FPU context switching fix for SMP
  2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
  2005-01-26  8:26 ` William Lee Irwin III
@ 2005-01-26  8:57 ` Krzysztof Helt
  2005-01-26 22:06 ` Baurjan Ismagulov
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Krzysztof Helt @ 2005-01-26  8:57 UTC (permalink / raw)
  To: sparclinux

Dnia 26-01-2005 o godz. 9:26 William Lee Irwin III napisa³(a):
> On Wed, Jan 26, 2005 at 09:24:42AM +0100, Krzysztof Helt wrote:
> > Here is a patch for FPU context switching in SMP.
> > A copy_thread() function clears PF_USEDFPU flag for a new thread,
> > but it does not clear the PSR_EF bit. Thus, a first FPU exception
> > called from the child thread is not handled properly. I made the
> > patch after PPC and MIPS architectures - both clear a similar bit
> > in copy_thread.
> > This bug does not exist in the UP kernel, probably because it
> > does not rely on PF_USEDFPU flag.
> > The patch below should be applied for both 2.4 and 2.6 branches.
> > I tested it with a test-fenv program from  glibc testsuite. The
> > test fails the same test cases in both SMP and UP with  the patch
> > applied. Without the patch, the test on SMP kernel failes in
> > almost two times more testcases.
> 
> Are you sure a bugfix merits a copyright attribution? It's atypical
> elsewhere...
> 
> 

So please remove it. I am quite new, so just don't know how to
measure it...

Krzysztof


----------------------------------------------------
W Stepford kobiety s± idealne, a mê¿czy¼ni szczê¶liwi, dlaczego?
Zobacz, Nicole Kidman w filmie "¯ony ze Stepford" 
Musisz je mieæ na DVD i Wideo!
http://klik.wp.pl/?adr=http%3A%2F%2Ffilm.wp.pl%2Fp%2Ffilm.html%3Fid%3D24449&sid05



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

* Re: FPU context switching fix for SMP
  2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
  2005-01-26  8:26 ` William Lee Irwin III
  2005-01-26  8:57 ` Krzysztof Helt
@ 2005-01-26 22:06 ` Baurjan Ismagulov
  2005-01-26 23:09 ` David S. Miller
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Baurjan Ismagulov @ 2005-01-26 22:06 UTC (permalink / raw)
  To: sparclinux

On Wed, Jan 26, 2005 at 12:26:10AM -0800, William Lee Irwin III wrote:
> Are you sure a bugfix merits a copyright attribution? It's atypical
> elsewhere...

IANAL, but as I understand section 2 of GPL, it requires that any
changes are logged.

With kind regards,
Baurjan.

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

* Re: FPU context switching fix for SMP
  2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
                   ` (2 preceding siblings ...)
  2005-01-26 22:06 ` Baurjan Ismagulov
@ 2005-01-26 23:09 ` David S. Miller
  2005-01-29 18:22 ` Baurjan Ismagulov
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: David S. Miller @ 2005-01-26 23:09 UTC (permalink / raw)
  To: sparclinux

On Wed, 26 Jan 2005 23:06:41 +0100
Baurjan Ismagulov <ibr@ata.cs.hun.edu.tr> wrote:

> On Wed, Jan 26, 2005 at 12:26:10AM -0800, William Lee Irwin III wrote:
> > Are you sure a bugfix merits a copyright attribution? It's atypical
> > elsewhere...
> 
> IANAL, but as I understand section 2 of GPL, it requires that any
> changes are logged.

It's only relevant if it is significant enough for copyright purposes.
Changes or bug fixes that are only 2 or 3 lines in nature, generally
aren't.

Also, two more points:

1) copyright law and licensing are two different things, don't confuse
   them

2) even if an author fails to put an explicit copyright statement
   into his work, many countries define their copyright law such that
   copyright of the work by that author is implicit at least to some
   extent

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

* Re: FPU context switching fix for SMP
  2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
                   ` (3 preceding siblings ...)
  2005-01-26 23:09 ` David S. Miller
@ 2005-01-29 18:22 ` Baurjan Ismagulov
  2005-02-15 17:40 ` David S. Miller
  2005-02-15 20:01 ` William Lee Irwin III
  6 siblings, 0 replies; 8+ messages in thread
From: Baurjan Ismagulov @ 2005-01-29 18:22 UTC (permalink / raw)
  To: sparclinux

On Wed, Jan 26, 2005 at 03:09:51PM -0800, David S. Miller wrote:
> On Wed, 26 Jan 2005 23:06:41 +0100 Baurjan Ismagulov <ibr@ata.cs.hun.edu.tr> wrote:
> > On Wed, Jan 26, 2005 at 12:26:10AM -0800, William Lee Irwin III wrote:
> > > Are you sure a bugfix merits a copyright attribution? It's atypical
> > > elsewhere...
> > 
> > IANAL, but as I understand section 2 of GPL, it requires that any
> > changes are logged.
> 
> It's only relevant if it is significant enough for copyright purposes.
> Changes or bug fixes that are only 2 or 3 lines in nature, generally
> aren't.

Ok, then our legal dept. interprets the license too literally :) .


> 1) copyright law and licensing are two different things, don't confuse
>    them

Sure. The OP hasn't claimed copyright, he's just put a modification
notice. As he distributes his modification, however, he has to comply
with the GPL, which doesn't say that 2a applies to legally significant
changes only, that is why I wrote my previous e-mail.


Thanks for the explanations!


With kind regards,
Baurjan.

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

* Re: FPU context switching fix for SMP
  2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
                   ` (4 preceding siblings ...)
  2005-01-29 18:22 ` Baurjan Ismagulov
@ 2005-02-15 17:40 ` David S. Miller
  2005-02-15 20:01 ` William Lee Irwin III
  6 siblings, 0 replies; 8+ messages in thread
From: David S. Miller @ 2005-02-15 17:40 UTC (permalink / raw)
  To: sparclinux

On Wed, 26 Jan 2005 09:24:42 +0100
"Krzysztof Helt" <krzysztof.h1@wp.pl> wrote:

> Here is a patch for FPU context switching in SMP.
> 
> A copy_thread() function clears PF_USEDFPU flag for a new thread,
> but it does not clear the PSR_EF bit. Thus, a first FPU exception
> called from the child thread is not handled properly. I made the
> patch after PPC and MIPS architectures - both clear a similar bit
> in copy_thread.
> This bug does not exist in the UP kernel, probably because it
> does not rely on PF_USEDFPU flag.
> 
> The patch below should be applied for both 2.4 and 2.6 branches.

I've modified your patch to only do this in the SMP case.

Here is how the two mechanisms work:

UP:
	last_task_used_math keeps trash of the last thread to
	use the FPU.  As we context switch, we clear PSR_EF in
	the %psr register.  If we take a FPU disabled trap:
	1) if this is last_task_used_math, simply re-enable FPU
	2) else, save FPU state to last_task_used_math, restore
	   FPU state of current thread, and update last_task_used_math
	   value
	When we exec() or exit() and last_task_used_math is the
	current thread, we reset it to NULL.

SMP:
	last_task_used_math is not used at all.
	Instead, a state bit assosciated with each thread keeps
	track of whether that thread used the FPU or not.
	At schedule() time, if set we clear the bit and save
	the FPU state of that task and clear PSR_EF.
	At FPU disabled trap time, we set the state bit
	and load the FPU state for the process.

The SMP case works in that each thread, when scheduled(), has
it's PSR_EF flag cleared.

This fork() bug takes away that invariant, which is why the
problems arose.

Thanks a lot Krzysztof.

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

* Re: FPU context switching fix for SMP
  2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
                   ` (5 preceding siblings ...)
  2005-02-15 17:40 ` David S. Miller
@ 2005-02-15 20:01 ` William Lee Irwin III
  6 siblings, 0 replies; 8+ messages in thread
From: William Lee Irwin III @ 2005-02-15 20:01 UTC (permalink / raw)
  To: sparclinux

On Tue, Feb 15, 2005 at 09:40:57AM -0800, David S. Miller wrote:
> I've modified your patch to only do this in the SMP case.
> Here is how the two mechanisms work:
[...]
> The SMP case works in that each thread, when scheduled(), has
> it's PSR_EF flag cleared.
> This fork() bug takes away that invariant, which is why the
> problems arose.
> Thanks a lot Krzysztof.

Looks like you got this one wrapped up before I figured out what was
going on.

Thanks.


-- wli

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

end of thread, other threads:[~2005-02-15 20:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-26  8:24 FPU context switching fix for SMP Krzysztof Helt
2005-01-26  8:26 ` William Lee Irwin III
2005-01-26  8:57 ` Krzysztof Helt
2005-01-26 22:06 ` Baurjan Ismagulov
2005-01-26 23:09 ` David S. Miller
2005-01-29 18:22 ` Baurjan Ismagulov
2005-02-15 17:40 ` David S. Miller
2005-02-15 20:01 ` William Lee Irwin III

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.