From owner-svn-src-head@freebsd.org Fri Feb 17 09:09:12 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 92911CE163A; Fri, 17 Feb 2017 09:09:12 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (turbocat.net [IPv6:2a01:4f8:c17:6c4b::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2B5891576; Fri, 17 Feb 2017 09:09:12 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2016.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 5A3B31FE025; Fri, 17 Feb 2017 10:08:52 +0100 (CET) Subject: Re: svn commit: r313859 - in head/sys: kern sys To: Mateusz Guzik , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201702170645.v1H6j4l6060548@repo.freebsd.org> From: Hans Petter Selasky Message-ID: <2c01557a-3412-8b46-ef4d-77214566b74a@selasky.org> Date: Fri, 17 Feb 2017 10:08:27 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <201702170645.v1H6j4l6060548@repo.freebsd.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Feb 2017 09:09:12 -0000 On 02/17/17 07:45, Mateusz Guzik wrote: > Author: mjg > Date: Fri Feb 17 06:45:04 2017 > New Revision: 313859 > URL: https://svnweb.freebsd.org/changeset/base/313859 > > Log: > Introduce SCHEDULER_STOPPED_TD for use when the thread pointer was already read > > Sprinkle in few places. > > Modified: > head/sys/kern/kern_condvar.c > head/sys/kern/kern_synch.c > head/sys/sys/systm.h > > Modified: head/sys/kern/kern_condvar.c > ============================================================================== > --- head/sys/kern/kern_condvar.c Fri Feb 17 06:22:05 2017 (r313858) > +++ head/sys/kern/kern_condvar.c Fri Feb 17 06:45:04 2017 (r313859) > @@ -122,7 +122,7 @@ _cv_wait(struct cv *cvp, struct lock_obj > "Waiting on \"%s\"", cvp->cv_description); > class = LOCK_CLASS(lock); > > - if (SCHEDULER_STOPPED()) > + if (SCHEDULER_STOPPED_TD(td)) > return; > > sleepq_lock(cvp); > @@ -176,7 +176,7 @@ _cv_wait_unlock(struct cv *cvp, struct l > ("cv_wait_unlock cannot be used with Giant")); > class = LOCK_CLASS(lock); > > - if (SCHEDULER_STOPPED()) { > + if (SCHEDULER_STOPPED_TD(td)) { > class->lc_unlock(lock); > return; > } > @@ -227,7 +227,7 @@ _cv_wait_sig(struct cv *cvp, struct lock > "Waiting on \"%s\"", cvp->cv_description); > class = LOCK_CLASS(lock); > > - if (SCHEDULER_STOPPED()) > + if (SCHEDULER_STOPPED_TD(td)) > return (0); > > sleepq_lock(cvp); > @@ -287,7 +287,7 @@ _cv_timedwait_sbt(struct cv *cvp, struct > "Waiting on \"%s\"", cvp->cv_description); > class = LOCK_CLASS(lock); > > - if (SCHEDULER_STOPPED()) > + if (SCHEDULER_STOPPED_TD(td)) > return (0); > > sleepq_lock(cvp); > @@ -349,7 +349,7 @@ _cv_timedwait_sig_sbt(struct cv *cvp, st > "Waiting on \"%s\"", cvp->cv_description); > class = LOCK_CLASS(lock); > > - if (SCHEDULER_STOPPED()) > + if (SCHEDULER_STOPPED_TD(td)) > return (0); > > sleepq_lock(cvp); > > Modified: head/sys/kern/kern_synch.c > ============================================================================== > --- head/sys/kern/kern_synch.c Fri Feb 17 06:22:05 2017 (r313858) > +++ head/sys/kern/kern_synch.c Fri Feb 17 06:45:04 2017 (r313859) > @@ -162,7 +162,7 @@ _sleep(void *ident, struct lock_object * > else > class = NULL; > > - if (SCHEDULER_STOPPED()) { > + if (SCHEDULER_STOPPED_TD(td)) { > if (lock != NULL && priority & PDROP) > class->lc_unlock(lock); > return (0); > @@ -250,7 +250,7 @@ msleep_spin_sbt(void *ident, struct mtx > KASSERT(ident != NULL, ("msleep_spin_sbt: NULL ident")); > KASSERT(TD_IS_RUNNING(td), ("msleep_spin_sbt: curthread not running")); > > - if (SCHEDULER_STOPPED()) > + if (SCHEDULER_STOPPED_TD(td)) > return (0); > > sleepq_lock(ident); > @@ -411,7 +411,7 @@ mi_switch(int flags, struct thread *newt > */ > if (kdb_active) > kdb_switch(); > - if (SCHEDULER_STOPPED()) > + if (SCHEDULER_STOPPED_TD(td)) > return; > if (flags & SW_VOL) { > td->td_ru.ru_nvcsw++; > > Modified: head/sys/sys/systm.h > ============================================================================== > --- head/sys/sys/systm.h Fri Feb 17 06:22:05 2017 (r313858) > +++ head/sys/sys/systm.h Fri Feb 17 06:45:04 2017 (r313859) > @@ -128,7 +128,11 @@ void kassert_panic(const char *fmt, ...) > * Otherwise, the kernel will deadlock since the scheduler isn't > * going to run the thread that holds any lock we need. > */ > -#define SCHEDULER_STOPPED() __predict_false(curthread->td_stopsched) > +#define SCHEDULER_STOPPED_TD(td) ({ \ > + MPASS((td) == curthread); \ > + __predict_false((td)->td_stopsched); \ > +}) > +#define SCHEDULER_STOPPED() SCHEDULER_STOPPED_TD(curthread) > > /* > * Align variables. > > Hi, Do these checks also cover panics? Or only shutdown? Should you also add a check for kdb_active // panicstr ? Then I could factor out some checks I've sprinkled in the USB code. --HPS