svn commit: r221081 - head/sys/kern

Ryan Stone rstone at FreeBSD.org
Tue Apr 26 20:34:31 UTC 2011


Author: rstone
Date: Tue Apr 26 20:34:30 2011
New Revision: 221081
URL: http://svn.freebsd.org/changeset/base/221081

Log:
  If the 4BSD scheduler tries to schedule a thread that has been pinned or
  bound to an AP before SMP has started, the system will panic when we try
  to touch per-CPU state for that AP because that state has not been
  initialized yet.  Fix this in the same way as ULE: place all threads in
  the global run queue before SMP has started.
  
  Reviewed by:	jhb
  MFC after:	1 month

Modified:
  head/sys/kern/sched_4bsd.c

Modified: head/sys/kern/sched_4bsd.c
==============================================================================
--- head/sys/kern/sched_4bsd.c	Tue Apr 26 20:25:16 2011	(r221080)
+++ head/sys/kern/sched_4bsd.c	Tue Apr 26 20:34:30 2011	(r221081)
@@ -1246,25 +1246,27 @@ sched_add(struct thread *td, int flags)
 	}
 	TD_SET_RUNQ(td);
 
-	if (td->td_pinned != 0) {
-		cpu = td->td_lastcpu;
-		ts->ts_runq = &runq_pcpu[cpu];
-		single_cpu = 1;
-		CTR3(KTR_RUNQ,
-		    "sched_add: Put td_sched:%p(td:%p) on cpu%d runq", ts, td,
-		    cpu);
-	} else if (td->td_flags & TDF_BOUND) {
-		/* Find CPU from bound runq. */
-		KASSERT(SKE_RUNQ_PCPU(ts),
-		    ("sched_add: bound td_sched not on cpu runq"));
-		cpu = ts->ts_runq - &runq_pcpu[0];
-		single_cpu = 1;
-		CTR3(KTR_RUNQ,
-		    "sched_add: Put td_sched:%p(td:%p) on cpu%d runq", ts, td,
-		    cpu);
-	} else if (ts->ts_flags & TSF_AFFINITY) {
-		/* Find a valid CPU for our cpuset */
-		cpu = sched_pickcpu(td);
+	/*
+	 * If SMP is started and the thread is pinned or otherwise limited to
+	 * a specific set of CPUs, queue the thread to a per-CPU run queue.
+	 * Otherwise, queue the thread to the global run queue.
+	 *
+	 * If SMP has not yet been started we must use the global run queue
+	 * as per-CPU state may not be initialized yet and we may crash if we
+	 * try to access the per-CPU run queues.
+	 */
+	if (smp_started && (td->td_pinned != 0 || td->td_flags & TDF_BOUND ||
+	    ts->ts_flags & TSF_AFFINITY)) {
+		if (td->td_pinned != 0)
+			cpu = td->td_lastcpu;
+		else if (td->td_flags & TDF_BOUND) {
+			/* Find CPU from bound runq. */
+			KASSERT(SKE_RUNQ_PCPU(ts),
+			    ("sched_add: bound td_sched not on cpu runq"));
+			cpu = ts->ts_runq - &runq_pcpu[0];
+		} else
+			/* Find a valid CPU for our cpuset */
+			cpu = sched_pickcpu(td);
 		ts->ts_runq = &runq_pcpu[cpu];
 		single_cpu = 1;
 		CTR3(KTR_RUNQ,


More information about the svn-src-head mailing list