Merge branch 'upstream' of git://git.infradead.org/users/pcmoore/audit
[deliverable/linux.git] / kernel / locking / lockdep_proc.c
CommitLineData
a8f24a39
IM
1/*
2 * kernel/lockdep_proc.c
3 *
4 * Runtime locking correctness validator
5 *
6 * Started by Ingo Molnar:
7 *
4b32d0a4
PZ
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>
a8f24a39
IM
10 *
11 * Code for /proc/lockdep and /proc/lockdep_stats:
12 *
13 */
9984de1a 14#include <linux/export.h>
a8f24a39
IM
15#include <linux/proc_fs.h>
16#include <linux/seq_file.h>
17#include <linux/kallsyms.h>
18#include <linux/debug_locks.h>
c46261de
PZ
19#include <linux/vmalloc.h>
20#include <linux/sort.h>
21#include <asm/uaccess.h>
22#include <asm/div64.h>
a8f24a39
IM
23
24#include "lockdep_internals.h"
25
26static void *l_next(struct seq_file *m, void *v, loff_t *pos)
27{
8109e1de 28 return seq_list_next(v, &all_lock_classes, pos);
a8f24a39
IM
29}
30
31static void *l_start(struct seq_file *m, loff_t *pos)
32{
8109e1de 33 return seq_list_start_head(&all_lock_classes, *pos);
a8f24a39
IM
34}
35
36static void l_stop(struct seq_file *m, void *v)
37{
38}
39
068135e6
JB
40static void print_name(struct seq_file *m, struct lock_class *class)
41{
99fb4a12 42 char str[KSYM_NAME_LEN];
068135e6
JB
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
a8f24a39
IM
57static int l_show(struct seq_file *m, void *v)
58{
8109e1de 59 struct lock_class *class = list_entry(v, struct lock_class, lock_entry);
068135e6 60 struct lock_list *entry;
f510b233 61 char usage[LOCK_USAGE_CHARS];
a8f24a39 62
8109e1de 63 if (v == &all_lock_classes) {
94c61c0a
TP
64 seq_printf(m, "all lock classes:\n");
65 return 0;
66 }
67
a8f24a39
IM
68 seq_printf(m, "%p", class->key);
69#ifdef CONFIG_DEBUG_LOCKDEP
70 seq_printf(m, " OPS:%8ld", class->ops);
71#endif
df60a844
SH
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
a8f24a39 76
f510b233
PZ
77 get_usage_chars(class, usage);
78 seq_printf(m, " %s", usage);
a8f24a39 79
068135e6
JB
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) {
2429e4ee 86 seq_printf(m, " -> [%p] ", entry->class->key);
068135e6
JB
87 print_name(m, entry->class);
88 seq_puts(m, "\n");
89 }
a8f24a39
IM
90 }
91 seq_puts(m, "\n");
92
93 return 0;
94}
95
15ad7cdc 96static const struct seq_operations lockdep_ops = {
a8f24a39
IM
97 .start = l_start,
98 .next = l_next,
99 .stop = l_stop,
100 .show = l_show,
101};
102
103static int lockdep_open(struct inode *inode, struct file *file)
104{
8109e1de 105 return seq_open(file, &lockdep_ops);
a8f24a39
IM
106}
107
15ad7cdc 108static const struct file_operations proc_lockdep_operations = {
a8f24a39
IM
109 .open = lockdep_open,
110 .read = seq_read,
111 .llseek = seq_lseek,
112 .release = seq_release,
113};
114
cd1a28e8 115#ifdef CONFIG_PROVE_LOCKING
443cd507
HY
116static void *lc_start(struct seq_file *m, loff_t *pos)
117{
118 if (*pos == 0)
119 return SEQ_START_TOKEN;
120
e9d65725
LZ
121 if (*pos - 1 < nr_lock_chains)
122 return lock_chains + (*pos - 1);
443cd507
HY
123
124 return NULL;
125}
126
12aac19d
LZ
127static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
128{
129 (*pos)++;
130 return lc_start(m, pos);
131}
132
443cd507
HY
133static void lc_stop(struct seq_file *m, void *v)
134{
135}
136
137static 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);
8bfe0298
RV
152 if (!class->key)
153 continue;
154
443cd507
HY
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
164static 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
171static int lockdep_chains_open(struct inode *inode, struct file *file)
172{
12aac19d 173 return seq_open(file, &lockdep_chains_ops);
443cd507
HY
174}
175
176static 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};
cd1a28e8 182#endif /* CONFIG_PROVE_LOCKING */
443cd507 183
a8f24a39
IM
184static void lockdep_stats_debug_show(struct seq_file *m)
185{
186#ifdef CONFIG_DEBUG_LOCKDEP
bd6d29c2
FW
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);
195
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));
206
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);
a8f24a39
IM
215#endif
216}
217
218static 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,
dec29608 228 sum_forward_deps = 0;
a8f24a39
IM
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++;
4fc95e86 238 if (class->usage_mask & LOCKF_ENABLED_IRQ)
a8f24a39
IM
239 nr_irq_unsafe++;
240 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
241 nr_softirq_safe++;
4fc95e86 242 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ)
a8f24a39
IM
243 nr_softirq_unsafe++;
244 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ)
245 nr_hardirq_safe++;
4fc95e86 246 if (class->usage_mask & LOCKF_ENABLED_HARDIRQ)
a8f24a39
IM
247 nr_hardirq_unsafe++;
248 if (class->usage_mask & LOCKF_USED_IN_IRQ_READ)
249 nr_irq_read_safe++;
4fc95e86 250 if (class->usage_mask & LOCKF_ENABLED_IRQ_READ)
a8f24a39
IM
251 nr_irq_read_unsafe++;
252 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
253 nr_softirq_read_safe++;
4fc95e86 254 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ)
a8f24a39
IM
255 nr_softirq_read_unsafe++;
256 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
257 nr_hardirq_read_safe++;
4fc95e86 258 if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ)
a8f24a39
IM
259 nr_hardirq_read_unsafe++;
260
df60a844 261#ifdef CONFIG_PROVE_LOCKING
419ca3f1 262 sum_forward_deps += lockdep_count_forward_deps(class);
df60a844 263#endif
a8f24a39 264 }
501b9ebf 265#ifdef CONFIG_DEBUG_LOCKDEP
bd6d29c2 266 DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused);
a8f24a39
IM
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
8e18257d 286#ifdef CONFIG_PROVE_LOCKING
a8f24a39
IM
287 seq_printf(m, " dependency chains: %11lu [max: %lu]\n",
288 nr_lock_chains, MAX_LOCKDEP_CHAINS);
443cd507 289 seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n",
cd1a28e8 290 nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
8e18257d 291#endif
a8f24a39
IM
292
293#ifdef CONFIG_TRACE_IRQFLAGS
294 seq_printf(m, " in-hardirq chains: %11u\n",
295 nr_hardirq_chains);
296 seq_printf(m, " in-softirq chains: %11u\n",
297 nr_softirq_chains);
298#endif
299 seq_printf(m, " in-process chains: %11u\n",
300 nr_process_chains);
301 seq_printf(m, " stack-trace entries: %11lu [max: %lu]\n",
302 nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES);
303 seq_printf(m, " combined max dependencies: %11u\n",
304 (nr_hardirq_chains + 1) *
305 (nr_softirq_chains + 1) *
306 (nr_process_chains + 1)
307 );
308 seq_printf(m, " hardirq-safe locks: %11lu\n",
309 nr_hardirq_safe);
310 seq_printf(m, " hardirq-unsafe locks: %11lu\n",
311 nr_hardirq_unsafe);
312 seq_printf(m, " softirq-safe locks: %11lu\n",
313 nr_softirq_safe);
314 seq_printf(m, " softirq-unsafe locks: %11lu\n",
315 nr_softirq_unsafe);
316 seq_printf(m, " irq-safe locks: %11lu\n",
317 nr_irq_safe);
318 seq_printf(m, " irq-unsafe locks: %11lu\n",
319 nr_irq_unsafe);
320
321 seq_printf(m, " hardirq-read-safe locks: %11lu\n",
322 nr_hardirq_read_safe);
323 seq_printf(m, " hardirq-read-unsafe locks: %11lu\n",
324 nr_hardirq_read_unsafe);
325 seq_printf(m, " softirq-read-safe locks: %11lu\n",
326 nr_softirq_read_safe);
327 seq_printf(m, " softirq-read-unsafe locks: %11lu\n",
328 nr_softirq_read_unsafe);
329 seq_printf(m, " irq-read-safe locks: %11lu\n",
330 nr_irq_read_safe);
331 seq_printf(m, " irq-read-unsafe locks: %11lu\n",
332 nr_irq_read_unsafe);
333
334 seq_printf(m, " uncategorized locks: %11lu\n",
335 nr_uncategorized);
336 seq_printf(m, " unused locks: %11lu\n",
337 nr_unused);
338 seq_printf(m, " max locking depth: %11u\n",
339 max_lockdep_depth);
bbfa2622 340#ifdef CONFIG_PROVE_LOCKING
12f3dfd0
ML
341 seq_printf(m, " max bfs queue depth: %11u\n",
342 max_bfs_queue_depth);
bbfa2622 343#endif
a8f24a39
IM
344 lockdep_stats_debug_show(m);
345 seq_printf(m, " debug_locks: %11u\n",
346 debug_locks);
347
348 return 0;
349}
350
351static int lockdep_stats_open(struct inode *inode, struct file *file)
352{
353 return single_open(file, lockdep_stats_show, NULL);
354}
355
15ad7cdc 356static const struct file_operations proc_lockdep_stats_operations = {
a8f24a39
IM
357 .open = lockdep_stats_open,
358 .read = seq_read,
359 .llseek = seq_lseek,
c0f33586 360 .release = single_release,
a8f24a39
IM
361};
362
c46261de
PZ
363#ifdef CONFIG_LOCK_STAT
364
365struct lock_stat_data {
366 struct lock_class *class;
367 struct lock_class_stats stats;
368};
369
370struct lock_stat_seq {
c46261de
PZ
371 struct lock_stat_data *iter_end;
372 struct lock_stat_data stats[MAX_LOCKDEP_KEYS];
373};
374
375/*
376 * sort on absolute number of contentions
377 */
378static int lock_stat_cmp(const void *l, const void *r)
379{
380 const struct lock_stat_data *dl = l, *dr = r;
381 unsigned long nl, nr;
382
383 nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr;
384 nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr;
385
386 return nr - nl;
387}
388
389static void seq_line(struct seq_file *m, char c, int offset, int length)
390{
391 int i;
392
393 for (i = 0; i < offset; i++)
394 seq_puts(m, " ");
395 for (i = 0; i < length; i++)
396 seq_printf(m, "%c", c);
397 seq_puts(m, "\n");
398}
399
400static void snprint_time(char *buf, size_t bufsiz, s64 nr)
401{
6918bc5c
PZ
402 s64 div;
403 s32 rem;
c46261de 404
2189459d 405 nr += 5; /* for display rounding */
6918bc5c
PZ
406 div = div_s64_rem(nr, 1000, &rem);
407 snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10);
c46261de
PZ
408}
409
410static void seq_time(struct seq_file *m, s64 time)
411{
412 char num[15];
413
414 snprint_time(num, sizeof(num), time);
415 seq_printf(m, " %14s", num);
416}
417
418static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
419{
420 seq_printf(m, "%14lu", lt->nr);
421 seq_time(m, lt->min);
422 seq_time(m, lt->max);
423 seq_time(m, lt->total);
838cc7b4 424 seq_time(m, lt->nr ? div_s64(lt->total, lt->nr) : 0);
c46261de
PZ
425}
426
427static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
428{
429 char name[39];
430 struct lock_class *class;
431 struct lock_class_stats *stats;
432 int i, namelen;
433
434 class = data->class;
435 stats = &data->stats;
436
d38e1d5a
PZ
437 namelen = 38;
438 if (class->name_version > 1)
439 namelen -= 2; /* XXX truncates versions > 9 */
440 if (class->subclass)
441 namelen -= 2;
442
443 if (!class->name) {
444 char str[KSYM_NAME_LEN];
445 const char *key_name;
446
447 key_name = __get_key_name(class->key, str);
448 snprintf(name, namelen, "%s", key_name);
449 } else {
450 snprintf(name, namelen, "%s", class->name);
451 }
c46261de 452 namelen = strlen(name);
d38e1d5a
PZ
453 if (class->name_version > 1) {
454 snprintf(name+namelen, 3, "#%d", class->name_version);
455 namelen += 2;
456 }
457 if (class->subclass) {
458 snprintf(name+namelen, 3, "/%d", class->subclass);
459 namelen += 2;
460 }
c46261de
PZ
461
462 if (stats->write_holdtime.nr) {
463 if (stats->read_holdtime.nr)
464 seq_printf(m, "%38s-W:", name);
465 else
466 seq_printf(m, "%40s:", name);
467
96645678 468 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
c46261de 469 seq_lock_time(m, &stats->write_waittime);
96645678 470 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
c46261de
PZ
471 seq_lock_time(m, &stats->write_holdtime);
472 seq_puts(m, "\n");
473 }
474
475 if (stats->read_holdtime.nr) {
476 seq_printf(m, "%38s-R:", name);
96645678 477 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
c46261de 478 seq_lock_time(m, &stats->read_waittime);
96645678 479 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
c46261de
PZ
480 seq_lock_time(m, &stats->read_holdtime);
481 seq_puts(m, "\n");
482 }
483
484 if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
485 return;
486
487 if (stats->read_holdtime.nr)
488 namelen += 2;
489
c7e78cff 490 for (i = 0; i < LOCKSTAT_POINTS; i++) {
c46261de
PZ
491 char ip[32];
492
493 if (class->contention_point[i] == 0)
494 break;
495
496 if (!i)
497 seq_line(m, '-', 40-namelen, namelen);
498
c46261de
PZ
499 snprintf(ip, sizeof(ip), "[<%p>]",
500 (void *)class->contention_point[i]);
3cf9b85b
JP
501 seq_printf(m, "%40s %14lu %29s %pS\n",
502 name, stats->contention_point[i],
503 ip, (void *)class->contention_point[i]);
c46261de 504 }
c7e78cff 505 for (i = 0; i < LOCKSTAT_POINTS; i++) {
c7e78cff
PZ
506 char ip[32];
507
508 if (class->contending_point[i] == 0)
509 break;
510
511 if (!i)
512 seq_line(m, '-', 40-namelen, namelen);
513
c7e78cff
PZ
514 snprintf(ip, sizeof(ip), "[<%p>]",
515 (void *)class->contending_point[i]);
3cf9b85b
JP
516 seq_printf(m, "%40s %14lu %29s %pS\n",
517 name, stats->contending_point[i],
518 ip, (void *)class->contending_point[i]);
c7e78cff 519 }
c46261de
PZ
520 if (i) {
521 seq_puts(m, "\n");
1232e380 522 seq_line(m, '.', 0, 40 + 1 + 12 * (14 + 1));
c46261de
PZ
523 seq_puts(m, "\n");
524 }
525}
526
527static void seq_header(struct seq_file *m)
528{
1232e380 529 seq_puts(m, "lock_stat version 0.4\n");
9833f8cb
PZ
530
531 if (unlikely(!debug_locks))
532 seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n");
533
1232e380
DB
534 seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1));
535 seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s "
96645678 536 "%14s %14s\n",
c46261de 537 "class name",
96645678 538 "con-bounces",
c46261de
PZ
539 "contentions",
540 "waittime-min",
541 "waittime-max",
542 "waittime-total",
1232e380 543 "waittime-avg",
96645678 544 "acq-bounces",
c46261de
PZ
545 "acquisitions",
546 "holdtime-min",
547 "holdtime-max",
1232e380
DB
548 "holdtime-total",
549 "holdtime-avg");
550 seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1));
c46261de
PZ
551 seq_printf(m, "\n");
552}
553
554static void *ls_start(struct seq_file *m, loff_t *pos)
555{
556 struct lock_stat_seq *data = m->private;
96004bb2 557 struct lock_stat_data *iter;
c46261de 558
94c61c0a
TP
559 if (*pos == 0)
560 return SEQ_START_TOKEN;
c46261de 561
96004bb2
LZ
562 iter = data->stats + (*pos - 1);
563 if (iter >= data->iter_end)
564 iter = NULL;
4b32d0a4 565
96004bb2 566 return iter;
c46261de
PZ
567}
568
569static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
570{
c46261de 571 (*pos)++;
96004bb2 572 return ls_start(m, pos);
c46261de
PZ
573}
574
575static void ls_stop(struct seq_file *m, void *v)
576{
577}
578
579static int ls_show(struct seq_file *m, void *v)
580{
94c61c0a
TP
581 if (v == SEQ_START_TOKEN)
582 seq_header(m);
583 else
584 seq_stats(m, v);
c46261de 585
c46261de
PZ
586 return 0;
587}
588
88e9d34c 589static const struct seq_operations lockstat_ops = {
c46261de
PZ
590 .start = ls_start,
591 .next = ls_next,
592 .stop = ls_stop,
593 .show = ls_show,
594};
595
596static int lock_stat_open(struct inode *inode, struct file *file)
597{
598 int res;
599 struct lock_class *class;
600 struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq));
601
602 if (!data)
603 return -ENOMEM;
604
605 res = seq_open(file, &lockstat_ops);
606 if (!res) {
607 struct lock_stat_data *iter = data->stats;
608 struct seq_file *m = file->private_data;
609
c46261de
PZ
610 list_for_each_entry(class, &all_lock_classes, lock_entry) {
611 iter->class = class;
612 iter->stats = lock_stats(class);
613 iter++;
614 }
615 data->iter_end = iter;
616
96004bb2 617 sort(data->stats, data->iter_end - data->stats,
c46261de
PZ
618 sizeof(struct lock_stat_data),
619 lock_stat_cmp, NULL);
620
621 m->private = data;
622 } else
623 vfree(data);
624
625 return res;
626}
627
628static ssize_t lock_stat_write(struct file *file, const char __user *buf,
629 size_t count, loff_t *ppos)
630{
631 struct lock_class *class;
632 char c;
633
634 if (count) {
635 if (get_user(c, buf))
636 return -EFAULT;
637
638 if (c != '0')
639 return count;
640
641 list_for_each_entry(class, &all_lock_classes, lock_entry)
642 clear_lock_stats(class);
643 }
644 return count;
645}
646
647static int lock_stat_release(struct inode *inode, struct file *file)
648{
649 struct seq_file *seq = file->private_data;
650
651 vfree(seq->private);
c46261de
PZ
652 return seq_release(inode, file);
653}
654
655static const struct file_operations proc_lock_stat_operations = {
656 .open = lock_stat_open,
657 .write = lock_stat_write,
658 .read = seq_read,
659 .llseek = seq_lseek,
660 .release = lock_stat_release,
661};
662#endif /* CONFIG_LOCK_STAT */
663
a8f24a39
IM
664static int __init lockdep_proc_init(void)
665{
c33fff0a 666 proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
cd1a28e8 667#ifdef CONFIG_PROVE_LOCKING
443cd507
HY
668 proc_create("lockdep_chains", S_IRUSR, NULL,
669 &proc_lockdep_chains_operations);
cd1a28e8 670#endif
c33fff0a
DL
671 proc_create("lockdep_stats", S_IRUSR, NULL,
672 &proc_lockdep_stats_operations);
a8f24a39 673
c46261de 674#ifdef CONFIG_LOCK_STAT
9795447f
LZ
675 proc_create("lock_stat", S_IRUSR | S_IWUSR, NULL,
676 &proc_lock_stat_operations);
c46261de
PZ
677#endif
678
a8f24a39
IM
679 return 0;
680}
681
682__initcall(lockdep_proc_init);
683
This page took 0.580847 seconds and 5 git commands to generate.