From owner-freebsd-arch@FreeBSD.ORG Mon Jan 26 18:05:19 2009 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 30C6B10656F0 for ; Mon, 26 Jan 2009 18:05:19 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outJ.internet-mail-service.net (outj.internet-mail-service.net [216.240.47.233]) by mx1.freebsd.org (Postfix) with ESMTP id 0DFFA8FC21 for ; Mon, 26 Jan 2009 18:05:18 +0000 (UTC) (envelope-from julian@elischer.org) Received: from idiom.com (mx0.idiom.com [216.240.32.160]) by out.internet-mail-service.net (Postfix) with ESMTP id 8485424E3; Mon, 26 Jan 2009 10:05:18 -0800 (PST) X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e Received: from julian-mac.elischer.org (home.elischer.org [216.240.48.38]) by idiom.com (Postfix) with ESMTP id 9919C2D6025; Mon, 26 Jan 2009 10:05:17 -0800 (PST) Message-ID: <497DFB61.1010602@elischer.org> Date: Mon, 26 Jan 2009 10:05:21 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 To: John Baldwin References: <497BA91D.805@elischer.org> <497D5DF8.8000706@elischer.org> <20090126105140.GL5889@elvis.mu.org> <200901260936.18232.jhb@freebsd.org> In-Reply-To: <200901260936.18232.jhb@freebsd.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: arch@freebsd.org, Alfred Perlstein , Kip Macy , freebsd-arch@freebsd.org Subject: Re: need for another mutex type/flag? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 Jan 2009 18:05:21 -0000 John Baldwin wrote: > On Monday 26 January 2009 5:51:40 am Alfred Perlstein wrote: >> * Julian Elischer [090125 22:53] wrote: >>> Alfred Perlstein wrote: >>>> Jeff, I think that Julian really wants to prevent a sleep inside >>>> his context. Right now, I think we only check for mutexes held >>>> before a sleep that arne't sleepable. It might make sense to allow >>>> one to just mark a thread non-sleepable even though no mutex is >>>> held. >>>> >>>> Julian, is that right? >>> basically, though I don't know the details of implementation.. >>> I just know that mutexes per se aren't bad for netgraph but >>> that node authors need some guidance on how to use them and >>> some way to prove to them when they do the wrong thing. >> The way to add the assertion you want would be to keep a count >> inside of the thread structure "td_nosleep", set to 0 at thread >> creation, then you can do this: >> >> TD_SLEEP_NO(td); /* td->td_nosleep++ */ >> call_some_untrusted_code(); >> TD_SLEEP_OK(td); /* td->td_nosleep-- */ >> >> Then add this to subr_witness.c:witness_warn(): >> >> if (flags & WARN_SLEEPOK && td->td_nosleep != 0) { >> printf("Sleeping in unsleepable context.\n"); >> n++; /* this variable is local to witness_warn() >> and triggers an ASSERT at the end */ >> } >> >> I could have sworn we already had such a feature, but it appears >> that it's only accessable if you're holding a lock, if you added >> this counter, then you could catch sleeps without needing a lock >> held. > > We have this feature already for sleeping, but I think Julian isn't worried > about sleeping (i.e. *sleep() or cv_*wait*()), but wants to prevent the code > from acquiring any other locks. It's easy to add a MTX_LEAF, I'm just not > sure if we really want to micro-manage the code that much. WITNESS will > already catch any LORs, and if they are acquiring a rarely-contested lock > then they aren't going to back up traffic in the common case. > maybe what I want is to be able to label a lock as "fleeting" By which I mean that the work that would be done while holding this lock would be fleeting (momentary) in nature. An example f a fleeting lock would be something that gains the lock in order to safely switch two pointers. no malloc is required and nothing is going to take a long time. locks that are NOT momentary include holding the process list lock while allocating a large buffer (series of them) and dumping the contents of all processes and things like that. one might almost say that a fleeting lock might be gotten while holding another fleeting lock, but that is pushing it for me..