From owner-svn-soc-all@FreeBSD.ORG Mon Jul 9 18:58:04 2012 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from socsvn.FreeBSD.org (unknown [IPv6:2001:4f8:fff6::2f]) by hub.freebsd.org (Postfix) with SMTP id 0A56D106567F for ; Mon, 9 Jul 2012 18:58:02 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 09 Jul 2012 18:58:02 +0000 Date: Mon, 09 Jul 2012 18:58:02 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <20120709185803.0A56D106567F@hub.freebsd.org> Cc: Subject: socsvn commit: r239193 - in soc2012/gmiller/locking-head: . tools/regression/lib/libthr/lockprof X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Jul 2012 18:58:04 -0000 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@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;