Index: head/sys/kern/kern_malloc.c =================================================================== --- head/sys/kern/kern_malloc.c +++ head/sys/kern/kern_malloc.c @@ -520,6 +520,10 @@ if (flags & M_WAITOK) { KASSERT(curthread->td_intr_nesting_level == 0, ("malloc(M_WAITOK) in interrupt context")); +#ifdef EPOCH_TRACE + if (__predict_false(curthread->td_epochnest > 0)) + epoch_trace_list(curthread); +#endif KASSERT(curthread->td_epochnest == 0, ("malloc(M_WAITOK) in epoch context")); } Index: head/sys/kern/kern_synch.c =================================================================== --- head/sys/kern/kern_synch.c +++ head/sys/kern/kern_synch.c @@ -148,6 +148,10 @@ ("sleeping without a lock")); KASSERT(ident != NULL, ("_sleep: NULL ident")); KASSERT(TD_IS_RUNNING(td), ("_sleep: curthread not running")); +#ifdef EPOCH_TRACE + if (__predict_false(curthread->td_epochnest > 0)) + epoch_trace_list(curthread); +#endif KASSERT(td->td_epochnest == 0, ("sleeping in an epoch section")); if (priority & PDROP) KASSERT(lock != NULL && lock != &Giant.lock_object, Index: head/sys/kern/subr_epoch.c =================================================================== --- head/sys/kern/subr_epoch.c +++ head/sys/kern/subr_epoch.c @@ -234,6 +234,17 @@ } else SLIST_REMOVE_HEAD(&td->td_epochs, et_tlink); } + +/* Used by assertions that check thread state before going to sleep. */ +void +epoch_trace_list(struct thread *td) +{ + epoch_tracker_t iet; + + SLIST_FOREACH(iet, &td->td_epochs, et_tlink) + printf("Epoch %s entered at %s:%d\n", iet->et_epoch->e_name, + iet->et_file, iet->et_line); +} #endif /* EPOCH_TRACE */ static void Index: head/sys/kern/subr_trap.c =================================================================== --- head/sys/kern/subr_trap.c +++ head/sys/kern/subr_trap.c @@ -166,6 +166,10 @@ WITNESS_WARN(WARN_PANIC, NULL, "userret: returning"); KASSERT(td->td_critnest == 0, ("userret: Returning in a critical section")); +#ifdef EPOCH_TRACE + if (__predict_false(curthread->td_epochnest > 0)) + epoch_trace_list(curthread); +#endif KASSERT(td->td_epochnest == 0, ("userret: Returning in an epoch section")); KASSERT(td->td_locks == 0, Index: head/sys/sys/epoch.h =================================================================== --- head/sys/sys/epoch.h +++ head/sys/sys/epoch.h @@ -83,6 +83,7 @@ void _epoch_enter_preempt(epoch_t epoch, epoch_tracker_t et EPOCH_FILE_LINE); void _epoch_exit_preempt(epoch_t epoch, epoch_tracker_t et EPOCH_FILE_LINE); #ifdef EPOCH_TRACE +void epoch_trace_list(struct thread *); #define epoch_enter_preempt(epoch, et) _epoch_enter_preempt(epoch, et, __FILE__, __LINE__) #define epoch_exit_preempt(epoch, et) _epoch_exit_preempt(epoch, et, __FILE__, __LINE__) #else