Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * kernel/lockdep_proc.c |
| 3 | * |
| 4 | * Runtime locking correctness validator |
| 5 | * |
| 6 | * Started by Ingo Molnar: |
| 7 | * |
Peter Zijlstra | 4b32d0a | 2007-07-19 01:48:59 -0700 | [diff] [blame] | 8 | * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> |
| 9 | * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 10 | * |
| 11 | * Code for /proc/lockdep and /proc/lockdep_stats: |
| 12 | * |
| 13 | */ |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/proc_fs.h> |
| 16 | #include <linux/seq_file.h> |
| 17 | #include <linux/kallsyms.h> |
| 18 | #include <linux/debug_locks.h> |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 19 | #include <linux/vmalloc.h> |
| 20 | #include <linux/sort.h> |
| 21 | #include <asm/uaccess.h> |
| 22 | #include <asm/div64.h> |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 23 | |
| 24 | #include "lockdep_internals.h" |
| 25 | |
| 26 | static void *l_next(struct seq_file *m, void *v, loff_t *pos) |
| 27 | { |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 28 | return seq_list_next(v, &all_lock_classes, pos); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static void *l_start(struct seq_file *m, loff_t *pos) |
| 32 | { |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 33 | return seq_list_start_head(&all_lock_classes, *pos); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static void l_stop(struct seq_file *m, void *v) |
| 37 | { |
| 38 | } |
| 39 | |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 40 | static void print_name(struct seq_file *m, struct lock_class *class) |
| 41 | { |
| 42 | char str[128]; |
| 43 | const char *name = class->name; |
| 44 | |
| 45 | if (!name) { |
| 46 | name = __get_key_name(class->key, str); |
| 47 | seq_printf(m, "%s", name); |
| 48 | } else{ |
| 49 | seq_printf(m, "%s", name); |
| 50 | if (class->name_version > 1) |
| 51 | seq_printf(m, "#%d", class->name_version); |
| 52 | if (class->subclass) |
| 53 | seq_printf(m, "/%d", class->subclass); |
| 54 | } |
| 55 | } |
| 56 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 57 | static int l_show(struct seq_file *m, void *v) |
| 58 | { |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 59 | struct lock_class *class = list_entry(v, struct lock_class, lock_entry); |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 60 | struct lock_list *entry; |
Peter Zijlstra | f510b23 | 2009-01-22 17:53:47 +0100 | [diff] [blame] | 61 | char usage[LOCK_USAGE_CHARS]; |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 62 | |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 63 | if (v == &all_lock_classes) { |
Tim Pepper | 94c61c0 | 2007-10-11 22:11:11 +0200 | [diff] [blame] | 64 | seq_printf(m, "all lock classes:\n"); |
| 65 | return 0; |
| 66 | } |
| 67 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 68 | seq_printf(m, "%p", class->key); |
| 69 | #ifdef CONFIG_DEBUG_LOCKDEP |
| 70 | seq_printf(m, " OPS:%8ld", class->ops); |
| 71 | #endif |
Stephen Hemminger | df60a84 | 2008-08-15 09:33:05 -0700 | [diff] [blame] | 72 | #ifdef CONFIG_PROVE_LOCKING |
| 73 | seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class)); |
| 74 | seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class)); |
| 75 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 76 | |
Peter Zijlstra | f510b23 | 2009-01-22 17:53:47 +0100 | [diff] [blame] | 77 | get_usage_chars(class, usage); |
| 78 | seq_printf(m, " %s", usage); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 79 | |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 80 | seq_printf(m, ": "); |
| 81 | print_name(m, class); |
| 82 | seq_puts(m, "\n"); |
| 83 | |
| 84 | list_for_each_entry(entry, &class->locks_after, entry) { |
| 85 | if (entry->distance == 1) { |
Huang, Ying | 2429e4e | 2008-06-13 14:40:17 +0800 | [diff] [blame] | 86 | seq_printf(m, " -> [%p] ", entry->class->key); |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 87 | print_name(m, entry->class); |
| 88 | seq_puts(m, "\n"); |
| 89 | } |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 90 | } |
| 91 | seq_puts(m, "\n"); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 96 | static const struct seq_operations lockdep_ops = { |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 97 | .start = l_start, |
| 98 | .next = l_next, |
| 99 | .stop = l_stop, |
| 100 | .show = l_show, |
| 101 | }; |
| 102 | |
| 103 | static int lockdep_open(struct inode *inode, struct file *file) |
| 104 | { |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 105 | return seq_open(file, &lockdep_ops); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 108 | static const struct file_operations proc_lockdep_operations = { |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 109 | .open = lockdep_open, |
| 110 | .read = seq_read, |
| 111 | .llseek = seq_lseek, |
| 112 | .release = seq_release, |
| 113 | }; |
| 114 | |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 115 | #ifdef CONFIG_PROVE_LOCKING |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 116 | static void *lc_start(struct seq_file *m, loff_t *pos) |
| 117 | { |
| 118 | if (*pos == 0) |
| 119 | return SEQ_START_TOKEN; |
| 120 | |
Li Zefan | e9d6572 | 2009-08-17 13:39:49 +0800 | [diff] [blame] | 121 | if (*pos - 1 < nr_lock_chains) |
| 122 | return lock_chains + (*pos - 1); |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 123 | |
| 124 | return NULL; |
| 125 | } |
| 126 | |
Li Zefan | 12aac19 | 2009-08-17 13:40:39 +0800 | [diff] [blame] | 127 | static void *lc_next(struct seq_file *m, void *v, loff_t *pos) |
| 128 | { |
| 129 | (*pos)++; |
| 130 | return lc_start(m, pos); |
| 131 | } |
| 132 | |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 133 | static void lc_stop(struct seq_file *m, void *v) |
| 134 | { |
| 135 | } |
| 136 | |
| 137 | static int lc_show(struct seq_file *m, void *v) |
| 138 | { |
| 139 | struct lock_chain *chain = v; |
| 140 | struct lock_class *class; |
| 141 | int i; |
| 142 | |
| 143 | if (v == SEQ_START_TOKEN) { |
| 144 | seq_printf(m, "all lock chains:\n"); |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | seq_printf(m, "irq_context: %d\n", chain->irq_context); |
| 149 | |
| 150 | for (i = 0; i < chain->depth; i++) { |
| 151 | class = lock_chain_get_class(chain, i); |
Rabin Vincent | 8bfe029 | 2008-08-11 09:30:26 +0200 | [diff] [blame] | 152 | if (!class->key) |
| 153 | continue; |
| 154 | |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 155 | seq_printf(m, "[%p] ", class->key); |
| 156 | print_name(m, class); |
| 157 | seq_puts(m, "\n"); |
| 158 | } |
| 159 | seq_puts(m, "\n"); |
| 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | static const struct seq_operations lockdep_chains_ops = { |
| 165 | .start = lc_start, |
| 166 | .next = lc_next, |
| 167 | .stop = lc_stop, |
| 168 | .show = lc_show, |
| 169 | }; |
| 170 | |
| 171 | static int lockdep_chains_open(struct inode *inode, struct file *file) |
| 172 | { |
Li Zefan | 12aac19 | 2009-08-17 13:40:39 +0800 | [diff] [blame] | 173 | return seq_open(file, &lockdep_chains_ops); |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | static const struct file_operations proc_lockdep_chains_operations = { |
| 177 | .open = lockdep_chains_open, |
| 178 | .read = seq_read, |
| 179 | .llseek = seq_lseek, |
| 180 | .release = seq_release, |
| 181 | }; |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 182 | #endif /* CONFIG_PROVE_LOCKING */ |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 183 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 184 | static void lockdep_stats_debug_show(struct seq_file *m) |
| 185 | { |
| 186 | #ifdef CONFIG_DEBUG_LOCKDEP |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 187 | unsigned long long hi1 = debug_atomic_read(hardirqs_on_events), |
| 188 | hi2 = debug_atomic_read(hardirqs_off_events), |
| 189 | hr1 = debug_atomic_read(redundant_hardirqs_on), |
| 190 | hr2 = debug_atomic_read(redundant_hardirqs_off), |
| 191 | si1 = debug_atomic_read(softirqs_on_events), |
| 192 | si2 = debug_atomic_read(softirqs_off_events), |
| 193 | sr1 = debug_atomic_read(redundant_softirqs_on), |
| 194 | sr2 = debug_atomic_read(redundant_softirqs_off); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 195 | |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 196 | seq_printf(m, " chain lookup misses: %11llu\n", |
| 197 | debug_atomic_read(chain_lookup_misses)); |
| 198 | seq_printf(m, " chain lookup hits: %11llu\n", |
| 199 | debug_atomic_read(chain_lookup_hits)); |
| 200 | seq_printf(m, " cyclic checks: %11llu\n", |
| 201 | debug_atomic_read(nr_cyclic_checks)); |
| 202 | seq_printf(m, " find-mask forwards checks: %11llu\n", |
| 203 | debug_atomic_read(nr_find_usage_forwards_checks)); |
| 204 | seq_printf(m, " find-mask backwards checks: %11llu\n", |
| 205 | debug_atomic_read(nr_find_usage_backwards_checks)); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 206 | |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 207 | seq_printf(m, " hardirq on events: %11llu\n", hi1); |
| 208 | seq_printf(m, " hardirq off events: %11llu\n", hi2); |
| 209 | seq_printf(m, " redundant hardirq ons: %11llu\n", hr1); |
| 210 | seq_printf(m, " redundant hardirq offs: %11llu\n", hr2); |
| 211 | seq_printf(m, " softirq on events: %11llu\n", si1); |
| 212 | seq_printf(m, " softirq off events: %11llu\n", si2); |
| 213 | seq_printf(m, " redundant softirq ons: %11llu\n", sr1); |
| 214 | seq_printf(m, " redundant softirq offs: %11llu\n", sr2); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 215 | #endif |
| 216 | } |
| 217 | |
| 218 | static int lockdep_stats_show(struct seq_file *m, void *v) |
| 219 | { |
| 220 | struct lock_class *class; |
| 221 | unsigned long nr_unused = 0, nr_uncategorized = 0, |
| 222 | nr_irq_safe = 0, nr_irq_unsafe = 0, |
| 223 | nr_softirq_safe = 0, nr_softirq_unsafe = 0, |
| 224 | nr_hardirq_safe = 0, nr_hardirq_unsafe = 0, |
| 225 | nr_irq_read_safe = 0, nr_irq_read_unsafe = 0, |
| 226 | nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0, |
| 227 | nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0, |
| 228 | sum_forward_deps = 0, factor = 0; |
| 229 | |
| 230 | list_for_each_entry(class, &all_lock_classes, lock_entry) { |
| 231 | |
| 232 | if (class->usage_mask == 0) |
| 233 | nr_unused++; |
| 234 | if (class->usage_mask == LOCKF_USED) |
| 235 | nr_uncategorized++; |
| 236 | if (class->usage_mask & LOCKF_USED_IN_IRQ) |
| 237 | nr_irq_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 238 | if (class->usage_mask & LOCKF_ENABLED_IRQ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 239 | nr_irq_unsafe++; |
| 240 | if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ) |
| 241 | nr_softirq_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 242 | if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 243 | nr_softirq_unsafe++; |
| 244 | if (class->usage_mask & LOCKF_USED_IN_HARDIRQ) |
| 245 | nr_hardirq_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 246 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 247 | nr_hardirq_unsafe++; |
| 248 | if (class->usage_mask & LOCKF_USED_IN_IRQ_READ) |
| 249 | nr_irq_read_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 250 | if (class->usage_mask & LOCKF_ENABLED_IRQ_READ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 251 | nr_irq_read_unsafe++; |
| 252 | if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ) |
| 253 | nr_softirq_read_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 254 | if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 255 | nr_softirq_read_unsafe++; |
| 256 | if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ) |
| 257 | nr_hardirq_read_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 258 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 259 | nr_hardirq_read_unsafe++; |
| 260 | |
Stephen Hemminger | df60a84 | 2008-08-15 09:33:05 -0700 | [diff] [blame] | 261 | #ifdef CONFIG_PROVE_LOCKING |
David Miller | 419ca3f | 2008-07-29 21:45:03 -0700 | [diff] [blame] | 262 | sum_forward_deps += lockdep_count_forward_deps(class); |
Stephen Hemminger | df60a84 | 2008-08-15 09:33:05 -0700 | [diff] [blame] | 263 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 264 | } |
Robert P. J. Day | 501b9eb | 2007-02-10 01:46:34 -0800 | [diff] [blame] | 265 | #ifdef CONFIG_DEBUG_LOCKDEP |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 266 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 267 | #endif |
| 268 | seq_printf(m, " lock-classes: %11lu [max: %lu]\n", |
| 269 | nr_lock_classes, MAX_LOCKDEP_KEYS); |
| 270 | seq_printf(m, " direct dependencies: %11lu [max: %lu]\n", |
| 271 | nr_list_entries, MAX_LOCKDEP_ENTRIES); |
| 272 | seq_printf(m, " indirect dependencies: %11lu\n", |
| 273 | sum_forward_deps); |
| 274 | |
| 275 | /* |
| 276 | * Total number of dependencies: |
| 277 | * |
| 278 | * All irq-safe locks may nest inside irq-unsafe locks, |
| 279 | * plus all the other known dependencies: |
| 280 | */ |
| 281 | seq_printf(m, " all direct dependencies: %11lu\n", |
| 282 | nr_irq_unsafe * nr_irq_safe + |
| 283 | nr_hardirq_unsafe * nr_hardirq_safe + |
| 284 | nr_list_entries); |
| 285 | |
| 286 | /* |
| 287 | * Estimated factor between direct and indirect |
| 288 | * dependencies: |
| 289 | */ |
| 290 | if (nr_list_entries) |
| 291 | factor = sum_forward_deps / nr_list_entries; |
| 292 | |
Peter Zijlstra | 8e18257 | 2007-07-19 01:48:54 -0700 | [diff] [blame] | 293 | #ifdef CONFIG_PROVE_LOCKING |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 294 | seq_printf(m, " dependency chains: %11lu [max: %lu]\n", |
| 295 | nr_lock_chains, MAX_LOCKDEP_CHAINS); |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 296 | seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n", |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 297 | nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS); |
Peter Zijlstra | 8e18257 | 2007-07-19 01:48:54 -0700 | [diff] [blame] | 298 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 299 | |
| 300 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 301 | seq_printf(m, " in-hardirq chains: %11u\n", |
| 302 | nr_hardirq_chains); |
| 303 | seq_printf(m, " in-softirq chains: %11u\n", |
| 304 | nr_softirq_chains); |
| 305 | #endif |
| 306 | seq_printf(m, " in-process chains: %11u\n", |
| 307 | nr_process_chains); |
| 308 | seq_printf(m, " stack-trace entries: %11lu [max: %lu]\n", |
| 309 | nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES); |
| 310 | seq_printf(m, " combined max dependencies: %11u\n", |
| 311 | (nr_hardirq_chains + 1) * |
| 312 | (nr_softirq_chains + 1) * |
| 313 | (nr_process_chains + 1) |
| 314 | ); |
| 315 | seq_printf(m, " hardirq-safe locks: %11lu\n", |
| 316 | nr_hardirq_safe); |
| 317 | seq_printf(m, " hardirq-unsafe locks: %11lu\n", |
| 318 | nr_hardirq_unsafe); |
| 319 | seq_printf(m, " softirq-safe locks: %11lu\n", |
| 320 | nr_softirq_safe); |
| 321 | seq_printf(m, " softirq-unsafe locks: %11lu\n", |
| 322 | nr_softirq_unsafe); |
| 323 | seq_printf(m, " irq-safe locks: %11lu\n", |
| 324 | nr_irq_safe); |
| 325 | seq_printf(m, " irq-unsafe locks: %11lu\n", |
| 326 | nr_irq_unsafe); |
| 327 | |
| 328 | seq_printf(m, " hardirq-read-safe locks: %11lu\n", |
| 329 | nr_hardirq_read_safe); |
| 330 | seq_printf(m, " hardirq-read-unsafe locks: %11lu\n", |
| 331 | nr_hardirq_read_unsafe); |
| 332 | seq_printf(m, " softirq-read-safe locks: %11lu\n", |
| 333 | nr_softirq_read_safe); |
| 334 | seq_printf(m, " softirq-read-unsafe locks: %11lu\n", |
| 335 | nr_softirq_read_unsafe); |
| 336 | seq_printf(m, " irq-read-safe locks: %11lu\n", |
| 337 | nr_irq_read_safe); |
| 338 | seq_printf(m, " irq-read-unsafe locks: %11lu\n", |
| 339 | nr_irq_read_unsafe); |
| 340 | |
| 341 | seq_printf(m, " uncategorized locks: %11lu\n", |
| 342 | nr_uncategorized); |
| 343 | seq_printf(m, " unused locks: %11lu\n", |
| 344 | nr_unused); |
| 345 | seq_printf(m, " max locking depth: %11u\n", |
| 346 | max_lockdep_depth); |
Ingo Molnar | bbfa262 | 2009-08-02 14:44:24 +0200 | [diff] [blame] | 347 | #ifdef CONFIG_PROVE_LOCKING |
Ming Lei | 12f3dfd | 2009-07-16 15:44:29 +0200 | [diff] [blame] | 348 | seq_printf(m, " max bfs queue depth: %11u\n", |
| 349 | max_bfs_queue_depth); |
Ingo Molnar | bbfa262 | 2009-08-02 14:44:24 +0200 | [diff] [blame] | 350 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 351 | lockdep_stats_debug_show(m); |
| 352 | seq_printf(m, " debug_locks: %11u\n", |
| 353 | debug_locks); |
| 354 | |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | static int lockdep_stats_open(struct inode *inode, struct file *file) |
| 359 | { |
| 360 | return single_open(file, lockdep_stats_show, NULL); |
| 361 | } |
| 362 | |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 363 | static const struct file_operations proc_lockdep_stats_operations = { |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 364 | .open = lockdep_stats_open, |
| 365 | .read = seq_read, |
| 366 | .llseek = seq_lseek, |
Alexey Dobriyan | c0f3358 | 2007-07-31 00:38:50 -0700 | [diff] [blame] | 367 | .release = single_release, |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 368 | }; |
| 369 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 370 | #ifdef CONFIG_LOCK_STAT |
| 371 | |
| 372 | struct lock_stat_data { |
| 373 | struct lock_class *class; |
| 374 | struct lock_class_stats stats; |
| 375 | }; |
| 376 | |
| 377 | struct lock_stat_seq { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 378 | struct lock_stat_data *iter_end; |
| 379 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; |
| 380 | }; |
| 381 | |
| 382 | /* |
| 383 | * sort on absolute number of contentions |
| 384 | */ |
| 385 | static int lock_stat_cmp(const void *l, const void *r) |
| 386 | { |
| 387 | const struct lock_stat_data *dl = l, *dr = r; |
| 388 | unsigned long nl, nr; |
| 389 | |
| 390 | nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr; |
| 391 | nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr; |
| 392 | |
| 393 | return nr - nl; |
| 394 | } |
| 395 | |
| 396 | static void seq_line(struct seq_file *m, char c, int offset, int length) |
| 397 | { |
| 398 | int i; |
| 399 | |
| 400 | for (i = 0; i < offset; i++) |
| 401 | seq_puts(m, " "); |
| 402 | for (i = 0; i < length; i++) |
| 403 | seq_printf(m, "%c", c); |
| 404 | seq_puts(m, "\n"); |
| 405 | } |
| 406 | |
| 407 | static void snprint_time(char *buf, size_t bufsiz, s64 nr) |
| 408 | { |
Peter Zijlstra | 6918bc5 | 2008-09-23 15:33:41 +0200 | [diff] [blame] | 409 | s64 div; |
| 410 | s32 rem; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 411 | |
Joe Korty | 2189459 | 2008-08-25 17:15:33 -0400 | [diff] [blame] | 412 | nr += 5; /* for display rounding */ |
Peter Zijlstra | 6918bc5 | 2008-09-23 15:33:41 +0200 | [diff] [blame] | 413 | div = div_s64_rem(nr, 1000, &rem); |
| 414 | snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static void seq_time(struct seq_file *m, s64 time) |
| 418 | { |
| 419 | char num[15]; |
| 420 | |
| 421 | snprint_time(num, sizeof(num), time); |
| 422 | seq_printf(m, " %14s", num); |
| 423 | } |
| 424 | |
| 425 | static void seq_lock_time(struct seq_file *m, struct lock_time *lt) |
| 426 | { |
| 427 | seq_printf(m, "%14lu", lt->nr); |
| 428 | seq_time(m, lt->min); |
| 429 | seq_time(m, lt->max); |
| 430 | seq_time(m, lt->total); |
| 431 | } |
| 432 | |
| 433 | static void seq_stats(struct seq_file *m, struct lock_stat_data *data) |
| 434 | { |
| 435 | char name[39]; |
| 436 | struct lock_class *class; |
| 437 | struct lock_class_stats *stats; |
| 438 | int i, namelen; |
| 439 | |
| 440 | class = data->class; |
| 441 | stats = &data->stats; |
| 442 | |
Peter Zijlstra | d38e1d5 | 2007-07-19 01:49:01 -0700 | [diff] [blame] | 443 | namelen = 38; |
| 444 | if (class->name_version > 1) |
| 445 | namelen -= 2; /* XXX truncates versions > 9 */ |
| 446 | if (class->subclass) |
| 447 | namelen -= 2; |
| 448 | |
| 449 | if (!class->name) { |
| 450 | char str[KSYM_NAME_LEN]; |
| 451 | const char *key_name; |
| 452 | |
| 453 | key_name = __get_key_name(class->key, str); |
| 454 | snprintf(name, namelen, "%s", key_name); |
| 455 | } else { |
| 456 | snprintf(name, namelen, "%s", class->name); |
| 457 | } |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 458 | namelen = strlen(name); |
Peter Zijlstra | d38e1d5 | 2007-07-19 01:49:01 -0700 | [diff] [blame] | 459 | if (class->name_version > 1) { |
| 460 | snprintf(name+namelen, 3, "#%d", class->name_version); |
| 461 | namelen += 2; |
| 462 | } |
| 463 | if (class->subclass) { |
| 464 | snprintf(name+namelen, 3, "/%d", class->subclass); |
| 465 | namelen += 2; |
| 466 | } |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 467 | |
| 468 | if (stats->write_holdtime.nr) { |
| 469 | if (stats->read_holdtime.nr) |
| 470 | seq_printf(m, "%38s-W:", name); |
| 471 | else |
| 472 | seq_printf(m, "%40s:", name); |
| 473 | |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 474 | seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 475 | seq_lock_time(m, &stats->write_waittime); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 476 | seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 477 | seq_lock_time(m, &stats->write_holdtime); |
| 478 | seq_puts(m, "\n"); |
| 479 | } |
| 480 | |
| 481 | if (stats->read_holdtime.nr) { |
| 482 | seq_printf(m, "%38s-R:", name); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 483 | seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 484 | seq_lock_time(m, &stats->read_waittime); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 485 | seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 486 | seq_lock_time(m, &stats->read_holdtime); |
| 487 | seq_puts(m, "\n"); |
| 488 | } |
| 489 | |
| 490 | if (stats->read_waittime.nr + stats->write_waittime.nr == 0) |
| 491 | return; |
| 492 | |
| 493 | if (stats->read_holdtime.nr) |
| 494 | namelen += 2; |
| 495 | |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 496 | for (i = 0; i < LOCKSTAT_POINTS; i++) { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 497 | char sym[KSYM_SYMBOL_LEN]; |
| 498 | char ip[32]; |
| 499 | |
| 500 | if (class->contention_point[i] == 0) |
| 501 | break; |
| 502 | |
| 503 | if (!i) |
| 504 | seq_line(m, '-', 40-namelen, namelen); |
| 505 | |
| 506 | sprint_symbol(sym, class->contention_point[i]); |
| 507 | snprintf(ip, sizeof(ip), "[<%p>]", |
| 508 | (void *)class->contention_point[i]); |
| 509 | seq_printf(m, "%40s %14lu %29s %s\n", name, |
| 510 | stats->contention_point[i], |
| 511 | ip, sym); |
| 512 | } |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 513 | for (i = 0; i < LOCKSTAT_POINTS; i++) { |
| 514 | char sym[KSYM_SYMBOL_LEN]; |
| 515 | char ip[32]; |
| 516 | |
| 517 | if (class->contending_point[i] == 0) |
| 518 | break; |
| 519 | |
| 520 | if (!i) |
| 521 | seq_line(m, '-', 40-namelen, namelen); |
| 522 | |
| 523 | sprint_symbol(sym, class->contending_point[i]); |
| 524 | snprintf(ip, sizeof(ip), "[<%p>]", |
| 525 | (void *)class->contending_point[i]); |
| 526 | seq_printf(m, "%40s %14lu %29s %s\n", name, |
| 527 | stats->contending_point[i], |
| 528 | ip, sym); |
| 529 | } |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 530 | if (i) { |
| 531 | seq_puts(m, "\n"); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 532 | seq_line(m, '.', 0, 40 + 1 + 10 * (14 + 1)); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 533 | seq_puts(m, "\n"); |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | static void seq_header(struct seq_file *m) |
| 538 | { |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 539 | seq_printf(m, "lock_stat version 0.3\n"); |
Peter Zijlstra | 9833f8c | 2009-02-14 16:59:04 +0100 | [diff] [blame] | 540 | |
| 541 | if (unlikely(!debug_locks)) |
| 542 | seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n"); |
| 543 | |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 544 | seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1)); |
| 545 | seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s " |
| 546 | "%14s %14s\n", |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 547 | "class name", |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 548 | "con-bounces", |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 549 | "contentions", |
| 550 | "waittime-min", |
| 551 | "waittime-max", |
| 552 | "waittime-total", |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 553 | "acq-bounces", |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 554 | "acquisitions", |
| 555 | "holdtime-min", |
| 556 | "holdtime-max", |
| 557 | "holdtime-total"); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 558 | seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1)); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 559 | seq_printf(m, "\n"); |
| 560 | } |
| 561 | |
| 562 | static void *ls_start(struct seq_file *m, loff_t *pos) |
| 563 | { |
| 564 | struct lock_stat_seq *data = m->private; |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 565 | struct lock_stat_data *iter; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 566 | |
Tim Pepper | 94c61c0 | 2007-10-11 22:11:11 +0200 | [diff] [blame] | 567 | if (*pos == 0) |
| 568 | return SEQ_START_TOKEN; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 569 | |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 570 | iter = data->stats + (*pos - 1); |
| 571 | if (iter >= data->iter_end) |
| 572 | iter = NULL; |
Peter Zijlstra | 4b32d0a | 2007-07-19 01:48:59 -0700 | [diff] [blame] | 573 | |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 574 | return iter; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) |
| 578 | { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 579 | (*pos)++; |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 580 | return ls_start(m, pos); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static void ls_stop(struct seq_file *m, void *v) |
| 584 | { |
| 585 | } |
| 586 | |
| 587 | static int ls_show(struct seq_file *m, void *v) |
| 588 | { |
Tim Pepper | 94c61c0 | 2007-10-11 22:11:11 +0200 | [diff] [blame] | 589 | if (v == SEQ_START_TOKEN) |
| 590 | seq_header(m); |
| 591 | else |
| 592 | seq_stats(m, v); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 593 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 594 | return 0; |
| 595 | } |
| 596 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 597 | static const struct seq_operations lockstat_ops = { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 598 | .start = ls_start, |
| 599 | .next = ls_next, |
| 600 | .stop = ls_stop, |
| 601 | .show = ls_show, |
| 602 | }; |
| 603 | |
| 604 | static int lock_stat_open(struct inode *inode, struct file *file) |
| 605 | { |
| 606 | int res; |
| 607 | struct lock_class *class; |
| 608 | struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq)); |
| 609 | |
| 610 | if (!data) |
| 611 | return -ENOMEM; |
| 612 | |
| 613 | res = seq_open(file, &lockstat_ops); |
| 614 | if (!res) { |
| 615 | struct lock_stat_data *iter = data->stats; |
| 616 | struct seq_file *m = file->private_data; |
| 617 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 618 | list_for_each_entry(class, &all_lock_classes, lock_entry) { |
| 619 | iter->class = class; |
| 620 | iter->stats = lock_stats(class); |
| 621 | iter++; |
| 622 | } |
| 623 | data->iter_end = iter; |
| 624 | |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 625 | sort(data->stats, data->iter_end - data->stats, |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 626 | sizeof(struct lock_stat_data), |
| 627 | lock_stat_cmp, NULL); |
| 628 | |
| 629 | m->private = data; |
| 630 | } else |
| 631 | vfree(data); |
| 632 | |
| 633 | return res; |
| 634 | } |
| 635 | |
| 636 | static ssize_t lock_stat_write(struct file *file, const char __user *buf, |
| 637 | size_t count, loff_t *ppos) |
| 638 | { |
| 639 | struct lock_class *class; |
| 640 | char c; |
| 641 | |
| 642 | if (count) { |
| 643 | if (get_user(c, buf)) |
| 644 | return -EFAULT; |
| 645 | |
| 646 | if (c != '0') |
| 647 | return count; |
| 648 | |
| 649 | list_for_each_entry(class, &all_lock_classes, lock_entry) |
| 650 | clear_lock_stats(class); |
| 651 | } |
| 652 | return count; |
| 653 | } |
| 654 | |
| 655 | static int lock_stat_release(struct inode *inode, struct file *file) |
| 656 | { |
| 657 | struct seq_file *seq = file->private_data; |
| 658 | |
| 659 | vfree(seq->private); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 660 | return seq_release(inode, file); |
| 661 | } |
| 662 | |
| 663 | static const struct file_operations proc_lock_stat_operations = { |
| 664 | .open = lock_stat_open, |
| 665 | .write = lock_stat_write, |
| 666 | .read = seq_read, |
| 667 | .llseek = seq_lseek, |
| 668 | .release = lock_stat_release, |
| 669 | }; |
| 670 | #endif /* CONFIG_LOCK_STAT */ |
| 671 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 672 | static int __init lockdep_proc_init(void) |
| 673 | { |
Denis V. Lunev | c33fff0 | 2008-04-29 01:02:31 -0700 | [diff] [blame] | 674 | proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations); |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 675 | #ifdef CONFIG_PROVE_LOCKING |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 676 | proc_create("lockdep_chains", S_IRUSR, NULL, |
| 677 | &proc_lockdep_chains_operations); |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 678 | #endif |
Denis V. Lunev | c33fff0 | 2008-04-29 01:02:31 -0700 | [diff] [blame] | 679 | proc_create("lockdep_stats", S_IRUSR, NULL, |
| 680 | &proc_lockdep_stats_operations); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 681 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 682 | #ifdef CONFIG_LOCK_STAT |
Li Zefan | 9795447 | 2009-08-07 16:37:10 +0800 | [diff] [blame] | 683 | proc_create("lock_stat", S_IRUSR | S_IWUSR, NULL, |
| 684 | &proc_lock_stat_operations); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 685 | #endif |
| 686 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | __initcall(lockdep_proc_init); |
| 691 | |