socsvn commit: r239507 - in soc2012/gmiller/locking-head: . lib/libwitness

gmiller at FreeBSD.org gmiller at FreeBSD.org
Wed Jul 18 02:47:10 UTC 2012


Author: gmiller
Date: Wed Jul 18 02:47:07 2012
New Revision: 239507
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239507

Log:
   r239542 at FreeBSD-dev:  root | 2012-07-14 18:44:29 -0500
   Implement pthread_lockorder_reset_np() and add some previously-omitted
   lock/unlock pairs.

Modified:
  soc2012/gmiller/locking-head/   (props changed)
  soc2012/gmiller/locking-head/lib/libwitness/lists.c
  soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
  soc2012/gmiller/locking-head/lib/libwitness/witness.h
  soc2012/gmiller/locking-head/lib/libwitness/wrappers.c

Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lists.c	Wed Jul 18 02:46:43 2012	(r239506)
+++ soc2012/gmiller/locking-head/lib/libwitness/lists.c	Wed Jul 18 02:47:07 2012	(r239507)
@@ -35,6 +35,9 @@
 static _Thread_local SLIST_HEAD(lock_head, lock_entry) lock_head =
     SLIST_HEAD_INITIALIZER(lock_head);
 
+static int reset_count = 0;
+static _Thread_local int thread_reset_count = 0;
+
 void
 add_lock(struct lock_info *lock)
 {
@@ -46,6 +49,20 @@
 	entry = malloc(sizeof(*entry));
 	entry->lock = lock;
 
+	if (reset_count > thread_reset_count) {
+		thread_reset_count = reset_count;
+
+		while (!SLIST_EMPTY(&lock_head)) {
+			entry = SLIST_FIRST(&lock_head);
+
+			SLIST_REMOVE_HEAD(&lock_head, lock_next);
+
+			free(entry);
+		}
+
+		next = NULL;
+	}
+
 	SLIST_INSERT_HEAD(&lock_head, entry, lock_next);
 
 	if (next != NULL && insert_lock(entry->lock, next->lock) < 0) {
@@ -68,3 +85,9 @@
 		}
 	}
 }
+
+void
+reset_lists(void)
+{
+	reset_count++;
+}

Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c	Wed Jul 18 02:46:43 2012	(r239506)
+++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c	Wed Jul 18 02:47:07 2012	(r239507)
@@ -76,3 +76,17 @@
 
 	return (0);
 }
+
+void
+reset_lock_info(void)
+{
+	struct lock_info *info;
+
+	while (!SLIST_EMPTY(&lock_info_head)) {
+		info = SLIST_FIRST(&lock_info_head);
+
+		SLIST_REMOVE_HEAD(&lock_info_head, lock_info_next);
+
+		free(info);
+	}
+}

Modified: soc2012/gmiller/locking-head/lib/libwitness/witness.h
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/witness.h	Wed Jul 18 02:46:43 2012	(r239506)
+++ soc2012/gmiller/locking-head/lib/libwitness/witness.h	Wed Jul 18 02:47:07 2012	(r239507)
@@ -48,13 +48,16 @@
 
 extern pthread_mutex_t witness_mtx;
 
-void	add_lock(struct lock_info *lock);
-void	remove_lock(struct lock_info *lock);
+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		reset_lists(void);
 
-int	insert_lock(struct lock_info *new_lock, struct lock_info *previous);
-
-void	log_reversal(struct lock_info *lock, struct lock_info *previous);
+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);

