Module Name: src
Committed By: pooka
Date: Wed Apr 9 23:53:36 UTC 2014
Modified Files:
src/sys/rump/librump/rumpkern: lwproc.c rump.c rump_private.h
scheduler.c threads.c vm.c
Log Message:
implement lwp_create() and a few related interfaces.
main raison d'impalerment: the aio driver
To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.293 -r1.294 src/sys/rump/librump/rumpkern/rump.c
cvs rdiff -u -r1.80 -r1.81 src/sys/rump/librump/rumpkern/rump_private.h
cvs rdiff -u -r1.36 -r1.37 src/sys/rump/librump/rumpkern/scheduler.c
cvs rdiff -u -r1.22 -r1.23 src/sys/rump/librump/rumpkern/threads.c
cvs rdiff -u -r1.152 -r1.153 src/sys/rump/librump/rumpkern/vm.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/librump/rumpkern/lwproc.c
diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.28 src/sys/rump/librump/rumpkern/lwproc.c:1.29
--- src/sys/rump/librump/rumpkern/lwproc.c:1.28 Sun Mar 16 15:30:05 2014
+++ src/sys/rump/librump/rumpkern/lwproc.c Wed Apr 9 23:53:36 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: lwproc.c,v 1.28 2014/03/16 15:30:05 pooka Exp $ */
+/* $NetBSD: lwproc.c,v 1.29 2014/04/09 23:53:36 pooka Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -28,7 +28,7 @@
#define RUMP__CURLWP_PRIVATE
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.28 2014/03/16 15:30:05 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.29 2014/04/09 23:53:36 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -109,6 +109,7 @@ lwproc_proc_free(struct proc *p)
if (rump_proc_vfs_release)
rump_proc_vfs_release(p);
+ doexithooks(p);
lim_free(p->p_limit);
pstatsfree(p->p_stats);
kauth_cred_free(p->p_cred);
Index: src/sys/rump/librump/rumpkern/rump.c
diff -u src/sys/rump/librump/rumpkern/rump.c:1.293 src/sys/rump/librump/rumpkern/rump.c:1.294
--- src/sys/rump/librump/rumpkern/rump.c:1.293 Wed Apr 9 23:49:27 2014
+++ src/sys/rump/librump/rumpkern/rump.c Wed Apr 9 23:53:36 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: rump.c,v 1.293 2014/04/09 23:49:27 pooka Exp $ */
+/* $NetBSD: rump.c,v 1.294 2014/04/09 23:53:36 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.293 2014/04/09 23:49:27 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.294 2014/04/09 23:53:36 pooka Exp $");
#include <sys/systm.h>
#define ELFSIZE ARCH_ELFSIZE
@@ -382,7 +382,7 @@ rump_init(void)
}
/* CPUs are up. allow kernel threads to run */
- rump_thread_allow();
+ rump_thread_allow(NULL);
rnd_init_softint();
Index: src/sys/rump/librump/rumpkern/rump_private.h
diff -u src/sys/rump/librump/rumpkern/rump_private.h:1.80 src/sys/rump/librump/rumpkern/rump_private.h:1.81
--- src/sys/rump/librump/rumpkern/rump_private.h:1.80 Sat Mar 15 15:15:27 2014
+++ src/sys/rump/librump/rumpkern/rump_private.h Wed Apr 9 23:53:36 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: rump_private.h,v 1.80 2014/03/15 15:15:27 pooka Exp $ */
+/* $NetBSD: rump_private.h,v 1.81 2014/04/09 23:53:36 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -146,7 +146,7 @@ void rump_hyperfree(void *, size_t);
void rump_xc_highpri(struct cpu_info *);
void rump_thread_init(void);
-void rump_thread_allow(void);
+void rump_thread_allow(struct lwp *);
void rump_consdev_init(void);
Index: src/sys/rump/librump/rumpkern/scheduler.c
diff -u src/sys/rump/librump/rumpkern/scheduler.c:1.36 src/sys/rump/librump/rumpkern/scheduler.c:1.37
--- src/sys/rump/librump/rumpkern/scheduler.c:1.36 Sat Mar 15 15:15:27 2014
+++ src/sys/rump/librump/rumpkern/scheduler.c Wed Apr 9 23:53:36 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: scheduler.c,v 1.36 2014/03/15 15:15:27 pooka Exp $ */
+/* $NetBSD: scheduler.c,v 1.37 2014/04/09 23:53:36 pooka Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.36 2014/03/15 15:15:27 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.37 2014/04/09 23:53:36 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -539,3 +539,19 @@ sched_nice(struct proc *p, int level)
/* nothing to do for now */
}
+
+void
+sched_enqueue(struct lwp *l, bool swtch)
+{
+
+ if (swtch)
+ panic("sched_enqueue with switcheroo");
+ rump_thread_allow(l);
+}
+
+void
+sched_dequeue(struct lwp *l)
+{
+
+ panic("sched_dequeue not implemented");
+}
Index: src/sys/rump/librump/rumpkern/threads.c
diff -u src/sys/rump/librump/rumpkern/threads.c:1.22 src/sys/rump/librump/rumpkern/threads.c:1.23
--- src/sys/rump/librump/rumpkern/threads.c:1.22 Sat Mar 15 15:15:27 2014
+++ src/sys/rump/librump/rumpkern/threads.c Wed Apr 9 23:53:36 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: threads.c,v 1.22 2014/03/15 15:15:27 pooka Exp $ */
+/* $NetBSD: threads.c,v 1.23 2014/04/09 23:53:36 pooka Exp $ */
/*
* Copyright (c) 2007-2009 Antti Kantee. All Rights Reserved.
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.22 2014/03/15 15:15:27 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.23 2014/04/09 23:53:36 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -37,31 +37,36 @@ __KERNEL_RCSID(0, "$NetBSD: threads.c,v
#include <sys/kthread.h>
#include <sys/malloc.h>
#include <sys/systm.h>
+#include <sys/queue.h>
#include <rump/rumpuser.h>
#include "rump_private.h"
-struct kthdesc {
+struct thrdesc {
void (*f)(void *);
void *arg;
- struct lwp *mylwp;
+ struct lwp *newlwp;
+ int runnable;
+
+ TAILQ_ENTRY(thrdesc) entries;
};
static bool threads_are_go;
static struct rumpuser_mtx *thrmtx;
static struct rumpuser_cv *thrcv;
+static TAILQ_HEAD(, thrdesc) newthr;
static void *
threadbouncer(void *arg)
{
- struct kthdesc *k = arg;
- struct lwp *l = k->mylwp;
+ struct thrdesc *td = arg;
+ struct lwp *l = td->newlwp;
void (*f)(void *);
void *thrarg;
- f = k->f;
- thrarg = k->arg;
+ f = td->f;
+ thrarg = td->arg;
/* don't allow threads to run before all CPUs have fully attached */
if (!threads_are_go) {
@@ -77,7 +82,7 @@ threadbouncer(void *arg)
rump_schedule();
/* free dance struct */
- free(k, M_TEMP);
+ kmem_intr_free(td, sizeof(*td));
if ((curlwp->l_pflag & LP_MPSAFE) == 0)
KERNEL_LOCK(1, NULL);
@@ -93,17 +98,27 @@ rump_thread_init(void)
rumpuser_mutex_init(&thrmtx, RUMPUSER_MTX_SPIN);
rumpuser_cv_init(&thrcv);
+ TAILQ_INIT(&newthr);
}
void
-rump_thread_allow(void)
+rump_thread_allow(struct lwp *l)
{
+ struct thrdesc *td;
rumpuser_mutex_enter(thrmtx);
- threads_are_go = true;
+ if (l == NULL) {
+ threads_are_go = true;
+ } else {
+ TAILQ_FOREACH(td, &newthr, entries) {
+ if (td->newlwp == l) {
+ td->runnable = 1;
+ break;
+ }
+ }
+ }
rumpuser_cv_broadcast(thrcv);
rumpuser_mutex_exit(thrmtx);
-
}
static struct {
@@ -126,7 +141,7 @@ kthread_create(pri_t pri, int flags, str
char thrstore[MAXCOMLEN];
const char *thrname = NULL;
va_list ap;
- struct kthdesc *k;
+ struct thrdesc *td;
struct lwp *l;
int rv;
@@ -171,10 +186,14 @@ kthread_create(pri_t pri, int flags, str
}
KASSERT(fmt != NULL);
- k = malloc(sizeof(*k), M_TEMP, M_WAITOK);
- k->f = func;
- k->arg = arg;
- k->mylwp = l = rump__lwproc_alloclwp(&proc0);
+ /*
+ * Allocate with intr-safe allocator, give that we may be
+ * creating interrupt threads.
+ */
+ td = kmem_intr_alloc(sizeof(*td), KM_SLEEP);
+ td->f = func;
+ td->arg = arg;
+ td->newlwp = l = rump__lwproc_alloclwp(&proc0);
l->l_flag |= LW_SYSTEM;
if (flags & KTHREAD_MPSAFE)
l->l_pflag |= LP_MPSAFE;
@@ -189,11 +208,11 @@ kthread_create(pri_t pri, int flags, str
strlcpy(l->l_name, thrname, MAXCOMLEN);
}
- rv = rumpuser_thread_create(threadbouncer, k, thrname,
+ rv = rumpuser_thread_create(threadbouncer, td, thrname,
(flags & KTHREAD_MUSTJOIN) == KTHREAD_MUSTJOIN,
pri, ci ? ci->ci_index : -1, &l->l_ctxlink);
if (rv)
- return rv;
+ return rv; /* XXX */
if (newlp) {
*newlp = l;
@@ -227,3 +246,107 @@ kthread_join(struct lwp *l)
return rv;
}
+
+/*
+ * Create a non-kernel thread that is scheduled by a rump kernel hypercall.
+ *
+ * Sounds strange and out-of-place? yup yup yup. the original motivation
+ * for this was aio. This is a very infrequent code path in rump kernels.
+ * XXX: threads created with lwp_create() are eternal for local clients.
+ * however, they are correctly reaped for remote clients with process exit.
+ */
+static void *
+lwpbouncer(void *arg)
+{
+ struct thrdesc *td = arg;
+ struct lwp *l = td->newlwp;
+ void (*f)(void *);
+ void *thrarg;
+ int run;
+
+ f = td->f;
+ thrarg = td->arg;
+
+ /* do not run until we've been enqueued */
+ rumpuser_mutex_enter_nowrap(thrmtx);
+ while ((run = td->runnable) == 0) {
+ rumpuser_cv_wait_nowrap(thrcv, thrmtx);
+ }
+ rumpuser_mutex_exit(thrmtx);
+
+ /* schedule ourselves */
+ rump_lwproc_curlwp_set(l);
+ rump_schedule();
+ kmem_free(td, sizeof(*td));
+
+ /* should we just die instead? */
+ if (run == -1) {
+ rump_lwproc_releaselwp();
+ lwp_userret(l);
+ panic("lwpbouncer reached unreachable");
+ }
+
+ /* run, and don't come back! */
+ f(thrarg);
+ panic("lwp return from worker not supported");
+}
+
+int
+lwp_create(struct lwp *l1, struct proc *p2, vaddr_t uaddr, int flags,
+ void *stack, size_t stacksize, void (*func)(void *), void *arg,
+ struct lwp **newlwpp, int sclass)
+{
+ struct thrdesc *td;
+ struct lwp *l;
+ int rv;
+
+ if (flags)
+ panic("lwp_create: flags not supported by this implementation");
+ td = kmem_alloc(sizeof(*td), KM_SLEEP);
+ td->f = func;
+ td->arg = arg;
+ td->runnable = 0;
+ td->newlwp = l = rump__lwproc_alloclwp(p2);
+
+ rumpuser_mutex_enter_nowrap(thrmtx);
+ TAILQ_INSERT_TAIL(&newthr, td, entries);
+ rumpuser_mutex_exit(thrmtx);
+
+ rv = rumpuser_thread_create(lwpbouncer, td, p2->p_comm, 0,
+ PRI_USER, -1, NULL);
+ if (rv)
+ panic("rumpuser_thread_create failed"); /* XXX */
+
+ *newlwpp = l;
+ return 0;
+}
+
+void
+lwp_exit(struct lwp *l)
+{
+ struct thrdesc *td;
+
+ rumpuser_mutex_enter_nowrap(thrmtx);
+ TAILQ_FOREACH(td, &newthr, entries) {
+ if (td->newlwp == l) {
+ td->runnable = -1;
+ break;
+ }
+ }
+ rumpuser_mutex_exit(thrmtx);
+
+ if (td == NULL)
+ panic("lwp_exit: could not find %p\n", l);
+}
+
+void
+lwp_userret(struct lwp *l)
+{
+
+ if ((l->l_flag & LW_RUMP_QEXIT) == 0)
+ return;
+
+ /* ok, so we should die */
+ rump_unschedule();
+ rumpuser_thread_exit();
+}
Index: src/sys/rump/librump/rumpkern/vm.c
diff -u src/sys/rump/librump/rumpkern/vm.c:1.152 src/sys/rump/librump/rumpkern/vm.c:1.153
--- src/sys/rump/librump/rumpkern/vm.c:1.152 Tue Mar 11 20:32:05 2014
+++ src/sys/rump/librump/rumpkern/vm.c Wed Apr 9 23:53:36 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: vm.c,v 1.152 2014/03/11 20:32:05 pooka Exp $ */
+/* $NetBSD: vm.c,v 1.153 2014/04/09 23:53:36 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.152 2014/03/11 20:32:05 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.153 2014/04/09 23:53:36 pooka Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -911,6 +911,21 @@ uvm_vm_page_to_phys(const struct vm_page
return 0;
}
+vaddr_t
+uvm_uarea_alloc(void)
+{
+
+ /* non-zero */
+ return (vaddr_t)11;
+}
+
+void
+uvm_uarea_free(vaddr_t uarea)
+{
+
+ /* nata, so creamy */
+}
+
/*
* Routines related to the Page Baroness.
*/