From owner-freebsd-hackers@freebsd.org Fri Aug 7 20:32:38 2015 Return-Path: Delivered-To: freebsd-hackers@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 31B5F9B67BD for ; Fri, 7 Aug 2015 20:32:38 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0FCB4CDA for ; Fri, 7 Aug 2015 20:32:38 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from ralph.baldwin.cx (75-48-78-19.lightspeed.cncrca.sbcglobal.net [75.48.78.19]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 0A81EB98E; Fri, 7 Aug 2015 16:32:37 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Cc: Hans Petter Selasky , Garrett Cooper Subject: Re: When and when not to use CTLFLAG_MPSAFE with the SYSCTL macros..? Date: Fri, 07 Aug 2015 12:41:55 -0700 Message-ID: <2324251.0KSjbGaFFg@ralph.baldwin.cx> User-Agent: KMail/4.14.3 (FreeBSD/10.2-PRERELEASE; KDE/4.14.3; amd64; ; ) In-Reply-To: <55C1AF5A.1080601@selasky.org> References: <55C1AF5A.1080601@selasky.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 07 Aug 2015 16:32:37 -0400 (EDT) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Aug 2015 20:32:38 -0000 On Wednesday, August 05, 2015 08:38:18 AM Hans Petter Selasky wrote: > On 08/05/15 00:47, Garrett Cooper wrote: > > Hi, > > =09I=E2=80=99ve been trying to figure out (because sysctl(9) is lac= king) when to use CTLFLAG_MPSAFE. Is it strictly when dealing with SYSC= TL_PROC handlers that do proper locking of shared resources, or are the= re other nuances that need to be handled? > > =09I=E2=80=99m also asking because SYSCTL_UQUAD, for instance, expl= icitly uses CTLFLAG_MPSAFE in the handler, which is a bit confusing. > > Thanks! > > -NGie >=20 > Hi, >=20 > This flag decides if you have Giant automatically locked or not aroun= d=20 > the sysctl proc. Your functions should have their own locks basically= . I=20 > believe it is a leftover from many years ago, when the FreeBSD kernel= =20 > was going multi threaded. It's only about 2-3 years old actually. To answer your question Garrett: yes it is really only for SYSCTL_PROC handlers. The existing "simple" handlers like sysctl_handle_int are as atomic as they can be regardless of Giant, so they don't need Giant.= If you have a variable that you want to control access to via locking y= ou need to use a custom handler, even if it is a simple int. --=20 John Baldwin