linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: Clear RI and EE at the same time in system call exit
@ 2012-05-29 11:20 Anton Blanchard
  2012-05-29 18:07 ` Scott Wood
  0 siblings, 1 reply; 3+ messages in thread
From: Anton Blanchard @ 2012-05-29 11:20 UTC (permalink / raw)
  To: benh, paulus, michael; +Cc: linuxppc-dev


In system call exit we currently clear RI and EE separately. An
mtmsrd is a slow operation and we can save cycles by doing it all
in one go.

This does complicate things a bit - we have to be careful to restore
RI if we branch out before returning to userspace.

On a POWER7 with virtual cputime disabled this patch improves the
null system call by 7%.

Signed-off-by: Anton Blanchard <anton@samba.org>
---

Index: linux-build/arch/powerpc/kernel/entry_64.S
===================================================================
--- linux-build.orig/arch/powerpc/kernel/entry_64.S	2012-05-28 18:23:33.374451416 +1000
+++ linux-build/arch/powerpc/kernel/entry_64.S	2012-05-29 21:18:22.280934940 +1000
@@ -197,7 +197,16 @@ syscall_exit:
 	wrteei	0
 #else
 	ld	r10,PACAKMSR(r13)
-	mtmsrd	r10,1
+	/*
+	 * For performance reasons we clear RI the same time that we
+	 * clear EE. We only need to clear RI just before we restore r13
+	 * below, but batching it with EE saves us one expensive mtmsrd call.
+	 * We have to be careful to restore RI if we branch anywhere from
+	 * here (eg syscall_exit_work).
+	 */
+	li	r9,MSR_RI
+	andc	r11,r10,r9
+	mtmsrd	r11,1
 #endif /* CONFIG_PPC_BOOK3E */
 
 	ld	r9,TI_FLAGS(r12)
@@ -214,17 +223,6 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
 	andi.	r6,r8,MSR_PR
 	ld	r4,_LINK(r1)
-	/*
-	 * Clear RI before restoring r13.  If we are returning to
-	 * userspace and we take an exception after restoring r13,
-	 * we end up corrupting the userspace r13 value.
-	 */
-#ifdef CONFIG_PPC_BOOK3S
-	/* No MSR:RI on BookE */
-	li	r12,MSR_RI
-	andc	r11,r10,r12
-	mtmsrd	r11,1			/* clear MSR.RI */
-#endif /* CONFIG_PPC_BOOK3S */
 
 	beq-	1f
 	ACCOUNT_CPU_USER_EXIT(r11, r12)
@@ -271,6 +269,7 @@ syscall_enosys:
 	b	syscall_exit
 	
 syscall_exit_work:
+	mtmsrd	r10,1		/* Restore RI */
 	/* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr.
 	 If TIF_NOERROR is set, just save r3 as it is. */
 

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

* Re: [PATCH] powerpc: Clear RI and EE at the same time in system call exit
  2012-05-29 11:20 [PATCH] powerpc: Clear RI and EE at the same time in system call exit Anton Blanchard
@ 2012-05-29 18:07 ` Scott Wood
  2012-05-29 22:22   ` Anton Blanchard
  0 siblings, 1 reply; 3+ messages in thread
From: Scott Wood @ 2012-05-29 18:07 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: michael, paulus, linuxppc-dev

On 05/29/2012 06:20 AM, Anton Blanchard wrote:
> 
> In system call exit we currently clear RI and EE separately. An
> mtmsrd is a slow operation and we can save cycles by doing it all
> in one go.
> 
> This does complicate things a bit - we have to be careful to restore
> RI if we branch out before returning to userspace.
> 
> On a POWER7 with virtual cputime disabled this patch improves the
> null system call by 7%.
> 
> Signed-off-by: Anton Blanchard <anton@samba.org>
> ---
> 
> Index: linux-build/arch/powerpc/kernel/entry_64.S
> ===================================================================
> --- linux-build.orig/arch/powerpc/kernel/entry_64.S	2012-05-28 18:23:33.374451416 +1000
> +++ linux-build/arch/powerpc/kernel/entry_64.S	2012-05-29 21:18:22.280934940 +1000
> @@ -197,7 +197,16 @@ syscall_exit:
>  	wrteei	0
>  #else
>  	ld	r10,PACAKMSR(r13)
> -	mtmsrd	r10,1
> +	/*
> +	 * For performance reasons we clear RI the same time that we
> +	 * clear EE. We only need to clear RI just before we restore r13
> +	 * below, but batching it with EE saves us one expensive mtmsrd call.
> +	 * We have to be careful to restore RI if we branch anywhere from
> +	 * here (eg syscall_exit_work).
> +	 */
> +	li	r9,MSR_RI
> +	andc	r11,r10,r9
> +	mtmsrd	r11,1
>  #endif /* CONFIG_PPC_BOOK3E */
>  
>  	ld	r9,TI_FLAGS(r12)
> @@ -214,17 +223,6 @@ BEGIN_FTR_SECTION
>  END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
>  	andi.	r6,r8,MSR_PR
>  	ld	r4,_LINK(r1)
> -	/*
> -	 * Clear RI before restoring r13.  If we are returning to
> -	 * userspace and we take an exception after restoring r13,
> -	 * we end up corrupting the userspace r13 value.
> -	 */
> -#ifdef CONFIG_PPC_BOOK3S
> -	/* No MSR:RI on BookE */
> -	li	r12,MSR_RI
> -	andc	r11,r10,r12
> -	mtmsrd	r11,1			/* clear MSR.RI */
> -#endif /* CONFIG_PPC_BOOK3S */
>  
>  	beq-	1f
>  	ACCOUNT_CPU_USER_EXIT(r11, r12)
> @@ -271,6 +269,7 @@ syscall_enosys:
>  	b	syscall_exit
>  	
>  syscall_exit_work:
> +	mtmsrd	r10,1		/* Restore RI */

That mtmsrd needs an #ifdef CONFIG_PPC_BOOK3S

-Scott

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

* [PATCH] powerpc: Clear RI and EE at the same time in system call exit
  2012-05-29 18:07 ` Scott Wood
