Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 Sep 2004 21:10:38 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 61309 for review
Message-ID:  <200409102110.i8ALAclt069135@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=61309

Change 61309 by jhb@jhb_slimer on 2004/09/10 21:09:59

	IFC @61307.

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_switch.c#45 integrate
.. //depot/projects/smpng/sys/kern/kern_synch.c#80 integrate
.. //depot/projects/smpng/sys/kern/sched_4bsd.c#37 integrate
.. //depot/projects/smpng/sys/kern/sched_ule.c#41 integrate
.. //depot/projects/smpng/sys/sys/sched.h#15 integrate

Differences ...

==== //depot/projects/smpng/sys/kern/kern_switch.c#45 (text+ko) ====

@@ -86,7 +86,7 @@
 ***/
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/kern_switch.c,v 1.88 2004/09/07 06:38:22 julian Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/kern_switch.c,v 1.89 2004/09/10 21:04:38 julian Exp $");
 
 #include "opt_sched.h"
 
@@ -192,7 +192,7 @@
  *  sched_thread_exit()  (local)
  *  sched_switch()  (local)
  *  sched_thread_exit()  (local)
- *  remrunqueue()  (local) (commented out)
+ *  remrunqueue()  (local) 
  */
 static void
 slot_fill(struct ksegrp *kg)
@@ -224,7 +224,7 @@
 	}
 }
 
-#if 0
+#ifdef SCHED_4BSD
 /*
  * Remove a thread from its KSEGRP's run queue.
  * This in turn may remove it from a KSE if it was already assigned
@@ -248,7 +248,7 @@
 	 * If it is not a threaded process, take the shortcut.
 	 */
 	if ((td->td_proc->p_flag & P_HADTHREADS) == 0) {
-		/* Bring its kse with it, leave the thread attached */
+		/* remve from sys run queue and free up a slot */
 		sched_rem(td);
 		kg->kg_avail_opennings++;
 		ke->ke_state = KES_THREAD; 
@@ -259,7 +259,7 @@
 	kg->kg_runnable--;
 	if (ke->ke_state == KES_ONRUNQ) {
 		/*
-		 * This thread has been assigned to a KSE.
+		 * This thread has been assigned to the system run queue.
 		 * We need to dissociate it and try assign the
 		 * KSE to the next available thread. Then, we should
 		 * see if we need to move the KSE in the run queues.
@@ -271,7 +271,7 @@
 		KASSERT((td2 != NULL), ("last assigned has wrong value"));
 		if (td2 == td) 
 			kg->kg_last_assigned = td3;
-		slot_fill(kg);
+		/* slot_fill(kg); */ /* will replace it with another */
 	}
 }
 #endif

==== //depot/projects/smpng/sys/kern/kern_synch.c#80 (text+ko) ====

@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/kern_synch.c,v 1.259 2004/09/05 02:09:53 julian Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/kern_synch.c,v 1.260 2004/09/10 21:04:38 julian Exp $");
 
 #include "opt_ktrace.h"
 
@@ -337,7 +337,7 @@
 	    (void *)td, td->td_sched, (long)p->p_pid, p->p_comm);
 	if (td->td_proc->p_flag & P_SA)
 		newtd = thread_switchout(td, flags, newtd);
-	sched_switch(td, newtd);
+	sched_switch(td, newtd, flags);
 
 	CTR4(KTR_PROC, "mi_switch: new thread %p (kse %p, pid %ld, %s)",
 	    (void *)td, td->td_sched, (long)p->p_pid, p->p_comm);

==== //depot/projects/smpng/sys/kern/sched_4bsd.c#37 (text+ko) ====

@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/sched_4bsd.c,v 1.60 2004/09/06 07:23:14 julian Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/sched_4bsd.c,v 1.61 2004/09/10 21:04:38 julian Exp $");
 
 #define kse td_sched
 
@@ -247,8 +247,23 @@
 SYSCTL_INT(_kern_sched_ipiwakeup, OID_AUTO, htt2, CTLFLAG_RW,
 	   &forward_wakeup_use_htt, 0,
 	   "account for htt");
+
 #endif
