Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Try to make sure that the appropriate calls to mutex_enter()...
details: https://anonhg.NetBSD.org/src/rev/67d68beda2d3
branches: trunk
changeset: 786358:67d68beda2d3
user: pooka <pooka%NetBSD.org@localhost>
date: Sat Apr 27 13:59:46 2013 +0000
description:
Try to make sure that the appropriate calls to mutex_enter() takes
a spin mutex (i.e. does not relinquish cpu context while trying to
take the mutex).
Bump the hypercall interface version number. I'll be doing a bunch
of other cleanups to simplify the interface for the benefit of
alternative hypervisor implementations. I'll be riding this bump
and doing a second one only after I'm finished with all of the
changes.
diffstat:
lib/librumpuser/rumpuser_pth.c | 26 +++++++++++++++++---------
lib/librumpuser/rumpuser_pth_dummy.c | 6 +++---
sys/rump/include/rump/rumpuser.h | 6 +++---
sys/rump/librump/rumpkern/locks.c | 35 +++++++++++++++++++++++++++++++----
sys/rump/librump/rumpkern/locks_up.c | 11 +++++++++--
5 files changed, 63 insertions(+), 21 deletions(-)
diffs (249 lines):
diff -r d4df116b77ff -r 67d68beda2d3 lib/librumpuser/rumpuser_pth.c
--- a/lib/librumpuser/rumpuser_pth.c Sat Apr 27 13:25:09 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth.c Sat Apr 27 13:59:46 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_pth.c,v 1.12 2013/02/11 16:02:31 pooka Exp $ */
+/* $NetBSD: rumpuser_pth.c,v 1.13 2013/04/27 13:59:46 pooka Exp $ */
/*
* Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
@@ -28,7 +28,7 @@
#include "rumpuser_port.h"
#if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth.c,v 1.12 2013/02/11 16:02:31 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth.c,v 1.13 2013/04/27 13:59:46 pooka Exp $");
#endif /* !lint */
#include <assert.h>
@@ -58,10 +58,12 @@
} \
} while (/*CONSTCOND*/0)
+#define MTX_KMUTEX 0x1
+#define MTX_ISSPIN 0x2
struct rumpuser_mtx {
pthread_mutex_t pthmtx;
struct lwp *owner;
- int iskmutex;
+ int flags;
};
#define RURW_AMWRITER(rw) (rw->writer == rumpuser_get_curlwp() \
@@ -295,22 +297,22 @@
pthread_mutexattr_destroy(&att);
(*mtx)->owner = NULL;
- (*mtx)->iskmutex = 0;
+ (*mtx)->flags = MTX_ISSPIN;
}
void
-rumpuser_mutex_init_kmutex(struct rumpuser_mtx **mtx)
+rumpuser_mutex_init_kmutex(struct rumpuser_mtx **mtx, int isspin)
{
rumpuser_mutex_init(mtx);
- (*mtx)->iskmutex = 1;
+ (*mtx)->flags = MTX_KMUTEX | (isspin ? MTX_ISSPIN : 0);
}
static void
mtxenter(struct rumpuser_mtx *mtx)
{
- if (!mtx->iskmutex)
+ if (!(mtx->flags & MTX_KMUTEX))
return;
assert(mtx->owner == NULL);
@@ -321,7 +323,7 @@
mtxexit(struct rumpuser_mtx *mtx)
{
- if (!mtx->iskmutex)
+ if (!(mtx->flags & MTX_KMUTEX))
return;
assert(mtx->owner != NULL);
@@ -332,6 +334,11 @@
rumpuser_mutex_enter(struct rumpuser_mtx *mtx)
{
+ if (mtx->flags & MTX_ISSPIN) {
+ rumpuser_mutex_enter_nowrap(mtx);
+ return;
+ }
+
if (pthread_mutex_trylock(&mtx->pthmtx) != 0)
KLOCK_WRAP(NOFAIL_ERRNO(pthread_mutex_lock(&mtx->pthmtx)));
mtxenter(mtx);
@@ -341,6 +348,7 @@
rumpuser_mutex_enter_nowrap(struct rumpuser_mtx *mtx)
{
+ assert(mtx->flags & MTX_ISSPIN);
NOFAIL_ERRNO(pthread_mutex_lock(&mtx->pthmtx));
mtxenter(mtx);
}
@@ -378,7 +386,7 @@
rumpuser_mutex_owner(struct rumpuser_mtx *mtx)
{
- if (__predict_false(!mtx->iskmutex)) {
+ if (__predict_false(!(mtx->flags & MTX_KMUTEX))) {
printf("panic: rumpuser_mutex_held unsupported on non-kmtx\n");
abort();
}
diff -r d4df116b77ff -r 67d68beda2d3 lib/librumpuser/rumpuser_pth_dummy.c
--- a/lib/librumpuser/rumpuser_pth_dummy.c Sat Apr 27 13:25:09 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth_dummy.c Sat Apr 27 13:59:46 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_pth_dummy.c,v 1.7 2012/11/06 18:33:00 pooka Exp $ */
+/* $NetBSD: rumpuser_pth_dummy.c,v 1.8 2013/04/27 13:59:46 pooka Exp $ */
/*
* Copyright (c) 2009 Antti Kantee. All Rights Reserved.
@@ -29,7 +29,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.7 2012/11/06 18:33:00 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.8 2013/04/27 13:59:46 pooka Exp $");
#endif /* !lint */
#include <sys/time.h>
@@ -111,7 +111,7 @@
}
void
-rumpuser_mutex_init_kmutex(struct rumpuser_mtx **mtx)
+rumpuser_mutex_init_kmutex(struct rumpuser_mtx **mtx, int isspin)
{
*mtx = calloc(1, sizeof(struct rumpuser_mtx));
diff -r d4df116b77ff -r 67d68beda2d3 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h Sat Apr 27 13:25:09 2013 +0000
+++ b/sys/rump/include/rump/rumpuser.h Sat Apr 27 13:59:46 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser.h,v 1.75 2013/03/08 19:04:28 pooka Exp $ */
+/* $NetBSD: rumpuser.h,v 1.76 2013/04/27 13:59:46 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -38,7 +38,7 @@
#include <stdint.h>
#endif
-#define RUMPUSER_VERSION 15
+#define RUMPUSER_VERSION 16
int rumpuser_getversion(void);
int rumpuser_daemonize_begin(void);
@@ -143,7 +143,7 @@
struct rumpuser_mtx;
void rumpuser_mutex_init(struct rumpuser_mtx **);
-void rumpuser_mutex_init_kmutex(struct rumpuser_mtx **);
+void rumpuser_mutex_init_kmutex(struct rumpuser_mtx **, int);
void rumpuser_mutex_enter(struct rumpuser_mtx *);
void rumpuser_mutex_enter_nowrap(struct rumpuser_mtx *);
int rumpuser_mutex_tryenter(struct rumpuser_mtx *);
diff -r d4df116b77ff -r 67d68beda2d3 sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Sat Apr 27 13:25:09 2013 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Sat Apr 27 13:59:46 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locks.c,v 1.55 2011/12/06 18:04:31 njoly Exp $ */
+/* $NetBSD: locks.c,v 1.56 2013/04/27 13:59:46 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.55 2011/12/06 18:04:31 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.56 2013/04/27 13:59:46 pooka Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -90,10 +90,29 @@
void
mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
{
+ int isspin;
+
+ /*
+ * Try to figure out if the caller wanted a spin mutex or
+ * not with this easy set of conditionals. The difference
+ * between a spin mutex and an adaptive mutex for a rump
+ * kernel is that the hypervisor does not relinquish the
+ * rump kernel CPU context for a spin mutex. The
+ * hypervisor itself may block even when "spinning".
+ */
+ if (type == MUTEX_SPIN) {
+ isspin = 1;
+ } else if (ipl == IPL_NONE || ipl == IPL_SOFTCLOCK ||
+ ipl == IPL_SOFTBIO || ipl == IPL_SOFTNET ||
+ ipl == IPL_SOFTSERIAL) {
+ isspin = 0;
+ } else {
+ isspin = 1;
+ }
CTASSERT(sizeof(kmutex_t) >= sizeof(void *));
- rumpuser_mutex_init_kmutex((struct rumpuser_mtx **)mtx);
+ rumpuser_mutex_init_kmutex((struct rumpuser_mtx **)mtx, isspin);
ALLOCK(mtx, &mutex_lockops);
}
@@ -113,7 +132,15 @@
rumpuser_mutex_enter(RUMPMTX(mtx));
LOCKED(mtx, false);
}
-__strong_alias(mutex_spin_enter,mutex_enter);
+
+void
+mutex_spin_enter(kmutex_t *mtx)
+{
+
+ WANTLOCK(mtx, false, false);
+ rumpuser_mutex_enter_nowrap(RUMPMTX(mtx));
+ LOCKED(mtx, false);
+}
int
mutex_tryenter(kmutex_t *mtx)
diff -r d4df116b77ff -r 67d68beda2d3 sys/rump/librump/rumpkern/locks_up.c
--- a/sys/rump/librump/rumpkern/locks_up.c Sat Apr 27 13:25:09 2013 +0000
+++ b/sys/rump/librump/rumpkern/locks_up.c Sat Apr 27 13:59:46 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locks_up.c,v 1.6 2012/04/28 18:04:02 stacktic Exp $ */
+/* $NetBSD: locks_up.c,v 1.7 2013/04/27 13:59:46 pooka Exp $ */
/*
* Copyright (c) 2010 Antti Kantee. All Rights Reserved.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.6 2012/04/28 18:04:02 stacktic Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks_up.c,v 1.7 2013/04/27 13:59:46 pooka Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -71,6 +71,13 @@
checkncpu();
/*
+ * In uniprocessor locking we don't need to differentiate
+ * between spin mutexes and adaptive ones. We could
+ * replace mutex_enter() with a NOP for spin mutexes, but
+ * not bothering with that for now.
+ */
+
+ /*
* XXX: pool_cache would be nice, but not easily possible,
* as pool cache init wants to call mutex_init() ...
*/
Home |
Main Index |
Thread Index |
Old Index