From owner-svn-src-all@FreeBSD.ORG Tue Mar 25 14:03:22 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3903EF96 for ; Tue, 25 Mar 2014 14:03:22 +0000 (UTC) Received: from mail-ob0-f179.google.com (mail-ob0-f179.google.com [209.85.214.179]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id F2978F48 for ; Tue, 25 Mar 2014 14:03:21 +0000 (UTC) Received: by mail-ob0-f179.google.com with SMTP id va2so590796obc.24 for ; Tue, 25 Mar 2014 07:03:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:content-type:mime-version:subject:from :in-reply-to:date:cc:content-transfer-encoding:message-id:references :to; bh=T94UrMpUxnPhFiQr2B+0LAxP53UJV7hsH5CSClDOW0s=; b=Zan7SREUZ2c0YGJMU2/MLHXA2unxbv5QuyrvO/ODN+qo19kmA9fVRjVEXpkl3CgBW1 u00wDOcHImnp1EeE4OtkDA/4uxy5EL3iJk3D5I16m35+uINu5AlVMiIxMUtIM1af2nDs rhyeQY3XZQB2I5bWlnKwbJfGsOfOgP9+4lenMOpQRXKlHj4qW2XV04kX+ChWEjzrpPPf /233Ob654tlAMBix091ESsvb0WuUh+GYFwIUEQiSTIROlHW1pCqs2nsna/7w9csj//fm 3p6t0TjvBhIbwH6egYssY35BNY+Sh6YRdbvj6Cc70Lm88vN/XgyVQgqVL1yGLxsdrSzL bdEg== X-Gm-Message-State: ALoCoQl05zJuELKXudbP61sU6huPexZ0WwTyj7Gc9cKLL5/4FbWUBUnSmoVPKypzI2hUwOocSUdv X-Received: by 10.60.33.229 with SMTP id u5mr748299oei.85.1395756195681; Tue, 25 Mar 2014 07:03:15 -0700 (PDT) Received: from netflix-mac.bsdimp.com (50-78-194-198-static.hfc.comcastbusiness.net. [50.78.194.198]) by mx.google.com with ESMTPSA id ii8sm30538479obb.11.2014.03.25.07.03.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Mar 2014 07:03:15 -0700 (PDT) Sender: Warner Losh Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: svn commit: r263704 - head/sys/kern From: Warner Losh In-Reply-To: <201403250328.s2P3Swsl054558@svn.freebsd.org> Date: Tue, 25 Mar 2014 08:03:13 -0600 Content-Transfer-Encoding: quoted-printable Message-Id: References: <201403250328.s2P3Swsl054558@svn.freebsd.org> To: Mateusz Guzik X-Mailer: Apple Mail (2.1874) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Mar 2014 14:03:22 -0000 On Mar 24, 2014, at 9:28 PM, Mateusz Guzik wrote: > Author: mjg > Date: Tue Mar 25 03:28:58 2014 > New Revision: 263704 > URL: http://svnweb.freebsd.org/changeset/base/263704 >=20 > Log: > Make /dev/devctl mpsafe. >=20 > MFC after: 1 week >=20 > Modified: > head/sys/kern/subr_bus.c >=20 > Modified: head/sys/kern/subr_bus.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=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D > --- head/sys/kern/subr_bus.c Tue Mar 25 03:25:30 2014 = (r263703) > +++ head/sys/kern/subr_bus.c Tue Mar 25 03:28:58 2014 = (r263704) > @@ -358,15 +358,16 @@ device_sysctl_fini(device_t dev) > /* Deprecated way to adjust queue length */ > static int sysctl_devctl_disable(SYSCTL_HANDLER_ARGS); > /* XXX Need to support old-style tunable hw.bus.devctl_disable" */ > -SYSCTL_PROC(_hw_bus, OID_AUTO, devctl_disable, CTLTYPE_INT | = CTLFLAG_RW, NULL, > - 0, sysctl_devctl_disable, "I", "devctl disable -- deprecated"); > +SYSCTL_PROC(_hw_bus, OID_AUTO, devctl_disable, CTLTYPE_INT | = CTLFLAG_RW | > + CTLFLAG_MPSAFE, NULL, 0, sysctl_devctl_disable, "I", > + "devctl disable -- deprecated=94); This can likely be deleted now... > #define DEVCTL_DEFAULT_QUEUE_LEN 1000 > static int sysctl_devctl_queue(SYSCTL_HANDLER_ARGS); > static int devctl_queue_length =3D DEVCTL_DEFAULT_QUEUE_LEN; > TUNABLE_INT("hw.bus.devctl_queue", &devctl_queue_length); > -SYSCTL_PROC(_hw_bus, OID_AUTO, devctl_queue, CTLTYPE_INT | = CTLFLAG_RW, NULL, > - 0, sysctl_devctl_queue, "I", "devctl queue length"); > +SYSCTL_PROC(_hw_bus, OID_AUTO, devctl_queue, CTLTYPE_INT | CTLFLAG_RW = | > + CTLFLAG_MPSAFE, NULL, 0, sysctl_devctl_queue, "I", "devctl queue = length"); >=20 > static d_open_t devopen; > static d_close_t devclose; > @@ -376,7 +377,6 @@ static d_poll_t devpoll; >=20 > static struct cdevsw dev_cdevsw =3D { > .d_version =3D D_VERSION, > - .d_flags =3D D_NEEDGIANT, > .d_open =3D devopen, > .d_close =3D devclose, > .d_read =3D devread, > @@ -420,23 +420,31 @@ devinit(void) > static int > devopen(struct cdev *dev, int oflags, int devtype, struct thread *td) > { > + > if (devsoftc.inuse) > return (EBUSY); Why not delete these two lines? Since this isn=92t a performance = critical part of the code, it is clearer and safer to just test inuse inside the locked section. > + mtx_lock(&devsoftc.mtx); > + if (devsoftc.inuse) { > + mtx_unlock(&devsoftc.mtx); > + return (EBUSY); > + } > /* move to init */ > devsoftc.inuse =3D 1; > devsoftc.nonblock =3D 0; > devsoftc.async_proc =3D NULL; > + mtx_unlock(&devsoftc.mtx); > return (0); > } >=20 > static int > devclose(struct cdev *dev, int fflag, int devtype, struct thread *td) > { > - devsoftc.inuse =3D 0; > + > mtx_lock(&devsoftc.mtx); > + devsoftc.inuse =3D 0; > + devsoftc.async_proc =3D NULL; > cv_broadcast(&devsoftc.cv); > mtx_unlock(&devsoftc.mtx); > - devsoftc.async_proc =3D NULL; > return (0); > }