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