Module Name:    src
Committed By:   pooka
Date:           Wed May 15 14:07:26 UTC 2013

Modified Files:
        src/lib/librumpuser: rumpuser.3 rumpuser_pth.c
        src/sys/rump/include/rump: rumpuser.h
        src/sys/rump/librump/rumpkern: lwproc.c rump.c scheduler.c

Log Message:
Add RUMPUSER_LWP_CLEAR instead of overloading RUMPUSER_LWP_SET.
This simplifies some alternative hypervisor implementations.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/librumpuser/rumpuser.3
cvs rdiff -u -r1.28 -r1.29 src/lib/librumpuser/rumpuser_pth.c
cvs rdiff -u -r1.103 -r1.104 src/sys/rump/include/rump/rumpuser.h
cvs rdiff -u -r1.22 -r1.23 src/sys/rump/librump/rumpkern/lwproc.c
cvs rdiff -u -r1.268 -r1.269 src/sys/rump/librump/rumpkern/rump.c
cvs rdiff -u -r1.33 -r1.34 src/sys/rump/librump/rumpkern/scheduler.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/rumpuser.3
diff -u src/lib/librumpuser/rumpuser.3:1.9 src/lib/librumpuser/rumpuser.3:1.10
--- src/lib/librumpuser/rumpuser.3:1.9	Fri May  3 20:27:16 2013
+++ src/lib/librumpuser/rumpuser.3	Wed May 15 14:07:26 2013
@@ -1,4 +1,4 @@
-.\"     $NetBSD: rumpuser.3,v 1.9 2013/05/03 20:27:16 wiz Exp $
+.\"     $NetBSD: rumpuser.3,v 1.10 2013/05/15 14:07:26 pooka Exp $
 .\"
 .\" Copyright (c) 2013 Antti Kantee.  All rights reserved.
 .\"
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd May 2, 2013
+.Dd May 15, 2013
 .Dt RUMPUSER 3
 .Os
 .Sh NAME
@@ -475,10 +475,14 @@ from the hypervisor.
 Set
 .Fa l
 as the current host thread's rump kernel context.
-The value
-.Dv NULL
-means that an existing rump kernel context (which must exist)
-must be cleared.
+A previous context must not exist.
+.It Dv RUMPUSER_LWP_CLEAR
+Clear the context previous set by
+.Dv RUMPUSER_LWP_SET .
+The value passed in
+.Fa l
+is the current thread and is never
+.Dv NULL.
 .El
 .Pp
 .Ft struct lwp *
@@ -641,7 +645,8 @@ Routines which do not return an integer 
 .%A Antti Kantee
 .%D 2012
 .%J Aalto University Doctoral Dissertations
-.%T Flexible Operating System Internals: The Design and Implementation of the Anykernel and Rump Kernerls
+.%T Flexible Operating System Internals: The Design and Implementation of the Anykernel and Rump Kernels
+.%O Section 2.3.2: The Hypercall Interface
 .Re
 .Sh HISTORY
 The rump kernel hypercall API was first introduced in

