From 14db6e91494d098f3c021f69fb9887a919fd2650 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 11 Dec 2010 00:35:29 -0800 Subject: [PATCH] kernel - Add debugging features * Add lwkt.mplock_backtrace to force the kernel to print a backtrace when it encounters a mplock collision. This is a bit problematic though as the backtrace can sometimes crash the kernel. * Allow lwkt.mplock_yield_delay to be set to 0. --- sys/kern/kern_mplock.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_mplock.c b/sys/kern/kern_mplock.c index c2800932a9..20cecc99b9 100644 --- a/sys/kern/kern_mplock.c +++ b/sys/kern/kern_mplock.c @@ -56,13 +56,16 @@ #ifdef SMP static int chain_mplock = 0; -static int bgl_yield = 10; +static int mplock_yield = 10; +static int mplock_backtrace; static __int64_t mplock_contention_count = 0; SYSCTL_INT(_lwkt, OID_AUTO, chain_mplock, CTLFLAG_RW, &chain_mplock, 0, "Chain IPI's to other CPU's potentially needing the MP lock when it is yielded"); -SYSCTL_INT(_lwkt, OID_AUTO, bgl_yield_delay, CTLFLAG_RW, &bgl_yield, 0, +SYSCTL_INT(_lwkt, OID_AUTO, mplock_yield_delay, CTLFLAG_RW, &mplock_yield, 0, "Duration of delay when MP lock is temporarily yielded"); +SYSCTL_INT(_lwkt, OID_AUTO, mplock_backtrace, CTLFLAG_RW, &mplock_backtrace, 0, + "Output backplane when mplock contention occurs"); SYSCTL_QUAD(_lwkt, OID_AUTO, mplock_contention_count, CTLFLAG_RW, &mplock_contention_count, 0, "spinning due to MPLOCK contention"); @@ -136,6 +139,10 @@ _get_mplock_contested(const char *file, int line) int nv; const void **stkframe = (const void **)&file; + if (mplock_backtrace > 0) { + --mplock_backtrace; + print_backtrace(-1); + } ++mplock_contention_count; for (;;) { ov = mp_lock; @@ -240,11 +247,11 @@ yield_mplock(thread_t td) { int savecnt; - if (td->td_xpcount == 0) { + if (td->td_xpcount == 0 && mplock_yield > 0) { savecnt = td->td_mpcount; td->td_mpcount = 1; rel_mplock(); - DELAY(bgl_yield); + DELAY(mplock_yield); get_mplock(); td->td_mpcount = savecnt; } -- 2.41.0