cos its not resizing the allocation, its allocating them for new cpus.

the same goes for counters_realloc being named counters_alloc_ncpus.

this adds doco for them too.

ok?

Index: share/man/man9/counters_alloc.9
===================================================================
RCS file: /cvs/src/share/man/man9/counters_alloc.9,v
retrieving revision 1.2
diff -u -p -r1.2 counters_alloc.9
--- share/man/man9/counters_alloc.9     21 Oct 2016 12:39:13 -0000      1.2
+++ share/man/man9/counters_alloc.9     24 Oct 2016 04:43:33 -0000
@@ -20,6 +20,9 @@
 .Sh NAME
 .Nm counters_alloc ,
 .Nm counters_free ,
+.Nm COUNTERS_BOOT_MEMORY ,
+.Nm COUNTERS_BOOT_INITIALIZER ,
+.Nm counters_alloc_ncpus ,
 .Nm counters_enter ,
 .Nm counters_leave ,
 .Nm counters_read ,
@@ -31,6 +34,14 @@
 .Fn counters_alloc "unsigned int ncounters" "int type"
 .Ft void
 .Fn counters_free "struct cpumem *cm" "unsigned int ncounters" "int type"
+.Fn COUNTERS_BOOT_MEMORY "NAME" "unsigned int ncounters"
+.Fn COUNTERS_BOOT_INITIALIZER "NAME"
+.Ft struct cpumemt *
+.Fo counters_alloc_ncpus
+.Fa "struct cpumem *cm"
+.Fa "unsigned int ncounters"
+.Fa "int type"
+.Fc
 .Ft uint64_t *
 .Fn counters_enter "struct counters_ref *ref" "struct cpumem *cm"
 .Ft void
@@ -84,6 +95,60 @@ arguments type originally provided to
 must be passed to
 .Fn counters_free .
 .Pp
+If a set of per CPU counters needs to be usable as soon as the
+kernel is booted, instead of after devices (which includes CPUs)
+are attached, a cpumem pointer and counters for the boot CPU may be
+statically allocated.
+.Pp
+.Fn COUNTERS_BOOT_MEMORY
+allocates counters for use by the boot CPU in the kernel and before
+the other CPUs are attached and run.
+The allocation is identified by
+.Fa NAME ,
+and provides memory for the number of counters specified by
+.Fa ncounters .
+.Pp
+.Pp
+.Fn COUNTERS_BOOT_INITIALIZER
+is used to initialise a cpumem pointer with the memory that was previously
+allocated using
+.Fn COUNTERS_BOOT_MEMORY
+and identified by
+.Fa NAME .
+.Pp
+.Fn counters_alloc_ncpus
+allocates additional per CPU counters for the CPUs that were attached
+during boot to the cpumem structure
+.Fa cm
+that was previously allocated statically using
+.Fn COUNTERS_BOOT_MEMORY
+and initialised with
+.Fn COUNTERS_BOOT_INITIALIZER .
+.Fn counters_alloc_ncpus
+allocates space for a number of counters specified by
+.Fa ncounters .
+The
+.Fa type
+argument specifies the type of memory that the counters will be
+allocated as via
+.Xr malloc 9 .
+The memory will be zeroed on allocation by passing
+.Fn M_ZERO
+to
+.Xr malloc 9 .
+The same number of counters originally passed to
+.Fa COUNTERS_BOOT_MEMORY
+must be specified by
+.Fa ncounters .
+.Pp
+Counters that have been allocated with
+.Fn COUNTERS_BOOT_MEMORY
+and
+.Fn counters_alloc_ncpus
+cannot be deallocated with
+.Fa counters_free .
+Any attempt to do so will lead to undefined behaviour.
+.Pp
 .Fn counters_enter
 provides access to the current CPU's set of counters referenced by
 .Fa cm .
@@ -119,6 +184,7 @@ up to the caller to serialise this call 
 .Sh CONTEXT
 .Fn counters_alloc ,
 .Fn counters_free ,
+.Fn counters_alloc_ncpus ,
 and
 .Fn counters_read
 may be called during autoconf, or from process context.
@@ -136,7 +202,9 @@ It is up to the caller to provide approp
 around calls to these functions to prevent concurrent access to the
 relevant data structures.
 .Sh RETURN VALUES
-.Fn counters_get
+.Fn counters_alloc
+and
+.Fn counters_alloc_ncpus
 will return an opaque cpumem pointer that references each CPU's
 set of counters.
 .Pp
