Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 2 | /* |
| 3 | * kernel/lockdep_proc.c |
| 4 | * |
| 5 | * Runtime locking correctness validator |
| 6 | * |
| 7 | * Started by Ingo Molnar: |
| 8 | * |
Peter Zijlstra | 4b32d0a | 2007-07-19 01:48:59 -0700 | [diff] [blame] | 9 | * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com> |
Peter Zijlstra | 90eec10 | 2015-11-16 11:08:45 +0100 | [diff] [blame] | 10 | * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 11 | * |
| 12 | * Code for /proc/lockdep and /proc/lockdep_stats: |
| 13 | * |
| 14 | */ |
Paul Gortmaker | 9984de1 | 2011-05-23 14:51:41 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 16 | #include <linux/proc_fs.h> |
| 17 | #include <linux/seq_file.h> |
| 18 | #include <linux/kallsyms.h> |
| 19 | #include <linux/debug_locks.h> |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 20 | #include <linux/vmalloc.h> |
| 21 | #include <linux/sort.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 23 | #include <asm/div64.h> |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 24 | |
| 25 | #include "lockdep_internals.h" |
| 26 | |
| 27 | static void *l_next(struct seq_file *m, void *v, loff_t *pos) |
| 28 | { |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 29 | return seq_list_next(v, &all_lock_classes, pos); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static void *l_start(struct seq_file *m, loff_t *pos) |
| 33 | { |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 34 | return seq_list_start_head(&all_lock_classes, *pos); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static void l_stop(struct seq_file *m, void *v) |
| 38 | { |
| 39 | } |
| 40 | |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 41 | static void print_name(struct seq_file *m, struct lock_class *class) |
| 42 | { |
Cyrill Gorcunov | 99fb4a1 | 2012-10-20 23:05:19 +0400 | [diff] [blame] | 43 | char str[KSYM_NAME_LEN]; |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 44 | const char *name = class->name; |
| 45 | |
| 46 | if (!name) { |
| 47 | name = __get_key_name(class->key, str); |
| 48 | seq_printf(m, "%s", name); |
| 49 | } else{ |
| 50 | seq_printf(m, "%s", name); |
| 51 | if (class->name_version > 1) |
| 52 | seq_printf(m, "#%d", class->name_version); |
| 53 | if (class->subclass) |
| 54 | seq_printf(m, "/%d", class->subclass); |
| 55 | } |
| 56 | } |
| 57 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 58 | static int l_show(struct seq_file *m, void *v) |
| 59 | { |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 60 | struct lock_class *class = list_entry(v, struct lock_class, lock_entry); |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 61 | struct lock_list *entry; |
Peter Zijlstra | f510b23 | 2009-01-22 17:53:47 +0100 | [diff] [blame] | 62 | char usage[LOCK_USAGE_CHARS]; |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 63 | |
Li Zefan | 8109e1d | 2009-08-17 13:40:17 +0800 | [diff] [blame] | 64 | if (v == &all_lock_classes) { |
Tim Pepper | 94c61c0 | 2007-10-11 22:11:11 +0200 | [diff] [blame] | 65 | seq_printf(m, "all lock classes:\n"); |
| 66 | return 0; |
| 67 | } |
| 68 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 69 | seq_printf(m, "%p", class->key); |
| 70 | #ifdef CONFIG_DEBUG_LOCKDEP |
Waiman Long | 8ca2b56c | 2018-10-03 13:07:18 -0400 | [diff] [blame] | 71 | seq_printf(m, " OPS:%8ld", debug_class_ops_read(class)); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 72 | #endif |
Xiongwei Song | 4840ce2 | 2021-06-29 21:59:16 +0800 | [diff] [blame] | 73 | if (IS_ENABLED(CONFIG_PROVE_LOCKING)) { |
| 74 | seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class)); |
| 75 | seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class)); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 76 | |
Xiongwei Song | 4840ce2 | 2021-06-29 21:59:16 +0800 | [diff] [blame] | 77 | get_usage_chars(class, usage); |
| 78 | seq_printf(m, " %s", usage); |
| 79 | } |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 80 | |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 81 | seq_printf(m, ": "); |
| 82 | print_name(m, class); |
| 83 | seq_puts(m, "\n"); |
| 84 | |
Xiongwei Song | 4840ce2 | 2021-06-29 21:59:16 +0800 | [diff] [blame] | 85 | if (IS_ENABLED(CONFIG_PROVE_LOCKING)) { |
| 86 | list_for_each_entry(entry, &class->locks_after, entry) { |
| 87 | if (entry->distance == 1) { |
| 88 | seq_printf(m, " -> [%p] ", entry->class->key); |
| 89 | print_name(m, entry->class); |
| 90 | seq_puts(m, "\n"); |
| 91 | } |
Jason Baron | 068135e | 2007-02-10 01:44:59 -0800 | [diff] [blame] | 92 | } |
Xiongwei Song | 4840ce2 | 2021-06-29 21:59:16 +0800 | [diff] [blame] | 93 | seq_puts(m, "\n"); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 94 | } |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Helge Deller | 15ad7cd | 2006-12-06 20:40:36 -0800 | [diff] [blame] | 99 | static const struct seq_operations lockdep_ops = { |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 100 | .start = l_start, |
| 101 | .next = l_next, |
| 102 | .stop = l_stop, |
| 103 | .show = l_show, |
| 104 | }; |
| 105 | |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 106 | #ifdef CONFIG_PROVE_LOCKING |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 107 | static void *lc_start(struct seq_file *m, loff_t *pos) |
| 108 | { |
Bart Van Assche | 2212684 | 2019-02-14 15:00:48 -0800 | [diff] [blame] | 109 | if (*pos < 0) |
| 110 | return NULL; |
| 111 | |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 112 | if (*pos == 0) |
| 113 | return SEQ_START_TOKEN; |
| 114 | |
Bart Van Assche | 2212684 | 2019-02-14 15:00:48 -0800 | [diff] [blame] | 115 | return lock_chains + (*pos - 1); |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 116 | } |
| 117 | |
Li Zefan | 12aac19 | 2009-08-17 13:40:39 +0800 | [diff] [blame] | 118 | static void *lc_next(struct seq_file *m, void *v, loff_t *pos) |
| 119 | { |
Bart Van Assche | 2212684 | 2019-02-14 15:00:48 -0800 | [diff] [blame] | 120 | *pos = lockdep_next_lockchain(*pos - 1) + 1; |
Li Zefan | 12aac19 | 2009-08-17 13:40:39 +0800 | [diff] [blame] | 121 | return lc_start(m, pos); |
| 122 | } |
| 123 | |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 124 | static void lc_stop(struct seq_file *m, void *v) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | static int lc_show(struct seq_file *m, void *v) |
| 129 | { |
| 130 | struct lock_chain *chain = v; |
| 131 | struct lock_class *class; |
| 132 | int i; |
Waiman Long | b9875e9 | 2020-02-06 10:24:04 -0500 | [diff] [blame] | 133 | static const char * const irq_strs[] = { |
| 134 | [0] = "0", |
| 135 | [LOCK_CHAIN_HARDIRQ_CONTEXT] = "hardirq", |
| 136 | [LOCK_CHAIN_SOFTIRQ_CONTEXT] = "softirq", |
| 137 | [LOCK_CHAIN_SOFTIRQ_CONTEXT| |
| 138 | LOCK_CHAIN_HARDIRQ_CONTEXT] = "hardirq|softirq", |
| 139 | }; |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 140 | |
| 141 | if (v == SEQ_START_TOKEN) { |
Waiman Long | 810507f | 2020-02-06 10:24:08 -0500 | [diff] [blame] | 142 | if (!nr_free_chain_hlocks) |
Peter Zijlstra | 75dd602 | 2016-03-30 11:36:59 +0200 | [diff] [blame] | 143 | seq_printf(m, "(buggered) "); |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 144 | seq_printf(m, "all lock chains:\n"); |
| 145 | return 0; |
| 146 | } |
| 147 | |
Waiman Long | b9875e9 | 2020-02-06 10:24:04 -0500 | [diff] [blame] | 148 | seq_printf(m, "irq_context: %s\n", irq_strs[chain->irq_context]); |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 149 | |
| 150 | for (i = 0; i < chain->depth; i++) { |
| 151 | class = lock_chain_get_class(chain, i); |
Rabin Vincent | 8bfe029 | 2008-08-11 09:30:26 +0200 | [diff] [blame] | 152 | if (!class->key) |
| 153 | continue; |
| 154 | |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 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 | }; |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 170 | #endif /* CONFIG_PROVE_LOCKING */ |
Huang, Ying | 443cd50 | 2008-06-20 16:39:21 +0800 | [diff] [blame] | 171 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 172 | static void lockdep_stats_debug_show(struct seq_file *m) |
| 173 | { |
| 174 | #ifdef CONFIG_DEBUG_LOCKDEP |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 175 | unsigned long long hi1 = debug_atomic_read(hardirqs_on_events), |
| 176 | hi2 = debug_atomic_read(hardirqs_off_events), |
| 177 | hr1 = debug_atomic_read(redundant_hardirqs_on), |
| 178 | hr2 = debug_atomic_read(redundant_hardirqs_off), |
| 179 | si1 = debug_atomic_read(softirqs_on_events), |
| 180 | si2 = debug_atomic_read(softirqs_off_events), |
| 181 | sr1 = debug_atomic_read(redundant_softirqs_on), |
| 182 | sr2 = debug_atomic_read(redundant_softirqs_off); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 183 | |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 184 | seq_printf(m, " chain lookup misses: %11llu\n", |
| 185 | debug_atomic_read(chain_lookup_misses)); |
| 186 | seq_printf(m, " chain lookup hits: %11llu\n", |
| 187 | debug_atomic_read(chain_lookup_hits)); |
| 188 | seq_printf(m, " cyclic checks: %11llu\n", |
| 189 | debug_atomic_read(nr_cyclic_checks)); |
Peter Zijlstra | ae81330 | 2017-03-03 10:13:38 +0100 | [diff] [blame] | 190 | seq_printf(m, " redundant checks: %11llu\n", |
| 191 | debug_atomic_read(nr_redundant_checks)); |
| 192 | seq_printf(m, " redundant links: %11llu\n", |
| 193 | debug_atomic_read(nr_redundant)); |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 194 | seq_printf(m, " find-mask forwards checks: %11llu\n", |
| 195 | debug_atomic_read(nr_find_usage_forwards_checks)); |
| 196 | seq_printf(m, " find-mask backwards checks: %11llu\n", |
| 197 | debug_atomic_read(nr_find_usage_backwards_checks)); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 198 | |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 199 | seq_printf(m, " hardirq on events: %11llu\n", hi1); |
| 200 | seq_printf(m, " hardirq off events: %11llu\n", hi2); |
| 201 | seq_printf(m, " redundant hardirq ons: %11llu\n", hr1); |
| 202 | seq_printf(m, " redundant hardirq offs: %11llu\n", hr2); |
| 203 | seq_printf(m, " softirq on events: %11llu\n", si1); |
| 204 | seq_printf(m, " softirq off events: %11llu\n", si2); |
| 205 | seq_printf(m, " redundant softirq ons: %11llu\n", sr1); |
| 206 | seq_printf(m, " redundant softirq offs: %11llu\n", sr2); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 207 | #endif |
| 208 | } |
| 209 | |
| 210 | static int lockdep_stats_show(struct seq_file *m, void *v) |
| 211 | { |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 212 | unsigned long nr_unused = 0, nr_uncategorized = 0, |
| 213 | nr_irq_safe = 0, nr_irq_unsafe = 0, |
| 214 | nr_softirq_safe = 0, nr_softirq_unsafe = 0, |
| 215 | nr_hardirq_safe = 0, nr_hardirq_unsafe = 0, |
| 216 | nr_irq_read_safe = 0, nr_irq_read_unsafe = 0, |
| 217 | nr_softirq_read_safe = 0, nr_softirq_read_unsafe = 0, |
| 218 | nr_hardirq_read_safe = 0, nr_hardirq_read_unsafe = 0, |
Sergey Senozhatsky | dec2960 | 2011-03-23 14:38:28 +0200 | [diff] [blame] | 219 | sum_forward_deps = 0; |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 220 | |
Yuyang Du | 68d41d8 | 2019-07-09 18:15:22 +0800 | [diff] [blame] | 221 | #ifdef CONFIG_PROVE_LOCKING |
Arnd Bergmann | 68037aa | 2019-07-15 11:27:49 +0200 | [diff] [blame] | 222 | struct lock_class *class; |
| 223 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 224 | list_for_each_entry(class, &all_lock_classes, lock_entry) { |
| 225 | |
| 226 | if (class->usage_mask == 0) |
| 227 | nr_unused++; |
| 228 | if (class->usage_mask == LOCKF_USED) |
| 229 | nr_uncategorized++; |
| 230 | if (class->usage_mask & LOCKF_USED_IN_IRQ) |
| 231 | nr_irq_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 232 | if (class->usage_mask & LOCKF_ENABLED_IRQ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 233 | nr_irq_unsafe++; |
| 234 | if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ) |
| 235 | nr_softirq_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 236 | if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 237 | nr_softirq_unsafe++; |
| 238 | if (class->usage_mask & LOCKF_USED_IN_HARDIRQ) |
| 239 | nr_hardirq_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 240 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 241 | nr_hardirq_unsafe++; |
| 242 | if (class->usage_mask & LOCKF_USED_IN_IRQ_READ) |
| 243 | nr_irq_read_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 244 | if (class->usage_mask & LOCKF_ENABLED_IRQ_READ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 245 | nr_irq_read_unsafe++; |
| 246 | if (class->usage_mask & LOCKF_USED_IN_SOFTIRQ_READ) |
| 247 | nr_softirq_read_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 248 | if (class->usage_mask & LOCKF_ENABLED_SOFTIRQ_READ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 249 | nr_softirq_read_unsafe++; |
| 250 | if (class->usage_mask & LOCKF_USED_IN_HARDIRQ_READ) |
| 251 | nr_hardirq_read_safe++; |
Peter Zijlstra | 4fc95e8 | 2009-01-22 13:10:52 +0100 | [diff] [blame] | 252 | if (class->usage_mask & LOCKF_ENABLED_HARDIRQ_READ) |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 253 | nr_hardirq_read_unsafe++; |
| 254 | |
David Miller | 419ca3f | 2008-07-29 21:45:03 -0700 | [diff] [blame] | 255 | sum_forward_deps += lockdep_count_forward_deps(class); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 256 | } |
Robert P. J. Day | 501b9eb | 2007-02-10 01:46:34 -0800 | [diff] [blame] | 257 | #ifdef CONFIG_DEBUG_LOCKDEP |
Frederic Weisbecker | bd6d29c | 2010-04-06 00:10:17 +0200 | [diff] [blame] | 258 | DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused); |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 259 | #endif |
Yuyang Du | 68d41d8 | 2019-07-09 18:15:22 +0800 | [diff] [blame] | 260 | |
| 261 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 262 | seq_printf(m, " lock-classes: %11lu [max: %lu]\n", |
| 263 | nr_lock_classes, MAX_LOCKDEP_KEYS); |
| 264 | seq_printf(m, " direct dependencies: %11lu [max: %lu]\n", |
| 265 | nr_list_entries, MAX_LOCKDEP_ENTRIES); |
| 266 | seq_printf(m, " indirect dependencies: %11lu\n", |
| 267 | sum_forward_deps); |
| 268 | |
| 269 | /* |
| 270 | * Total number of dependencies: |
| 271 | * |
| 272 | * All irq-safe locks may nest inside irq-unsafe locks, |
| 273 | * plus all the other known dependencies: |
| 274 | */ |
| 275 | seq_printf(m, " all direct dependencies: %11lu\n", |
| 276 | nr_irq_unsafe * nr_irq_safe + |
| 277 | nr_hardirq_unsafe * nr_hardirq_safe + |
| 278 | nr_list_entries); |
| 279 | |
Peter Zijlstra | 8e18257 | 2007-07-19 01:48:54 -0700 | [diff] [blame] | 280 | #ifdef CONFIG_PROVE_LOCKING |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 281 | seq_printf(m, " dependency chains: %11lu [max: %lu]\n", |
Bart Van Assche | 2212684 | 2019-02-14 15:00:48 -0800 | [diff] [blame] | 282 | lock_chain_count(), MAX_LOCKDEP_CHAINS); |
Waiman Long | 810507f | 2020-02-06 10:24:08 -0500 | [diff] [blame] | 283 | seq_printf(m, " dependency chain hlocks used: %11lu [max: %lu]\n", |
| 284 | MAX_LOCKDEP_CHAIN_HLOCKS - |
| 285 | (nr_free_chain_hlocks + nr_lost_chain_hlocks), |
| 286 | MAX_LOCKDEP_CHAIN_HLOCKS); |
| 287 | seq_printf(m, " dependency chain hlocks lost: %11u\n", |
| 288 | nr_lost_chain_hlocks); |
Peter Zijlstra | 8e18257 | 2007-07-19 01:48:54 -0700 | [diff] [blame] | 289 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 290 | |
| 291 | #ifdef CONFIG_TRACE_IRQFLAGS |
| 292 | seq_printf(m, " in-hardirq chains: %11u\n", |
| 293 | nr_hardirq_chains); |
| 294 | seq_printf(m, " in-softirq chains: %11u\n", |
| 295 | nr_softirq_chains); |
| 296 | #endif |
| 297 | seq_printf(m, " in-process chains: %11u\n", |
| 298 | nr_process_chains); |
| 299 | seq_printf(m, " stack-trace entries: %11lu [max: %lu]\n", |
| 300 | nr_stack_trace_entries, MAX_STACK_TRACE_ENTRIES); |
Bart Van Assche | 8c77922 | 2019-07-22 11:24:43 -0700 | [diff] [blame] | 301 | #if defined(CONFIG_TRACE_IRQFLAGS) && defined(CONFIG_PROVE_LOCKING) |
Waiman Long | a030f97 | 2019-12-11 16:31:39 -0500 | [diff] [blame] | 302 | seq_printf(m, " number of stack traces: %11llu\n", |
Bart Van Assche | 8c77922 | 2019-07-22 11:24:43 -0700 | [diff] [blame] | 303 | lockdep_stack_trace_count()); |
Waiman Long | a030f97 | 2019-12-11 16:31:39 -0500 | [diff] [blame] | 304 | seq_printf(m, " number of stack hash chains: %11llu\n", |
Bart Van Assche | 8c77922 | 2019-07-22 11:24:43 -0700 | [diff] [blame] | 305 | lockdep_stack_hash_count()); |
| 306 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 307 | seq_printf(m, " combined max dependencies: %11u\n", |
| 308 | (nr_hardirq_chains + 1) * |
| 309 | (nr_softirq_chains + 1) * |
| 310 | (nr_process_chains + 1) |
| 311 | ); |
| 312 | seq_printf(m, " hardirq-safe locks: %11lu\n", |
| 313 | nr_hardirq_safe); |
| 314 | seq_printf(m, " hardirq-unsafe locks: %11lu\n", |
| 315 | nr_hardirq_unsafe); |
| 316 | seq_printf(m, " softirq-safe locks: %11lu\n", |
| 317 | nr_softirq_safe); |
| 318 | seq_printf(m, " softirq-unsafe locks: %11lu\n", |
| 319 | nr_softirq_unsafe); |
| 320 | seq_printf(m, " irq-safe locks: %11lu\n", |
| 321 | nr_irq_safe); |
| 322 | seq_printf(m, " irq-unsafe locks: %11lu\n", |
| 323 | nr_irq_unsafe); |
| 324 | |
| 325 | seq_printf(m, " hardirq-read-safe locks: %11lu\n", |
| 326 | nr_hardirq_read_safe); |
| 327 | seq_printf(m, " hardirq-read-unsafe locks: %11lu\n", |
| 328 | nr_hardirq_read_unsafe); |
| 329 | seq_printf(m, " softirq-read-safe locks: %11lu\n", |
| 330 | nr_softirq_read_safe); |
| 331 | seq_printf(m, " softirq-read-unsafe locks: %11lu\n", |
| 332 | nr_softirq_read_unsafe); |
| 333 | seq_printf(m, " irq-read-safe locks: %11lu\n", |
| 334 | nr_irq_read_safe); |
| 335 | seq_printf(m, " irq-read-unsafe locks: %11lu\n", |
| 336 | nr_irq_read_unsafe); |
| 337 | |
| 338 | seq_printf(m, " uncategorized locks: %11lu\n", |
| 339 | nr_uncategorized); |
| 340 | seq_printf(m, " unused locks: %11lu\n", |
| 341 | nr_unused); |
| 342 | seq_printf(m, " max locking depth: %11u\n", |
| 343 | max_lockdep_depth); |
Ingo Molnar | bbfa262 | 2009-08-02 14:44:24 +0200 | [diff] [blame] | 344 | #ifdef CONFIG_PROVE_LOCKING |
Ming Lei | 12f3dfd | 2009-07-16 15:44:29 +0200 | [diff] [blame] | 345 | seq_printf(m, " max bfs queue depth: %11u\n", |
| 346 | max_bfs_queue_depth); |
Ingo Molnar | bbfa262 | 2009-08-02 14:44:24 +0200 | [diff] [blame] | 347 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 348 | lockdep_stats_debug_show(m); |
| 349 | seq_printf(m, " debug_locks: %11u\n", |
| 350 | debug_locks); |
| 351 | |
Waiman Long | 1d44bcb | 2020-02-06 10:24:05 -0500 | [diff] [blame] | 352 | /* |
Ingo Molnar | e2db759 | 2021-03-22 02:35:05 +0100 | [diff] [blame] | 353 | * Zapped classes and lockdep data buffers reuse statistics. |
Waiman Long | 1d44bcb | 2020-02-06 10:24:05 -0500 | [diff] [blame] | 354 | */ |
| 355 | seq_puts(m, "\n"); |
| 356 | seq_printf(m, " zapped classes: %11lu\n", |
| 357 | nr_zapped_classes); |
Waiman Long | 797b82eb | 2020-02-06 10:24:07 -0500 | [diff] [blame] | 358 | #ifdef CONFIG_PROVE_LOCKING |
| 359 | seq_printf(m, " zapped lock chains: %11lu\n", |
| 360 | nr_zapped_lock_chains); |
Waiman Long | 810507f | 2020-02-06 10:24:08 -0500 | [diff] [blame] | 361 | seq_printf(m, " large chain blocks: %11u\n", |
| 362 | nr_large_chain_blocks); |
Waiman Long | 797b82eb | 2020-02-06 10:24:07 -0500 | [diff] [blame] | 363 | #endif |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 364 | return 0; |
| 365 | } |
| 366 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 367 | #ifdef CONFIG_LOCK_STAT |
| 368 | |
| 369 | struct lock_stat_data { |
| 370 | struct lock_class *class; |
| 371 | struct lock_class_stats stats; |
| 372 | }; |
| 373 | |
| 374 | struct lock_stat_seq { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 375 | struct lock_stat_data *iter_end; |
| 376 | struct lock_stat_data stats[MAX_LOCKDEP_KEYS]; |
| 377 | }; |
| 378 | |
| 379 | /* |
| 380 | * sort on absolute number of contentions |
| 381 | */ |
| 382 | static int lock_stat_cmp(const void *l, const void *r) |
| 383 | { |
| 384 | const struct lock_stat_data *dl = l, *dr = r; |
| 385 | unsigned long nl, nr; |
| 386 | |
| 387 | nl = dl->stats.read_waittime.nr + dl->stats.write_waittime.nr; |
| 388 | nr = dr->stats.read_waittime.nr + dr->stats.write_waittime.nr; |
| 389 | |
| 390 | return nr - nl; |
| 391 | } |
| 392 | |
| 393 | static void seq_line(struct seq_file *m, char c, int offset, int length) |
| 394 | { |
| 395 | int i; |
| 396 | |
| 397 | for (i = 0; i < offset; i++) |
| 398 | seq_puts(m, " "); |
| 399 | for (i = 0; i < length; i++) |
| 400 | seq_printf(m, "%c", c); |
| 401 | seq_puts(m, "\n"); |
| 402 | } |
| 403 | |
| 404 | static void snprint_time(char *buf, size_t bufsiz, s64 nr) |
| 405 | { |
Peter Zijlstra | 6918bc5 | 2008-09-23 15:33:41 +0200 | [diff] [blame] | 406 | s64 div; |
| 407 | s32 rem; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 408 | |
Joe Korty | 2189459d | 2008-08-25 17:15:33 -0400 | [diff] [blame] | 409 | nr += 5; /* for display rounding */ |
Peter Zijlstra | 6918bc5 | 2008-09-23 15:33:41 +0200 | [diff] [blame] | 410 | div = div_s64_rem(nr, 1000, &rem); |
| 411 | snprintf(buf, bufsiz, "%lld.%02d", (long long)div, (int)rem/10); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static void seq_time(struct seq_file *m, s64 time) |
| 415 | { |
| 416 | char num[15]; |
| 417 | |
| 418 | snprint_time(num, sizeof(num), time); |
| 419 | seq_printf(m, " %14s", num); |
| 420 | } |
| 421 | |
| 422 | static void seq_lock_time(struct seq_file *m, struct lock_time *lt) |
| 423 | { |
| 424 | seq_printf(m, "%14lu", lt->nr); |
| 425 | seq_time(m, lt->min); |
| 426 | seq_time(m, lt->max); |
| 427 | seq_time(m, lt->total); |
Chris Wilson | a7ef9b2 | 2020-07-25 19:51:10 +0100 | [diff] [blame] | 428 | seq_time(m, lt->nr ? div64_u64(lt->total, lt->nr) : 0); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static void seq_stats(struct seq_file *m, struct lock_stat_data *data) |
| 432 | { |
Bart Van Assche | 364f6af | 2019-07-22 11:24:40 -0700 | [diff] [blame] | 433 | const struct lockdep_subclass_key *ckey; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 434 | struct lock_class_stats *stats; |
Peter Zijlstra | cee34d8 | 2015-06-02 12:50:13 +0200 | [diff] [blame] | 435 | struct lock_class *class; |
| 436 | const char *cname; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 437 | int i, namelen; |
Peter Zijlstra | cee34d8 | 2015-06-02 12:50:13 +0200 | [diff] [blame] | 438 | char name[39]; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 439 | |
| 440 | class = data->class; |
| 441 | stats = &data->stats; |
| 442 | |
Peter Zijlstra | d38e1d5 | 2007-07-19 01:49:01 -0700 | [diff] [blame] | 443 | namelen = 38; |
| 444 | if (class->name_version > 1) |
| 445 | namelen -= 2; /* XXX truncates versions > 9 */ |
| 446 | if (class->subclass) |
| 447 | namelen -= 2; |
| 448 | |
Peter Zijlstra | cee34d8 | 2015-06-02 12:50:13 +0200 | [diff] [blame] | 449 | rcu_read_lock_sched(); |
| 450 | cname = rcu_dereference_sched(class->name); |
| 451 | ckey = rcu_dereference_sched(class->key); |
| 452 | |
| 453 | if (!cname && !ckey) { |
| 454 | rcu_read_unlock_sched(); |
| 455 | return; |
| 456 | |
| 457 | } else if (!cname) { |
Peter Zijlstra | d38e1d5 | 2007-07-19 01:49:01 -0700 | [diff] [blame] | 458 | char str[KSYM_NAME_LEN]; |
| 459 | const char *key_name; |
| 460 | |
Peter Zijlstra | cee34d8 | 2015-06-02 12:50:13 +0200 | [diff] [blame] | 461 | key_name = __get_key_name(ckey, str); |
Peter Zijlstra | d38e1d5 | 2007-07-19 01:49:01 -0700 | [diff] [blame] | 462 | snprintf(name, namelen, "%s", key_name); |
| 463 | } else { |
Peter Zijlstra | cee34d8 | 2015-06-02 12:50:13 +0200 | [diff] [blame] | 464 | snprintf(name, namelen, "%s", cname); |
Peter Zijlstra | d38e1d5 | 2007-07-19 01:49:01 -0700 | [diff] [blame] | 465 | } |
Peter Zijlstra | cee34d8 | 2015-06-02 12:50:13 +0200 | [diff] [blame] | 466 | rcu_read_unlock_sched(); |
| 467 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 468 | namelen = strlen(name); |
Peter Zijlstra | d38e1d5 | 2007-07-19 01:49:01 -0700 | [diff] [blame] | 469 | if (class->name_version > 1) { |
| 470 | snprintf(name+namelen, 3, "#%d", class->name_version); |
| 471 | namelen += 2; |
| 472 | } |
| 473 | if (class->subclass) { |
| 474 | snprintf(name+namelen, 3, "/%d", class->subclass); |
| 475 | namelen += 2; |
| 476 | } |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 477 | |
| 478 | if (stats->write_holdtime.nr) { |
| 479 | if (stats->read_holdtime.nr) |
| 480 | seq_printf(m, "%38s-W:", name); |
| 481 | else |
| 482 | seq_printf(m, "%40s:", name); |
| 483 | |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 484 | seq_printf(m, "%14lu ", stats->bounces[bounce_contended_write]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 485 | seq_lock_time(m, &stats->write_waittime); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 486 | seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_write]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 487 | seq_lock_time(m, &stats->write_holdtime); |
| 488 | seq_puts(m, "\n"); |
| 489 | } |
| 490 | |
| 491 | if (stats->read_holdtime.nr) { |
| 492 | seq_printf(m, "%38s-R:", name); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 493 | seq_printf(m, "%14lu ", stats->bounces[bounce_contended_read]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 494 | seq_lock_time(m, &stats->read_waittime); |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 495 | seq_printf(m, " %14lu ", stats->bounces[bounce_acquired_read]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 496 | seq_lock_time(m, &stats->read_holdtime); |
| 497 | seq_puts(m, "\n"); |
| 498 | } |
| 499 | |
| 500 | if (stats->read_waittime.nr + stats->write_waittime.nr == 0) |
| 501 | return; |
| 502 | |
| 503 | if (stats->read_holdtime.nr) |
| 504 | namelen += 2; |
| 505 | |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 506 | for (i = 0; i < LOCKSTAT_POINTS; i++) { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 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 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 515 | snprintf(ip, sizeof(ip), "[<%p>]", |
| 516 | (void *)class->contention_point[i]); |
Joe Perches | 3cf9b85 | 2010-11-05 16:12:38 -0700 | [diff] [blame] | 517 | seq_printf(m, "%40s %14lu %29s %pS\n", |
| 518 | name, stats->contention_point[i], |
| 519 | ip, (void *)class->contention_point[i]); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 520 | } |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 521 | for (i = 0; i < LOCKSTAT_POINTS; i++) { |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 522 | char ip[32]; |
| 523 | |
| 524 | if (class->contending_point[i] == 0) |
| 525 | break; |
| 526 | |
| 527 | if (!i) |
| 528 | seq_line(m, '-', 40-namelen, namelen); |
| 529 | |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 530 | snprintf(ip, sizeof(ip), "[<%p>]", |
| 531 | (void *)class->contending_point[i]); |
Joe Perches | 3cf9b85 | 2010-11-05 16:12:38 -0700 | [diff] [blame] | 532 | seq_printf(m, "%40s %14lu %29s %pS\n", |
| 533 | name, stats->contending_point[i], |
| 534 | ip, (void *)class->contending_point[i]); |
Peter Zijlstra | c7e78cf | 2008-10-16 23:17:09 +0200 | [diff] [blame] | 535 | } |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 536 | if (i) { |
| 537 | seq_puts(m, "\n"); |
Davidlohr Bueso | 1232e38 | 2013-10-08 20:37:16 -0700 | [diff] [blame] | 538 | seq_line(m, '.', 0, 40 + 1 + 12 * (14 + 1)); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 539 | seq_puts(m, "\n"); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | static void seq_header(struct seq_file *m) |
| 544 | { |
Davidlohr Bueso | 1232e38 | 2013-10-08 20:37:16 -0700 | [diff] [blame] | 545 | seq_puts(m, "lock_stat version 0.4\n"); |
Peter Zijlstra | 9833f8c | 2009-02-14 16:59:04 +0100 | [diff] [blame] | 546 | |
| 547 | if (unlikely(!debug_locks)) |
| 548 | seq_printf(m, "*WARNING* lock debugging disabled!! - possibly due to a lockdep warning\n"); |
| 549 | |
Davidlohr Bueso | 1232e38 | 2013-10-08 20:37:16 -0700 | [diff] [blame] | 550 | seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1)); |
| 551 | seq_printf(m, "%40s %14s %14s %14s %14s %14s %14s %14s %14s %14s %14s " |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 552 | "%14s %14s\n", |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 553 | "class name", |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 554 | "con-bounces", |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 555 | "contentions", |
| 556 | "waittime-min", |
| 557 | "waittime-max", |
| 558 | "waittime-total", |
Davidlohr Bueso | 1232e38 | 2013-10-08 20:37:16 -0700 | [diff] [blame] | 559 | "waittime-avg", |
Peter Zijlstra | 9664567 | 2007-07-19 01:49:00 -0700 | [diff] [blame] | 560 | "acq-bounces", |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 561 | "acquisitions", |
| 562 | "holdtime-min", |
| 563 | "holdtime-max", |
Davidlohr Bueso | 1232e38 | 2013-10-08 20:37:16 -0700 | [diff] [blame] | 564 | "holdtime-total", |
| 565 | "holdtime-avg"); |
| 566 | seq_line(m, '-', 0, 40 + 1 + 12 * (14 + 1)); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 567 | seq_printf(m, "\n"); |
| 568 | } |
| 569 | |
| 570 | static void *ls_start(struct seq_file *m, loff_t *pos) |
| 571 | { |
| 572 | struct lock_stat_seq *data = m->private; |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 573 | struct lock_stat_data *iter; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 574 | |
Tim Pepper | 94c61c0 | 2007-10-11 22:11:11 +0200 | [diff] [blame] | 575 | if (*pos == 0) |
| 576 | return SEQ_START_TOKEN; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 577 | |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 578 | iter = data->stats + (*pos - 1); |
| 579 | if (iter >= data->iter_end) |
| 580 | iter = NULL; |
Peter Zijlstra | 4b32d0a | 2007-07-19 01:48:59 -0700 | [diff] [blame] | 581 | |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 582 | return iter; |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static void *ls_next(struct seq_file *m, void *v, loff_t *pos) |
| 586 | { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 587 | (*pos)++; |
Li Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 588 | return ls_start(m, pos); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | static void ls_stop(struct seq_file *m, void *v) |
| 592 | { |
| 593 | } |
| 594 | |
| 595 | static int ls_show(struct seq_file *m, void *v) |
| 596 | { |
Tim Pepper | 94c61c0 | 2007-10-11 22:11:11 +0200 | [diff] [blame] | 597 | if (v == SEQ_START_TOKEN) |
| 598 | seq_header(m); |
| 599 | else |
| 600 | seq_stats(m, v); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 601 | |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 602 | return 0; |
| 603 | } |
| 604 | |
James Morris | 88e9d34 | 2009-09-22 16:43:43 -0700 | [diff] [blame] | 605 | static const struct seq_operations lockstat_ops = { |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 606 | .start = ls_start, |
| 607 | .next = ls_next, |
| 608 | .stop = ls_stop, |
| 609 | .show = ls_show, |
| 610 | }; |
| 611 | |
| 612 | static 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 Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 626 | 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 Zefan | 96004bb | 2009-08-17 13:40:59 +0800 | [diff] [blame] | 633 | sort(data->stats, data->iter_end - data->stats, |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 634 | 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 | |
| 644 | static 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 | |
| 663 | static 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 Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 668 | return seq_release(inode, file); |
| 669 | } |
| 670 | |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 671 | static const struct proc_ops lock_stat_proc_ops = { |
| 672 | .proc_open = lock_stat_open, |
| 673 | .proc_write = lock_stat_write, |
| 674 | .proc_read = seq_read, |
| 675 | .proc_lseek = seq_lseek, |
| 676 | .proc_release = lock_stat_release, |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 677 | }; |
| 678 | #endif /* CONFIG_LOCK_STAT */ |
| 679 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 680 | static int __init lockdep_proc_init(void) |
| 681 | { |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 682 | proc_create_seq("lockdep", S_IRUSR, NULL, &lockdep_ops); |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 683 | #ifdef CONFIG_PROVE_LOCKING |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 684 | proc_create_seq("lockdep_chains", S_IRUSR, NULL, &lockdep_chains_ops); |
Huang, Ying | cd1a28e | 2008-06-23 11:20:54 +0800 | [diff] [blame] | 685 | #endif |
Christoph Hellwig | 3f3942a | 2018-05-15 15:57:23 +0200 | [diff] [blame] | 686 | proc_create_single("lockdep_stats", S_IRUSR, NULL, lockdep_stats_show); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 687 | #ifdef CONFIG_LOCK_STAT |
Alexey Dobriyan | 97a3253 | 2020-02-03 17:37:17 -0800 | [diff] [blame] | 688 | proc_create("lock_stat", S_IRUSR | S_IWUSR, NULL, &lock_stat_proc_ops); |
Peter Zijlstra | c46261d | 2007-07-19 01:48:57 -0700 | [diff] [blame] | 689 | #endif |
| 690 | |
Ingo Molnar | a8f24a3 | 2006-07-03 00:24:52 -0700 | [diff] [blame] | 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | __initcall(lockdep_proc_init); |
| 695 | |