Source-Changes-HG archive

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

[src/trunk]: src/sys increment p_nrlwps in lwp_create rather than letting cal...



details:   https://anonhg.NetBSD.org/src/rev/f022f7d97a81
branches:  trunk
changeset: 755635:f022f7d97a81
user:      yamt <yamt%NetBSD.org@localhost>
date:      Sun Jun 13 04:13:31 2010 +0000

description:
increment p_nrlwps in lwp_create rather than letting callers do so
as it's always decremented by lwp_exit.  this fixes error recovery of
eg. aio_procinit.

diffstat:

 sys/compat/mach/mach_thread.c |   5 ++---
 sys/compat/sa/compat_sa.c     |   7 ++-----
 sys/kern/kern_fork.c          |   5 +++--
 sys/kern/kern_kthread.c       |  10 ++--------
 sys/kern/kern_lwp.c           |   5 +++--
 sys/kern/sys_aio.c            |   5 ++---
 sys/kern/sys_lwp.c            |   7 ++++---
 7 files changed, 18 insertions(+), 26 deletions(-)

diffs (200 lines):

diff -r 543099fa1f8f -r f022f7d97a81 sys/compat/mach/mach_thread.c
--- a/sys/compat/mach/mach_thread.c     Sun Jun 13 04:08:49 2010 +0000
+++ b/sys/compat/mach/mach_thread.c     Sun Jun 13 04:13:31 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mach_thread.c,v 1.49 2009/10/21 21:12:05 rmind Exp $ */
+/*     $NetBSD: mach_thread.c,v 1.50 2010/06/13 04:13:31 yamt Exp $ */
 
 /*-
  * Copyright (c) 2002-2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.49 2009/10/21 21:12:05 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mach_thread.c,v 1.50 2010/06/13 04:13:31 yamt Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -210,7 +210,6 @@
        mctc.mctc_lwp->l_private = 0;
        mctc.mctc_lwp->l_stat = LSRUN;
        sched_enqueue(mctc.mctc_lwp, false);
-       p->p_nrlwps++;
        lwp_unlock(mctc.mctc_lwp);
        mutex_exit(p->p_lock);
 
diff -r 543099fa1f8f -r f022f7d97a81 sys/compat/sa/compat_sa.c
--- a/sys/compat/sa/compat_sa.c Sun Jun 13 04:08:49 2010 +0000
+++ b/sys/compat/sa/compat_sa.c Sun Jun 13 04:13:31 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: compat_sa.c,v 1.12 2009/10/21 21:12:05 rmind Exp $     */
+/*     $NetBSD: compat_sa.c,v 1.13 2010/06/13 04:13:31 yamt Exp $      */
 
 /*-
  * Copyright (c) 2001, 2004, 2005, 2006 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
 #include "opt_ktrace.h"
 #include "opt_multiprocessor.h"
 #include "opt_sa.h"
-__KERNEL_RCSID(0, "$NetBSD: compat_sa.c,v 1.12 2009/10/21 21:12:05 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: compat_sa.c,v 1.13 2010/06/13 04:13:31 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1837,9 +1837,6 @@
         * newlwp helpfully puts it there. Unclear if newlwp should
         * be tweaked.
         */
-       mutex_enter(p->p_lock);
-       p->p_nrlwps++;
-       mutex_exit(p->p_lock);
 
        vp = (targ_vp) ? targ_vp : l->l_savp;
        mutex_enter(&vp->savp_mutex);
