linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [x86-64] remove locked instruction from switch_to()
@ 2009-01-10 21:26 Benjamin LaHaise
  2009-01-10 22:36 ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin LaHaise @ 2009-01-10 21:26 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: linux-kernel

The patch below removes an unnecessary locked instruction from switch_to().  
TIF_FORK is only ever set in copy_thread() on initial process creation, and 
gets cleared during the first scheduling of the process.  As such, it is 
safe to use an unlocked test for the flag within switch_to()./

Signed-off-by: Benjamin LaHaise <bcrl@kvack.org

diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
index 2ed3f0f..ee2e589 100644
--- a/arch/x86/include/asm/system.h
+++ b/arch/x86/include/asm/system.h
@@ -96,15 +96,15 @@ do {									\
 	     "thread_return:\n\t"					  \
 	     "movq %%gs:%P[pda_pcurrent],%%rsi\n\t"			  \
 	     "movq %P[thread_info](%%rsi),%%r8\n\t"			  \
-	     LOCK_PREFIX "btr  %[tif_fork],%P[ti_flags](%%r8)\n\t"	  \
 	     "movq %%rax,%%rdi\n\t" 					  \
-	     "jc   ret_from_fork\n\t"					  \
+	     "testl  %[_tif_fork],%P[ti_flags](%%r8)\n\t"	  \
+	     "jnz   ret_from_fork\n\t"					  \
 	     RESTORE_CONTEXT						  \
 	     : "=a" (last)					  	  \
 	     : [next] "S" (next), [prev] "D" (prev),			  \
 	       [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
 	       [ti_flags] "i" (offsetof(struct thread_info, flags)),	  \
-	       [tif_fork] "i" (TIF_FORK),			  	  \
+	       [_tif_fork] "i" (_TIF_FORK),			  	  \
 	       [thread_info] "i" (offsetof(struct task_struct, stack)),   \
 	       [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent))  \
 	     : "memory", "cc" __EXTRA_CLOBBER)
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index b86f332..16b4587 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -247,6 +247,7 @@ ENTRY(native_usergs_sysret64)
  */ 	
 /* rdi:	prev */	
 ENTRY(ret_from_fork)
+	LOCK ; btr $TIF_FORK,TI_flags(%r8)
 	CFI_DEFAULT_STACK
 	push kernel_eflags(%rip)
 	CFI_ADJUST_CFA_OFFSET 8

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

* Re: [x86-64] remove locked instruction from switch_to()
  2009-01-10 21:26 [x86-64] remove locked instruction from switch_to() Benjamin LaHaise
@ 2009-01-10 22:36 ` Ingo Molnar
  2009-01-11  4:00   ` [PATCH] x86-64: " Benjamin LaHaise
  0 siblings, 1 reply; 4+ messages in thread
From: Ingo Molnar @ 2009-01-10 22:36 UTC (permalink / raw)
  To: Benjamin LaHaise
  Cc: linux-kernel, H. Peter Anvin, Thomas Gleixner, Alexander van Heukelum


* Benjamin LaHaise <bcrl@kvack.org> wrote:

> The patch below removes an unnecessary locked instruction from 
> switch_to().  TIF_FORK is only ever set in copy_thread() on initial 
> process creation, and gets cleared during the first scheduling of the 
> process.  As such, it is safe to use an unlocked test for the flag 
> within switch_to()./
> 
> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org
> 
> diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
> index 2ed3f0f..ee2e589 100644
> --- a/arch/x86/include/asm/system.h
> +++ b/arch/x86/include/asm/system.h
> @@ -96,15 +96,15 @@ do {									\
>  	     "thread_return:\n\t"					  \
>  	     "movq %%gs:%P[pda_pcurrent],%%rsi\n\t"			  \
>  	     "movq %P[thread_info](%%rsi),%%r8\n\t"			  \
> -	     LOCK_PREFIX "btr  %[tif_fork],%P[ti_flags](%%r8)\n\t"	  \
>  	     "movq %%rax,%%rdi\n\t" 					  \
> -	     "jc   ret_from_fork\n\t"					  \
> +	     "testl  %[_tif_fork],%P[ti_flags](%%r8)\n\t"	  \
> +	     "jnz   ret_from_fork\n\t"					  \
>  	     RESTORE_CONTEXT						  \
>  	     : "=a" (last)					  	  \
>  	     : [next] "S" (next), [prev] "D" (prev),			  \
>  	       [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
>  	       [ti_flags] "i" (offsetof(struct thread_info, flags)),	  \
> -	       [tif_fork] "i" (TIF_FORK),			  	  \
> +	       [_tif_fork] "i" (_TIF_FORK),			  	  \
>  	       [thread_info] "i" (offsetof(struct task_struct, stack)),   \
>  	       [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent))  \
>  	     : "memory", "cc" __EXTRA_CLOBBER)
> diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
> index b86f332..16b4587 100644
> --- a/arch/x86/kernel/entry_64.S
> +++ b/arch/x86/kernel/entry_64.S
> @@ -247,6 +247,7 @@ ENTRY(native_usergs_sysret64)
>   */ 	
>  /* rdi:	prev */	
>  ENTRY(ret_from_fork)
> +	LOCK ; btr $TIF_FORK,TI_flags(%r8)
>  	CFI_DEFAULT_STACK

