Re: [RFC][PATCH 4/7] lockdep: Seperate lock ids for read/writeacquires

From: Peter Zijlstra
Date: Mon Apr 18 2011 - 12:50:15 EST


On Mon, 2011-04-18 at 12:46 -0400, Steven Rostedt wrote:
> > +/*
> > + * A lock's class id is used to calculate the chain-key. Since we need to
> > + * differentiate between the chains which contain the read acquire of
> > + * a lock from the chains having write acquire of the same lock,
> > + * we offset the class_idx by MAX_LOCKDEP_KEYS if it is a read acquire.
>
> Don't we only care to do this if we have a recursive read? I thought
> simple reads still work fine with the current algorithm?
>
> > + *
> > + * Thus the the lock's key during a chain-key calculation can be in the range
> > + * 1 to 2 * MAX_LOCKDEP_KEYS - 1.
> > + *
> > + * LOCKDEP_CHAIN_KEY_BITS holds the number of bits required to
> > + * represent this range.
> > + */
> > +#define LOCKDEP_CHAIN_KEY_BITS (MAX_LOCKDEP_KEYS_BITS + 1)
> > struct held_lock {
> > /*
> > * One-way hash of the dependency chain up to this point. We
> > Index: linux-2.6/kernel/lockdep.c
> > ===================================================================
> > --- linux-2.6.orig/kernel/lockdep.c
> > +++ linux-2.6/kernel/lockdep.c
> > @@ -303,8 +303,8 @@ static struct list_head chainhash_table[
> > * unique.
> > */
> > #define iterate_chain_key(key1, key2) \
> > - (((key1) << MAX_LOCKDEP_KEYS_BITS) ^ \
> > - ((key1) >> (64-MAX_LOCKDEP_KEYS_BITS)) ^ \
> > + (((key1) << LOCKDEP_CHAIN_KEY_BITS) ^ \
> > + ((key1) >> (64 - LOCKDEP_CHAIN_KEY_BITS)) ^ \
> > (key2))
> >
> > void lockdep_off(void)
> > @@ -1988,6 +1988,9 @@ static void check_chain_key(struct task_
> > if (DEBUG_LOCKS_WARN_ON(id >= MAX_LOCKDEP_KEYS))
> > return;
> >
> > + if (is_read(hlock->rw_state))
> > + id += MAX_LOCKDEP_KEYS;
>
> Again, isn't this about recursive reads? Or am I just confused ;)

So what we do here is split off the write chain, the above could have
been writeen if (!is_write()) to clarify that.

Everything except recursive read validation will traverse both chains,
the recursive read validation will only traverse the write chains and
ignore the combined read/recursive-read chain.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/