From owner-svn-soc-all@FreeBSD.ORG Mon Jun 11 23:29:17 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 98B221065670 for ; Mon, 11 Jun 2012 23:29:15 +0000 (UTC) (envelope-from gmiller@FreeBSD.org) Received: by socsvn.FreeBSD.org (sSMTP sendmail emulation); Mon, 11 Jun 2012 23:29:15 +0000 Date: Mon, 11 Jun 2012 23:29:15 +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: <20120611232915.98B221065670@hub.freebsd.org> Cc: Subject: socsvn commit: r237520 - in soc2012/gmiller/locking-head: include lib/libthr/thread 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, 11 Jun 2012 23:29:17 -0000 Author: gmiller Date: Mon Jun 11 23:29:14 2012 New Revision: 237520 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237520 Log: Implement pthread_getstatistics_begin_np(), pthread_getstatistics_next_np(), and pthread_get_statistics_end_np(). Modified: soc2012/gmiller/locking-head/include/pthread_np.h soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Modified: soc2012/gmiller/locking-head/include/pthread_np.h ============================================================================== --- soc2012/gmiller/locking-head/include/pthread_np.h Mon Jun 11 22:25:20 2012 (r237519) +++ soc2012/gmiller/locking-head/include/pthread_np.h Mon Jun 11 23:29:14 2012 (r237520) @@ -71,11 +71,23 @@ #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 *, - size_t record_size); +void pthread_getstatistics_begin_np(struct pthread_statistics_np *); void pthread_getstatistics_next_np(struct pthread_statistics_np *); void pthread_getstatistics_end_np(struct pthread_statistics_np *); Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Mon Jun 11 22:25:20 2012 (r237519) +++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Mon Jun 11 23:29:14 2012 (r237520) @@ -66,6 +66,11 @@ struct acq_point_head mutex_hash[LOCK_PROF_HASH_SIZE]; +struct _pthread_statistics_private { + int hash; + struct acquisition_point *last_record; +}; + void _lock_profile_init() { @@ -275,20 +280,72 @@ { } +static int +find_next_record(struct pthread_statistics_np *stats) +{ + struct pthread *curthread = _get_curthread(); + + THR_CRITICAL_ENTER(curthread); + + for (;;) { + if (stats->_pvt->last_record == NULL) { + if (stats->_pvt->hash >= LOCK_PROF_HASH_SIZE) { + break; + } else { + stats->_pvt->hash++; + stats->_pvt->last_record = + SLIST_FIRST(&mutex_hash[stats->_pvt->hash]); + } + } else { + stats->_pvt->last_record = SLIST_NEXT(stats->_pvt-> + last_record, + acq_point_next); + } + + if (stats->_pvt->last_record != NULL) { + break; + } + } + + if (stats->_pvt->last_record != NULL) { + stats->file = stats->_pvt->last_record->file; + stats->line = stats->_pvt->last_record->line; + stats->wait_max = stats->_pvt->last_record->wait_max; + stats->hold_max = stats->_pvt->last_record->hold_max; + stats->contest_count = stats->_pvt->last_record->contest_count; + stats->wait_time = stats->_pvt->last_record->wait_time; + stats->hold_time = stats->_pvt->last_record->hold_time; + stats->acq_count = stats->_pvt->last_record->acq_count; + } + + THR_CRITICAL_LEAVE(curthread); + + return (stats->_pvt->last_record != NULL); +} + void -pthread_getstatistics_begin_np(struct pthread_statistics_np *stats, - size_t record_size) +pthread_getstatistics_begin_np(struct pthread_statistics_np *stats) { + stats->_pvt = malloc(sizeof(struct _pthread_statistics_private)); + stats->_pvt->hash = 0; + stats->_pvt->last_record = NULL; + + find_next_record(stats); } void pthread_getstatistics_next_np(struct pthread_statistics_np *stats) { + find_next_record(stats); } void pthread_getstatistics_end_np(struct pthread_statistics_np *stats) { + if (stats->_pvt != NULL) { + free(stats->_pvt); + stats->_pvt = NULL; + } } #endif /* LOCK_PROFILING */