Modified: soc2012/gmiller/locking-head/lib/libwitness/wrappers.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/wrappers.c	Wed Jul 18 02:46:43 2012	(r239506)
+++ soc2012/gmiller/locking-head/lib/libwitness/wrappers.c	Wed Jul 18 02:47:07 2012	(r239507)
@@ -55,11 +55,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_mutex_lock(mutex);
 	if (mutex != &witness_mtx && ret == 0) {
 		add_lock(lookup_lock(mutex));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -68,11 +72,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_mutex_trylock(mutex);
 	if (mutex != &witness_mtx && ret == 0) {
 		add_lock(lookup_lock(mutex));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -81,11 +89,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_mutex_timedlock(mutex, ts);
 	if (mutex != &witness_mtx && ret == 0) {
 		add_lock(lookup_lock(mutex));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -94,19 +106,31 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_mutex_unlock(mutex);
 	if (mutex != &witness_mtx && ret == 0) {
 		remove_lock(lookup_lock(mutex));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
 int
 pthread_mutex_destroy(pthread_mutex_t *mutex)
 {
+	int ret;
+
+	_pthread_mutex_lock(&witness_mtx);
+
 	destroy_lock(mutex);
-	return (_pthread_mutex_destroy(mutex));
+	ret = _pthread_mutex_destroy(mutex);
+
+	_pthread_mutex_unlock(&witness_mtx);
+
+	return (ret);
 }
 
 int
@@ -114,11 +138,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_rwlock_rdlock(rwlock);
 	if (ret == 0) {
 		add_lock(lookup_lock(rwlock));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -127,11 +155,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_rwlock_tryrdlock(rwlock);
 	if (ret == 0) {
 		add_lock(lookup_lock(rwlock));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -140,11 +172,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_rwlock_timedrdlock(rwlock, ts);
 	if (ret == 0) {
 		add_lock(lookup_lock(rwlock));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -153,11 +189,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_rwlock_wrlock(rwlock);
 	if (ret == 0) {
 		add_lock(lookup_lock(rwlock));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -166,11 +206,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_rwlock_trywrlock(rwlock);
 	if (ret == 0) {
 		add_lock(lookup_lock(rwlock));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -179,11 +223,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_rwlock_timedwrlock(rwlock, ts);
 	if (ret == 0) {
 		add_lock(lookup_lock(rwlock));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -192,19 +240,31 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_rwlock_unlock(rwlock);
 	if (ret == 0) {
 		remove_lock(lookup_lock(rwlock));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
 int
 pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
 {
+	int ret;
+
+	_pthread_mutex_lock(&witness_mtx);
+
 	destroy_lock(rwlock);
-	return (_pthread_rwlock_destroy(rwlock));
+	ret = _pthread_rwlock_destroy(rwlock);
+
+	_pthread_mutex_unlock(&witness_mtx);
+
+	return (ret);
 }
 
 int
@@ -212,11 +272,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_spin_lock(spin);
 	if (ret == 0) {
 		add_lock(lookup_lock(spin));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -225,11 +289,15 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_spin_lock(spin);
 	if (ret == 0) {
 		add_lock(lookup_lock(spin));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
@@ -238,29 +306,47 @@
 {
 	int ret;
 
+	_pthread_mutex_lock(&witness_mtx);
+
 	ret = _pthread_spin_unlock(spin);
 	if (ret == 0) {
 		remove_lock(lookup_lock(spin));
 	}
 
+	_pthread_mutex_unlock(&witness_mtx);
+
 	return (ret);
 }
 
 int
 pthread_spin_destroy(pthread_spinlock_t *spin)
 {
+	int ret;
+
+	_pthread_mutex_lock(&witness_mtx);
+
 	destroy_lock(spin);
-	return (_pthread_spin_destroy(spin));
+	ret = _pthread_spin_destroy(spin);
+
+	_pthread_mutex_unlock(&witness_mtx);
+
+	return (ret);
 }
 
 int
 pthread_lockorder_set_np(void *first, void *second)
 {
+	int ret = 0;
+
+	_pthread_mutex_lock(&witness_mtx);
+
 	if (insert_lock(lookup_lock(first), lookup_lock(second)) < 0) {
-		return (EINVAL);
+		ret = EINVAL;
 	}
 
-	return (0);
+	_pthread_mutex_unlock(&witness_mtx);
+
+	return (ret);
 }
 
 int
@@ -270,6 +356,9 @@
 	struct lock_info *second;
 	struct blessing *first_bless;
 	struct blessing *second_bless = NULL;
+	int ret = 0;
+
+	_pthread_mutex_lock(&witness_mtx);
 
 	first = lookup_lock(first_addr);
 	second = lookup_lock(second_addr);
@@ -283,14 +372,28 @@
 	}
 
 	if (second_bless == NULL) {
-		return (ENOMEM);
+		ret = ENOMEM;
+	} else {
+		first_bless->lock = second;
+		SLIST_INSERT_HEAD(&first->bless_head, first_bless, bless_next);
+
+		second_bless->lock = first;
+		SLIST_INSERT_HEAD(&second->bless_head, second_bless,
+				  bless_next);
 	}
 
-	first_bless->lock = second;
-	SLIST_INSERT_HEAD(&first->bless_head, first_bless, bless_next);
+	_pthread_mutex_unlock(&witness_mtx);
+
+	return (ret);
+}
+
+void
+pthread_lockorder_reset_np(void)
+{
+	_pthread_mutex_lock(&witness_mtx);
 
-	second_bless->lock = first;
-	SLIST_INSERT_HEAD(&second->bless_head, second_bless, bless_next);
+	reset_lists();
+	reset_lock_info();
 
-	return (0);
+	_pthread_mutex_unlock(&witness_mtx);
 }


More information about the svn-soc-all mailing list