Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch use a completely separate trap handler for syscall ...



details:   https://anonhg.NetBSD.org/src/rev/ddd7c0f9cf66
branches:  trunk
changeset: 534721:ddd7c0f9cf66
user:      chs <chs%NetBSD.org@localhost>
date:      Fri Aug 02 03:46:42 2002 +0000

description:
use a completely separate trap handler for syscall traps.
this reduces syscall overhead by 10% to 20% depending on cpu type.

diffstat:

 sys/arch/powerpc/ibm4xx/trap.c           |   6 +-
 sys/arch/powerpc/ibm4xx/trap_subr.S      |  48 ++++++++++++++++++-
 sys/arch/powerpc/include/userret.h       |  81 ++++++++++++++++++++++++++++++++
 sys/arch/powerpc/mpc6xx/genassym.cf      |   4 +-
 sys/arch/powerpc/mpc6xx/mpc6xx_machdep.c |   7 ++-
 sys/arch/powerpc/powerpc/syscall.c       |   9 +-
 sys/arch/powerpc/powerpc/trap.c          |  40 +--------------
 sys/arch/powerpc/powerpc/trap_subr.S     |  50 +++++++++++++++++++-
 sys/arch/powerpc/powerpc/trap_subr_mp.S  |  51 +++++++++++++++++++-
 sys/arch/walnut/walnut/genassym.cf       |   4 +-
 sys/arch/walnut/walnut/machdep.c         |   6 +-
 11 files changed, 251 insertions(+), 55 deletions(-)

diffs (truncated from 518 to 300 lines):

diff -r 1e7c0503ae5c -r ddd7c0f9cf66 sys/arch/powerpc/ibm4xx/trap.c
--- a/sys/arch/powerpc/ibm4xx/trap.c    Fri Aug 02 03:42:33 2002 +0000
+++ b/sys/arch/powerpc/ibm4xx/trap.c    Fri Aug 02 03:46:42 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.7 2002/07/11 01:38:49 simonb Exp $  */
+/*     $NetBSD: trap.c,v 1.8 2002/08/02 03:46:42 chs Exp $     */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -249,10 +249,6 @@
                KERNEL_PROC_UNLOCK(p);
                break;
 
-       case EXC_SC|EXC_USER:
-               (*p->p_md.md_syscall)(frame);
-               break;
-
        case EXC_AST|EXC_USER:
                astpending = 0;         /* we are about to do it */
                KERNEL_PROC_LOCK(p);
diff -r 1e7c0503ae5c -r ddd7c0f9cf66 sys/arch/powerpc/ibm4xx/trap_subr.S
--- a/sys/arch/powerpc/ibm4xx/trap_subr.S       Fri Aug 02 03:42:33 2002 +0000
+++ b/sys/arch/powerpc/ibm4xx/trap_subr.S       Fri Aug 02 03:46:42 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap_subr.S,v 1.4 2002/07/11 01:38:49 simonb Exp $     */
+/*     $NetBSD: trap_subr.S,v 1.5 2002/08/02 03:46:42 chs Exp $        */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -70,7 +70,7 @@
  * NOTICE: This is not a standalone file.  to use it, #include it in
  * your port's locore.S, like so:
  *
- *     #include <powerpc/powerpc/trap_subr.S>
+ *     #include <powerpc/ibm4xx/trap_subr.S>
  */
 
 /*
@@ -358,6 +358,50 @@
        FRAME_LEAVE(exitsave)
        rfi
        ba      .       /* Protect against prefetch */
