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 lwp usage some much-needed lo...



details:   https://anonhg.NetBSD.org/src/rev/9b4c07d10653
branches:  trunk
changeset: 748179:9b4c07d10653
user:      pooka <pooka%NetBSD.org@localhost>
date:      Thu Oct 15 16:39:22 2009 +0000

description:
Give lwp usage some much-needed love: stop treating lwp0 as the
all-sink and make sure each separate thread in rump has its own
lwp.  Happy-go-lucky callers will get scheduled a temporary lwp
on entry, while true lwp connoisseurs may request a stable lwp
for their purposes.  Some more love may be required later down the
road, but for now different threads will stepping on each others
toes.

diffstat:

 sys/rump/librump/rumpkern/arch/i386/rumpcpu.c |    6 +-
 sys/rump/librump/rumpkern/emul.c              |    8 +-
 sys/rump/librump/rumpkern/locks.c             |   14 +-
 sys/rump/librump/rumpkern/rump.c              |  136 +++++++++++++------------
 sys/rump/librump/rumpkern/rump_private.h      |    6 +-
 sys/rump/librump/rumpkern/rumpkern.ifspec     |   13 +-
 sys/rump/librump/rumpkern/scheduler.c         |   42 ++++++-
 sys/rump/librump/rumpkern/sysproxy_socket.c   |   12 +-
 8 files changed, 137 insertions(+), 100 deletions(-)

diffs (truncated from 492 to 300 lines):

diff -r 6534c2dc778c -r 9b4c07d10653 sys/rump/librump/rumpkern/arch/i386/rumpcpu.c
--- a/sys/rump/librump/rumpkern/arch/i386/rumpcpu.c     Thu Oct 15 13:01:24 2009 +0000
+++ b/sys/rump/librump/rumpkern/arch/i386/rumpcpu.c     Thu Oct 15 16:39:22 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpcpu.c,v 1.6 2009/10/15 00:28:47 pooka Exp $        */
+/*     $NetBSD: rumpcpu.c,v 1.7 2009/10/15 16:39:22 pooka Exp $        */
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rumpcpu.c,v 1.6 2009/10/15 00:28:47 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rumpcpu.c,v 1.7 2009/10/15 16:39:22 pooka Exp $");
 
 #include <sys/param.h>
 
@@ -57,7 +57,7 @@
 x86_curlwp()
 {
 
-       return rump_get_curlwp();
+       return rumpuser_get_curlwp();
 }
 
 void
diff -r 6534c2dc778c -r 9b4c07d10653 sys/rump/librump/rumpkern/emul.c
--- a/sys/rump/librump/rumpkern/emul.c  Thu Oct 15 13:01:24 2009 +0000
+++ b/sys/rump/librump/rumpkern/emul.c  Thu Oct 15 16:39:22 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: emul.c,v 1.101 2009/10/15 00:28:46 pooka Exp $ */
+/*     $NetBSD: emul.c,v 1.102 2009/10/15 16:39:22 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.101 2009/10/15 00:28:46 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.102 2009/10/15 16:39:22 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/malloc.h>
@@ -442,7 +442,7 @@
        k = kmem_alloc(sizeof(struct kthdesc), KM_SLEEP);
        k->f = func;
        k->arg = arg;
-       k->mylwp = l = rump_setup_curlwp(0, rump_nextlid(), 0);
+       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);
@@ -460,7 +460,7 @@
 
        if ((curlwp->l_pflag & LP_MPSAFE) == 0)
                KERNEL_UNLOCK_ONE(NULL);
-       rump_clear_curlwp();
+       rump_lwp_release(curlwp);
        rump_unschedule();
        rumpuser_thread_exit();
 }
diff -r 6534c2dc778c -r 9b4c07d10653 sys/rump/librump/rumpkern/locks.c
--- a/sys/rump/librump/rumpkern/locks.c Thu Oct 15 13:01:24 2009 +0000
+++ b/sys/rump/librump/rumpkern/locks.c Thu Oct 15 16:39:22 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locks.c,v 1.29 2009/10/15 00:28:46 pooka Exp $ */
+/*     $NetBSD: locks.c,v 1.30 2009/10/15 16:39:22 pooka Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.29 2009/10/15 00:28:46 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locks.c,v 1.30 2009/10/15 16:39:22 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -343,9 +343,11 @@
 
        while (nlocks--) {
                if (!rumpuser_mutex_tryenter(rump_giantlock)) {
-                       rump_unschedule();
+                       struct lwp *l = curlwp;
+
+                       rump_unschedule_cpu(l);
                        rumpuser_mutex_enter_nowrap(rump_giantlock);
-                       rump_schedule();
+                       rump_schedule_cpu(l);
                }
                lockcnt++;
        }
@@ -382,14 +384,14 @@
 {
 
        _kernel_unlock(nlocks, countp);
-       rump_unschedule();
+       rump_unschedule_cpu(curlwp);
 }
 
 void
 rump_user_schedule(int nlocks)
 {
 
-       rump_schedule();
+       rump_schedule_cpu(curlwp);
 
        if (nlocks)
                _kernel_lock(nlocks);
diff -r 6534c2dc778c -r 9b4c07d10653 sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c  Thu Oct 15 13:01:24 2009 +0000
+++ b/sys/rump/librump/rumpkern/rump.c  Thu Oct 15 16:39:22 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump.c,v 1.124 2009/10/15 00:28:46 pooka Exp $ */
+/*     $NetBSD: rump.c,v 1.125 2009/10/15 16:39:22 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.124 2009/10/15 00:28:46 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.125 2009/10/15 16:39:22 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -388,34 +388,43 @@
        return resid;
 }
 
-/* public interface */
 static pid_t nextpid = 1;
 struct lwp *
 rump_newproc_switch()
 {
-       struct lwp *oldlwp = curlwp;
+       struct lwp *l;
        pid_t mypid;
 
        mypid = atomic_inc_uint_nv(&nextpid);
        if (__predict_false(mypid == 0))
                mypid = atomic_inc_uint_nv(&nextpid);
 
-       rumpuser_set_curlwp(NULL);
-       rump_setup_curlwp(mypid, 0, 1);
+       l = rump_lwp_alloc(mypid, 0);
+       rump_lwp_switch(l);
 
-       return oldlwp;
+       return l;
 }
 
