- Fix the case where we're not preempting but there is already a newtd

as this happens via thread_switchout().  I don't particularly like the
   structure of the code here.  We twice call out to thread code when
   a thread is voluntarily switching.  Once to thread_switchout() and once
   to slot_fill(), while sched_4BSD does even more work which is redundant
   to select another thread to use our remaining slice.  This should be
   simplified in the future, but for now I'm only going to fix the bug not
   the bad design.
This commit is contained in:
Jeff Roberson 2005-06-07 02:59:16 +00:00
parent 0f2e86fb2a
commit 6680bbd529
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=147068

View File

@ -1350,14 +1350,22 @@ sched_switch(struct thread *td, struct thread *newtd, int flags)
}
if (newtd != NULL) {
/*
* If we bring in a thread,
* then account for it as if it had been added to the
* run queue and then chosen.
* If we bring in a thread account for it as if it had been
* added to the run queue and then chosen.
*/
newtd->td_kse->ke_flags |= KEF_DIDRUN;
newtd->td_kse->ke_runq = ksq->ksq_curr;
TD_SET_RUNNING(newtd);
kseq_load_add(KSEQ_SELF(), newtd->td_kse);
/*
* XXX When we preempt, we've already consumed a slot because
* we got here through sched_add(). However, newtd can come
* from thread_switchout() which can't SLOT_USE() because
* the SLOT code is scheduler dependent. We must use the
* slot here otherwise.
*/
if ((flags & SW_PREEMPT) == 0)
SLOT_USE(newtd->td_ksegrp);
} else
newtd = choosethread();
if (td != newtd) {