2021-06-29 14:01:02

by Xiongwei Song

[permalink] [raw]
Subject: [PATCH v3] locking/lockdep: Fix meaningless usages output of lock classes

From: Xiongwei Song <[email protected]>

When enabling CONFIG_LOCK_STAT, then CONFIG_LOCKDEP is forcedly enabled.
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 CONFIG_PROVE_LOCKING defined section,
however in the test situation, it's not.

The fix is to move the usages reading and seq_print from
CONFIG_PROVE_LOCKING undefined setcion to its defined section. Also,
locks_after list of lock_class is empty when CONFIG_PROVE_LOCKING
undefined, so do the same thing as what have done for usages of lock
classes.

With this patch with CONFIG_PROVE_LOCKING undefined, 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]>
---

v3: Improve commit log. Thank Longman very much for the comments.
v2: https://lkml.org/lkml/2021/6/28/1549

---
kernel/locking/lockdep_proc.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 806978314496..b8d9a050c337 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -70,26 +70,28 @@ static int l_show(struct seq_file *m, void *v)
#ifdef CONFIG_DEBUG_LOCKDEP
seq_printf(m, " OPS:%8ld", debug_class_ops_read(class));
#endif
-#ifdef CONFIG_PROVE_LOCKING
- seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
- seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));
-#endif
+ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
+ seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
+ seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));

- get_usage_chars(class, usage);
- seq_printf(m, " %s", usage);
+ get_usage_chars(class, usage);
+ seq_printf(m, " %s", usage);
+ }

seq_printf(m, ": ");
print_name(m, class);
seq_puts(m, "\n");

- list_for_each_entry(entry, &class->locks_after, entry) {
- if (entry->distance == 1) {
- seq_printf(m, " -> [%p] ", entry->class->key);
- print_name(m, entry->class);
- seq_puts(m, "\n");
+ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
+ list_for_each_entry(entry, &class->locks_after, entry) {
+ if (entry->distance == 1) {
+ seq_printf(m, " -> [%p] ", entry->class->key);
+ print_name(m, entry->class);
+ seq_puts(m, "\n");
+ }
}
+ seq_puts(m, "\n");
}
- seq_puts(m, "\n");

return 0;
}
--
2.30.2


2021-06-29 14:04:21

by Waiman Long

[permalink] [raw]
Subject: Re: [PATCH v3] locking/lockdep: Fix meaningless usages output of lock classes

On 6/29/21 9:59 AM, Xiongwei Song wrote:
> From: Xiongwei Song <[email protected]>
>
> When enabling CONFIG_LOCK_STAT, then CONFIG_LOCKDEP is forcedly enabled.
> 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 CONFIG_PROVE_LOCKING defined section,
> however in the test situation, it's not.
>
> The fix is to move the usages reading and seq_print from
> CONFIG_PROVE_LOCKING undefined setcion to its defined section. Also,
> locks_after list of lock_class is empty when CONFIG_PROVE_LOCKING
> undefined, so do the same thing as what have done for usages of lock
> classes.
>
> With this patch with CONFIG_PROVE_LOCKING undefined, 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]>
> ---
>
> v3: Improve commit log. Thank Longman very much for the comments.
> v2: https://lkml.org/lkml/2021/6/28/1549
>
> ---
> kernel/locking/lockdep_proc.c | 26 ++++++++++++++------------
> 1 file changed, 14 insertions(+), 12 deletions(-)
>
> diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
> index 806978314496..b8d9a050c337 100644
> --- a/kernel/locking/lockdep_proc.c
> +++ b/kernel/locking/lockdep_proc.c
> @@ -70,26 +70,28 @@ static int l_show(struct seq_file *m, void *v)
> #ifdef CONFIG_DEBUG_LOCKDEP
> seq_printf(m, " OPS:%8ld", debug_class_ops_read(class));
> #endif
> -#ifdef CONFIG_PROVE_LOCKING
> - seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
> - seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));
> -#endif
> + if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
> + seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
> + seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));
>
> - get_usage_chars(class, usage);
> - seq_printf(m, " %s", usage);
> + get_usage_chars(class, usage);
> + seq_printf(m, " %s", usage);
> + }
>
> seq_printf(m, ": ");
> print_name(m, class);
> seq_puts(m, "\n");
>
> - list_for_each_entry(entry, &class->locks_after, entry) {
> - if (entry->distance == 1) {
> - seq_printf(m, " -> [%p] ", entry->class->key);
> - print_name(m, entry->class);
> - seq_puts(m, "\n");
> + if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
> + list_for_each_entry(entry, &class->locks_after, entry) {
> + if (entry->distance == 1) {
> + seq_printf(m, " -> [%p] ", entry->class->key);
> + print_name(m, entry->class);
> + seq_puts(m, "\n");
> + }
> }
> + seq_puts(m, "\n");
> }
> - seq_puts(m, "\n");
>
> return 0;
> }

