Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/rump Allocate struct cpu_info dynamically. Saves quite ...
details: https://anonhg.NetBSD.org/src/rev/69b3e7bd2fd8
branches: trunk
changeset: 343505:69b3e7bd2fd8
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Feb 08 18:18:19 2016 +0000
description:
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.
diffstat:
sys/rump/include/rump-sys/kern.h | 4 +-
sys/rump/librump/rumpkern/lwproc.c | 8 ++--
sys/rump/librump/rumpkern/rump.c | 6 ++--
sys/rump/librump/rumpkern/scheduler.c | 48 +++++++++++++++++++---------------
4 files changed, 36 insertions(+), 30 deletions(-)
diffs (216 lines):
diff -r aa5b73afcddd -r 69b3e7bd2fd8 sys/rump/include/rump-sys/kern.h
--- a/sys/rump/include/rump-sys/kern.h Mon Feb 08 17:18:43 2016 +0000
+++ b/sys/rump/include/rump-sys/kern.h Mon Feb 08 18:18:19 2016 +0000
@@ -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 @@
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;
diff -r aa5b73afcddd -r 69b3e7bd2fd8 sys/rump/librump/rumpkern/lwproc.c
--- a/sys/rump/librump/rumpkern/lwproc.c Mon Feb 08 17:18:43 2016 +0000
+++ b/sys/rump/librump/rumpkern/lwproc.c Mon Feb 08 18:18:19 2016 +0000
@@ -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 @@
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);
diff -r aa5b73afcddd -r 69b3e7bd2fd8 sys/rump/librump/rumpkern/rump.c
--- a/sys/rump/librump/rumpkern/rump.c Mon Feb 08 17:18:43 2016 +0000
+++ b/sys/rump/librump/rumpkern/rump.c Mon Feb 08 18:18:19 2016 +0000
@@ -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 @@
/* 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 */
diff -r aa5b73afcddd -r 69b3e7bd2fd8 sys/rump/librump/rumpkern/scheduler.c
--- a/sys/rump/librump/rumpkern/scheduler.c Mon Feb 08 17:18:43 2016 +0000
+++ b/sys/rump/librump/rumpkern/scheduler.c Mon Feb 08 18:18:19 2016 +0000
@@ -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 @@
#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 @@
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 @@
cpu_lookup(u_int index)
{
- return &rump_cpus[index];
+ return rcpu_storage[index].rcpu_ci;
}
static inline struct rumpcpu *
@@ -127,9 +133,7 @@
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 @@
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 @@
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;
+ 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;
- rcpu->rcpu_wanted = 0;
- rumpuser_cv_init(&rcpu->rcpu_cv);
- rumpuser_mutex_init(&rcpu->rcpu_mtx, RUMPUSER_MTX_SPIN);
}
mutex_init(&unruntime_lock, MUTEX_DEFAULT, IPL_SCHED);
@@ -182,7 +188,7 @@
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 @@
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 @@
*/
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 @@
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);
Home |
Main Index |
Thread Index |
Old Index