locking/lockdep: Report more stack trace statistics
authorBart Van Assche <bvanassche@acm.org>
Mon, 22 Jul 2019 18:24:43 +0000 (11:24 -0700)
committerIngo Molnar <mingo@kernel.org>
Thu, 25 Jul 2019 13:43:28 +0000 (15:43 +0200)
Report the number of stack traces and the number of stack trace hash
chains. These two numbers are useful because these allow to estimate
the number of stack trace hash collisions.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will.deacon@arm.com>
Link: https://lkml.kernel.org/r/20190722182443.216015-5-bvanassche@acm.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/locking/lockdep.c
kernel/locking/lockdep_internals.h
kernel/locking/lockdep_proc.c

index 1a96869cb2f062890d8a15956f0230a6e24bfc02..3c3902c40a0ead24baedd59979285e80d74b1829 100644 (file)
@@ -516,6 +516,35 @@ static struct lock_trace *save_trace(void)
 
        return trace;
 }
+
+/* Return the number of stack traces in the stack_trace[] array. */
+u64 lockdep_stack_trace_count(void)
+{
+       struct lock_trace *trace;
+       u64 c = 0;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(stack_trace_hash); i++) {
+               hlist_for_each_entry(trace, &stack_trace_hash[i], hash_entry) {
+                       c++;
+               }
+       }
+
+       return c;
+}
+
+/* Return the number of stack hash chains that have at least one stack trace. */
+u64 lockdep_stack_hash_count(void)
+{
+       u64 c = 0;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(stack_trace_hash); i++)
+               if (!hlist_empty(&stack_trace_hash[i]))
+                       c++;
+
+       return c;
+}
 #endif
 
 unsigned int nr_hardirq_chains;
index 93a008bf77db49c79e00327efff17845284caddc..18d85aebbb57f93808d452a1bde0d742f1e4b146 100644 (file)
@@ -140,6 +140,10 @@ extern unsigned int max_bfs_queue_depth;
 #ifdef CONFIG_PROVE_LOCKING
 extern unsigned long lockdep_count_forward_deps(struct lock_class *);
 extern unsigned long lockdep_count_backward_deps(struct lock_class *);
+#ifdef CONFIG_TRACE_IRQFLAGS
+u64 lockdep_stack_trace_count(void);
+u64 lockdep_stack_hash_count(void);
+#endif
 #else
 static inline unsigned long
 lockdep_count_forward_deps(struct lock_class *class)
index ed9842425cac25d363d83c7781a02c28787978fa..dadb7b7fba3733ca7dfe80cf5624c88b7c147c96 100644 (file)
@@ -285,6 +285,12 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
                        nr_process_chains);
        seq_printf(m, " stack-trace entries:           %11lu [max: %lu]\n",
                        nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES);
+#if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING)
+       seq_printf(m, " number of stack traces:        %llu\n",
+                  lockdep_stack_trace_count());
+       seq_printf(m, " number of stack hash chains:   %llu\n",
+                  lockdep_stack_hash_count());
+#endif
        seq_printf(m, " combined max dependencies:     %11u\n",
                        (nr_hardirq_chains + 1) *
                        (nr_softirq_chains + 1) *