diff -r 543099fa1f8f -r f022f7d97a81 sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c      Sun Jun 13 04:08:49 2010 +0000
+++ b/sys/kern/kern_fork.c      Sun Jun 13 04:13:31 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_fork.c,v 1.176 2010/03/01 21:10:16 darran Exp $   */
+/*     $NetBSD: kern_fork.c,v 1.177 2010/06/13 04:13:31 yamt Exp $     */
 
 /*-
  * Copyright (c) 1999, 2001, 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.176 2010/03/01 21:10:16 darran Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.177 2010/06/13 04:13:31 yamt Exp $");
 
 #include "opt_ktrace.h"
 
@@ -502,6 +502,7 @@
        getmicrotime(&p2->p_stats->p_start);
        p2->p_acflag = AFORK;
        lwp_lock(l2);
+       KASSERT(p2->p_nrlwps == 1);
        if (p2->p_sflag & PS_STOPFORK) {
                p2->p_nrlwps = 0;
                p2->p_stat = SSTOP;
diff -r 543099fa1f8f -r f022f7d97a81 sys/kern/kern_kthread.c
--- a/sys/kern/kern_kthread.c   Sun Jun 13 04:08:49 2010 +0000
+++ b/sys/kern/kern_kthread.c   Sun Jun 13 04:13:31 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_kthread.c,v 1.29 2010/05/12 15:53:20 haad Exp $   */
+/*     $NetBSD: kern_kthread.c,v 1.30 2010/06/13 04:13:31 yamt Exp $   */
 
 /*-
  * Copyright (c) 1998, 1999, 2007, 2009 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_kthread.c,v 1.29 2010/05/12 15:53:20 haad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_kthread.c,v 1.30 2010/06/13 04:13:31 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -149,12 +149,6 @@
                lwp_unlock(l);
        } else
                lwp_unlock_to(l, ci->ci_schedstate.spc_lwplock);
-
-       /*
-        * The LWP is not created suspended or stopped and cannot be set
-        * into those states later, so must be considered runnable.
-        */
-       proc0.p_nrlwps++;
        mutex_exit(proc0.p_lock);
 
        /* All done! */
diff -r 543099fa1f8f -r f022f7d97a81 sys/kern/kern_lwp.c
--- a/sys/kern/kern_lwp.c       Sun Jun 13 04:08:49 2010 +0000
+++ b/sys/kern/kern_lwp.c       Sun Jun 13 04:13:31 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_lwp.c,v 1.148 2010/06/11 07:32:32 pooka Exp $     */
+/*     $NetBSD: kern_lwp.c,v 1.149 2010/06/13 04:13:31 yamt Exp $      */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -209,7 +209,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.148 2010/06/11 07:32:32 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.149 2010/06/13 04:13:31 yamt Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -745,6 +745,7 @@
        l2->l_lid = p2->p_nlwpid;
        LIST_INSERT_HEAD(&p2->p_lwps, l2, l_sibling);
        p2->p_nlwps++;
+       p2->p_nrlwps++;
 
        if ((p2->p_flag & PK_SYSTEM) == 0) {
                /* Inherit an affinity */
diff -r 543099fa1f8f -r f022f7d97a81 sys/kern/sys_aio.c
--- a/sys/kern/sys_aio.c        Sun Jun 13 04:08:49 2010 +0000
+++ b/sys/kern/sys_aio.c        Sun Jun 13 04:13:31 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_aio.c,v 1.31 2010/01/30 21:23:46 rmind Exp $       */
+/*     $NetBSD: sys_aio.c,v 1.32 2010/06/13 04:13:31 yamt Exp $        */
 
 /*
  * Copyright (c) 2007 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_aio.c,v 1.31 2010/01/30 21:23:46 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_aio.c,v 1.32 2010/06/13 04:13:31 yamt Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -216,7 +216,6 @@
 
        /* Complete the initialization of thread, and run it */
        aio->aio_worker = l;
-       p->p_nrlwps++;
        lwp_lock(l);
        l->l_stat = LSRUN;
        l->l_priority = MAXPRI_USER;
diff -r 543099fa1f8f -r f022f7d97a81 sys/kern/sys_lwp.c
--- a/sys/kern/sys_lwp.c        Sun Jun 13 04:08:49 2010 +0000
+++ b/sys/kern/sys_lwp.c        Sun Jun 13 04:13:31 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_lwp.c,v 1.50 2010/06/06 07:46:17 skrll Exp $       */
+/*     $NetBSD: sys_lwp.c,v 1.51 2010/06/13 04:13:32 yamt Exp $        */
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.50 2010/06/06 07:46:17 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.51 2010/06/13 04:13:32 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -140,16 +140,17 @@
                if (p->p_stat == SSTOP || (p->p_sflag & PS_STOPPING) != 0) {
                        KASSERT(l2->l_wchan == NULL);
                        l2->l_stat = LSSTOP;
+                       p->p_nrlwps--;
                        lwp_unlock_to(l2, spc->spc_lwplock);
                } else {
                        KASSERT(lwp_locked(l2, spc->spc_mutex));
-                       p->p_nrlwps++;
                        l2->l_stat = LSRUN;
                        sched_enqueue(l2, false);
                        lwp_unlock(l2);
                }
        } else {
                l2->l_stat = LSSUSPENDED;
+               p->p_nrlwps--;
                lwp_unlock_to(l2, spc->spc_lwplock);
        }
        mutex_exit(p->p_lock);



Home | Main Index | Thread Index | Old Index