-/* rump private */
 struct lwp *
-rump_setup_curlwp(pid_t pid, lwpid_t lid, int set)
+rump_lwp_alloc_and_switch(pid_t pid, lwpid_t lid)
+{
+       struct lwp *l;
+
+       l = rump_lwp_alloc(pid, lid);
+       rump_lwp_switch(l);
+
+       return l;
+}
+
+struct lwp *
+rump_lwp_alloc(pid_t pid, lwpid_t lid)
 {
        struct lwp *l;
        struct proc *p;
 
-       l = kmem_zalloc(sizeof(struct lwp), KM_SLEEP);
+       l = kmem_zalloc(sizeof(*l), KM_SLEEP);
        if (pid != 0) {
-               p = kmem_zalloc(sizeof(struct proc), KM_SLEEP);
+               p = kmem_zalloc(sizeof(*p), KM_SLEEP);
                rump_proc_vfs_init(p);
                p->p_stats = &rump_stats;
                p->p_limit = &rump_limits;
@@ -431,18 +440,60 @@
        l->l_proc = p;
        l->l_lid = lid;
        l->l_fd = p->p_fd;
-       l->l_mutex = RUMP_LMUTEX_MAGIC;
+       l->l_mutex = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NONE);
        l->l_cpu = NULL;
 
-       /* give current cpu to new lwp */
-       if (set) {
-               struct cpu_info *saveci = curlwp->l_cpu;
+       return l;
+}
+
+void
+rump_lwp_switch(struct lwp *newlwp)
+{
+       struct lwp *l = curlwp;
+
+       rumpuser_set_curlwp(NULL);
+       newlwp->l_cpu = l->l_cpu;
+       rumpuser_set_curlwp(newlwp);
+       if (l->l_flag & LW_WEXIT)
+               rump_lwp_free(l);
+}
+
+/* XXX: this has effect only on non-pid0 lwps */
+void
+rump_lwp_release(struct lwp *l)
+{
+       struct proc *p;
 
-               curlwp->l_cpu = NULL;
-               rumpuser_set_curlwp(l);
-               curlwp->l_cpu = saveci;
+       p = l->l_proc;
+       if (p->p_pid != 0) {
+               mutex_obj_free(p->p_lock);
+               fd_free();
+               rump_proc_vfs_release(p);
+               rump_cred_put(l->l_cred);
+               kmem_free(p, sizeof(*p));
        }
+       KASSERT((l->l_flag & LW_WEXIT) == 0);
+       l->l_flag |= LW_WEXIT;
+}
 
+void
+rump_lwp_free(struct lwp *l)
+{
+
+       KASSERT(l->l_flag & LW_WEXIT);
+       KASSERT(l != rumpuser_get_curlwp());
+       rump_cred_put(l->l_cred);
+       mutex_obj_free(l->l_mutex);
+       kmem_free(l, sizeof(*l));
+}
+
+struct lwp *
+rump_lwp_curlwp(void)
+{
+       struct lwp *l = curlwp;
+
+       if (l->l_flag & LW_WEXIT)
+               return NULL;
        return l;
 }
 
@@ -455,53 +506,6 @@
        p->p_vmspace = vm;
 }
 
-void
-rump_clear_curlwp(void)
-{
-       struct cpu_info *ci;
-       struct lwp *l;
-       struct proc *p;
-
-       l = rumpuser_get_curlwp();
-       ci = l->l_cpu;
-       KASSERT(ci);
-       p = l->l_proc;
-       if (p->p_pid != 0) {
-               mutex_obj_free(p->p_lock);
-               fd_free();
-               rump_proc_vfs_release(p);
-               rump_cred_put(l->l_cred);
-               kmem_free(p, sizeof(*p));
-       }
-       kmem_free(l, sizeof(*l));
-
-       /* lwp0 inherits current cpu.  quite XXX */
-       rumpuser_set_curlwp(NULL);
-       lwp0.l_cpu = ci; 
-}
-
-struct lwp *
-rump_get_curlwp(void)
-{
-       struct lwp *l;
-
-       l = rumpuser_get_curlwp();
-       if (l == NULL)
-               l = &lwp0;
-
-       return l;
-}
-
-void
-rump_set_curlwp(struct lwp *l)
-{
-
-       /* clear current */
-       rumpuser_set_curlwp(NULL);
-       /* set new */
-       rumpuser_set_curlwp(l);



Home | Main Index | Thread Index | Old Index