Index: share/man/man9/cpumem_get.9
===================================================================
RCS file: /cvs/src/share/man/man9/cpumem_get.9,v
retrieving revision 1.5
diff -u -p -r1.5 cpumem_get.9
--- share/man/man9/cpumem_get.9 21 Oct 2016 15:00:30 -0000      1.5
+++ share/man/man9/cpumem_get.9 24 Oct 2016 04:43:33 -0000
@@ -21,7 +21,10 @@
 .Nm cpumem_get ,
 .Nm cpumem_put ,
 .Nm cpumem_malloc ,
+.Nm cpumem_malloc_ncpus ,
 .Nm cpumem_free ,
+.Nm CPUMEM_BOOT_MEMORY ,
+.Nm CPUMEM_BOOT_INITIALIZER ,
 .Nm cpumem_enter ,
 .Nm cpumem_leave ,
 .Nm cpumem_first ,
@@ -37,6 +40,10 @@
 .Fn cpumem_malloc "size_t sz" "int type"
 .Ft void
 .Fn cpumem_free "struct cpumem *cm" "int type" "size_t sz"
+.Fn CPUMEM_BOOT_MEMORY "NAME" "size_t sz"
+.Fn CPUMEM_BOOT_INITIALIZER "NAME"
+.Ft struct cpumem *
+.Fn cpumem_malloc_ncpus "struct cpumem *cm" "size_t sz" "int type"
 .Ft void *
 .Fn cpumem_enter "struct cpumem *cm"
 .Ft void
@@ -100,6 +107,59 @@ must be specified by
 and
 .Fa type
 respectively.
+.Pp
+If a per CPU memory allocation needs to be usable as soon as the
+kernel is booted, instead of after devices (which includes CPUs)
+are attached, a cpumem pointer and memory for the boot CPU may be
+statically allocated.
+.Pp
+.Fn CPUMEM_BOOT_MEMORY
+allocates memory for use by the boot CPU in the kernel and before
+the other CPUs are attached and run.  The allocation is identified
+by
+.Fn NAME ,
+and provides
+.Fn sz
+bytes as the boot CPUs memory allocation.
+.Pp
+.Fn CPUMEM_BOOT_INITIALIZER
+is used to initialise a cpumem pointer with the memory that was previously
+allocated using
+.Fn CPUMEM_BOOT_MEMORY
+and identified by
+.Fa NAME .
+.Pp
+.Fn cpumem_malloc_ncpus
+allocates additional per CPU memory for the additional CPUs that
+were attached by the kernel during boot to the cpumem structure
+.Fa cm
+that was previously allocated statically using
+.Fn CPUMEM_BOOT_MEMORY and
+initialized with
+.Fn CPUMEM_BOOT_INITIALIZER .
+.Fn cpumem_malloc_ncpus
+allocates
+.Fa sz
+bytes of
+.Fa type
+memory for each additional CPU using
+.Xr malloc 9 .
+The memory will be zeroed on allocation by passing
+.Fn M_ZERO
+to
+.Xr malloc 9 .
+The same object size originally passed to
+.Fa CPUMEM_BOOT_MEMORY
+must be specified by
+.Fa sz .
+.Pp
+Memory that has been allocated with
+.Fn CPUMEM_BOOT_MEMORY
+and
+.Fn cpumem_malloc_ncpus
+cannot be deallocated with
+.Fa cpumem_free .
+Any attempt to do so will lead to undefined behaviour.
 .Ss Per CPU Memory Access
 .Fn cpumem_enter
 provides access to the current CPU's memory allocation referenced by
@@ -136,8 +196,9 @@ to each CPU's allocation in turn.
 .Fn cpumem_get ,
 .Fn cpumem_put ,
 .Fn cpumem_malloc ,
+.Fn cpumem_free ,
 and
-.Fn cpumem_free
+.Fn cpumem_malloc_ncpus
 may be called during autoconf, or from process context.
 .Pp
 .Fn cpumem_enter ,
@@ -154,9 +215,10 @@ It is up to the caller to provide approp
 around calls to these functions to prevent concurrent access to the
 relevant data structures.
 .Sh RETURN VALUES
-.Fn cpumem_get
+.Fn cpumem_get ,
+.Fn cpumem_malloc ,
 and
