From owner-freebsd-hackers@freebsd.org Sat Aug 8 05:44:22 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 0F2EC9B6DEE for ; Sat, 8 Aug 2015 05:44:22 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: from mail-qk0-x22a.google.com (mail-qk0-x22a.google.com [IPv6:2607:f8b0:400d:c09::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BE0A5D73; Sat, 8 Aug 2015 05:44:21 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: by qkdg63 with SMTP id g63so43836066qkd.0; Fri, 07 Aug 2015 22:44:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=DMJ3JwEvJckp1YCW3GxRK0SYITgiz2suhNprDBr2jqU=; b=btzSSRzSxzq/vJ+Fm6493IklIQz5/3+kKJC0JZ6LzEtIrdmDu8Kc2mqDYJa15uq/Hz JTyaDICEHIh2RJovktNQJ16nY/+Nz4UHGFOhY2qAFeEoONSs9dGImYCLTqayIE0xN15N eTxNrgq+U30cyM9P/Le2WYIHM01WEzaMz5mTYuzB6Y6JvhPjJQW7FFI2tCurcUv8YeuM VfIiXIMwDTnrEs0OYfWsaTNeyReHQyYA9ldw9uj/5S65alUvZk8894g7VXe3KyHYzNvE upV4fjOKGlIiiTFeX4odYZY6uGYxVzlI8p2kc18qi62LjNC1Xs5M6FYmvSw33Ba4W99o eGEQ== MIME-Version: 1.0 X-Received: by 10.55.53.193 with SMTP id c184mr19589041qka.62.1439012660826; Fri, 07 Aug 2015 22:44:20 -0700 (PDT) Received: by 10.140.98.73 with HTTP; Fri, 7 Aug 2015 22:44:20 -0700 (PDT) In-Reply-To: References: <55C1AF5A.1080601@selasky.org> <2324251.0KSjbGaFFg@ralph.baldwin.cx> Date: Fri, 7 Aug 2015 22:44:20 -0700 Message-ID: Subject: Re: When and when not to use CTLFLAG_MPSAFE with the SYSCTL macros..? From: NGie Cooper To: Oliver Pinter Cc: John Baldwin , "freebsd-hackers@freebsd.org" , Hans Petter Selasky Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: Sat, 08 Aug 2015 05:44:22 -0000 On Fri, Aug 7, 2015 at 1:53 PM, Oliver Pinter wrote: > On 8/7/15, John Baldwin 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