summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/kern/init_main.c4
-rw-r--r--sys/kern/kern_sysctl.c24
-rw-r--r--sys/kern/uipc_mbuf.c54
-rw-r--r--sys/sys/mbuf.h11
4 files changed, 73 insertions, 20 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index d65e00cfa82..90cdd985516 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.260 2016/10/21 06:27:50 dlg Exp $ */
+/* $OpenBSD: init_main.c,v 1.261 2016/10/24 04:38:44 dlg Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -415,6 +415,8 @@ main(void *framep)
prof_init();
#endif
+ mbcpuinit(); /* enable per cpu mbuf data */
+
/* init exec and emul */
init_exec();
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index ab67f6d1d82..294b28b095c 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_sysctl.c,v 1.317 2016/10/22 04:39:18 guenther Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.318 2016/10/24 04:38:44 dlg Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
@@ -62,6 +62,7 @@
#include <sys/namei.h>
#include <sys/exec.h>
#include <sys/mbuf.h>
+#include <sys/percpu.h>
#include <sys/sensors.h>
#include <sys/pipe.h>
#include <sys/eventvar.h>
@@ -390,9 +391,24 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
case KERN_FILE:
return (sysctl_file(name + 1, namelen - 1, oldp, oldlenp, p));
#endif
- case KERN_MBSTAT:
- return (sysctl_rdstruct(oldp, oldlenp, newp, &mbstat,
- sizeof(mbstat)));
+ case KERN_MBSTAT: {
+ extern struct cpumem *mbstat;
+ uint64_t counters[MBSTAT_COUNT];
+ struct mbstat mbs;
+ unsigned int i;
+
+ memset(&mbs, 0, sizeof(mbs));
+ counters_read(mbstat, counters, MBSTAT_COUNT);
+ for (i = 0; i < MBSTAT_TYPES; i++)
+ mbs.m_mtypes[i] = counters[i];
+
+ mbs.m_drops = counters[MBSTAT_DROPS];
+ mbs.m_wait = counters[MBSTAT_WAIT];
+ mbs.m_drain = counters[MBSTAT_DRAIN];
+
+ return (sysctl_rdstruct(oldp, oldlenp, newp,
+ &mbs, sizeof(mbs)));
+ }
#if defined(GPROF) || defined(DDBPROF)
case KERN_PROF:
return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp,
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 30841a9bd50..ae91a517d1d 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uipc_mbuf.c,v 1.233 2016/10/10 00:41:17 dlg Exp $ */
+/* $OpenBSD: uipc_mbuf.c,v 1.234 2016/10/24 04:38:44 dlg Exp $ */
/* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */
/*
@@ -83,6 +83,7 @@
#include <sys/domain.h>
#include <sys/protosw.h>
#include <sys/pool.h>
+#include <sys/percpu.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
@@ -99,9 +100,11 @@
#include <net/pfvar.h>
#endif /* NPF > 0 */
-struct mbstat mbstat; /* mbuf stats */
-struct mutex mbstatmtx = MUTEX_INITIALIZER(IPL_NET);
-struct pool mbpool; /* mbuf pool */
+/* mbuf stats */
+COUNTERS_BOOT_MEMORY(mbstat_boot, MBSTAT_COUNT);
+struct cpumem *mbstat = COUNTERS_BOOT_INITIALIZER(mbstat_boot);
+/* mbuf pools */
+struct pool mbpool;
struct pool mtagpool;
/* mbuf cluster pools */
@@ -173,6 +176,12 @@ mbinit(void)
}
void
+mbcpuinit()
+{
+ mbstat = counters_realloc(mbstat, MBSTAT_COUNT, M_DEVBUF);
+}
+
+void
nmbclust_update(void)
{
unsigned int i, n;
@@ -204,14 +213,21 @@ struct mbuf *
m_get(int nowait, int type)
{
struct mbuf *m;
+ struct counters_ref cr;
+ uint64_t *counters;
+ int s;
+
+ KDASSERT(type < MT_NTYPES);
m = pool_get(&mbpool, nowait == M_WAIT ? PR_WAITOK : PR_NOWAIT);
if (m == NULL)
return (NULL);
- mtx_enter(&mbstatmtx);
- mbstat.m_mtypes[type]++;
- mtx_leave(&mbstatmtx);
+ s = splnet();
+ counters = counters_enter(&cr, mbstat);
+ counters[type]++;
+ counters_leave(&cr, mbstat);
+ splx(s);
m->m_type = type;
m->m_next = NULL;
@@ -230,14 +246,21 @@ struct mbuf *
m_gethdr(int nowait, int type)
{
struct mbuf *m;
+ struct counters_ref cr;
+ uint64_t *counters;
+ int s;
+
+ KDASSERT(type < MT_NTYPES);
m = pool_get(&mbpool, nowait == M_WAIT ? PR_WAITOK : PR_NOWAIT);
if (m == NULL)
return (NULL);
- mtx_enter(&mbstatmtx);
- mbstat.m_mtypes[type]++;
- mtx_leave(&mbstatmtx);
+ s = splnet();
+ counters = counters_enter(&cr, mbstat);
+ counters[type]++;
+ counters_leave(&cr, mbstat);
+ splx(s);
m->m_type = type;
@@ -349,13 +372,18 @@ struct mbuf *
m_free(struct mbuf *m)
{
struct mbuf *n;
+ struct counters_ref cr;
+ uint64_t *counters;
+ int s;
if (m == NULL)
return (NULL);
- mtx_enter(&mbstatmtx);
- mbstat.m_mtypes[m->m_type]--;
- mtx_leave(&mbstatmtx);
+ s = splnet();
+ counters = counters_enter(&cr, mbstat);
+ counters[m->m_type]--;
+ counters_leave(&cr, mbstat);
+ splx(s);
n = m->m_next;
if (m->m_flags & M_ZEROIZE) {
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
index 26d6ad51b68..eb7200a560b 100644
--- a/sys/sys/mbuf.h
+++ b/sys/sys/mbuf.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mbuf.h,v 1.221 2016/10/17 02:53:47 lteo Exp $ */
+/* $OpenBSD: mbuf.h,v 1.222 2016/10/24 04:38:44 dlg Exp $ */
/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
/*
@@ -236,6 +236,7 @@ struct mbuf {
#define MT_FTABLE 5 /* fragment reassembly header */
#define MT_CONTROL 6 /* extra-data protocol message */
#define MT_OOBDATA 7 /* expedited data */
+#define MT_NTYPES 8
/* flowid field */
#define M_FLOWID_VALID 0x8000 /* is the flowid set */
@@ -393,6 +394,12 @@ struct mbstat {
u_short m_mtypes[256]; /* type specific mbuf allocations */
};
+#define MBSTAT_TYPES MT_NTYPES
+#define MBSTAT_DROPS (MBSTAT_TYPES + 0)
+#define MBSTAT_WAIT (MBSTAT_TYPES + 1)
+#define MBSTAT_DRAIN (MBSTAT_TYPES + 2)
+#define MBSTAT_COUNT (MBSTAT_TYPES + 3)
+
#include <sys/mutex.h>
struct mbuf_list {
@@ -410,7 +417,6 @@ struct mbuf_queue {
#ifdef _KERNEL
-extern struct mbstat mbstat;
extern int nmbclust; /* limit on the # of clusters */
extern int mblowat; /* mbuf low water mark */
extern int mcllowat; /* mbuf cluster low water mark */
@@ -419,6 +425,7 @@ extern int max_protohdr; /* largest protocol header */
extern int max_hdr; /* largest link+protocol header */
void mbinit(void);
+void mbcpuinit(void);
struct mbuf *m_copym(struct mbuf *, int, int, int);
struct mbuf *m_free(struct mbuf *);
struct mbuf *m_get(int, int);