Index: src/lib/librumpuser/rumpuser_pth.c
diff -u src/lib/librumpuser/rumpuser_pth.c:1.28 src/lib/librumpuser/rumpuser_pth.c:1.29
--- src/lib/librumpuser/rumpuser_pth.c:1.28	Sun May  5 12:27:38 2013
+++ src/lib/librumpuser/rumpuser_pth.c	Wed May 15 14:07:26 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser_pth.c,v 1.28 2013/05/05 12:27:38 pooka Exp $	*/
+/*	$NetBSD: rumpuser_pth.c,v 1.29 2013/05/15 14:07:26 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth.c,v 1.28 2013/05/05 12:27:38 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_pth.c,v 1.29 2013/05/15 14:07:26 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/queue.h>
@@ -627,26 +627,27 @@ rumpuser_curlwpop(enum rumplwpop op, str
 		free(rl);
 		break;
 	case RUMPUSER_LWP_SET:
-		assert(pthread_getspecific(curlwpkey) == NULL || l == NULL);
+		assert(pthread_getspecific(curlwpkey) == NULL && l != NULL);
 
-		if (l) {
-			pthread_mutex_lock(&lwplock);
-			LIST_FOREACH(rl, &lwps, l_entries) {
-				if (rl->l == l)
-					break;
-			}
-			if (!rl) {
-				fprintf(stderr,
-				    "LWP_SET: %p does not exist\n", l);
-				abort();
-			}
-			pthread_mutex_unlock(&lwplock);
-		} else {
-			rl = NULL;
+		pthread_mutex_lock(&lwplock);
+		LIST_FOREACH(rl, &lwps, l_entries) {
+			if (rl->l == l)
+				break;
 		}
+		if (!rl) {
+			fprintf(stderr,
+			    "LWP_SET: %p does not exist\n", l);
+			abort();
+		}
+		pthread_mutex_unlock(&lwplock);
 
 		pthread_setspecific(curlwpkey, rl);
 		break;
+	case RUMPUSER_LWP_CLEAR:
+		assert(((struct rumpuser_lwp *)
+		    pthread_getspecific(curlwpkey))->l == l);
+		pthread_setspecific(curlwpkey, NULL);
+		break;
 	}
 }
 
@@ -671,9 +672,13 @@ rumpuser_curlwpop(enum rumplwpop op, str
 	case RUMPUSER_LWP_DESTROY:
 		break;
 	case RUMPUSER_LWP_SET:
-		assert(pthread_getspecific(curlwpkey) == NULL || l == NULL);
+		assert(pthread_getspecific(curlwpkey) == NULL);
 		pthread_setspecific(curlwpkey, l);
 		break;
+	case RUMPUSER_LWP_CLEAR:
+		assert(pthread_getspecific(curlwpkey) == l);
+		pthread_setspecific(curlwpkey, NULL);
+		break;
 	}
 }
 

Index: src/sys/rump/include/rump/rumpuser.h
diff -u src/sys/rump/include/rump/rumpuser.h:1.103 src/sys/rump/include/rump/rumpuser.h:1.104
--- src/sys/rump/include/rump/rumpuser.h:1.103	Thu May  2 21:45:28 2013
+++ src/sys/rump/include/rump/rumpuser.h	Wed May 15 14:07:26 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.h,v 1.103 2013/05/02 21:45:28 pooka Exp $	*/
+/*	$NetBSD: rumpuser.h,v 1.104 2013/05/15 14:07:26 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2013 Antti Kantee.  All Rights Reserved.
@@ -164,7 +164,10 @@ int  rumpuser_thread_create(void *(*f)(v
 void rumpuser_thread_exit(void) __dead;
 int  rumpuser_thread_join(void *);
 
-enum rumplwpop { RUMPUSER_LWP_CREATE, RUMPUSER_LWP_DESTROY, RUMPUSER_LWP_SET };
+enum rumplwpop {
+	RUMPUSER_LWP_CREATE, RUMPUSER_LWP_DESTROY,
+	RUMPUSER_LWP_SET, RUMPUSER_LWP_CLEAR
+};
 void rumpuser_curlwpop(enum rumplwpop, struct lwp *);
 struct lwp *rumpuser_curlwp(void);
 

Index: src/sys/rump/librump/rumpkern/lwproc.c
diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.22 src/sys/rump/librump/rumpkern/lwproc.c:1.23
--- src/sys/rump/librump/rumpkern/lwproc.c:1.22	Thu May  2 19:15:01 2013
+++ src/sys/rump/librump/rumpkern/lwproc.c	Wed May 15 14:07:26 2013
@@ -1,4 +1,4 @@
-/*      $NetBSD: lwproc.c,v 1.22 2013/05/02 19:15:01 pooka Exp $	*/
+/*      $NetBSD: lwproc.c,v 1.23 2013/05/15 14:07:26 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.22 2013/05/02 19:15:01 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.23 2013/05/15 14:07:26 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -352,7 +352,7 @@ rump_lwproc_switch(struct lwp *newlwp)
 		fd_free();
 	}
 
-	rumpuser_curlwpop(RUMPUSER_LWP_SET, NULL);
+	rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, l);
 
 	newlwp->l_cpu = newlwp->l_target_cpu = l->l_cpu;
 	newlwp->l_mutex = l->l_mutex;

Index: src/sys/rump/librump/rumpkern/rump.c
diff -u src/sys/rump/librump/rumpkern/rump.c:1.268 src/sys/rump/librump/rumpkern/rump.c:1.269
--- src/sys/rump/librump/rumpkern/rump.c:1.268	Thu May  2 21:45:28 2013
+++ src/sys/rump/librump/rumpkern/rump.c	Wed May 15 14:07:26 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump.c,v 1.268 2013/05/02 21:45:28 pooka Exp $	*/
+/*	$NetBSD: rump.c,v 1.269 2013/05/15 14:07:26 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.268 2013/05/02 21:45:28 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.269 2013/05/15 14:07:26 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -346,7 +346,7 @@ rump_init(void)
 
 	rump_scheduler_init(numcpu);
 	/* revert temporary context and schedule a semireal context */
-	rumpuser_curlwpop(RUMPUSER_LWP_SET, NULL);
+	rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, l);
 	initproc = &proc0; /* borrow proc0 before we get initproc started */
 	rump_schedule();
 	bootlwp = curlwp;

Index: src/sys/rump/librump/rumpkern/scheduler.c
diff -u src/sys/rump/librump/rumpkern/scheduler.c:1.33 src/sys/rump/librump/rumpkern/scheduler.c:1.34
--- src/sys/rump/librump/rumpkern/scheduler.c:1.33	Thu May  2 19:15:01 2013
+++ src/sys/rump/librump/rumpkern/scheduler.c	Wed May 15 14:07:26 2013
@@ -1,4 +1,4 @@
-/*      $NetBSD: scheduler.c,v 1.33 2013/05/02 19:15:01 pooka Exp $	*/
+/*      $NetBSD: scheduler.c,v 1.34 2013/05/15 14:07:26 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.33 2013/05/02 19:15:01 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.34 2013/05/15 14:07:26 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -399,10 +399,10 @@ rump_unschedule()
 		lwp0.l_mutex = &unruntime_lock;
 		lwp0.l_pflag &= ~LP_RUNNING;
 		lwp0rele();
-		rumpuser_curlwpop(RUMPUSER_LWP_SET, NULL);
+		rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, &lwp0);
 
 	} else if (__predict_false(l->l_flag & LW_RUMP_CLEAR)) {
-		rumpuser_curlwpop(RUMPUSER_LWP_SET, NULL);
+		rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, l);
 		l->l_flag &= ~LW_RUMP_CLEAR;
 	}
 }

Reply via email to