Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump/librump/rumpkern Give the kthread->pthread interfac...
details: https://anonhg.NetBSD.org/src/rev/8758a8e7f70f
branches: trunk
changeset: 748759:8758a8e7f70f
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Nov 04 19:17:53 2009 +0000
description:
Give the kthread->pthread interface emulation its own module.
diffstat:
sys/rump/librump/rumpkern/Makefile.rumpkern | 4 +-
sys/rump/librump/rumpkern/emul.c | 116 +---------------------
sys/rump/librump/rumpkern/threads.c | 152 ++++++++++++++++++++++++++++
3 files changed, 156 insertions(+), 116 deletions(-)
diffs (truncated from 325 to 300 lines):
diff -r 4947b0485772 -r 8758a8e7f70f sys/rump/librump/rumpkern/Makefile.rumpkern
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern Wed Nov 04 19:02:28 2009 +0000
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern Wed Nov 04 19:17:53 2009 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.rumpkern,v 1.60 2009/11/04 18:25:36 pooka Exp $
+# $NetBSD: Makefile.rumpkern,v 1.61 2009/11/04 19:17:53 pooka Exp $
#
.include "${RUMPTOP}/Makefile.rump"
@@ -17,7 +17,7 @@
#
SRCS= rump.c rumpcopy.c emul.c intr.c locks.c ltsleep.c \
memalloc.c percpu.c scheduler.c sleepq.c \
- sysproxy_socket.c vm.c
+ sysproxy_socket.c threads.c vm.c
# stubs
#
diff -r 4947b0485772 -r 8758a8e7f70f sys/rump/librump/rumpkern/emul.c
--- a/sys/rump/librump/rumpkern/emul.c Wed Nov 04 19:02:28 2009 +0000
+++ b/sys/rump/librump/rumpkern/emul.c Wed Nov 04 19:17:53 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emul.c,v 1.107 2009/11/04 18:25:36 pooka Exp $ */
+/* $NetBSD: emul.c,v 1.108 2009/11/04 19:17:53 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.107 2009/11/04 18:25:36 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.108 2009/11/04 19:17:53 pooka Exp $");
#include <sys/param.h>
#include <sys/null.h>
@@ -43,7 +43,6 @@
#include <sys/queue.h>
#include <sys/file.h>
#include <sys/filedesc.h>
-#include <sys/kthread.h>
#include <sys/cpu.h>
#include <sys/kmem.h>
#include <sys/poll.h>
@@ -55,8 +54,6 @@
#include <dev/cons.h>
-#include <machine/stdarg.h>
-
#include <rump/rumpuser.h>
#include <uvm/uvm_map.h>
@@ -193,115 +190,6 @@
microtime(tv);
}
-struct kthdesc {
- void (*f)(void *);
- void *arg;
- struct lwp *mylwp;
-};
-
-static void *
-threadbouncer(void *arg)
-{
- struct kthdesc *k = arg;
- void (*f)(void *);
- void *thrarg;
-
- /* schedule ourselves first */
- f = k->f;
- thrarg = k->arg;
- rumpuser_set_curlwp(k->mylwp);
- rump_schedule();
-
- kmem_free(k, sizeof(struct kthdesc));
- if ((curlwp->l_pflag & LP_MPSAFE) == 0)
- KERNEL_LOCK(1, NULL);
-
- f(thrarg);
-
- panic("unreachable, should kthread_exit()");
-}
-
-int
-kthread_create(pri_t pri, int flags, struct cpu_info *ci,
- void (*func)(void *), void *arg, lwp_t **newlp, const char *fmt, ...)
-{
- char thrstore[MAXCOMLEN];
- const char *thrname = NULL;
- va_list ap;
- struct kthdesc *k;
- struct lwp *l;
- int rv;
-
- thrstore[0] = '\0';
- if (fmt) {
- va_start(ap, fmt);
- vsnprintf(thrstore, sizeof(thrstore), fmt, ap);
- va_end(ap);
- thrname = thrstore;
- }
-
- /*
- * We don't want a module unload thread.
- * (XXX: yes, this is a kludge too, and the kernel should
- * have a more flexible method for configuring which threads
- * we want).
- */
- if (strcmp(thrstore, "modunload") == 0) {
- return 0;
- }
-
- if (!rump_threads) {
- /* fake them */
- if (strcmp(thrstore, "vrele") == 0) {
- printf("rump warning: threads not enabled, not starting"
- " vrele thread\n");
- return 0;
- } else if (strcmp(thrstore, "cachegc") == 0) {
- printf("rump warning: threads not enabled, not starting"
- " namecache g/c thread\n");
- return 0;
- } else if (strcmp(thrstore, "nfssilly") == 0) {
- printf("rump warning: threads not enabled, not enabling"
- " nfs silly rename\n");
- return 0;
- } else if (strcmp(thrstore, "unpgc") == 0) {
- printf("rump warning: threads not enabled, not enabling"
- " UNP garbage collection\n");
- return 0;
- } else
- panic("threads not available, setenv RUMP_THREADS 1");
- }
-
- KASSERT(fmt != NULL);
- if (ci != NULL)
- panic("%s: bounded threads not supported", __func__);
-
- k = kmem_alloc(sizeof(struct kthdesc), KM_SLEEP);
- k->f = func;
- k->arg = arg;
- k->mylwp = l = rump_lwp_alloc(0, rump_nextlid());
- if (flags & KTHREAD_MPSAFE)
- l->l_pflag |= LP_MPSAFE;
- rv = rumpuser_thread_create(threadbouncer, k, thrname);
- if (rv)
- return rv;
-
- if (newlp)
- *newlp = l;
- return 0;
-}
-
-void
-kthread_exit(int ecode)
-{
-
- if ((curlwp->l_pflag & LP_MPSAFE) == 0)
- KERNEL_UNLOCK_ONE(NULL);
- rump_lwp_release(curlwp);
- rump_unschedule();
- rumpuser_thread_exit();
-}
-
struct proc *
p_find(pid_t pid, uint flags)
{
diff -r 4947b0485772 -r 8758a8e7f70f sys/rump/librump/rumpkern/threads.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/librump/rumpkern/threads.c Wed Nov 04 19:17:53 2009 +0000
@@ -0,0 +1,152 @@
+/* $NetBSD: threads.c,v 1.1 2009/11/04 19:17:53 pooka Exp $ */
+
+/*
+ * Copyright (c) 2007-2009 Antti Kantee. All Rights Reserved.
+ *
+ * Development of this software was supported by
+ * The Finnish Cultural Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.1 2009/11/04 19:17:53 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/kmem.h>
+#include <sys/kthread.h>
+#include <sys/systm.h>
+
+#include <machine/stdarg.h>
+
+#include <rump/rumpuser.h>
+
+#include "rump_private.h"
+
+struct kthdesc {
+ void (*f)(void *);
+ void *arg;
+ struct lwp *mylwp;
+};
+
+static void *
+threadbouncer(void *arg)
+{
+ struct kthdesc *k = arg;
+ void (*f)(void *);
+ void *thrarg;
+
+ /* schedule ourselves first */
+ f = k->f;
+ thrarg = k->arg;
+ rumpuser_set_curlwp(k->mylwp);
+ rump_schedule();
+
+ kmem_free(k, sizeof(struct kthdesc));
+ if ((curlwp->l_pflag & LP_MPSAFE) == 0)
+ KERNEL_LOCK(1, NULL);
+
+ f(thrarg);
+
+ panic("unreachable, should kthread_exit()");
+}
+
+int
+kthread_create(pri_t pri, int flags, struct cpu_info *ci,
+ void (*func)(void *), void *arg, lwp_t **newlp, const char *fmt, ...)
+{
+ char thrstore[MAXCOMLEN];
+ const char *thrname = NULL;
+ va_list ap;
+ struct kthdesc *k;
+ struct lwp *l;
+ int rv;
+
+ thrstore[0] = '\0';
+ if (fmt) {
+ va_start(ap, fmt);
+ vsnprintf(thrstore, sizeof(thrstore), fmt, ap);
+ va_end(ap);
+ thrname = thrstore;
+ }
+
+ /*
+ * We don't want a module unload thread.
+ * (XXX: yes, this is a kludge too, and the kernel should
+ * have a more flexible method for configuring which threads
+ * we want).
+ */
+ if (strcmp(thrstore, "modunload") == 0) {
+ return 0;
+ }
+
+ if (!rump_threads) {
+ /* fake them */
+ if (strcmp(thrstore, "vrele") == 0) {
+ printf("rump warning: threads not enabled, not starting"
+ " vrele thread\n");
+ return 0;
+ } else if (strcmp(thrstore, "cachegc") == 0) {
+ printf("rump warning: threads not enabled, not starting"
+ " namecache g/c thread\n");
+ return 0;
+ } else if (strcmp(thrstore, "nfssilly") == 0) {
+ printf("rump warning: threads not enabled, not enabling"
+ " nfs silly rename\n");
+ return 0;
+ } else if (strcmp(thrstore, "unpgc") == 0) {
+ printf("rump warning: threads not enabled, not enabling"
+ " UNP garbage collection\n");
+ return 0;
+ } else
+ panic("threads not available, setenv RUMP_THREADS 1");
+ }
+
+ KASSERT(fmt != NULL);
+ if (ci != NULL)
+ panic("%s: bounded threads not supported", __func__);
+
Home |
Main Index |
Thread Index |
Old Index