+
+
+
+       .globl  _C_LABEL(sctrap),_C_LABEL(scsize)
+_C_LABEL(sctrap):
+       STANDARD_PROLOG(tempsave);
+       bla     s_sctrap
+_C_LABEL(scsize) = .-_C_LABEL(sctrap)
+
+s_sctrap:
+       FRAME_SETUP(tempsave)
+/* Now we can recover interrupts again: */
+       wrteei  1                       /* Enable interrupts */
+/* Call the appropriate syscall handler: */
+       addi    3,1,8
+       lis     4,_C_LABEL(curproc)@ha
+       lwz     4,_C_LABEL(curproc)@l(4)
+       lwz     4,P_MD_SYSCALL@l(4)
+       mtctr   4
+       bctrl
+/* Disable interrupts: */
+       wrteei  0
+/* Test AST pending: */
+       lwz     5,FRAME_SRR1+8(1)
+       mtcr    5
+       bc      4,17,1f                 /* branch if PSL_PR is false */
+#if defined(MULTIPROCESSOR)
+       GET_CPUINFO(3)
+       lwz     4,CI_ASTPENDING(3)
+#else
+       lis     3,_C_LABEL(astpending)@ha
+       lwz     4,_C_LABEL(astpending)@l(3)
+#endif
+       andi.   4,4,1
+       beq     1f
+       li      6,EXC_AST
+       stw     6,FRAME_EXC+8(1)
+       b       trapagain
+1:
+       FRAME_LEAVE(exitsave)
+       rfi
+       ba      .       /* Protect against prefetch */
+
+
 /*
  * External interrupt second level handler
  */
diff -r 1e7c0503ae5c -r ddd7c0f9cf66 sys/arch/powerpc/include/userret.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/powerpc/include/userret.h        Fri Aug 02 03:46:42 2002 +0000
@@ -0,0 +1,81 @@
+/*     $NetBSD: userret.h,v 1.1 2002/08/02 03:46:43 chs Exp $  */
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Define the code needed before returning to user mode, for
+ * trap and syscall.
+ */
+static __inline void
+userret(struct proc *p, struct trapframe *frame)
+{
+       struct cpu_info *ci = curcpu();
+       struct pcb *pcb;
+       int sig;
+
+       /* Take pending signals. */
+       while ((sig = CURSIG(p)) != 0) {
+               KERNEL_PROC_LOCK(p);
+               postsig(sig);
+               KERNEL_PROC_UNLOCK(p);
+       }
+
+       pcb = &p->p_addr->u_pcb;
+
+       /*
+        * If someone stole the fp or vector unit while we were away,
+        * disable it
+        */
+#ifdef PPC_HAS_FPU
+       if ((pcb->pcb_flags & PCB_FPU) &&
+           (p != ci->ci_fpuproc || pcb->pcb_fpcpu != ci)) {
+               frame->srr1 &= ~PSL_FP;
+       }
+#endif
+#ifdef ALTIVEC
+       if ((pcb->pcb_flags & PCB_ALTIVEC) &&
+           (p != ci->ci_vecproc || pcb->pcb_veccpu != ci)) {
+               frame->srr1 &= ~PSL_VEC;
+       }
+
+       /*
+        * If the new process isn't the current AltiVec process on this
+        * cpu, we need to stop any data streams that are active (since
+        * it will be a different address space).
+        */
+       if (ci->ci_vecproc != NULL && ci->ci_vecproc != p) {
+               __asm __volatile("dssall;sync");
+       }
+#endif
+
+       ci->ci_schedstate.spc_curpriority = p->p_priority = p->p_usrpri;
+}
diff -r 1e7c0503ae5c -r ddd7c0f9cf66 sys/arch/powerpc/mpc6xx/genassym.cf
--- a/sys/arch/powerpc/mpc6xx/genassym.cf       Fri Aug 02 03:42:33 2002 +0000
+++ b/sys/arch/powerpc/mpc6xx/genassym.cf       Fri Aug 02 03:46:42 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.5 2002/07/24 05:44:37 chs Exp $
+#      $NetBSD: genassym.cf,v 1.6 2002/08/02 03:46:44 chs Exp $
 
 #
 # Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -112,6 +112,8 @@
 define P_STAT          offsetof(struct proc, p_stat)
 define P_CPU           offsetof(struct proc, p_cpu)
 
+define P_MD_SYSCALL    offsetof(struct proc, p_md.md_syscall)
+
 define SONPROC         SONPROC
 
 define CI_SIZE         sizeof(struct cpu_info)
