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