From 0d7ad36cd0c158fe65514380432f4b70f744a7ce Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 30 Mar 2007 18:07:24 +0000 Subject: - Use lock_init/lock_destroy() to setup the lock_object inside of lockmgr. We can now use LOCK_CLASS() as a stronger check in lockmgr_chain() as a result. This required putting back lk_flags as lockmgr's use of flags conflicted with other flags in lo_flags otherwise. - Tweak 'show lock' output for lockmgr to match sx, rw, and mtx. --- sys/kern/kern_lock.c | 18 +++++++++++------- sys/sys/lockmgr.h | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'sys') diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index 318b039..58c13e5 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -180,7 +180,7 @@ acquire(struct lock **lkpp, int extflags, int wanted, int *contested, uint64_t * * accepted shared locks and shared-to-exclusive upgrades to go away. */ int -_lockmgr(struct lock *lkp, int flags, struct mtx *interlkp, +_lockmgr(struct lock *lkp, u_int flags, struct mtx *interlkp, struct thread *td, char *file, int line) { @@ -544,7 +544,6 @@ lockinit(lkp, prio, wmesg, timo, flags) lkp->lk_waitcount = 0; lkp->lk_exclusivecount = 0; lkp->lk_prio = prio; - lkp->lk_wmesg = wmesg; lkp->lk_timo = timo; lkp->lk_lockholder = LK_NOPROC; lkp->lk_newlock = NULL; @@ -552,6 +551,8 @@ lockinit(lkp, prio, wmesg, timo, flags) stack_zero(&lkp->lk_stack); #endif lock_profile_object_init(&lkp->lk_object, &lock_class_lockmgr, wmesg); + lock_init(&lkp->lk_object, &lock_class_lockmgr, wmesg, NULL, + LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE); } /* @@ -564,6 +565,7 @@ lockdestroy(lkp) CTR2(KTR_LOCK, "lockdestroy(): lkp == %p (lk_wmesg == \"%s\")", lkp, lkp->lk_wmesg); lock_profile_object_destroy(&lkp->lk_object); + lock_destroy(&lkp->lk_object); } /* @@ -661,7 +663,8 @@ lockmgr_chain(struct thread *td, struct thread **ownerp) lkp = td->td_wchan; /* Simple test to see if wchan points to a lockmgr lock. */ - if (lkp->lk_wmesg == td->td_wmesg) + if (LOCK_CLASS(&lkp->lk_object) == &lock_class_lockmgr && + lkp->lk_wmesg == td->td_wmesg) goto ok; /* @@ -670,7 +673,8 @@ lockmgr_chain(struct thread *td, struct thread **ownerp) */ lkp = (struct lock *)((char *)td->td_wchan - offsetof(struct lock, lk_flags)); - if (lkp->lk_wmesg == td->td_wmesg && (lkp->lk_flags & LK_WAITDRAIN)) + if (LOCK_CLASS(&lkp->lk_object) == &lock_class_lockmgr && + lkp->lk_wmesg == td->td_wmesg && (lkp->lk_flags & LK_WAITDRAIN)) goto ok; /* Doen't seem to be a lockmgr lock. */ @@ -697,8 +701,8 @@ db_show_lockmgr(struct lock_object *lock) lkp = (struct lock *)lock; - db_printf("lock type: %s\n", lkp->lk_wmesg); - db_printf("state: "); + db_printf(" lock type: %s\n", lkp->lk_wmesg); + db_printf(" state: "); if (lkp->lk_sharecount) db_printf("SHARED (count %d)\n", lkp->lk_sharecount); else if (lkp->lk_flags & LK_HAVE_EXCL) { @@ -709,6 +713,6 @@ db_show_lockmgr(struct lock_object *lock) } else db_printf("UNLOCKED\n"); if (lkp->lk_waitcount > 0) - db_printf("waiters: %d\n", lkp->lk_waitcount); + db_printf(" waiters: %d\n", lkp->lk_waitcount); } #endif diff --git a/sys/sys/lockmgr.h b/sys/sys/lockmgr.h index e3a0ac3..79a5130 100644 --- a/sys/sys/lockmgr.h +++ b/sys/sys/lockmgr.h @@ -53,6 +53,7 @@ struct mtx; struct lock { struct lock_object lk_object; /* common lock properties */ struct mtx *lk_interlock; /* lock on remaining fields */ + u_int lk_flags; /* see below */ int lk_sharecount; /* # of accepted shared locks */ int lk_waitcount; /* # of processes sleeping for lock */ short lk_exclusivecount; /* # of recursive exclusive locks */ @@ -66,7 +67,6 @@ struct lock { #endif }; -#define lk_flags lk_object.lo_flags #define lk_wmesg lk_object.lo_name /* * Lock request types: @@ -202,7 +202,7 @@ void lockinit(struct lock *, int prio, const char *wmesg, int timo, int flags); void lockdestroy(struct lock *); -int _lockmgr(struct lock *, int flags, +int _lockmgr(struct lock *, u_int flags, struct mtx *, struct thread *p, char *file, int line); void transferlockers(struct lock *, struct lock *); void lockmgr_printinfo(struct lock *); -- cgit v1.1