Module Name:    src
Committed By:   yamt
Date:           Sun Jun 13 04:13:32 UTC 2010

Modified Files:
        src/sys/compat/mach: mach_thread.c
        src/sys/compat/sa: compat_sa.c
        src/sys/kern: kern_fork.c kern_kthread.c kern_lwp.c sys_aio.c sys_lwp.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sys/compat/mach/mach_thread.c
cvs rdiff -u -r1.12 -r1.13 src/sys/compat/sa/compat_sa.c
cvs rdiff -u -r1.176 -r1.177 src/sys/kern/kern_fork.c
cvs rdiff -u -r1.29 -r1.30 src/sys/kern/kern_kthread.c
cvs rdiff -u -r1.148 -r1.149 src/sys/kern/kern_lwp.c
cvs rdiff -u -r1.31 -r1.32 src/sys/kern/sys_aio.c
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/sys_lwp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/mach/mach_thread.c
diff -u src/sys/compat/mach/mach_thread.c:1.49 src/sys/compat/mach/mach_thread.c:1.50
--- src/sys/compat/mach/mach_thread.c:1.49	Wed Oct 21 21:12:05 2009
+++ src/sys/compat/mach/mach_thread.c	Sun Jun 13 04:13:31 2010
@@ -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);
 

Index: src/sys/compat/sa/compat_sa.c
diff -u src/sys/compat/sa/compat_sa.c:1.12 src/sys/compat/sa/compat_sa.c:1.13
--- src/sys/compat/sa/compat_sa.c:1.12	Wed Oct 21 21:12:05 2009
+++ src/sys/compat/sa/compat_sa.c	Sun Jun 13 04:13:31 2010
@@ -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);

Index: src/sys/kern/kern_fork.c
diff -u src/sys/kern/kern_fork.c:1.176 src/sys/kern/kern_fork.c:1.177
--- src/sys/kern/kern_fork.c:1.176	Mon Mar  1 21:10:16 2010
+++ src/sys/kern/kern_fork.c	Sun Jun 13 04:13:31 2010
@@ -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;

Index: src/sys/kern/kern_kthread.c
diff -u src/sys/kern/kern_kthread.c:1.29 src/sys/kern/kern_kthread.c:1.30
--- src/sys/kern/kern_kthread.c:1.29	Wed May 12 15:53:20 2010
+++ src/sys/kern/kern_kthread.c	Sun Jun 13 04:13:31 2010
@@ -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! */

Index: src/sys/kern/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.148 src/sys/kern/kern_lwp.c:1.149
--- src/sys/kern/kern_lwp.c:1.148	Fri Jun 11 07:32:32 2010
+++ src/sys/kern/kern_lwp.c	Sun Jun 13 04:13:31 2010
@@ -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 */

Index: src/sys/kern/sys_aio.c
diff -u src/sys/kern/sys_aio.c:1.31 src/sys/kern/sys_aio.c:1.32
--- src/sys/kern/sys_aio.c:1.31	Sat Jan 30 21:23:46 2010
+++ src/sys/kern/sys_aio.c	Sun Jun 13 04:13:31 2010
@@ -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;

Index: src/sys/kern/sys_lwp.c
diff -u src/sys/kern/sys_lwp.c:1.50 src/sys/kern/sys_lwp.c:1.51
--- src/sys/kern/sys_lwp.c:1.50	Sun Jun  6 07:46:17 2010
+++ src/sys/kern/sys_lwp.c	Sun Jun 13 04:13:32 2010
@@ -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);

Reply via email to