socsvn commit: r239193 - in soc2012/gmiller/locking-head: . tools/regression/lib/libthr/lockprof

gmiller at FreeBSD.org gmiller at FreeBSD.org
Mon Jul 9 18:58:04 UTC 2012


Author: gmiller
Date: Mon Jul  9 18:58:02 2012
New Revision: 239193
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239193

Log:
   r239216 at FreeBSD-dev:  root | 2012-07-03 11:16:28 -0500
   Add tests for conflict counts and total and maximum wait times for
   contested locks.

Modified:
  soc2012/gmiller/locking-head/   (props changed)
  soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c

Modified: soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c
==============================================================================
--- soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c	Mon Jul  9 18:57:52 2012	(r239192)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c	Mon Jul  9 18:58:02 2012	(r239193)
@@ -52,6 +52,35 @@
 	pthread_resetstatistics_np();
 }
 
+void *
+conflict_thread_func(void *v)
+{
+	v = v;
+
+	pthread_mutex_lock(&mutex);
+
+	sleep(5);
+
+	pthread_mutex_unlock(&mutex);
+
+	return NULL;
+}
+
+void
+conflict_test()
+{
+	pthread_t thread1;
+	pthread_t thread2;
+
+	pthread_resetstatistics_np();
+
+	pthread_create(&thread1, NULL, conflict_thread_func, NULL);
+	pthread_create(&thread2, NULL, conflict_thread_func, NULL);
+
+	pthread_join(thread2, NULL);
+	pthread_join(thread1, NULL);
+}
+
 #define	MAX_TESTS	(100)
 
 int success_count = 0;
@@ -173,6 +202,35 @@
 	check(record_count == 0);
 }
 
+void
+check_stats_conflict(void)
+{
+	int		record_count = 0;
+	struct pthread_statistics_np stats;
+	long		tm;
+
+	pthread_getstatistics_begin_np(&stats);
+	while (pthread_getstatistics_next_np(&stats)) {
+		record_count++;
+	}
+	pthread_getstatistics_end_np(&stats);
+
+	check(record_count == 1);
+
+	pthread_getstatistics_begin_np(&stats);
+	pthread_getstatistics_next_np(&stats);
+	pthread_getstatistics_end_np(&stats);
+
+	check(stats.contest_count == 1);
+
+	tm = stats.wait_time.tv_sec * 1000000L +
+	    stats.wait_time.tv_nsec / 1000;
+	check(tm > 0);
+
+	tm = stats.wait_max.tv_sec * 1000000L + stats.wait_max.tv_nsec / 1000;
+	check(tm > 0);
+}
+
 int
 main(void)
 {
@@ -185,6 +243,9 @@
 	multi_cycle();
 	check_stats_multi();
 
+	conflict_test();
+	check_stats_conflict();
+
 	show_test_results();
 
 	return 0;


More information about the svn-soc-all mailing list