From owner-freebsd-arch@FreeBSD.ORG Sat Mar 29 09:57:20 2008 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 9D435106566B; Sat, 29 Mar 2008 09:57:20 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from webaccess-cl.virtdom.com (webaccess-cl.virtdom.com [216.240.101.25]) by mx1.freebsd.org (Postfix) with ESMTP id 611958FC14; Sat, 29 Mar 2008 09:57:20 +0000 (UTC) (envelope-from jroberson@chesapeake.net) Received: from [10.0.1.200] (cpe-24-94-72-120.hawaii.res.rr.com [24.94.72.120]) (authenticated bits=0) by webaccess-cl.virtdom.com (8.13.6/8.13.6) with ESMTP id m2T9vA7n040532; Sat, 29 Mar 2008 05:57:14 -0400 (EDT) (envelope-from jroberson@chesapeake.net) Date: Fri, 28 Mar 2008 23:58:02 -1000 (HST) From: Jeff Roberson X-X-Sender: jroberson@desktop To: Hans Petter Selasky In-Reply-To: <200803291013.28797.hselasky@c2i.net> Message-ID: <20080328235600.O72156@desktop> References: <10004.1205307334@critter.freebsd.dk> <20080312152744.I29518@fledge.watson.org> <20080328202602.N72156@desktop> <200803291013.28797.hselasky@c2i.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: arch@freebsd.org, freebsd-arch@freebsd.org Subject: Re: timeout/callout small step forward 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: Sat, 29 Mar 2008 09:57:20 -0000 On Sat, 29 Mar 2008, Hans Petter Selasky wrote: > Hi, > > How does this patch handle when multiple callouts use the same mutex ? Imagine > that two threads are about to lock the same mutex, then the second thread > will get nowhere while waiting for the first thread to execute the callback. You are worried that there will be too much contention or that there is some correctness issue? If you're worried about contention, it would seem that most callers use some per-object mutex for the callout. So there isn't likely to be much contention among callouts. > > I think the solution is that callbacks are put in a tree. Giant locked > callbacks go all into the same tree. Else the user of callouts is responsible > for making up the tree. > > struct callout { > struct thread *exec_td; > struct callout *parent; > }; > > struct callout *c; > > while (c->parent != NULL) { > c = c->parent; > } > > if (c->exec_td != NULL) { > callout should go into the same thread; > } else { > pick the next free thread and set "c->exec_td" > } > > Callouts that belong to the same tree are run from the same thread. This does > not only apply for callouts, but also multithreaded node systems ... > > Yours > --HPS >