Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Jun 2002 18:13:17 -0700 (PDT)
From:      Julian Elischer <julian@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 13129 for review
Message-ID:  <200206190113.g5J1DHH53692@freefall.freebsd.org>

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

Change 13129 by julian@julian_ref on 2002/06/18 18:12:51

	 working on cleaning up a twisty maze of little passages,
	no wait.. maybe it was a maze of twisty....

Affected files ...

... //depot/projects/kse/sys/kern/kern_switch.c#51 edit
... //depot/projects/kse/sys/kern/kern_thread.c#71 edit

Differences ...

==== //depot/projects/kse/sys/kern/kern_switch.c#51 (text+ko) ====

@@ -146,23 +146,31 @@
 /*
  * Given a KSE (now surplus), either assign a new runable thread to it
  * (and put it in the run queue) or put it in the ksegrp's idle KSE list.
+ * Assumes the kse is not linked to any threads any more. (has been cleaned).
  */
 void
 kse_reassign(struct kse *ke)
 {
-	struct ksegrp *kg = ke->ke_ksegrp;
+	struct ksegrp *kg;
 	struct thread *td;
-	struct proc *p;
+
+	kg = ke->ke_ksegrp;
 
-	ke->ke_state = KES_IDLE; /* temp state */
+	/*
+	 * Find the first unassigned thread
+	 * If there is a 'last assigned' then see what's next.
+	 * otherwise look at what is first.
+	 */
 	if ((td = kg->kg_last_assigned)) {
-		/* If there is a 'last assigned' then see what's next. */
 		td = TAILQ_NEXT(td, td_runq);
 	} else {
 		td = TAILQ_FIRST(&kg->kg_runq);
 	}
+
+	/*
+	 * If we found one assign it the kse, otherwise idle the kse.
+	 */
 	if (td) {
-		p = ke->ke_proc;
 		kg->kg_last_assigned = td;
 		td->td_kse = ke;
 		ke->ke_thread = td;

==== //depot/projects/kse/sys/kern/kern_thread.c#71 (text+ko) ====

@@ -174,56 +174,6 @@
 }
 
 /*
- * Unlink thread from its process, and reassign its KSE to another thread.
- */
-static void
-thread_unlink(struct thread *td)
-{
-	struct proc	*p;
-	struct ksegrp	*kg;
-	struct kse	*ke;
-
-	p = td->td_proc;
-	kg = td->td_ksegrp;
-	ke = td->td_kse;
-
-	/* Reassign this thread's KSE. */
-	if (ke != NULL) {
-		ke->ke_thread = NULL;
-		td->td_kse = NULL;
-		ke->ke_state = KES_UNQUEUED;
-		kse_reassign(ke);
-	}
-
-	/* Unlink this thread from its proc. */
-	if (p != NULL) {
-		TAILQ_REMOVE(&p->p_threads, td, td_plist);
-		if (kg != NULL)
-			TAILQ_REMOVE(&kg->kg_threads, td, td_kglist);
-		p->p_numthreads--;
-#if 0
-		if (P_SHOULDSTOP(p) == P_STOPPED_SNGL) {
-			if (p->p_numthreads == ((p->p_flag & P_SINGLE_EXIT) ?
-			    1 : p->p_suspcount)) {
-				TAILQ_REMOVE(&p->p_suspended,
-				    p->p_singlethread, td_runq);
-				setrunqueue(p->p_singlethread);
-				p->suspcount--;
-			}
-		}
-#else
-		thread_unsuspend(p);	/* see if it is there yet */
-#endif
-	}
-	if (kg != NULL)
-		kg->kg_numthreads--;
-	td->td_state	= TDS_SURPLUS;
-	td->td_proc	= NULL;
-	td->td_ksegrp	= NULL;
-	td->td_last_kse	= NULL;
-}
-
-/*
  * Initialize global thread allocation resources.
  */
 void
@@ -343,10 +293,14 @@
 	struct thread *td;
 	struct kse *ke;
 	struct proc *p;
+	struct ksegrp	*kg;
 
 	td = curthread;
+	kg = td->td_ksegrp;
 	p = td->td_proc;
 	ke = td->td_kse;
+
+	mtx_assert(&sched_lock, MA_OWNED);
 	PROC_LOCK_ASSERT(p, MA_OWNED);
 	CTR1(KTR_PROC, "thread_exit: thread %p", td);
 	KASSERT(!mtx_owned(&Giant), ("dying thread owns giant"));
@@ -356,7 +310,43 @@
 		ke->ke_tdspare = NULL;
 	}
 	cpu_thread_exit(td);	/* XXXSMP */
-	thread_unlink(td); 	/* Remember that this reassigns the KSE */
+
+	/* Reassign this thread's KSE. */
+	if (ke != NULL) {
+		ke->ke_thread = NULL;
+		td->td_kse = NULL;
+		ke->ke_state = KES_UNQUEUED;
+		kse_reassign(ke);
+	}
+
+	/* Unlink this thread from its proc. and the kseg */
+	if (p != NULL) {
+		TAILQ_REMOVE(&p->p_threads, td, td_plist);
+		p->p_numthreads--;
+		if (kg != NULL) {
+			TAILQ_REMOVE(&kg->kg_threads, td, td_kglist);
+			kg->kg_numthreads--;
+		}
+#if 0
+		if (P_SHOULDSTOP(p) == P_STOPPED_SNGL) {
+			if (p->p_numthreads == ((p->p_flag & P_SINGLE_EXIT) ?
+			    1 : p->p_suspcount)) {
+				TAILQ_REMOVE(&p->p_suspended,
+				    p->p_singlethread, td_runq);
+				setrunqueue(p->p_singlethread);
+				p->suspcount--;
+			}
+		}
+#else
+		thread_unsuspend(p);	/* see if it is there yet */
+#endif
+	}
+	if (kg != NULL)
+		kg->kg_numthreads--;
+	td->td_state	= TDS_SURPLUS;
+	td->td_proc	= NULL;
+	td->td_ksegrp	= NULL;
+	td->td_last_kse	= NULL;
 	ke->ke_tdspare = td;
 	PROC_UNLOCK(p);
 	cpu_throw();

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?200206190113.g5J1DHH53692>