--- //depot/projects/smpng/sys/kern/kern_lock.c 2008/08/25 16:33:41 +++ //depot/user/jhb/lock/kern/kern_lock.c 2008/08/29 14:51:34 @@ -375,7 +375,7 @@ case LK_SHARED: if (LK_CAN_WITNESS(flags)) WITNESS_CHECKORDER(&lk->lock_object, LOP_NEWORDER, - file, line); + file, line, ilk); for (;;) { x = lk->lk_lock; @@ -505,7 +505,7 @@ case LK_EXCLUSIVE: if (LK_CAN_WITNESS(flags)) WITNESS_CHECKORDER(&lk->lock_object, LOP_NEWORDER | - LOP_EXCLUSIVE, file, line); + LOP_EXCLUSIVE, file, line, ilk); /* * If curthread already holds the lock and this one is @@ -724,7 +724,7 @@ case LK_DRAIN: if (LK_CAN_WITNESS(flags)) WITNESS_CHECKORDER(&lk->lock_object, LOP_NEWORDER | - LOP_EXCLUSIVE, file, line); + LOP_EXCLUSIVE, file, line, ilk); /* * Trying to drain a lock we already own will result in a --- //depot/projects/smpng/sys/kern/kern_mutex.c 2008/03/13 21:35:00 +++ //depot/user/jhb/lock/kern/kern_mutex.c 2008/08/29 14:51:34 @@ -177,7 +177,7 @@ ("mtx_lock() of spin mutex %s @ %s:%d", m->lock_object.lo_name, file, line)); WITNESS_CHECKORDER(&m->lock_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE, - file, line); + file, line, NULL); _get_sleep_lock(m, curthread, opts, file, line); LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file, @@ -221,7 +221,7 @@ ("mtx_lock_spin: recursed on non-recursive mutex %s @ %s:%d\n", m->lock_object.lo_name, file, line)); WITNESS_CHECKORDER(&m->lock_object, opts | LOP_NEWORDER | LOP_EXCLUSIVE, - file, line); + file, line, NULL); _get_spin_lock(m, curthread, opts, file, line); LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file, line); @@ -515,7 +513,7 @@ ("thread_lock: recursed on non-recursive mutex %s @ %s:%d\n", m->lock_object.lo_name, file, line)); WITNESS_CHECKORDER(&m->lock_object, - opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line); + opts | LOP_NEWORDER | LOP_EXCLUSIVE, file, line, NULL); while (!_obtain_lock(m, tid)) { if (m->mtx_lock == tid) { m->mtx_recurse++; --- //depot/projects/smpng/sys/kern/kern_rmlock.c 2007/12/20 22:29:11 +++ //depot/user/jhb/lock/kern/kern_rmlock.c 2008/08/29 14:51:34 @@ -433,7 +433,7 @@ WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, - file, line); + file, line, NULL); _rm_wlock(rm); @@ -460,7 +460,7 @@ { - WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER , file, line); + WITNESS_CHECKORDER(&rm->lock_object, LOP_NEWORDER , file, line, NULL); _rm_rlock(rm, tracker); --- //depot/projects/smpng/sys/kern/kern_rwlock.c 2008/07/25 18:20:23 +++ //depot/user/jhb/lock/kern/kern_rwlock.c 2008/08/29 14:51:34 @@ -206,7 +206,7 @@ KASSERT(rw->rw_lock != RW_DESTROYED, ("rw_wlock() of destroyed rwlock @ %s:%d", file, line)); WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, - line); + line, NULL); __rw_wlock(rw, curthread, file, line); LOCK_LOG_LOCK("WLOCK", &rw->lock_object, 0, rw->rw_recurse, file, line); WITNESS_LOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line); @@ -283,7 +283,7 @@ KASSERT(rw_wowner(rw) != curthread, ("%s (%s): wlock already held @ %s:%d", __func__, rw->lock_object.lo_name, file, line)); - WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER, file, line); + WITNESS_CHECKORDER(&rw->lock_object, LOP_NEWORDER, file, line, NULL); for (;;) { /* --- //depot/projects/smpng/sys/kern/kern_sx.c 2008/08/05 21:26:01 +++ //depot/user/jhb/lock/kern/kern_sx.c 2008/08/29 14:51:34 @@ -211,7 +211,7 @@ MPASS(curthread != NULL); KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, ("sx_slock() of destroyed sx @ %s:%d", file, line)); - WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER, file, line); + WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER, file, line, NULL); error = __sx_slock(sx, opts, file, line); if (!error) { LOCK_LOG_LOCK("SLOCK", &sx->lock_object, 0, 0, file, line); @@ -254,7 +254,7 @@ KASSERT(sx->sx_lock != SX_LOCK_DESTROYED, ("sx_xlock() of destroyed sx @ %s:%d", file, line)); WITNESS_CHECKORDER(&sx->lock_object, LOP_NEWORDER | LOP_EXCLUSIVE, file, - line); + line, NULL); error = __sx_xlock(sx, curthread, opts, file, line); if (!error) { LOCK_LOG_LOCK("XLOCK", &sx->lock_object, 0, sx->sx_recurse, --- //depot/projects/smpng/sys/kern/subr_witness.c 2008/08/25 16:33:41 +++ //depot/user/jhb/lock/kern/subr_witness.c 2008/08/29 16:30:50 @@ -1013,10 +1013,10 @@ void witness_checkorder(struct lock_object *lock, int flags, const char *file, - int line) + int line, struct lock_object *interlock) { struct lock_list_entry **lock_list, *lle; - struct lock_instance *lock1, *lock2; + struct lock_instance *lock1, *lock2, *plock; struct lock_class *class; struct witness *w, *w1; struct thread *td; @@ -1096,11 +1096,25 @@ } /* + * Find the previously acquired lock, but ignore interlocks. + */ + plock = &(*lock_list)->ll_children[(*lock_list)->ll_count - 1]; + if (interlock != NULL && plock->li_lock == interlock) { + if ((*lock_list)->ll_count == 1) { + /* + * The interlock is the only lock we hold, so + * nothing to do. + */ + return; + } + plock = &(*lock_list)->ll_children[(*lock_list)->ll_count - 2]; + } + + /* * Try to perform most checks without a lock. If this succeeds we * can skip acquiring the lock and return success. */ - lock1 = &(*lock_list)->ll_children[(*lock_list)->ll_count - 1]; - w1 = lock1->li_lock->lo_witness; + w1 = plock->li_lock->lo_witness; if (witness_lock_order_check(w1, w)) return; @@ -1143,12 +1157,20 @@ MPASS(j < WITNESS_COUNT); lock1 = &lle->ll_children[i]; - w1 = lock1->li_lock->lo_witness; + + /* + * Ignore the interlock the first time we see it. + */ + if (interlock != NULL && interlock == lock1->li_lock) { + interlock = NULL; + continue; + } /* * If this lock doesn't undergo witness checking, * then skip it. */ + w1 = lock1->li_lock->lo_witness; if (w1 == NULL) { KASSERT((lock1->li_lock->lo_flags & LO_WITNESS) == 0, ("lock missing witness structure")); @@ -1273,7 +1295,6 @@ return; } } - lock1 = &(*lock_list)->ll_children[(*lock_list)->ll_count - 1]; /* * If requested, build a new lock order. However, don't build a new @@ -1282,11 +1303,11 @@ * always come before Giant. */ if (flags & LOP_NEWORDER && - !(lock1->li_lock == &Giant.lock_object && + !(plock->li_lock == &Giant.lock_object && (lock->lo_flags & LO_SLEEPABLE) != 0)) { CTR3(KTR_WITNESS, "%s: adding %s as a child of %s", __func__, - w->w_name, lock1->li_lock->lo_witness->w_name); - itismychild(lock1->li_lock->lo_witness, w); + w->w_name, plock->li_lock->lo_witness->w_name); + itismychild(plock->li_lock->lo_witness, w); } out: mtx_unlock_spin(&w_mtx); --- //depot/projects/smpng/sys/sys/lock.h 2008/08/25 16:33:41 +++ //depot/user/jhb/lock/sys/lock.h 2008/08/29 14:51:34 @@ -203,7 +203,8 @@ void witness_init(struct lock_object *, const char *); void witness_destroy(struct lock_object *); int witness_defineorder(struct lock_object *, struct lock_object *); -void witness_checkorder(struct lock_object *, int, const char *, int); +void witness_checkorder(struct lock_object *, int, const char *, int, + struct lock_object *); void witness_lock(struct lock_object *, int, const char *, int); void witness_upgrade(struct lock_object *, int, const char *, int); void witness_downgrade(struct lock_object *, int, const char *, int); @@ -231,8 +232,8 @@ #define WITNESS_DESTROY(lock) \ witness_destroy(lock) -#define WITNESS_CHECKORDER(lock, flags, file, line) \ - witness_checkorder((lock), (flags), (file), (line)) +#define WITNESS_CHECKORDER(lock, flags, file, line, interlock) \ + witness_checkorder((lock), (flags), (file), (line), (interlock)) #define WITNESS_DEFINEORDER(lock1, lock2) \ witness_defineorder((struct lock_object *)(lock1), \ @@ -276,7 +277,7 @@ #define WITNESS_INIT(lock, type) #define WITNESS_DESTROY(lock) #define WITNESS_DEFINEORDER(lock1, lock2) 0 -#define WITNESS_CHECKORDER(lock, flags, file, line) +#define WITNESS_CHECKORDER(lock, flags, file, line, interlock) #define WITNESS_LOCK(lock, flags, file, line) #define WITNESS_UPGRADE(lock, flags, file, line) #define WITNESS_DOWNGRADE(lock, flags, file, line) @@ -296,10 +297,10 @@ */ #define witness_check(l) \ WITNESS_CHECKORDER(&(l)->lock_object, LOP_EXCLUSIVE, LOCK_FILE, \ - LOCK_LINE) + LOCK_LINE, NULL) #define witness_check_shared(l) \ - WITNESS_CHECKORDER(&(l)->lock_object, 0, LOCK_FILE, LOCK_LINE) + WITNESS_CHECKORDER(&(l)->lock_object, 0, LOCK_FILE, LOCK_LINE, NULL) #endif /* _KERNEL */ #endif /* _SYS_LOCK_H_ */