Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Aug 2015 22:53:45 +0200
From:      Oliver Pinter <oliver.pinter@hardenedbsd.org>
To:        John Baldwin <jhb@freebsd.org>
Cc:        freebsd-hackers@freebsd.org, 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:  <CAPQ4fft5ad9=veFnp1ZycAtK1agQJUK1qQx-H_gCENSDCBFb%2BQ@mail.gmail.com>
In-Reply-To: <2324251.0KSjbGaFFg@ralph.baldwin.cx>
References:  <F4A56F9C-058B-4D91-B75D-92DEC16E8B2E@gmail.com> <55C1AF5A.1080601@selasky.org> <2324251.0KSjbGaFFg@ralph.baldwin.cx>

next in thread | previous in thread | raw e-mail | index | archive | help
On 8/7/15, John Baldwin <jhb@freebsd.org> wrote:
> On Wednesday, August 05, 2015 08:38:18 AM Hans Petter Selasky wrote:
>> On 08/05/15 00:47, Garrett Cooper wrote:
>> > Hi,
>> > 	I=E2=80=99ve been trying to figure out (because sysctl(9) is lacking)=
 when to
>> > use CTLFLAG_MPSAFE. Is it strictly when dealing with SYSCTL_PROC
>> > handlers that do proper locking of shared resources, or are there othe=
r
>> > nuances that need to be handled?
>> > 	I=E2=80=99m also asking because SYSCTL_UQUAD, for instance, explicitl=
y uses
>> > CTLFLAG_MPSAFE in the handler, which is a bit confusing.
>> > Thanks!
>> > -NGie
>>
>> Hi,
>>
>> This flag decides if you have Giant automatically locked or not around
>> the sysctl proc. Your functions should have their own locks basically. I
>> believe it is a leftover from many years ago, when the FreeBSD kernel
>> 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.

For the basic types the CTLFLAG_MPSAFE flag are always added:
https://github.com/freebsd/freebsd/blob/master/sys/sys/sysctl.h#L322 .

>
> If you have a variable that you want to control access to via locking you
> need to use a custom handler, even if it is a simple int.
>
> --
> John Baldwin
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org=
"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPQ4fft5ad9=veFnp1ZycAtK1agQJUK1qQx-H_gCENSDCBFb%2BQ>