Commit f214737b authored by Bart Van Assche's avatar Bart Van Assche Committed by Ingo Molnar

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: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarPeter 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.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent d93ac78b
...@@ -45,6 +45,8 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass, ...@@ -45,6 +45,8 @@ void lock_acquire(struct lockdep_map *lock, unsigned int subclass,
void lock_release(struct lockdep_map *lock, int nested, void lock_release(struct lockdep_map *lock, int nested,
unsigned long ip); unsigned long ip);
void lockdep_reset_lock(struct lockdep_map *lock); void lockdep_reset_lock(struct lockdep_map *lock);
void lockdep_register_key(struct lock_class_key *key);
void lockdep_unregister_key(struct lock_class_key *key);
extern void debug_check_no_locks_freed(const void *from, unsigned long len); extern void debug_check_no_locks_freed(const void *from, unsigned long len);
#define STATIC_LOCKDEP_MAP_INIT(_name, _key) \ #define STATIC_LOCKDEP_MAP_INIT(_name, _key) \
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
struct liblockdep_pthread_mutex { struct liblockdep_pthread_mutex {
pthread_mutex_t mutex; pthread_mutex_t mutex;
struct lock_class_key key;
struct lockdep_map dep_map; struct lockdep_map dep_map;
}; };
...@@ -29,9 +30,8 @@ static inline int __mutex_init(liblockdep_pthread_mutex_t *lock, ...@@ -29,9 +30,8 @@ static inline int __mutex_init(liblockdep_pthread_mutex_t *lock,
#define liblockdep_pthread_mutex_init(mutex, mutexattr) \ #define liblockdep_pthread_mutex_init(mutex, mutexattr) \
({ \ ({ \
static struct lock_class_key __key; \ lockdep_register_key(&(mutex)->key); \
\ __mutex_init((mutex), #mutex, &(mutex)->key, (mutexattr)); \
__mutex_init((mutex), #mutex, &__key, (mutexattr)); \
}) })
static inline int liblockdep_pthread_mutex_lock(liblockdep_pthread_mutex_t *lock) 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 ...@@ -55,6 +55,7 @@ static inline int liblockdep_pthread_mutex_trylock(liblockdep_pthread_mutex_t *l
static inline int liblockdep_pthread_mutex_destroy(liblockdep_pthread_mutex_t *lock) static inline int liblockdep_pthread_mutex_destroy(liblockdep_pthread_mutex_t *lock)
{ {
lockdep_reset_lock(&lock->dep_map); lockdep_reset_lock(&lock->dep_map);
lockdep_unregister_key(&lock->key);
return pthread_mutex_destroy(&lock->mutex); return pthread_mutex_destroy(&lock->mutex);
} }
......
...@@ -14,4 +14,13 @@ void main(void) ...@@ -14,4 +14,13 @@ void main(void)
pthread_mutex_destroy(&b); pthread_mutex_destroy(&b);
pthread_mutex_destroy(&a); pthread_mutex_destroy(&a);
pthread_mutex_init(&a, NULL);
pthread_mutex_init(&b, NULL);
LOCK_UNLOCK_2(a, b);
LOCK_UNLOCK_2(b, a);
pthread_mutex_destroy(&b);
pthread_mutex_destroy(&a);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment