As proposed by mpi@ in http://marc.info/?l=openbsd-tech&m=148585429014645&w=2
I think that choosing a "proper" type doesn't bring much information, and having one parameter less makes things simpler. mbuf counters move from M_DEVBUF to M_COUNTERS as a result, but I can't see a reason for those to be special. Comments / oks? Index: kern/subr_percpu.c =================================================================== RCS file: /d/cvs/src/sys/kern/subr_percpu.c,v retrieving revision 1.6 diff -u -p -r1.6 subr_percpu.c --- kern/subr_percpu.c 11 Jan 2017 17:46:28 -0000 1.6 +++ kern/subr_percpu.c 31 Jan 2017 11:19:51 -0000 @@ -125,7 +125,7 @@ cpumem_next(struct cpumem_iter *i, struc } struct cpumem * -counters_alloc(unsigned int n, int type) +counters_alloc(unsigned int n) { struct cpumem *cm; struct cpumem_iter cmi; @@ -135,7 +135,7 @@ counters_alloc(unsigned int n, int type) KASSERT(n > 0); n++; /* add space for a generation number */ - cm = cpumem_malloc(n * sizeof(uint64_t), type); + cm = cpumem_malloc(n * sizeof(uint64_t), M_COUNTERS); CPUMEM_FOREACH(counters, &cmi, cm) { for (i = 0; i < n; i++) @@ -146,17 +146,17 @@ counters_alloc(unsigned int n, int type) } struct cpumem * -counters_alloc_ncpus(struct cpumem *cm, unsigned int n, int type) +counters_alloc_ncpus(struct cpumem *cm, unsigned int n) { n++; /* the generation number */ - return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), type)); + return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), M_COUNTERS)); } void -counters_free(struct cpumem *cm, int type, unsigned int n) +counters_free(struct cpumem *cm, unsigned int n) { n++; /* generation number */ - cpumem_free(cm, type, n * sizeof(uint64_t)); + cpumem_free(cm, M_COUNTERS, n * sizeof(uint64_t)); } void @@ -284,24 +284,24 @@ cpumem_next(struct cpumem_iter *i, struc } struct cpumem * -counters_alloc(unsigned int n, int type) +counters_alloc(unsigned int n) { KASSERT(n > 0); - return (cpumem_malloc(n * sizeof(uint64_t), type)); + return (cpumem_malloc(n * sizeof(uint64_t), M_COUNTERS)); } struct cpumem * -counters_alloc_ncpus(struct cpumem *cm, unsigned int n, int type) +counters_alloc_ncpus(struct cpumem *cm, unsigned int n) { /* this is unecessary, but symmetrical */ - return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), type)); + return (cpumem_malloc_ncpus(cm, n * sizeof(uint64_t), M_COUNTERS)); } void -counters_free(struct cpumem *cm, int type, unsigned int n) +counters_free(struct cpumem *cm, unsigned int n) { - cpumem_free(cm, type, n * sizeof(uint64_t)); + cpumem_free(cm, M_COUNTERS, n * sizeof(uint64_t)); } void Index: kern/uipc_mbuf.c =================================================================== RCS file: /d/cvs/src/sys/kern/uipc_mbuf.c,v retrieving revision 1.240 diff -u -p -r1.240 uipc_mbuf.c --- kern/uipc_mbuf.c 25 Jan 2017 09:41:45 -0000 1.240 +++ kern/uipc_mbuf.c 31 Jan 2017 11:22:42 -0000 @@ -186,7 +186,7 @@ mbinit(void) void mbcpuinit() { - mbstat = counters_alloc_ncpus(mbstat, MBSTAT_COUNT, M_DEVBUF); + mbstat = counters_alloc_ncpus(mbstat, MBSTAT_COUNT); } void Index: net/route.c =================================================================== RCS file: /d/cvs/src/sys/net/route.c,v retrieving revision 1.349 diff -u -p -r1.349 route.c --- net/route.c 24 Jan 2017 10:08:30 -0000 1.349 +++ net/route.c 31 Jan 2017 11:22:55 -0000 @@ -191,7 +191,7 @@ TAILQ_HEAD(rt_labels, rt_label) rt_label void route_init(void) { - rtcounters = counters_alloc(rts_ncounters, M_COUNTERS); + rtcounters = counters_alloc(rts_ncounters); pool_init(&rtentry_pool, sizeof(struct rtentry), 0, IPL_SOFTNET, 0, "rtentry", NULL); Index: netinet/igmp.c =================================================================== RCS file: /d/cvs/src/sys/netinet/igmp.c,v retrieving revision 1.62 diff -u -p -r1.62 igmp.c --- netinet/igmp.c 29 Jan 2017 19:58:47 -0000 1.62 +++ netinet/igmp.c 31 Jan 2017 11:23:07 -0000 @@ -118,7 +118,7 @@ igmp_init(void) igmp_timers_are_running = 0; rti_head = 0; - igmpcounters = counters_alloc(igps_ncounters, M_COUNTERS); + igmpcounters = counters_alloc(igps_ncounters); router_alert = m_get(M_DONTWAIT, MT_DATA); if (router_alert == NULL) { printf("%s: no mbuf\n", __func__); Index: netinet/ip_input.c =================================================================== RCS file: /d/cvs/src/sys/netinet/ip_input.c,v retrieving revision 1.293 diff -u -p -r1.293 ip_input.c --- netinet/ip_input.c 29 Jan 2017 19:58:47 -0000 1.293 +++ netinet/ip_input.c 31 Jan 2017 11:23:41 -0000 @@ -167,7 +167,7 @@ ip_init(void) const u_int16_t defrootonlyports_tcp[] = DEFROOTONLYPORTS_TCP; const u_int16_t defrootonlyports_udp[] = DEFROOTONLYPORTS_UDP; - ipcounters = counters_alloc(ips_ncounters, M_COUNTERS); + ipcounters = counters_alloc(ips_ncounters); pool_init(&ipqent_pool, sizeof(struct ipqent), 0, IPL_SOFTNET, 0, "ipqe", NULL); Index: netinet/udp_usrreq.c =================================================================== RCS file: /d/cvs/src/sys/netinet/udp_usrreq.c,v retrieving revision 1.229 diff -u -p -r1.229 udp_usrreq.c --- netinet/udp_usrreq.c 29 Jan 2017 19:58:47 -0000 1.229 +++ netinet/udp_usrreq.c 31 Jan 2017 11:23:31 -0000 @@ -143,7 +143,7 @@ int udp_sysctl_udpstat(void *, size_t *, void udp_init(void) { - udpcounters = counters_alloc(udps_ncounters, M_COUNTERS); + udpcounters = counters_alloc(udps_ncounters); in_pcbinit(&udbtable, UDB_INITIAL_HASH_SIZE); } Index: sys/percpu.h =================================================================== RCS file: /d/cvs/src/sys/sys/percpu.h,v retrieving revision 1.5 diff -u -p -r1.5 percpu.h --- sys/percpu.h 20 Dec 2016 12:07:14 -0000 1.5 +++ sys/percpu.h 31 Jan 2017 11:27:17 -0000 @@ -110,9 +110,9 @@ static struct { \ * per cpu counters */ -struct cpumem *counters_alloc(unsigned int, int); -struct cpumem *counters_alloc_ncpus(struct cpumem *, unsigned int, int); -void counters_free(struct cpumem *, int, unsigned int); +struct cpumem *counters_alloc(unsigned int); +struct cpumem *counters_alloc_ncpus(struct cpumem *, unsigned int); +void counters_free(struct cpumem *, unsigned int); void counters_read(struct cpumem *, uint64_t *, unsigned int); void counters_zero(struct cpumem *, unsigned int); -- jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE