Debugging rw lock

John Baldwin jhb at freebsd.org
Fri Feb 14 18:18:51 UTC 2014


On Thursday, February 13, 2014 10:47:46 pm Julian Elischer wrote:
> On 2/14/14, 5:02 AM, Alfred Perlstein wrote:
> >
> > On 2/13/14, 12:59 PM, Vijay Singh wrote:
> >> You're talking about instrumenting the code, right? But which 
> >> thread? I was
> >> thinking of augmenting the rw lock to record the readers, but 
> >> wanted to
> >> check if something is possible without instrumentation.
> >
> > If rw locks are implemented using low level atomics then you're 
> > going to make the very slow and have a LOT of work to do as opposed 
> > to just using a thread specific storage to implement it. You're 
> > better off just making use of the fact that only "curthread" can 
> > access the per-thread stack and just use that.  Or at least that's 
> > how it works in my brain.
> 
> maybe do it the other way around and count the read locks a thread 
> has.. then when there is a problem go see what they hold..
> (or add the ability to detail 10 locks each or something)

We already do that.  Vijay, you can look at td_rw_rlocks in each
struct thread.  You can at least ignore the threads with a count set
to zero.

The other option is to run with WITNESS enabled.  You can then do
'show all locks' in ddb and you can see which thread owns the lock
(and the file and line number where it acquired it)

-- 
John Baldwin


More information about the freebsd-hackers mailing list