Module Name:    src
Committed By:   ad
Date:           Sun Oct  8 12:38:58 UTC 2023

Modified Files:
        src/sys/kern: kern_exec.c kern_exit.c

Log Message:
Defer some wakeups till lock release.


To generate a diff of this commit:
cvs rdiff -u -r1.520 -r1.521 src/sys/kern/kern_exec.c
cvs rdiff -u -r1.297 -r1.298 src/sys/kern/kern_exit.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/kern/kern_exec.c
diff -u src/sys/kern/kern_exec.c:1.520 src/sys/kern/kern_exec.c:1.521
--- src/sys/kern/kern_exec.c:1.520	Wed Oct  4 22:17:09 2023
+++ src/sys/kern/kern_exec.c	Sun Oct  8 12:38:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exec.c,v 1.520 2023/10/04 22:17:09 ad Exp $	*/
+/*	$NetBSD: kern_exec.c,v 1.521 2023/10/08 12:38:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.520 2023/10/04 22:17:09 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.521 2023/10/08 12:38:58 ad Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -1314,7 +1314,6 @@ execve_runproc(struct lwp *l, struct exe
 		lp = p->p_vforklwp;
 		p->p_vforklwp = NULL;
 		l->l_lwpctl = NULL; /* was on loan from blocked parent */
-		cv_broadcast(&lp->l_waitcv);
 
 		/* Clear flags after cv_broadcast() (scheduler needs them). */
 		p->p_lflag &= ~PL_PPWAIT;
@@ -1322,6 +1321,7 @@ execve_runproc(struct lwp *l, struct exe
 
 		/* If parent is still on same CPU, teleport curlwp elsewhere. */
 		samecpu = (lp->l_cpu == curlwp->l_cpu);
+		cv_broadcast(&lp->l_waitcv);
 		mutex_exit(&proc_lock);
 
 		/* Give the parent its CPU back - find a new home. */

Index: src/sys/kern/kern_exit.c
diff -u src/sys/kern/kern_exit.c:1.297 src/sys/kern/kern_exit.c:1.298
--- src/sys/kern/kern_exit.c:1.297	Wed Oct  4 20:48:13 2023
+++ src/sys/kern/kern_exit.c	Sun Oct  8 12:38:58 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $	*/
+/*	$NetBSD: kern_exit.c,v 1.298 2023/10/08 12:38:58 ad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 1999, 2006, 2007, 2008, 2020, 2023
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.297 2023/10/04 20:48:13 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.298 2023/10/08 12:38:58 ad Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_dtrace.h"
@@ -548,9 +548,6 @@ exit1(struct lwp *l, int exitcode, int s
 	calcru(p, &p->p_stats->p_ru.ru_utime, &p->p_stats->p_ru.ru_stime,
 	    NULL, NULL);
 
-	if (wakeinit)
-		cv_broadcast(&initproc->p_waitcv);
-
 	callout_destroy(&l->l_timeout_ch);
 
 	/*
@@ -558,7 +555,6 @@ exit1(struct lwp *l, int exitcode, int s
 	 */
 	pcu_discard_all(l);
 
-	mutex_enter(p->p_lock);
 	/*
 	 * Notify other processes tracking us with a knote that
 	 * we're exiting.
@@ -568,6 +564,7 @@ exit1(struct lwp *l, int exitcode, int s
 	 * knote_proc_exit() expects that p->p_lock is already
 	 * held (and will assert so).
 	 */
+	mutex_enter(p->p_lock);
 	if (!SLIST_EMPTY(&p->p_klist)) {
 		knote_proc_exit(p);
 	}
@@ -592,9 +589,11 @@ exit1(struct lwp *l, int exitcode, int s
 	 * Signal the parent to collect us, and drop the proclist lock.
 	 * Drop debugger/procfs lock; no new references can be gained.
 	 */
-	cv_broadcast(&p->p_pptr->p_waitcv);
 	rw_exit(&p->p_reflock);
+	cv_broadcast(&p->p_pptr->p_waitcv);
 	mutex_exit(&proc_lock);
+	if (wakeinit)
+		cv_broadcast(&initproc->p_waitcv);
 
 	/*
 	 * NOTE: WE ARE NO LONGER ALLOWED TO SLEEP!

Reply via email to