Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 06 Jun 2012 12:08:03 +0000
From:      gmiller@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r237205 - soc2012/gmiller/locking-head/lib/libthr/thread
Message-ID:  <20120606120803.F2EF01065670@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
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



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