Re: [PATCH 7/7] lockdep: Remove cmpxchg to update nr_chain_hlocks

From: Yong Zhang
Date: Thu Apr 21 2011 - 02:50:20 EST


On Thu, Apr 21, 2011 at 9:42 AM, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> From: Steven Rostedt <srostedt@xxxxxxxxxx>
>
> For some reason nr_chain_hlocks is updated with cmpxchg, but this
> is performed inside of the lockdep global "grab_lock()", which also
> makes simple modification of this variable atomic.
>
> Remove the cmpxchg logic for updating nr_chain_hlocks and simplify
> the code.
>
> Acked-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
> Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
> ---
> Âkernel/lockdep.c | Â 14 ++++----------
> Â1 files changed, 4 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/lockdep.c b/kernel/lockdep.c
> index 3b1ac92..60bce52 100644
> --- a/kernel/lockdep.c
> +++ b/kernel/lockdep.c
> @@ -1973,7 +1973,7 @@ static inline int lookup_chain_cache(struct task_struct *curr,
> Â Â Â Âstruct list_head *hash_head = chainhashentry(chain_key);
> Â Â Â Âstruct lock_chain *chain;
> Â Â Â Âstruct held_lock *hlock_curr, *hlock_next;

Maybe we can also remove hlock_next in this function for some cleanup, because
it's just an alias of hlock.

Thanks,
Yong

> - Â Â Â int i, j, n, cn;
> + Â Â Â int i, j;
>
> Â Â Â Âif (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
> Â Â Â Â Â Â Â Âreturn 0;
> @@ -2033,15 +2033,9 @@ cache_hit:
> Â Â Â Â}
> Â Â Â Âi++;
> Â Â Â Âchain->depth = curr->lockdep_depth + 1 - i;
> - Â Â Â cn = nr_chain_hlocks;
> - Â Â Â while (cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS) {
> - Â Â Â Â Â Â Â n = cmpxchg(&nr_chain_hlocks, cn, cn + chain->depth);
> - Â Â Â Â Â Â Â if (n == cn)
> - Â Â Â Â Â Â Â Â Â Â Â break;
> - Â Â Â Â Â Â Â cn = n;
> - Â Â Â }
> - Â Â Â if (likely(cn + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
> - Â Â Â Â Â Â Â chain->base = cn;
> + Â Â Â if (likely(nr_chain_hlocks + chain->depth <= MAX_LOCKDEP_CHAIN_HLOCKS)) {
> + Â Â Â Â Â Â Â chain->base = nr_chain_hlocks;
> + Â Â Â Â Â Â Â nr_chain_hlocks += chain->depth;
> Â Â Â Â Â Â Â Âfor (j = 0; j < chain->depth - 1; j++, i++) {
> Â Â Â Â Â Â Â Â Â Â Â Âint lock_id = curr->held_locks[i].class_idx - 1;
> Â Â Â Â Â Â Â Â Â Â Â Âchain_hlocks[chain->base + j] = lock_id;
> --
> 1.7.2.3
>
>
> --
> 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/
>



--
Only stand for myself
--
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/