PERFORCE change 61076 for review
Julian Elischer
julian at FreeBSD.org
Sun Sep 5 21:22:57 PDT 2004
http://perforce.freebsd.org/chv.cgi?CH=61076
Change 61076 by julian at 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);
More information about the p4-projects
mailing list