Index: kern/subr_sleepqueue.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_sleepqueue.c,v retrieving revision 1.43 diff -u -r1.43 subr_sleepqueue.c --- kern/subr_sleepqueue.c 25 Jan 2008 19:44:46 -0000 1.43 +++ kern/subr_sleepqueue.c 7 Feb 2008 06:19:22 -0000 @@ -801,7 +801,7 @@ if (TD_IS_SLEEPING(td) && TD_ON_SLEEPQ(td)) { wchan = td->td_wchan; sc = SC_LOOKUP(wchan); - MPASS(td->td_lock == &sc->sc_lock); + THREAD_LOCKPTR_ASSERT(td, &sc->sc_lock); sq = sleepq_lookup(wchan); MPASS(sq != NULL); td->td_flags |= TDF_TIMEOUT; Index: kern/subr_turnstile.c =================================================================== RCS file: /home/ncvs/src/sys/kern/subr_turnstile.c,v retrieving revision 1.171 diff -u -r1.171 subr_turnstile.c --- kern/subr_turnstile.c 6 Feb 2008 01:02:13 -0000 1.171 +++ kern/subr_turnstile.c 7 Feb 2008 06:19:23 -0000 @@ -180,7 +180,7 @@ THREAD_LOCK_ASSERT(td, MA_OWNED); pri = td->td_priority; ts = td->td_blocked; - MPASS(td->td_lock == &ts->ts_lock); + THREAD_LOCKPTR_ASSERT(td, &ts->ts_lock); /* * Grab a recursive lock on this turnstile chain so it stays locked * for the whole operation. The caller expects us to return with @@ -267,7 +267,7 @@ */ ts = td->td_blocked; MPASS(ts != NULL); - MPASS(td->td_lock == &ts->ts_lock); + THREAD_LOCKPTR_ASSERT(td, &ts->ts_lock); /* Resort td on the list if needed. */ if (!turnstile_adjust_thread(ts, td)) { mtx_unlock_spin(&ts->ts_lock); @@ -308,7 +308,7 @@ * It needs to be moved if either its priority is lower than * the previous thread or higher than the next thread. */ - MPASS(td->td_lock == &ts->ts_lock); + THREAD_LOCKPTR_ASSERT(td, &ts->ts_lock); td1 = TAILQ_PREV(td, threadqueue, td_lockq); td2 = TAILQ_NEXT(td, td_lockq); if ((td1 != NULL && td->td_priority < td1->td_priority) || @@ -422,7 +422,7 @@ */ ts = td->td_blocked; MPASS(ts != NULL); - MPASS(td->td_lock == &ts->ts_lock); + THREAD_LOCKPTR_ASSERT(td, &ts->ts_lock); mtx_assert(&ts->ts_lock, MA_OWNED); /* Resort the turnstile on the list. */ @@ -645,7 +645,7 @@ td = turnstile_first_waiter(ts); MPASS(td != NULL); MPASS(td->td_proc->p_magic == P_MAGIC); - MPASS(td->td_lock == &ts->ts_lock); + THREAD_LOCKPTR_ASSERT(td, &ts->ts_lock); /* * Update the priority of the new owner if needed. @@ -740,7 +740,7 @@ CTR4(KTR_LOCK, "%s: td %d blocked on [%p] %s", __func__, td->td_tid, lock, lock->lo_name); - MPASS(td->td_lock == &ts->ts_lock); + THREAD_LOCKPTR_ASSERT(td, &ts->ts_lock); SCHED_STAT_INC(switch_turnstile); mi_switch(SW_VOL, NULL); @@ -918,7 +918,7 @@ td = TAILQ_FIRST(&pending_threads); TAILQ_REMOVE(&pending_threads, td, td_lockq); thread_lock(td); - MPASS(td->td_lock == &ts->ts_lock); + THREAD_LOCKPTR_ASSERT(td, &ts->ts_lock); MPASS(td->td_proc->p_magic == P_MAGIC); MPASS(TD_ON_LOCK(td)); TD_CLR_LOCK(td); Index: sys/proc.h =================================================================== RCS file: /home/ncvs/src/sys/sys/proc.h,v retrieving revision 1.502 diff -u -r1.502 proc.h --- sys/proc.h 6 Feb 2008 01:02:12 -0000 1.502 +++ sys/proc.h 7 Feb 2008 06:19:27 -0000 @@ -313,6 +313,17 @@ mtx_assert(__m, (type)); \ } while (0) +#ifdef INVARIANTS +#define THREAD_LOCKPTR_ASSERT(td, lock) \ +do { \ + struct mtx *__m = (td)->td_lock; \ + KASSERT((__m == &blocked_lock || __m == (lock)), \ + ("Thread %p lock %p does not match %p", td, __m, (lock))); \ +} while (0) +#else +#define THREAD_LOCKPTR_ASSERT(td, lock) +#endif + /* * Flags kept in td_flags: * To change these you MUST have the scheduler lock.