Factor out the common ast bits into mi_ast()
authorguenther <guenther@openbsd.org>
Sat, 10 May 2014 05:33:00 +0000 (05:33 +0000)
committerguenther <guenther@openbsd.org>
Sat, 10 May 2014 05:33:00 +0000 (05:33 +0000)
ok deraadt@

15 files changed:
sys/arch/alpha/alpha/trap.c
sys/arch/amd64/amd64/trap.c
sys/arch/arm/arm/ast.c
sys/arch/hppa/hppa/trap.c
sys/arch/hppa64/hppa64/trap.c
sys/arch/i386/i386/trap.c
sys/arch/m88k/m88k/trap.c
sys/arch/mips64/mips64/trap.c
sys/arch/powerpc/powerpc/trap.c
sys/arch/sh/sh/trap.c
sys/arch/solbourne/solbourne/trap.c
sys/arch/sparc/sparc/trap.c
sys/arch/sparc64/sparc64/trap.c
sys/arch/vax/vax/trap.c
sys/sys/syscall_mi.h

index 45c44d0..2d7d82b 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: trap.c,v 1.72 2014/04/18 11:51:16 guenther Exp $ */
+/* $OpenBSD: trap.c,v 1.73 2014/05/10 05:33:00 guenther Exp $ */
 /* $NetBSD: trap.c,v 1.52 2000/05/24 16:48:33 thorpej Exp $ */
 
 /*-
@@ -720,16 +720,7 @@ ast(framep)
                panic("ast and not user");
 #endif
 
-       atomic_add_int(&uvmexp.softs, 1);
-
-       if (p->p_flag & P_OWEUPC) {
-               KERNEL_LOCK();
-               ADDUPROF(p);
-               KERNEL_UNLOCK();
-       }
-
-       if (ci->ci_want_resched)
-               preempt(NULL);
+       mi_ast(p, ci->ci_want_resched);
 
        /* Do any deferred user pmap operations. */
        PMAP_USERRET(vm_map_pmap(&p->p_vmspace->vm_map));
index 4ef833b..0ce734d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.37 2014/04/30 06:24:23 sf Exp $    */
+/*     $OpenBSD: trap.c,v 1.38 2014/05/10 05:33:00 guenther Exp $      */
 /*     $NetBSD: trap.c,v 1.2 2003/05/04 23:51:56 fvdl Exp $    */
 
 /*-
@@ -281,15 +281,7 @@ copyfault:
                goto out;
 
        case T_ASTFLT|T_USER:           /* Allow process switch */
-               uvmexp.softs++;
-               if (p->p_flag & P_OWEUPC) {
-                       KERNEL_LOCK();
-                       ADDUPROF(p);
-                       KERNEL_UNLOCK();
-               }
-               /* Allow a forced task switch. */
-               if (curcpu()->ci_want_resched)
-                       preempt(NULL);
+               mi_ast(p, curcpu()->ci_want_resched);
                goto out;
 
        case T_BOUND|T_USER:
index 7fb82e5..ea410ec 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ast.c,v 1.10 2011/11/16 20:50:18 deraadt Exp $        */
+/*     $OpenBSD: ast.c,v 1.11 2014/05/10 05:33:00 guenther Exp $       */
 /*     $NetBSD: ast.c,v 1.6 2003/10/31 16:44:34 cl Exp $       */
 
 /*
@@ -50,6 +50,7 @@
 #include <sys/signal.h>
 #include <sys/signalvar.h>
 #include <sys/vmmeter.h>
+#include <sys/syscall_mi.h>
 
 #include <machine/cpu.h>
 #include <machine/frame.h>
@@ -81,7 +82,6 @@ ast(struct trapframe *tf)
        /* Interrupts were restored by exception_exit. */
 
        uvmexp.traps++;
-       uvmexp.softs++;
 
 #ifdef DEBUG
        if (p == NULL)
@@ -90,14 +90,7 @@ ast(struct trapframe *tf)
                panic("ast: no pcb!");
 #endif 
 
-       if (p->p_flag & P_OWEUPC) {
-               ADDUPROF(p);
-       }
-
-       /* Allow a forced task switch. */
-       if (want_resched)
-               preempt(NULL);
-
+       mi_ast(p, want_resched);
        userret(p);
 }
 
