14 #include <linux/export.h>
21 #include <asm/uaccess.h>
22 #include <asm/div64.h>
36 static void l_stop(
struct seq_file *
m,
void *
v)
40 static void print_name(
struct seq_file *
m,
struct lock_class *
class)
43 const char *
name =
class->name;
50 if (
class->name_version > 1)
57 static int l_show(
struct seq_file *m,
void *
v)
60 struct lock_list *
entry;
63 if (v == &all_lock_classes) {
69 #ifdef CONFIG_DEBUG_LOCKDEP
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));
85 if (entry->distance == 1) {
87 print_name(m, entry->class);
105 return seq_open(file, &lockdep_ops);
109 .open = lockdep_open,
115 #ifdef CONFIG_PROVE_LOCKING
116 static void *lc_start(
struct seq_file *m, loff_t *
pos)
121 if (*pos - 1 < nr_lock_chains)
127 static void *lc_next(
struct seq_file *m,
void *v, loff_t *pos)
130 return lc_start(m, pos);
133 static void lc_stop(
struct seq_file *m,
void *v)
137 static int lc_show(
struct seq_file *m,
void *v)
139 struct lock_chain *
chain =
v;
140 struct lock_class *
class;
148 seq_printf(m,
"irq_context: %d\n", chain->irq_context);
150 for (i = 0; i < chain->depth; i++) {
156 print_name(m,
class);
173 return seq_open(file, &lockdep_chains_ops);
177 .
open = lockdep_chains_open,
184 static void lockdep_stats_debug_show(
struct seq_file *m)
186 #ifdef CONFIG_DEBUG_LOCKDEP
196 seq_printf(m,
" chain lookup misses: %11llu\n",
202 seq_printf(m,
" find-mask forwards checks: %11llu\n",
204 seq_printf(m,
" find-mask backwards checks: %11llu\n",
207 seq_printf(m,
" hardirq on events: %11llu\n", hi1);
208 seq_printf(m,
" hardirq off events: %11llu\n", hi2);
209 seq_printf(m,
" redundant hardirq ons: %11llu\n", hr1);
210 seq_printf(m,
" redundant hardirq offs: %11llu\n", hr2);
213 seq_printf(m,
" redundant softirq ons: %11llu\n", sr1);
214 seq_printf(m,
" redundant softirq offs: %11llu\n", sr2);
218 static int lockdep_stats_show(
struct seq_file *m,
void *v)
220 struct lock_class *
class;
221 unsigned long nr_unused = 0, nr_uncategorized = 0,
222 nr_irq_safe = 0, nr_irq_unsafe = 0,
223 nr_softirq_safe = 0, nr_softirq_unsafe = 0,
224 nr_hardirq_safe = 0, nr_hardirq_unsafe = 0,
225 nr_irq_read_safe = 0, nr_irq_read_unsafe = 0,
226 nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0,
227 nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0,
228 sum_forward_deps = 0;
232 if (
class->usage_mask == 0)
234 if (
class->usage_mask == LOCKF_USED)
240 if (
class->usage_mask & LOCKF_USED_IN_SOFTIRQ)
242 if (
class->usage_mask & LOCKF_ENABLED_SOFTIRQ)
244 if (
class->usage_mask & LOCKF_USED_IN_HARDIRQ)
246 if (
class->usage_mask & LOCKF_ENABLED_HARDIRQ)
251 nr_irq_read_unsafe++;
252 if (
class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ)
253 nr_softirq_read_safe++;
254 if (
class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ)
255 nr_softirq_read_unsafe++;
256 if (
class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ)
257 nr_hardirq_read_safe++;
258 if (
class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ)
259 nr_hardirq_read_unsafe++;
261 #ifdef CONFIG_PROVE_LOCKING
262 sum_forward_deps += lockdep_count_forward_deps(
class);
265 #ifdef CONFIG_DEBUG_LOCKDEP
268 seq_printf(m,
" lock-classes: %11lu [max: %lu]\n",
270 seq_printf(m,
" direct dependencies: %11lu [max: %lu]\n",
272 seq_printf(m,
" indirect dependencies: %11lu\n",
281 seq_printf(m,
" all direct dependencies: %11lu\n",
282 nr_irq_unsafe * nr_irq_safe +
283 nr_hardirq_unsafe * nr_hardirq_safe +
286 #ifdef CONFIG_PROVE_LOCKING
287 seq_printf(m,
" dependency chains: %11lu [max: %lu]\n",
289 seq_printf(m,
" dependency chain hlocks: %11d [max: %lu]\n",
293 #ifdef CONFIG_TRACE_IRQFLAGS
301 seq_printf(m,
" stack-trace entries: %11lu [max: %lu]\n",
303 seq_printf(m,
" combined max dependencies: %11u\n",
310 seq_printf(m,
" hardirq-unsafe locks: %11lu\n",
314 seq_printf(m,
" softirq-unsafe locks: %11lu\n",
321 seq_printf(m,
" hardirq-read-safe locks: %11lu\n",
322 nr_hardirq_read_safe);
323 seq_printf(m,
" hardirq-read-unsafe locks: %11lu\n",
324 nr_hardirq_read_unsafe);
325 seq_printf(m,
" softirq-read-safe locks: %11lu\n",
326 nr_softirq_read_safe);
327 seq_printf(m,
" softirq-read-unsafe locks: %11lu\n",
328 nr_softirq_read_unsafe);
329 seq_printf(m,
" irq-read-safe locks: %11lu\n",
331 seq_printf(m,
" irq-read-unsafe locks: %11lu\n",
334 seq_printf(m,
" uncategorized locks: %11lu\n",
340 #ifdef CONFIG_PROVE_LOCKING
342 max_bfs_queue_depth);
344 lockdep_stats_debug_show(m);
357 .open = lockdep_stats_open,
363 #ifdef CONFIG_LOCK_STAT
365 struct lock_stat_data {
366 struct lock_class *
class;
367 struct lock_class_stats
stats;
370 struct lock_stat_seq {
371 struct lock_stat_data *iter_end;
372 struct lock_stat_data
stats[MAX_LOCKDEP_KEYS];
378 static int lock_stat_cmp(
const void *
l,
const void *
r)
380 const struct lock_stat_data *
dl =
l, *dr =
r;
381 unsigned long nl,
nr;
383 nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr;
384 nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr;
393 for (i = 0; i <
offset; i++)
395 for (i = 0; i <
length; i++)
400 static void snprint_time(
char *
buf,
size_t bufsiz,
s64 nr)
406 div = div_s64_rem(nr, 1000, &rem);
407 snprintf(buf, bufsiz,
"%lld.%02d", (
long long)div, (
int)rem/10);
414 snprint_time(num,
sizeof(num), time);
418 static void seq_lock_time(
struct seq_file *m,
struct lock_time *lt)
426 static void seq_stats(
struct seq_file *m,
struct lock_stat_data *
data)
429 struct lock_class *
class;
430 struct lock_class_stats *
stats;
434 stats = &data->stats;
437 if (
class->name_version > 1)
444 const char *key_name;
447 snprintf(name, namelen,
"%s", key_name);
452 if (
class->name_version > 1) {
456 if (
class->subclass) {
461 if (stats->write_holdtime.nr) {
462 if (stats->read_holdtime.nr)
467 seq_printf(m,
"%14lu ", stats->bounces[bounce_contended_write]);
468 seq_lock_time(m, &stats->write_waittime);
469 seq_printf(m,
" %14lu ", stats->bounces[bounce_acquired_write]);
470 seq_lock_time(m, &stats->write_holdtime);
474 if (stats->read_holdtime.nr) {
476 seq_printf(m,
"%14lu ", stats->bounces[bounce_contended_read]);
477 seq_lock_time(m, &stats->read_waittime);
478 seq_printf(m,
" %14lu ", stats->bounces[bounce_acquired_read]);
479 seq_lock_time(m, &stats->read_holdtime);
483 if (stats->read_waittime.nr + stats->write_waittime.nr == 0)
486 if (stats->read_holdtime.nr)
489 for (i = 0; i < LOCKSTAT_POINTS; i++) {
492 if (
class->contention_point[i] == 0)
496 seq_line(m,
'-', 40-namelen, namelen);
499 (
void *)
class->contention_point[i]);
501 name, stats->contention_point[i],
502 ip, (
void *)
class->contention_point[i]);
504 for (i = 0; i < LOCKSTAT_POINTS; i++) {
507 if (
class->contending_point[i] == 0)
511 seq_line(m,
'-', 40-namelen, namelen);
514 (
void *)
class->contending_point[i]);
516 name, stats->contending_point[i],
517 ip, (
void *)
class->contending_point[i]);
521 seq_line(m,
'.', 0, 40 + 1 + 10 * (14 + 1));
526 static void seq_header(
struct seq_file *m)
531 seq_printf(m,
"*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n");
533 seq_line(m,
'-', 0, 40 + 1 + 10 * (14 + 1));
534 seq_printf(m,
"%40s %14s %14s %14s %14s %14s %14s %14s %14s "
547 seq_line(m,
'-', 0, 40 + 1 + 10 * (14 + 1));
551 static void *ls_start(
struct seq_file *m, loff_t *pos)
553 struct lock_stat_seq *data = m->
private;
554 struct lock_stat_data *iter;
559 iter = data->stats + (*pos - 1);
560 if (iter >= data->iter_end)
566 static void *ls_next(
struct seq_file *m,
void *v, loff_t *pos)
569 return ls_start(m, pos);
572 static void ls_stop(
struct seq_file *m,
void *v)
576 static int ls_show(
struct seq_file *m,
void *v)
596 struct lock_class *
class;
597 struct lock_stat_seq *data =
vmalloc(
sizeof(
struct lock_stat_seq));
602 res =
seq_open(file, &lockstat_ops);
604 struct lock_stat_data *iter = data->stats;
609 iter->stats = lock_stats(
class);
612 data->iter_end = iter;
614 sort(data->stats, data->iter_end - data->stats,
615 sizeof(
struct lock_stat_data),
616 lock_stat_cmp,
NULL);
625 static ssize_t lock_stat_write(
struct file *file,
const char __user *buf,
626 size_t count, loff_t *ppos)
628 struct lock_class *
class;
639 clear_lock_stats(
class);
644 static
int lock_stat_release(
struct inode *inode,
struct file *file)
653 .
open = lock_stat_open,
654 .write = lock_stat_write,
657 .release = lock_stat_release,
661 static int __init lockdep_proc_init(
void)
663 proc_create(
"lockdep",
S_IRUSR,
NULL, &proc_lockdep_operations);
664 #ifdef CONFIG_PROVE_LOCKING
666 &proc_lockdep_chains_operations);
669 &proc_lockdep_stats_operations);
671 #ifdef CONFIG_LOCK_STAT
673 &proc_lock_stat_operations);