blob: 20dbcbf9c7dd2cf34486f3e9f307f1e3cf8a97bc [file] [log] [blame]
Ingo Molnara8f24a32006-07-03 00:24:52 -07001/*
2 * kernel/lockdep_proc.c
3 *
4 * Runtime locking correctness validator
5 *
6 * Started by Ingo Molnar:
7 *
Peter Zijlstra4b32d0a2007-07-19 01:48:59 -07008 * 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 Molnara8f24a32006-07-03 00:24:52 -070010 *
11 * Code for /proc/lockdep and /proc/lockdep_stats:
12 *
13 */
Ingo Molnara8f24a32006-07-03 00:24:52 -070014#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 Zijlstrac46261d2007-07-19 01:48:57 -070019#include <linux/vmalloc.h>
20#include <linux/sort.h>
21#include <asm/uaccess.h>
22#include <asm/div64.h>
Ingo Molnara8f24a32006-07-03 00:24:52 -070023
24#include "lockdep_internals.h"
25
26static void *l_next(struct seq_file *m, void *v, loff_t *pos)
27{
Tim Pepper94c61c02007-10-11 22:11:11 +020028 struct lock_class *class;
Ingo Molnara8f24a32006-07-03 00:24:52 -070029
30 (*pos)++;
31
Tim Pepper94c61c02007-10-11 22:11:11 +020032 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 Molnara8f24a32006-07-03 00:24:52 -070043
44 return class;
45}
46
47static void *l_start(struct seq_file *m, loff_t *pos)
48{
Tim Pepper94c61c02007-10-11 22:11:11 +020049 struct lock_class *class;
50 loff_t i = 0;
Ingo Molnara8f24a32006-07-03 00:24:52 -070051
Tim Pepper94c61c02007-10-11 22:11:11 +020052 if (*pos == 0)
53 return SEQ_START_TOKEN;
Ingo Molnara8f24a32006-07-03 00:24:52 -070054
Tim Pepper94c61c02007-10-11 22:11:11 +020055 list_for_each_entry(class, &all_lock_classes, lock_entry) {
56 if (++i == *pos)
57 return class;
58 }
59 return NULL;
Ingo Molnara8f24a32006-07-03 00:24:52 -070060}
61
62static void l_stop(struct seq_file *m, void *v)
63{
64}
65
Jason Baron068135e2007-02-10 01:44:59 -080066static void print_name(struct seq_file *m, struct lock_class *class)
67{
68 char str[128];
69 const char *name = class->name;
70
71 if (!name) {
72 name = __get_key_name(class->key, str);
73 seq_printf(m, "%s", name);
74 } else{
75 seq_printf(m, "%s", name);
76 if (class->name_version > 1)
77 seq_printf(m, "#%d", class->name_version);
78 if (class->subclass)
79 seq_printf(m, "/%d", class->subclass);
80 }
81}
82
Ingo Molnara8f24a32006-07-03 00:24:52 -070083static int l_show(struct seq_file *m, void *v)
84{
Tim Pepper94c61c02007-10-11 22:11:11 +020085 struct lock_class *class = v;
Jason Baron068135e2007-02-10 01:44:59 -080086 struct lock_list *entry;
87 char c1, c2, c3, c4;
Ingo Molnara8f24a32006-07-03 00:24:52 -070088
Tim Pepper94c61c02007-10-11 22:11:11 +020089 if (v == SEQ_START_TOKEN) {
90 seq_printf(m, "all lock classes:\n");
91 return 0;
92 }
93
Ingo Molnara8f24a32006-07-03 00:24:52 -070094 seq_printf(m, "%p", class->key);
95#ifdef CONFIG_DEBUG_LOCKDEP
96 seq_printf(m, " OPS:%8ld", class->ops);
97#endif
Stephen Hemmingerdf60a842008-08-15 09:33:05 -070098#ifdef CONFIG_PROVE_LOCKING
99 seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
100 seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));
101#endif
Ingo Molnara8f24a32006-07-03 00:24:52 -0700102
103 get_usage_chars(class, &c1, &c2, &c3, &c4);
104 seq_printf(m, " %c%c%c%c", c1, c2, c3, c4);
105
Jason Baron068135e2007-02-10 01:44:59 -0800106 seq_printf(m, ": ");
107 print_name(m, class);
108 seq_puts(m, "\n");
109
110 list_for_each_entry(entry, &class->locks_after, entry) {
111 if (entry->distance == 1) {
Huang, Ying2429e4e2008-06-13 14:40:17 +0800112 seq_printf(m, " -> [%p] ", entry->class->key);
Jason Baron068135e2007-02-10 01:44:59 -0800113 print_name(m, entry->class);
114 seq_puts(m, "\n");
115 }
Ingo Molnara8f24a32006-07-03 00:24:52 -0700116 }
117 seq_puts(m, "\n");
118
119 return 0;
120}
121
Helge Deller15ad7cd2006-12-06 20:40:36 -0800122static const struct seq_operations lockdep_ops = {
Ingo Molnara8f24a32006-07-03 00:24:52 -0700123 .start = l_start,
124 .next = l_next,
125 .stop = l_stop,
126 .show = l_show,
127};
128
129static int lockdep_open(struct inode *inode, struct file *file)
130{
131 int res = seq_open(file, &lockdep_ops);
132 if (!res) {
133 struct seq_file *m = file->private_data;
134
135 if (!list_empty(&all_lock_classes))
136 m->private = list_entry(all_lock_classes.next,
137 struct lock_class, lock_entry);
138 else
139 m->private = NULL;
140 }
141 return res;
142}
143
Helge Deller15ad7cd2006-12-06 20:40:36 -0800144static const struct file_operations proc_lockdep_operations = {
Ingo Molnara8f24a32006-07-03 00:24:52 -0700145 .open = lockdep_open,
146 .read = seq_read,
147 .llseek = seq_lseek,
148 .release = seq_release,
149};
150
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800151#ifdef CONFIG_PROVE_LOCKING
Huang, Ying443cd502008-06-20 16:39:21 +0800152static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
153{
154 struct lock_chain *chain;
155
156 (*pos)++;
157
158 if (v == SEQ_START_TOKEN)
159 chain = m->private;
160 else {
161 chain = v;
162
163 if (*pos < nr_lock_chains)
164 chain = lock_chains + *pos;
165 else
166 chain = NULL;
167 }
168
169 return chain;
170}
171
172static void *lc_start(struct seq_file *m, loff_t *pos)
173{
174 if (*pos == 0)
175 return SEQ_START_TOKEN;
176
177 if (*pos < nr_lock_chains)
178 return lock_chains + *pos;
179
180 return NULL;
181}
182
183static void lc_stop(struct seq_file *m, void *v)
184{
185}
186
187static int lc_show(struct seq_file *m, void *v)
188{
189 struct lock_chain *chain = v;
190 struct lock_class *class;
191 int i;
192
193 if (v == SEQ_START_TOKEN) {
194 seq_printf(m, "all lock chains:\n");
195 return 0;
196 }
197
198 seq_printf(m, "irq_context: %d\n", chain->irq_context);
199
200 for (i = 0; i < chain->depth; i++) {
201 class = lock_chain_get_class(chain, i);
Rabin Vincent8bfe0292008-08-11 09:30:26 +0200202 if (!class->key)
203 continue;
204
Huang, Ying443cd502008-06-20 16:39:21 +0800205 seq_printf(m, "[%p] ", class->key);
206 print_name(m, class);
207 seq_puts(m, "\n");
208 }
209 seq_puts(m, "\n");
210
211 return 0;
212}
213
214static const struct seq_operations lockdep_chains_ops = {
215 .start = lc_start,
216 .next = lc_next,
217 .stop = lc_stop,
218 .show = lc_show,
219};
220
221static int lockdep_chains_open(struct inode *inode, struct file *file)
222{
223 int res = seq_open(file, &lockdep_chains_ops);
224 if (!res) {
225 struct seq_file *m = file->private_data;
226
227 if (nr_lock_chains)
228 m->private = lock_chains;
229 else
230 m->private = NULL;
231 }
232 return res;
233}
234
235static const struct file_operations proc_lockdep_chains_operations = {
236 .open = lockdep_chains_open,
237 .read = seq_read,
238 .llseek = seq_lseek,
239 .release = seq_release,
240};
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800241#endif /* CONFIG_PROVE_LOCKING */
Huang, Ying443cd502008-06-20 16:39:21 +0800242
Ingo Molnara8f24a32006-07-03 00:24:52 -0700243static void lockdep_stats_debug_show(struct seq_file *m)
244{
245#ifdef CONFIG_DEBUG_LOCKDEP
246 unsigned int hi1 = debug_atomic_read(&hardirqs_on_events),
247 hi2 = debug_atomic_read(&hardirqs_off_events),
248 hr1 = debug_atomic_read(&redundant_hardirqs_on),
249 hr2 = debug_atomic_read(&redundant_hardirqs_off),
250 si1 = debug_atomic_read(&softirqs_on_events),
251 si2 = debug_atomic_read(&softirqs_off_events),
252 sr1 = debug_atomic_read(&redundant_softirqs_on),
253 sr2 = debug_atomic_read(&redundant_softirqs_off);
254
255 seq_printf(m, " chain lookup misses: %11u\n",
256 debug_atomic_read(&chain_lookup_misses));
257 seq_printf(m, " chain lookup hits: %11u\n",
258 debug_atomic_read(&chain_lookup_hits));
259 seq_printf(m, " cyclic checks: %11u\n",
260 debug_atomic_read(&nr_cyclic_checks));
261 seq_printf(m, " cyclic-check recursions: %11u\n",
262 debug_atomic_read(&nr_cyclic_check_recursions));
263 seq_printf(m, " find-mask forwards checks: %11u\n",
264 debug_atomic_read(&nr_find_usage_forwards_checks));
265 seq_printf(m, " find-mask forwards recursions: %11u\n",
266 debug_atomic_read(&nr_find_usage_forwards_recursions));
267 seq_printf(m, " find-mask backwards checks: %11u\n",
268 debug_atomic_read(&nr_find_usage_backwards_checks));
269 seq_printf(m, " find-mask backwards recursions:%11u\n",
270 debug_atomic_read(&nr_find_usage_backwards_recursions));
271
272 seq_printf(m, " hardirq on events: %11u\n", hi1);
273 seq_printf(m, " hardirq off events: %11u\n", hi2);
274 seq_printf(m, " redundant hardirq ons: %11u\n", hr1);
275 seq_printf(m, " redundant hardirq offs: %11u\n", hr2);
276 seq_printf(m, " softirq on events: %11u\n", si1);
277 seq_printf(m, " softirq off events: %11u\n", si2);
278 seq_printf(m, " redundant softirq ons: %11u\n", sr1);
279 seq_printf(m, " redundant softirq offs: %11u\n", sr2);
280#endif
281}
282
283static int lockdep_stats_show(struct seq_file *m, void *v)
284{
285 struct lock_class *class;
286 unsigned long nr_unused = 0, nr_uncategorized = 0,
287 nr_irq_safe = 0, nr_irq_unsafe = 0,
288 nr_softirq_safe = 0, nr_softirq_unsafe = 0,
289 nr_hardirq_safe = 0, nr_hardirq_unsafe = 0,
290 nr_irq_read_safe = 0, nr_irq_read_unsafe = 0,
291 nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0,
292 nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0,
293 sum_forward_deps = 0, factor = 0;
294
295 list_for_each_entry(class, &all_lock_classes, lock_entry) {
296
297 if (class->usage_mask == 0)
298 nr_unused++;
299 if (class->usage_mask == LOCKF_USED)
300 nr_uncategorized++;
301 if (class->usage_mask & LOCKF_USED_IN_IRQ)
302 nr_irq_safe++;
303 if (class->usage_mask & LOCKF_ENABLED_IRQS)
304 nr_irq_unsafe++;
305 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
306 nr_softirq_safe++;
307 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQS)
308 nr_softirq_unsafe++;
309 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ)
310 nr_hardirq_safe++;
311 if (class->usage_mask & LOCKF_ENABLED_HARDIRQS)
312 nr_hardirq_unsafe++;
313 if (class->usage_mask & LOCKF_USED_IN_IRQ_READ)
314 nr_irq_read_safe++;
315 if (class->usage_mask & LOCKF_ENABLED_IRQS_READ)
316 nr_irq_read_unsafe++;
317 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
318 nr_softirq_read_safe++;
319 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQS_READ)
320 nr_softirq_read_unsafe++;
321 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
322 nr_hardirq_read_safe++;
323 if (class->usage_mask & LOCKF_ENABLED_HARDIRQS_READ)
324 nr_hardirq_read_unsafe++;
325
Stephen Hemmingerdf60a842008-08-15 09:33:05 -0700326#ifdef CONFIG_PROVE_LOCKING
David Miller419ca3f2008-07-29 21:45:03 -0700327 sum_forward_deps += lockdep_count_forward_deps(class);
Stephen Hemmingerdf60a842008-08-15 09:33:05 -0700328#endif
Ingo Molnara8f24a32006-07-03 00:24:52 -0700329 }
Robert P. J. Day501b9eb2007-02-10 01:46:34 -0800330#ifdef CONFIG_DEBUG_LOCKDEP
Ingo Molnara8f24a32006-07-03 00:24:52 -0700331 DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused);
332#endif
333 seq_printf(m, " lock-classes: %11lu [max: %lu]\n",
334 nr_lock_classes, MAX_LOCKDEP_KEYS);
335 seq_printf(m, " direct dependencies: %11lu [max: %lu]\n",
336 nr_list_entries, MAX_LOCKDEP_ENTRIES);
337 seq_printf(m, " indirect dependencies: %11lu\n",
338 sum_forward_deps);
339
340 /*
341 * Total number of dependencies:
342 *
343 * All irq-safe locks may nest inside irq-unsafe locks,
344 * plus all the other known dependencies:
345 */
346 seq_printf(m, " all direct dependencies: %11lu\n",
347 nr_irq_unsafe * nr_irq_safe +
348 nr_hardirq_unsafe * nr_hardirq_safe +
349 nr_list_entries);
350
351 /*
352 * Estimated factor between direct and indirect
353 * dependencies:
354 */
355 if (nr_list_entries)
356 factor = sum_forward_deps / nr_list_entries;
357
Peter Zijlstra8e182572007-07-19 01:48:54 -0700358#ifdef CONFIG_PROVE_LOCKING
Ingo Molnara8f24a32006-07-03 00:24:52 -0700359 seq_printf(m, " dependency chains: %11lu [max: %lu]\n",
360 nr_lock_chains, MAX_LOCKDEP_CHAINS);
Huang, Ying443cd502008-06-20 16:39:21 +0800361 seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n",
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800362 nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
Peter Zijlstra8e182572007-07-19 01:48:54 -0700363#endif
Ingo Molnara8f24a32006-07-03 00:24:52 -0700364
365#ifdef CONFIG_TRACE_IRQFLAGS
366 seq_printf(m, " in-hardirq chains: %11u\n",
367 nr_hardirq_chains);
368 seq_printf(m, " in-softirq chains: %11u\n",
369 nr_softirq_chains);
370#endif
371 seq_printf(m, " in-process chains: %11u\n",
372 nr_process_chains);
373 seq_printf(m, " stack-trace entries: %11lu [max: %lu]\n",
374 nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES);
375 seq_printf(m, " combined max dependencies: %11u\n",
376 (nr_hardirq_chains + 1) *
377 (nr_softirq_chains + 1) *
378 (nr_process_chains + 1)
379 );
380 seq_printf(m, " hardirq-safe locks: %11lu\n",
381 nr_hardirq_safe);
382 seq_printf(m, " hardirq-unsafe locks: %11lu\n",
383 nr_hardirq_unsafe);
384 seq_printf(m, " softirq-safe locks: %11lu\n",
385 nr_softirq_safe);
386 seq_printf(m, " softirq-unsafe locks: %11lu\n",
387 nr_softirq_unsafe);
388 seq_printf(m, " irq-safe locks: %11lu\n",
389 nr_irq_safe);
390 seq_printf(m, " irq-unsafe locks: %11lu\n",
391 nr_irq_unsafe);
392
393 seq_printf(m, " hardirq-read-safe locks: %11lu\n",
394 nr_hardirq_read_safe);
395 seq_printf(m, " hardirq-read-unsafe locks: %11lu\n",
396 nr_hardirq_read_unsafe);
397 seq_printf(m, " softirq-read-safe locks: %11lu\n",
398 nr_softirq_read_safe);
399 seq_printf(m, " softirq-read-unsafe locks: %11lu\n",
400 nr_softirq_read_unsafe);
401 seq_printf(m, " irq-read-safe locks: %11lu\n",
402 nr_irq_read_safe);
403 seq_printf(m, " irq-read-unsafe locks: %11lu\n",
404 nr_irq_read_unsafe);
405
406 seq_printf(m, " uncategorized locks: %11lu\n",
407 nr_uncategorized);
408 seq_printf(m, " unused locks: %11lu\n",
409 nr_unused);
410 seq_printf(m, " max locking depth: %11u\n",
411 max_lockdep_depth);
412 seq_printf(m, " max recursion depth: %11u\n",
413 max_recursion_depth);
414 lockdep_stats_debug_show(m);
415 seq_printf(m, " debug_locks: %11u\n",
416 debug_locks);
417
418 return 0;
419}
420
421static int lockdep_stats_open(struct inode *inode, struct file *file)
422{
423 return single_open(file, lockdep_stats_show, NULL);
424}
425
Helge Deller15ad7cd2006-12-06 20:40:36 -0800426static const struct file_operations proc_lockdep_stats_operations = {
Ingo Molnara8f24a32006-07-03 00:24:52 -0700427 .open = lockdep_stats_open,
428 .read = seq_read,
429 .llseek = seq_lseek,
Alexey Dobriyanc0f33582007-07-31 00:38:50 -0700430 .release = single_release,
Ingo Molnara8f24a32006-07-03 00:24:52 -0700431};
432
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700433#ifdef CONFIG_LOCK_STAT
434
435struct lock_stat_data {
436 struct lock_class *class;
437 struct lock_class_stats stats;
438};
439
440struct lock_stat_seq {
441 struct lock_stat_data *iter;
442 struct lock_stat_data *iter_end;
443 struct lock_stat_data stats[MAX_LOCKDEP_KEYS];
444};
445
446/*
447 * sort on absolute number of contentions
448 */
449static int lock_stat_cmp(const void *l, const void *r)
450{
451 const struct lock_stat_data *dl = l, *dr = r;
452 unsigned long nl, nr;
453
454 nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr;
455 nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr;
456
457 return nr - nl;
458}
459
460static void seq_line(struct seq_file *m, char c, int offset, int length)
461{
462 int i;
463
464 for (i = 0; i < offset; i++)
465 seq_puts(m, " ");
466 for (i = 0; i < length; i++)
467 seq_printf(m, "%c", c);
468 seq_puts(m, "\n");
469}
470
471static void snprint_time(char *buf, size_t bufsiz, s64 nr)
472{
473 unsigned long rem;
474
Joe Korty2189459d2008-08-25 17:15:33 -0400475 nr += 5; /* for display rounding */
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700476 rem = do_div(nr, 1000); /* XXX: do_div_signed */
Joe Korty2189459d2008-08-25 17:15:33 -0400477 snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, (int)rem/10);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700478}
479
480static void seq_time(struct seq_file *m, s64 time)
481{
482 char num[15];
483
484 snprint_time(num, sizeof(num), time);
485 seq_printf(m, " %14s", num);
486}
487
488static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
489{
490 seq_printf(m, "%14lu", lt->nr);
491 seq_time(m, lt->min);
492 seq_time(m, lt->max);
493 seq_time(m, lt->total);
494}
495
496static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
497{
498 char name[39];
499 struct lock_class *class;
500 struct lock_class_stats *stats;
501 int i, namelen;
502
503 class = data->class;
504 stats = &data->stats;
505
Peter Zijlstrad38e1d52007-07-19 01:49:01 -0700506 namelen = 38;
507 if (class->name_version > 1)
508 namelen -= 2; /* XXX truncates versions > 9 */
509 if (class->subclass)
510 namelen -= 2;
511
512 if (!class->name) {
513 char str[KSYM_NAME_LEN];
514 const char *key_name;
515
516 key_name = __get_key_name(class->key, str);
517 snprintf(name, namelen, "%s", key_name);
518 } else {
519 snprintf(name, namelen, "%s", class->name);
520 }
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700521 namelen = strlen(name);
Peter Zijlstrad38e1d52007-07-19 01:49:01 -0700522 if (class->name_version > 1) {
523 snprintf(name+namelen, 3, "#%d", class->name_version);
524 namelen += 2;
525 }
526 if (class->subclass) {
527 snprintf(name+namelen, 3, "/%d", class->subclass);
528 namelen += 2;
529 }
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700530
531 if (stats->write_holdtime.nr) {
532 if (stats->read_holdtime.nr)
533 seq_printf(m, "%38s-W:", name);
534 else
535 seq_printf(m, "%40s:", name);
536
Peter Zijlstra96645672007-07-19 01:49:00 -0700537 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700538 seq_lock_time(m, &stats->write_waittime);
Peter Zijlstra96645672007-07-19 01:49:00 -0700539 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700540 seq_lock_time(m, &stats->write_holdtime);
541 seq_puts(m, "\n");
542 }
543
544 if (stats->read_holdtime.nr) {
545 seq_printf(m, "%38s-R:", name);
Peter Zijlstra96645672007-07-19 01:49:00 -0700546 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700547 seq_lock_time(m, &stats->read_waittime);
Peter Zijlstra96645672007-07-19 01:49:00 -0700548 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700549 seq_lock_time(m, &stats->read_holdtime);
550 seq_puts(m, "\n");
551 }
552
553 if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
554 return;
555
556 if (stats->read_holdtime.nr)
557 namelen += 2;
558
559 for (i = 0; i < ARRAY_SIZE(class->contention_point); i++) {
560 char sym[KSYM_SYMBOL_LEN];
561 char ip[32];
562
563 if (class->contention_point[i] == 0)
564 break;
565
566 if (!i)
567 seq_line(m, '-', 40-namelen, namelen);
568
569 sprint_symbol(sym, class->contention_point[i]);
570 snprintf(ip, sizeof(ip), "[<%p>]",
571 (void *)class->contention_point[i]);
572 seq_printf(m, "%40s %14lu %29s %s\n", name,
573 stats->contention_point[i],
574 ip, sym);
575 }
576 if (i) {
577 seq_puts(m, "\n");
Peter Zijlstra96645672007-07-19 01:49:00 -0700578 seq_line(m, '.', 0, 40 + 1 + 10 * (14 + 1));
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700579 seq_puts(m, "\n");
580 }
581}
582
583static void seq_header(struct seq_file *m)
584{
Peter Zijlstra96645672007-07-19 01:49:00 -0700585 seq_printf(m, "lock_stat version 0.2\n");
586 seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
587 seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s "
588 "%14s %14s\n",
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700589 "class name",
Peter Zijlstra96645672007-07-19 01:49:00 -0700590 "con-bounces",
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700591 "contentions",
592 "waittime-min",
593 "waittime-max",
594 "waittime-total",
Peter Zijlstra96645672007-07-19 01:49:00 -0700595 "acq-bounces",
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700596 "acquisitions",
597 "holdtime-min",
598 "holdtime-max",
599 "holdtime-total");
Peter Zijlstra96645672007-07-19 01:49:00 -0700600 seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700601 seq_printf(m, "\n");
602}
603
604static void *ls_start(struct seq_file *m, loff_t *pos)
605{
606 struct lock_stat_seq *data = m->private;
607
Tim Pepper94c61c02007-10-11 22:11:11 +0200608 if (*pos == 0)
609 return SEQ_START_TOKEN;
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700610
Tim Pepper94c61c02007-10-11 22:11:11 +0200611 data->iter = data->stats + *pos;
612 if (data->iter >= data->iter_end)
Peter Zijlstra4b32d0a2007-07-19 01:48:59 -0700613 data->iter = NULL;
614
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700615 return data->iter;
616}
617
618static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
619{
620 struct lock_stat_seq *data = m->private;
621
622 (*pos)++;
623
Tim Pepper94c61c02007-10-11 22:11:11 +0200624 if (v == SEQ_START_TOKEN)
625 data->iter = data->stats;
626 else {
627 data->iter = v;
628 data->iter++;
629 }
630
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700631 if (data->iter == data->iter_end)
632 data->iter = NULL;
633
634 return data->iter;
635}
636
637static void ls_stop(struct seq_file *m, void *v)
638{
639}
640
641static int ls_show(struct seq_file *m, void *v)
642{
Tim Pepper94c61c02007-10-11 22:11:11 +0200643 if (v == SEQ_START_TOKEN)
644 seq_header(m);
645 else
646 seq_stats(m, v);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700647
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700648 return 0;
649}
650
651static struct seq_operations lockstat_ops = {
652 .start = ls_start,
653 .next = ls_next,
654 .stop = ls_stop,
655 .show = ls_show,
656};
657
658static int lock_stat_open(struct inode *inode, struct file *file)
659{
660 int res;
661 struct lock_class *class;
662 struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
663
664 if (!data)
665 return -ENOMEM;
666
667 res = seq_open(file, &lockstat_ops);
668 if (!res) {
669 struct lock_stat_data *iter = data->stats;
670 struct seq_file *m = file->private_data;
671
672 data->iter = iter;
673 list_for_each_entry(class, &all_lock_classes, lock_entry) {
674 iter->class = class;
675 iter->stats = lock_stats(class);
676 iter++;
677 }
678 data->iter_end = iter;
679
680 sort(data->stats, data->iter_end - data->iter,
681 sizeof(struct lock_stat_data),
682 lock_stat_cmp, NULL);
683
684 m->private = data;
685 } else
686 vfree(data);
687
688 return res;
689}
690
691static ssize_t lock_stat_write(struct file *file, const char __user *buf,
692 size_t count, loff_t *ppos)
693{
694 struct lock_class *class;
695 char c;
696
697 if (count) {
698 if (get_user(c, buf))
699 return -EFAULT;
700
701 if (c != '0')
702 return count;
703
704 list_for_each_entry(class, &all_lock_classes, lock_entry)
705 clear_lock_stats(class);
706 }
707 return count;
708}
709
710static int lock_stat_release(struct inode *inode, struct file *file)
711{
712 struct seq_file *seq = file->private_data;
713
714 vfree(seq->private);
715 seq->private = NULL;
716 return seq_release(inode, file);
717}
718
719static const struct file_operations proc_lock_stat_operations = {
720 .open = lock_stat_open,
721 .write = lock_stat_write,
722 .read = seq_read,
723 .llseek = seq_lseek,
724 .release = lock_stat_release,
725};
726#endif /* CONFIG_LOCK_STAT */
727
Ingo Molnara8f24a32006-07-03 00:24:52 -0700728static int __init lockdep_proc_init(void)
729{
Denis V. Lunevc33fff02008-04-29 01:02:31 -0700730 proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800731#ifdef CONFIG_PROVE_LOCKING
Huang, Ying443cd502008-06-20 16:39:21 +0800732 proc_create("lockdep_chains", S_IRUSR, NULL,
733 &proc_lockdep_chains_operations);
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800734#endif
Denis V. Lunevc33fff02008-04-29 01:02:31 -0700735 proc_create("lockdep_stats", S_IRUSR, NULL,
736 &proc_lockdep_stats_operations);
Ingo Molnara8f24a32006-07-03 00:24:52 -0700737
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700738#ifdef CONFIG_LOCK_STAT
Denis V. Lunevc33fff02008-04-29 01:02:31 -0700739 proc_create("lock_stat", S_IRUSR, NULL, &proc_lock_stat_operations);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700740#endif
741
Ingo Molnara8f24a32006-07-03 00:24:52 -0700742 return 0;
743}
744
745__initcall(lockdep_proc_init);
746