index 1b5e34c..130c9f1 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.131 2014/05/08 21:32:45 miod Exp $ */
+/*     $OpenBSD: trap.c,v 1.132 2014/05/10 05:33:00 guenther Exp $     */
 
 /*
  * Copyright (c) 1998-2004 Michael Shalayeff
@@ -139,14 +139,7 @@ ast(struct proc *p)
 {
        if (p->p_md.md_astpending) {
                p->p_md.md_astpending = 0;
-               uvmexp.softs++;
-               if (p->p_flag & P_OWEUPC) {
-                       KERNEL_LOCK();
-                       ADDUPROF(p);
-                       KERNEL_UNLOCK();
-               }
-               if (curcpu()->ci_want_resched)
-                       preempt(NULL);
+               mi_ast(p, curcpu()->ci_want_resched);
        }
 
 }
index 8310c42..86e6a7e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.36 2014/04/18 11:51:16 guenther Exp $      */
+/*     $OpenBSD: trap.c,v 1.37 2014/05/10 05:33:00 guenther Exp $      */
 
 /*
  * Copyright (c) 2005 Michael Shalayeff
@@ -132,12 +132,7 @@ ast(struct proc *p)
 {
        if (astpending) {
                astpending = 0;
-               uvmexp.softs++;
-               if (p->p_flag & P_OWEUPC) {
-                       ADDUPROF(p);
-               }
-               if (want_resched)
-                       preempt(NULL);
+               mi_ast(p, want_resched);
        }
 }
 
index 31d4c77..9ec543f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.114 2014/04/18 11:51:17 guenther Exp $     */
+/*     $OpenBSD: trap.c,v 1.115 2014/05/10 05:33:00 guenther Exp $     */
 /*     $NetBSD: trap.c,v 1.95 1996/05/05 06:50:02 mycroft Exp $        */
 
 /*-
@@ -334,14 +334,7 @@ trap(struct trapframe *frame)
                goto out;
 
        case T_ASTFLT|T_USER:           /* Allow process switch */
-               uvmexp.softs++;
-               if (p->p_flag & P_OWEUPC) {
-                       KERNEL_LOCK();
-                       ADDUPROF(p);
-                       KERNEL_UNLOCK();
-               }
-               if (want_resched)
-                       preempt(NULL);
+               mi_ast(p, want_resched);
                goto out;
 
        case T_DNA|T_USER: {
index f73b801..5426eea 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.91 2014/05/08 22:17:33 miod Exp $  */
+/*     $OpenBSD: trap.c,v 1.92 2014/05/10 05:33:00 guenther Exp $      */
 /*
  * Copyright (c) 2004, Miodrag Vallat.
  * Copyright (c) 1998 Steve Murphree, Jr.
@@ -205,16 +205,9 @@ ast(struct trapframe *frame)
        struct cpu_info *ci = curcpu();
        struct proc *p = ci->ci_curproc;
 
-       uvmexp.softs++;
        p->p_md.md_astpending = 0;
-       if (p->p_flag & P_OWEUPC) {
-               KERNEL_LOCK();
-               ADDUPROF(p);
-               KERNEL_UNLOCK();
-       }
-       if (ci->ci_want_resched)
-               preempt(NULL);
 
+       mi_ast(p, ci->ci_want_resched);
        userret(p);
 }
 
index 5576f84..d24a98a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.93 2014/04/18 11:51:17 guenther Exp $      */
+/*     $OpenBSD: trap.c,v 1.94 2014/05/10 05:33:00 guenther Exp $      */
 
 /*
  * Copyright (c) 1988 University of Utah.
@@ -148,17 +148,9 @@ ast()
        struct cpu_info *ci = curcpu();
        struct proc *p = ci->ci_curproc;
 
-       atomic_add_int(&uvmexp.softs, 1);
-
        p->p_md.md_astpending = 0;
-       if (p->p_flag & P_OWEUPC) {
-               KERNEL_LOCK();
-               ADDUPROF(p);
-               KERNEL_UNLOCK();
-       }
-       if (ci->ci_want_resched)
-               preempt(NULL);
 
+       mi_ast(p, ci->ci_want_resched);
        userret(p);
 }
 
index 8725a28..7bd6d13 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.97 2014/05/09 18:16:15 miod Exp $  */
+/*     $OpenBSD: trap.c,v 1.98 2014/05/10 05:33:00 guenther Exp $      */
 /*     $NetBSD: trap.c,v 1.3 1996/10/13 03:31:37 christos Exp $        */
 
 /*
@@ -619,15 +619,8 @@ for (i = 0; i < errnum; i++) {
                break;
 
        case EXC_AST|EXC_USER:
-               uvmexp.softs++;
                p->p_md.md_astpending = 0;      /* we are about to do it */
-               if (p->p_flag & P_OWEUPC) {
-                       KERNEL_LOCK();
-                       ADDUPROF(p);
-                       KERNEL_UNLOCK();
-               }
-               if (ci->ci_want_resched)
-                       preempt(NULL);
+               mi_ast(p, ci->ci_want_resched);
                break;
        }
 
