From owner-p4-projects@FreeBSD.ORG Mon Sep 6 04:22:56 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 7509716A4D0; Mon, 6 Sep 2004 04:22:56 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3CDE416A4CE for ; Mon, 6 Sep 2004 04:22:56 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1F6D043D2D for ; Mon, 6 Sep 2004 04:22:56 +0000 (GMT) (envelope-from julian@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i864MtSR059171 for ; Mon, 6 Sep 2004 04:22:56 GMT (envelope-from julian@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i864MtKc059168 for perforce@freebsd.org; Mon, 6 Sep 2004 04:22:55 GMT (envelope-from julian@freebsd.org) Date: Mon, 6 Sep 2004 04:22:55 GMT Message-Id: <200409060422.i864MtKc059168@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to julian@freebsd.org using -f From: Julian Elischer To: Perforce Change Reviews Subject: PERFORCE change 61076 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2004 04:22:57 -0000 http://perforce.freebsd.org/chv.cgi?CH=61076 Change 61076 by julian@julian_ref on 2004/09/06 04:22:52 Very simplistic code to allow a sleeping thread to nominate a thread to replace it. Affected files ... .. //depot/projects/nsched/sys/kern/kern_switch.c#11 edit .. //depot/projects/nsched/sys/kern/kern_synch.c#12 edit .. //depot/projects/nsched/sys/kern/sched_4bsd.c#38 edit .. //depot/projects/nsched/sys/kern/sched_ule.c#24 edit .. //depot/projects/nsched/sys/sys/sched.h#14 edit Differences ... ==== //depot/projects/nsched/sys/kern/kern_switch.c#11 (text+ko) ==== @@ -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/nsched/sys/kern/kern_synch.c#12 (text+ko) ==== @@ -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/nsched/sys/kern/sched_4bsd.c#38 (text+ko) ==== @@ -733,10 +733,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,8 +749,28 @@ if ((p->p_flag & P_NOLOAD) == 0) sched_tdcnt--; - if (newtd != NULL && (newtd->td_proc->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 ((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); + } else { + FOREACH_KSEGRP_IN_PROC(p, kg) { + if ((newtd = TAILQ_FIRST(&kg->kg_runq))) { + 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. @@ -756,6 +779,9 @@ newtd->td_ksegrp->kg_avail_opennings--; newtd->td_kse->ke_flags |= KEF_DIDRUN; TD_SET_RUNNING(newtd); + if ((newtd->td_proc->p_flag & P_NOLOAD) == 0) + sched_tdcnt++; + } td->td_lastcpu = td->td_oncpu; td->td_flags &= ~TDF_NEEDRESCHED; ==== //depot/projects/nsched/sys/kern/sched_ule.c#24 (text+ko) ==== @@ -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/nsched/sys/sys/sched.h#14 (text+ko) ==== @@ -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);