+static int sched_followon = 0;
+SYSCTL_INT(_kern_sched, OID_AUTO, followon, CTLFLAG_RW,
+	   &sched_followon, 0,
+	   "allow threads to share a quantum");
 
+static int sched_pfollowons = 0;
+SYSCTL_INT(_kern_sched, OID_AUTO, pfollowons, CTLFLAG_RD,
+	   &sched_pfollowons, 0,
+	   "number of followons done to a different ksegrp");
+
+static int sched_kgfollowons = 0;
+SYSCTL_INT(_kern_sched, OID_AUTO, kgfollowons, CTLFLAG_RD,
+	   &sched_kgfollowons, 0,
+	   "number of followons done in a ksegrp");
+
 /*
  * Arrange to reschedule if necessary, taking the priorities and
  * schedulers into account.
@@ -733,10 +748,13 @@
 	td->td_base_pri = td->td_priority;
 }
 
+static void remrunqueue(struct thread *td);
+
 void
-sched_switch(struct thread *td, struct thread *newtd)
+sched_switch(struct thread *td, struct thread *newtd, int flags)
 {
 	struct kse *ke;
+	struct ksegrp *kg;
 	struct proc *p;
 
 	ke = td->td_kse;
@@ -746,6 +764,33 @@
 
 	if ((p->p_flag & P_NOLOAD) == 0)
 		sched_tdcnt--;
+
+	/* 
+	 * We are volunteering to switch out so we get to nominate
+	 * a successor for the rest of our quantum
+	 * First try another thread in our ksegrp, and then look for 
+	 * other ksegrps in our process.
+	 */
+	if (sched_followon &&
+	    (p->p_flag & P_HADTHREADS) &&
+	    (flags & SW_VOL) &&
+	    newtd == NULL) {
+		/* lets schedule another thread from this process */
+		 kg = td->td_ksegrp;
+		 if ((newtd = TAILQ_FIRST(&kg->kg_runq))) {
+			remrunqueue(newtd);
+			sched_kgfollowons++;
+		 } else {
+			FOREACH_KSEGRP_IN_PROC(p, kg) {
+				if ((newtd = TAILQ_FIRST(&kg->kg_runq))) {
+					sched_pfollowons++;
+					remrunqueue(newtd);
+					break;
+				}
+			}
+		}
+	}
+
 	/* 
 	 * The thread we are about to run needs to be counted as if it had been 
 	 * added to the run queue and selected.
@@ -757,6 +802,7 @@
 		if ((newtd->td_proc->p_flag & P_NOLOAD) == 0)
 			sched_tdcnt++;
 	}
+
 	td->td_lastcpu = td->td_oncpu;
 	td->td_flags &= ~TDF_NEEDRESCHED;
 	td->td_pflags &= ~TDP_OWEPREEMPT;

==== //depot/projects/smpng/sys/kern/sched_ule.c#41 (text+ko) ====

@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/kern/sched_ule.c,v 1.125 2004/09/05 02:09:53 julian Exp $");
+__FBSDID("$FreeBSD: src/sys/kern/sched_ule.c,v 1.126 2004/09/10 21:04:38 julian Exp $");
 
 #include <opt_sched.h>
 
@@ -1225,7 +1225,7 @@
 }
 
 void
-sched_switch(struct thread *td, struct thread *newtd)
+sched_switch(struct thread *td, struct thread *newtd, int flags)
 {
 	struct kse *ke;
 

==== //depot/projects/smpng/sys/sys/sched.h#15 (text+ko) ====

@@ -23,7 +23,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/sys/sched.h,v 1.16 2004/09/05 02:09:54 julian Exp $
+ * $FreeBSD: src/sys/sys/sched.h,v 1.17 2004/09/10 21:04:37 julian Exp $
  */
 
 #ifndef _SYS_SCHED_H_
@@ -66,7 +66,7 @@
 fixpt_t	sched_pctcpu(struct thread *td);
 void	sched_prio(struct thread *td, u_char prio);
 void	sched_sleep(struct thread *td);
-void	sched_switch(struct thread *td, struct thread *newtd);
+void	sched_switch(struct thread *td, struct thread *newtd, int flags);
 void	sched_userret(struct thread *td);
 void	sched_wakeup(struct thread *td);
 



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