index 56c9828..10035c9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.26 2014/05/08 21:43:04 miod Exp $  */
+/*     $OpenBSD: trap.c,v 1.27 2014/05/10 05:33:00 guenther Exp $      */
 /*     $NetBSD: exception.c,v 1.32 2006/09/04 23:57:52 uwe Exp $       */
 /*     $NetBSD: syscall.c,v 1.6 2006/03/07 07:21:50 thorpej Exp $      */
 
@@ -479,18 +479,8 @@ ast(struct proc *p, struct trapframe *tf)
 
        while (p->p_md.md_astpending) {
                p->p_md.md_astpending = 0;
-               uvmexp.softs++;
-
                refreshcreds(p);
-               if (p->p_flag & P_OWEUPC) {
-                       ADDUPROF(p);
-               }
-
-               if (want_resched) {
-                       /* We are being preempted. */
-                       preempt(NULL);
-               }
-
+               mi_ast(p, want_resched);
                userret(p);
        }
 }
index dbd3007..76ac5f7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.19 2014/04/18 11:51:17 guenther Exp $      */
+/*     $OpenBSD: trap.c,v 1.20 2014/05/10 05:33:00 guenther Exp $      */
 /*     OpenBSD: trap.c,v 1.42 2004/12/06 20:12:25 miod Exp     */
 
 /*
@@ -308,11 +308,7 @@ trap(type, psr, pc, tf)
 
        case T_AST:
                want_ast = 0;
-               if (p->p_flag & P_OWEUPC) {
-                       ADDUPROF(p);
-               }
-               if (want_resched)
-                       preempt(NULL);
+               mi_ast(p, want_resched);
                break;
 
        case T_ILLINST:
index 9ef2531..5f15e83 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.66 2014/04/30 04:20:31 miod Exp $  */
+/*     $OpenBSD: trap.c,v 1.67 2014/05/10 05:33:00 guenther Exp $      */
 /*     $NetBSD: trap.c,v 1.58 1997/09/12 08:55:01 pk Exp $ */
 
 /*
@@ -301,11 +301,7 @@ trap(type, psr, pc, tf)
 
        case T_AST:
                want_ast = 0;
-               if (p->p_flag & P_OWEUPC) {
-                       ADDUPROF(p);
-               }
-               if (want_resched)
-                       preempt(NULL);
+               mi_ast(p, want_resched);
                break;
 
        case T_ILLINST:
index d1605f0..1be8548 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.81 2014/04/18 11:51:17 guenther Exp $      */
+/*     $OpenBSD: trap.c,v 1.82 2014/05/10 05:33:00 guenther Exp $      */
 /*     $NetBSD: trap.c,v 1.73 2001/08/09 01:03:01 eeh Exp $ */
 
 /*
@@ -452,13 +452,7 @@ dopanic:
 
        case T_AST:
                p->p_md.md_astpending = 0;
-               if (p->p_flag & P_OWEUPC) {
-                       KERNEL_LOCK();
-                       ADDUPROF(p);
-                       KERNEL_UNLOCK();
-               }
-               if (curcpu()->ci_want_resched)
-                       preempt(NULL);
+               mi_ast(p, curcpu()->ci_want_resched);
                break;
 
        case T_RWRET:
index bcd9a5a..842234f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: trap.c,v 1.51 2014/04/18 11:51:17 guenther Exp $     */
+/*     $OpenBSD: trap.c,v 1.52 2014/05/10 05:33:00 guenther Exp $     */
 /*     $NetBSD: trap.c,v 1.47 1999/08/21 19:26:20 matt Exp $     */
 /*
  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
@@ -253,11 +253,7 @@ if(faultdebug)printf("trap accflt type %lx, code %lx, pc %lx, psl %lx\n",
        case T_ASTFLT|T_USER:
                mtpr(AST_NO,PR_ASTLVL);
                trapsig = 0;
-               if (p->p_flag & P_OWEUPC) {
-                       ADDUPROF(p);
-               }
-               if (want_resched)
-                       preempt(NULL);
+               mi_ast(p, want_resched);
                break;
 
 #ifdef DDB
index 20293f0..d8c52ea 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: syscall_mi.h,v 1.3 2014/04/18 11:51:17 guenther Exp $ */
+/*     $OpenBSD: syscall_mi.h,v 1.4 2014/05/10 05:33:00 guenther Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -142,3 +142,26 @@ mi_child_return(struct proc *p)
        }
 #endif
 }
+
+/* 
+ * Do the specific processing necessary for an AST
+ */
+static void
+mi_ast(struct proc *p, int resched)
+{
+       uvmexp.softs++;
+
+       if (p->p_flag & P_OWEUPC) {
+               KERNEL_LOCK();
+               ADDUPROF(p);
+               KERNEL_UNLOCK();
+       }
+       if (resched)
+               preempt(NULL);
+
+       /*
+        * XXX could move call to userret() here, but
+        * hppa calls ast() in syscall return and sh calls
+        * it after userret()
+        */
+}