From owner-p4-projects@FreeBSD.ORG Fri Feb 24 15:09:07 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 9D17E16A425; Fri, 24 Feb 2006 15:09:06 +0000 (GMT) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7372D16A422 for ; Fri, 24 Feb 2006 15:09:06 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 21C1843D49 for ; Fri, 24 Feb 2006 15:09:06 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k1OF95Ye098371 for ; Fri, 24 Feb 2006 15:09:06 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k1OF957n098368 for perforce@freebsd.org; Fri, 24 Feb 2006 15:09:05 GMT (envelope-from jhb@freebsd.org) Date: Fri, 24 Feb 2006 15:09:05 GMT Message-Id: <200602241509.k1OF957n098368@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 92336 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Feb 2006 15:09:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=92336 Change 92336 by jhb@jhb_zion on 2006/02/24 15:08:55 - Make the spin lock too long panic message more useful and more accurate (the "5 seconds" is dubious). - Allow idle threads to spin on sched_lock forever. Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#118 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#118 (text+ko) ==== @@ -91,8 +91,9 @@ */ #define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED) -#define mtx_owner(m) (mtx_unowned((m)) ? NULL \ - : (struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) +#define mtx_rawowner(m) ((struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) + +#define mtx_owner(m) (mtx_unowned((m)) ? NULL : mtx_rawowner((m))) #ifdef DDB static void db_show_mtx(struct lock_object *lock); @@ -550,7 +551,8 @@ if (m != &Giant && TD_IS_RUNNING(owner)) { #endif turnstile_release(&m->mtx_object); - while (mtx_owner(m) == owner && TD_IS_RUNNING(owner)) { + while (mtx_rawowner(m) == owner && + TD_IS_RUNNING(owner)) { cpu_spinwait(); } continue; @@ -606,7 +608,8 @@ _mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file, int line) { - int i = 0; + int i = 0, idlespin = 0; + struct thread *td; #ifdef __i386__ int apic_hack; #endif @@ -614,6 +617,9 @@ if (LOCK_LOG_TEST(&m->mtx_object, opts)) CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); + /* It's ok for the idle loop to spin forever on sched_lock. */ + if (m == &sched_lock && curthread == PCPU_GET(idlethread)) + idlespin = 1; for (;;) { if (_obtain_lock(m, tid)) break; @@ -630,14 +636,17 @@ cpu_spinwait(); continue; } - if (i < 60000000) + if (i < 60000000 || kdb_active || panicstr != NULL || + idlespin) DELAY(1); - else if (!kdb_active && !panicstr) { - printf("spin lock %s held by %p for > 5 seconds\n", - m->mtx_object.lo_name, (void *)m->mtx_lock); + else { + td = mtx_owner(m); + printf( + "spin lock %p (%s) held by %p (tid %d) too long\n", + m, m->mtx_object.lo_name, mtx_rawowner(m), + td ? td->td_tid : -1); #ifdef WITNESS - witness_display_spinlock(&m->mtx_object, - mtx_owner(m)); + witness_display_spinlock(&m->mtx_object, td); #endif panic("spin lock held too long"); }