PERFORCE change 117183 for review

John Baldwin jhb at FreeBSD.org
Mon Apr 2 13:42:09 UTC 2007


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

Change 117183 by jhb at jhb_mutex on 2007/04/02 13:41:44

	Merge in fixes and new sx tests from jhb_lock.

Affected files ...

.. //depot/projects/smpng/sys/modules/crash/crash.c#37 integrate
.. //depot/projects/smpng/sys/modules/crash2/crash2.c#21 integrate

Differences ...

==== //depot/projects/smpng/sys/modules/crash/crash.c#37 (text+ko) ====

@@ -87,6 +87,23 @@
 /* Events. */
 
 static void
+cv_sx(void)
+{
+	struct cv blah;
+
+	cv_init(&blah, "blah");
+	sx_slock(&foo);
+	cv_timedwait(&blah, &foo, hz/10);
+	if (sx_try_upgrade(&foo) == 0)
+		printf("bad juju, upgrade failed\n");
+	else {
+		cv_timedwait(&blah, &foo, hz/10);
+		sx_xunlock(&foo);
+	}
+}
+CRASH_EVENT("test cv_wait() with sx", cv_sx);
+
+static void
 sleep_sx_recurse(void)
 {
 	sx_slock(&foo);
@@ -660,7 +677,7 @@
 	kdb_enter("order should be test1 then test2");
 	printf("Check order of test1 -> test2 should succeed.\n");
 	mtx_lock(&test1_mtx);
-	witness_check_mutex(&test2_mtx);
+	witness_check(&test2_mtx);
 	mtx_unlock(&test1_mtx);
 	status = WITNESS_DEFINEORDER(&test2_mtx, &test1_mtx);
 	printf("Status of test2 -> test1 set order should be EDOOFUS: %d\n",

==== //depot/projects/smpng/sys/modules/crash2/crash2.c#21 (text+ko) ====

@@ -94,6 +94,7 @@
 static struct sx one, two, three, four;
 static struct lock fee, fi, fo, fum;
 static int crash2_wait = 1;
+static volatile int lots = 50000;
 
 static int	mod_event(struct module *module, int cmd, void *arg);
 static int	load(void *arg);
@@ -131,6 +132,111 @@
 static struct sx *sxs[] = { &one, &two, &three, &four };
 
 static void
+one_grades(int dummy)
+{
+
+	switch (arc4random() % 10) {
+	case 0:
+		sx_xlock(&one);
+		DELAY(30);
+		sx_xunlock(&one);
+		break;
+	case 1:
+	case 2:
+		sx_slock(&one);
+		DELAY(40);
+		if (!sx_try_upgrade(&one)) {
+			sx_sunlock(&one);
+			sx_xlock(&one);
+			DELAY(40);
+		}
+		DELAY(10);
+		sx_xunlock(&one);
+		break;
+	case 3:
+	case 4:
+	case 5:
+	case 6:
+		sx_xlock(&one);
+		DELAY(30);
+		sx_downgrade(&one);
+		DELAY(20);
+		sx_sunlock(&one);
+		break;
+	default:
+		sx_slock(&one);
+		DELAY(50);
+		sx_sunlock(&one);
+	}
+}
+
+static void
+one_grades_lots(int dummy)
+{
+	int i;
+
+	for (i = 0; i < lots; i++)
+		one_grades(dummy);
+}
+
+CRASH2_EVENT("lots of one up/downgrades", one_grades_lots, one_grades_lots,
+    one_grades_lots, one_grades_lots);
+CRASH2_EVENT("one up/downgrades", one_grades, one_grades, one_grades,
+    one_grades);
+
+static void
+whack_one(int dummy)
+{
+	switch (arc4random() % 10) {
+	case 0:
+	case 1:
+	case 2:
+		sx_xlock(&one);
+		DELAY(30);
+		sx_xunlock(&one);
+		break;
+	default:
+		sx_slock(&one);
+		DELAY(150);
+		sx_sunlock(&one);
+	}
+}
+
+static void
+whack_one_lots(int dummy)
+{
+	int i;
+
+	for (i = 0; i < lots; i++)
+		whack_one(dummy);
+}
+
+static void
+xlock_one(int dummy)
+{
+
+	sx_xlock(&one);
+	DELAY(1000);
+	sx_xunlock(&one);
+}
+
+static void
+slock_one(int dummy)
+{
+
+	sx_slock(&one);
+	DELAY(1000);
+	sx_sunlock(&one);
+}
+
+CRASH2_EVENT("whack one repeatedly", whack_one_lots, whack_one_lots,
+    whack_one_lots, whack_one_lots);
+CRASH2_EVENT("whack one", whack_one, whack_one, whack_one, whack_one);
+CRASH2_EVENT("one 2 each", slock_one, xlock_one, slock_one, xlock_one);
+CRASH2_EVENT("one writers", xlock_one, xlock_one, xlock_one, xlock_one);
+CRASH2_EVENT("one readers", slock_one, slock_one, slock_one, slock_one);
+
+static void
 sleep_deadlock(int thread)
 {
 
@@ -212,7 +318,7 @@
 {
 	int i;
 
-	for (i = 0; i < 50000; i++)
+	for (i = 0; i < lots; i++)
 		foo_grades(dummy);
 }
 
@@ -254,7 +360,7 @@
 {
 	int i;
 
-	for (i = 0; i < 50000; i++)
+	for (i = 0; i < lots; i++)
 		whack_foo(dummy);
 }
 
@@ -341,6 +447,9 @@
 SYSCTL_PROC(_debug_crash2, OID_AUTO, test, CTLTYPE_INT | CTLFLAG_RW, 0, 0,
     sysctl_debug_crash2_test, "I", "");
 
+SYSCTL_INT(_debug_crash2, OID_AUTO, lots, CTLFLAG_RW,
+    __DEVOLATILE(int *, &lots), 0, "Iterations for 'lots' tests");
+
 static void
 crash_thread(void *arg)
 {
@@ -355,14 +464,15 @@
 		while ((ev = event[i]) == 0)
 			cv_wait(&event_cv, &event_mtx);
 		event[i] = 0;
+		mtx_unlock(&event_mtx);
 		if (ev == -1) {
 			printf("crash2[%d]: exiting\n", i);
-			mtx_unlock(&event_mtx);
 			kthread_exit(0);
 			break;
 		}
 		/* Give sysctl time to finish. */
 		pause("delay", hz / 5);
+		mtx_lock(&event_mtx);
 		if (ev < 0 || ev >= MAX_EVENT) {
 			printf("crash2[%d]: event %d is not defined!\n", i, ev);
 			continue;


More information about the p4-projects mailing list