Module Name: src Committed By: pooka Date: Fri Jan 28 16:58:28 UTC 2011
Modified Files: src/sys/rump/librump/rumpkern: locks.c lwproc.c rump.c scheduler.c src/sys/sys: lwp.h Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/sys/rump/librump/rumpkern/locks.c cvs rdiff -u -r1.11 -r1.12 src/sys/rump/librump/rumpkern/lwproc.c cvs rdiff -u -r1.222 -r1.223 src/sys/rump/librump/rumpkern/rump.c cvs rdiff -u -r1.24 -r1.25 src/sys/rump/librump/rumpkern/scheduler.c cvs rdiff -u -r1.141 -r1.142 src/sys/sys/lwp.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/rump/librump/rumpkern/locks.c diff -u src/sys/rump/librump/rumpkern/locks.c:1.48 src/sys/rump/librump/rumpkern/locks.c:1.49 --- src/sys/rump/librump/rumpkern/locks.c:1.48 Tue Jan 18 22:21:23 2011 +++ src/sys/rump/librump/rumpkern/locks.c Fri Jan 28 16:58:28 2011 @@ -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 */ Index: src/sys/rump/librump/rumpkern/lwproc.c diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.11 src/sys/rump/librump/rumpkern/lwproc.c:1.12 --- src/sys/rump/librump/rumpkern/lwproc.c:1.11 Fri Jan 28 16:34:31 2011 +++ src/sys/rump/librump/rumpkern/lwproc.c Fri Jan 28 16:58:28 2011 @@ -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; Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.222 src/sys/rump/librump/rumpkern/rump.c:1.223 --- src/sys/rump/librump/rumpkern/rump.c:1.222 Thu Jan 27 17:36:27 2011 +++ src/sys/rump/librump/rumpkern/rump.c Fri Jan 28 16:58:28 2011 @@ -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); Index: src/sys/rump/librump/rumpkern/scheduler.c diff -u src/sys/rump/librump/rumpkern/scheduler.c:1.24 src/sys/rump/librump/rumpkern/scheduler.c:1.25 --- src/sys/rump/librump/rumpkern/scheduler.c:1.24 Tue Jan 11 10:49:20 2011 +++ src/sys/rump/librump/rumpkern/scheduler.c Fri Jan 28 16:58:28 2011 @@ -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); Index: src/sys/sys/lwp.h diff -u src/sys/sys/lwp.h:1.141 src/sys/sys/lwp.h:1.142 --- src/sys/sys/lwp.h:1.141 Tue Jan 18 20:17:50 2011 +++ src/sys/sys/lwp.h Fri Jan 28 16:58:27 2011 @@ -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 */