PERFORCE change 98411 for review

John Baldwin jhb at FreeBSD.org
Sat Jun 3 19:03:20 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=98411

Change 98411 by jhb at 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);


More information about the p4-projects mailing list