Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Apr 2002 20:56:54 -0700 (PDT)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 9489 for review
Message-ID:  <200204100356.g3A3usR38841@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=9489

Change 9489 by jhb@jhb_laptop on 2002/04/09 20:56:10

	Hold sched_lock for almost all of the switch statement inside
	psignal() except for when signalling our parent when we stop.
	The code in the switch assumes that if we are in one state we
	are in that state for the entire switch, so we hold sched_lock
	to ensure the process doesn't change state out from under us.

Affected files ...

... //depot/projects/smpng/sys/kern/kern_sig.c#29 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_sig.c#29 (text+ko) ====

@@ -190,7 +190,6 @@
 {
 
 	PROC_LOCK_ASSERT(p, MA_OWNED);
-	mtx_assert(&sched_lock, MA_NOTOWNED);
 	mtx_lock_spin(&sched_lock);
 	if (SIGPENDING(p)) {
 		p->p_sflag |= PS_NEEDSIGCHK;
@@ -1324,6 +1323,7 @@
 		SIG_CONTSIGMASK(p->p_siglist);
 	}
 	SIGADDSET(p->p_siglist, sig);
+	mtx_lock_spin(&sched_lock);
 	signotify(p);
 
 	/*
@@ -1334,7 +1334,6 @@
 	 * XXX: we shouldn't drop sched_lock from signotify() and then lock it
 	 * again here.
 	 */
-	mtx_lock_spin(&sched_lock);
 	if (action == SIG_HOLD && (!(prop & SA_CONT) || p->p_stat != SSTOP)) {
 		mtx_unlock_spin(&sched_lock);
 		return;
@@ -1349,11 +1348,8 @@
 		 * be noticed when the process returns through
 		 * trap() or syscall().
 		 */
-		if ((td->td_flags & TDF_SINTR) == 0) {
-			mtx_unlock_spin(&sched_lock);
+		if ((td->td_flags & TDF_SINTR) == 0)
 			goto out;
-		}
-		mtx_unlock_spin(&sched_lock);
 		/*
 		 * Process is sleeping and traced... make it runnable
 		 * so it can discover the signal in issignal() and stop
@@ -1385,6 +1381,7 @@
 			 */
 			if (p->p_flag & P_PPWAIT)
 				goto out;
+			mtx_unlock_spin(&sched_lock);
 			SIGDELSET(p->p_siglist, sig);
 			p->p_xstat = sig;
 			PROC_LOCK(p->p_pptr);
@@ -1393,14 +1390,12 @@
 			PROC_UNLOCK(p->p_pptr);
 			mtx_lock_spin(&sched_lock);
 			stop(p);
-			mtx_unlock_spin(&sched_lock);
 			goto out;
 		} else
 			goto runfast;
 		/* NOTREACHED */
 
 	case SSTOP:
-		mtx_unlock_spin(&sched_lock);
 		/*
 		 * If traced process is already stopped,
 		 * then no further action is necessary.
@@ -1429,7 +1424,6 @@
 				SIGDELSET(p->p_siglist, sig);
 			if (action == SIG_CATCH)
 				goto runfast;
-			mtx_lock_spin(&sched_lock);
 			/*
 			 * XXXKSE
 			 * do this for each thread.
@@ -1449,7 +1443,6 @@
 					goto run;
 				p->p_stat = SSLEEP;
 			}
-			mtx_unlock_spin(&sched_lock);
 			goto out;
 		}
 
@@ -1469,7 +1462,6 @@
 		 * the process runnable, leave it stopped.
 		 * XXXKSE should we wake ALL blocked threads?
 		 */
-		mtx_lock_spin(&sched_lock);
 		if (p->p_flag & P_KSES) {
 			FOREACH_THREAD_IN_PROC(p, td) {
 				if (td->td_wchan && (td->td_flags & TDF_SINTR)){
@@ -1487,7 +1479,6 @@
 					unsleep(td); /* XXXKSE */
 			}
 		}
-		mtx_unlock_spin(&sched_lock);
 		goto out;
 
 	default:
@@ -1511,7 +1502,6 @@
 			}
 #endif
 		}
-		mtx_unlock_spin(&sched_lock);
 		goto out;
 	}
 	/*NOTREACHED*/
@@ -1522,7 +1512,6 @@
 	 * XXXKSE Should we make them all run fast?
 	 * Maybe just one would be enough?
 	 */
-	mtx_lock_spin(&sched_lock);
 
 	if (FIRST_THREAD_IN_PROC(p)->td_priority > PUSER) {
 		FIRST_THREAD_IN_PROC(p)->td_priority = PUSER;
@@ -1531,9 +1520,10 @@
 	/* If we jump here, sched_lock has to be owned. */
 	mtx_assert(&sched_lock, MA_OWNED | MA_NOTRECURSED);
 	setrunnable(td); /* XXXKSE */
+out:
 	mtx_unlock_spin(&sched_lock);
-out:
-	/* If we jump here, sched_lock should not be owned. */
+
+	/* Once we get here, sched_lock should not be owned. */
 	mtx_assert(&sched_lock, MA_NOTOWNED);
 }
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204100356.g3A3usR38841>