From owner-freebsd-arch@FreeBSD.ORG Mon Jan 26 10:51:41 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 174491065670; Mon, 26 Jan 2009 10:51:41 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by mx1.freebsd.org (Postfix) with ESMTP id 02EEA8FC12; Mon, 26 Jan 2009 10:51:40 +0000 (UTC) (envelope-from bright@elvis.mu.org) Received: by elvis.mu.org (Postfix, from userid 1192) id E578D1A3C39; Mon, 26 Jan 2009 02:51:40 -0800 (PST) Date: Mon, 26 Jan 2009 02:51:40 -0800 From: Alfred Perlstein To: Julian Elischer Message-ID: <20090126105140.GL5889@elvis.mu.org> References: <497BA91D.805@elischer.org> <3c1674c90901241956j244ed067p7ff4df5454beba82@mail.gmail.com> <497C235E.5090807@elischer.org> <20090124224716.X983@desktop> <20090125092838.GC87077@elvis.mu.org> <497D5DF8.8000706@elischer.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <497D5DF8.8000706@elischer.org> User-Agent: Mutt/1.4.2.3i Cc: arch@freebsd.org, Kip Macy 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 10:51:41 -0000 * 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. -Alfred