From bfc761fdba732e46979638ae050d0477eaf4b2cb Mon Sep 17 00:00:00 2001 From: attilio Date: Sun, 18 Nov 2007 14:43:53 +0000 Subject: Expand lock class with the "virtual" function lc_assert which will offer an unified way for all the lock primitives to express lock assertions. Currenty, lockmgrs and rmlocks don't have assertions, so just panic in that case. This will be a base for more callout improvements. Ok'ed by: jhb, jeff --- sys/kern/kern_lock.c | 9 +++++++++ sys/kern/kern_mutex.c | 10 ++++++++++ sys/kern/kern_rmlock.c | 9 +++++++++ sys/kern/kern_rwlock.c | 9 +++++++++ sys/kern/kern_sx.c | 9 +++++++++ sys/sys/lock.h | 1 + 6 files changed, 47 insertions(+) diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 7256630..6a5f213 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$"); #include #endif +static void assert_lockmgr(struct lock_object *lock, int what); #ifdef DDB #include static void db_show_lockmgr(struct lock_object *lock); @@ -70,6 +71,7 @@ static int unlock_lockmgr(struct lock_object *lock); struct lock_class lock_class_lockmgr = { .lc_name = "lockmgr", .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_lockmgr, #ifdef DDB .lc_ddb_show = db_show_lockmgr, #endif @@ -83,6 +85,13 @@ struct lock_class lock_class_lockmgr = { */ void +assert_lockmgr(struct lock_object *lock, int what) +{ + + panic("lockmgr locks do not support assertions"); +} + +void lock_lockmgr(struct lock_object *lock, int how) { diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 036a277..cb054fd 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -84,6 +84,7 @@ __FBSDID("$FreeBSD$"); #define mtx_owner(m) ((struct thread *)((m)->mtx_lock & ~MTX_FLAGMASK)) +static void assert_mtx(struct lock_object *lock, int what); #ifdef DDB static void db_show_mtx(struct lock_object *lock); #endif @@ -98,6 +99,7 @@ static int unlock_spin(struct lock_object *lock); struct lock_class lock_class_mtx_sleep = { .lc_name = "sleep mutex", .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, + .lc_assert = assert_mtx, #ifdef DDB .lc_ddb_show = db_show_mtx, #endif @@ -107,6 +109,7 @@ struct lock_class lock_class_mtx_sleep = { struct lock_class lock_class_mtx_spin = { .lc_name = "spin mutex", .lc_flags = LC_SPINLOCK | LC_RECURSABLE, + .lc_assert = assert_mtx, #ifdef DDB .lc_ddb_show = db_show_mtx, #endif @@ -135,6 +138,13 @@ static inline void lock_profile_init(void) {;} #endif void +assert_mtx(struct lock_object *lock, int what) +{ + + mtx_assert((struct mtx *)lock, what); +} + +void lock_mtx(struct lock_object *lock, int how) { diff --git a/sys/kern/kern_rmlock.c b/sys/kern/kern_rmlock.c index 276aee6..cbf5cc5 100644 --- a/sys/kern/kern_rmlock.c +++ b/sys/kern/kern_rmlock.c @@ -71,12 +71,14 @@ static __inline void compiler_memory_barrier(void) { __asm __volatile("":::"memory"); } +static void assert_rm(struct lock_object *lock, int what); static void lock_rm(struct lock_object *lock, int how); static int unlock_rm(struct lock_object *lock); struct lock_class lock_class_rm = { .lc_name = "rm", .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, + .lc_assert = assert_rm, #if 0 #ifdef DDB .lc_ddb_show = db_show_rwlock, @@ -87,6 +89,13 @@ struct lock_class lock_class_rm = { }; static void +assert_rm(struct lock_object *lock, int what) +{ + + panic("assert_rm called"); +} + +static void lock_rm(struct lock_object *lock, int how) { panic("lock_rm called"); } diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 809e526..315f887 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -59,12 +59,14 @@ CTASSERT((RW_RECURSE & LO_CLASSFLAGS) == RW_RECURSE); static void db_show_rwlock(struct lock_object *lock); #endif +static void assert_rw(struct lock_object *lock, int what); static void lock_rw(struct lock_object *lock, int how); static int unlock_rw(struct lock_object *lock); struct lock_class lock_class_rw = { .lc_name = "rw", .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_rw, #ifdef DDB .lc_ddb_show = db_show_rwlock, #endif @@ -103,6 +105,13 @@ struct lock_class lock_class_rw = { #endif void +assert_rw(struct lock_object *lock, int what) +{ + + rw_assert((struct rwlock *)lock, what); +} + +void lock_rw(struct lock_object *lock, int how) { struct rwlock *rw; diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index 8e99ee3..1e3f135 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -103,6 +103,7 @@ CTASSERT(((SX_ADAPTIVESPIN | SX_RECURSE) & LO_CLASSFLAGS) == */ #define sx_recursed(sx) ((sx)->sx_recurse != 0) +static void assert_sx(struct lock_object *lock, int what); #ifdef DDB static void db_show_sx(struct lock_object *lock); #endif @@ -112,6 +113,7 @@ static int unlock_sx(struct lock_object *lock); struct lock_class lock_class_sx = { .lc_name = "sx", .lc_flags = LC_SLEEPLOCK | LC_SLEEPABLE | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_sx, #ifdef DDB .lc_ddb_show = db_show_sx, #endif @@ -124,6 +126,13 @@ struct lock_class lock_class_sx = { #endif void +assert_sx(struct lock_object *lock, int what) +{ + + sx_assert((struct sx *)lock, what); +} + +void lock_sx(struct lock_object *lock, int how) { struct sx *sx; diff --git a/sys/sys/lock.h b/sys/sys/lock.h index 2a9c4aa..a70e077 100644 --- a/sys/sys/lock.h +++ b/sys/sys/lock.h @@ -57,6 +57,7 @@ struct thread; struct lock_class { const char *lc_name; u_int lc_flags; + void (*lc_assert)(struct lock_object *lock, int what); void (*lc_ddb_show)(struct lock_object *lock); void (*lc_lock)(struct lock_object *lock, int how); int (*lc_unlock)(struct lock_object *lock); -- cgit v1.1