]>
Commit | Line | Data |
---|---|---|
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 | */ | |
a8f24a39 IM |
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> | |
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 | ||
26 | static 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 | ||
31 | static 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 | ||
36 | static void l_stop(struct seq_file *m, void *v) | |
37 | { | |
38 | } | |
39 | ||
068135e6 JB |
40 | static void print_name(struct seq_file *m, struct lock_class *class) |
41 | { | |
42 | char str[128]; | |
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 |
57 | static 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 | 96 | static 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 | ||
103 | static int lockdep_open(struct inode *inode, struct file *file) | |
104 | { | |
8109e1de | 105 | return seq_open(file, &lockdep_ops); |
a8f24a39 IM |
106 | } |
107 | ||
15ad7cdc | 108 | static 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 |
116 | static 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 |
127 | static 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 |
133 | static void lc_stop(struct seq_file *m, void *v) |
134 | { | |
135 | } | |
136 | ||
137 | static 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 | ||
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 | }; | |
170 | ||
171 | static int lockdep_chains_open(struct inode *inode, struct file *file) | |
172 | { | |
12aac19d | 173 | return seq_open(file, &lockdep_chains_ops); |
443cd507 HY |
174 | } |
175 | ||
176 | static 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 |
184 | static void lockdep_stats_debug_show(struct seq_file *m) |
185 | { | |
186 | #ifdef CONFIG_DEBUG_LOCKDEP | |
187 | unsigned int 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: %11u\n", | |
197 | debug_atomic_read(&chain_lookup_misses)); | |
198 | seq_printf(m, " chain lookup hits: %11u\n", | |
199 | debug_atomic_read(&chain_lookup_hits)); | |
200 | seq_printf(m, " cyclic checks: %11u\n", | |
201 | debug_atomic_read(&nr_cyclic_checks)); | |
202 | seq_printf(m, " cyclic-check recursions: %11u\n", | |
203 | debug_atomic_read(&nr_cyclic_check_recursions)); | |
204 | seq_printf(m, " find-mask forwards checks: %11u\n", | |
205 | debug_atomic_read(&nr_find_usage_forwards_checks)); | |
206 | seq_printf(m, " find-mask forwards recursions: %11u\n", | |
207 | debug_atomic_read(&nr_find_usage_forwards_recursions)); | |
208 | seq_printf(m, " find-mask backwards checks: %11u\n", | |
209 | debug_atomic_read(&nr_find_usage_backwards_checks)); | |
210 | seq_printf(m, " find-mask backwards recursions:%11u\n", | |
211 | debug_atomic_read(&nr_find_usage_backwards_recursions)); | |
212 | ||
213 | seq_printf(m, " hardirq on events: %11u\n", hi1); | |
214 | seq_printf(m, " hardirq off events: %11u\n", hi2); | |
215 | seq_printf(m, " redundant hardirq ons: %11u\n", hr1); | |
216 | seq_printf(m, " redundant hardirq offs: %11u\n", hr2); | |
217 | seq_printf(m, " softirq on events: %11u\n", si1); | |
218 | seq_printf(m, " softirq off events: %11u\n", si2); | |
219 | seq_printf(m, " redundant softirq ons: %11u\n", sr1); | |
220 | seq_printf(m, " redundant softirq offs: %11u\n", sr2); | |
221 | #endif | |
222 | } | |
223 | ||
224 | static int lockdep_stats_show(struct seq_file *m, void *v) | |
225 | { | |
226 | struct lock_class *class; | |
227 | unsigned long nr_unused = 0, nr_uncategorized = 0, | |
228 | nr_irq_safe = 0, nr_irq_unsafe = 0, | |
229 | nr_softirq_safe = 0, nr_softirq_unsafe = 0, | |
230 | nr_hardirq_safe = 0, nr_hardirq_unsafe = 0, | |
231 | nr_irq_read_safe = 0, nr_irq_read_unsafe = 0, | |
232 | nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0, | |
233 | nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0, | |
234 | sum_forward_deps = 0, factor = 0; | |
235 | ||
236 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | |
237 | ||
238 | if (class->usage_mask == 0) | |
239 | nr_unused++; | |
240 | if (class->usage_mask == LOCKF_USED) | |
241 | nr_uncategorized++; | |
242 | if (class->usage_mask & LOCKF_USED_IN_IRQ) | |
243 | nr_irq_safe++; | |
4fc95e86 | 244 | if (class->usage_mask & LOCKF_ENABLED_IRQ) |
a8f24a39 IM |
245 | nr_irq_unsafe++; |
246 | if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ) | |
247 | nr_softirq_safe++; | |
4fc95e86 | 248 | if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ) |
a8f24a39 IM |
249 | nr_softirq_unsafe++; |
250 | if (class->usage_mask & LOCKF_USED_IN_HARDIRQ) | |
251 | nr_hardirq_safe++; | |
4fc95e86 | 252 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQ) |
a8f24a39 IM |
253 | nr_hardirq_unsafe++; |
254 | if (class->usage_mask & LOCKF_USED_IN_IRQ_READ) | |
255 | nr_irq_read_safe++; | |
4fc95e86 | 256 | if (class->usage_mask & LOCKF_ENABLED_IRQ_READ) |
a8f24a39 IM |
257 | nr_irq_read_unsafe++; |
258 | if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ) | |
259 | nr_softirq_read_safe++; | |
4fc95e86 | 260 | if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ) |
a8f24a39 IM |
261 | nr_softirq_read_unsafe++; |
262 | if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ) | |
263 | nr_hardirq_read_safe++; | |
4fc95e86 | 264 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ) |
a8f24a39 IM |
265 | nr_hardirq_read_unsafe++; |
266 | ||
df60a844 | 267 | #ifdef CONFIG_PROVE_LOCKING |
419ca3f1 | 268 | sum_forward_deps += lockdep_count_forward_deps(class); |
df60a844 | 269 | #endif |
a8f24a39 | 270 | } |
501b9ebf | 271 | #ifdef CONFIG_DEBUG_LOCKDEP |
a8f24a39 IM |
272 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused); |
273 | #endif | |
274 | seq_printf(m, " lock-classes: %11lu [max: %lu]\n", | |
275 | nr_lock_classes, MAX_LOCKDEP_KEYS); | |
276 | seq_printf(m, " direct dependencies: %11lu [max: %lu]\n", | |
277 | nr_list_entries, MAX_LOCKDEP_ENTRIES); | |
278 | seq_printf(m, " indirect dependencies: %11lu\n", | |
279 | sum_forward_deps); | |
280 | ||
281 | /* | |
282 | * Total number of dependencies: | |
283 | * | |
284 | * All irq-safe locks may nest inside irq-unsafe locks, | |
285 | * plus all the other known dependencies: | |
286 | */ | |
287 | seq_printf(m, " all direct dependencies: %11lu\n", | |
288 | nr_irq_unsafe * nr_irq_safe + | |
289 | nr_hardirq_unsafe * nr_hardirq_safe + | |
290 | nr_list_entries); | |
291 | ||
292 | /* | |
293 | * Estimated factor between direct and indirect | |
294 | * dependencies: | |
295 | */ | |
296 | if (nr_list_entries) | |
297 | factor = sum_forward_deps / nr_list_entries; | |
298 | ||
8e18257d | 299 | #ifdef CONFIG_PROVE_LOCKING |
a8f24a39 IM |
300 | seq_printf(m, " dependency chains: %11lu [max: %lu]\n", |
301 | nr_lock_chains, MAX_LOCKDEP_CHAINS); | |
443cd507 | 302 | seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n", |
cd1a28e8 | 303 | nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS); |
8e18257d | 304 | #endif |
a8f24a39 IM |
305 | |
306 | #ifdef CONFIG_TRACE_IRQFLAGS | |
307 | seq_printf(m, " in-hardirq chains: %11u\n", | |
308 | nr_hardirq_chains); | |
309 | seq_printf(m, " in-softirq chains: %11u\n", | |
310 | nr_softirq_chains); | |
311 | #endif | |
312 | seq_printf(m, " in-process chains: %11u\n", | |
313 | nr_process_chains); | |
314 | seq_printf(m, " stack-trace entries: %11lu [max: %lu]\n", | |
315 | nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES); | |
316 | seq_printf(m, " combined max dependencies: %11u\n", | |
317 | (nr_hardirq_chains + 1) * | |
318 | (nr_softirq_chains + 1) * | |
319 | (nr_process_chains + 1) | |
320 | ); | |
321 | seq_printf(m, " hardirq-safe locks: %11lu\n", | |
322 | nr_hardirq_safe); | |
323 | seq_printf(m, " hardirq-unsafe locks: %11lu\n", | |
324 | nr_hardirq_unsafe); | |
325 | seq_printf(m, " softirq-safe locks: %11lu\n", | |
326 | nr_softirq_safe); | |
327 | seq_printf(m, " softirq-unsafe locks: %11lu\n", | |
328 | nr_softirq_unsafe); | |
329 | seq_printf(m, " irq-safe locks: %11lu\n", | |
330 | nr_irq_safe); | |
331 | seq_printf(m, " irq-unsafe locks: %11lu\n", | |
332 | nr_irq_unsafe); | |
333 | ||
334 | seq_printf(m, " hardirq-read-safe locks: %11lu\n", | |
335 | nr_hardirq_read_safe); | |
336 | seq_printf(m, " hardirq-read-unsafe locks: %11lu\n", | |
337 | nr_hardirq_read_unsafe); | |
338 | seq_printf(m, " softirq-read-safe locks: %11lu\n", | |
339 | nr_softirq_read_safe); | |
340 | seq_printf(m, " softirq-read-unsafe locks: %11lu\n", | |
341 | nr_softirq_read_unsafe); | |
342 | seq_printf(m, " irq-read-safe locks: %11lu\n", | |
343 | nr_irq_read_safe); | |
344 | seq_printf(m, " irq-read-unsafe locks: %11lu\n", | |
345 | nr_irq_read_unsafe); | |
346 | ||
347 | seq_printf(m, " uncategorized locks: %11lu\n", | |
348 | nr_uncategorized); | |
349 | seq_printf(m, " unused locks: %11lu\n", | |
350 | nr_unused); | |
351 | seq_printf(m, " max locking depth: %11u\n", | |
352 | max_lockdep_depth); | |
353 | seq_printf(m, " max recursion depth: %11u\n", | |
354 | max_recursion_depth); | |
bbfa2622 | 355 | #ifdef CONFIG_PROVE_LOCKING |
12f3dfd0 ML |
356 | seq_printf(m, " max bfs queue depth: %11u\n", |
357 | max_bfs_queue_depth); | |
bbfa2622 | 358 | #endif |
a8f24a39 IM |
359 | lockdep_stats_debug_show(m); |
360 | seq_printf(m, " debug_locks: %11u\n", | |
361 | debug_locks); | |
362 | ||
363 | return 0; | |
364 | } | |
365 | ||
366 | static int lockdep_stats_open(struct inode *inode, struct file *file) | |
367 | { | |
368 | return single_open(file, lockdep_stats_show, NULL); | |
369 | } | |
370 | ||
15ad7cdc | 371 | static const struct file_operations proc_lockdep_stats_operations = { |
a8f24a39 IM |
372 | .open = lockdep_stats_open, |
373 | .read = seq_read, | |
374 | .llseek = seq_lseek, | |
c0f33586 | 375 | .release = single_release, |
a8f24a39 IM |
376 | }; |
377 | ||
c46261de PZ |
378 | #ifdef CONFIG_LOCK_STAT |
379 | ||
380 | struct lock_stat_data { | |
381 | struct lock_class *class; | |
382 | struct lock_class_stats stats; | |
383 | }; | |
384 | ||
385 | struct lock_stat_seq { | |
386 | struct lock_stat_data *iter; | |
387 | struct lock_stat_data *iter_end; | |
388 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; | |
389 | }; | |
390 | ||
391 | /* | |
392 | * sort on absolute number of contentions | |
393 | */ | |
394 | static int lock_stat_cmp(const void *l, const void *r) | |
395 | { | |
396 | const struct lock_stat_data *dl = l, *dr = r; | |
397 | unsigned long nl, nr; | |
398 | ||
399 | nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr; | |
400 | nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr; | |
401 | ||
402 | return nr - nl; | |
403 | } | |
404 | ||
405 | static void seq_line(struct seq_file *m, char c, int offset, int length) | |
406 | { | |
407 | int i; | |
408 | ||
409 | for (i = 0; i < offset; i++) | |
410 | seq_puts(m, " "); | |
411 | for (i = 0; i < length; i++) | |
412 | seq_printf(m, "%c", c); | |
413 | seq_puts(m, "\n"); | |
414 | } | |
415 | ||
416 | static void snprint_time(char *buf, size_t bufsiz, s64 nr) | |
417 | { | |
6918bc5c PZ |
418 | s64 div; |
419 | s32 rem; | |
c46261de | 420 | |
2189459d | 421 | nr += 5; /* for display rounding */ |
6918bc5c PZ |
422 | div = div_s64_rem(nr, 1000, &rem); |
423 | snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10); | |
c46261de PZ |
424 | } |
425 | ||
426 | static void seq_time(struct seq_file *m, s64 time) | |
427 | { | |
428 | char num[15]; | |
429 | ||
430 | snprint_time(num, sizeof(num), time); | |
431 | seq_printf(m, " %14s", num); | |
432 | } | |
433 | ||
434 | static void seq_lock_time(struct seq_file *m, struct lock_time *lt) | |
435 | { | |
436 | seq_printf(m, "%14lu", lt->nr); | |
437 | seq_time(m, lt->min); | |
438 | seq_time(m, lt->max); | |
439 | seq_time(m, lt->total); | |
440 | } | |
441 | ||
442 | static void seq_stats(struct seq_file *m, struct lock_stat_data *data) | |
443 | { | |
444 | char name[39]; | |
445 | struct lock_class *class; | |
446 | struct lock_class_stats *stats; | |
447 | int i, namelen; | |
448 | ||
449 | class = data->class; | |
450 | stats = &data->stats; | |
451 | ||
d38e1d5a PZ |
452 | namelen = 38; |
453 | if (class->name_version > 1) | |
454 | namelen -= 2; /* XXX truncates versions > 9 */ | |
455 | if (class->subclass) | |
456 | namelen -= 2; | |
457 | ||
458 | if (!class->name) { | |
459 | char str[KSYM_NAME_LEN]; | |
460 | const char *key_name; | |
461 | ||
462 | key_name = __get_key_name(class->key, str); | |
463 | snprintf(name, namelen, "%s", key_name); | |
464 | } else { | |
465 | snprintf(name, namelen, "%s", class->name); | |
466 | } | |
c46261de | 467 | namelen = strlen(name); |
d38e1d5a PZ |
468 | if (class->name_version > 1) { |
469 | snprintf(name+namelen, 3, "#%d", class->name_version); | |
470 | namelen += 2; | |
471 | } | |
472 | if (class->subclass) { | |
473 | snprintf(name+namelen, 3, "/%d", class->subclass); | |
474 | namelen += 2; | |
475 | } | |
c46261de PZ |
476 | |
477 | if (stats->write_holdtime.nr) { | |
478 | if (stats->read_holdtime.nr) | |
479 | seq_printf(m, "%38s-W:", name); | |
480 | else | |
481 | seq_printf(m, "%40s:", name); | |
482 | ||
96645678 | 483 | seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]); |
c46261de | 484 | seq_lock_time(m, &stats->write_waittime); |
96645678 | 485 | seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]); |
c46261de PZ |
486 | seq_lock_time(m, &stats->write_holdtime); |
487 | seq_puts(m, "\n"); | |
488 | } | |
489 | ||
490 | if (stats->read_holdtime.nr) { | |
491 | seq_printf(m, "%38s-R:", name); | |
96645678 | 492 | seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]); |
c46261de | 493 | seq_lock_time(m, &stats->read_waittime); |
96645678 | 494 | seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]); |
c46261de PZ |
495 | seq_lock_time(m, &stats->read_holdtime); |
496 | seq_puts(m, "\n"); | |
497 | } | |
498 | ||
499 | if (stats->read_waittime.nr + stats->write_waittime.nr == 0) | |
500 | return; | |
501 | ||
502 | if (stats->read_holdtime.nr) | |
503 | namelen += 2; | |
504 | ||
c7e78cff | 505 | for (i = 0; i < LOCKSTAT_POINTS; i++) { |
c46261de PZ |
506 | char sym[KSYM_SYMBOL_LEN]; |
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 | ||
515 | sprint_symbol(sym, class->contention_point[i]); | |
516 | snprintf(ip, sizeof(ip), "[<%p>]", | |
517 | (void *)class->contention_point[i]); | |
518 | seq_printf(m, "%40s %14lu %29s %s\n", name, | |
519 | stats->contention_point[i], | |
520 | ip, sym); | |
521 | } | |
c7e78cff PZ |
522 | for (i = 0; i < LOCKSTAT_POINTS; i++) { |
523 | char sym[KSYM_SYMBOL_LEN]; | |
524 | char ip[32]; | |
525 | ||
526 | if (class->contending_point[i] == 0) | |
527 | break; | |
528 | ||
529 | if (!i) | |
530 | seq_line(m, '-', 40-namelen, namelen); | |
531 | ||
532 | sprint_symbol(sym, class->contending_point[i]); | |
533 | snprintf(ip, sizeof(ip), "[<%p>]", | |
534 | (void *)class->contending_point[i]); | |
535 | seq_printf(m, "%40s %14lu %29s %s\n", name, | |
536 | stats->contending_point[i], | |
537 | ip, sym); | |
538 | } | |
c46261de PZ |
539 | if (i) { |
540 | seq_puts(m, "\n"); | |
96645678 | 541 | seq_line(m, '.', 0, 40 + 1 + 10 * (14 + 1)); |
c46261de PZ |
542 | seq_puts(m, "\n"); |
543 | } | |
544 | } | |
545 | ||
546 | static void seq_header(struct seq_file *m) | |
547 | { | |
c7e78cff | 548 | seq_printf(m, "lock_stat version 0.3\n"); |
9833f8cb PZ |
549 | |
550 | if (unlikely(!debug_locks)) | |
551 | seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n"); | |
552 | ||
96645678 PZ |
553 | seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1)); |
554 | seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s " | |
555 | "%14s %14s\n", | |
c46261de | 556 | "class name", |
96645678 | 557 | "con-bounces", |
c46261de PZ |
558 | "contentions", |
559 | "waittime-min", | |
560 | "waittime-max", | |
561 | "waittime-total", | |
96645678 | 562 | "acq-bounces", |
c46261de PZ |
563 | "acquisitions", |
564 | "holdtime-min", | |
565 | "holdtime-max", | |
566 | "holdtime-total"); | |
96645678 | 567 | seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1)); |
c46261de PZ |
568 | seq_printf(m, "\n"); |
569 | } | |
570 | ||
571 | static void *ls_start(struct seq_file *m, loff_t *pos) | |
572 | { | |
573 | struct lock_stat_seq *data = m->private; | |
574 | ||
94c61c0a TP |
575 | if (*pos == 0) |
576 | return SEQ_START_TOKEN; | |
c46261de | 577 | |
21227434 | 578 | data->iter = data->stats + (*pos - 1); |
94c61c0a | 579 | if (data->iter >= data->iter_end) |
4b32d0a4 PZ |
580 | data->iter = NULL; |
581 | ||
c46261de PZ |
582 | return data->iter; |
583 | } | |
584 | ||
585 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) | |
586 | { | |
587 | struct lock_stat_seq *data = m->private; | |
588 | ||
589 | (*pos)++; | |
590 | ||
94c61c0a TP |
591 | if (v == SEQ_START_TOKEN) |
592 | data->iter = data->stats; | |
593 | else { | |
594 | data->iter = v; | |
595 | data->iter++; | |
596 | } | |
597 | ||
c46261de PZ |
598 | if (data->iter == data->iter_end) |
599 | data->iter = NULL; | |
600 | ||
601 | return data->iter; | |
602 | } | |
603 | ||
604 | static void ls_stop(struct seq_file *m, void *v) | |
605 | { | |
606 | } | |
607 | ||
608 | static int ls_show(struct seq_file *m, void *v) | |
609 | { | |
94c61c0a TP |
610 | if (v == SEQ_START_TOKEN) |
611 | seq_header(m); | |
612 | else | |
613 | seq_stats(m, v); | |
c46261de | 614 | |
c46261de PZ |
615 | return 0; |
616 | } | |
617 | ||
618 | static struct seq_operations lockstat_ops = { | |
619 | .start = ls_start, | |
620 | .next = ls_next, | |
621 | .stop = ls_stop, | |
622 | .show = ls_show, | |
623 | }; | |
624 | ||
625 | static int lock_stat_open(struct inode *inode, struct file *file) | |
626 | { | |
627 | int res; | |
628 | struct lock_class *class; | |
629 | struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq)); | |
630 | ||
631 | if (!data) | |
632 | return -ENOMEM; | |
633 | ||
634 | res = seq_open(file, &lockstat_ops); | |
635 | if (!res) { | |
636 | struct lock_stat_data *iter = data->stats; | |
637 | struct seq_file *m = file->private_data; | |
638 | ||
639 | data->iter = iter; | |
640 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | |
641 | iter->class = class; | |
642 | iter->stats = lock_stats(class); | |
643 | iter++; | |
644 | } | |
645 | data->iter_end = iter; | |
646 | ||
647 | sort(data->stats, data->iter_end - data->iter, | |
648 | sizeof(struct lock_stat_data), | |
649 | lock_stat_cmp, NULL); | |
650 | ||
651 | m->private = data; | |
652 | } else | |
653 | vfree(data); | |
654 | ||
655 | return res; | |
656 | } | |
657 | ||
658 | static ssize_t lock_stat_write(struct file *file, const char __user *buf, | |
659 | size_t count, loff_t *ppos) | |
660 | { | |
661 | struct lock_class *class; | |
662 | char c; | |
663 | ||
664 | if (count) { | |
665 | if (get_user(c, buf)) | |
666 | return -EFAULT; | |
667 | ||
668 | if (c != '0') | |
669 | return count; | |
670 | ||
671 | list_for_each_entry(class, &all_lock_classes, lock_entry) | |
672 | clear_lock_stats(class); | |
673 | } | |
674 | return count; | |
675 | } | |
676 | ||
677 | static int lock_stat_release(struct inode *inode, struct file *file) | |
678 | { | |
679 | struct seq_file *seq = file->private_data; | |
680 | ||
681 | vfree(seq->private); | |
682 | seq->private = NULL; | |
683 | return seq_release(inode, file); | |
684 | } | |
685 | ||
686 | static const struct file_operations proc_lock_stat_operations = { | |
687 | .open = lock_stat_open, | |
688 | .write = lock_stat_write, | |
689 | .read = seq_read, | |
690 | .llseek = seq_lseek, | |
691 | .release = lock_stat_release, | |
692 | }; | |
693 | #endif /* CONFIG_LOCK_STAT */ | |
694 | ||
a8f24a39 IM |
695 | static int __init lockdep_proc_init(void) |
696 | { | |
c33fff0a | 697 | proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations); |
cd1a28e8 | 698 | #ifdef CONFIG_PROVE_LOCKING |
443cd507 HY |
699 | proc_create("lockdep_chains", S_IRUSR, NULL, |
700 | &proc_lockdep_chains_operations); | |
cd1a28e8 | 701 | #endif |
c33fff0a DL |
702 | proc_create("lockdep_stats", S_IRUSR, NULL, |
703 | &proc_lockdep_stats_operations); | |
a8f24a39 | 704 | |
c46261de | 705 | #ifdef CONFIG_LOCK_STAT |
c33fff0a | 706 | proc_create("lock_stat", S_IRUSR, NULL, &proc_lock_stat_operations); |
c46261de PZ |
707 | #endif |
708 | ||
a8f24a39 IM |
709 | return 0; |
710 | } | |
711 | ||
712 | __initcall(lockdep_proc_init); | |
713 |