From owner-freebsd-hackers@freebsd.org Fri Aug 7 20:53:52 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 CA0A69B6B9E for ; Fri, 7 Aug 2015 20:53:52 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) (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 70B5A1915 for ; Fri, 7 Aug 2015 20:53:52 +0000 (UTC) (envelope-from oliver.pinter@hardenedbsd.org) Received: by wibxm9 with SMTP id xm9so75111684wib.0 for ; Fri, 07 Aug 2015 13:53:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Bh1wPDUftZiAkoZyqDVQwKTuwWGn9S5P7+jUQJRFW0o=; b=acMkP/pYsaNZbhuKil/zoCZWZpjht//SjJHZQXinhbvu4R7ZWXd184t4f5w/IXA6Bw wl+V00arZK4ahiomq2mA930Xfs7J6HT15ASeozHVQjAP4kTK1DdjpE8smOjL1BNkCgR4 WJGCZUoXJ9U7/CZ/M5Xkllz5l5iuhVKC138t/Y9QyjnQSu/kE4Cs1h7rjjOQMu5uiGwb +Tnlf1gYyhWpz6sQFAvbk6VaHAWMy6Ta4zEO1aoTy/B48oLeWOU1QZdtnu/uNJL19cFS uIA5JTuYWkF/KLyyGavST30+BJRuqSSQZ2genB/jMUzv5oujOntnuMJIFfAWYpBpPtY5 t8ZQ== X-Gm-Message-State: ALoCoQlg/wt62cx1d4aUrDxyoh0Oe1PGx8OxXOWm5Bp/JSgKtWzMpFRpQjBp5mx6Tu3gXYs+j7IP MIME-Version: 1.0 X-Received: by 10.180.39.65 with SMTP id n1mr165332wik.59.1438980825102; Fri, 07 Aug 2015 13:53:45 -0700 (PDT) Received: by 10.194.73.6 with HTTP; Fri, 7 Aug 2015 13:53:45 -0700 (PDT) In-Reply-To: <2324251.0KSjbGaFFg@ralph.baldwin.cx> References: <55C1AF5A.1080601@selasky.org> <2324251.0KSjbGaFFg@ralph.baldwin.cx> Date: Fri, 7 Aug 2015 22:53:45 +0200 Message-ID: Subject: Re: When and when not to use CTLFLAG_MPSAFE with the SYSCTL macros..? From: Oliver Pinter To: John Baldwin Cc: freebsd-hackers@freebsd.org, Hans Petter Selasky , Garrett Cooper 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: Fri, 07 Aug 2015 20:53:52 -0000 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 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= "