[Openmcl-devel] lock owner: how to access?
dherring at tentpost.com
Wed Jul 6 00:27:45 PDT 2011
On Tue, 5 Jul 2011, Ron Garret wrote:
> On Jul 2, 2011, at 1:35 AM, Gary Byers wrote:
>> The only thing you can generally do (outside of a context like the kernel
>> debugger, where all other threads are stopped) is answer the question
>> "what thread owned this lock a few cycles ago, when I asked ?" The answer
>> to that question is either useful or misleading, and there's no general
>> way of knowing which.
> You can make that answer more useful by adding a timestamp (or a counter) to a lock that keeps track of the last time the lock was grabbed. That lets you determine wether a cycle in the resource contention graph is real or a timing artifact by walking the cycle twice. If the timestamps/counters haven't changed since the first traverse then you have found a deadlock.
Such timing instrumentation may be expensive to add compared to the
payoff. How often do we actually care? How long must the observer wait
between cycle walks?
A with-rest-of-world-stopped macro might be useful for wrapping
probe-lock-owner in the cases where one needs an answer for other than
reporting purposes. Otherwise the lock owner can still change between
when the probe is performed and when you see/act on the answer.
The lateral option to all this is to call trylock in a polling loop.
When trylock succeeds, you know who the owner is. ;)
More information about the Openmcl-devel