From da7985a02b212ef3c447e35ed8d168b9026dcb40 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Tue, 16 Aug 2022 00:21:15 +0000 Subject: [PATCH] KERNEL_LOCK(9): Send an IPI to print holder's stack trace on spinout. --- sys/kern/kern_lock.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sys/kern/kern_lock.c b/sys/kern/kern_lock.c index c302a6cc517f..332f161d5f40 100644 --- a/sys/kern/kern_lock.c +++ b/sys/kern/kern_lock.c @@ -134,6 +134,22 @@ lockops_t _kernel_lock_ops = { .lo_dump = _kernel_lock_dump, }; +#ifdef LOCKDEBUG + +#include + +static void +kernel_lock_trace_ipi(void *cookie) +{ + + printf("%s[%d %s]: hogging kernel lock\n", cpu_name(curcpu()), + curlwp->l_lid, + curlwp->l_name ? curlwp->l_name : curproc->p_comm); + db_stacktrace(); +} + +#endif + /* * Initialize the kernel lock. */ @@ -177,6 +193,7 @@ _kernel_lock(int nlocks) LOCKSTAT_FLAG(lsflag); struct lwp *owant; #ifdef LOCKDEBUG + static struct cpu_info *kernel_lock_holder; u_int spins = 0; #endif int s; @@ -235,6 +252,11 @@ _kernel_lock(int nlocks) #ifdef LOCKDEBUG if (SPINLOCK_SPINOUT(spins)) { extern int start_init_exec; + ipi_msg_t msg = { + .func = kernel_lock_trace_ipi, + }; + ipi_unicast(&msg, kernel_lock_holder); + ipi_wait(&msg); if (start_init_exec) _KERNEL_LOCK_ABORT("spinout"); } @@ -278,6 +300,10 @@ _kernel_lock(int nlocks) #ifndef __HAVE_ATOMIC_AS_MEMBAR membar_enter(); #endif + +#ifdef LOCKDEBUG + kernel_lock_holder = curcpu(); +#endif } /*