-.Fn cpumem_malloc
+.Fn cpumem_malloc_ncpus
 will return an opaque cpumem pointer that references each CPU's
 memory allocation.
 .Pp
Index: sys/kern/subr_percpu.c
===================================================================
RCS file: /cvs/src/sys/kern/subr_percpu.c,v
retrieving revision 1.3
diff -u -p -r1.3 subr_percpu.c
--- sys/kern/subr_percpu.c      24 Oct 2016 03:15:38 -0000      1.3
+++ sys/kern/subr_percpu.c      24 Oct 2016 04:43:34 -0000
@@ -76,7 +76,7 @@ cpumem_malloc(size_t sz, int type)
 }
 
 struct cpumem *
-cpumem_realloc(struct cpumem *bootcm, size_t sz, int type)
+cpumem_alloc_ncpus(struct cpumem *bootcm, size_t sz, int type)
 {
        struct cpumem *cm;
        unsigned int cpu;
@@ -146,10 +146,10 @@ counters_alloc(unsigned int n, int type)
 }
 
 struct cpumem *
-counters_realloc(struct cpumem *cm, unsigned int n, int type)
+counters_alloc_ncpus(struct cpumem *cm, unsigned int n, int type)
 {
        n++; /* the generation number */
-       return (cpumem_realloc(cm, n * sizeof(uint64_t), type));
+       return (cpumem_alloc_ncpus(cm, n * sizeof(uint64_t), type));
 }
 
 void
@@ -259,7 +259,7 @@ cpumem_malloc(size_t sz, int type)
 }
 
 struct cpumem *
-cpumem_realloc(struct cpumem *cm, size_t sz, int type)
+cpumem_alloc_ncpus(struct cpumem *cm, size_t sz, int type)
 {
        return (cm);
 }
@@ -291,10 +291,10 @@ counters_alloc(unsigned int n, int type)
 }
 
 struct cpumem *
-counters_realloc(struct cpumem *cm, unsigned int n, int type)
+counters_alloc_ncpus(struct cpumem *cm, unsigned int n, int type)
 {
        /* this is unecessary, but symmetrical */
-       return (cpumem_realloc(cm, n * sizeof(uint64_t), type));
+       return (cpumem_alloc_ncpus(cm, n * sizeof(uint64_t), type));
 }
 
 void
Index: sys/kern/uipc_mbuf.c
===================================================================
RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v
retrieving revision 1.234
diff -u -p -r1.234 uipc_mbuf.c
--- sys/kern/uipc_mbuf.c        24 Oct 2016 04:38:44 -0000      1.234
+++ sys/kern/uipc_mbuf.c        24 Oct 2016 04:43:34 -0000
@@ -178,7 +178,7 @@ mbinit(void)
 void
 mbcpuinit()
 {
-       mbstat = counters_realloc(mbstat, MBSTAT_COUNT, M_DEVBUF);
+       mbstat = counters_alloc_ncpus(mbstat, MBSTAT_COUNT, M_DEVBUF);
 }
 
 void
Index: sys/sys/percpu.h
===================================================================
RCS file: /cvs/src/sys/sys/percpu.h,v
retrieving revision 1.2
diff -u -p -r1.2 percpu.h
--- sys/sys/percpu.h    24 Oct 2016 03:15:35 -0000      1.2
+++ sys/sys/percpu.h    24 Oct 2016 04:43:34 -0000
@@ -54,7 +54,7 @@ struct cpumem *cpumem_get(struct pool *)
 void            cpumem_put(struct pool *, struct cpumem *);
 
 struct cpumem  *cpumem_malloc(size_t, int);
-struct cpumem  *cpumem_realloc(struct cpumem *, size_t, int);
+struct cpumem  *cpumem_malloc_ncpus(struct cpumem *, size_t, int);
 void            cpumem_free(struct cpumem *, int, size_t);
 
 void           *cpumem_first(struct cpumem_iter *, struct cpumem *);
@@ -111,7 +111,7 @@ static struct {                                             
                \
  */
 
 struct cpumem  *counters_alloc(unsigned int, int);
-struct cpumem  *counters_realloc(struct cpumem *, unsigned int, int);
+struct cpumem  *counters_alloc_ncpus(struct cpumem *, unsigned int, int);
 void            counters_free(struct cpumem *, int, unsigned int);
 void            counters_read(struct cpumem *, uint64_t *, unsigned int);
 void            counters_zero(struct cpumem *, unsigned int);

Reply via email to