From owner-svn-src-head@FreeBSD.ORG Tue Mar 25 14:03:16 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D3DE1EAC for ; Tue, 25 Mar 2014 14:03:16 +0000 (UTC) Received: from mail-ob0-f181.google.com (mail-ob0-f181.google.com [209.85.214.181]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 8EDCEF45 for ; Tue, 25 Mar 2014 14:03:16 +0000 (UTC) Received: by mail-ob0-f181.google.com with SMTP id wp4so596060obc.12 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=DzUokKshTBjgjdXflF+fdx4O87zRAkJGBUx4vTfMVlHBlpH2IUiMWmm+qtEbWlm6pI +u6rf0S7VRRsssx4gRId2VtWSFHlBGMWH85Icv3vovGiFSwOpWmY2veKm+i01vL7uPOh ouW/9K86eArtbiBLL5eG9aYhyVKI2eIZwUyWHUIBqj2wQFCGI2lP8Cn6dxZxp0OKheu/ zcr66Nhyc7mU5BDSExo+DpnX5v5BLBJ4cMywoXCAJvmasJv2YNJzFH9E1Ij0N45w4jlC VKZdXnNIciQO/PteH0g2LYtrUPj7GyHL5V4H5iVSDGFm0//Dc9297HSZiFHzlFcxy6lo XYEA== X-Gm-Message-State: ALoCoQl8w67MdrBZx+Y7+5wRZNaagyC/yu0dzg3hk9HOH9AnL09mLzLvnEgw+b6dpPq2UeFLJWZ4 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-head@freebsd.org X-Mailman-Version: 2.1.17 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: Tue, 25 Mar 2014 14:03:16 -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); > }