Source-Changes-HG archive

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

[src/trunk]: src/sys Some lwp-walkers expect the correct value for l_stat, so...



details:   https://anonhg.NetBSD.org/src/rev/48e23027cd7a
branches:  trunk
changeset: 761460:48e23027cd7a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Jan 28 16:58:27 2011 +0000

description:
Some lwp-walkers expect the correct value for l_stat, so use a flag
in l_flag instead of l_stat for the purpose of flagging lwps in a
dying proc.

diffstat:

 sys/rump/librump/rumpkern/locks.c     |  14 +++++++-------
 sys/rump/librump/rumpkern/lwproc.c    |  15 ++++++++++-----
 sys/rump/librump/rumpkern/rump.c      |   8 ++++----
 sys/rump/librump/rumpkern/scheduler.c |  19 +++++++++++++------
 sys/sys/lwp.h                         |   3 ++-
 5 files changed, 36 insertions(+), 23 deletions(-)

diffs (262 lines):

diff -r ebcc5e77587c -r 48e23027cd7a sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Fri Jan 28 16:34:31 2011 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Fri Jan 28 16:58:27 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locks.c,v 1.48 2011/01/18 22:21:23 haad Exp $  */
+/*     $NetBSD: locks.c,v 1.49 2011/01/28 16:58:28 pooka Exp $ */
 
 /*
  * Copyright (c) 2007, 2008 Antti Kantee.  All Rights Reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.48 2011/01/18 22:21:23 haad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.49 2011/01/28 16:58:28 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -283,7 +283,7 @@
        struct lwp *l = curlwp;
        int rv;
 
-       if (__predict_false(l->l_stat == LSDEAD || l->l_stat == LSZOMB)) {
+       if (__predict_false(l->l_flag & LW_RUMP_DYING)) {
                /*
                 * sleepq code expects us to sleep, so set l_mutex
                 * back to cpu lock here if we didn't.
@@ -305,21 +305,21 @@
        }
 
        /*
-        * Check for LSDEAD.  if so, we need to wait here until we
+        * Check for DYING.  if so, we need to wait here until we
         * are allowed to exit.
         */
