Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Jun 2012 23:29:15 +0000
From:      gmiller@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r237520 - in soc2012/gmiller/locking-head: include lib/libthr/thread
Message-ID:  <20120611232915.98B221065670@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <inttypes.h>
+
+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 */



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