Support LOCKDEBUG. To use it, compile sys/rump with RUMP_LOCKDEBUG=yes.

requested by martin (sparc64 gdb cannot reliably produce a stack trace)
This commit is contained in:
pooka 2011-01-06 11:22:54 +00:00
parent f150925704
commit cd73d116db
6 changed files with 114 additions and 35 deletions

View File

@ -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 @@ CPPFLAGS+= -nostdinc -isystem ${RUMPTOP}/..
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.

View File

@ -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 @@ SRCS+= clock_subr.c
#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

View File

@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.147 2010/11/21 17:34:11 pooka Exp $");
#include <sys/reboot.h>
#include <sys/syscallvar.h>
#include <sys/xcall.h>
#include <sys/sleepq.h>
#include <dev/cons.h>
@ -293,3 +294,12 @@ trace_exit(register_t code, register_t rval[], int error)
/* nada */
}
#ifdef LOCKDEBUG
void
turnstile_print(volatile void *obj, void (*pr)(const char *, ...))
{
/* nada */
}
#endif

View File

@ -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>
@ -40,6 +40,42 @@ __KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.44 2010/12/01 17:22:51 pooka Exp $");
#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
@ -61,12 +97,14 @@ mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
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 @@ void
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 @@ rw_init(krwlock_t *rw)
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 @@ void
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 @@ cv_wait(kcondvar_t *cv, kmutex_t *mtx)
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 @@ cv_wait_sig(kcondvar_t *cv, kmutex_t *mtx)
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 @@ cv_timedwait(kcondvar_t *cv, kmutex_t *mtx, int ticks)
{
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 @@ cv_timedwait(kcondvar_t *cv, kmutex_t *mtx, int ticks)
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
return 0;
rv = 0;
LOCKED(mtx, false);
}
}
int
cv_timedwait_sig(kcondvar_t *cv, kmutex_t *mtx, int ticks)
{
return cv_timedwait(cv, mtx, ticks);
return rv;
}
__strong_alias(cv_timedwait_sig,cv_timedwait);
void
cv_signal(kcondvar_t *cv)

View File

@ -1,4 +1,4 @@
/* $NetBSD: lwproc.c,v 1.7 2011/01/02 12:52:25 pooka Exp $ */
/* $NetBSD: lwproc.c,v 1.8 2011/01/06 11:22:55 pooka Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.7 2011/01/02 12:52:25 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.8 2011/01/06 11:22:55 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -218,6 +218,7 @@ lwproc_makelwp(struct proc *p, struct lwp *l, bool doswitch, bool procmake)
l->l_fd = p->p_fd;
l->l_cpu = NULL;
l->l_target_cpu = rump_cpu; /* Initial target CPU always the same */
TAILQ_INIT(&l->l_ld_locks);
lwp_initspecific(l);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rump.c,v 1.215 2011/01/04 16:23:36 pooka Exp $ */
/* $NetBSD: rump.c,v 1.216 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: rump.c,v 1.215 2011/01/04 16:23:36 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.216 2011/01/06 11:22:55 pooka Exp $");
#include <sys/systm.h>
#define ELFSIZE ARCH_ELFSIZE
@ -69,6 +69,7 @@ __KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.215 2011/01/04 16:23:36 pooka Exp $");
#include <sys/uidinfo.h>
#include <sys/vmem.h>
#include <sys/xcall.h>
#include <sys/simplelock.h>
#include <rump/rumpuser.h>
@ -368,6 +369,9 @@ rump__init(int rump_version)
selsysinit(ci);
percpu_init_cpu(ci);
TAILQ_INIT(&ci->ci_data.cpu_ld_locks);
__cpu_simple_lock_init(&ci->ci_data.cpu_ld_lock);
aprint_verbose("cpu%d at thinair0: rump virtual cpu\n", i);
}