Skip to content

Commit f214737

Browse files
bvanasscheIngo Molnar
authored andcommitted
lockdep/lib/tests: Test dynamic key registration
Make sure that the lockdep_register_key() and lockdep_unregister_key() code is tested when running the lockdep tests. Signed-off-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Waiman Long <longman@redhat.com> Cc: Will Deacon <will.deacon@arm.com> Cc: johannes.berg@intel.com Cc: tj@kernel.org Link: https://lkml.kernel.org/r/20190214230058.196511-24-bvanassche@acm.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent d93ac78 commit f214737

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

tools/lib/lockdep/include/liblockdep/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
4545
void lock_release(struct lockdep_map *lock, int nested,
4646
unsigned long ip);
4747
void lockdep_reset_lock(struct lockdep_map *lock);
48+
void lockdep_register_key(struct lock_class_key *key);
49+
void lockdep_unregister_key(struct lock_class_key *key);
4850
extern void debug_check_no_locks_freed(const void *from, unsigned long len);
4951

5052
#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \

tools/lib/lockdep/include/liblockdep/mutex.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
struct liblockdep_pthread_mutex {
99
pthread_mutex_t mutex;
10+
struct lock_class_key key;
1011
struct lockdep_map dep_map;
1112
};
1213

@@ -27,11 +28,10 @@ static inline int __mutex_init(liblockdep_pthread_mutex_t *lock,
2728
return pthread_mutex_init(&lock->mutex, __mutexattr);
2829
}
2930

30-
#define liblockdep_pthread_mutex_init(mutex, mutexattr) \
31-
({ \
32-
static struct lock_class_key __key; \
33-
\
34-
__mutex_init((mutex), #mutex, &__key, (mutexattr)); \
31+
#define liblockdep_pthread_mutex_init(mutex, mutexattr) \
32+
({ \
33+
lockdep_register_key(&(mutex)->key); \
34+
__mutex_init((mutex), #mutex, &(mutex)->key, (mutexattr)); \
3535
})
3636

3737
static inline int liblockdep_pthread_mutex_lock(liblockdep_pthread_mutex_t *lock)
@@ -55,6 +55,7 @@ static inline int liblockdep_pthread_mutex_trylock(liblockdep_pthread_mutex_t *l
5555
static inline int liblockdep_pthread_mutex_destroy(liblockdep_pthread_mutex_t *lock)
5656
{
5757
lockdep_reset_lock(&lock->dep_map);
58+
lockdep_unregister_key(&lock->key);
5859
return pthread_mutex_destroy(&lock->mutex);
5960
}
6061

tools/lib/lockdep/tests/ABBA.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,13 @@ void main(void)
1414

1515
pthread_mutex_destroy(&b);
1616
pthread_mutex_destroy(&a);
17+
18+
pthread_mutex_init(&a, NULL);
19+
pthread_mutex_init(&b, NULL);
20+
21+
LOCK_UNLOCK_2(a, b);
22+
LOCK_UNLOCK_2(b, a);
23+
24+
pthread_mutex_destroy(&b);
25+
pthread_mutex_destroy(&a);
1726
}

0 commit comments

Comments
 (0)