lockdep: add lock_class information to lock_chain and output it
authorHuang, Ying <ying.huang@intel.com>
Mon, 23 Jun 2008 03:20:54 +0000 (11:20 +0800)
committerIngo Molnar <mingo@elte.hu>
Mon, 23 Jun 2008 23:28:20 +0000 (01:28 +0200)
It is based on x86/master branch of git-x86 tree, and has been tested
on x86_64 platform.

ChangeLog:

v2:

- Enclosing proc file system related code into CONFIG_PROVE_LOCKING.

- Fix nr_chain_hlocks update code.

Signed-off-by: Huang Ying <ying.huang@intel.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
kernel/lockdep.c
kernel/lockdep_internals.h
kernel/lockdep_proc.c

index a796f1f38ac5b0c625c37a0d81cb23665d7f5e1e..7553a28b99cdd3b832eec916b5f3a2f9ea84157a 100644 (file)
@@ -1459,7 +1459,7 @@ out_bug:
 
 unsigned long nr_lock_chains;
 struct lock_chain lock_chains[MAX_LOCKDEP_CHAINS];
-atomic_t nr_chain_hlocks;
+int nr_chain_hlocks;
 static u16 chain_hlocks[MAX_LOCKDEP_CHAIN_HLOCKS];
 
 struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i)
@@ -1481,7 +1481,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;
-       int i, j, n;
+       int i, j, n, cn;
 
        if (DEBUG_LOCKS_WARN_ON(!irqs_disabled()))
                return 0;
@@ -1540,9 +1540,15 @@ cache_hit:
        }
        i++;
        chain->depth = curr->lockdep_depth + 1 - i;
-       n = atomic_add_return(chain->depth, &nr_chain_hlocks);
-       if (unlikely(n < MAX_LOCKDEP_CHAIN_HLOCKS)) {
-               chain->base = n - chain->depth;
+       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;
                for (j = 0; j < chain->depth - 1; j++, i++) {
                        int lock_id = curr->held_locks[i].class - lock_classes;
                        chain_hlocks[chain->base + j] = lock_id;
index db09b176dd34e191645ae93b2a524f51d3585e32..c3600a091a2874952e97c149f21080ede90ded95 100644 (file)
@@ -44,7 +44,7 @@ struct lock_class *lock_chain_get_class(struct lock_chain *chain, int i);
 extern unsigned long nr_lock_classes;
 extern unsigned long nr_list_entries;
 extern unsigned long nr_lock_chains;
-extern atomic_t nr_chain_hlocks;
+extern int nr_chain_hlocks;
 extern unsigned long nr_stack_trace_entries;
 
 extern unsigned int nr_hardirq_chains;
index 14d052c8a83538114faf68b166e99d6733ac7068..9b0e940e2545efe99012dd1526ef79a4739f02d2 100644 (file)
@@ -178,6 +178,7 @@ static const struct file_operations proc_lockdep_operations = {
        .release        = seq_release,
 };
 
+#ifdef CONFIG_PROVE_LOCKING
 static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
 {
        struct lock_chain *chain;
@@ -264,6 +265,7 @@ static const struct file_operations proc_lockdep_chains_operations = {
        .llseek         = seq_lseek,
        .release        = seq_release,
 };
+#endif /* CONFIG_PROVE_LOCKING */
 
 static void lockdep_stats_debug_show(struct seq_file *m)
 {
@@ -382,7 +384,7 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
        seq_printf(m, " dependency chains:             %11lu [max: %lu]\n",
                        nr_lock_chains, MAX_LOCKDEP_CHAINS);
        seq_printf(m, " dependency chain hlocks:       %11d [max: %lu]\n",
-                       atomic_read(&nr_chain_hlocks), MAX_LOCKDEP_CHAIN_HLOCKS);
+                       nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
 #endif
 
 #ifdef CONFIG_TRACE_IRQFLAGS
@@ -750,8 +752,10 @@ static const struct file_operations proc_lock_stat_operations = {
 static int __init lockdep_proc_init(void)
 {
        proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
+#ifdef CONFIG_PROVE_LOCKING
        proc_create("lockdep_chains", S_IRUSR, NULL,
                    &proc_lockdep_chains_operations);
+#endif
        proc_create("lockdep_stats", S_IRUSR, NULL,
                    &proc_lockdep_stats_operations);