Module Name: src Committed By: pooka Date: Sun Mar 10 16:51:31 UTC 2013
Modified Files: src/sys/rump/librump/rumpkern: rump.c rump_private.h threads.c Log Message: Don't allow kernel threads to run before all CPUs have been initialized to avoid them getting scheduled on non-initialized CPUs. To generate a diff of this commit: cvs rdiff -u -r1.255 -r1.256 src/sys/rump/librump/rumpkern/rump.c cvs rdiff -u -r1.73 -r1.74 src/sys/rump/librump/rumpkern/rump_private.h cvs rdiff -u -r1.17 -r1.18 src/sys/rump/librump/rumpkern/threads.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/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.255 src/sys/rump/librump/rumpkern/rump.c:1.256 --- src/sys/rump/librump/rumpkern/rump.c:1.255 Fri Mar 8 19:04:28 2013 +++ src/sys/rump/librump/rumpkern/rump.c Sun Mar 10 16:51:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.255 2013/03/08 19:04:28 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.256 2013/03/10 16:51:31 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.255 2013/03/08 19:04:28 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.256 2013/03/10 16:51:31 pooka Exp $"); #include <sys/systm.h> #define ELFSIZE ARCH_ELFSIZE @@ -267,6 +267,7 @@ rump__init(int rump_version) } else { numcpu = rumpuser_getnhostcpu(); } + rump_thread_init(); rump_cpus_bootstrap(&numcpu); rumpuser_gettime(&sec, &nsec, &error); @@ -385,6 +386,9 @@ rump__init(int rump_version) aprint_verbose("cpu%d at thinair0: rump virtual cpu\n", i); } + /* CPUs are up. allow kernel threads to run */ + rump_thread_allow(); + mksysctls(); kqueue_init(); iostat_init(); Index: src/sys/rump/librump/rumpkern/rump_private.h diff -u src/sys/rump/librump/rumpkern/rump_private.h:1.73 src/sys/rump/librump/rumpkern/rump_private.h:1.74 --- src/sys/rump/librump/rumpkern/rump_private.h:1.73 Tue Feb 19 09:04:54 2013 +++ src/sys/rump/librump/rumpkern/rump_private.h Sun Mar 10 16:51:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: rump_private.h,v 1.73 2013/02/19 09:04:54 martin Exp $ */ +/* $NetBSD: rump_private.h,v 1.74 2013/03/10 16:51:31 pooka Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -141,4 +141,7 @@ void rump_hyperfree(void *, size_t); void rump_xc_highpri(struct cpu_info *); +void rump_thread_init(void); +void rump_thread_allow(void); + #endif /* _SYS_RUMP_PRIVATE_H_ */ Index: src/sys/rump/librump/rumpkern/threads.c diff -u src/sys/rump/librump/rumpkern/threads.c:1.17 src/sys/rump/librump/rumpkern/threads.c:1.18 --- src/sys/rump/librump/rumpkern/threads.c:1.17 Sun Nov 4 14:40:47 2012 +++ src/sys/rump/librump/rumpkern/threads.c Sun Mar 10 16:51:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: threads.c,v 1.17 2012/11/04 14:40:47 pooka Exp $ */ +/* $NetBSD: threads.c,v 1.18 2013/03/10 16:51:31 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.17 2012/11/04 14:40:47 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.18 2013/03/10 16:51:31 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -48,6 +48,10 @@ struct kthdesc { struct lwp *mylwp; }; +static bool threads_are_go; +static struct rumpuser_mtx *thrmtx; +static struct rumpuser_cv *thrcv; + static void * threadbouncer(void *arg) { @@ -59,6 +63,15 @@ threadbouncer(void *arg) f = k->f; thrarg = k->arg; + /* don't allow threads to run before all CPUs have fully attached */ + if (!threads_are_go) { + rumpuser_mutex_enter_nowrap(thrmtx); + while (!threads_are_go) { + rumpuser_cv_wait_nowrap(thrcv, thrmtx); + } + rumpuser_mutex_exit(thrmtx); + } + /* schedule ourselves */ rumpuser_set_curlwp(l); rump_schedule(); @@ -74,6 +87,25 @@ threadbouncer(void *arg) panic("unreachable, should kthread_exit()"); } +void +rump_thread_init(void) +{ + + rumpuser_mutex_init(&thrmtx); + rumpuser_cv_init(&thrcv); +} + +void +rump_thread_allow(void) +{ + + rumpuser_mutex_enter(thrmtx); + threads_are_go = true; + rumpuser_cv_broadcast(thrcv); + rumpuser_mutex_exit(thrmtx); + +} + static struct { const char *t_name; bool t_ncmp;