From owner-freebsd-arch@FreeBSD.ORG Fri Dec 17 21:00:08 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 128D116A4CE for ; Fri, 17 Dec 2004 21:00:08 +0000 (GMT) Received: from mail1.speakeasy.net (mail1.speakeasy.net [216.254.0.201]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9516B43D5A for ; Fri, 17 Dec 2004 21:00:07 +0000 (GMT) (envelope-from jmg@hydrogen.funkthat.com) Received: (qmail 9335 invoked from network); 17 Dec 2004 21:00:07 -0000 Received: from gate.funkthat.com (HELO hydrogen.funkthat.com) ([69.17.45.168]) (envelope-sender ) by mail1.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 17 Dec 2004 21:00:06 -0000 Received: from hydrogen.funkthat.com (qxabuf@localhost.funkthat.com [127.0.0.1])iBHL06GH051416; Fri, 17 Dec 2004 13:00:06 -0800 (PST) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.12.10/8.12.10/Submit) id iBHL05OD051414; Fri, 17 Dec 2004 13:00:05 -0800 (PST) Date: Fri, 17 Dec 2004 13:00:05 -0800 From: John-Mark Gurney To: Max Laier Message-ID: <20041217210004.GZ19624@funkthat.com> Mail-Followup-To: Max Laier , freebsd-current@freebsd.org, Suleiman Souhlal , freebsd-arch@freebsd.org References: <94AE3F5A-4CD6-11D9-8BD6-000A95C4D7BC@FreeBSD.org> <200412130913.20215.max@love2party.net> <200412131232.55051.max@love2party.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200412131232.55051.max@love2party.net> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD 4.2-RELEASE i386 X-PGP-Fingerprint: B7 EC EF F8 AE ED A7 31 96 7A 22 B3 D8 56 36 F4 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html cc: freebsd-current@freebsd.org cc: Suleiman Souhlal cc: freebsd-arch@freebsd.org Subject: Re: sysctl locking X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: John-Mark Gurney List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Dec 2004 21:00:08 -0000 Max Laier wrote this message on Mon, Dec 13, 2004 at 12:32 +0100: > If we come to the conclusion that it is required to protect these values > better, I suggest the following: > > 1) Extend sysctl_add_oid() to accept an additional mutex argument. > 2) Extend the simple sysctl handler to use this mutex to protect the actual > write(?read?). We must not hold the mutex during the useland copy in/out so > we must move to temporary storage. > 3) To maintain the current API and behavior we use &Giant as the default > fallback argument. This might need some extension for complex handler (i.e. > no mutex given -> acquire Giant before calling the complex handler). > > What do people think of this? Does it make any sense? Should we be concerned > at all? Does the extension make sense? Comments? If all one is doing is a single read or a single write, then a mutex is not needed... Since you are not syncronizing with something else or doing a write based on a read (i.e atomic increment, etc), the read/write could happen at any order.. Only if the entire value can not be written atomicly (like 64 bit ints of 486's, Pentiums have an 8 byte xchng op) would a mutex be helpful... In the kqueue case, there is a function knlist_empty that originally would obtain the lock, read the value and then unlock.. This was pointless since any state returned by the function would be stale and any decision made on it would be bogus... It was changed to require that the calling function hold the lock so that the state was consistent with the subsequent decission... If a sysctl needs that level of protection, it seems like they need to be writing their own custom handler to handle the required interactions.. -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."