diff -r 1e7c0503ae5c -r ddd7c0f9cf66 sys/arch/powerpc/mpc6xx/mpc6xx_machdep.c
--- a/sys/arch/powerpc/mpc6xx/mpc6xx_machdep.c  Fri Aug 02 03:42:33 2002 +0000
+++ b/sys/arch/powerpc/mpc6xx/mpc6xx_machdep.c  Fri Aug 02 03:46:42 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mpc6xx_machdep.c,v 1.4 2002/07/16 16:39:12 matt Exp $  */
+/*     $NetBSD: mpc6xx_machdep.c,v 1.5 2002/08/02 03:46:44 chs Exp $   */
 
 /*
  * Copyright (C) 2002 Matt Thomas
@@ -104,6 +104,7 @@
 mpc6xx_init(void (*handler)(void))
 {
        extern int trapcode, trapsize;
+       extern int sctrap, scsize;
        extern int alitrap, alisize;
        extern int dsitrap, dsisize;
        extern int isitrap, isisize;
@@ -162,6 +163,10 @@
                         */
                        break;
 #endif
+               case EXC_SC:
+                       size = (size_t)&scsize;
+                       memcpy((void *)EXC_SC, &sctrap, size);
+                       break;
                case EXC_ALI:
                        size = (size_t)&alisize;
                        memcpy((void *)EXC_ALI, &alitrap, size);
diff -r 1e7c0503ae5c -r ddd7c0f9cf66 sys/arch/powerpc/powerpc/syscall.c
--- a/sys/arch/powerpc/powerpc/syscall.c        Fri Aug 02 03:42:33 2002 +0000
+++ b/sys/arch/powerpc/powerpc/syscall.c        Fri Aug 02 03:46:42 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syscall.c,v 1.3 2002/07/28 07:05:53 chs Exp $  */
+/*     $NetBSD: syscall.c,v 1.4 2002/08/02 03:46:45 chs Exp $  */
 
 /*
  * Copyright (C) 2002 Matt Thomas
@@ -53,6 +53,7 @@
 
 #include <uvm/uvm_extern.h>
 
+#include <powerpc/userret.h>
 #include <machine/cpu.h>
 #include <machine/frame.h>
 
@@ -86,7 +87,6 @@
        int n;
 
        curcpu()->ci_ev_scalls.ev_count++;
-       uvmexp.syscalls++;
 
        code = frame->fixreg[0];
        callp = p->p_emul->e_sysent;
@@ -163,6 +163,7 @@
                frame->cr |= 0x10000000;
                break;
        }
+       userret(p, frame);
 }
 
 void
@@ -178,9 +179,7 @@
        int n;
 
        KERNEL_PROC_LOCK(p);
-
        curcpu()->ci_ev_scalls.ev_count++;
-       uvmexp.syscalls++;
 
        code = frame->fixreg[0];
        callp = p->p_emul->e_sysent;
@@ -251,6 +250,7 @@
        }
        KERNEL_PROC_UNLOCK(p);
        trace_exit(p, code, params, rval, error);
+       userret(p, frame);
 }
 
 void
@@ -303,4 +303,3 @@
        /* Profiling?                                                   XXX */
        curcpu()->ci_schedstate.spc_curpriority = p->p_priority;
 }
-
diff -r 1e7c0503ae5c -r ddd7c0f9cf66 sys/arch/powerpc/powerpc/trap.c
--- a/sys/arch/powerpc/powerpc/trap.c   Fri Aug 02 03:42:33 2002 +0000
+++ b/sys/arch/powerpc/powerpc/trap.c   Fri Aug 02 03:46:42 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.66 2002/07/28 07:07:45 chs Exp $    */
+/*     $NetBSD: trap.c,v 1.67 2002/08/02 03:46:45 chs Exp $    */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -55,6 +55,7 @@
 #include <machine/trap.h>
 #include <powerpc/altivec.h>
 #include <powerpc/spr.h>
+#include <powerpc/userret.h>
 
 #ifndef MULTIPROCESSOR
 volatile int astpending;
@@ -223,9 +224,6 @@
                trapsignal(p, SIGSEGV, EXC_ISI);
                KERNEL_PROC_UNLOCK(p);
                break;
-       case EXC_SC|EXC_USER:
-               (*p->p_md.md_syscall)(frame);
-               break;



Home | Main Index | Thread Index | Old Index