Skip to content

Commit ce52a18

Browse files
Waiman-LongIngo Molnar
authored andcommitted
locking/lockdep: Add a faster path in __lock_release()
When __lock_release() is called, the most likely unlock scenario is on the innermost lock in the chain. In this case, we can skip some of the checks and provide a faster path to completion. Signed-off-by: Waiman Long <longman@redhat.com> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Link: http://lkml.kernel.org/r/1538511560-10090-4-git-send-email-longman@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 8ee1086 commit ce52a18

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

kernel/locking/lockdep.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3626,17 +3626,28 @@ __lock_release(struct lockdep_map *lock, int nested, unsigned long ip)
36263626
curr->lockdep_depth = i;
36273627
curr->curr_chain_key = hlock->prev_chain_key;
36283628

3629+
/*
3630+
* The most likely case is when the unlock is on the innermost
3631+
* lock. In this case, we are done!
3632+
*/
3633+
if (i == depth-1)
3634+
return 1;
3635+
36293636
if (reacquire_held_locks(curr, depth, i + 1))
36303637
return 0;
36313638

36323639
/*
36333640
* We had N bottles of beer on the wall, we drank one, but now
36343641
* there's not N-1 bottles of beer left on the wall...
36353642
*/
3636-
if (DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth - 1))
3637-
return 0;
3643+
DEBUG_LOCKS_WARN_ON(curr->lockdep_depth != depth-1);
36383644

3639-
return 1;
3645+
/*
3646+
* Since reacquire_held_locks() would have called check_chain_key()
3647+
* indirectly via __lock_acquire(), we don't need to do it again
3648+
* on return.
3649+
*/
3650+
return 0;
36403651
}
36413652

36423653
static int __lock_is_held(const struct lockdep_map *lock, int read)

0 commit comments

Comments
 (0)