Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Feb 2003 20:29:56 -0500 (EST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Maksim Yevmenkin <m_evmenkin@yahoo.com>
Cc:        hackers@freebsd.org, current@freebsd.org
Subject:   RE: Need an expert's advise on WITNESS problem(?) (very long)
Message-ID:  <XFMail.20030221202956.jhb@FreeBSD.org>
In-Reply-To: <20030217045644.42272.qmail@web40305.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help

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 <jhb@FreeBSD.org>  <><  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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20030221202956.jhb>