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