-       if (__predict_false(l->l_stat == LSDEAD)) {
+       if (__predict_false(l->l_flag & LW_RUMP_DYING)) {
                struct proc *p = l->l_proc;
 
                mutex_exit(mtx); /* drop and retake later */
 
                mutex_enter(p->p_lock);
-               while (l->l_stat == LSDEAD) {
+               while (p->p_stat != SDYING) {
                        /* avoid recursion */
                        rumpuser_cv_wait(RUMPCV(&p->p_waitcv),
                            RUMPMTX(p->p_lock));
                }
-               KASSERT(l->l_stat == LSZOMB);
+               KASSERT(p->p_stat == SDYING);
                mutex_exit(p->p_lock);
 
                /* ok, we can exit and remove "reference" to l->private */
diff -r ebcc5e77587c -r 48e23027cd7a sys/rump/librump/rumpkern/lwproc.c
--- a/sys/rump/librump/rumpkern/lwproc.c        Fri Jan 28 16:34:31 2011 +0000
+++ b/sys/rump/librump/rumpkern/lwproc.c        Fri Jan 28 16:58:27 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: lwproc.c,v 1.11 2011/01/28 16:34:31 pooka Exp $       */
+/*      $NetBSD: lwproc.c,v 1.12 2011/01/28 16:58:28 pooka Exp $       */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.11 2011/01/28 16:34:31 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.12 2011/01/28 16:58:28 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -53,7 +53,8 @@
 
        KASSERT(p->p_nlwps == 0);
        KASSERT(LIST_EMPTY(&p->p_lwps));
-       KASSERT(p->p_stat == SIDL || p->p_stat == SDEAD);
+       KASSERT(p->p_stat == SACTIVE || p->p_stat == SDYING ||
+           p->p_stat == SDEAD);
 
        LIST_REMOVE(p, p_list);
        LIST_REMOVE(p, p_sibling);
@@ -141,6 +142,7 @@
 
        p->p_pptr = parent;
        p->p_ppid = parent->p_pid;
+       p->p_stat = SACTIVE;
 
        kauth_proc_fork(parent, p);
 
@@ -199,6 +201,8 @@
                lwproc_proc_free(p);    
 }
 
+extern kmutex_t unruntime_lock;
+
 /*
  * called with p_lock held, releases lock before return
  */
@@ -217,9 +221,10 @@
        lwp_update_creds(l);
 
        l->l_fd = p->p_fd;
-       l->l_cpu = NULL;
+       l->l_cpu = rump_cpu;
        l->l_target_cpu = rump_cpu; /* Initial target CPU always the same */
        l->l_stat = LSRUN;
+       l->l_mutex = &unruntime_lock;
        TAILQ_INIT(&l->l_ld_locks);
 
        lwp_initspecific(l);
@@ -341,7 +346,7 @@
        }
        mutex_exit(newlwp->l_proc->p_lock);
 
-       l->l_mutex = NULL;
+       l->l_mutex = &unruntime_lock;
        l->l_cpu = NULL;
        l->l_pflag &= ~LP_RUNNING;
        l->l_flag &= ~LW_PENDSIG;
diff -r ebcc5e77587c -r 48e23027cd7a sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Fri Jan 28 16:34:31 2011 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Fri Jan 28 16:58:27 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.222 2011/01/27 17:36:27 pooka Exp $ */
+/*     $NetBSD: rump.c,v 1.223 2011/01/28 16:58:28 pooka Exp $ */
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.222 2011/01/27 17:36:27 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.223 2011/01/28 16:58:28 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -788,7 +788,7 @@
        LIST_FOREACH(l, &p->p_lwps, l_sibling) {
                if (l == curlwp)
                        continue;
-               l->l_stat = LSDEAD;
+               l->l_flag |= LW_RUMP_DYING;
        }
        mutex_exit(p->p_lock);
 
@@ -816,8 +816,8 @@
        LIST_FOREACH(l, &p->p_lwps, l_sibling) {
                if (l->l_private)
                        cv_broadcast(l->l_private);
-               l->l_stat = LSZOMB;
        }
+       p->p_stat = SDYING;
        cv_broadcast(&p->p_waitcv);
        mutex_exit(p->p_lock);
 
diff -r ebcc5e77587c -r 48e23027cd7a sys/rump/librump/rumpkern/scheduler.c
--- a/sys/rump/librump/rumpkern/scheduler.c     Fri Jan 28 16:34:31 2011 +0000
+++ b/sys/rump/librump/rumpkern/scheduler.c     Fri Jan 28 16:58:27 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: scheduler.c,v 1.24 2011/01/11 10:49:20 pooka Exp $    */
+/*      $NetBSD: scheduler.c,v 1.25 2011/01/28 16:58:28 pooka Exp $    */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.24 2011/01/11 10:49:20 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.25 2011/01/28 16:58:28 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -78,6 +78,8 @@
 static struct rumpuser_cv *lwp0cv;
 static unsigned nextcpu;
 
+kmutex_t unruntime_lock; /* unruntime lwp lock.  practically unused */
+
 static bool lwp0isbusy = false;
 
 /*
@@ -165,6 +167,8 @@
                rumpuser_cv_init(&rcpu->rcpu_cv);
                rumpuser_mutex_init(&rcpu->rcpu_mtx);
        }
+
+       mutex_init(&unruntime_lock, MUTEX_DEFAULT, IPL_NONE);
 }
 
 /*
@@ -196,7 +200,7 @@
 {
 
        /* busy lwp0 */
-       KASSERT(curlwp == NULL || curlwp->l_cpu == NULL);
+       KASSERT(curlwp == NULL || curlwp->l_stat != LSONPROC);
        rumpuser_mutex_enter_nowrap(lwp0mtx);
        while (lwp0isbusy)
                rumpuser_cv_wait_nowrap(lwp0cv, lwp0mtx);
@@ -271,6 +275,8 @@
        bool domigrate;
        bool bound = l->l_pflag & LP_BOUND;
 
+       l->l_stat = LSRUN;
+
        /*
         * First, try fastpath: if we were the previous user of the
         * CPU, everything is in order cachewise and we can just
@@ -342,6 +348,7 @@
        l->l_cpu = l->l_target_cpu = rcpu->rcpu_ci;
        l->l_mutex = rcpu->rcpu_ci->ci_schedstate.spc_mutex;
        l->l_ncsw++;
+       l->l_stat = LSONPROC;
 
        rcpu->rcpu_ci->ci_curlwp = l;
 }
@@ -359,7 +366,8 @@
 
        KASSERT(l->l_mutex == l->l_cpu->ci_schedstate.spc_mutex);
        rump_unschedule_cpu(l);
-       l->l_mutex = NULL;
+       l->l_mutex = &unruntime_lock;
+       l->l_stat = LSSTOP;
 
        /*
         * Check special conditions:
@@ -379,7 +387,7 @@
 
                /* release lwp0 */
                rump_unschedule_cpu(&lwp0);
-               lwp0.l_mutex = NULL;
+               lwp0.l_mutex = &unruntime_lock;
                lwp0.l_pflag &= ~LP_RUNNING;
                lwp0rele();
                rumpuser_set_curlwp(NULL);
@@ -415,7 +423,6 @@
 
        ci = l->l_cpu;
        ci->ci_curlwp = NULL;
-       l->l_cpu = NULL;
        rcpu = &rcpu_storage[ci-&rump_cpus[0]];
 
        KASSERT(rcpu->rcpu_ci == ci);
diff -r ebcc5e77587c -r 48e23027cd7a sys/sys/lwp.h
--- a/sys/sys/lwp.h     Fri Jan 28 16:34:31 2011 +0000
+++ b/sys/sys/lwp.h     Fri Jan 28 16:58:27 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lwp.h,v 1.141 2011/01/18 20:17:50 rmind Exp $  */
+/*     $NetBSD: lwp.h,v 1.142 2011/01/28 16:58:27 pooka Exp $  */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009, 2010
@@ -232,6 +232,7 @@
 #define        LW_SA_YIELD     0x40000000 /* LWP on VP is yielding */
 #define        LW_SA_IDLE      0x80000000 /* VP is idle */
 #define        LW_RUMP_CLEAR   LW_SA_IDLE /* clear curlwp in rump scheduler */
+#define        LW_RUMP_DYING   LW_SA_YIELD/* lwp is part of a dying process */
 
 /* The second set of flags is kept in l_pflag. */
 #define        LP_KTRACTIVE    0x00000001 /* Executing ktrace operation */



Home | Main Index | Thread Index | Old Index