Date: Sat, 3 Jun 2006 19:01:43 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 98411 for review Message-ID: <200606031901.k53J1hqd076121@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606031901.k53J1hqd076121>