From owner-cvs-all Fri Aug 31 0: 7:37 2001 Delivered-To: cvs-all@freebsd.org Received: from mail.speakeasy.net (mail6.speakeasy.net [216.254.0.206]) by hub.freebsd.org (Postfix) with ESMTP id 9824A37B405 for ; Fri, 31 Aug 2001 00:07:25 -0700 (PDT) (envelope-from jhb@FreeBSD.org) Received: (qmail 51825 invoked from network); 31 Aug 2001 06:57:38 -0000 Received: from unknown (HELO laptop.baldwin.cx) ([64.81.54.73]) (envelope-sender ) by mail6.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 31 Aug 2001 06:57:38 -0000 Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: Date: Thu, 30 Aug 2001 23:57:43 -0700 (PDT) From: John Baldwin To: Mike Silbersack Subject: Re: RE: cvs commit: src/sys/kern init_sysent.c sysv_msg.c sysv_s Cc: cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG, Matt Dillon Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 31-Aug-01 Mike Silbersack wrote: > > On Thu, 30 Aug 2001, Matt Dillon wrote: > >> As long as you aren't holding any other mutexes when you aquire Giant >> and the stuff outside of Giant is MP-SAFE, and there are no atomicy >> constraints between the Giant-locked sections making up the syscall, >> and you are holding a reference on structural objects you hold through a >> loss of Giant (and you are holding references on objects held if you >> block while holding Giant)... then you can obtain and drop Giant >> all you want. > > Ok, good. I just wanted to make sure there weren't any unstated rules > with regard to this. > > Also, just for clarification, Giant can be grabbed recursively, correct? > Our "SMP kernel synchronization rules" pages seems to imply so, but isn't > too clear. > > (http://people.freebsd.org/~jasone/smp/smp_synch_rules.html, for > reference.) That does need some clarification. I'm working on a paper for BSDCon that details locking for this stuff. When its done it will be in the developer's handbook as well. > Also, on that page it states: > > Do not tsleep()/msleep()/cv_wait() while holding a mutex other than Giant. > > Is this still true? With this restriction, threading sounds like it could > be very tough. Might it be possible to double-check that page (it is > almost a year old now) and add information which could be useful to others > pushing down locks? Not really. spl's didn't stay across sleep's either. The only data 4.x locks across a sleep is via lockmgr(). You do the same now with sx locks. Mutexes are more replacements for spl() type functionality, except that spl's only protected against interrupts, and were more coarsely grained. > I suppose some of this info could be picked up from a good book on SMP > strategies, but I think a quick faq could be very helpful. > > Right now I'm thinking of protecting arc4random (it's not important, but > I've been in it recently, and it's a very simple piece of code - one entry > point.) However, just thinking about it I've already come up with a few > questions: > > 1. Do I need to grab Giant before calling down to the time functions? > 2. Do I need to grab Giant before calling into the random device? (I > suspect not, since Mark wrote it recently.) First off, don't drop Giant if you are called with it as you may break assumptions in the code that calls you. Secondly, Giant always has to be first in lock orders, so don't grab Giant if you are holding any other locks or you will break things. As a good rule of thumb for now, don't worry about Giant. If some of the code you call uses it, add mtx_assert()'s to ensure calling code holds Giant when it calls you to avoid lock order problems with Giant. -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message