Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 07 Aug 2015 12:41:55 -0700
From:      John Baldwin <jhb@freebsd.org>
To:        freebsd-hackers@freebsd.org
Cc:        Hans Petter Selasky <hps@selasky.org>, Garrett Cooper <yaneurabeya@gmail.com>
Subject:   Re: When and when not to use CTLFLAG_MPSAFE with the SYSCTL macros..?
Message-ID:  <2324251.0KSjbGaFFg@ralph.baldwin.cx>
In-Reply-To: <55C1AF5A.1080601@selasky.org>
References:  <F4A56F9C-058B-4D91-B75D-92DEC16E8B2E@gmail.com> <55C1AF5A.1080601@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2324251.0KSjbGaFFg>