summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_percpu.c
diff options
context:
space:
mode:
authordlg <dlg@openbsd.org>2016-10-27 09:40:20 +0000
committerdlg <dlg@openbsd.org>2016-10-27 09:40:20 +0000
commit8457285f6725d0c8bf1657f004b70f448501cdfc (patch)
treee3a3f27c70f22574d024897192a9201bcb6a936b /sys/kern/subr_percpu.c
parentHuawei squatted on BGP Path Attribute 30, and Cisco squatted on 31. So, (diff)
downloadwireguard-openbsd-8457285f6725d0c8bf1657f004b70f448501cdfc.tar.xz
wireguard-openbsd-8457285f6725d0c8bf1657f004b70f448501cdfc.zip
use ncpusfound to size the percpu allocations.
ncpus is used on half the architectures to indicate the number of cpus that have been hatched, and is used on them in things like ddb to figure out how many cpus to shut down again. ncpusfound is incremented during autoconf on MP machines to show how big ncpus will probably become. percpu is initted after autoconf but before cpus are hatched, so this works well.
Diffstat (limited to '')
-rw-r--r--sys/kern/subr_percpu.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/sys/kern/subr_percpu.c b/sys/kern/subr_percpu.c
index e396d92fe3a..8ff00635165 100644
--- a/sys/kern/subr_percpu.c
+++ b/sys/kern/subr_percpu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: subr_percpu.c,v 1.4 2016/10/24 23:58:33 dlg Exp $ */
+/* $OpenBSD: subr_percpu.c,v 1.5 2016/10/27 09:40:20 dlg Exp $ */
/*
* Copyright (c) 2016 David Gwynne <dlg@openbsd.org>
@@ -30,8 +30,8 @@ struct pool cpumem_pl;
void
percpu_init(void)
{
- pool_init(&cpumem_pl, sizeof(struct cpumem) * ncpus, 0, IPL_NONE,
- PR_WAITOK, "percpumem", &pool_allocator_single);
+ pool_init(&cpumem_pl, sizeof(struct cpumem) * ncpusfound, 0,
+ IPL_NONE, PR_WAITOK, "percpumem", &pool_allocator_single);
}
struct cpumem *
@@ -42,7 +42,7 @@ cpumem_get(struct pool *pp)
cm = pool_get(&cpumem_pl, PR_WAITOK);
- for (cpu = 0; cpu < ncpus; cpu++)
+ for (cpu = 0; cpu < ncpusfound; cpu++)
cm[cpu].mem = pool_get(pp, PR_WAITOK | PR_ZERO);
return (cm);
@@ -53,7 +53,7 @@ cpumem_put(struct pool *pp, struct cpumem *cm)
{
unsigned int cpu;
- for (cpu = 0; cpu < ncpus; cpu++)
+ for (cpu = 0; cpu < ncpusfound; cpu++)
pool_put(pp, cm[cpu].mem);
pool_put(&cpumem_pl, cm);
@@ -69,7 +69,7 @@ cpumem_malloc(size_t sz, int type)
cm = pool_get(&cpumem_pl, PR_WAITOK);
- for (cpu = 0; cpu < ncpus; cpu++)
+ for (cpu = 0; cpu < ncpusfound; cpu++)
cm[cpu].mem = malloc(sz, type, M_WAITOK | M_ZERO);
return (cm);
@@ -86,7 +86,7 @@ cpumem_malloc_ncpus(struct cpumem *bootcm, size_t sz, int type)
cm = pool_get(&cpumem_pl, PR_WAITOK);
cm[0].mem = bootcm[0].mem;
- for (cpu = 1; cpu < ncpus; cpu++)
+ for (cpu = 1; cpu < ncpusfound; cpu++)
cm[cpu].mem = malloc(sz, type, M_WAITOK | M_ZERO);
return (cm);
@@ -99,7 +99,7 @@ cpumem_free(struct cpumem *cm, int type, size_t sz)
sz = roundup(sz, CACHELINESIZE);
- for (cpu = 0; cpu < ncpus; cpu++)
+ for (cpu = 0; cpu < ncpusfound; cpu++)
free(cm[cpu].mem, type, sz);
pool_put(&cpumem_pl, cm);
@@ -118,7 +118,7 @@ cpumem_next(struct cpumem_iter *i, struct cpumem *cm)
{
unsigned int cpu = ++i->cpu;
- if (cpu >= ncpus)
+ if (cpu >= ncpusfound)
return (NULL);
return (cm[cpu].mem);