@ 2012-05-29 22:22   ` Anton Blanchard
  0 siblings, 0 replies; 3+ messages in thread
From: Anton Blanchard @ 2012-05-29 22:22 UTC (permalink / raw)
  To: benh, paulus, michael, scottwood; +Cc: linuxppc-dev


Hi Scott,

> >  syscall_exit_work:
> > +	mtmsrd	r10,1		/* Restore RI */
> 
> That mtmsrd needs an #ifdef CONFIG_PPC_BOOK3S

Thanks!
Anton
--

In system call exit we currently clear RI and EE separately. An
mtmsrd is a slow operation and we can save cycles by doing it all
in one go.

This does complicate things a bit - we have to be careful to restore
RI if we branch out before returning to userspace.

On a POWER7 with virtual cputime disabled this patch improves the
null system call by 7%.

Signed-off-by: Anton Blanchard <anton@samba.org>
---

Index: linux-build/arch/powerpc/kernel/entry_64.S
===================================================================
--- linux-build.orig/arch/powerpc/kernel/entry_64.S	2012-05-29 21:22:40.293549055 +1000
+++ linux-build/arch/powerpc/kernel/entry_64.S	2012-05-30 07:47:31.380737406 +1000
@@ -197,7 +197,16 @@ syscall_exit:
 	wrteei	0
 #else
 	ld	r10,PACAKMSR(r13)
-	mtmsrd	r10,1
+	/*
+	 * For performance reasons we clear RI the same time that we
+	 * clear EE. We only need to clear RI just before we restore r13
+	 * below, but batching it with EE saves us one expensive mtmsrd call.
+	 * We have to be careful to restore RI if we branch anywhere from
+	 * here (eg syscall_exit_work).
+	 */
+	li	r9,MSR_RI
+	andc	r11,r10,r9
+	mtmsrd	r11,1
 #endif /* CONFIG_PPC_BOOK3E */
 
 	ld	r9,TI_FLAGS(r12)
@@ -214,17 +223,6 @@ BEGIN_FTR_SECTION
 END_FTR_SECTION_IFCLR(CPU_FTR_STCX_CHECKS_ADDRESS)
 	andi.	r6,r8,MSR_PR
 	ld	r4,_LINK(r1)
-	/*
-	 * Clear RI before restoring r13.  If we are returning to
-	 * userspace and we take an exception after restoring r13,
-	 * we end up corrupting the userspace r13 value.
-	 */
-#ifdef CONFIG_PPC_BOOK3S
-	/* No MSR:RI on BookE */
-	li	r12,MSR_RI
-	andc	r11,r10,r12
-	mtmsrd	r11,1			/* clear MSR.RI */
-#endif /* CONFIG_PPC_BOOK3S */
 
 	beq-	1f
 	ACCOUNT_CPU_USER_EXIT(r11, r12)
@@ -271,6 +269,9 @@ syscall_enosys:
 	b	syscall_exit
 	
 syscall_exit_work:
+#ifdef CONFIG_PPC_BOOK3S
+	mtmsrd	r10,1		/* Restore RI */
+#endif
 	/* If TIF_RESTOREALL is set, don't scribble on either r3 or ccr.
 	 If TIF_NOERROR is set, just save r3 as it is. */
 

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

end of thread, other threads:[~2012-05-29 22:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-29 11:20 [PATCH] powerpc: Clear RI and EE at the same time in system call exit Anton Blanchard
2012-05-29 18:07 ` Scott Wood
2012-05-29 22:22   ` Anton Blanchard

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).