Module Name: src Committed By: pooka Date: Thu Jan 6 11:22:55 UTC 2011
Modified Files: src/sys/rump: Makefile.rump src/sys/rump/librump/rumpkern: Makefile.rumpkern emul.c locks.c lwproc.c rump.c Log Message: Support LOCKDEBUG. To use it, compile sys/rump with RUMP_LOCKDEBUG=yes. requested by martin (sparc64 gdb cannot reliably produce a stack trace) To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/sys/rump/Makefile.rump cvs rdiff -u -r1.105 -r1.106 src/sys/rump/librump/rumpkern/Makefile.rumpkern cvs rdiff -u -r1.147 -r1.148 src/sys/rump/librump/rumpkern/emul.c cvs rdiff -u -r1.44 -r1.45 src/sys/rump/librump/rumpkern/locks.c cvs rdiff -u -r1.7 -r1.8 src/sys/rump/librump/rumpkern/lwproc.c cvs rdiff -u -r1.215 -r1.216 src/sys/rump/librump/rumpkern/rump.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/rump/Makefile.rump diff -u src/sys/rump/Makefile.rump:1.58 src/sys/rump/Makefile.rump:1.59 --- src/sys/rump/Makefile.rump:1.58 Mon Dec 6 09:12:34 2010 +++ src/sys/rump/Makefile.rump Thu Jan 6 11:22:54 2011 @@ -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. Index: src/sys/rump/librump/rumpkern/Makefile.rumpkern diff -u src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.105 src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.106 --- src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.105 Tue Jan 4 16:23:36 2011 +++ src/sys/rump/librump/rumpkern/Makefile.rumpkern Thu Jan 6 11:22:55 2011 @@ -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 Index: src/sys/rump/librump/rumpkern/emul.c diff -u src/sys/rump/librump/rumpkern/emul.c:1.147 src/sys/rump/librump/rumpkern/emul.c:1.148 --- src/sys/rump/librump/rumpkern/emul.c:1.147 Sun Nov 21 17:34:11 2010 +++ src/sys/rump/librump/rumpkern/emul.c Thu Jan 6 11:22:55 2011 @@ -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 Index: src/sys/rump/librump/rumpkern/locks.c diff -u src/sys/rump/librump/rumpkern/locks.c:1.44 src/sys/rump/librump/rumpkern/locks.c:1.45 --- src/sys/rump/librump/rumpkern/locks.c:1.44 Wed Dec 1 17:22:51 2010 +++ src/sys/rump/librump/rumpkern/locks.c Thu Jan 6 11:22:55 2011 @@ -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 - 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) Index: src/sys/rump/librump/rumpkern/lwproc.c diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.7 src/sys/rump/librump/rumpkern/lwproc.c:1.8 --- src/sys/rump/librump/rumpkern/lwproc.c:1.7 Sun Jan 2 12:52:25 2011 +++ src/sys/rump/librump/rumpkern/lwproc.c Thu Jan 6 11:22:55 2011 @@ -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 @@ 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); Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.215 src/sys/rump/librump/rumpkern/rump.c:1.216 --- src/sys/rump/librump/rumpkern/rump.c:1.215 Tue Jan 4 16:23:36 2011 +++ src/sys/rump/librump/rumpkern/rump.c Thu Jan 6 11:22:55 2011 @@ -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 @@ #include <sys/uidinfo.h> #include <sys/vmem.h> #include <sys/xcall.h> +#include <sys/simplelock.h> #include <rump/rumpuser.h> @@ -368,6 +369,9 @@ 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); }