socsvn commit: r237205 - soc2012/gmiller/locking-head/lib/libthr/thread

gmiller at FreeBSD.org gmiller at FreeBSD.org
Wed Jun 6 12:08:05 UTC 2012


Author: gmiller
Date: Wed Jun  6 12:08:03 2012
New Revision: 237205
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237205

Log:
  Add a WIP version of mutex_lookup(), which returns a lock_acquisition
  object to store profiling stats for the given acquisition point.
  

Modified:
  soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c

Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c	Wed Jun  6 11:46:37 2012	(r237204)
+++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c	Wed Jun  6 12:08:03 2012	(r237205)
@@ -27,12 +27,50 @@
 
 #ifdef LOCK_PROFILING
 
+#include <stdlib.h>
+
 #include "thr_private.h"
 
+#define LOCK_PROF_HASH_SIZE (4096)
+
+struct lock_acquisition {
+	const char *file;
+	int line;
+	SLIST_ENTRY(lock_acquisition) acq_next;
+};
+
+SLIST_HEAD(acq_head, lock_acquisition);
+
+struct acq_head mutex_hash[LOCK_PROF_HASH_SIZE];
+
+static struct lock_acquisition *
+mutex_lookup(struct pthread_mutex *m, const char *file, int line)
+{
+	u_int hash;
+	struct lock_acquisition *acq;
+
+	hash = ((uintptr_t)file * 31 + line) & (LOCK_PROF_HASH_SIZE - 1);
+
+	SLIST_FOREACH(acq, &mutex_hash[hash], acq_next) {
+		if (acq->file == file && acq->line == line) {
+			return acq;
+		}
+	}
+
+	acq = malloc(sizeof(struct lock_acquisition));
+	acq->file = file;
+	acq->line = line;
+
+	SLIST_INSERT_HEAD(&mutex_hash[hash], acq, acq_next);
+
+	return acq;
+}
+
 void
 _mutex_obtain_success(struct pthread_mutex *m, struct timespec *waittime,
 		      const char *file, int line)
 {
+	mutex_lookup(m, file, line);
 }
 
 void


More information about the svn-soc-all mailing list