From c36ccfa22bc39764d3b634e96e1d88086bad8639 Mon Sep 17 00:00:00 2001 From: Jeff Roberson Date: Fri, 11 Apr 2003 18:37:34 +0000 Subject: [PATCH] - When migrating a kse from one kseq to the next actually insert it onto the second kseq's run queue so that it is referenced by the kse when it is switched out. - Spell ksq_rslices properly. Reported by: Ian Freislich --- sys/kern/sched_ule.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 04dcf2961f6..00be5706787 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -924,7 +924,7 @@ sched_clock(struct kse *ke) */ ke->ke_slice--; #ifdef SMP - kseq->ksq_rslice--; + kseq->ksq_rslices--; #endif if (ke->ke_slice > 0) @@ -991,16 +991,11 @@ sched_choose(void) { struct kseq *kseq; struct kse *ke; -#ifdef SMP - int steal; - steal = 0; -#endif - - kseq = KSEQ_SELF(); #ifdef SMP retry: #endif + kseq = KSEQ_SELF(); ke = kseq_choose(kseq); if (ke) { runq_remove(ke->ke_runq, ke); @@ -1011,28 +1006,30 @@ retry: ke, ke->ke_runq, ke->ke_slice, ke->ke_thread->td_priority); } -#ifdef SMP - /* - * If we've stolen this thread we need to kill the pointer - * to the run queue and reset the cpu id. - */ - if (steal) { - kseq_rem(kseq, ke); - ke->ke_cpu = PCPU_GET(cpuid); - kseq_add(KSEQ_SELF(), ke); - } -#endif return (ke); } #ifdef SMP - if (ke == NULL && smp_started) { + if (smp_started) { /* * Find the cpu with the highest load and steal one proc. */ - steal = 1; - if ((kseq = kseq_load_highest()) != NULL) - goto retry; + if ((kseq = kseq_load_highest()) == NULL) + return (NULL); + + /* + * Remove this kse from this kseq and runq and then requeue + * on the current processor. Then we will dequeue it + * normally above. + */ + ke = kseq_choose(kseq); + runq_remove(ke->ke_runq, ke); + ke->ke_state = KES_THREAD; + kseq_rem(kseq, ke); + + ke->ke_cpu = PCPU_GET(cpuid); + sched_add(ke); + goto retry; } #endif