From owner-freebsd-current Fri Feb 21 17:29:51 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1287937B428 for ; Fri, 21 Feb 2003 17:29:46 -0800 (PST) Received: from mail.speakeasy.net (mail12.speakeasy.net [216.254.0.212]) by mx1.FreeBSD.org (Postfix) with ESMTP id 16B2243FB1 for ; Fri, 21 Feb 2003 17:29:44 -0800 (PST) (envelope-from jhb@FreeBSD.org) Received: (qmail 19810 invoked from network); 22 Feb 2003 01:29:54 -0000 Received: from unknown (HELO server.baldwin.cx) ([216.27.160.63]) (envelope-sender ) by mail12.speakeasy.net (qmail-ldap-1.03) with DES-CBC3-SHA encrypted SMTP for ; 22 Feb 2003 01:29:54 -0000 Received: from laptop.baldwin.cx (laptop.baldwin.cx [192.168.0.4]) by server.baldwin.cx (8.12.6/8.12.6) with ESMTP id h1M1TChT005696; Fri, 21 Feb 2003 20:29:12 -0500 (EST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.5.2 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <20030217045644.42272.qmail@web40305.mail.yahoo.com> Date: Fri, 21 Feb 2003 20:29:56 -0500 (EST) From: John Baldwin To: Maksim Yevmenkin Subject: RE: Need an expert's advise on WITNESS problem(?) (very long) Cc: hackers@freebsd.org, current@freebsd.org Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 17-Feb-2003 Maksim Yevmenkin wrote: > Dear Hackers, > > I need an expert's advice on the small locking/WITNESS problem > (if this is a real problem of course). It basically boils down > to the following: > > Consider three (3) MTX_DEF mutexes: A, B1 and B2. Mutex A has a > name "mutex_A" and type "type_A". Mutex B1 has a name "mutex_B1" > and mutex B2 has name "mutex_B2". Both mutex B1 and B2 have the > same type "type_B". Please note that mutexes B1 and B2 are > completely independent from each other. They just have the same > mutex type (B1 and B2 are used for fine grained locking). > > Now consider the code that has two (2) paths: P1 and P2. > > On the path P1 the code first acquires mutex A and then mutex > B1. Then the code releases mutex B1 and then mutex A. > > On the path P2 the code first acquires mutex B2 and then mutex > A. Then the code releases mutex B2 and then mutex A. > > So the code's flow looks something like this > > --->---\ /--->--- B1 --->--- Code path P1 > A > ---<---/ \---<--- B2 ---<--- Code path P2 > > Now the problem (again if this is a problem) is that WITNESS > code builds relations between mutex types (or at least I think > it does). So when the code runs, WITNESS will build relations > between mutex types for the first path the code follows (lets > say P1). Later when the code follows the second path (in this > example P2), WITNESS will create "lock order reversal" message. > > The questions are: > > 1) Is anything wrong with the such code and/or mutex use? > Since mutexes B1 and B2 are completely independent, there > is no deadlock danger, right? Please tell me if I'm wrong > and missing something here. > > 2) Is there any way to resolve the problem? I'm prepared to > change/re-design my code if needed. > > 3) Is WITNESS right in this case? Yes. By saying that two locks are the same type, you are saying that they should be treated the same. For example, you could have all process locks have 'process lock' for their type and have 'pid XXXX' for their name so that the names are more informative for debugging. Similarly, all network interface drivers would use the same type for their driver lock but might use the name of the interface for the name of the actual lock. -- John Baldwin <>< http://www.FreeBSD.org/~jhb/ "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message