From owner-svn-soc-all@FreeBSD.ORG Tue Jul 10 21:27:18 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 71048106564A for ; Tue, 10 Jul 2012 21:27:16 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Tue, 10 Jul 2012 21:27:16 +0000 Date: Tue, 10 Jul 2012 21:27:16 +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: <20120710212716.71048106564A@hub.freebsd.org> Cc: Subject: socsvn commit: r239256 - in soc2012/gmiller/locking-head: . include lib/libthr/thread lib/libwitness 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: Tue, 10 Jul 2012 21:27:18 -0000 Author: gmiller Date: Tue Jul 10 21:27:15 2012 New Revision: 239256 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239256 Log: r239219@FreeBSD-dev: root | 2012-07-03 15:50:08 -0500 Begin implementation of LoR logging in libwitness. Rename lock profiling statistics *_np() functions for more consistent naming scheme: pthread_getstatistics_begin_np() -> pthread_statistics_begin_np() pthread_getstatistics_next_np() -> pthread_statistics_next_np() pthread_getstatistics_end_np() -> pthread_statistics_end_np() pthread_resetstatistics_np() -> pthread_statistics_reset_np() pthread_lockprof_enable_np() -> pthread_statistics_enable_np() pthread_lockprof_disable_np() -> pthread_statistics_disable_np() Added: soc2012/gmiller/locking-head/lib/libwitness/logs.c Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/include/pthread_np.h soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c soc2012/gmiller/locking-head/lib/libwitness/Makefile soc2012/gmiller/locking-head/lib/libwitness/lists.c soc2012/gmiller/locking-head/lib/libwitness/witness.h soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Modified: soc2012/gmiller/locking-head/include/pthread_np.h ============================================================================== --- soc2012/gmiller/locking-head/include/pthread_np.h Tue Jul 10 20:59:35 2012 (r239255) +++ soc2012/gmiller/locking-head/include/pthread_np.h Tue Jul 10 21:27:15 2012 (r239256) @@ -37,6 +37,32 @@ /* * Non-POSIX type definitions: */ + +#ifdef LOCK_PROFILING + +#include + +struct _pthread_statistics_private; + +struct pthread_statistics_np { + struct _pthread_statistics_private *_pvt; + const char *file; + int line; + struct timespec wait_max; + struct timespec hold_max; + uintmax_t contest_count; + struct timespec wait_time; + struct timespec hold_time; + int acq_count; +}; + +#endif + +struct pthread_lock_order_np { + void *lock_first; + void *lock_second; +}; + typedef void (*pthread_switch_routine_t)(pthread_t, pthread_t); /* @@ -68,31 +94,19 @@ int pthread_switch_add_np(pthread_switch_routine_t); int pthread_switch_delete_np(pthread_switch_routine_t); int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); +void pthread_lor_begin_np(struct pthread_lock_order_np *); +int pthread_lor_next_np(struct pthread_lock_order_np *); +void pthread_lor_end_np(struct pthread_lock_order_np *); +void pthread_lor_clear_np(void); #ifdef LOCK_PROFILING -#include - -struct _pthread_statistics_private; - -struct pthread_statistics_np { - struct _pthread_statistics_private *_pvt; - const char *file; - int line; - struct timespec wait_max; - struct timespec hold_max; - uintmax_t contest_count; - struct timespec wait_time; - struct timespec hold_time; - int acq_count; -}; - -void pthread_getstatistics_begin_np(struct pthread_statistics_np *); -int pthread_getstatistics_next_np(struct pthread_statistics_np *); -void pthread_getstatistics_end_np(struct pthread_statistics_np *); -void pthread_resetstatistics_np(void); -void pthread_lockprof_enable_np(void); -void pthread_lockprof_disable_np(void); +void pthread_statistics_begin_np(struct pthread_statistics_np *); +int pthread_statistics_next_np(struct pthread_statistics_np *); +void pthread_statistics_end_np(struct pthread_statistics_np *); +void pthread_statistics_reset_np(void); +void pthread_statistics_enable_np(void); +void pthread_statistics_disable_np(void); #endif Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Tue Jul 10 20:59:35 2012 (r239255) +++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Tue Jul 10 21:27:15 2012 (r239256) @@ -284,7 +284,7 @@ } void -pthread_getstatistics_begin_np(struct pthread_statistics_np *stats) +pthread_statistics_begin_np(struct pthread_statistics_np *stats) { stats->_pvt = malloc(sizeof(struct _pthread_statistics_private)); stats->_pvt->hash = 0; @@ -292,13 +292,13 @@ } int -pthread_getstatistics_next_np(struct pthread_statistics_np *stats) +pthread_statistics_next_np(struct pthread_statistics_np *stats) { return (find_next_record(stats)); } void -pthread_getstatistics_end_np(struct pthread_statistics_np *stats) +pthread_statistics_end_np(struct pthread_statistics_np *stats) { if (stats->_pvt != NULL) { free(stats->_pvt); @@ -307,7 +307,7 @@ } void -pthread_resetstatistics_np() +pthread_statistics_reset_np() { struct pthread *curthread = _get_curthread(); u_int hash; @@ -334,13 +334,13 @@ } void -pthread_lockprof_enable_np() +pthread_statistics_enable_np() { lockprof_enabled = 1; } void -pthread_lockprof_disable_np() +pthread_statistics_disable_np() { lockprof_enabled = 0; } Modified: soc2012/gmiller/locking-head/lib/libwitness/Makefile ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/Makefile Tue Jul 10 20:59:35 2012 (r239255) +++ soc2012/gmiller/locking-head/lib/libwitness/Makefile Tue Jul 10 21:27:15 2012 (r239256) @@ -4,7 +4,7 @@ LIB= witness SHLIB_MAJOR= 1 -SRCS= wrappers.c graph.c lists.c +SRCS= wrappers.c graph.c lists.c logs.c DPADD= ${LIBTHR} LDADD= -lthr Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/lists.c Tue Jul 10 20:59:35 2012 (r239255) +++ soc2012/gmiller/locking-head/lib/libwitness/lists.c Tue Jul 10 21:27:15 2012 (r239256) @@ -57,7 +57,7 @@ SLIST_INSERT_HEAD(&lock_head, entry, lock_next); if (next != NULL && insert_lock(entry, next) < 0) { - puts("LoR detected."); + log_reversal(entry, next); } printf("inserted lock %p\n", lock); Added: soc2012/gmiller/locking-head/lib/libwitness/logs.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/gmiller/locking-head/lib/libwitness/logs.c Tue Jul 10 21:27:15 2012 (r239256) @@ -0,0 +1,39 @@ +/*- + * Copyright (c) 2012 Greg Miller .. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include "witness.h" + +void +log_reversal(void *lock, void *previous) +{ + struct pthread_lock_order_np *entry; + + entry = malloc(sizeof(struct pthread_lock_order_np)); + entry->lock_first = previous; + entry->lock_second = lock; +} + Modified: soc2012/gmiller/locking-head/lib/libwitness/witness.h ============================================================================== --- soc2012/gmiller/locking-head/lib/libwitness/witness.h Tue Jul 10 20:59:35 2012 (r239255) +++ soc2012/gmiller/locking-head/lib/libwitness/witness.h Tue Jul 10 21:27:15 2012 (r239256) @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -48,3 +49,5 @@ void remove_lock(void *lock); int insert_lock(void *new_lock, void *previous); + +void log_reversal(void *lock, void *previous); 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 Tue Jul 10 20:59:35 2012 (r239255) +++ soc2012/gmiller/locking-head/tools/regression/lib/libthr/lockprof/lock-cycle.c Tue Jul 10 21:27:15 2012 (r239256) @@ -49,7 +49,7 @@ void reset_stats() { - pthread_resetstatistics_np(); + pthread_statistics_reset_np(); } void * @@ -72,7 +72,7 @@ pthread_t thread1; pthread_t thread2; - pthread_resetstatistics_np(); + pthread_statistics_reset_np(); pthread_create(&thread1, NULL, conflict_thread_func, NULL); pthread_create(&thread2, NULL, conflict_thread_func, NULL); @@ -122,17 +122,17 @@ struct pthread_statistics_np stats; long tm; - pthread_getstatistics_begin_np(&stats); - while (pthread_getstatistics_next_np(&stats)) { + pthread_statistics_begin_np(&stats); + while (pthread_statistics_next_np(&stats)) { record_count++; } - pthread_getstatistics_end_np(&stats); + pthread_statistics_end_np(&stats); check(record_count == 1); - pthread_getstatistics_begin_np(&stats); - pthread_getstatistics_next_np(&stats); - pthread_getstatistics_end_np(&stats); + pthread_statistics_begin_np(&stats); + pthread_statistics_next_np(&stats); + pthread_statistics_end_np(&stats); check(strcmp(stats.file, "lock-cycle.c") == 0); check(stats.line == 16); @@ -160,17 +160,17 @@ struct pthread_statistics_np stats; long tm; - pthread_getstatistics_begin_np(&stats); - while (pthread_getstatistics_next_np(&stats)) { + pthread_statistics_begin_np(&stats); + while (pthread_statistics_next_np(&stats)) { record_count++; } - pthread_getstatistics_end_np(&stats); + pthread_statistics_end_np(&stats); check(record_count == 1); - pthread_getstatistics_begin_np(&stats); - pthread_getstatistics_next_np(&stats); - pthread_getstatistics_end_np(&stats); + pthread_statistics_begin_np(&stats); + pthread_statistics_next_np(&stats); + pthread_statistics_end_np(&stats); check(strcmp(stats.file, "lock-cycle.c") == 0); check(stats.line == 16); @@ -193,11 +193,11 @@ int record_count = 0; struct pthread_statistics_np stats; - pthread_getstatistics_begin_np(&stats); - while (pthread_getstatistics_next_np(&stats)) { + pthread_statistics_begin_np(&stats); + while (pthread_statistics_next_np(&stats)) { record_count++; } - pthread_getstatistics_end_np(&stats); + pthread_statistics_end_np(&stats); check(record_count == 0); } @@ -209,17 +209,17 @@ struct pthread_statistics_np stats; long tm; - pthread_getstatistics_begin_np(&stats); - while (pthread_getstatistics_next_np(&stats)) { + pthread_statistics_begin_np(&stats); + while (pthread_statistics_next_np(&stats)) { record_count++; } - pthread_getstatistics_end_np(&stats); + pthread_statistics_end_np(&stats); check(record_count == 1); - pthread_getstatistics_begin_np(&stats); - pthread_getstatistics_next_np(&stats); - pthread_getstatistics_end_np(&stats); + pthread_statistics_begin_np(&stats); + pthread_statistics_next_np(&stats); + pthread_statistics_end_np(&stats); check(stats.contest_count == 1);