Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Inform the rump kernel hypervisor of valid thread contexts so
details: https://anonhg.NetBSD.org/src/rev/807643a2799d
branches: trunk
changeset: 786584:807643a2799d
user: pooka <pooka%NetBSD.org@localhost>
date: Thu May 02 19:14:59 2013 +0000
description:
Inform the rump kernel hypervisor of valid thread contexts so
that the implementation can allocate and release storage for them
in an optimal fashion, if necessary.
diffstat:
lib/librumpuser/rumpuser.3 | 42 ++++++++-
lib/librumpuser/rumpuser_pth.c | 109 +++++++++++++++++++++++--
lib/librumpuser/rumpuser_pth_dummy.c | 17 ++-
sys/rump/include/machine/cpu.h | 6 +-
sys/rump/include/rump/rumpuser.h | 7 +-
sys/rump/librump/rumpkern/arch/i386/rumpcpu.c | 6 +-
sys/rump/librump/rumpkern/lwproc.c | 14 ++-
sys/rump/librump/rumpkern/rump.c | 11 +-
sys/rump/librump/rumpkern/scheduler.c | 17 ++-
sys/rump/librump/rumpkern/threads.c | 6 +-
10 files changed, 185 insertions(+), 50 deletions(-)
diffs (truncated from 534 to 300 lines):
diff -r 54ccedc28384 -r 807643a2799d lib/librumpuser/rumpuser.3
--- a/lib/librumpuser/rumpuser.3 Thu May 02 16:49:08 2013 +0000
+++ b/lib/librumpuser/rumpuser.3 Thu May 02 19:14:59 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: rumpuser.3,v 1.5 2013/05/02 15:32:19 pooka Exp $
+.\" $NetBSD: rumpuser.3,v 1.6 2013/05/02 19:14:59 pooka Exp $
.\"
.\" Copyright (c) 2013 Antti Kantee. All rights reserved.
.\"
@@ -450,25 +450,53 @@
.Fn rumpuser_thread_create .
.Pp
.Ft void
-.Fn rumpuser_set_curlwp "struct lwp *l"
+.Fn rumpuser_curlwpop "enum rumplwpop op" "struct lwp *l"
.Pp
+Manipulate the hypervisor's thread context database.
+The possible operations are create, destroy and set as specified by
+.Fa op :
+.Bl -tag -width "XRUMPUSER_LWP_DESTROY"
+.It Dv RUMPUSER_LWP_CREATE
+Inform the hypervisor that
+.Fa l
+is now a valid thread context which may be set.
+A currently valid value of
+.Fa l
+may not be specified.
+This operation is informational and does not mandate any action
+from the hypervisor.
+.It Dv RUMPUSER_LWP_DESTROY
+Inform the hypervisor that
+.Fa l
+is no longer a valid thread context.
+This means that it may no longer be set as the current context.
+A currently set context or an invalid one may not be destroyed.
+This operation is informational and does not mandate any action
+from the hypervisor.
+.It Dv RUMPUSER_LWP_SET
Set
.Fa l
-as the rump kernel thread context for the calling host thread.
+as the current host thread's rump kernel context.
The value
.Dv NULL
means that an existing rump kernel context (which must exist)
must be cleared.
+.El
.Pp
.Ft struct lwp *
-.Fn rumpuser_get_curlwp "void"
+.Fn rumpuser_curlwp "void"
.Pp
-Retrieve the rump kernel thread context previously set by
-.Fn rumpuser_set_curlwp .
-This routine can be called when a context does not exist and
+Retrieve the rump kernel thread context associated with the current host
+thread, as set by
+.Fn rumpuser_curlwpop .
+This routine may be called when a context is not set and
the routine must return
.Dv NULL
in that case.
+This interface is expected to be called very often.
+Any optimizations pertaining to the execution speed of this routine
+should be done in
+.Fn rumpuser_curlwpop .
.Pp
.Ft void
.Fn rumpuser_seterrno "int errno"
diff -r 54ccedc28384 -r 807643a2799d lib/librumpuser/rumpuser_pth.c
--- a/lib/librumpuser/rumpuser_pth.c Thu May 02 16:49:08 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth.c Thu May 02 19:14:59 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_pth.c,v 1.22 2013/05/02 16:49:08 pooka Exp $ */
+/* $NetBSD: rumpuser_pth.c,v 1.23 2013/05/02 19:14:59 pooka Exp $ */
/*
* Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
@@ -28,9 +28,11 @@
#include "rumpuser_port.h"
#if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth.c,v 1.22 2013/05/02 16:49:08 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth.c,v 1.23 2013/05/02 19:14:59 pooka Exp $");
#endif /* !lint */
+#include <sys/queue.h>
+
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
@@ -53,14 +55,14 @@
int flags;
};
-#define RURW_AMWRITER(rw) (rw->writer == rumpuser_get_curlwp() \
+#define RURW_AMWRITER(rw) (rw->writer == rumpuser_curlwp() \
&& rw->readers == -1)
#define RURW_HASREAD(rw) (rw->readers > 0)
#define RURW_SETWRITE(rw) \
do { \
assert(rw->readers == 0); \
- rw->writer = rumpuser_get_curlwp(); \
+ rw->writer = rumpuser_curlwp(); \
rw->readers = -1; \
} while (/*CONSTCOND*/0)
#define RURW_CLRWRITE(rw) \
@@ -193,7 +195,7 @@
return;
assert(mtx->owner == NULL);
- mtx->owner = rumpuser_get_curlwp();
+ mtx->owner = rumpuser_curlwp();
}
static void
@@ -460,17 +462,106 @@
* curlwp
*/
+/*
+ * the if0'd curlwp implementation is not used by this hypervisor,
+ * but serves as test code to check that the intended usage works.
+ */
+#if 0
+struct rumpuser_lwp {
+ struct lwp *l;
+ LIST_ENTRY(rumpuser_lwp) l_entries;
+};
+static LIST_HEAD(, rumpuser_lwp) lwps = LIST_HEAD_INITIALIZER(lwps);
+static pthread_mutex_t lwplock = PTHREAD_MUTEX_INITIALIZER;
+
void
-rumpuser_set_curlwp(struct lwp *l)
+rumpuser_curlwpop(enum rumplwpop op, struct lwp *l)
{
+ struct rumpuser_lwp *rl, *rliter;
- assert(pthread_getspecific(curlwpkey) == NULL || l == NULL);
- pthread_setspecific(curlwpkey, l);
+ switch (op) {
+ case RUMPUSER_LWP_CREATE:
+ rl = malloc(sizeof(*rl));
+ rl->l = l;
+ pthread_mutex_lock(&lwplock);
+ LIST_FOREACH(rliter, &lwps, l_entries) {
+ if (rliter->l == l) {
+ fprintf(stderr, "LWP_CREATE: %p exists\n", l);
+ abort();
+ }
+ }
+ LIST_INSERT_HEAD(&lwps, rl, l_entries);
+ pthread_mutex_unlock(&lwplock);
+ break;
+ case RUMPUSER_LWP_DESTROY:
+ pthread_mutex_lock(&lwplock);
+ LIST_FOREACH(rl, &lwps, l_entries) {
+ if (rl->l == l)
+ break;
+ }
+ if (!rl) {
+ fprintf(stderr, "LWP_DESTROY: %p does not exist\n", l);
+ abort();
+ }
+ LIST_REMOVE(rl, l_entries);
+ pthread_mutex_unlock(&lwplock);
+ free(rl);
+ break;
+ case RUMPUSER_LWP_SET:
+ assert(pthread_getspecific(curlwpkey) == NULL || l == NULL);
+
+ if (l) {
+ pthread_mutex_lock(&lwplock);
+ LIST_FOREACH(rl, &lwps, l_entries) {
+ if (rl->l == l)
+ break;
+ }
+ if (!rl) {
+ fprintf(stderr,
+ "LWP_SET: %p does not exist\n", l);
+ abort();
+ }
+ pthread_mutex_unlock(&lwplock);
+ } else {
+ rl = NULL;
+ }
+
+ pthread_setspecific(curlwpkey, rl);
+ break;
+ }
}
struct lwp *
-rumpuser_get_curlwp(void)
+rumpuser_curlwp(void)
+{
+ struct rumpuser_lwp *rl;
+
+ rl = pthread_getspecific(curlwpkey);
+ return rl ? rl->l : NULL;
+}
+
+#else
+
+void
+rumpuser_curlwpop(enum rumplwpop op, struct lwp *l)
+{
+
+ switch (op) {
+ case RUMPUSER_LWP_CREATE:
+ break;
+ case RUMPUSER_LWP_DESTROY:
+ break;
+ case RUMPUSER_LWP_SET:
+ assert(pthread_getspecific(curlwpkey) == NULL || l == NULL);
+ pthread_setspecific(curlwpkey, l);
+ break;
+ }
+}
+
+struct lwp *
+rumpuser_curlwp(void)
{
return pthread_getspecific(curlwpkey);
}
+#endif
diff -r 54ccedc28384 -r 807643a2799d lib/librumpuser/rumpuser_pth_dummy.c
--- a/lib/librumpuser/rumpuser_pth_dummy.c Thu May 02 16:49:08 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth_dummy.c Thu May 02 19:14:59 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_pth_dummy.c,v 1.12 2013/04/30 13:37:03 pooka Exp $ */
+/* $NetBSD: rumpuser_pth_dummy.c,v 1.13 2013/05/02 19:14:59 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.12 2013/04/30 13:37:03 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth_dummy.c,v 1.13 2013/05/02 19:14:59 pooka Exp $");
#endif /* !lint */
#include <sys/time.h>
@@ -283,14 +283,21 @@
*/
void
-rumpuser_set_curlwp(struct lwp *l)
+rumpuser_curlwpop(enum rumplwpop op, struct lwp *l)
{
- curlwp = l;
+ switch (op) {
+ case RUMPUSER_LWP_CREATE:
+ case RUMPUSER_LWP_DESTROY:
+ break;
+ case RUMPUSER_LWP_SET:
+ curlwp = l;
+ break;
+ }
}
struct lwp *
-rumpuser_get_curlwp(void)
+rumpuser_curlwp(void)
{
return curlwp;
diff -r 54ccedc28384 -r 807643a2799d sys/rump/include/machine/cpu.h
--- a/sys/rump/include/machine/cpu.h Thu May 02 16:49:08 2013 +0000
+++ b/sys/rump/include/machine/cpu.h Thu May 02 19:14:59 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.15 2011/03/21 16:41:08 pooka Exp $ */
+/* $NetBSD: cpu.h,v 1.16 2013/05/02 19:15:00 pooka Exp $ */
/*
* Copyright (c) 2008-2011 Antti Kantee. All Rights Reserved.
@@ -73,8 +73,8 @@
void __syncicache(void *, size_t);
#endif
-struct lwp *rumpuser_get_curlwp(void);
-#define curlwp rumpuser_get_curlwp()
+struct lwp *rumpuser_curlwp(void);
+#define curlwp rumpuser_curlwp()
#define curcpu() (curlwp->l_cpu)
#define cpu_number() (cpu_index(curcpu))
diff -r 54ccedc28384 -r 807643a2799d sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h Thu May 02 16:49:08 2013 +0000
+++ b/sys/rump/include/rump/rumpuser.h Thu May 02 19:14:59 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser.h,v 1.100 2013/04/30 16:03:44 pooka Exp $ */
+/* $NetBSD: rumpuser.h,v 1.101 2013/05/02 19:15:01 pooka Exp $ */
/*
* Copyright (c) 2007-2013 Antti Kantee. All Rights Reserved.
Home |
Main Index |
Thread Index |
Old Index