svn commit: r227439 - stable/8/sys/kern
Ryan Stone
rstone at FreeBSD.org
Fri Nov 11 02:13:35 UTC 2011
Author: rstone
Date: Fri Nov 11 02:13:35 2011
New Revision: 227439
URL: http://svn.freebsd.org/changeset/base/227439
Log:
MFC 221081:
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.
Modified:
stable/8/sys/kern/sched_4bsd.c
Directory Properties:
stable/8/sys/ (props changed)
stable/8/sys/amd64/include/xen/ (props changed)
stable/8/sys/cddl/contrib/opensolaris/ (props changed)
stable/8/sys/contrib/dev/acpica/ (props changed)
stable/8/sys/contrib/pf/ (props changed)
Modified: stable/8/sys/kern/sched_4bsd.c
==============================================================================
--- stable/8/sys/kern/sched_4bsd.c Fri Nov 11 02:10:24 2011 (r227438)
+++ stable/8/sys/kern/sched_4bsd.c Fri Nov 11 02:13:35 2011 (r227439)
@@ -1241,25 +1241,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-stable-8
mailing list