From owner-freebsd-arch@FreeBSD.ORG Mon Jan 26 14:58:32 2009 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DADBF1065761; Mon, 26 Jan 2009 14:58:32 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id A97758FC2A; Mon, 26 Jan 2009 14:58:32 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (pool-98-109-39-197.nwrknj.fios.verizon.net [98.109.39.197]) by cyrus.watson.org (Postfix) with ESMTPSA id 3BDA246B0C; Mon, 26 Jan 2009 09:58:32 -0500 (EST) Received: from localhost (john@localhost [127.0.0.1]) (authenticated bits=0) by server.baldwin.cx (8.14.3/8.14.3) with ESMTP id n0QEw2xv078018; Mon, 26 Jan 2009 09:58:25 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-arch@freebsd.org Date: Mon, 26 Jan 2009 09:36:17 -0500 User-Agent: KMail/1.9.7 References: <497BA91D.805@elischer.org> <497D5DF8.8000706@elischer.org> <20090126105140.GL5889@elvis.mu.org> In-Reply-To: <20090126105140.GL5889@elvis.mu.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200901260936.18232.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [127.0.0.1]); Mon, 26 Jan 2009 09:58:26 -0500 (EST) X-Virus-Scanned: ClamAV 0.94.2/8904/Mon Jan 26 08:06:06 2009 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 required=4.2 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: arch@freebsd.org, Alfred Perlstein , Julian Elischer , 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 14:58:33 -0000 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. -- John Baldwin