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