Looks good to me.

Acked-by: Waiman Long <[email protected]>

Subject: [tip: locking/urgent] locking/lockdep: Fix meaningless usages output of lock classes

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID: a23fb0cfa911423327e5a2089d33ab6cddc6a6aa
Gitweb: https://git.kernel.org/tip/a23fb0cfa911423327e5a2089d33ab6cddc6a6aa
Author: Xiongwei Song <[email protected]>
AuthorDate: Tue, 29 Jun 2021 21:59:16 +08:00
Committer: Peter Zijlstra <[email protected]>
CommitterDate: Fri, 02 Jul 2021 15:58:26 +02:00

locking/lockdep: Fix meaningless usages output of lock classes

When enabling CONFIG_LOCK_STAT, then CONFIG_LOCKDEP is forcedly enabled.
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 CONFIG_PROVE_LOCKING defined section,
however in the test situation, it's not.

The fix is to move the usages reading and seq_print from
CONFIG_PROVE_LOCKING undefined setcion to its defined section. Also,
locks_after list of lock_class is empty when CONFIG_PROVE_LOCKING
undefined, so do the same thing as what have done for usages of lock
classes.

With this patch with CONFIG_PROVE_LOCKING undefined, 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]>
Acked-by: Waiman Long <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
kernel/locking/lockdep_proc.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 8069783..b8d9a05 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -70,26 +70,28 @@ static int l_show(struct seq_file *m, void *v)
#ifdef CONFIG_DEBUG_LOCKDEP
seq_printf(m, " OPS:%8ld", debug_class_ops_read(class));
#endif
-#ifdef CONFIG_PROVE_LOCKING
- seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
- seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));
-#endif
+ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
+ seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
+ seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));

- get_usage_chars(class, usage);
- seq_printf(m, " %s", usage);
+ get_usage_chars(class, usage);
+ seq_printf(m, " %s", usage);
+ }

seq_printf(m, ": ");
print_name(m, class);
seq_puts(m, "\n");

- list_for_each_entry(entry, &class->locks_after, entry) {
- if (entry->distance == 1) {
- seq_printf(m, " -> [%p] ", entry->class->key);
- print_name(m, entry->class);
- seq_puts(m, "\n");
+ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
+ list_for_each_entry(entry, &class->locks_after, entry) {
+ if (entry->distance == 1) {
+ seq_printf(m, " -> [%p] ", entry->class->key);
+ print_name(m, entry->class);
+ seq_puts(m, "\n");
+ }
}
+ seq_puts(m, "\n");
}
- seq_puts(m, "\n");

return 0;
}

Subject: [tip: locking/urgent] locking/lockdep: Fix meaningless /proc/lockdep output of lock classes on !CONFIG_PROVE_LOCKING

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID: 4840ce2267f9d887f333d88a037c82c566f84081
Gitweb: https://git.kernel.org/tip/4840ce2267f9d887f333d88a037c82c566f84081
Author: Xiongwei Song <[email protected]>
AuthorDate: Tue, 29 Jun 2021 21:59:16 +08:00
Committer: Ingo Molnar <[email protected]>
CommitterDate: Mon, 05 Jul 2021 10:44:52 +02:00

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]
---
kernel/locking/lockdep_proc.c | 26 ++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 8069783..b8d9a05 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -70,26 +70,28 @@ static int l_show(struct seq_file *m, void *v)
#ifdef CONFIG_DEBUG_LOCKDEP
seq_printf(m, " OPS:%8ld", debug_class_ops_read(class));
#endif
-#ifdef CONFIG_PROVE_LOCKING
- seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
- seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));
-#endif
+ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
+ seq_printf(m, " FD:%5ld", lockdep_count_forward_deps(class));
+ seq_printf(m, " BD:%5ld", lockdep_count_backward_deps(class));

- get_usage_chars(class, usage);
- seq_printf(m, " %s", usage);
+ get_usage_chars(class, usage);
+ seq_printf(m, " %s", usage);
+ }

seq_printf(m, ": ");
print_name(m, class);
seq_puts(m, "\n");

- list_for_each_entry(entry, &class->locks_after, entry) {
- if (entry->distance == 1) {
- seq_printf(m, " -> [%p] ", entry->class->key);
- print_name(m, entry->class);
- seq_puts(m, "\n");
+ if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
+ list_for_each_entry(entry, &class->locks_after, entry) {
+ if (entry->distance == 1) {
+ seq_printf(m, " -> [%p] ", entry->class->key);
+ print_name(m, entry->class);
+ seq_puts(m, "\n");
+ }
}
+ seq_puts(m, "\n");
}
- seq_puts(m, "\n");

return 0;
}