Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Mar 2003 10:39:38 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 26697 for review
Message-ID:  <200303111839.h2BIdc7t064866@repoman.freebsd.org>

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

Change 26697 by jhb@jhb_laptop on 2003/03/11 10:39:34

	Add a synchronization event to force the threads to both be
	executing the eventhandler at the same time to force the race
	that we are testing.

Affected files ...

.. //depot/projects/smpng/sys/modules/evtest/evtest.c#19 edit

Differences ...

==== //depot/projects/smpng/sys/modules/evtest/evtest.c#19 (text+ko) ====

@@ -54,16 +54,16 @@
 #include <sys/sysctl.h>
 #include <sys/systm.h>
 
-#define	MAX_EVENT	10
+#define	MAX_EVENT	11
 #define	NUM_THREADS	2
 
 #define	EVENT_TYPE_BROADCAST	0x1
 
 static eventhandler_tag first_tag, foo_tag;
-static struct cv event_cv, broadcast_cv, event_recvd;
+static struct cv event_cv, broadcast_cv, event_recvd, sync_cv;
 static struct mtx event_mtx;
 static struct sema evtest_sema;
-static int event, broadcast_count, num_threads;
+static int event, broadcast_count, num_threads, sync_threads;
 
 struct thread_info {
 	struct proc *ti_p;
@@ -85,6 +85,7 @@
 	{ "add post handler" },
 	{ "add dump handler" },
 	{ "add removefoo handler" },
+	{ "add synchronization handler" },
 };
 
 static int	mod_event(struct module *module, int cmd, void *arg);
@@ -99,7 +100,7 @@
 EVENTHANDLER_DECLARE(evtest, evtest_fn *);
 
 static evtest_fn evtest_print, evtest_wait, evtest_post, evtest_dumplist,
-    evtest_removefoo;
+    evtest_removefoo, evtest_sync;
 
 struct evtest_fninfo {
 	evtest_fn *ev_fn;
@@ -112,6 +113,7 @@
 	{ &evtest_post, "evtest_post" },
 	{ &evtest_dumplist, "evtest_dumplist" },
 	{ &evtest_removefoo, "evtest_removefoo" },
+	{ &evtest_sync, "evtest_sync" },
 	{ NULL, NULL }
 };
 	
@@ -223,6 +225,19 @@
 	mtx_unlock(&event_mtx);
 }
 
+static void
+evtest_sync(void *arg)
+{
+
+	mtx_lock(&event_mtx);
+	sync_threads++;
+	if (sync_threads == num_threads)
+		cv_broadcast(&sync_cv);
+	else
+		cv_wait(&sync_cv, &event_mtx);
+	mtx_unlock(&event_mtx);
+}
+
 /*
  * Yes, this is really gross and greatly violates the eventhandler
  * abstraction.  Deal.
@@ -279,6 +294,7 @@
 			}
 		}
 		event = 0;
+		sync_threads = 0;
 		cv_signal(&event_recvd);
 		while ((ev = event) == 0)
 			cv_wait(&event_cv, &event_mtx);
@@ -348,6 +364,10 @@
 			first_tag = EVENTHANDLER_REGISTER(evtest,
 			    evtest_removefoo, NULL, 5);
 			break;
+		case 11:
+			first_tag = EVENTHANDLER_REGISTER(evtest,
+			    evtest_sync, NULL, 5);
+			break;
 		default:
 			panic("event %d is bogus\n", event);
 		}
@@ -406,6 +426,7 @@
 	mtx_lock(&event_mtx);
 	for (i = 0; i < NUM_THREADS; i++)
 		thread_destroy(i);
+	cv_destroy(&sync_cv);
 	cv_destroy(&broadcast_cv);
 	sema_destroy(&evtest_sema);
 	mtx_destroy(&event_mtx);
@@ -426,6 +447,7 @@
 	cv_init(&event_recvd, "evrcvd");
 	sema_init(&evtest_sema, 1, "evtest semaphore");
 	cv_init(&broadcast_cv, "evbcast");
+	cv_init(&sync_cv, "evsync");
 	error = thread_create(0, "event thread 0");
 	if (error) {
 		cleanup();

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




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