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

gmiller at FreeBSD.org gmiller at FreeBSD.org
Fri Aug 17 23:08:45 UTC 2012


Author: gmiller
Date: Fri Aug 17 23:08:43 2012
New Revision: 240483
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240483

Log:
   r240504 at FreeBSD-dev:  root | 2012-08-15 14:51:32 -0500
   Rename lists.c -> locklist.c to better describe its purpose.

Added:
  soc2012/gmiller/locking-head/lib/libwitness/locklist.c
     - copied unchanged from r240482, soc2012/gmiller/locking-head/lib/libwitness/lists.c
Deleted:
  soc2012/gmiller/locking-head/lib/libwitness/lists.c
Modified:
  soc2012/gmiller/locking-head/   (props changed)
  soc2012/gmiller/locking-head/lib/libwitness/Makefile

Modified: soc2012/gmiller/locking-head/lib/libwitness/Makefile
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/Makefile	Fri Aug 17 23:08:26 2012	(r240482)
+++ soc2012/gmiller/locking-head/lib/libwitness/Makefile	Fri Aug 17 23:08:43 2012	(r240483)
@@ -4,7 +4,7 @@
 
 LIB=		witness
 SHLIB_MAJOR=	1
-SRCS=		api.c graph.c lists.c lockinfo.c xml.c unwind.c
+SRCS=		api.c graph.c locklist.c lockinfo.c xml.c unwind.c
 DPADD=		${LIBTHR}
 LDADD=		-lthr
 

Copied: soc2012/gmiller/locking-head/lib/libwitness/locklist.c (from r240482, soc2012/gmiller/locking-head/lib/libwitness/lists.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2012/gmiller/locking-head/lib/libwitness/locklist.c	Fri Aug 17 23:08:43 2012	(r240483, copy of r240482, soc2012/gmiller/locking-head/lib/libwitness/lists.c)
@@ -0,0 +1,159 @@
+/*-
+ * 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"
+
+struct lock_entry {
+	SLIST_ENTRY(lock_entry) lock_next;
+	struct lock_info *lock;
+	struct backtrace trace;
+};
+
+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;
+static int	exit_set = 0;
+struct lor_head	lor_head = STAILQ_HEAD_INITIALIZER(lor_head);
+
+static void
+log_reversal(struct lock_info *lock, struct backtrace *lock_trace,
+	     struct lock_info *previous, struct backtrace *previous_trace)
+{
+	struct lor_entry *entry;
+
+	entry = malloc(sizeof(struct lor_entry));
+	if (entry != NULL) {
+		entry->lock_first = previous;
+		entry->first_trace = trace_str(previous_trace);
+		entry->lock_second = lock;
+		entry->second_trace = trace_str(lock_trace);
+
+		STAILQ_INSERT_TAIL(&lor_head, entry, lor_next);
+	}
+}
+
+void
+free_frame(struct backtrace *trace)
+{
+	struct stack_frame *frame;
+
+	while (!SLIST_EMPTY(trace)) {
+		frame = SLIST_FIRST(trace);
+		SLIST_REMOVE_HEAD(trace, frame_next);
+
+		free(frame);
+	}
+
+}
+
+static void
+free_entry(struct lock_entry *entry)
+{
+	free_frame(&entry->trace);
+	free(entry);
+}
+
+void
+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);
+		exit_set = 1;
+	}
+
+	if (in_witness() > 1 || lock == NULL) {
+		return;
+	}
+
+	inst = lookup_lock(lock);
+	info = get_lock_info(inst);
+
+	next = SLIST_FIRST(&lock_head);
+
+	entry = malloc(sizeof(*entry));
+	if (entry == NULL) {
+		return;
+	}
+
+	SLIST_INIT(&entry->trace);
+	record_backtrace(&entry->trace);
+	entry->lock = info;
+
+	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(entry);
+		}
+
+		next = NULL;
+	}
+
+	SLIST_INSERT_HEAD(&lock_head, entry, lock_next);
+
+	if (next != NULL && insert_lock(next->lock, entry->lock) < 0) {
+		log_reversal(entry->lock, &entry->trace, next->lock,
+			     &next->trace);
+	}
+}
+
+void
+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 == info) {
+			SLIST_REMOVE(&lock_head, entry, lock_entry, lock_next);
+			free_entry(entry);
+
+			break;
+		}
+	}
+}
+
+void
+reset_lists(void)
+{
+	reset_count++;
+}


More information about the svn-soc-all mailing list