Module Name: src Committed By: pooka Date: Sat Mar 15 15:15:27 UTC 2014
Modified Files: src/sys/rump: Makefile.rump src/sys/rump/include/machine: cpu.h src/sys/rump/include/rump: rumpuser.h src/sys/rump/librump/rumpkern: lwproc.c rump.c rump_private.h scheduler.c threads.c src/sys/rump/librump/rumpkern/arch/x86: rump_x86_cpu.c Added Files: src/sys/rump/librump/rumpkern: rump_curlwp.h rump_curlwp___thread.h rump_curlwp_hypercall.h Log Message: Allow compile-time optimizations to curlwp. This can have a pretty staggering impact on performance. When running sendto() in a loop, the improvement is 200k more calls per second with an inlined __thread curlwp as opposed to the default. In other words, it shaves off hundreds of CPU cycles per call (~20%). Even just eliminating the x86_curlwp() call in favor of an inline gives an improvement of 60k calls per second. To generate a diff of this commit: cvs rdiff -u -r1.91 -r1.92 src/sys/rump/Makefile.rump cvs rdiff -u -r1.19 -r1.20 src/sys/rump/include/machine/cpu.h cvs rdiff -u -r1.108 -r1.109 src/sys/rump/include/rump/rumpuser.h cvs rdiff -u -r1.26 -r1.27 src/sys/rump/librump/rumpkern/lwproc.c cvs rdiff -u -r1.289 -r1.290 src/sys/rump/librump/rumpkern/rump.c cvs rdiff -u -r0 -r1.1 src/sys/rump/librump/rumpkern/rump_curlwp.h \ src/sys/rump/librump/rumpkern/rump_curlwp___thread.h \ src/sys/rump/librump/rumpkern/rump_curlwp_hypercall.h cvs rdiff -u -r1.79 -r1.80 src/sys/rump/librump/rumpkern/rump_private.h cvs rdiff -u -r1.35 -r1.36 src/sys/rump/librump/rumpkern/scheduler.c cvs rdiff -u -r1.21 -r1.22 src/sys/rump/librump/rumpkern/threads.c cvs rdiff -u -r1.1 -r1.2 \ src/sys/rump/librump/rumpkern/arch/x86/rump_x86_cpu.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/rump/Makefile.rump diff -u src/sys/rump/Makefile.rump:1.91 src/sys/rump/Makefile.rump:1.92 --- src/sys/rump/Makefile.rump:1.91 Thu Mar 13 01:34:06 2014 +++ src/sys/rump/Makefile.rump Sat Mar 15 15:15:26 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.rump,v 1.91 2014/03/13 01:34:06 pooka Exp $ +# $NetBSD: Makefile.rump,v 1.92 2014/03/15 15:15:26 pooka Exp $ # WARNS?= 3 # XXX: src/sys won't compile with -Wsign-compare yet @@ -8,14 +8,13 @@ NOLINT= # kernel code # Use NetBSD kernel ABI by default on x86 archs. Performance-related # compile-time options may override this at a later date. -.if ${MACHINE_ARCH} == "i386" || \ - ${MACHINE_ARCH} == "x86_64" +.if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64") _RUMP_NATIVEABI= yes CPPFLAGS+= -D_RUMP_NATIVE_ABI .else _RUMP_NATIVEABI= no CPPFLAGS:= -I${RUMPTOP}/include ${CPPFLAGS} -CPPFLAGS+= -D_RUMPKERNEL +CPPFLAGS+= -D_RUMPKERNEL -I${RUMPTOP}/librump/rumpkern .endif CPPFLAGS+= -DMAXUSERS=32 Index: src/sys/rump/include/machine/cpu.h diff -u src/sys/rump/include/machine/cpu.h:1.19 src/sys/rump/include/machine/cpu.h:1.20 --- src/sys/rump/include/machine/cpu.h:1.19 Mon Mar 10 23:02:07 2014 +++ src/sys/rump/include/machine/cpu.h Sat Mar 15 15:15:26 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.19 2014/03/10 23:02:07 pooka Exp $ */ +/* $NetBSD: cpu.h,v 1.20 2014/03/15 15:15:26 pooka Exp $ */ /* * Copyright (c) 2008-2011 Antti Kantee. All Rights Reserved. @@ -38,6 +38,8 @@ #include <sys/cpu_data.h> #include <machine/pcb.h> +#include "rump_curlwp.h" + struct cpu_info { struct cpu_data ci_data; cpuid_t ci_cpuid; @@ -73,8 +75,7 @@ static __inline void cpu_handle_ipi(void void __syncicache(void *, size_t); #endif /* __powerpc__ */ -struct lwp *rumpuser_curlwp(void); -#define curlwp rumpuser_curlwp() +#define curlwp rump_curlwp_fast() #define curcpu() (curlwp->l_cpu) #define cpu_number() (cpu_index(curcpu)) Index: src/sys/rump/include/rump/rumpuser.h diff -u src/sys/rump/include/rump/rumpuser.h:1.108 src/sys/rump/include/rump/rumpuser.h:1.109 --- src/sys/rump/include/rump/rumpuser.h:1.108 Wed May 15 16:00:04 2013 +++ src/sys/rump/include/rump/rumpuser.h Sat Mar 15 15:15:26 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: rumpuser.h,v 1.108 2013/05/15 16:00:04 pooka Exp $ */ +/* $NetBSD: rumpuser.h,v 1.109 2014/03/15 15:15:26 pooka Exp $ */ /* * Copyright (c) 2007-2013 Antti Kantee. All Rights Reserved. @@ -175,12 +175,14 @@ int rumpuser_thread_create(void *(*f)(v void rumpuser_thread_exit(void) __dead; int rumpuser_thread_join(void *); +#if defined(LIBRUMPUSER) || defined(RUMP_CURLWP_PRIVATE) enum rumplwpop { RUMPUSER_LWP_CREATE, RUMPUSER_LWP_DESTROY, RUMPUSER_LWP_SET, RUMPUSER_LWP_CLEAR }; void rumpuser_curlwpop(int, struct lwp *); struct lwp *rumpuser_curlwp(void); +#endif /* LIBRUMPUSER || RUMP_CURLWP_PRIVATE */ struct rumpuser_mtx; #define RUMPUSER_MTX_SPIN 0x01 Index: src/sys/rump/librump/rumpkern/lwproc.c diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.26 src/sys/rump/librump/rumpkern/lwproc.c:1.27 --- src/sys/rump/librump/rumpkern/lwproc.c:1.26 Mon Dec 16 15:36:29 2013 +++ src/sys/rump/librump/rumpkern/lwproc.c Sat Mar 15 15:15:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: lwproc.c,v 1.26 2013/12/16 15:36:29 pooka Exp $ */ +/* $NetBSD: lwproc.c,v 1.27 2014/03/15 15:15:27 pooka Exp $ */ /* * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. @@ -25,8 +25,10 @@ * SUCH DAMAGE. */ +#define RUMP_CURLWP_PRIVATE + #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.26 2013/12/16 15:36:29 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.27 2014/03/15 15:15:27 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -42,11 +44,41 @@ __KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1 #include <sys/uidinfo.h> #include <rump/rumpuser.h> - #include "rump_private.h" +#include "rump_curlwp.h" struct emul *emul_default = &emul_netbsd; +void +rump_lwproc_init(void) +{ + + lwproc_curlwpop(RUMPUSER_LWP_CREATE, &lwp0); +} + +struct lwp * +rump_lwproc_curlwp_hypercall(void) +{ + + return rumpuser_curlwp(); +} + +void +rump_lwproc_curlwp_set(struct lwp *l) +{ + + KASSERT(curlwp == NULL); + lwproc_curlwpop(RUMPUSER_LWP_SET, l); +} + +void +rump_lwproc_curlwp_clear(struct lwp *l) +{ + + KASSERT(l == curlwp); + lwproc_curlwpop(RUMPUSER_LWP_CLEAR, l); +} + static void lwproc_proc_free(struct proc *p) { @@ -219,7 +251,7 @@ lwproc_freelwp(struct lwp *l) kmem_free(l->l_name, MAXCOMLEN); lwp_finispecific(l); - rumpuser_curlwpop(RUMPUSER_LWP_DESTROY, l); + lwproc_curlwpop(RUMPUSER_LWP_DESTROY, l); membar_exit(); kmem_free(l, sizeof(*l)); @@ -255,7 +287,7 @@ lwproc_makelwp(struct proc *p, struct lw lwp_initspecific(l); membar_enter(); - rumpuser_curlwpop(RUMPUSER_LWP_CREATE, l); + lwproc_curlwpop(RUMPUSER_LWP_CREATE, l); if (doswitch) { rump_lwproc_switch(l); } @@ -364,13 +396,13 @@ rump_lwproc_switch(struct lwp *newlwp) } KERNEL_UNLOCK_ALL(NULL, &l->l_biglocks); - rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, l); + lwproc_curlwpop(RUMPUSER_LWP_CLEAR, l); newlwp->l_cpu = newlwp->l_target_cpu = l->l_cpu; newlwp->l_mutex = l->l_mutex; newlwp->l_pflag |= LP_RUNNING; - rumpuser_curlwpop(RUMPUSER_LWP_SET, newlwp); + lwproc_curlwpop(RUMPUSER_LWP_SET, newlwp); curcpu()->ci_curlwp = newlwp; KERNEL_LOCK(newlwp->l_biglocks, NULL); Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.289 src/sys/rump/librump/rumpkern/rump.c:1.290 --- src/sys/rump/librump/rumpkern/rump.c:1.289 Mon Mar 10 22:44:11 2014 +++ src/sys/rump/librump/rumpkern/rump.c Sat Mar 15 15:15:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.289 2014/03/10 22:44:11 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.290 2014/03/15 15:15:27 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.289 2014/03/10 22:44:11 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.290 2014/03/15 15:15:27 pooka Exp $"); #include <sys/systm.h> #define ELFSIZE ARCH_ELFSIZE @@ -254,12 +254,10 @@ rump_init(void) } /* init minimal lwp/cpu context */ + rump_lwproc_init(); l = &lwp0; l->l_cpu = l->l_target_cpu = rump_cpu; - - /* lwp0 isn't created like other threads, so notify hypervisor here */ - rumpuser_curlwpop(RUMPUSER_LWP_CREATE, l); - rumpuser_curlwpop(RUMPUSER_LWP_SET, l); + rump_lwproc_curlwp_set(l); /* retrieve env vars which affect the early stage of bootstrap */ if (rumpuser_getparam("RUMP_THREADS", buf, sizeof(buf)) == 0) { @@ -341,7 +339,7 @@ rump_init(void) rump_scheduler_init(numcpu); /* revert temporary context and schedule a semireal context */ - rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, l); + rump_lwproc_curlwp_clear(l); initproc = &proc0; /* borrow proc0 before we get initproc started */ rump_schedule(); bootlwp = curlwp; Index: src/sys/rump/librump/rumpkern/rump_private.h diff -u src/sys/rump/librump/rumpkern/rump_private.h:1.79 src/sys/rump/librump/rumpkern/rump_private.h:1.80 --- src/sys/rump/librump/rumpkern/rump_private.h:1.79 Fri Jan 17 01:32:53 2014 +++ src/sys/rump/librump/rumpkern/rump_private.h Sat Mar 15 15:15:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: rump_private.h,v 1.79 2014/01/17 01:32:53 pooka Exp $ */ +/* $NetBSD: rump_private.h,v 1.80 2014/03/15 15:15:27 pooka Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -152,4 +152,8 @@ void rump_consdev_init(void); void rump_hyperentropy_init(void); +void rump_lwproc_init(void); +void rump_lwproc_curlwp_set(struct lwp *); +void rump_lwproc_curlwp_clear(struct lwp *); + #endif /* _SYS_RUMP_PRIVATE_H_ */ Index: src/sys/rump/librump/rumpkern/scheduler.c diff -u src/sys/rump/librump/rumpkern/scheduler.c:1.35 src/sys/rump/librump/rumpkern/scheduler.c:1.36 --- src/sys/rump/librump/rumpkern/scheduler.c:1.35 Mon Dec 9 19:47:59 2013 +++ src/sys/rump/librump/rumpkern/scheduler.c Sat Mar 15 15:15:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: scheduler.c,v 1.35 2013/12/09 19:47:59 pooka Exp $ */ +/* $NetBSD: scheduler.c,v 1.36 2014/03/15 15:15:27 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.35 2013/12/09 19:47:59 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.36 2014/03/15 15:15:27 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -240,7 +240,7 @@ rump_schedule() * for this case -- anyone who cares about performance will * start a real thread. */ - if (__predict_true((l = rumpuser_curlwp()) != NULL)) { + if (__predict_true((l = curlwp) != NULL)) { rump_schedule_cpu(l); LWP_CACHE_CREDS(l, l->l_proc); } else { @@ -248,7 +248,7 @@ rump_schedule() /* schedule cpu and use lwp0 */ rump_schedule_cpu(&lwp0); - rumpuser_curlwpop(RUMPUSER_LWP_SET, &lwp0); + rump_lwproc_curlwp_set(&lwp0); /* allocate thread, switch to it, and release lwp0 */ l = rump__lwproc_alloclwp(initproc); @@ -365,7 +365,7 @@ rump_schedule_cpu_interlock(struct lwp * void rump_unschedule() { - struct lwp *l = rumpuser_curlwp(); + struct lwp *l = curlwp; #ifdef DIAGNOSTIC int nlock; @@ -399,10 +399,10 @@ rump_unschedule() lwp0.l_mutex = &unruntime_lock; lwp0.l_pflag &= ~LP_RUNNING; lwp0rele(); - rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, &lwp0); + rump_lwproc_curlwp_clear(&lwp0); } else if (__predict_false(l->l_flag & LW_RUMP_CLEAR)) { - rumpuser_curlwpop(RUMPUSER_LWP_CLEAR, l); + rump_lwproc_curlwp_clear(l); l->l_flag &= ~LW_RUMP_CLEAR; } } Index: src/sys/rump/librump/rumpkern/threads.c diff -u src/sys/rump/librump/rumpkern/threads.c:1.21 src/sys/rump/librump/rumpkern/threads.c:1.22 --- src/sys/rump/librump/rumpkern/threads.c:1.21 Thu May 2 19:15:01 2013 +++ src/sys/rump/librump/rumpkern/threads.c Sat Mar 15 15:15:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: threads.c,v 1.21 2013/05/02 19:15:01 pooka Exp $ */ +/* $NetBSD: threads.c,v 1.22 2014/03/15 15:15:27 pooka Exp $ */ /* * Copyright (c) 2007-2009 Antti Kantee. All Rights Reserved. @@ -29,7 +29,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.21 2013/05/02 19:15:01 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.22 2014/03/15 15:15:27 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -73,7 +73,7 @@ threadbouncer(void *arg) } /* schedule ourselves */ - rumpuser_curlwpop(RUMPUSER_LWP_SET, l); + rump_lwproc_curlwp_set(l); rump_schedule(); /* free dance struct */ Index: src/sys/rump/librump/rumpkern/arch/x86/rump_x86_cpu.c diff -u src/sys/rump/librump/rumpkern/arch/x86/rump_x86_cpu.c:1.1 src/sys/rump/librump/rumpkern/arch/x86/rump_x86_cpu.c:1.2 --- src/sys/rump/librump/rumpkern/arch/x86/rump_x86_cpu.c:1.1 Wed Feb 12 22:28:43 2014 +++ src/sys/rump/librump/rumpkern/arch/x86/rump_x86_cpu.c Sat Mar 15 15:15:27 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: rump_x86_cpu.c,v 1.1 2014/02/12 22:28:43 pooka Exp $ */ +/* $NetBSD: rump_x86_cpu.c,v 1.2 2014/03/15 15:15:27 pooka Exp $ */ /* * Copyright (c) 2008 Antti Kantee. All Rights Reserved. @@ -29,13 +29,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rump_x86_cpu.c,v 1.1 2014/02/12 22:28:43 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump_x86_cpu.c,v 1.2 2014/03/15 15:15:27 pooka Exp $"); #include <sys/param.h> #include <machine/cpu.h> #include "rump_private.h" +#include "rump_curlwp.h" struct cpu_info *cpu_info_list; @@ -65,7 +66,7 @@ struct lwp * x86_curlwp() { - return rumpuser_curlwp(); + return rump_curlwp_fast(); } void Added files: Index: src/sys/rump/librump/rumpkern/rump_curlwp.h diff -u /dev/null src/sys/rump/librump/rumpkern/rump_curlwp.h:1.1 --- /dev/null Sat Mar 15 15:15:27 2014 +++ src/sys/rump/librump/rumpkern/rump_curlwp.h Sat Mar 15 15:15:27 2014 @@ -0,0 +1,54 @@ +/* $NetBSD: rump_curlwp.h,v 1.1 2014/03/15 15:15:27 pooka Exp $ */ + +/*- + * Copyright (c) 2014 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. + */ + +#ifndef _SYS_RUMP_CURLWP_H_ +#define _SYS_RUMP_CURLWP_H_ + +struct lwp * rump_lwproc_curlwp_hypercall(void); + +/* hattrick numbers to avoid someone accidentally using "1" as the value */ +#define RUMP_CURLWP_MODEL_HYPERCALL 10501 +#define RUMP_CURLWP_MODEL___THREAD 20502 +#define RUMP_CURLWP_MODEL_REGISTER 30503 +#define RUMP_CURLWP_MODEL_DEFAULT RUMP_CURLWP_MODEL_HYPERCALL + +#ifndef RUMP_CURLWP_MODEL +#define RUMP_CURLWP_MODEL RUMP_CURLWP_MODEL_DEFAULT +#endif + +/* provides rump_curlwp_fast() */ +#if RUMP_CURLWP_MODEL == RUMP_CURLWP_MODEL_HYPERCALL +#include "rump_curlwp_hypercall.h" +#elif RUMP_CURLWP_MODEL == RUMP_CURLWP_MODEL___THREAD +#include "rump_curlwp___thread.h" +#elif RUMP_CURLWP_MODEL == RUMP_CURLWP_MODEL_REGISTER +#error "RUMP_CURLWP_MODEL_REGISTER not yet implemented" +#else +#error "unknown RUMP_CURLWP" +#endif + +#endif /* _SYS_RUMP_CURLWP_H_ */ Index: src/sys/rump/librump/rumpkern/rump_curlwp___thread.h diff -u /dev/null src/sys/rump/librump/rumpkern/rump_curlwp___thread.h:1.1 --- /dev/null Sat Mar 15 15:15:27 2014 +++ src/sys/rump/librump/rumpkern/rump_curlwp___thread.h Sat Mar 15 15:15:27 2014 @@ -0,0 +1,63 @@ +/* $NetBSD: rump_curlwp___thread.h,v 1.1 2014/03/15 15:15:27 pooka Exp $ */ + +/*- + * Copyright (c) 2014 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. + */ + +extern __thread struct lwp *curlwp_storage; +#ifdef RUMP_CURLWP_PRIVATE +#include <rump/rumpuser.h> + +__thread struct lwp *curlwp_storage; +static void +lwproc_curlwpop(enum rumplwpop op, struct lwp *l) +{ + + switch (op) { + case RUMPUSER_LWP_CREATE: + case RUMPUSER_LWP_DESTROY: + break; + case RUMPUSER_LWP_SET: + KASSERT(curlwp_storage == NULL); + curlwp_storage = l; + break; + case RUMPUSER_LWP_CLEAR: + KASSERT(curlwp_storage == l); + curlwp_storage = NULL; + break; + } + /* + * Need to keep hypercall layer in sync, since it can use curlwp + * for things like mutexes. Should be fixed/adjusted somehow. + */ + rumpuser_curlwpop(op, l); +} +#endif + +static inline struct lwp * __attribute__((const)) +rump_curlwp_fast(void) +{ + + return curlwp_storage; +} Index: src/sys/rump/librump/rumpkern/rump_curlwp_hypercall.h diff -u /dev/null src/sys/rump/librump/rumpkern/rump_curlwp_hypercall.h:1.1 --- /dev/null Sat Mar 15 15:15:27 2014 +++ src/sys/rump/librump/rumpkern/rump_curlwp_hypercall.h Sat Mar 15 15:15:27 2014 @@ -0,0 +1,43 @@ +/* $NetBSD: rump_curlwp_hypercall.h,v 1.1 2014/03/15 15:15:27 pooka Exp $ */ + +/*- + * Copyright (c) 2014 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. + */ + +#ifdef RUMP_CURLWP_PRIVATE +#include <rump/rumpuser.h> +static void +lwproc_curlwpop(enum rumplwpop op, struct lwp *l) +{ + + rumpuser_curlwpop(op, l); +} +#endif + +static inline struct lwp * +rump_curlwp_fast(void) +{ + + return rump_lwproc_curlwp_hypercall(); +}