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 Use subr_percpu.c instead of homeg...



details:   https://anonhg.NetBSD.org/src/rev/abb62aedfe2d
branches:  trunk
changeset: 750814:abb62aedfe2d
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Jan 15 19:01:04 2010 +0000

description:
Use subr_percpu.c instead of homegrown implementation.  ...except
when using malloc(3)-relegated allocators (happens in production
e.g. on Linux), since subr_percpu.c uses vmem and i don't want to
reimplement vmem.

diffstat:

 sys/rump/librump/rumpkern/Makefile.rumpkern |   8 +-
 sys/rump/librump/rumpkern/emul.c            |  20 +++++-
 sys/rump/librump/rumpkern/memalloc.c        |  65 +++++++++++++++++++++-
 sys/rump/librump/rumpkern/percpu.c          |  87 -----------------------------
 sys/rump/librump/rumpkern/rump.c            |   8 +-
 5 files changed, 87 insertions(+), 101 deletions(-)

diffs (truncated from 307 to 300 lines):

diff -r 13492c488db2 -r abb62aedfe2d sys/rump/librump/rumpkern/Makefile.rumpkern
--- a/sys/rump/librump/rumpkern/Makefile.rumpkern       Fri Jan 15 18:38:16 2010 +0000
+++ b/sys/rump/librump/rumpkern/Makefile.rumpkern       Fri Jan 15 19:01:04 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.rumpkern,v 1.70 2009/12/16 21:25:55 pooka Exp $
+#      $NetBSD: Makefile.rumpkern,v 1.71 2010/01/15 19:01:04 pooka Exp $
 #
 
 .include "${RUMPTOP}/Makefile.rump"
@@ -16,8 +16,8 @@
 # Source modules, first the ones specifically implemented for librump.
 # 
 SRCS=  rump.c rumpcopy.c emul.c intr.c locks.c ltsleep.c       \
-       memalloc.c percpu.c scheduler.c sleepq.c                \
-       sysproxy_socket.c threads.c vm.c
+       memalloc.c scheduler.c sleepq.c sysproxy_socket.c       \
+       threads.c vm.c
 
 vers.c: ${RUMPTOP}/../conf/newvers.sh ${RUMPTOP}/../conf/osrelease.sh
        ${_MKMSG_CREATE} vers.c
@@ -69,7 +69,7 @@
 # corner cases as well (not to mention if you want to debug the
 # allocators themselves).
 #CPPFLAGS+=    -DRUMP_USE_UNREAL_ALLOCATORS
-SRCS+=         subr_kmem.c subr_pool.c subr_vmem.c
+SRCS+=         subr_kmem.c subr_percpu.c subr_pool.c subr_vmem.c
 
 # no shlib_version because this is automatically in sync with lib/librump
 SHLIB_MAJOR=    0
diff -r 13492c488db2 -r abb62aedfe2d sys/rump/librump/rumpkern/emul.c
--- a/sys/rump/librump/rumpkern/emul.c  Fri Jan 15 18:38:16 2010 +0000
+++ b/sys/rump/librump/rumpkern/emul.c  Fri Jan 15 19:01:04 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: emul.c,v 1.118 2010/01/13 01:53:38 pooka Exp $ */
+/*     $NetBSD: emul.c,v 1.119 2010/01/15 19:01:04 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.118 2010/01/13 01:53:38 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.119 2010/01/15 19:01:04 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/null.h>
@@ -384,11 +384,22 @@
 }
 void (*delay_func)(unsigned int) = rump_delay;
 
+bool
+kpreempt(uintptr_t where)
+{
+
+       return false;
+}
+
+/*
+ * There is no kernel thread preemption in rump currently.  But call
+ * the implementing macros anyway in case they grow some side-effects
+ * down the road.
+ */
 void
 kpreempt_disable(void)
 {
 
-       /* XXX: see below */
        KPREEMPT_DISABLE(curlwp);
 }
 
@@ -396,8 +407,7 @@
 kpreempt_enable(void)
 {
 
-       /* try to make sure kpreempt_disable() is only used from panic() */
-       panic("kpreempt not supported");
+       KPREEMPT_ENABLE(curlwp);
 }
 
 void
