Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jun 2002 00:51:14 -0700 (PDT)
From:      Julian Elischer <julian@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 13311 for review
Message-ID:  <200206230751.g5N7pEV73087@freefall.freebsd.org>

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

Change 13311 by julian@julian_jules1 on 2002/06/23 00:50:37

	Bunch of possible fixes and stuff from Matt and myself.

Affected files ...

... //depot/projects/kse/sys/kern/kern_switch.c#56 edit

Differences ...

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

@@ -131,7 +131,11 @@
 		if (td->td_flags & TDF_UNBOUND) {
 			TAILQ_REMOVE(&kg->kg_runq, td, td_runq);
 			if (kg->kg_last_assigned == td) 
-				kg->kg_last_assigned = NULL;
+				if (TAILQ_PREV(td, threadlist_head, td_runq)
+				    != NULL)
+					printf("Yo MAMA!\n");
+				kg->kg_last_assigned = TAILQ_PREV(td,
+				    threadlist_head, td_runq);
 			/*
 			 *  If we have started running an upcall,
 			 * Then TDF_UNBOUND WAS set because the thread was 
@@ -255,11 +259,8 @@
 	struct kse *ke;
 
 	mtx_assert(&sched_lock, MA_OWNED);
-	if (td->td_state != TDS_RUNQ) {
-		panic("remrunqueue: Bad state on run queue");
-		/* NOTREACHED */
-		return;
-	}
+	KASSERT (td->td_state != TDS_RUNQ),
+		("remrunqueue: Bad state on run queue"));
 	kg = td->td_ksegrp;
 	ke = td->td_kse;
 	/*
@@ -270,7 +271,7 @@
 	td->td_state = TDS_UNQUEUED;
 	kg->kg_runnable--;
 	if ((td->td_flags & TDF_UNBOUND) == 0)  {
-		/* Bring its kse with it. */
+		/* Bring its kse with it, leave the thread attached */
 		runq_remove(&runq, ke);
 		ke->ke_state = KES_UNQUEUED; 
 		return;
@@ -282,8 +283,10 @@
 		 * KSE to the next available thread. Then, we should
 		 * see if we need to move the KSE in the run queues.
 		 */
+		td->td_kse = NULL;
 		td2 = kg->kg_last_assigned;
 		if ((td3 = TAILQ_NEXT(td2, td_runq))) {
+			KASSERT(td3 != td, ("td3 somehow matched td"));
 			/*
 			 * Give the next unassigned thread to the KSE
 			 * so the number of runnable KSEs remains
@@ -302,14 +305,9 @@
 			 */
 			if (td == td2) {
 				kg->kg_last_assigned =
-					TAILQ_PREV(td,
-					    threadlist_head, td_runq);
+				    TAILQ_PREV(td, threadlist_head, td_runq);
 			}
 			runq_remove(&runq, ke);
-			if (td == td2) {
-				kg->kg_last_assigned = TAILQ_PREV(td,
-				    threadlist_head, td_runq);
-			}
 KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self!"));
 			KASSERT((ke->ke_state != KES_IDLE),
 			    ("kse already idle"));
@@ -351,25 +349,27 @@
 	}
 	/* 
 	 * Ok, so we are threading with this thread.
-	 * quickly disassociate the KSE if we have one..
+	 * We don't have a KSE, see if we can get one..
 	 */
 	if ((ke = td->td_kse) == NULL) {
 		/*
-		 * see if we will need a KSE and if there is one..
+		 * We will need a KSE, see if there is one..
 		 * First look for a free one, before getting desperate.
+		 * If we can't get one, our priority is not high enough..
+		 * that's ok..
 		 */
 		if (kg->kg_idle_kses) {
 			/*
 			 * There is a free one so it's ours for the asking..
 			 */
 			ke = TAILQ_FIRST(&kg->kg_iq);
-KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self!"));
+KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self3!"));
 			TAILQ_REMOVE(&kg->kg_iq, ke, ke_kgrlist);
 			ke->ke_state = KES_UNQUEUED;
 			kg->kg_idle_kses--;
 			ke->ke_thread = td;
 			td->td_kse = ke;
-KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self!"));
+KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self4!"));
 		} else if ((kg->kg_last_assigned) &&
 		   (kg->kg_last_assigned->td_priority > td->td_priority)) {
 			/*
@@ -383,8 +383,11 @@
 			ke->ke_thread = td;
 			td2->td_kse = NULL;
 			td->td_kse = ke;
-KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self!"));
+KASSERT((ke->ke_kgrlist.tqe_next != ke), ("linked to self5!"));
 		}
+	} else {
+		KASSERT(ke->ke_thread == td, ("KSE/thread mismatch"));
+		KASSERT(ke->ke_state != KES_IDLE, ("KSE unexpectedly idle"));
 	}
 
 	/*
@@ -407,8 +410,6 @@
 	 * If needed, readjust the last_assigned pointer.
 	 */
 	if (ke) {
-		ke->ke_thread = td;
-		td->td_kse = ke;
 		if (kg->kg_last_assigned ==
 		    TAILQ_PREV(td, threadlist_head, td_runq)) {
 			kg->kg_last_assigned = td;
@@ -747,11 +748,7 @@
 	struct rqhead *rqh;
 	int pri;
 
-	if (ke->ke_state != KES_ONRUNQ) {
-		printf("request to removed unqueued item from runq: ");
-		printf("state was %d", ke->ke_state);
-		return;
-	}
+	KASSERT((ke->ke_state == KES_ONRUNQ), ("KSE not on run queue"));
 	mtx_assert(&sched_lock, MA_OWNED);
 	pri = ke->ke_rqindex;
 	rqh = &rq->rq_queues[pri];

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?200206230751.g5N7pEV73087>