Skip to content

Commit 4840ce2

Browse files
xwsongIngo Molnar
authored andcommitted
locking/lockdep: Fix meaningless /proc/lockdep output of lock classes on !CONFIG_PROVE_LOCKING
When enabling CONFIG_LOCK_STAT=y, then CONFIG_LOCKDEP=y is forcedly enabled, but CONFIG_PROVE_LOCKING is disabled. We can get output from /proc/lockdep, which currently includes usages of lock classes. But the usages are meaningless, see the output below: / # cat /proc/lockdep all lock classes: ffffffff9af63350 ....: cgroup_mutex ffffffff9af54eb8 ....: (console_sem).lock ffffffff9af54e60 ....: console_lock ffffffff9ae74c38 ....: console_owner_lock ffffffff9ae74c80 ....: console_owner ffffffff9ae66e60 ....: cpu_hotplug_lock Only one usage context for each lock, this is because each usage is only changed in mark_lock() that is in the CONFIG_PROVE_LOCKING=y section, however in the test situation, it's not. The fix is to move the usages reading and seq_print from the !CONFIG_PROVE_LOCKING section to its defined section. Also, locks_after list of lock_class is empty when !CONFIG_PROVE_LOCKING, so do the same thing as what have done for usages of lock classes. With this patch with !CONFIG_PROVE_LOCKING we can get the results below: / # cat /proc/lockdep all lock classes: ffffffff85163290: cgroup_mutex ffffffff85154dd8: (console_sem).lock ffffffff85154d80: console_lock ffffffff85074b58: console_owner_lock ffffffff85074ba0: console_owner ffffffff85066d60: cpu_hotplug_lock ... a class key and the relevant class name each line. Signed-off-by: Xiongwei Song <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Waiman Long <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1b1cf8f commit 4840ce2

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

kernel/locking/lockdep_proc.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,28 @@ static int l_show(struct seq_file *m, void *v)
7070
#ifdef CONFIG_DEBUG_LOCKDEP
7171
seq_printf(m, " OPS:%8ld", debug_class_ops_read(class));
7272
#endif
73-
#ifdef 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));
76-
#endif
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));
7776

78-
get_usage_chars(class, usage);
79-
seq_printf(m, " %s", usage);
77+
get_usage_chars(class, usage);
78+
seq_printf(m, " %s", usage);
79+
}
8080

8181
seq_printf(m, ": ");
8282
print_name(m, class);
8383
seq_puts(m, "\n");
8484

85-
list_for_each_entry(entry, &class->locks_after, entry) {
86-
if (entry->distance == 1) {
87-
seq_printf(m, " -> [%p] ", entry->class->key);
88-
print_name(m, entry->class);
89-
seq_puts(m, "\n");
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+
}
9092
}
93+
seq_puts(m, "\n");
9194
}
92-
seq_puts(m, "\n");
9395

9496
return 0;
9597
}

0 commit comments

Comments
 (0)