From owner-p4-projects@FreeBSD.ORG Sat Jun 3 19:03:20 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 A450516A4C1; Sat, 3 Jun 2006 19:03:20 +0000 (UTC) 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 8242516A4AC for ; Sat, 3 Jun 2006 19:03:20 +0000 (UTC) (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 3683D43D4C for ; Sat, 3 Jun 2006 19:03:20 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k53J1hRM076124 for ; Sat, 3 Jun 2006 19:01:43 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k53J1hqd076121 for perforce@freebsd.org; Sat, 3 Jun 2006 19:01:43 GMT (envelope-from jhb@freebsd.org) Date: Sat, 3 Jun 2006 19:01:43 GMT Message-Id: <200606031901.k53J1hqd076121@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 98411 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: Sat, 03 Jun 2006 19:03:20 -0000 http://perforce.freebsd.org/chv.cgi?CH=98411 Change 98411 by jhb@jhb_mutex on 2006/06/03 19:01:04 Make mtx_owner() equivalent to mtx_rawowner(). Most places already know that the mutex is owned anyway and this is a macro only visible to kern_mutex.c. Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#124 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#124 (text+ko) ==== @@ -88,12 +88,15 @@ /* * Internal utility macros. + * + * Note that mtx_owner() can return an invalid pointer + * ((struct thread *)MTX_UNOWNED) if the mutex is unowned. */ #define mtx_unowned(m) ((m)->mtx_lock == MTX_UNOWNED) -#define mtx_rawowner(m) ((struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) +#define mtx_owner(m) ((struct thread *)((m)->mtx_lock & MTX_FLAGMASK)) -#define mtx_owner(m) (mtx_unowned((m)) ? NULL : mtx_rawowner((m))) +#define BAD_OWNER ((struct thread *)MTX_UNOWNED) #ifdef DDB static void db_show_mtx(struct lock_object *lock); @@ -551,10 +554,8 @@ if (m != &Giant && TD_IS_RUNNING(owner)) { #endif turnstile_release(&m->mtx_object); - while (mtx_rawowner(m) == owner && - TD_IS_RUNNING(owner)) { + while (mtx_owner(m) == owner && TD_IS_RUNNING(owner)) cpu_spinwait(); - } continue; } #endif /* SMP && !NO_ADAPTIVE_MUTEXES */ @@ -620,9 +621,7 @@ /* 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; + while (!_obtain_lock(m, tid)) { /* Give interrupts a chance while we spin. */ spinlock_exit(); @@ -641,9 +640,16 @@ DELAY(1); else { td = mtx_owner(m); + + /* + * If we get the bad owner cookie, the + * mutex is unlocked, so try again. + */ + if (td == BAD_OWNER) + continue; printf( "spin lock %p (%s) held by %p (tid %d) too long\n", - m, m->mtx_object.lo_name, mtx_rawowner(m), + m, m->mtx_object.lo_name, td, td ? td->td_tid : -1); #ifdef WITNESS witness_display_spinlock(&m->mtx_object, td);