All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] locking/lockdep: Fix meaningless usages output of lock classes
@ 2021-06-28 15:17 Xiongwei Song
  2021-06-28 21:17 ` Waiman Long
  0 siblings, 1 reply; 3+ messages in thread
From: Xiongwei Song @ 2021-06-28 15:17 UTC (permalink / raw)
  To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel, Xiongwei Song

From: Xiongwei Song <sxwjean@gmail.com>

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.

Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
---
 kernel/locking/lockdep_proc.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
index 806978314496..a1ec2652d492 100644
--- a/kernel/locking/lockdep_proc.c
+++ b/kernel/locking/lockdep_proc.c
@@ -70,23 +70,25 @@ 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");
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] locking/lockdep: Fix meaningless usages output of lock classes
  2021-06-28 15:17 [PATCH v2] locking/lockdep: Fix meaningless usages output of lock classes Xiongwei Song
@ 2021-06-28 21:17 ` Waiman Long
  2021-06-29  2:52   ` Xiongwei Song
  0 siblings, 1 reply; 3+ messages in thread
From: Waiman Long @ 2021-06-28 21:17 UTC (permalink / raw)
  To: Xiongwei Song, peterz, mingo, will, boqun.feng
  Cc: linux-kernel, Xiongwei Song

On 6/28/21 11:17 AM, Xiongwei Song wrote:
> From: Xiongwei Song <sxwjean@gmail.com>
>
> 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, CONFIG_LOCKDEP without CONFIG_PROVE_LOCKING will make 
/proc/lockdep displays just the list of lock classes with their 
associated lock keys. I think it is worth explicitly saying that in the 
commit log.
> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> ---
>   kernel/locking/lockdep_proc.c | 24 +++++++++++++-----------
>   1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
> index 806978314496..a1ec2652d492 100644
> --- a/kernel/locking/lockdep_proc.c
> +++ b/kernel/locking/lockdep_proc.c
> @@ -70,23 +70,25 @@ 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");

Maybe you can remove the blank lines in this case by moving the last 
seq_puts() inside the if loop. The blank lines are not really needed 
without the associated locks_after information.

Cheers,
Longman


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] locking/lockdep: Fix meaningless usages output of lock classes
  2021-06-28 21:17 ` Waiman Long
@ 2021-06-29  2:52   ` Xiongwei Song
  0 siblings, 0 replies; 3+ messages in thread
From: Xiongwei Song @ 2021-06-29  2:52 UTC (permalink / raw)
  To: Waiman Long
  Cc: Xiongwei Song, peterz, mingo, will, Boqun Feng,
	Linux Kernel Mailing List

On Tue, Jun 29, 2021 at 5:17 AM Waiman Long <llong@redhat.com> wrote:
>
> On 6/28/21 11:17 AM, Xiongwei Song wrote:
> > From: Xiongwei Song <sxwjean@gmail.com>
> >
> > 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, CONFIG_LOCKDEP without CONFIG_PROVE_LOCKING will make
> /proc/lockdep displays just the list of lock classes with their
> associated lock keys. I think it is worth explicitly saying that in the
> commit log.

Make sense. Will update.

> > Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> > ---
> >   kernel/locking/lockdep_proc.c | 24 +++++++++++++-----------
> >   1 file changed, 13 insertions(+), 11 deletions(-)
> >
> > diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
> > index 806978314496..a1ec2652d492 100644
> > --- a/kernel/locking/lockdep_proc.c
> > +++ b/kernel/locking/lockdep_proc.c
> > @@ -70,23 +70,25 @@ 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");
>
> Maybe you can remove the blank lines in this case by moving the last
> seq_puts() inside the if loop. The blank lines are not really needed
> without the associated locks_after information.

Yeah, I agree. Thank you.

Regards,
Xiongwei

> Cheers,
> Longman
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-29  2:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-28 15:17 [PATCH v2] locking/lockdep: Fix meaningless usages output of lock classes Xiongwei Song
2021-06-28 21:17 ` Waiman Long
2021-06-29  2:52   ` Xiongwei Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.