* [PATCH 0/3] some improvements for lockdep
@ 2021-06-17 14:28 Xiongwei Song
2021-06-17 14:28 ` [PATCH 1/3] locking/lockdep: unlikely bfs_error() inside Xiongwei Song
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Xiongwei Song @ 2021-06-17 14:28 UTC (permalink / raw)
To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel, Xiongwei Song
Unlikely the checks of return values of graph walk will improve the
performance to some degree, patch 1 and patch 2 are for this.
The patch 3 will print a warning after counting lock deps when hitting
bfs errors.
Xiongwei Song (3):
locking/lockdep: unlikely bfs_error function
locking/lockdep: unlikely conditons about BFS_RMATCH
locking/lockdep: print possible warning after counting deps
kernel/locking/lockdep.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/3] locking/lockdep: unlikely bfs_error() inside 2021-06-17 14:28 [PATCH 0/3] some improvements for lockdep Xiongwei Song @ 2021-06-17 14:28 ` Xiongwei Song 2021-06-17 14:28 ` [PATCH 2/3] locking/lockdep: unlikely conditons about BFS_RMATCH Xiongwei Song 2021-06-17 14:28 ` [PATCH 3/3] locking/lockdep: print possible warning after counting deps Xiongwei Song 2 siblings, 0 replies; 6+ messages in thread From: Xiongwei Song @ 2021-06-17 14:28 UTC (permalink / raw) To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel, Xiongwei Song From: Xiongwei Song <sxwjean@gmail.com> The error from graph walk is small probability event, and there are some bfs_error calls during lockdep detection, so unlikely bfs_error inside can improve performance a little bit. Suggested-by: Waiman Long <longman@redhat.com> Signed-off-by: Xiongwei Song <sxwjean@gmail.com> --- kernel/locking/lockdep.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 7641bd407239..a8a66a2a9bc1 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -1540,7 +1540,7 @@ enum bfs_result { */ static inline bool bfs_error(enum bfs_result res) { - return res < 0; + return unlikely(res < 0); } /* @@ -2089,7 +2089,7 @@ check_path(struct held_lock *target, struct lock_list *src_entry, ret = __bfs_forwards(src_entry, target, match, skip, target_entry); - if (unlikely(bfs_error(ret))) + if (bfs_error(ret)) print_bfs_bug(ret); return ret; @@ -2936,7 +2936,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, * in the graph whose neighbours are to be checked. */ ret = check_noncircular(next, prev, trace); - if (unlikely(bfs_error(ret) || ret == BFS_RMATCH)) + if (bfs_error(ret) || unlikely(ret == BFS_RMATCH)) return 0; if (!check_irq_usage(curr, prev, next)) -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] locking/lockdep: unlikely conditons about BFS_RMATCH 2021-06-17 14:28 [PATCH 0/3] some improvements for lockdep Xiongwei Song 2021-06-17 14:28 ` [PATCH 1/3] locking/lockdep: unlikely bfs_error() inside Xiongwei Song @ 2021-06-17 14:28 ` Xiongwei Song 2021-06-17 14:28 ` [PATCH 3/3] locking/lockdep: print possible warning after counting deps Xiongwei Song 2 siblings, 0 replies; 6+ messages in thread From: Xiongwei Song @ 2021-06-17 14:28 UTC (permalink / raw) To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel, Xiongwei Song From: Xiongwei Song <sxwjean@gmail.com> The probability that graph walk will return BFS_RMATCH is slim, so unlikey conditons about BFS_RMATCH can improve performance a little bit. Signed-off-by: Xiongwei Song <sxwjean@gmail.com> --- kernel/locking/lockdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index a8a66a2a9bc1..cb94097014d8 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2750,7 +2750,7 @@ check_redundant(struct held_lock *src, struct held_lock *target) */ ret = check_path(target, &src_entry, hlock_equal, usage_skip, &target_entry); - if (ret == BFS_RMATCH) + if (unlikely(ret == BFS_RMATCH)) debug_atomic_inc(nr_redundant); return ret; @@ -2992,7 +2992,7 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev, ret = check_redundant(prev, next); if (bfs_error(ret)) return 0; - else if (ret == BFS_RMATCH) + else if (unlikely(ret == BFS_RMATCH)) return 2; if (!*trace) { -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] locking/lockdep: print possible warning after counting deps 2021-06-17 14:28 [PATCH 0/3] some improvements for lockdep Xiongwei Song 2021-06-17 14:28 ` [PATCH 1/3] locking/lockdep: unlikely bfs_error() inside Xiongwei Song 2021-06-17 14:28 ` [PATCH 2/3] locking/lockdep: unlikely conditons about BFS_RMATCH Xiongwei Song @ 2021-06-17 14:28 ` Xiongwei Song 2021-06-17 15:12 ` Boqun Feng 2 siblings, 1 reply; 6+ messages in thread From: Xiongwei Song @ 2021-06-17 14:28 UTC (permalink / raw) To: peterz, mingo, will, longman, boqun.feng; +Cc: linux-kernel, Xiongwei Song From: Xiongwei Song <sxwjean@gmail.com> The graph walk might hit error when counting dependencies. Once the return value is negative, print a warning to reminder users. Suggested-by: Waiman Long <longman@redhat.com> Signed-off-by: Xiongwei Song <sxwjean@gmail.com> --- kernel/locking/lockdep.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index cb94097014d8..cfe0f4374594 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -2028,8 +2028,12 @@ static unsigned long __lockdep_count_forward_deps(struct lock_list *this) { unsigned long count = 0; struct lock_list *target_entry; + enum bfs_result ret; + + ret = __bfs_forwards(this, (void *)&count, noop_count, NULL, &target_entry); - __bfs_forwards(this, (void *)&count, noop_count, NULL, &target_entry); + if (bfs_error(ret)) + print_bfs_bug(ret); return count; } @@ -2053,8 +2057,12 @@ static unsigned long __lockdep_count_backward_deps(struct lock_list *this) { unsigned long count = 0; struct lock_list *target_entry; + enum bfs_result ret; + + ret = __bfs_backwards(this, (void *)&count, noop_count, NULL, &target_entry); - __bfs_backwards(this, (void *)&count, noop_count, NULL, &target_entry); + if (bfs_error(ret)) + print_bfs_bug(ret); return count; } -- 2.30.2 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] locking/lockdep: print possible warning after counting deps 2021-06-17 14:28 ` [PATCH 3/3] locking/lockdep: print possible warning after counting deps Xiongwei Song @ 2021-06-17 15:12 ` Boqun Feng 2021-06-18 1:54 ` Xiongwei Song 0 siblings, 1 reply; 6+ messages in thread From: Boqun Feng @ 2021-06-17 15:12 UTC (permalink / raw) To: Xiongwei Song; +Cc: peterz, mingo, will, longman, linux-kernel, Xiongwei Song Hi, On Thu, Jun 17, 2021 at 10:28:28PM +0800, Xiongwei Song wrote: > From: Xiongwei Song <sxwjean@gmail.com> > > The graph walk might hit error when counting dependencies. Once the > return value is negative, print a warning to reminder users. > Thanks for the improvement, but please see below: > Suggested-by: Waiman Long <longman@redhat.com> > Signed-off-by: Xiongwei Song <sxwjean@gmail.com> > --- > kernel/locking/lockdep.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > index cb94097014d8..cfe0f4374594 100644 > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -2028,8 +2028,12 @@ static unsigned long __lockdep_count_forward_deps(struct lock_list *this) > { > unsigned long count = 0; > struct lock_list *target_entry; > + enum bfs_result ret; > + > + ret = __bfs_forwards(this, (void *)&count, noop_count, NULL, &target_entry); > > - __bfs_forwards(this, (void *)&count, noop_count, NULL, &target_entry); > + if (bfs_error(ret)) > + print_bfs_bug(ret); Here print_bfs_bug() will eventually call debug_locks_off_graph_unlock() to release the graph lock, and the caller (lockdep_count_fowards_deps()) will also call graph_unlock() afterwards, and that means we unlock *twice* if a BFS error happens... although in that case, lockdep should stop working so messing up with the graph lock may not hurt anything, but still, I don't think we want to do that. So probably you can open-code __lockdep_count_forward_deps() into lockdep_count_forwards_deps(), and call print_bfs_bug() or graph_unlock() accordingly. The body of __lockdep_count_forward_deps() is really small, so I think it's OK to open-code it into its caller. Regards, Boqun > > return count; > } > @@ -2053,8 +2057,12 @@ static unsigned long __lockdep_count_backward_deps(struct lock_list *this) > { > unsigned long count = 0; > struct lock_list *target_entry; > + enum bfs_result ret; > + > + ret = __bfs_backwards(this, (void *)&count, noop_count, NULL, &target_entry); > > - __bfs_backwards(this, (void *)&count, noop_count, NULL, &target_entry); > + if (bfs_error(ret)) > + print_bfs_bug(ret); > > return count; > } > -- > 2.30.2 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] locking/lockdep: print possible warning after counting deps 2021-06-17 15:12 ` Boqun Feng @ 2021-06-18 1:54 ` Xiongwei Song 0 siblings, 0 replies; 6+ messages in thread From: Xiongwei Song @ 2021-06-18 1:54 UTC (permalink / raw) To: Boqun Feng Cc: Xiongwei Song, peterz, mingo, will, longman, Linux Kernel Mailing List On Thu, Jun 17, 2021 at 11:13 PM Boqun Feng <boqun.feng@gmail.com> wrote: > > Hi, > > On Thu, Jun 17, 2021 at 10:28:28PM +0800, Xiongwei Song wrote: > > From: Xiongwei Song <sxwjean@gmail.com> > > > > The graph walk might hit error when counting dependencies. Once the > > return value is negative, print a warning to reminder users. > > > > Thanks for the improvement, but please see below: > > > Suggested-by: Waiman Long <longman@redhat.com> > > Signed-off-by: Xiongwei Song <sxwjean@gmail.com> > > --- > > kernel/locking/lockdep.c | 12 ++++++++++-- > > 1 file changed, 10 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > > index cb94097014d8..cfe0f4374594 100644 > > --- a/kernel/locking/lockdep.c > > +++ b/kernel/locking/lockdep.c > > @@ -2028,8 +2028,12 @@ static unsigned long __lockdep_count_forward_deps(struct lock_list *this) > > { > > unsigned long count = 0; > > struct lock_list *target_entry; > > + enum bfs_result ret; > > + > > + ret = __bfs_forwards(this, (void *)&count, noop_count, NULL, &target_entry); > > > > - __bfs_forwards(this, (void *)&count, noop_count, NULL, &target_entry); > > + if (bfs_error(ret)) > > + print_bfs_bug(ret); > > Here print_bfs_bug() will eventually call debug_locks_off_graph_unlock() > to release the graph lock, and the caller (lockdep_count_fowards_deps()) > will also call graph_unlock() afterwards, and that means we unlock > *twice* if a BFS error happens... although in that case, lockdep should > stop working so messing up with the graph lock may not hurt anything, > but still, I don't think we want to do that. > > So probably you can open-code __lockdep_count_forward_deps() into > lockdep_count_forwards_deps(), and call print_bfs_bug() or > graph_unlock() accordingly. The body of __lockdep_count_forward_deps() > is really small, so I think it's OK to open-code it into its caller. Thank you so much for the detailed comments. Let me improve and update the patch. Regards, Xiongwei > > Regards, > Boqun > > > > > return count; > > } > > @@ -2053,8 +2057,12 @@ static unsigned long __lockdep_count_backward_deps(struct lock_list *this) > > { > > unsigned long count = 0; > > struct lock_list *target_entry; > > + enum bfs_result ret; > > + > > + ret = __bfs_backwards(this, (void *)&count, noop_count, NULL, &target_entry); > > > > - __bfs_backwards(this, (void *)&count, noop_count, NULL, &target_entry); > > + if (bfs_error(ret)) > > + print_bfs_bug(ret); > > > > return count; > > } > > -- > > 2.30.2 > > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-06-18 1:55 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-06-17 14:28 [PATCH 0/3] some improvements for lockdep Xiongwei Song 2021-06-17 14:28 ` [PATCH 1/3] locking/lockdep: unlikely bfs_error() inside Xiongwei Song 2021-06-17 14:28 ` [PATCH 2/3] locking/lockdep: unlikely conditons about BFS_RMATCH Xiongwei Song 2021-06-17 14:28 ` [PATCH 3/3] locking/lockdep: print possible warning after counting deps Xiongwei Song 2021-06-17 15:12 ` Boqun Feng 2021-06-18 1:54 ` Xiongwei Song
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox