socsvn commit: r240265 - in soc2012/gmiller/locking-head: . include lib/libwitness tools/regression/lib/libwitness

gmiller at FreeBSD.org gmiller at FreeBSD.org
Sat Aug 11 05:18:54 UTC 2012


Author: gmiller
Date: Sat Aug 11 05:18:51 2012
New Revision: 240265
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240265

Log:
   r240330 at FreeBSD-dev:  root | 2012-08-11 00:17:01 -0500
   Treat locks that have the same name as the same lock.

Modified:
  soc2012/gmiller/locking-head/   (props changed)
  soc2012/gmiller/locking-head/include/pthread_np.h
  soc2012/gmiller/locking-head/lib/libwitness/lists.c
  soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
  soc2012/gmiller/locking-head/lib/libwitness/logs.c
  soc2012/gmiller/locking-head/lib/libwitness/witness.h
  soc2012/gmiller/locking-head/lib/libwitness/wrappers.c
  soc2012/gmiller/locking-head/lib/libwitness/xml.c
  soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c
  soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.c
  soc2012/gmiller/locking-head/tools/regression/lib/libwitness/shared.c

Modified: soc2012/gmiller/locking-head/include/pthread_np.h
==============================================================================
--- soc2012/gmiller/locking-head/include/pthread_np.h	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/include/pthread_np.h	Sat Aug 11 05:18:51 2012	(r240265)
@@ -62,20 +62,17 @@
 
 struct pthread_lor_np {
 	struct _pthread_lor_private *_pvt;
-	void		*lock_first;
-	void		*lock_second;
-	const char	*name_first;
-	const char	*name_second;
+	char		*name_first;
+	char		*name_second;
 };
 
 struct _pthread_lockorder_private;
 
 struct pthread_lockorder_np {
 	struct _pthread_lockorder_private *_pvt;
-	void		*lock;
 	char		*name;
-	void		*child;
-	void		*sibling;
+	char		*child;
+	char		*sibling;
 };
 
 typedef void	(*pthread_switch_routine_t)(pthread_t, pthread_t);

Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lists.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/lib/libwitness/lists.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -40,10 +40,12 @@
 static int	exit_set = 0;
 
 void
-add_lock(struct lock_info *lock)
+add_lock(void *lock)
 {
 	struct lock_entry *entry;
 	struct lock_entry *next;
+	struct lock_instance *inst;
+	struct lock_info *info;
 
 	if (exit_set == 0) {
 		atexit(write_xml);
@@ -54,6 +56,9 @@
 		return;
 	}
 
+	inst = lookup_lock(lock);
+	info = get_lock_info(inst);
+
 	next = SLIST_FIRST(&lock_head);
 
 	entry = malloc(sizeof(*entry));
@@ -61,7 +66,7 @@
 		return;
 	}
 
-	entry->lock = lock;
+	entry->lock = info;
 
 	if (reset_count > thread_reset_count) {
 		thread_reset_count = reset_count;
@@ -85,13 +90,18 @@
 }
 
 void
-remove_lock(struct lock_info *lock)
+remove_lock(void *lock)
 {
+	struct lock_instance *inst;
+	struct lock_info *info;
 	struct lock_entry *entry;
 	struct lock_entry *temp;
 
+	inst = lookup_lock(lock);
+	info = get_lock_info(inst);
+
 	SLIST_FOREACH_SAFE(entry, &lock_head, lock_next, temp) {
-		if (entry->lock == lock) {
+		if (entry->lock == info) {
 			SLIST_REMOVE(&lock_head, entry, lock_entry, lock_next);
 			free(entry);
 

Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -32,46 +32,50 @@
 static SLIST_HEAD(lock_info_head, lock_info) lock_info_head =
     SLIST_HEAD_INITIALIZER(lock_info_head);
 
+static SLIST_HEAD(lock_instance_head, lock_instance) lock_instance_head =
+    SLIST_HEAD_INITIALIZER(lock_instance_head);
+
 struct _pthread_lockorder_private {
 	struct lock_info *last_record;
 };
 
-struct lock_info *
+struct lock_instance *
 lookup_lock(void *lock)
 {
-	struct lock_info *info = NULL;
+	struct lock_instance *inst = NULL;
+	struct lock_instance *iter;
 
-	SLIST_FOREACH(info, &lock_info_head, lock_info_next) {
-		if (info->lock == lock && info->active) {
+	SLIST_FOREACH(iter, &lock_instance_head, lock_instance_next) {
+		if (iter->lock == lock) {
+			inst = iter;
 			break;
 		}
 	}
 
-	if (info == NULL) {
-		info = malloc(sizeof(struct lock_info));
-		if (info != NULL) {
-			info->active = 1;
-			info->lock = lock;
-			info->child = NULL;
-			info->sibling = NULL;
-			info->name = NULL;
-			SLIST_INIT(&info->bless_head);
-			SLIST_INSERT_HEAD(&lock_info_head, info,
-					  lock_info_next);
+	if (inst == NULL) {
+		inst = malloc(sizeof(struct lock_instance));
+		if (inst != NULL) {
+			inst->lock = lock;
+			inst->info = NULL;
+
+			SLIST_INSERT_HEAD(&lock_instance_head, inst,
+					  lock_instance_next);
 		}
 	}
 
-	return (info);
+	return (inst);
 }
 
 void
 destroy_lock(void *lock)
 {
-	struct lock_info *info;
+	struct lock_instance *inst;
 
-	info = lookup_lock(lock);
-	if (info != NULL) {
-		info->active = 0;
+	inst = lookup_lock(lock);
+	if (inst != NULL) {
+		SLIST_REMOVE(&lock_instance_head, inst, lock_instance,
+			     lock_instance_next);
+		free(inst);
 	}
 }
 
@@ -114,36 +118,122 @@
 	}
 }
 
-int
-pthread_setname_np(void *lock, const char *name)
+void
+reset_lock_instance(void)
+{
+	struct lock_instance *inst;
+
+	while (!SLIST_EMPTY(&lock_instance_head)) {
+		inst = SLIST_FIRST(&lock_instance_head);
+
+		SLIST_REMOVE_HEAD(&lock_instance_head, lock_instance_next);
+
+		free(inst);
+	}
+}
+
+struct lock_info *
+get_lock_info(struct lock_instance *inst)
 {
 	struct lock_info *info;
 
-	info = lookup_lock(lock);
+	if (inst == NULL) {
+		return (NULL);
+	}
+
+	if (inst->info != NULL) {
+  		return (inst->info);
+	}
+
+	info = malloc(sizeof(struct lock_info));
+	if (info != NULL) {
+		info->name = NULL;
+		info->child = NULL;
+		info->sibling = NULL;
+		SLIST_INIT(&info->bless_head);
+		SLIST_INSERT_HEAD(&lock_info_head, info, lock_info_next);
+
+		inst->info = info;
+	}
+
+	return (info);
+}
+
+static struct lock_info *
+lookup_info(const char *name)
+{
+	struct lock_info *info = NULL;
+	struct lock_info *iter;
+
+	SLIST_FOREACH(iter, &lock_info_head, lock_info_next) {
+		if (strcmp(name, get_lock_name(iter)) == 0) {
+			info = iter;
+			break;
+		}
+	}
+
 	if (info == NULL) {
-		return (ENOMEM);
+		info = malloc(sizeof(struct lock_info));
+		if (info != NULL) {
+			info->name = strdup(name);
+			info->child = NULL;
+			info->sibling = NULL;
+			SLIST_INIT(&info->bless_head);
+			SLIST_INSERT_HEAD(&lock_info_head, info,
+					  lock_info_next);
+		}
 	}
 
-	info->name = reallocf(info->name, strlen(name) + 1);
-	if (info->name == NULL) {
-		return (errno);
+	return (info);
+}
+
+int
+pthread_setname_np(void *lock, const char *name)
+{
+	struct lock_instance *inst;
+
+	inst = lookup_lock(lock);
+	if (inst == NULL) {
+		return (ENOMEM);
 	}
 
-	strcpy(info->name, name);
+	inst->info = lookup_info(name);
+	if (inst->info == NULL) {
+		return (ENOMEM);
+	}
 
 	return (0);
 }
 
+const char *
+get_lock_name(struct lock_info *info)
+{
+	if (info->name != NULL) {
+		return (info->name);
+	}
+
+	return "";
+}
+
 void
-check_default_name(struct lock_info *lock, const char *prefix)
+check_default_name(void *lock, const char *prefix)
 {
-	if (lock != NULL && lock->name == NULL) {
-		lock->name = malloc(MAX_DEFAULT_NAME_LENGTH + 1);
-		if (lock->name != NULL) {
-			snprintf(lock->name, MAX_DEFAULT_NAME_LENGTH, "%s%p",
-				 prefix, lock->lock);
-		}
+	struct lock_instance *inst;
+	struct lock_info *info;
+
+	inst = lookup_lock(lock);
+	info = get_lock_info(inst);
+
+	if (info == NULL || info->name != NULL) {
+		return;
+	}
+
+	info->name = malloc(MAX_DEFAULT_NAME_LENGTH + 1);
+	if (info->name == NULL) {
+		return;
 	}
+
+	snprintf(info->name, MAX_DEFAULT_NAME_LENGTH, "%s_%p", prefix, lock);
 }
 
 int
@@ -196,20 +286,18 @@
 
 	if (node->name != NULL) {
 		free(node->name);
-		node->name = NULL;
 	}
 
-	node->lock = node->_pvt->last_record->lock;
-	if (node->_pvt->last_record->name != NULL) {
-		node->name = strdup(node->_pvt->last_record->name);
-	}
+	node->name = strdup(get_lock_name(node->_pvt->last_record));
 	if (node->_pvt->last_record->child != NULL) {
-		node->child = node->_pvt->last_record->child->lock;
+		node->child =
+		    strdup(get_lock_name(node->_pvt->last_record->child));
 	} else {
 		node->child = NULL;
 	}
 	if (node->_pvt->last_record->sibling != NULL) {
-		node->sibling = node->_pvt->last_record->sibling->lock;
+		node->sibling =
+		    strdup(get_lock_name(node->_pvt->last_record->sibling));
 	} else {
 		node->sibling = NULL;
 	}
@@ -222,11 +310,13 @@
 void
 pthread_lockorder_end_np(struct pthread_lockorder_np *node)
 {
-	free(node->_pvt);
-	node->_pvt = NULL;
+	if (node->_pvt != NULL) {
+		free(node->_pvt);
+		node->_pvt = NULL;
+	}
 
 	if (node->name != NULL) {
-		free((char *)node->name);
+		free(node->name);
 		node->name = NULL;
 	}
 }

Modified: soc2012/gmiller/locking-head/lib/libwitness/logs.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/logs.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/lib/libwitness/logs.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -57,6 +57,7 @@
 pthread_lor_begin_np(struct pthread_lor_np *lor)
 {
 	int		ret = 0;
+
         /*
 	  The lock isn't needed to prevent races, but it is needed to ensure
 	  that any locks grabbed by malloc() don't get logged.
@@ -70,6 +71,9 @@
 		lor->_pvt->last_record = NULL;
 	}
 
+	lor->name_first = NULL;
+	lor->name_second = NULL;
+
 	pthread_mutex_unlock(&witness_mtx);
 
 	return (ret);
@@ -90,10 +94,10 @@
 	}
 
 	if (lor->_pvt->last_record != NULL) {
-		lor->lock_first = lor->_pvt->last_record->lock_first->lock;
-		lor->lock_second = lor->_pvt->last_record->lock_second->lock;
-		lor->name_first = lor->_pvt->last_record->lock_first->name;
-		lor->name_second = lor->_pvt->last_record->lock_second->name;
+		lor->name_first =
+		    strdup(get_lock_name(lor->_pvt->last_record->lock_first));
+		lor->name_second =
+		    strdup(get_lock_name(lor->_pvt->last_record->lock_second));
 
 		res = 1;
 	}
@@ -110,6 +114,14 @@
 		free(lor->_pvt);
 		lor->_pvt = NULL;
 	}
+
+	if (lor->name_first != NULL) {
+		free(lor->name_first);
+	}
+
+	if (lor->name_second != NULL) {
+		free(lor->name_second);
+	}
 }
 
 void

Modified: soc2012/gmiller/locking-head/lib/libwitness/witness.h
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/witness.h	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/lib/libwitness/witness.h	Sat Aug 11 05:18:51 2012	(r240265)
@@ -41,31 +41,38 @@
 
 struct lock_info {
 	SLIST_ENTRY(lock_info) lock_info_next;
-	SLIST_ENTRY(lock_info) root_next;
-	void		*lock;
-	int		active;
 	struct lock_info *child;
 	struct lock_info *sibling;
 	SLIST_HEAD(bless_head, blessing) bless_head;
 	char		*name;
 };
 
+struct lock_instance {
+	SLIST_ENTRY(lock_instance) lock_instance_next;
+	struct lock_info *info;
+	void		*lock;
+};
+
 extern pthread_mutex_t witness_mtx;
 
-void		add_lock(struct lock_info *lock);
-void		remove_lock(struct lock_info *lock);
-int		insert_lock(struct lock_info *new_lock,
-			    struct lock_info *previous);
+void		add_lock(void *lock);
+void		remove_lock(void *lock);
+
+int		insert_lock(struct lock_info *from,
+			    struct lock_info *to);
 
 void		reset_lists(void);
 
 void		log_reversal(struct lock_info *lock,
 			     struct lock_info *previous);
 
-struct lock_info *lookup_lock(void *lock);
-void		destroy_lock(void *lock);
 int		blessed(struct lock_info *first, struct lock_info *second);
 void		reset_lock_info(void);
-void		check_default_name(struct lock_info *lock, const char *prefix);
+void		check_default_name(void *lock, const char *prefix);
+const char 	*get_lock_name(struct lock_info *info);
+struct lock_info *get_lock_info(struct lock_instance *lock);
+void		destroy_lock(void *lock);
+struct lock_instance *lookup_lock(void *lock);
+void		reset_lock_instance(void);
 
 void		write_xml(void);

Modified: soc2012/gmiller/locking-head/lib/libwitness/wrappers.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/wrappers.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/lib/libwitness/wrappers.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -54,16 +54,14 @@
 pthread_mutex_lock(pthread_mutex_t *mutex)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(mutex);
-	check_default_name(lock, "mutex_");
+	check_default_name(mutex, "mutex");
 
 	ret = _pthread_mutex_lock(mutex);
 	if (mutex != &witness_mtx && ret == 0) {
-		add_lock(lock);
+		add_lock(mutex);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -75,16 +73,14 @@
 pthread_mutex_trylock(pthread_mutex_t *mutex)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(mutex);
-	check_default_name(lock, "mutex_");
+	check_default_name(mutex, "mutex");
 
 	ret = _pthread_mutex_trylock(mutex);
 	if (mutex != &witness_mtx && ret == 0) {
-		add_lock(lock);
+		add_lock(mutex);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -96,16 +92,14 @@
 pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *ts)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(mutex);
-	check_default_name(lock, "mutex_");
+	check_default_name(mutex, "mutex");
 
 	ret = _pthread_mutex_timedlock(mutex, ts);
 	if (mutex != &witness_mtx && ret == 0) {
-		add_lock(lock);
+		add_lock(mutex);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -122,7 +116,7 @@
 
 	ret = _pthread_mutex_unlock(mutex);
 	if (mutex != &witness_mtx && ret == 0) {
-		remove_lock(lookup_lock(mutex));
+		remove_lock(mutex);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -149,16 +143,14 @@
 pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(rwlock);
-	check_default_name(lock, "rwlock_");
+	check_default_name(rwlock, "rwlock");
 
 	ret = _pthread_rwlock_rdlock(rwlock);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(rwlock);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -170,16 +162,14 @@
 pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(rwlock);
-	check_default_name(lock, "rwlock_");
+	check_default_name(rwlock, "rwlock");
 
 	ret = _pthread_rwlock_tryrdlock(rwlock);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(rwlock);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -191,16 +181,14 @@
 pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *ts)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(rwlock);
-	check_default_name(lock, "rwlock_");
+	check_default_name(rwlock, "rwlock");
 
 	ret = _pthread_rwlock_timedrdlock(rwlock, ts);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(rwlock);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -212,16 +200,14 @@
 pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(rwlock);
-	check_default_name(lock, "rwlock_");
+	check_default_name(rwlock, "rwlock");
 
 	ret = _pthread_rwlock_wrlock(rwlock);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(rwlock);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -233,16 +219,14 @@
 pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(rwlock);
-	check_default_name(lock, "rwlock_");
+	check_default_name(rwlock, "rwlock");
 
 	ret = _pthread_rwlock_trywrlock(rwlock);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(rwlock);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -254,16 +238,14 @@
 pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *ts)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(rwlock);
-	check_default_name(lock, "rwlock_");
+	check_default_name(rwlock, "rwlock");
 
 	ret = _pthread_rwlock_timedwrlock(rwlock, ts);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(rwlock);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -280,7 +262,7 @@
 
 	ret = _pthread_rwlock_unlock(rwlock);
 	if (ret == 0) {
-		remove_lock(lookup_lock(rwlock));
+		remove_lock(rwlock);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -307,16 +289,14 @@
 pthread_spin_lock(pthread_spinlock_t *spin)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(spin);
-	check_default_name(lock, "spinlock_");
+	check_default_name(spin, "spinlock");
 
 	ret = _pthread_spin_lock(spin);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(spin);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -328,16 +308,14 @@
 pthread_spin_trylock(pthread_spinlock_t *spin)
 {
 	int		ret;
-	struct lock_info *lock;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	lock = lookup_lock(spin);
-	check_default_name(lock, "spinlock_");
+	check_default_name(spin, "spinlock");
 
 	ret = _pthread_spin_lock(spin);
 	if (ret == 0) {
-		add_lock(lock);
+		add_lock(spin);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -354,7 +332,7 @@
 
 	ret = _pthread_spin_unlock(spin);
 	if (ret == 0) {
-		remove_lock(lookup_lock(spin));
+		remove_lock(spin);
 	}
 
 	_pthread_mutex_unlock(&witness_mtx);
@@ -384,7 +362,8 @@
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	if (insert_lock(lookup_lock(first), lookup_lock(second)) < 0) {
+	if (insert_lock(get_lock_info(lookup_lock(first)),
+			get_lock_info(lookup_lock(second))) < 0) {
 		ret = EINVAL;
 	}
 
@@ -398,14 +377,19 @@
 {
 	struct lock_info *first;
 	struct lock_info *second;
+	struct lock_instance *first_inst;
+	struct lock_instance *second_inst;
 	struct blessing *first_bless = NULL;
 	struct blessing *second_bless = NULL;
 	int ret = 0;
 
 	_pthread_mutex_lock(&witness_mtx);
 
-	first = lookup_lock(first_addr);
-	second = lookup_lock(second_addr);
+	first_inst = lookup_lock(first_addr);
+	second_inst = lookup_lock(second_addr);
+
+	first = get_lock_info(first_inst);
+	second = get_lock_info(second_inst);
 
 	first_bless = malloc(sizeof(struct blessing));
 	second_bless = malloc(sizeof(struct blessing));
@@ -414,14 +398,6 @@
 	    second_bless == NULL) {
 		ret = ENOMEM;
 
-		if (first != NULL) {
-			free(first);
-		}
-
-		if (second != NULL) {
-			free(second);
-		}
-
 		if (first_bless != NULL) {
 			free(first_bless);
 		}
@@ -445,6 +421,7 @@
 	_pthread_mutex_lock(&witness_mtx);
 
 	reset_lists();
+	reset_lock_instance();
 	reset_lock_info();
 
 	_pthread_mutex_unlock(&witness_mtx);

Modified: soc2012/gmiller/locking-head/lib/libwitness/xml.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/xml.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/lib/libwitness/xml.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -68,13 +68,6 @@
 	fprintf(xml_file, "<%s>%s</%s>\n", tag, str, tag);
 }
 
-static void
-write_element_pointer(const char *tag, void *ptr)
-{
-	indent();
-	fprintf(xml_file, "<%s>%p</%s>\n", tag, ptr, tag);
-}
-
 void
 write_xml(void)
 {
@@ -91,15 +84,8 @@
 	while (pthread_lor_next_np(&lor)) {
 		open_element("lor");
 
-		open_element("first");
-		write_element_pointer("address", lor.lock_first);
-		write_element_string("name", lor.name_first);
-		close_element("first");
-
-		open_element("second");
-		write_element_pointer("address", lor.lock_second);
-		write_element_string("name", lor.name_second);
-		close_element("second");
+		write_element_string("first", lor.name_first);
+		write_element_string("second", lor.name_second);
 
 		close_element("lor");
 	}
@@ -113,13 +99,12 @@
 	while (pthread_lockorder_next_np(&node)) {
 		open_element("node");
 
-		write_element_pointer("address", node.lock);
 		write_element_string("name", node.name);
 		if (node.child != NULL) {
-			write_element_pointer("child", node.child);
+			write_element_string("child", node.child);
 		}
 		if (node.sibling != NULL) {
-			write_element_pointer("sibling", node.sibling);
+			write_element_string("sibling", node.sibling);
 		}
 
 		close_element("node");

Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c
==============================================================================
--- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/graph.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -27,23 +27,25 @@
 
 #include <pthread.h>
 #include <pthread_np.h>
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "check.h"
 
 void
-check_graph(pthread_mutex_t *lock_buffer, int lock_count)
+check_graph(int lock_count)
 {
 	struct pthread_lockorder_np order;
 	int i;
 
 	pthread_lockorder_begin_np(&order);
 	while (pthread_lockorder_next_np(&order)) {
-		i = (pthread_mutex_t *)order.lock - lock_buffer;
-		if (i >= 0 && i < lock_count) {
-			check((i < (lock_count - 1) &&
-			       (lock_buffer + i + 1) == order.child) ||
-			      (i == (lock_count - 1) && order.child == NULL));
+		i = atol(order.name);
+		if (i >= 1 && i <= lock_count) {
+			check((i < lock_count &&
+			       order.child != NULL &&
+			       atol(order.child) == i + 1) ||
+			      (i == lock_count && order.child == NULL));
 			check(order.sibling == NULL);
 		}
 	}
@@ -87,6 +89,7 @@
 	int		i;
 	pthread_mutex_t	*lock_buffer;
 	int		*lock_set;
+	char		name[11];
 
 	pthread_lockorder_reset_np();
 
@@ -95,10 +98,13 @@
 
 	for (i = 0; i < lock_count; i++) {
 		pthread_mutex_init(&lock_buffer[i], NULL);
+
+		sprintf(name, "%d", i + 1);
+		pthread_setname_np(&lock_buffer[i], name);
 	}
 
 	graph_test(lock_buffer, lock_count, lock_set, 0, 0);
-	check_graph(lock_buffer, lock_count);
+	check_graph(lock_count);
 
 	for (i = 0; i < lock_count; i++) {
 		pthread_mutex_destroy(&lock_buffer[i]);

Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.c
==============================================================================
--- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/setname.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -61,16 +61,16 @@
 
 	pthread_lor_begin_np(&lor);
 	while (pthread_lor_next_np(&lor)) {
+		check((strcmp(lor.name_first, "mutex 1") == 0 && 
+		       strcmp(lor.name_second, "mutex 2") == 0) ||
+		      (strcmp(lor.name_first, "mutex 2") == 0 &&
+		       strcmp(lor.name_second, "mutex 1") == 0));
+
 		record_count++;
 	}
 	pthread_lor_end_np(&lor);
 
 	check(record_count == 1);
-
-	check((strcmp(lor.name_first, "mutex 1") == 0 && 
-	       strcmp(lor.name_second, "mutex 2") == 0) ||
-	      (strcmp(lor.name_first, "mutex 2") == 0 &&
-	       strcmp(lor.name_second, "mutex 1") == 0));
 }
 
 int

Modified: soc2012/gmiller/locking-head/tools/regression/lib/libwitness/shared.c
==============================================================================
--- soc2012/gmiller/locking-head/tools/regression/lib/libwitness/shared.c	Sat Aug 11 05:18:33 2012	(r240264)
+++ soc2012/gmiller/locking-head/tools/regression/lib/libwitness/shared.c	Sat Aug 11 05:18:51 2012	(r240265)
@@ -31,41 +31,89 @@
 #include "check.h"
 
 void
-share_test(void)
+unshared_test(void)
 {
 	pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
 	pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
 
-	pthread_setname_np(mutex1, "shared_mutex");
-	pthread_setname_np(mutex2, "shared_mutex");
+	pthread_mutex_lock(&mutex1);
+	pthread_mutex_lock(&mutex2);
+
+	pthread_mutex_unlock(&mutex2);
+	pthread_mutex_unlock(&mutex1);
+
+	pthread_mutex_lock(&mutex2);
+	pthread_mutex_lock(&mutex1);
+
+	pthread_mutex_unlock(&mutex1);
+	pthread_mutex_unlock(&mutex2);
+
+	pthread_mutex_destroy(&mutex1);
+	pthread_mutex_destroy(&mutex2);
+}
+
+void
+check_unshared(void)
+{
+	struct pthread_lor_np lor;
+	int lor_count = 0;
+
+	pthread_lor_begin_np(&lor);
+	while (pthread_lor_next_np(&lor)) {
+		lor_count++;
+	}
+	pthread_lor_end_np(&lor);
+
+	check(lor_count == 1);
+}
+
+void
+shared_test(void)
+{
+	pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
+	pthread_mutex_t mutex2 = PTHREAD_MUTEX_INITIALIZER;
+
+	pthread_lor_clear_np();
+
+	pthread_setname_np(&mutex1, "shared_mutex");
+	pthread_setname_np(&mutex2, "shared_mutex");
 
 	pthread_mutex_lock(&mutex1);
 	pthread_mutex_lock(&mutex2);
 
 	pthread_mutex_unlock(&mutex2);
 	pthread_mutex_unlock(&mutex1);
+
+	pthread_mutex_lock(&mutex2);
+	pthread_mutex_lock(&mutex1);
+
+	pthread_mutex_unlock(&mutex1);
+	pthread_mutex_unlock(&mutex2);
 }
 
 void
-check_share(void)
+check_shared(void)
 {
-	struct pthread_lockorder_np order;
-	int node_count = 0;
+	struct pthread_lor_np lor;
+	int lor_count = 0;
 
-	pthread_lockorder_begin_np(&order);
-	while (pthread_lockorder_next_np(&order)) {
-		node_count++;
+	pthread_lor_begin_np(&lor);
+	while (pthread_lor_next_np(&lor)) {
+		lor_count++;
 	}
-	pthread_lockorder_end_np(&order);
+	pthread_lor_end_np(&lor);
 
-	check(node_count == 0);
+	check(lor_count == 0);
 }
 
 int
 main(void)
 {
-	share_test();
-	check_share();
+	unshared_test();
+	check_unshared();
+
+	shared_test();
+	check_shared();
 
 	show_test_results();
 


More information about the svn-soc-all mailing list