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