Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump Support LOCKDEBUG. To use it, compile sys/rump wit...
details: https://anonhg.NetBSD.org/src/rev/d42a66d33409
branches: trunk
changeset: 760505:d42a66d33409
user: pooka <pooka%NetBSD.org@localhost>
date: Thu Jan 06 11:22:54 2011 +0000
description:
Support LOCKDEBUG. To use it, compile sys/rump with RUMP_LOCKDEBUG=yes.
requested by martin (sparc64 gdb cannot reliably produce a stack trace)
diffstat:
sys/rump/Makefile.rump | 6 +-
sys/rump/librump/rumpkern/Makefile.rumpkern | 6 +-
sys/rump/librump/rumpkern/emul.c | 14 +++-
sys/rump/librump/rumpkern/locks.c | 110 +++++++++++++++++++++------
sys/rump/librump/rumpkern/lwproc.c | 5 +-
sys/rump/librump/rumpkern/rump.c | 8 +-
6 files changed, 114 insertions(+), 35 deletions(-)
diffs (truncated from 379 to 300 lines):
diff -r 379f9df99627 -r d42a66d33409 sys/rump/Makefile.rump
--- a/sys/rump/Makefile.rump Thu Jan 06 11:07:48 2011 +0000
+++ b/sys/rump/Makefile.rump Thu Jan 06 11:22:54 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.rump,v 1.58 2010/12/06 09:12:34 pooka Exp $
+# $NetBSD: Makefile.rump,v 1.59 2011/01/06 11:22:54 pooka Exp $
#
WARNS?= 3 # XXX: src/sys won't compile with -Wsign-compare yet
@@ -30,6 +30,10 @@
LDFLAGS+= -T ${RUMPTOP}/ldscript.rump
#CPPFLAGS+= -DDEBUG
+.ifdef RUMP_LOCKDEBUG
+CPPFLAGS+= -DLOCKDEBUG
+.endif
+
# kernel libs should not get linked against libc
# XXX: actually, we would like to enable this but cannot, since it
# also leaves out libgcc, it causes problems on some platforms.
diff -r 379f9df99627 -r d42a66d33409 sys/rump/librump/rumpkern/Makefile.rumpkern
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern Thu Jan 06 11:07:48 2011 +0000
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern Thu Jan 06 11:22:54 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.rumpkern,v 1.105 2011/01/04 16:23:36 pooka Exp $
+# $NetBSD: Makefile.rumpkern,v 1.106 2011/01/06 11:22:55 pooka Exp $
#
.include "${RUMPTOP}/Makefile.rump"
@@ -125,6 +125,10 @@
#CPPFLAGS+= -DRUMP_USE_UNREAL_ALLOCATORS
SRCS+= subr_kmem.c subr_percpu.c subr_pool.c subr_vmem.c
+.ifdef RUMP_LOCKDEBUG
+SRCS+= subr_lockdebug.c
+.endif
+
# no shlib_version because this is automatically in sync with lib/librump
SHLIB_MAJOR= 0
SHLIB_MINOR= 0
diff -r 379f9df99627 -r d42a66d33409 sys/rump/librump/rumpkern/emul.c
--- a/sys/rump/librump/rumpkern/emul.c Thu Jan 06 11:07:48 2011 +0000
+++ b/sys/rump/librump/rumpkern/emul.c Thu Jan 06 11:22:54 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emul.c,v 1.147 2010/11/21 17:34:11 pooka Exp $ */
+/* $NetBSD: emul.c,v 1.148 2011/01/06 11:22:55 pooka Exp $ */
/*
* Copyright (c) 2007 Antti Kantee. All Rights Reserved.
@@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.147 2010/11/21 17:34:11 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.148 2011/01/06 11:22:55 pooka Exp $");
#include <sys/param.h>
#include <sys/null.h>
@@ -52,6 +52,7 @@
#include <sys/reboot.h>
#include <sys/syscallvar.h>
#include <sys/xcall.h>
+#include <sys/sleepq.h>
#include <dev/cons.h>
@@ -293,3 +294,12 @@
/* nada */
}
+
+#ifdef LOCKDEBUG
+void
+turnstile_print(volatile void *obj, void (*pr)(const char *, ...))
+{
+
+ /* nada */
+}
+#endif
diff -r 379f9df99627 -r d42a66d33409 sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Thu Jan 06 11:07:48 2011 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Thu Jan 06 11:22:54 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locks.c,v 1.44 2010/12/01 17:22:51 pooka Exp $ */
+/* $NetBSD: locks.c,v 1.45 2011/01/06 11:22:55 pooka Exp $ */
/*
* Copyright (c) 2007, 2008 Antti Kantee. All Rights Reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.44 2010/12/01 17:22:51 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.45 2011/01/06 11:22:55 pooka Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -41,6 +41,42 @@
#include "rump_private.h"
/*
+ * Simple lockdebug. If it's compiled in, it's always active.
+ * Currently available only for mtx/rwlock.
+ */
+#ifdef LOCKDEBUG
+#include <sys/lockdebug.h>
+
+static lockops_t mutex_lockops = {
+ "mutex",
+ LOCKOPS_SLEEP,
+ NULL
+};
+static lockops_t rw_lockops = {
+ "mutex",
+ LOCKOPS_SLEEP,
+ NULL
+};
+
+#define ALLOCK(lock, ops) \
+ lockdebug_alloc(lock, ops, (uintptr_t)__builtin_return_address(0))
+#define FREELOCK(lock) \
+ lockdebug_free(lock)
+#define WANTLOCK(lock, shar, try) \
+ lockdebug_wantlock(lock, (uintptr_t)__builtin_return_address(0), shar, try)
+#define LOCKED(lock, shar) \
+ lockdebug_locked(lock, NULL, (uintptr_t)__builtin_return_address(0), shar)
+#define UNLOCKED(lock, shar) \
+ lockdebug_unlocked(lock, (uintptr_t)__builtin_return_address(0), shar)
+#else
+#define ALLOCK(a, b)
+#define FREELOCK(a)
+#define WANTLOCK(a, b, c)
+#define LOCKED(a, b)
+#define UNLOCKED(a, b)
+#endif
+
+/*
* We map locks to pthread routines. The difference between kernel
* and rumpuser routines is that while the kernel uses static
* storage, rumpuser allocates the object from the heap. This
@@ -61,12 +97,14 @@
CTASSERT(sizeof(kmutex_t) >= sizeof(void *));
rumpuser_mutex_init_kmutex((struct rumpuser_mtx **)mtx);
+ ALLOCK(mtx, &mutex_lockops);
}
void
mutex_destroy(kmutex_t *mtx)
{
+ FREELOCK(mtx);
rumpuser_mutex_destroy(RUMPMTX(mtx));
}
@@ -74,36 +112,33 @@
mutex_enter(kmutex_t *mtx)
{
+ WANTLOCK(mtx, false, false);
rumpuser_mutex_enter(RUMPMTX(mtx));
+ LOCKED(mtx, false);
}
-
-void
-mutex_spin_enter(kmutex_t *mtx)
-{
-
- mutex_enter(mtx);
-}
+__strong_alias(mutex_spin_enter,mutex_enter);
int
mutex_tryenter(kmutex_t *mtx)
{
+ int rv;
- return rumpuser_mutex_tryenter(RUMPMTX(mtx));
+ rv = rumpuser_mutex_tryenter(RUMPMTX(mtx));
+ if (rv) {
+ WANTLOCK(mtx, false, true);
+ LOCKED(mtx, false);
+ }
+ return rv;
}
void
mutex_exit(kmutex_t *mtx)
{
+ UNLOCKED(mtx, false);
rumpuser_mutex_exit(RUMPMTX(mtx));
}
-
-void
-mutex_spin_exit(kmutex_t *mtx)
-{
-
- mutex_exit(mtx);
-}
+__strong_alias(mutex_spin_exit,mutex_exit);
int
mutex_owned(kmutex_t *mtx)
@@ -130,12 +165,14 @@
CTASSERT(sizeof(krwlock_t) >= sizeof(void *));
rumpuser_rw_init((struct rumpuser_rw **)rw);
+ ALLOCK(rw, &rw_lockops);
}
void
rw_destroy(krwlock_t *rw)
{
+ FREELOCK(rw);
rumpuser_rw_destroy(RUMPRW(rw));
}
@@ -143,20 +180,36 @@
rw_enter(krwlock_t *rw, const krw_t op)
{
+
+ WANTLOCK(rw, op == RW_READER, false);
rumpuser_rw_enter(RUMPRW(rw), op == RW_WRITER);
+ LOCKED(rw, op == RW_READER);
}
int
rw_tryenter(krwlock_t *rw, const krw_t op)
{
+ int rv;
- return rumpuser_rw_tryenter(RUMPRW(rw), op == RW_WRITER);
+ rv = rumpuser_rw_tryenter(RUMPRW(rw), op == RW_WRITER);
+ if (rv) {
+ WANTLOCK(rw, op == RW_READER, true);
+ LOCKED(rw, op == RW_READER);
+ }
+ return rv;
}
void
rw_exit(krwlock_t *rw)
{
+#ifdef LOCKDEBUG
+ bool shared = !rw_write_held(rw);
+
+ if (shared)
+ KASSERT(rw_read_held(rw));
+ UNLOCKED(rw, shared);
+#endif
rumpuser_rw_exit(RUMPRW(rw));
}
@@ -215,7 +268,9 @@
if (__predict_false(rump_threads == 0))
panic("cv_wait without threads");
+ UNLOCKED(mtx, false);
rumpuser_cv_wait(RUMPCV(cv), RUMPMTX(mtx));
+ LOCKED(mtx, false);
}
int
@@ -224,7 +279,9 @@
if (__predict_false(rump_threads == 0))
panic("cv_wait without threads");
+ UNLOCKED(mtx, false);
rumpuser_cv_wait(RUMPCV(cv), RUMPMTX(mtx));
+ LOCKED(mtx, false);
return 0;
}
@@ -233,10 +290,11 @@
{
struct timespec ts, tick;
extern int hz;
+ int rv;
if (ticks == 0) {
cv_wait(cv, mtx);
- return 0;
+ rv = 0;
} else {
/*
* XXX: this fetches rump kernel time, but
@@ -247,20 +305,18 @@
tick.tv_nsec = (ticks % hz) * (1000000000/hz);
timespecadd(&ts, &tick, &ts);
+ UNLOCKED(mtx, false);
if (rumpuser_cv_timedwait(RUMPCV(cv), RUMPMTX(mtx),
ts.tv_sec, ts.tv_nsec))
- return EWOULDBLOCK;
+ rv = EWOULDBLOCK;
else
Home |
Main Index |
Thread Index |
Old Index