From owner-freebsd-current@FreeBSD.ORG Wed Apr 20 22:02:44 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A8262106566C; Wed, 20 Apr 2011 22:02:44 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-ew0-f54.google.com (mail-ew0-f54.google.com [209.85.215.54]) by mx1.freebsd.org (Postfix) with ESMTP id DF2608FC0A; Wed, 20 Apr 2011 22:02:43 +0000 (UTC) Received: by ewy1 with SMTP id 1so460378ewy.13 for ; Wed, 20 Apr 2011 15:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Wy0R0Y+iXYmlXmTQ+imBBkMYukHvTh1tI84PXEa1nyc=; b=GPGB1iWRJyFPn6ANSlkUVtnZhtRp2KE54BwUCSgOdVegK5D5h7z4cdxK2Ep9shTncP ZOmj8Q50jOkVpfLsrMq6tuvcYBV71GCOxhYy4Bue7/7GYVFztIwuVXe/d9o6pkj1Mnpn xlUOZnLUMZlyG/u0AwzBxpXgwqSE1wxQUJkww= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ZnGUe+lFLB6yV9+swukd/hG3dOnXQqnlyLVpHnEvpudDf0sAozh0wKOIxJqYx1iJDp rz9WkVKKuScJaHNkBQQaQk9P1nN8kiR2lKNWZ4EVOYawzqIZJ5tZRuPtEc5kBPtWdA6B GxDiB6dGfXG6vXJW3gRN2mbTQwz78vs5XD71w= MIME-Version: 1.0 Received: by 10.213.19.17 with SMTP id y17mr3322145eba.38.1303336962854; Wed, 20 Apr 2011 15:02:42 -0700 (PDT) Received: by 10.213.4.209 with HTTP; Wed, 20 Apr 2011 15:02:42 -0700 (PDT) In-Reply-To: <201104061429.50185.jhb@freebsd.org> References: <201104060836.56542.jhb@freebsd.org> <201104061429.50185.jhb@freebsd.org> Date: Wed, 20 Apr 2011 18:02:42 -0400 Message-ID: From: Ryan Stone To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-current@freebsd.org, Ed Maste Subject: Re: sched_4bsd startup crash trying to run a bound thread on an AP that hasn't started X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Apr 2011 22:02:44 -0000 On Wed, Apr 6, 2011 at 2:29 PM, John Baldwin wrote: > I guess one other option would be something like this: > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (smp_started && (td->td_pinned !=3D 0 |= | td->td_flags & TDF_BOUND || > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ts->ts_flags & TSF_AFFINITY)) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (td->td_pinned !=3D 0) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cpu =3D td= ->td_lastcpu; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else if (td->td_flags & TD= F_BOUND) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Find CP= U from bound runq. */ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0KASSERT(..= .); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cpu =3D ts= ->ts_runq - &runq_pcpu[0]; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Find a = valid CPU for our cpuset. */ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0cpu =3D sc= hed_pickcpu(td); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ts->ts_runq =3D &runq_pcpu= [cpu]; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0single_cpu =3D 1; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0CTR3(KTR_RUNQ, ...); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} else { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Global runq case. */ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0} > > This also avoids duplicating some common code to all the single_cpu cases= . > > -- > John Baldwin > I went with this option. Does this look right? Index: sys/kern/sched_4bsd.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- sys/kern/sched_4bsd.c (revision 220603) +++ sys/kern/sched_4bsd.c (working copy) @@ -1246,30 +1246,28 @@ } TD_SET_RUNQ(td); - if (td->td_pinned !=3D 0) { - cpu =3D td->td_lastcpu; + /* + * If SMP is not started, don't obey any requested CPU pinning as t= hat + * CPU has either not yet started or it is curcpu. Trying to run a + * thread on a CPU that has not yet started will panic the system. + */ + if (smp_started && (td->td_pinned !=3D 0 || td->td_flags & TDF_BOUN= D || + ts->ts_flags & TSF_AFFINITY)) { + if (td->td_pinned !=3D 0) + cpu =3D 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 =3D ts->ts_runq - &runq_pcpu[0]; + } else + /* Find a valid CPU for our cpuset */ + cpu =3D sched_pickcpu(td); ts->ts_runq =3D &runq_pcpu[cpu]; single_cpu =3D 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 =3D ts->ts_runq - &runq_pcpu[0]; - single_cpu =3D 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 =3D sched_pickcpu(td); - ts->ts_runq =3D &runq_pcpu[cpu]; - single_cpu =3D 1; - CTR3(KTR_RUNQ, - "sched_add: Put td_sched:%p(td:%p) on cpu%d runq", ts, = td, - cpu); } else { CTR2(KTR_RUNQ, "sched_add: adding td_sched:%p (td:%p) to gbl runq", ts= ,