nice!

Small detail, it does not apply to latest -git cleanly:

 hunk #1 FAILED at 247.
 1 out of 1 hunk FAILED -- rejects in file arch/x86/kernel/entry_64.S

Probably trivial - would you mind to repost?

	Ingo

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

* [PATCH] x86-64: remove locked instruction from switch_to()
  2009-01-10 22:36 ` Ingo Molnar
@ 2009-01-11  4:00   ` Benjamin LaHaise
  2009-01-11  4:05     ` Ingo Molnar
  0 siblings, 1 reply; 4+ messages in thread
From: Benjamin LaHaise @ 2009-01-11  4:00 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: linux-kernel, H. Peter Anvin, Thomas Gleixner, Alexander van Heukelum

Here is a rediffed and test booted version of the patch against linus' git 
tree as of a couple of hours ago.

The patch below removes an unnecessary locked instruction from 
switch_to().  TIF_FORK is only ever set in copy_thread() on initial 
process creation, and gets cleared during the first scheduling of the 
process.  As such, it is safe to use an unlocked test for the flag 
within switch_to()./

Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>

diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
index 8e626ea..fa47b1e 100644
--- a/arch/x86/include/asm/system.h
+++ b/arch/x86/include/asm/system.h
@@ -96,15 +96,15 @@ do {									\
 	     "thread_return:\n\t"					  \
 	     "movq %%gs:%P[pda_pcurrent],%%rsi\n\t"			  \
 	     "movq %P[thread_info](%%rsi),%%r8\n\t"			  \
-	     LOCK_PREFIX "btr  %[tif_fork],%P[ti_flags](%%r8)\n\t"	  \
 	     "movq %%rax,%%rdi\n\t" 					  \
-	     "jc   ret_from_fork\n\t"					  \
+	     "testl  %[_tif_fork],%P[ti_flags](%%r8)\n\t"	  \
+	     "jnz   ret_from_fork\n\t"					  \
 	     RESTORE_CONTEXT						  \
 	     : "=a" (last)					  	  \
 	     : [next] "S" (next), [prev] "D" (prev),			  \
 	       [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
 	       [ti_flags] "i" (offsetof(struct thread_info, flags)),	  \
-	       [tif_fork] "i" (TIF_FORK),			  	  \
+	       [_tif_fork] "i" (_TIF_FORK),			  	  \
 	       [thread_info] "i" (offsetof(struct task_struct, stack)),   \
 	       [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent))  \
 	     : "memory", "cc" __EXTRA_CLOBBER)
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index e28c7a9..38dd374 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -408,6 +408,8 @@ END(save_paranoid)
 ENTRY(ret_from_fork)
 	DEFAULT_FRAME
 
+	LOCK ; btr $TIF_FORK,TI_flags(%r8)
+
 	push kernel_eflags(%rip)
 	CFI_ADJUST_CFA_OFFSET 8
 	popf					# reset kernel eflags

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

* Re: [PATCH] x86-64: remove locked instruction from switch_to()
  2009-01-11  4:00   ` [PATCH] x86-64: " Benjamin LaHaise
@ 2009-01-11  4:05     ` Ingo Molnar
  0 siblings, 0 replies; 4+ messages in thread
From: Ingo Molnar @ 2009-01-11  4:05 UTC (permalink / raw)
  To: Benjamin LaHaise
  Cc: linux-kernel, H. Peter Anvin, Thomas Gleixner, Alexander van Heukelum


* Benjamin LaHaise <bcrl@kvack.org> wrote:

> Here is a rediffed and test booted version of the patch against linus' git 
> tree as of a couple of hours ago.
> 
> The patch below removes an unnecessary locked instruction from 
> switch_to().  TIF_FORK is only ever set in copy_thread() on initial 
> process creation, and gets cleared during the first scheduling of the 
> process.  As such, it is safe to use an unlocked test for the flag 
> within switch_to()./
> 
> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>

applied to tip/x86/asm, thanks Ben!

	Ingo

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

end of thread, other threads:[~2009-01-11  4:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-10 21:26 [x86-64] remove locked instruction from switch_to() Benjamin LaHaise
2009-01-10 22:36 ` Ingo Molnar
2009-01-11  4:00   ` [PATCH] x86-64: " Benjamin LaHaise
2009-01-11  4:05     ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).