Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Aug 2008 20:34:57 GMT
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 146856 for review
Message-ID:  <200808072034.m77KYvw5010070@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=146856

Change 146856 by jhb@jhb_mutex on 2008/08/07 20:34:04

	- Tests for Giant with *sleep() and cv_*wait*().
	- Misc compile.

Affected files ...

.. //depot/projects/smpng/sys/modules/crash/crash.c#53 integrate
.. //depot/projects/smpng/sys/modules/crash2/crash2.c#23 integrate

Differences ...

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

@@ -90,6 +90,76 @@
 /* Events. */
 
 static void
+broadcast(void *cv)
+{
+
+	cv_broadcast(cv);
+}
+
+static void
+wait_unlock_Giant(void)
+{
+	struct callout c;
+	struct cv cv;
+
+	callout_init(&c, 0);
+	cv_init(&cv, "Giant");
+
+	mtx_lock(&Giant);
+	callout_reset(&c, 1, broadcast, &cv);
+	printf("This had better panic...\n");
+	cv_wait_unlock(&cv, &Giant);
+	cv_destroy(&cv);
+}
+CRASH_EVENT("try to cv_wait_unlock() with Giant", wait_unlock_Giant);
+
+static int Giant_wchan;
+
+static void
+pdrop_Giant(void)
+{
+
+	printf("This had better panic...\n");
+	mtx_lock(&Giant);
+	mtx_sleep(&Giant_wchan, &Giant, PDROP, "Giant", 1);
+}
+CRASH_EVENT("try to PDROP Giant", pdrop_Giant);
+
+static void
+sleeping_with_Giant(void)
+{
+	struct callout c;
+	struct cv cv;
+	int error;
+	
+	callout_init(&c, 0);
+	cv_init(&cv, "Giant");
+
+	mtx_assert(&Giant, MA_NOTOWNED);
+	mtx_lock(&Giant);
+	error = mtx_sleep(&Giant_wchan, &Giant, 0, "Giant", 1);
+        KASSERT(error == EWOULDBLOCK, ("mtx_sleep did not timeout"));
+	mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED);
+	error = cv_timedwait(&cv, &Giant, 1);
+        KASSERT(error == EWOULDBLOCK, ("cv_timedwait did not timeout"));
+	mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED);
+	error = cv_timedwait_sig(&cv, &Giant, 1);
+        KASSERT(error == EWOULDBLOCK, ("cv_timedwait_sig did not timeout"));
+	mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED);
+	callout_reset(&c, 1, broadcast, &cv);
+	printf("Testing cv_wait with Giant\n");
+	cv_wait(&cv, &Giant);
+	mtx_assert(&Giant, MA_OWNED | MA_NOTRECURSED);
+	callout_reset(&c, 1, broadcast, &cv);
+	printf("Testing cv_wait_sig with Giant\n");
+	cv_wait_sig(&cv, &Giant);
+	mtx_unlock(&Giant);
+	mtx_assert(&Giant, MA_NOTOWNED);
+	cv_destroy(&cv);	
+}
+CRASH_EVENT("use Giant for sleep interlock", sleeping_with_Giant);
+
+static void
 pause_forever(void)
 {
 	struct thread *td;
@@ -163,7 +233,7 @@
 	sleepq_add(&race_wchan, NULL, "race", SLEEPQ_SLEEP, 0);
 	sleepq_set_timeout(&race_wchan, 1);
 	DELAY(2 * 1000 * 1000);
-	rval = sleepq_timedwait(&race_wchan);
+	rval = sleepq_timedwait(&race_wchan, 0);
 	binuptime(&finish);
 	thread_lock(td);
 	sched_unbind(td);

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

@@ -244,10 +244,10 @@
 	if (thread % 2)
 		sx_xlock(sxs[thread % 4]);
 	else
-		lockmgr(locks[thread % 4], LK_EXCLUSIVE, NULL, curthread);
+		lockmgr(locks[thread % 4], LK_EXCLUSIVE, NULL);
 	pause("slp_dead", hz/10);
 	if (thread % 2)
-		lockmgr(locks[(thread + 1) % 4], LK_SHARED, NULL, curthread);
+		lockmgr(locks[(thread + 1) % 4], LK_SHARED, NULL);
 	else
 		sx_slock(sxs[(thread + 1) % 4]);
 }
@@ -258,9 +258,9 @@
 lockmgr_deadlock(int thread)
 {
 
-	lockmgr(locks[thread % 4], LK_EXCLUSIVE, NULL, curthread);
+	lockmgr(locks[thread % 4], LK_EXCLUSIVE, NULL);
 	pause("lk_dead", hz/10);
-	lockmgr(locks[(thread + 1) % 4], LK_EXCLUSIVE, NULL, curthread);
+	lockmgr(locks[(thread + 1) % 4], LK_EXCLUSIVE, NULL);
 }
 CRASH2_EVENT("lockmgr cycle", lockmgr_deadlock, lockmgr_deadlock,
     lockmgr_deadlock, lockmgr_deadlock);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808072034.m77KYvw5010070>