socsvn commit: r239470 - in soc2012/gmiller/locking-head: .
lib/libwitness
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Mon Jul 16 15:14:24 UTC 2012
Author: gmiller
Date: Mon Jul 16 15:14:21 2012
New Revision: 239470
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239470
Log:
r239506 at FreeBSD-dev: root | 2012-07-14 06:11:18 -0500
Create a new structure lock_info for use as a lock identifier instead of
using the lock's address. This correctly handles stack-allocated locks and
allows for the addition of lock names.
Added:
soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
Modified:
soc2012/gmiller/locking-head/ (props changed)
soc2012/gmiller/locking-head/lib/libwitness/Makefile
soc2012/gmiller/locking-head/lib/libwitness/graph.c
soc2012/gmiller/locking-head/lib/libwitness/lists.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
Modified: soc2012/gmiller/locking-head/lib/libwitness/Makefile
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/Makefile Mon Jul 16 14:05:33 2012 (r239469)
+++ soc2012/gmiller/locking-head/lib/libwitness/Makefile Mon Jul 16 15:14:21 2012 (r239470)
@@ -4,7 +4,7 @@
LIB= witness
SHLIB_MAJOR= 1
-SRCS= wrappers.c graph.c lists.c logs.c
+SRCS= wrappers.c graph.c lists.c logs.c lockinfo.c
DPADD= ${LIBTHR}
LDADD= -lthr
Modified: soc2012/gmiller/locking-head/lib/libwitness/graph.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 16 14:05:33 2012 (r239469)
+++ soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 16 15:14:21 2012 (r239470)
@@ -27,10 +27,16 @@
#include "witness.h"
+struct graph_node {
+ struct lock_info *lock;
+ struct graph_node *child;
+ struct graph_node *sibling;
+};
+
struct graph_node *root = NULL;
static struct graph_node *
-scan_graph(struct graph_node *graph, void *lock)
+scan_graph(struct graph_node *graph, struct lock_info *lock)
{
struct graph_node *ret;
@@ -101,7 +107,7 @@
}
int
-insert_lock(void *new_lock, void *previous)
+insert_lock(struct lock_info *new_lock, struct lock_info *previous)
{
return (insert_edge(lookup_node(previous), lookup_node(new_lock)));
}
Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lists.c Mon Jul 16 14:05:33 2012 (r239469)
+++ soc2012/gmiller/locking-head/lib/libwitness/lists.c Mon Jul 16 15:14:21 2012 (r239470)
@@ -27,11 +27,16 @@
#include "witness.h"
+struct lock_entry {
+ SLIST_ENTRY(lock_entry) lock_next;
+ struct lock_info *lock;
+};
+
static _Thread_local SLIST_HEAD(lock_head, lock_entry) lock_head =
SLIST_HEAD_INITIALIZER(lock_head);
void
-add_lock(void *lock)
+add_lock(struct lock_info *lock)
{
struct lock_entry *entry;
struct lock_entry *next;
@@ -49,7 +54,7 @@
}
void
-remove_lock(void *lock)
+remove_lock(struct lock_info *lock)
{
struct lock_entry *entry;
struct lock_entry *temp;
Added: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 16 15:14:21 2012 (r239470)
@@ -0,0 +1,61 @@
+/*-
+ * Copyright (c) 2012 Greg Miller <gmiller at freebsd.org>..
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include "witness.h"
+
+static SLIST_HEAD(lock_info_head, lock_info) lock_info_head =
+ SLIST_HEAD_INITIALIZER(lock_info_head);
+
+struct lock_info *
+lookup_lock(void *lock)
+{
+ struct lock_info *info;
+
+ SLIST_FOREACH(info, &lock_info_head, lock_info_next) {
+ if (info->lock == lock && info->active) {
+ break;
+ }
+ }
+
+ if (info == NULL) {
+ info = malloc(sizeof(struct lock_info));
+ info->active = 1;
+ info->lock = lock;
+ SLIST_INSERT_HEAD(&lock_info_head, info, lock_info_next);
+ }
+
+ return (info);
+}
+
+void
+destroy_lock(void *lock)
+{
+ struct lock_info *info;
+
+ info = lookup_lock(lock);
+ info->active = 0;
+}
Modified: soc2012/gmiller/locking-head/lib/libwitness/logs.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/logs.c Mon Jul 16 14:05:33 2012 (r239469)
+++ soc2012/gmiller/locking-head/lib/libwitness/logs.c Mon Jul 16 15:14:21 2012 (r239470)
@@ -31,8 +31,8 @@
struct lor_entry {
STAILQ_ENTRY(lor_entry) lor_next;
- void *lock_first;
- void *lock_second;
+ struct lock_info *lock_first;
+ struct lock_info *lock_second;
};
struct _pthread_lor_private {
@@ -40,7 +40,7 @@
};
void
-log_reversal(void *lock, void *previous)
+log_reversal(struct lock_info *lock, struct lock_info *previous)
{
struct lor_entry *entry;
@@ -58,7 +58,6 @@
The lock isn't needed to prevent races, but it is needed to ensure
that any locks grabbed by malloc() don't get logged.
*/
-
pthread_mutex_lock(&witness_mtx);
lor->_pvt = malloc(sizeof(struct _pthread_lor_private));
Modified: soc2012/gmiller/locking-head/lib/libwitness/witness.h
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/witness.h Mon Jul 16 14:05:33 2012 (r239469)
+++ soc2012/gmiller/locking-head/lib/libwitness/witness.h Mon Jul 16 15:14:21 2012 (r239470)
@@ -31,22 +31,20 @@
#include <pthread_np.h>
#include <stdlib.h>
-struct lock_entry {
- SLIST_ENTRY(lock_entry) lock_next;
+struct lock_info {
+ SLIST_ENTRY(lock_info) lock_info_next;
void *lock;
-};
-
-struct graph_node {
- void *lock;
- struct graph_node *child;
- struct graph_node *sibling;
+ int active;
};
extern pthread_mutex_t witness_mtx;
-void add_lock(void *lock);
-void remove_lock(void *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);
-int insert_lock(void *new_lock, void *previous);
+void log_reversal(struct lock_info *lock, struct lock_info *previous);
-void log_reversal(void *lock, void *previous);
+struct lock_info *lookup_lock(void *lock);
+void destroy_lock(void *lock);
Modified: soc2012/gmiller/locking-head/lib/libwitness/wrappers.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Mon Jul 16 14:05:33 2012 (r239469)
+++ soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Mon Jul 16 15:14:21 2012 (r239470)
@@ -32,6 +32,7 @@
int _pthread_mutex_timedlock(pthread_mutex_t *mutex,
const struct timespec *ts);
int _pthread_mutex_unlock(pthread_mutex_t *mutex);
+int _pthread_mutex_destroy(pthread_mutex_t *mutex);
int _pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
int _pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock);
int _pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock,
@@ -41,9 +42,11 @@
int _pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock,
const struct timespec *ts);
int _pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
+int _pthread_rwlock_destroy(pthread_rwlock_t *rwlock);
int _pthread_spin_lock(pthread_spinlock_t *spin);
int _pthread_spin_trylock(pthread_spinlock_t *spin);
int _pthread_spin_unlock(pthread_spinlock_t *spin);
+int _pthread_spin_destroy(pthread_spinlock_t *spin);
pthread_mutex_t witness_mtx = PTHREAD_MUTEX_INITIALIZER;
@@ -54,7 +57,7 @@
ret = _pthread_mutex_lock(mutex);
if (mutex != &witness_mtx && ret == 0) {
- add_lock(mutex);
+ add_lock(lookup_lock(mutex));
}
return (ret);
@@ -67,7 +70,7 @@
ret = _pthread_mutex_trylock(mutex);
if (mutex != &witness_mtx && ret == 0) {
- add_lock(mutex);
+ add_lock(lookup_lock(mutex));
}
return (ret);
@@ -80,7 +83,7 @@
ret = _pthread_mutex_timedlock(mutex, ts);
if (mutex != &witness_mtx && ret == 0) {
- add_lock(mutex);
+ add_lock(lookup_lock(mutex));
}
return (ret);
@@ -93,20 +96,27 @@
ret = _pthread_mutex_unlock(mutex);
if (mutex != &witness_mtx && ret == 0) {
- remove_lock(mutex);
+ remove_lock(lookup_lock(mutex));
}
return (ret);
}
int
+pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+ destroy_lock(mutex);
+ return (_pthread_mutex_destroy(mutex));
+}
+
+int
pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
{
int ret;
ret = _pthread_rwlock_rdlock(rwlock);
if (ret == 0) {
- add_lock(rwlock);
+ add_lock(lookup_lock(rwlock));
}
return (ret);
@@ -119,7 +129,7 @@
ret = _pthread_rwlock_tryrdlock(rwlock);
if (ret == 0) {
- add_lock(rwlock);
+ add_lock(lookup_lock(rwlock));
}
return (ret);
@@ -132,7 +142,7 @@
ret = _pthread_rwlock_timedrdlock(rwlock, ts);
if (ret == 0) {
- add_lock(rwlock);
+ add_lock(lookup_lock(rwlock));
}
return (ret);
@@ -145,7 +155,7 @@
ret = _pthread_rwlock_wrlock(rwlock);
if (ret == 0) {
- add_lock(rwlock);
+ add_lock(lookup_lock(rwlock));
}
return (ret);
@@ -158,7 +168,7 @@
ret = _pthread_rwlock_trywrlock(rwlock);
if (ret == 0) {
- add_lock(rwlock);
+ add_lock(lookup_lock(rwlock));
}
return (ret);
@@ -171,7 +181,7 @@
ret = _pthread_rwlock_timedwrlock(rwlock, ts);
if (ret == 0) {
- add_lock(rwlock);
+ add_lock(lookup_lock(rwlock));
}
return (ret);
@@ -184,20 +194,27 @@
ret = _pthread_rwlock_unlock(rwlock);
if (ret == 0) {
- remove_lock(rwlock);
+ remove_lock(lookup_lock(rwlock));
}
return (ret);
}
int
+pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
+{
+ destroy_lock(rwlock);
+ return (_pthread_rwlock_destroy(rwlock));
+}
+
+int
pthread_spin_lock(pthread_spinlock_t *spin)
{
int ret;
ret = _pthread_spin_lock(spin);
if (ret == 0) {
- add_lock(spin);
+ add_lock(lookup_lock(spin));
}
return (ret);
@@ -210,7 +227,7 @@
ret = _pthread_spin_lock(spin);
if (ret == 0) {
- add_lock(spin);
+ add_lock(lookup_lock(spin));
}
return (ret);
@@ -223,8 +240,15 @@
ret = _pthread_spin_unlock(spin);
if (ret == 0) {
- remove_lock(spin);
+ remove_lock(lookup_lock(spin));
}
return (ret);
}
+
+int
+pthread_spin_destroy(pthread_spinlock_t *spin)
+{
+ destroy_lock(spin);
+ return (_pthread_spin_destroy(spin));
+}
More information about the svn-soc-all
mailing list