From 6680bbd5291a864dcf0bc675c62b2cea9e5fb5ca Mon Sep 17 00:00:00 2001 From: Jeff Roberson Date: Tue, 7 Jun 2005 02:59:16 +0000 Subject: [PATCH] - 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. --- sys/kern/sched_ule.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index d9c1975c0b9e..fc5c7ab396fc 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -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) {