diff -r 13492c488db2 -r abb62aedfe2d sys/rump/librump/rumpkern/memalloc.c
--- a/sys/rump/librump/rumpkern/memalloc.c      Fri Jan 15 18:38:16 2010 +0000
+++ b/sys/rump/librump/rumpkern/memalloc.c      Fri Jan 15 19:01:04 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: memalloc.c,v 1.4 2010/01/11 19:19:57 stacktic Exp $    */
+/*     $NetBSD: memalloc.c,v 1.5 2010/01/15 19:01:04 pooka Exp $       */
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -26,16 +26,19 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: memalloc.c,v 1.4 2010/01/11 19:19:57 stacktic Exp $");
+__KERNEL_RCSID(0, "$NetBSD: memalloc.c,v 1.5 2010/01/15 19:01:04 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
 #include <sys/malloc.h>
+#include <sys/percpu.h>
 #include <sys/pool.h>
 #include <sys/vmem.h>
 
 #include <rump/rumpuser.h>
 
+#include "rump_private.h"
+
 /*
  * Allocator "implementations" which relegate tasks to the host
  * libc malloc.
@@ -325,4 +328,62 @@
 
        return;
 }
+
+/*
+ * A simplified percpu is included in here since subr_percpu.c uses
+ * the vmem allocator and I don't want to reimplement vmem.  So use
+ * this simplified percpu for non-vmem systems.
+ */
+
+static kmutex_t pcmtx;
+
+void
+percpu_init(void)
+{
+
+       mutex_init(&pcmtx, MUTEX_DEFAULT, IPL_NONE);
+}
+
+void
+percpu_init_cpu(struct cpu_info *ci)
+{
+
+       /* nada */
+}
+
+void *
+percpu_getref(percpu_t *pc)
+{
+
+       mutex_enter(&pcmtx);
+       return pc;
+}
+
+void
+percpu_putref(percpu_t *pc)
+{
+
+       mutex_exit(&pcmtx);
+}
+
+percpu_t *
+percpu_alloc(size_t size)
+{
+
+       return kmem_alloc(size, KM_SLEEP);
+}
+
+void
+percpu_free(percpu_t *pc, size_t size)
+{
+
+       kmem_free(pc, size);
+}
+
+void
+percpu_foreach(percpu_t *pc, percpu_callback_t cb, void *arg)
+{
+
+       cb(pc, arg, rump_cpu);
+}
 #endif /* RUMP_USE_UNREAL_ALLOCATORS */
diff -r 13492c488db2 -r abb62aedfe2d sys/rump/librump/rumpkern/percpu.c
--- a/sys/rump/librump/rumpkern/percpu.c        Fri Jan 15 18:38:16 2010 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-/*     $NetBSD: percpu.c,v 1.6 2009/10/15 00:28:46 pooka Exp $ */
-
-/*
- * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
- *
- * 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: percpu.c,v 1.6 2009/10/15 00:28:46 pooka Exp $");
-
-#include <sys/param.h>
-#include <sys/kmem.h>
-#include <sys/mutex.h>
-#include <sys/percpu.h>
-
-#include "rump_private.h"
-
-/*
- * A poor-man's userspace percpu emulation.  Since we can't disable
- * preemption currently, use a mutex.  Not the world's most efficient
- * method, but quite enough.  Hence, we can have only one cpu.
- */
-
-static kmutex_t pcmtx;
-
-void
-percpu_init(void)
-{
-
-       mutex_init(&pcmtx, MUTEX_DEFAULT, IPL_NONE);
-}
-
-void *
-percpu_getref(percpu_t *pc)
-{
-
-       mutex_enter(&pcmtx);
-       return pc;
-}
-
-void
-percpu_putref(percpu_t *pc)
-{
-
-       mutex_exit(&pcmtx);
-}
-
-percpu_t *
-percpu_alloc(size_t size)
-{
-
-       return kmem_alloc(size, KM_SLEEP);
-}
-
-void
-percpu_free(percpu_t *pc, size_t size)
-{
-
-       kmem_free(pc, size);
-}
-
-void
-percpu_foreach(percpu_t *pc, percpu_callback_t cb, void *arg)
-{
-
-       cb(pc, arg, rump_cpu);
-}
diff -r 13492c488db2 -r abb62aedfe2d sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Fri Jan 15 18:38:16 2010 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Fri Jan 15 19:01:04 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.149 2010/01/13 00:07:40 pooka Exp $ */
+/*     $NetBSD: rump.c,v 1.150 2010/01/15 19:01:04 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.149 2010/01/13 00:07:40 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.150 2010/01/15 19:01:04 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -270,6 +270,8 @@
        rumpuser_set_curlwp(NULL);
        rump_schedule();
 
+       percpu_init();
+
        /* we are mostly go.  do per-cpu subsystem init */
        for (i = 0; i < ncpu; i++) {
                struct cpu_info *ci = cpu_lookup(i);
@@ -279,13 +281,13 @@
                xc_init_cpu(ci);
                pool_cache_cpu_init(ci);
                selsysinit(ci);
+               percpu_init_cpu(ci);
        }
 
        sysctl_init();



Home | Main Index | Thread Index | Old Index