Index: sched_ule.c =================================================================== RCS file: /home/ncvs/src/sys/kern/sched_ule.c,v retrieving revision 1.208 diff -u -r1.208 sched_ule.c --- sched_ule.c 22 Sep 2007 02:20:14 -0000 1.208 +++ sched_ule.c 23 Sep 2007 23:45:36 -0000 @@ -1410,7 +1410,7 @@ * score. Negative nice values make it easier for a thread to be * considered interactive. */ - score = sched_interact_score(td) - td->td_proc->p_nice; + score = imax(0, sched_interact_score(td) - td->td_proc->p_nice); if (score < sched_interact) { pri = PRI_MIN_REALTIME; pri += ((PRI_MAX_REALTIME - PRI_MIN_REALTIME) / sched_interact) @@ -1865,6 +1865,7 @@ if (PMC_PROC_IS_USING_PMCS(td->td_proc)) PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_OUT); #endif + TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd; cpu_switch(td, newtd, mtx); /* * We may return from cpu_switch on a different cpu. However, @@ -1873,7 +1874,6 @@ */ cpuid = PCPU_GET(cpuid); tdq = TDQ_CPU(cpuid); - TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)td; #ifdef HWPMC_HOOKS if (PMC_PROC_IS_USING_PMCS(td->td_proc)) PMC_SWITCH_CONTEXT(td, PMC_FN_CSW_IN); @@ -2569,6 +2569,7 @@ void sched_throw(struct thread *td) { + struct thread *newtd; struct tdq *tdq; tdq = TDQ_SELF(); @@ -2581,9 +2582,11 @@ tdq_load_rem(tdq, td->td_sched); } KASSERT(curthread->td_md.md_spinlock_count == 1, ("invalid count")); + newtd = choosethread(); + TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)newtd; PCPU_SET(switchtime, cpu_ticks()); PCPU_SET(switchticks, ticks); - cpu_throw(td, choosethread()); /* doesn't return */ + cpu_throw(td, newtd); /* doesn't return */ } /* @@ -2608,8 +2611,7 @@ td->td_lock = TDQ_LOCKPTR(tdq); MPASS(td->td_lock == TDQ_LOCKPTR(tdq)); td->td_oncpu = cpuid; - TDQ_LOCKPTR(tdq)->mtx_lock = (uintptr_t)td; - THREAD_LOCK_ASSERT(td, MA_OWNED | MA_NOTRECURSED); + TDQ_LOCK_ASSERT(tdq, MA_OWNED | MA_NOTRECURSED); } static SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RW, 0,