Date: Fri, 7 Aug 2015 22:44:20 -0700 From: NGie Cooper <yaneurabeya@gmail.com> To: Oliver Pinter <oliver.pinter@hardenedbsd.org> Cc: John Baldwin <jhb@freebsd.org>, "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>, Hans Petter Selasky <hps@selasky.org> Subject: Re: When and when not to use CTLFLAG_MPSAFE with the SYSCTL macros..? Message-ID: <CAGHfRMC0kf-TN-Df_fdPUM6%2BSVoCvEgssoh_nEj4w%2BJrkTYuFQ@mail.gmail.com> In-Reply-To: <CAPQ4fft5ad9=veFnp1ZycAtK1agQJUK1qQx-H_gCENSDCBFb%2BQ@mail.gmail.com> References: <F4A56F9C-058B-4D91-B75D-92DEC16E8B2E@gmail.com> <55C1AF5A.1080601@selasky.org> <2324251.0KSjbGaFFg@ralph.baldwin.cx> <CAPQ4fft5ad9=veFnp1ZycAtK1agQJUK1qQx-H_gCENSDCBFb%2BQ@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Aug 7, 2015 at 1:53 PM, Oliver Pinter <oliver.pinter@hardenedbsd.org> wrote: > 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 lacki= ng) when to >>> > use CTLFLAG_MPSAFE. Is it strictly when dealing with SYSCTL_PROC >>> > handlers that do proper locking of shared resources, or are there oth= er >>> > nuances that need to be handled? >>> > I=E2=80=99m also asking because SYSCTL_UQUAD, for instance, explic= itly 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 yo= u >> need to use a custom handler, even if it is a simple int. Thank you, all -- I see it now. -NGie
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGHfRMC0kf-TN-Df_fdPUM6%2BSVoCvEgssoh_nEj4w%2BJrkTYuFQ>