From 53a6c8b3ac32bedbbdd749112f5c674fa94cdbd1 Mon Sep 17 00:00:00 2001 From: Jeff Roberson Date: Sat, 14 Mar 2009 11:41:36 +0000 Subject: [PATCH] - Fix an error that occurs when mp_ncpu is an odd number. steal_thresh is calculated as 0 which causes errors elsewhere. Submitted by: KOIE Hidetaka - When sched_affinity() is called with a thread that is not curthread we need to handle the ON_RUNQ() case by adding the thread to the correct run queue. Submitted by: Justin Teller MFC after: 1 Week --- sys/kern/sched_ule.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 96f7280473f..a748b701840 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -1337,11 +1337,11 @@ sched_initticks(void *dummy) */ balance_interval = realstathz; /* - * Set steal thresh to log2(mp_ncpu) but no greater than 4. This - * prevents excess thrashing on large machines and excess idle on - * smaller machines. + * Set steal thresh to roughly log2(mp_ncpu) but no greater than 4. + * This prevents excess thrashing on large machines and excess idle + * on smaller machines. */ - steal_thresh = min(ffs(mp_ncpus) - 1, 3); + steal_thresh = min(fls(mp_ncpus) - 1, 3); affinity = SCHED_AFFINITY_DEFAULT; #endif } @@ -2417,6 +2417,11 @@ sched_affinity(struct thread *td) ts = td->td_sched; if (THREAD_CAN_SCHED(td, ts->ts_cpu)) return; + if (TD_ON_RUNQ(td)) { + sched_rem(td); + sched_add(td, SRQ_BORING); + return; + } if (!TD_IS_RUNNING(td)) return; td->td_flags |= TDF_NEEDRESCHED;