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 Enable holding implicit threads ov...



details:   https://anonhg.NetBSD.org/src/rev/f7d5865c170a
branches:  trunk
changeset: 790951:f7d5865c170a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Oct 27 20:25:45 2013 +0000

description:
Enable holding implicit threads over explicit scheduling points (i.e.
a kernel driver calling rump_lwproc_switch()).  Also, correctly handle
curcpu()->ci_curlwp and biglock there.

diffstat:

 sys/rump/librump/rumpkern/lwproc.c       |  47 +++++++++++++++++++++++++------
 sys/rump/librump/rumpkern/rump_private.h |   4 ++-
 2 files changed, 40 insertions(+), 11 deletions(-)

diffs (115 lines):

diff -r 2a0003c204f7 -r f7d5865c170a sys/rump/librump/rumpkern/lwproc.c
--- a/sys/rump/librump/rumpkern/lwproc.c        Sun Oct 27 18:30:49 2013 +0000
+++ b/sys/rump/librump/rumpkern/lwproc.c        Sun Oct 27 20:25:45 2013 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: lwproc.c,v 1.23 2013/05/15 14:07:26 pooka Exp $       */
+/*      $NetBSD: lwproc.c,v 1.24 2013/10/27 20:25:45 pooka Exp $       */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.23 2013/05/15 14:07:26 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.24 2013/10/27 20:25:45 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -185,7 +185,6 @@
        p = l->l_proc;
        mutex_enter(p->p_lock);
 
-       /* XXX: l_refcnt */
        KASSERT(l->l_flag & LW_WEXIT);
        KASSERT(l->l_refcnt == 0);
 
@@ -352,6 +351,7 @@
                fd_free();
        }
 
+       KERNEL_UNLOCK_ALL(NULL, &l->l_biglocks);
        rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, l);
 
        newlwp->l_cpu = newlwp->l_target_cpu = l->l_cpu;
@@ -359,6 +359,8 @@
        newlwp->l_pflag |= LP_RUNNING;
 
        rumpuser_curlwpop(RUMPUSER_LWP_SET, newlwp);
+       curcpu()->ci_curlwp = newlwp;
+       KERNEL_LOCK(newlwp->l_biglocks, NULL);
 
        /*
         * Check if the thread should get a signal.  This is
@@ -380,21 +382,46 @@
        }
 }
 
+/*
+ * Mark the current thread to be released upon return from
+ * kernel.
+ */
 void
 rump_lwproc_releaselwp(void)
 {
-       struct proc *p;
        struct lwp *l = curlwp;
 
-       if (l->l_refcnt == 0 && l->l_flag & LW_WEXIT)
+       if (l->l_refcnt == 0 || l->l_flag & LW_WEXIT)
                panic("releasing non-pertinent lwp");
 
-       p = l->l_proc;
-       mutex_enter(p->p_lock);
-       KASSERT(l->l_refcnt != 0);
+       rump__lwproc_lwprele();
+       KASSERT(l->l_refcnt == 0 && (l->l_flag & LW_WEXIT));
+}
+
+/*
+ * In-kernel routines used to add and remove references for the
+ * current thread.  The main purpose is to make it possible for
+ * implicit threads to persist over scheduling operations in
+ * rump kernel drivers.  Note that we don't need p_lock in a
+ * rump kernel, since we do refcounting only for curlwp.
+ */
+void
+rump__lwproc_lwphold(void)
+{
+       struct lwp *l = curlwp;
+
+       l->l_refcnt++;
+       l->l_flag &= ~LW_WEXIT;
+}
+
+void
+rump__lwproc_lwprele(void)
+{
+       struct lwp *l = curlwp;
+
        l->l_refcnt--;
-       mutex_exit(p->p_lock);
-       l->l_flag |= LW_WEXIT; /* will be released when unscheduled */
+       if (l->l_refcnt == 0)
+               l->l_flag |= LW_WEXIT;
 }
 
 struct lwp *
diff -r 2a0003c204f7 -r f7d5865c170a sys/rump/librump/rumpkern/rump_private.h
--- a/sys/rump/librump/rumpkern/rump_private.h  Sun Oct 27 18:30:49 2013 +0000
+++ b/sys/rump/librump/rumpkern/rump_private.h  Sun Oct 27 20:25:45 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rump_private.h,v 1.77 2013/09/17 23:55:16 pooka Exp $  */
+/*     $NetBSD: rump_private.h,v 1.78 2013/10/27 20:25:45 pooka Exp $  */
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -108,6 +108,8 @@
 extern bool rump_ttycomponent;
 
 struct lwp *   rump__lwproc_alloclwp(struct proc *);
+void           rump__lwproc_lwphold(void);
+void           rump__lwproc_lwprele(void);
 
 void   rump_cpus_bootstrap(int *);
 void   rump_biglock_init(void);



Home | Main Index | Thread Index | Old Index