Module Name: src Committed By: pooka Date: Mon Feb 8 18:18:19 UTC 2016
Modified Files: src/sys/rump/include/rump-sys: kern.h src/sys/rump/librump/rumpkern: lwproc.c rump.c scheduler.c Log Message: Allocate struct cpu_info dynamically. Saves quite a lot of BSS in the common case and reduces rump kernel memory requirements by 10% or more in really tiny deployments. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/rump/include/rump-sys/kern.h cvs rdiff -u -r1.37 -r1.38 src/sys/rump/librump/rumpkern/lwproc.c cvs rdiff -u -r1.327 -r1.328 src/sys/rump/librump/rumpkern/rump.c cvs rdiff -u -r1.42 -r1.43 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/sys/rump/include/rump-sys/kern.h diff -u src/sys/rump/include/rump-sys/kern.h:1.2 src/sys/rump/include/rump-sys/kern.h:1.3 --- src/sys/rump/include/rump-sys/kern.h:1.2 Tue Feb 2 13:07:30 2016 +++ src/sys/rump/include/rump-sys/kern.h Mon Feb 8 18:18:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: kern.h,v 1.2 2016/02/02 13:07:30 pooka Exp $ */ +/* $NetBSD: kern.h,v 1.3 2016/02/08 18:18:19 pooka Exp $ */ /* * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. @@ -144,7 +144,7 @@ typedef void (*rump_proc_vfs_release_fn) extern rump_proc_vfs_init_fn rump_proc_vfs_init; extern rump_proc_vfs_release_fn rump_proc_vfs_release; -extern struct cpu_info *rump_cpu; +extern struct cpu_info rump_bootcpu; extern bool rump_ttycomponent; Index: src/sys/rump/librump/rumpkern/lwproc.c diff -u src/sys/rump/librump/rumpkern/lwproc.c:1.37 src/sys/rump/librump/rumpkern/lwproc.c:1.38 --- src/sys/rump/librump/rumpkern/lwproc.c:1.37 Tue Jan 26 23:12:17 2016 +++ src/sys/rump/librump/rumpkern/lwproc.c Mon Feb 8 18:18:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: lwproc.c,v 1.37 2016/01/26 23:12:17 pooka Exp $ */ +/* $NetBSD: lwproc.c,v 1.38 2016/02/08 18:18:19 pooka Exp $ */ /* * Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ #define RUMP__CURLWP_PRIVATE #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.37 2016/01/26 23:12:17 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lwproc.c,v 1.38 2016/02/08 18:18:19 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -334,8 +334,8 @@ lwproc_makelwp(struct proc *p, struct lw LIST_INSERT_HEAD(&p->p_lwps, l, l_sibling); l->l_fd = p->p_fd; - l->l_cpu = rump_cpu; - l->l_target_cpu = rump_cpu; /* Initial target CPU always the same */ + l->l_cpu = &rump_bootcpu; + l->l_target_cpu = &rump_bootcpu; /* Initial target CPU always same */ l->l_stat = LSRUN; l->l_mutex = &unruntime_lock; TAILQ_INIT(&l->l_ld_locks); Index: src/sys/rump/librump/rumpkern/rump.c diff -u src/sys/rump/librump/rumpkern/rump.c:1.327 src/sys/rump/librump/rumpkern/rump.c:1.328 --- src/sys/rump/librump/rumpkern/rump.c:1.327 Tue Jan 26 23:12:17 2016 +++ src/sys/rump/librump/rumpkern/rump.c Mon Feb 8 18:18:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: rump.c,v 1.327 2016/01/26 23:12:17 pooka Exp $ */ +/* $NetBSD: rump.c,v 1.328 2016/02/08 18:18:19 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.327 2016/01/26 23:12:17 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.328 2016/02/08 18:18:19 pooka Exp $"); #include <sys/systm.h> #define ELFSIZE ARCH_ELFSIZE @@ -246,7 +246,7 @@ rump_init(void) /* init minimal lwp/cpu context */ rump_lwproc_init(); l = &lwp0; - l->l_cpu = l->l_target_cpu = rump_cpu; + l->l_cpu = l->l_target_cpu = &rump_bootcpu; rump_lwproc_curlwp_set(l); /* retrieve env vars which affect the early stage of bootstrap */ Index: src/sys/rump/librump/rumpkern/scheduler.c diff -u src/sys/rump/librump/rumpkern/scheduler.c:1.42 src/sys/rump/librump/rumpkern/scheduler.c:1.43 --- src/sys/rump/librump/rumpkern/scheduler.c:1.42 Tue Jan 26 23:12:18 2016 +++ src/sys/rump/librump/rumpkern/scheduler.c Mon Feb 8 18:18:19 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: scheduler.c,v 1.42 2016/01/26 23:12:18 pooka Exp $ */ +/* $NetBSD: scheduler.c,v 1.43 2016/02/08 18:18:19 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.42 2016/01/26 23:12:18 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: scheduler.c,v 1.43 2016/02/08 18:18:19 pooka Exp $"); #include <sys/param.h> #include <sys/atomic.h> @@ -42,7 +42,6 @@ __KERNEL_RCSID(0, "$NetBSD: scheduler.c, #include <rump/rumpuser.h> -static struct cpu_info rump_cpus[MAXCPUS]; static struct rumpcpu { /* needed in fastpath */ struct cpu_info *rcpu_ci; @@ -69,7 +68,14 @@ static struct rumpcpu { int rcpu_align[0] __aligned(CACHE_LINE_SIZE); } rcpu_storage[MAXCPUS]; -struct cpu_info *rump_cpu = &rump_cpus[0]; +static inline struct rumpcpu * +cpuinfo_to_rumpcpu(struct cpu_info *ci) +{ + + return &rcpu_storage[cpu_index(ci)]; +} + +struct cpu_info rump_bootcpu; kcpuset_t *kcpuset_attached = NULL; kcpuset_t *kcpuset_running = NULL; int ncpu, ncpuonline; @@ -107,7 +113,7 @@ struct cpu_info * cpu_lookup(u_int index) { - return &rump_cpus[index]; + return rcpu_storage[index].rcpu_ci; } static inline struct rumpcpu * @@ -127,9 +133,7 @@ getnextcpu(void) void rump_cpus_bootstrap(int *nump) { - struct cpu_info *ci; int num = *nump; - int i; if (num > MAXCPUS) { aprint_verbose("CPU limit: %d wanted, %d (MAXCPUS) " @@ -137,16 +141,11 @@ rump_cpus_bootstrap(int *nump) num = MAXCPUS; } - for (i = 0; i < num; i++) { - ci = &rump_cpus[i]; - ci->ci_index = i; - } - kcpuset_create(&kcpuset_attached, true); kcpuset_create(&kcpuset_running, true); /* attach first cpu for bootstrap */ - rump_cpu_attach(&rump_cpus[0]); + rump_cpu_attach(&rump_bootcpu); ncpu = 1; *nump = num; } @@ -161,15 +160,22 @@ rump_scheduler_init(int numcpu) rumpuser_mutex_init(&lwp0mtx, RUMPUSER_MTX_SPIN); rumpuser_cv_init(&lwp0cv); for (i = 0; i < numcpu; i++) { + if (i == 0) { + ci = &rump_bootcpu; + } else { + ci = kmem_zalloc(sizeof(*ci), KM_SLEEP); + ci->ci_index = i; + } + rcpu = &rcpu_storage[i]; - ci = &rump_cpus[i]; rcpu->rcpu_ci = ci; - ci->ci_schedstate.spc_mutex = - mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED); - ci->ci_schedstate.spc_flags = SPCF_RUNNING; rcpu->rcpu_wanted = 0; rumpuser_cv_init(&rcpu->rcpu_cv); rumpuser_mutex_init(&rcpu->rcpu_mtx, RUMPUSER_MTX_SPIN); + + ci->ci_schedstate.spc_mutex = + mutex_obj_alloc(MUTEX_DEFAULT, IPL_SCHED); + ci->ci_schedstate.spc_flags = SPCF_RUNNING; } mutex_init(&unruntime_lock, MUTEX_DEFAULT, IPL_SCHED); @@ -182,7 +188,7 @@ void rump_schedlock_cv_wait(struct rumpuser_cv *cv) { struct lwp *l = curlwp; - struct rumpcpu *rcpu = &rcpu_storage[l->l_cpu-&rump_cpus[0]]; + struct rumpcpu *rcpu = cpuinfo_to_rumpcpu(l->l_cpu); /* mutex will be taken and released in cpu schedule/unschedule */ rumpuser_cv_wait(cv, rcpu->rcpu_mtx); @@ -192,7 +198,7 @@ int rump_schedlock_cv_timedwait(struct rumpuser_cv *cv, const struct timespec *ts) { struct lwp *l = curlwp; - struct rumpcpu *rcpu = &rcpu_storage[l->l_cpu-&rump_cpus[0]]; + struct rumpcpu *rcpu = cpuinfo_to_rumpcpu(l->l_cpu); /* mutex will be taken and released in cpu schedule/unschedule */ return rumpuser_cv_timedwait(cv, rcpu->rcpu_mtx, @@ -298,7 +304,7 @@ rump_schedule_cpu_interlock(struct lwp * */ KASSERT(l->l_target_cpu != NULL); - rcpu = &rcpu_storage[l->l_target_cpu-&rump_cpus[0]]; + rcpu = cpuinfo_to_rumpcpu(l->l_target_cpu); if (atomic_cas_ptr(&rcpu->rcpu_prevlwp, l, RCPULWP_BUSY) == l) { if (interlock == rcpu->rcpu_mtx) rumpuser_mutex_exit(rcpu->rcpu_mtx); @@ -440,7 +446,7 @@ rump_unschedule_cpu1(struct lwp *l, void ci = l->l_cpu; ci->ci_curlwp = ci->ci_data.cpu_onproc = NULL; - rcpu = &rcpu_storage[ci-&rump_cpus[0]]; + rcpu = cpuinfo_to_rumpcpu(ci); KASSERT(rcpu->rcpu_ci == ci);