PERFORCE change 85783 for review

John Baldwin jhb at FreeBSD.org
Mon Oct 24 08:49:54 PDT 2005


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

Change 85783 by jhb at jhb_slimer on 2005/10/24 15:49:43

	Don't panic if a spin lock is added that is not in the static order
	list.  Just warn about it instead.

Affected files ...

.. //depot/projects/smpng/sys/kern/subr_witness.c#140 edit

Differences ...

==== //depot/projects/smpng/sys/kern/subr_witness.c#140 (text+ko) ====

@@ -450,6 +450,12 @@
 static int witness_cold = 1;
 
 /*
+ * This global is set to 1 once the static lock orders have been enrolled
+ * so that a warning can be issued for any spin locks enrolled later.
+ */
+static int witness_spin_warn = 0;
+
+/*
  * Global variables for book keeping.
  */
 static int lock_cur_cnt;
@@ -500,6 +506,7 @@
 			w = w1;
 		}
 	}
+	witness_spin_warn = 1;
 
 	/* Iterate through all locks and add them to witness. */
 	mtx_lock(&all_mtx);
@@ -513,7 +520,7 @@
 	mtx_unlock(&all_mtx);
 
 	/* Mark the witness code as being ready for use. */
-	atomic_store_rel_int(&witness_cold, 0);
+	witness_cold = 0;
 
 	mtx_lock(&Giant);
 }
@@ -1403,13 +1410,15 @@
 		}
 	}
 	/*
-	 * This isn't quite right, as witness_cold is still 0 while we
-	 * enroll all the locks initialized before witness_initialize().
+	 * We issue a warning for any spin locks not defined in the static
+	 * order list as a way to discourage their use (folks should really
+	 * be using non-spin mutexes most of the time).  However, several
+	 * 3rd part device drivers use spin locks because that is all they
+	 * have available on Windows and Linux and they think that normal
+	 * mutexes are insufficient.
 	 */
-	if ((lock_class->lc_flags & LC_SPINLOCK) && !witness_cold) {
-		mtx_unlock_spin(&w_mtx);
-		panic("spin lock %s not in order list", description);
-	}
+	if ((lock_class->lc_flags & LC_SPINLOCK) && witness_spin_warn)
+		printf("WITNESS: spin lock %s not in order list", description);
 	if ((w = witness_get()) == NULL)
 		return (NULL);
 	w->w_name = description;


More information about the p4-projects mailing list