i wanted to enable per-cpu caches on the myx cluster pool, but the
myx pool is set up before the cpumem subsystem is ready to back it.
rather than add more hooks in myx, this has the cpumem subsystem
init its own pool on the first use of it.
it assumes ncpusfound will be correctly set before the first use
of the pool.
ok?
Index: dev/pci/if_myx.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_myx.c,v
retrieving revision 1.102
diff -u -p -r1.102 if_myx.c
--- dev/pci/if_myx.c 7 Feb 2017 06:51:58 -0000 1.102
+++ dev/pci/if_myx.c 31 Jul 2017 07:20:27 -0000
@@ -304,6 +304,7 @@ myx_attach(struct device *parent, struct
m_pool_init(myx_mcl_pool, MYX_RXBIG_SIZE, MYX_BOUNDARY,
"myxmcl");
+ pool_cache_init(myx_mcl_pool);
}
if (myx_pcie_dc(sc, pa) != 0)
Index: kern/init_main.c
===================================================================
RCS file: /cvs/src/sys/kern/init_main.c,v
retrieving revision 1.269
diff -u -p -r1.269 init_main.c
--- kern/init_main.c 28 Apr 2017 13:50:55 -0000 1.269
+++ kern/init_main.c 31 Jul 2017 07:20:27 -0000
@@ -148,7 +148,6 @@ void futex_init(void);
void taskq_init(void);
void timeout_proc_init(void);
void pool_gc_pages(void *);
-void percpu_init(void);
extern char sigcode[], esigcode[], sigcoderet[];
#ifdef SYSCALL_DEBUG
@@ -370,9 +369,6 @@ main(void *framep)
/* Configure virtual memory system, set vm rlimits. */
uvm_init_limits(p);
-
- /* Per CPU memory allocation */
- percpu_init();
/* Initialize the file systems. */
#if defined(NFSSERVER) || defined(NFSCLIENT)
Index: kern/subr_percpu.c
===================================================================
RCS file: /cvs/src/sys/kern/subr_percpu.c,v
retrieving revision 1.7
diff -u -p -r1.7 subr_percpu.c
--- kern/subr_percpu.c 5 Feb 2017 16:23:38 -0000 1.7
+++ kern/subr_percpu.c 31 Jul 2017 07:20:27 -0000
@@ -27,11 +27,25 @@
#ifdef MULTIPROCESSOR
struct pool cpumem_pl;
+struct cpumem *
+ percpu_get(void);
+void percpu_put(struct cpumem *);
+
+struct cpumem *
+percpu_get(void)
+{
+ if (cpumem_pl.pr_size == 0) {
+ pool_init(&cpumem_pl, sizeof(struct cpumem) * ncpusfound, 0,
+ IPL_NONE, PR_WAITOK, "percpumem", &pool_allocator_single);
+ }
+
+ return (pool_get(&cpumem_pl, PR_WAITOK));
+}
+
void
-percpu_init(void)
+percpu_put(struct cpumem *cm)
{
- pool_init(&cpumem_pl, sizeof(struct cpumem) * ncpusfound, 0,
- IPL_NONE, PR_WAITOK, "percpumem", &pool_allocator_single);
+ pool_put(&cpumem_pl, cm);
}
struct cpumem *
@@ -40,7 +54,7 @@ cpumem_get(struct pool *pp)
struct cpumem *cm;
unsigned int cpu;
- cm = pool_get(&cpumem_pl, PR_WAITOK);
+ cm = percpu_get();
for (cpu = 0; cpu < ncpusfound; cpu++)
cm[cpu].mem = pool_get(pp, PR_WAITOK | PR_ZERO);
@@ -56,7 +70,7 @@ cpumem_put(struct pool *pp, struct cpume
for (cpu = 0; cpu < ncpusfound; cpu++)
pool_put(pp, cm[cpu].mem);
- pool_put(&cpumem_pl, cm);
+ percpu_put(cm);
}
struct cpumem *
@@ -67,7 +81,7 @@ cpumem_malloc(size_t sz, int type)
sz = roundup(sz, CACHELINESIZE);
- cm = pool_get(&cpumem_pl, PR_WAITOK);
+ cm = percpu_get();
for (cpu = 0; cpu < ncpusfound; cpu++)
cm[cpu].mem = malloc(sz, type, M_WAITOK | M_ZERO);
@@ -83,7 +97,7 @@ cpumem_malloc_ncpus(struct cpumem *bootc
sz = roundup(sz, CACHELINESIZE);
- cm = pool_get(&cpumem_pl, PR_WAITOK);
+ cm = percpu_get();
cm[0].mem = bootcm[0].mem;
for (cpu = 1; cpu < ncpusfound; cpu++)
@@ -102,7 +116,7 @@ cpumem_free(struct cpumem *cm, int type,
for (cpu = 0; cpu < ncpusfound; cpu++)
free(cm[cpu].mem, type, sz);
- pool_put(&cpumem_pl, cm);
+ percpu_put(cm);
}
void *