blob: 8dac8402e07e6214fd7be90198f9790fb0717f0e [file] [log] [blame]
Ingo Molnara8f24a32006-07-03 00:24:52 -07001/*
2 * kernel/lockdep_proc.c
3 *
4 * Runtime locking correctness validator
5 *
6 * Started by Ingo Molnar:
7 *
Peter Zijlstra4b32d0a2007-07-19 01:48:59 -07008 * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
9 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com>
Ingo Molnara8f24a32006-07-03 00:24:52 -070010 *
11 * Code for /proc/lockdep and /proc/lockdep_stats:
12 *
13 */
Ingo Molnara8f24a32006-07-03 00:24:52 -070014#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>
Peter Zijlstrac46261d2007-07-19 01:48:57 -070019#include <linux/vmalloc.h>
20#include <linux/sort.h>
21#include <asm/uaccess.h>
22#include <asm/div64.h>
Ingo Molnara8f24a32006-07-03 00:24:52 -070023
24#include "lockdep_internals.h"
25
26static void *l_next(struct seq_file *m, void *v, loff_t *pos)
27{
Li Zefan8109e1d2009-08-17 13:40:17 +080028 return seq_list_next(v, &all_lock_classes, pos);
Ingo Molnara8f24a32006-07-03 00:24:52 -070029}
30
31static void *l_start(struct seq_file *m, loff_t *pos)
32{
Li Zefan8109e1d2009-08-17 13:40:17 +080033 return seq_list_start_head(&all_lock_classes, *pos);
Ingo Molnara8f24a32006-07-03 00:24:52 -070034}
35
36static void l_stop(struct seq_file *m, void *v)
37{
38}
39
Jason Baron068135e2007-02-10 01:44:59 -080040static 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
Ingo Molnara8f24a32006-07-03 00:24:52 -070057static int l_show(struct seq_file *m, void *v)
58{
Li Zefan8109e1d2009-08-17 13:40:17 +080059 struct lock_class *class = list_entry(v, struct lock_class, lock_entry);
Jason Baron068135e2007-02-10 01:44:59 -080060 struct lock_list *entry;
Peter Zijlstraf510b232009-01-22 17:53:47 +010061 char usage[LOCK_USAGE_CHARS];
Ingo Molnara8f24a32006-07-03 00:24:52 -070062
Li Zefan8109e1d2009-08-17 13:40:17 +080063 if (v == &all_lock_classes) {
Tim Pepper94c61c02007-10-11 22:11:11 +020064 seq_printf(m, "all lock classes:\n");
65 return 0;
66 }
67
Ingo Molnara8f24a32006-07-03 00:24:52 -070068 seq_printf(m, "%p", class->key);
69#ifdef CONFIG_DEBUG_LOCKDEP
70 seq_printf(m, " OPS:%8ld", class->ops);
71#endif
Stephen Hemmingerdf60a842008-08-15 09:33:05 -070072#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
Ingo Molnara8f24a32006-07-03 00:24:52 -070076
Peter Zijlstraf510b232009-01-22 17:53:47 +010077 get_usage_chars(class, usage);
78 seq_printf(m, " %s", usage);
Ingo Molnara8f24a32006-07-03 00:24:52 -070079
Jason Baron068135e2007-02-10 01:44:59 -080080 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) {
Huang, Ying2429e4e2008-06-13 14:40:17 +080086 seq_printf(m, " -> [%p] ", entry->class->key);
Jason Baron068135e2007-02-10 01:44:59 -080087 print_name(m, entry->class);
88 seq_puts(m, "\n");
89 }
Ingo Molnara8f24a32006-07-03 00:24:52 -070090 }
91 seq_puts(m, "\n");
92
93 return 0;
94}
95
Helge Deller15ad7cd2006-12-06 20:40:36 -080096static const struct seq_operations lockdep_ops = {
Ingo Molnara8f24a32006-07-03 00:24:52 -070097 .start = l_start,
98 .next = l_next,
99 .stop = l_stop,
100 .show = l_show,
101};
102
103static int lockdep_open(struct inode *inode, struct file *file)
104{
Li Zefan8109e1d2009-08-17 13:40:17 +0800105 return seq_open(file, &lockdep_ops);
Ingo Molnara8f24a32006-07-03 00:24:52 -0700106}
107
Helge Deller15ad7cd2006-12-06 20:40:36 -0800108static const struct file_operations proc_lockdep_operations = {
Ingo Molnara8f24a32006-07-03 00:24:52 -0700109 .open = lockdep_open,
110 .read = seq_read,
111 .llseek = seq_lseek,
112 .release = seq_release,
113};
114
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800115#ifdef CONFIG_PROVE_LOCKING
Huang, Ying443cd502008-06-20 16:39:21 +0800116static void *lc_start(struct seq_file *m, loff_t *pos)
117{
118 if (*pos == 0)
119 return SEQ_START_TOKEN;
120
Li Zefane9d65722009-08-17 13:39:49 +0800121 if (*pos - 1 < nr_lock_chains)
122 return lock_chains + (*pos - 1);
Huang, Ying443cd502008-06-20 16:39:21 +0800123
124 return NULL;
125}
126
Li Zefan12aac192009-08-17 13:40:39 +0800127static void *lc_next(struct seq_file *m, void *v, loff_t *pos)
128{
129 (*pos)++;
130 return lc_start(m, pos);
131}
132
Huang, Ying443cd502008-06-20 16:39:21 +0800133static void lc_stop(struct seq_file *m, void *v)
134{
135}
136
137static int lc_show(struct seq_file *m, void *v)
138{
139 struct lock_chain *chain = v;
140 struct lock_class *class;
141 int i;
142
143 if (v == SEQ_START_TOKEN) {
144 seq_printf(m, "all lock chains:\n");
145 return 0;
146 }
147
148 seq_printf(m, "irq_context: %d\n", chain->irq_context);
149
150 for (i = 0; i < chain->depth; i++) {
151 class = lock_chain_get_class(chain, i);
Rabin Vincent8bfe0292008-08-11 09:30:26 +0200152 if (!class->key)
153 continue;
154
Huang, Ying443cd502008-06-20 16:39:21 +0800155 seq_printf(m, "[%p] ", class->key);
156 print_name(m, class);
157 seq_puts(m, "\n");
158 }
159 seq_puts(m, "\n");
160
161 return 0;
162}
163
164static const struct seq_operations lockdep_chains_ops = {
165 .start = lc_start,
166 .next = lc_next,
167 .stop = lc_stop,
168 .show = lc_show,
169};
170
171static int lockdep_chains_open(struct inode *inode, struct file *file)
172{
Li Zefan12aac192009-08-17 13:40:39 +0800173 return seq_open(file, &lockdep_chains_ops);
Huang, Ying443cd502008-06-20 16:39:21 +0800174}
175
176static const struct file_operations proc_lockdep_chains_operations = {
177 .open = lockdep_chains_open,
178 .read = seq_read,
179 .llseek = seq_lseek,
180 .release = seq_release,
181};
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800182#endif /* CONFIG_PROVE_LOCKING */
Huang, Ying443cd502008-06-20 16:39:21 +0800183
Ingo Molnara8f24a32006-07-03 00:24:52 -0700184static 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
224static 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++;
Peter Zijlstra4fc95e82009-01-22 13:10:52 +0100244 if (class->usage_mask & LOCKF_ENABLED_IRQ)
Ingo Molnara8f24a32006-07-03 00:24:52 -0700245 nr_irq_unsafe++;
246 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
247 nr_softirq_safe++;
Peter Zijlstra4fc95e82009-01-22 13:10:52 +0100248 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ)
Ingo Molnara8f24a32006-07-03 00:24:52 -0700249 nr_softirq_unsafe++;
250 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ)
251 nr_hardirq_safe++;
Peter Zijlstra4fc95e82009-01-22 13:10:52 +0100252 if (class->usage_mask & LOCKF_ENABLED_HARDIRQ)
Ingo Molnara8f24a32006-07-03 00:24:52 -0700253 nr_hardirq_unsafe++;
254 if (class->usage_mask & LOCKF_USED_IN_IRQ_READ)
255 nr_irq_read_safe++;
Peter Zijlstra4fc95e82009-01-22 13:10:52 +0100256 if (class->usage_mask & LOCKF_ENABLED_IRQ_READ)
Ingo Molnara8f24a32006-07-03 00:24:52 -0700257 nr_irq_read_unsafe++;
258 if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
259 nr_softirq_read_safe++;
Peter Zijlstra4fc95e82009-01-22 13:10:52 +0100260 if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ)
Ingo Molnara8f24a32006-07-03 00:24:52 -0700261 nr_softirq_read_unsafe++;
262 if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
263 nr_hardirq_read_safe++;
Peter Zijlstra4fc95e82009-01-22 13:10:52 +0100264 if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ)
Ingo Molnara8f24a32006-07-03 00:24:52 -0700265 nr_hardirq_read_unsafe++;
266
Stephen Hemmingerdf60a842008-08-15 09:33:05 -0700267#ifdef CONFIG_PROVE_LOCKING
David Miller419ca3f2008-07-29 21:45:03 -0700268 sum_forward_deps += lockdep_count_forward_deps(class);
Stephen Hemmingerdf60a842008-08-15 09:33:05 -0700269#endif
Ingo Molnara8f24a32006-07-03 00:24:52 -0700270 }
Robert P. J. Day501b9eb2007-02-10 01:46:34 -0800271#ifdef CONFIG_DEBUG_LOCKDEP
Ingo Molnara8f24a32006-07-03 00:24:52 -0700272 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
Peter Zijlstra8e182572007-07-19 01:48:54 -0700299#ifdef CONFIG_PROVE_LOCKING
Ingo Molnara8f24a32006-07-03 00:24:52 -0700300 seq_printf(m, " dependency chains: %11lu [max: %lu]\n",
301 nr_lock_chains, MAX_LOCKDEP_CHAINS);
Huang, Ying443cd502008-06-20 16:39:21 +0800302 seq_printf(m, " dependency chain hlocks: %11d [max: %lu]\n",
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800303 nr_chain_hlocks, MAX_LOCKDEP_CHAIN_HLOCKS);
Peter Zijlstra8e182572007-07-19 01:48:54 -0700304#endif
Ingo Molnara8f24a32006-07-03 00:24:52 -0700305
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);
Ingo Molnarbbfa2622009-08-02 14:44:24 +0200355#ifdef CONFIG_PROVE_LOCKING
Ming Lei12f3dfd2009-07-16 15:44:29 +0200356 seq_printf(m, " max bfs queue depth: %11u\n",
357 max_bfs_queue_depth);
Ingo Molnarbbfa2622009-08-02 14:44:24 +0200358#endif
Ingo Molnara8f24a32006-07-03 00:24:52 -0700359 lockdep_stats_debug_show(m);
360 seq_printf(m, " debug_locks: %11u\n",
361 debug_locks);
362
363 return 0;
364}
365
366static int lockdep_stats_open(struct inode *inode, struct file *file)
367{
368 return single_open(file, lockdep_stats_show, NULL);
369}
370
Helge Deller15ad7cd2006-12-06 20:40:36 -0800371static const struct file_operations proc_lockdep_stats_operations = {
Ingo Molnara8f24a32006-07-03 00:24:52 -0700372 .open = lockdep_stats_open,
373 .read = seq_read,
374 .llseek = seq_lseek,
Alexey Dobriyanc0f33582007-07-31 00:38:50 -0700375 .release = single_release,
Ingo Molnara8f24a32006-07-03 00:24:52 -0700376};
377
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700378#ifdef CONFIG_LOCK_STAT
379
380struct lock_stat_data {
381 struct lock_class *class;
382 struct lock_class_stats stats;
383};
384
385struct lock_stat_seq {
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700386 struct lock_stat_data *iter_end;
387 struct lock_stat_data stats[MAX_LOCKDEP_KEYS];
388};
389
390/*
391 * sort on absolute number of contentions
392 */
393static int lock_stat_cmp(const void *l, const void *r)
394{
395 const struct lock_stat_data *dl = l, *dr = r;
396 unsigned long nl, nr;
397
398 nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr;
399 nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr;
400
401 return nr - nl;
402}
403
404static void seq_line(struct seq_file *m, char c, int offset, int length)
405{
406 int i;
407
408 for (i = 0; i < offset; i++)
409 seq_puts(m, " ");
410 for (i = 0; i < length; i++)
411 seq_printf(m, "%c", c);
412 seq_puts(m, "\n");
413}
414
415static void snprint_time(char *buf, size_t bufsiz, s64 nr)
416{
Peter Zijlstra6918bc52008-09-23 15:33:41 +0200417 s64 div;
418 s32 rem;
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700419
Joe Korty2189459d2008-08-25 17:15:33 -0400420 nr += 5; /* for display rounding */
Peter Zijlstra6918bc52008-09-23 15:33:41 +0200421 div = div_s64_rem(nr, 1000, &rem);
422 snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700423}
424
425static void seq_time(struct seq_file *m, s64 time)
426{
427 char num[15];
428
429 snprint_time(num, sizeof(num), time);
430 seq_printf(m, " %14s", num);
431}
432
433static void seq_lock_time(struct seq_file *m, struct lock_time *lt)
434{
435 seq_printf(m, "%14lu", lt->nr);
436 seq_time(m, lt->min);
437 seq_time(m, lt->max);
438 seq_time(m, lt->total);
439}
440
441static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
442{
443 char name[39];
444 struct lock_class *class;
445 struct lock_class_stats *stats;
446 int i, namelen;
447
448 class = data->class;
449 stats = &data->stats;
450
Peter Zijlstrad38e1d52007-07-19 01:49:01 -0700451 namelen = 38;
452 if (class->name_version > 1)
453 namelen -= 2; /* XXX truncates versions > 9 */
454 if (class->subclass)
455 namelen -= 2;
456
457 if (!class->name) {
458 char str[KSYM_NAME_LEN];
459 const char *key_name;
460
461 key_name = __get_key_name(class->key, str);
462 snprintf(name, namelen, "%s", key_name);
463 } else {
464 snprintf(name, namelen, "%s", class->name);
465 }
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700466 namelen = strlen(name);
Peter Zijlstrad38e1d52007-07-19 01:49:01 -0700467 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 }
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700475
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
Peter Zijlstra96645672007-07-19 01:49:00 -0700482 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700483 seq_lock_time(m, &stats->write_waittime);
Peter Zijlstra96645672007-07-19 01:49:00 -0700484 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700485 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);
Peter Zijlstra96645672007-07-19 01:49:00 -0700491 seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700492 seq_lock_time(m, &stats->read_waittime);
Peter Zijlstra96645672007-07-19 01:49:00 -0700493 seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700494 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
Peter Zijlstrac7e78cf2008-10-16 23:17:09 +0200504 for (i = 0; i < LOCKSTAT_POINTS; i++) {
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700505 char sym[KSYM_SYMBOL_LEN];
506 char ip[32];
507
508 if (class->contention_point[i] == 0)
509 break;
510
511 if (!i)
512 seq_line(m, '-', 40-namelen, namelen);
513
514 sprint_symbol(sym, class->contention_point[i]);
515 snprintf(ip, sizeof(ip), "[<%p>]",
516 (void *)class->contention_point[i]);
517 seq_printf(m, "%40s %14lu %29s %s\n", name,
518 stats->contention_point[i],
519 ip, sym);
520 }
Peter Zijlstrac7e78cf2008-10-16 23:17:09 +0200521 for (i = 0; i < LOCKSTAT_POINTS; i++) {
522 char sym[KSYM_SYMBOL_LEN];
523 char ip[32];
524
525 if (class->contending_point[i] == 0)
526 break;
527
528 if (!i)
529 seq_line(m, '-', 40-namelen, namelen);
530
531 sprint_symbol(sym, class->contending_point[i]);
532 snprintf(ip, sizeof(ip), "[<%p>]",
533 (void *)class->contending_point[i]);
534 seq_printf(m, "%40s %14lu %29s %s\n", name,
535 stats->contending_point[i],
536 ip, sym);
537 }
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700538 if (i) {
539 seq_puts(m, "\n");
Peter Zijlstra96645672007-07-19 01:49:00 -0700540 seq_line(m, '.', 0, 40 + 1 + 10 * (14 + 1));
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700541 seq_puts(m, "\n");
542 }
543}
544
545static void seq_header(struct seq_file *m)
546{
Peter Zijlstrac7e78cf2008-10-16 23:17:09 +0200547 seq_printf(m, "lock_stat version 0.3\n");
Peter Zijlstra9833f8c2009-02-14 16:59:04 +0100548
549 if (unlikely(!debug_locks))
550 seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n");
551
Peter Zijlstra96645672007-07-19 01:49:00 -0700552 seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
553 seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s "
554 "%14s %14s\n",
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700555 "class name",
Peter Zijlstra96645672007-07-19 01:49:00 -0700556 "con-bounces",
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700557 "contentions",
558 "waittime-min",
559 "waittime-max",
560 "waittime-total",
Peter Zijlstra96645672007-07-19 01:49:00 -0700561 "acq-bounces",
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700562 "acquisitions",
563 "holdtime-min",
564 "holdtime-max",
565 "holdtime-total");
Peter Zijlstra96645672007-07-19 01:49:00 -0700566 seq_line(m, '-', 0, 40 + 1 + 10 * (14 + 1));
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700567 seq_printf(m, "\n");
568}
569
570static void *ls_start(struct seq_file *m, loff_t *pos)
571{
572 struct lock_stat_seq *data = m->private;
Li Zefan96004bb2009-08-17 13:40:59 +0800573 struct lock_stat_data *iter;
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700574
Tim Pepper94c61c02007-10-11 22:11:11 +0200575 if (*pos == 0)
576 return SEQ_START_TOKEN;
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700577
Li Zefan96004bb2009-08-17 13:40:59 +0800578 iter = data->stats + (*pos - 1);
579 if (iter >= data->iter_end)
580 iter = NULL;
Peter Zijlstra4b32d0a2007-07-19 01:48:59 -0700581
Li Zefan96004bb2009-08-17 13:40:59 +0800582 return iter;
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700583}
584
585static void *ls_next(struct seq_file *m, void *v, loff_t *pos)
586{
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700587 (*pos)++;
Li Zefan96004bb2009-08-17 13:40:59 +0800588 return ls_start(m, pos);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700589}
590
591static void ls_stop(struct seq_file *m, void *v)
592{
593}
594
595static int ls_show(struct seq_file *m, void *v)
596{
Tim Pepper94c61c02007-10-11 22:11:11 +0200597 if (v == SEQ_START_TOKEN)
598 seq_header(m);
599 else
600 seq_stats(m, v);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700601
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700602 return 0;
603}
604
605static struct seq_operations lockstat_ops = {
606 .start = ls_start,
607 .next = ls_next,
608 .stop = ls_stop,
609 .show = ls_show,
610};
611
612static 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
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700626 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
Li Zefan96004bb2009-08-17 13:40:59 +0800633 sort(data->stats, data->iter_end - data->stats,
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700634 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
644static 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
663static int lock_stat_release(struct inode *inode, struct file *file)
664{
665 struct seq_file *seq = file->private_data;
666
667 vfree(seq->private);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700668 return seq_release(inode, file);
669}
670
671static const struct file_operations proc_lock_stat_operations = {
672 .open = lock_stat_open,
673 .write = lock_stat_write,
674 .read = seq_read,
675 .llseek = seq_lseek,
676 .release = lock_stat_release,
677};
678#endif /* CONFIG_LOCK_STAT */
679
Ingo Molnara8f24a32006-07-03 00:24:52 -0700680static int __init lockdep_proc_init(void)
681{
Denis V. Lunevc33fff02008-04-29 01:02:31 -0700682 proc_create("lockdep", S_IRUSR, NULL, &proc_lockdep_operations);
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800683#ifdef CONFIG_PROVE_LOCKING
Huang, Ying443cd502008-06-20 16:39:21 +0800684 proc_create("lockdep_chains", S_IRUSR, NULL,
685 &proc_lockdep_chains_operations);
Huang, Yingcd1a28e2008-06-23 11:20:54 +0800686#endif
Denis V. Lunevc33fff02008-04-29 01:02:31 -0700687 proc_create("lockdep_stats", S_IRUSR, NULL,
688 &proc_lockdep_stats_operations);
Ingo Molnara8f24a32006-07-03 00:24:52 -0700689
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700690#ifdef CONFIG_LOCK_STAT
Denis V. Lunevc33fff02008-04-29 01:02:31 -0700691 proc_create("lock_stat", S_IRUSR, NULL, &proc_lock_stat_operations);
Peter Zijlstrac46261d2007-07-19 01:48:57 -0700692#endif
693
Ingo Molnara8f24a32006-07-03 00:24:52 -0700694 return 0;
695}
696
697__initcall(lockdep_proc_init);
698