diff options
Diffstat (limited to 'kernel/lockdep_proc.c')
-rw-r--r-- | kernel/lockdep_proc.c | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c index 2fde34127e2e..e682926c9ad6 100644 --- a/kernel/lockdep_proc.c +++ b/kernel/lockdep_proc.c | |||
@@ -15,6 +15,10 @@ | |||
15 | #include <linux/seq_file.h> | 15 | #include <linux/seq_file.h> |
16 | #include <linux/kallsyms.h> | 16 | #include <linux/kallsyms.h> |
17 | #include <linux/debug_locks.h> | 17 | #include <linux/debug_locks.h> |
18 | #include <linux/vmalloc.h> | ||
19 | #include <linux/sort.h> | ||
20 | #include <asm/uaccess.h> | ||
21 | #include <asm/div64.h> | ||
18 | 22 | ||
19 | #include "lockdep_internals.h" | 23 | #include "lockdep_internals.h" |
20 | 24 | ||
@@ -344,6 +348,262 @@ static const struct file_operations proc_lockdep_stats_operations = { | |||
344 | .release = seq_release, | 348 | .release = seq_release, |
345 | }; | 349 | }; |
346 | 350 | ||
351 | #ifdef CONFIG_LOCK_STAT | ||
352 | |||
353 | struct lock_stat_data { | ||
354 | struct lock_class *class; | ||
355 | struct lock_class_stats stats; | ||
356 | }; | ||
357 | |||
358 | struct lock_stat_seq { | ||
359 | struct lock_stat_data *iter; | ||
360 | struct lock_stat_data *iter_end; | ||
361 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; | ||
362 | }; | ||
363 | |||
364 | /* | ||
365 | * sort on absolute number of contentions | ||
366 | */ | ||
367 | static int lock_stat_cmp(const void *l, const void *r) | ||
368 | { | ||
369 | const struct lock_stat_data *dl = l, *dr = r; | ||
370 | unsigned long nl, nr; | ||
371 | |||
372 | nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr; | ||
373 | nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr; | ||
374 | |||
375 | return nr - nl; | ||
376 | } | ||
377 | |||
378 | static void seq_line(struct seq_file *m, char c, int offset, int length) | ||
379 | { | ||
380 | int i; | ||
381 | |||
382 | for (i = 0; i < offset; i++) | ||
383 | seq_puts(m, " "); | ||
384 | for (i = 0; i < length; i++) | ||
385 | seq_printf(m, "%c", c); | ||
386 | seq_puts(m, "\n"); | ||
387 | } | ||
388 | |||
389 | static void snprint_time(char *buf, size_t bufsiz, s64 nr) | ||
390 | { | ||
391 | unsigned long rem; | ||
392 | |||
393 | rem = do_div(nr, 1000); /* XXX: do_div_signed */ | ||
394 | snprintf(buf, bufsiz, "%lld.%02d", (long long)nr, ((int)rem+5)/10); | ||
395 | } | ||
396 | |||
397 | static void seq_time(struct seq_file *m, s64 time) | ||
398 | { | ||
399 | char num[15]; | ||
400 | |||
401 | snprint_time(num, sizeof(num), time); | ||
402 | seq_printf(m, " %14s", num); | ||
403 | } | ||
404 | |||
405 | static void seq_lock_time(struct seq_file *m, struct lock_time *lt) | ||
406 | { | ||
407 | seq_printf(m, "%14lu", lt->nr); | ||
408 | seq_time(m, lt->min); | ||
409 | seq_time(m, lt->max); | ||
410 | seq_time(m, lt->total); | ||
411 | } | ||
412 | |||
413 | static void seq_stats(struct seq_file *m, struct lock_stat_data *data) | ||
414 | { | ||
415 | char name[39]; | ||
416 | struct lock_class *class; | ||
417 | struct lock_class_stats *stats; | ||
418 | int i, namelen; | ||
419 | |||
420 | class = data->class; | ||
421 | stats = &data->stats; | ||
422 | |||
423 | snprintf(name, 38, "%s", class->name); | ||
424 | namelen = strlen(name); | ||
425 | |||
426 | if (stats->write_holdtime.nr) { | ||
427 | if (stats->read_holdtime.nr) | ||
428 | seq_printf(m, "%38s-W:", name); | ||
429 | else | ||
430 | seq_printf(m, "%40s:", name); | ||
431 | |||
432 | seq_lock_time(m, &stats->write_waittime); | ||
433 | seq_puts(m, " "); | ||
434 | seq_lock_time(m, &stats->write_holdtime); | ||
435 | seq_puts(m, "\n"); | ||
436 | } | ||
437 | |||
438 | if (stats->read_holdtime.nr) { | ||
439 | seq_printf(m, "%38s-R:", name); | ||
440 | seq_lock_time(m, &stats->read_waittime); | ||
441 | seq_puts(m, " "); | ||
442 | seq_lock_time(m, &stats->read_holdtime); | ||
443 | seq_puts(m, "\n"); | ||
444 | } | ||
445 | |||
446 | if (stats->read_waittime.nr + stats->write_waittime.nr == 0) | ||
447 | return; | ||
448 | |||
449 | if (stats->read_holdtime.nr) | ||
450 | namelen += 2; | ||
451 | |||
452 | for (i = 0; i < ARRAY_SIZE(class->contention_point); i++) { | ||
453 | char sym[KSYM_SYMBOL_LEN]; | ||
454 | char ip[32]; | ||
455 | |||
456 | if (class->contention_point[i] == 0) | ||
457 | break; | ||
458 | |||
459 | if (!i) | ||
460 | seq_line(m, '-', 40-namelen, namelen); | ||
461 | |||
462 | sprint_symbol(sym, class->contention_point[i]); | ||
463 | snprintf(ip, sizeof(ip), "[<%p>]", | ||
464 | (void *)class->contention_point[i]); | ||
465 | seq_printf(m, "%40s %14lu %29s %s\n", name, | ||
466 | stats->contention_point[i], | ||
467 | ip, sym); | ||
468 | } | ||
469 | if (i) { | ||
470 | seq_puts(m, "\n"); | ||
471 | seq_line(m, '.', 0, 40 + 1 + 8 * (14 + 1)); | ||
472 | seq_puts(m, "\n"); | ||
473 | } | ||
474 | } | ||
475 | |||
476 | static void seq_header(struct seq_file *m) | ||
477 | { | ||
478 | seq_printf(m, "lock_stat version 0.1\n"); | ||
479 | seq_line(m, '-', 0, 40 + 1 + 8 * (14 + 1)); | ||
480 | seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s\n", | ||
481 | "class name", | ||
482 | "contentions", | ||
483 | "waittime-min", | ||
484 | "waittime-max", | ||
485 | "waittime-total", | ||
486 | "acquisitions", | ||
487 | "holdtime-min", | ||
488 | "holdtime-max", | ||
489 | "holdtime-total"); | ||
490 | seq_line(m, '-', 0, 40 + 1 + 8 * (14 + 1)); | ||
491 | seq_printf(m, "\n"); | ||
492 | } | ||
493 | |||
494 | static void *ls_start(struct seq_file *m, loff_t *pos) | ||
495 | { | ||
496 | struct lock_stat_seq *data = m->private; | ||
497 | |||
498 | if (data->iter == data->stats) | ||
499 | seq_header(m); | ||
500 | |||
501 | return data->iter; | ||
502 | } | ||
503 | |||
504 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) | ||
505 | { | ||
506 | struct lock_stat_seq *data = m->private; | ||
507 | |||
508 | (*pos)++; | ||
509 | |||
510 | data->iter = v; | ||
511 | data->iter++; | ||
512 | if (data->iter == data->iter_end) | ||
513 | data->iter = NULL; | ||
514 | |||
515 | return data->iter; | ||
516 | } | ||
517 | |||
518 | static void ls_stop(struct seq_file *m, void *v) | ||
519 | { | ||
520 | } | ||
521 | |||
522 | static int ls_show(struct seq_file *m, void *v) | ||
523 | { | ||
524 | struct lock_stat_seq *data = m->private; | ||
525 | |||
526 | seq_stats(m, data->iter); | ||
527 | return 0; | ||
528 | } | ||
529 | |||
530 | static struct seq_operations lockstat_ops = { | ||
531 | .start = ls_start, | ||
532 | .next = ls_next, | ||
533 | .stop = ls_stop, | ||
534 | .show = ls_show, | ||
535 | }; | ||
536 | |||
537 | static int lock_stat_open(struct inode *inode, struct file *file) | ||
538 | { | ||
539 | int res; | ||
540 | struct lock_class *class; | ||
541 | struct lock_stat_seq *data = vmalloc(sizeof(struct lock_stat_seq)); | ||
542 | |||
543 | if (!data) | ||
544 | return -ENOMEM; | ||
545 | |||
546 | res = seq_open(file, &lockstat_ops); | ||
547 | if (!res) { | ||
548 | struct lock_stat_data *iter = data->stats; | ||
549 | struct seq_file *m = file->private_data; | ||
550 | |||
551 | data->iter = iter; | ||
552 | list_for_each_entry(class, &all_lock_classes, lock_entry) { | ||
553 | iter->class = class; | ||
554 | iter->stats = lock_stats(class); | ||
555 | iter++; | ||
556 | } | ||
557 | data->iter_end = iter; | ||
558 | |||
559 | sort(data->stats, data->iter_end - data->iter, | ||
560 | sizeof(struct lock_stat_data), | ||
561 | lock_stat_cmp, NULL); | ||
562 | |||
563 | m->private = data; | ||
564 | } else | ||
565 | vfree(data); | ||
566 | |||
567 | return res; | ||
568 | } | ||
569 | |||
570 | static ssize_t lock_stat_write(struct file *file, const char __user *buf, | ||
571 | size_t count, loff_t *ppos) | ||
572 | { | ||
573 | struct lock_class *class; | ||
574 | char c; | ||
575 | |||
576 | if (count) { | ||
577 | if (get_user(c, buf)) | ||
578 | return -EFAULT; | ||
579 | |||
580 | if (c != '0') | ||
581 | return count; | ||
582 | |||
583 | list_for_each_entry(class, &all_lock_classes, lock_entry) | ||
584 | clear_lock_stats(class); | ||
585 | } | ||
586 | return count; | ||
587 | } | ||
588 | |||
589 | static int lock_stat_release(struct inode *inode, struct file *file) | ||
590 | { | ||
591 | struct seq_file *seq = file->private_data; | ||
592 | |||
593 | vfree(seq->private); | ||
594 | seq->private = NULL; | ||
595 | return seq_release(inode, file); | ||
596 | } | ||
597 | |||
598 | static const struct file_operations proc_lock_stat_operations = { | ||
599 | .open = lock_stat_open, | ||
600 | .write = lock_stat_write, | ||
601 | .read = seq_read, | ||
602 | .llseek = seq_lseek, | ||
603 | .release = lock_stat_release, | ||
604 | }; | ||
605 | #endif /* CONFIG_LOCK_STAT */ | ||
606 | |||
347 | static int __init lockdep_proc_init(void) | 607 | static int __init lockdep_proc_init(void) |
348 | { | 608 | { |
349 | struct proc_dir_entry *entry; | 609 | struct proc_dir_entry *entry; |
@@ -356,6 +616,12 @@ static int __init lockdep_proc_init(void) | |||
356 | if (entry) | 616 | if (entry) |
357 | entry->proc_fops = &proc_lockdep_stats_operations; | 617 | entry->proc_fops = &proc_lockdep_stats_operations; |
358 | 618 | ||
619 | #ifdef CONFIG_LOCK_STAT | ||
620 | entry = create_proc_entry("lock_stat", S_IRUSR, NULL); | ||
621 | if (entry) | ||
622 | entry->proc_fops = &proc_lock_stat_operations; | ||
623 | #endif | ||
624 | |||
359 | return 0; | 625 | return 0; |
360 | } | 626 | } |
361 | 627 | ||