diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2008-12-11 16:45:46 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2008-12-11 16:45:46 +0000 |
commit | 7505ac789440ab79520a3193eb85316c416adfc9 (patch) | |
tree | a190176a8196341bf5934cdcf75c9ce69d98808a /sys | |
parent | 2de9b65c30130b7b1a5e668c58a11cbfaf47c881 (diff) |
export per-interface mbuf cluster pool use statistics out to userland
inside if_data, so that netstat(1) and systat(1) can see them
ok dlg
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/uipc_mbuf.c | 97 | ||||
-rw-r--r-- | sys/net/if.c | 100 | ||||
-rw-r--r-- | sys/net/if.h | 27 | ||||
-rw-r--r-- | sys/sys/mbuf.h | 3 |
4 files changed, 114 insertions, 113 deletions
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index bae66752398..7259693222c 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uipc_mbuf.c,v 1.108 2008/12/04 23:40:44 dlg Exp $ */ +/* $OpenBSD: uipc_mbuf.c,v 1.109 2008/12/11 16:45:45 deraadt Exp $ */ /* $NetBSD: uipc_mbuf.c,v 1.15.4.1 1996/06/13 17:11:44 cgd Exp $ */ /* @@ -270,6 +270,101 @@ m_getclr(int nowait, int type) } void +m_clinitifp(struct ifnet *ifp) +{ + struct mclpool *mclp = ifp->if_data.ifi_mclpool; + extern u_int mclsizes[]; + int i; + + /* Initialize high water marks for use of cluster pools */ + for (i = 0; i < MCLPOOLS; i++) { + mclp[i].mcl_hwm = MAX(4, mclp[i].mcl_lwm); + mclp[i].mcl_size = mclsizes[i]; + } +} + +void +m_clsetlwm(struct ifnet *ifp, u_int pktlen, u_int lwm) +{ + extern u_int mclsizes[]; + int i; + + for (i = 0; i < MCLPOOLS; i++) { + if (pktlen <= mclsizes[i]) + break; + } + if (i >= MCLPOOLS) + return; + + ifp->if_data.ifi_mclpool[i].mcl_lwm = lwm; +} + +extern int m_clticks; +int m_livelock; + +int +m_cldrop(struct ifnet *ifp, int pi) +{ + static int liveticks; + struct mclpool *mclp; + extern int ticks; + int i; + + if (m_livelock == 0 && ticks - m_clticks > 2) { + struct ifnet *aifp; + + /* + * Timeout did not run, so we are in some kind of livelock. + * Decrease the cluster allocation high water marks on all + * interfaces and prevent them from growth for the very near + * future. + */ + m_livelock = 1; + ifp->if_data.ifi_livelocks++; + liveticks = ticks; + TAILQ_FOREACH(aifp, &ifnet, if_list) { + mclp = aifp->if_data.ifi_mclpool; + for (i = 0; i < nitems(mclp); i++) + mclp[i].mcl_hwm = + max(mclp[i].mcl_hwm / 2,mclp[i].mcl_lwm); + } + } else if (m_livelock && ticks - liveticks > 5) + m_livelock = 0; /* Let the high water marks grow again */ + + mclp = ifp->if_data.ifi_mclpool; + if (mclp[pi].mcl_alive <= 2 && mclp[pi].mcl_hwm < 32768 && + ISSET(ifp->if_flags, IFF_RUNNING) && m_livelock == 0) { + /* About to run out, so increase the watermark */ + mclp[pi].mcl_hwm++; + } else if (mclp[pi].mcl_alive >= mclp[pi].mcl_hwm) + return (1); /* No more packets given */ + + return (0); +} + +void +m_clcount(struct ifnet *ifp, int pi) +{ + ifp->if_data.ifi_mclpool[pi].mcl_alive++; +} + +void +m_cluncount(struct mbuf *m, int all) +{ + struct mbuf_ext *me; + + do { + me = &m->m_ext; + if (((m->m_flags & (M_EXT|M_CLUSTER)) != (M_EXT|M_CLUSTER)) || + (me->ext_ifp == NULL)) + continue; + + me->ext_ifp->if_data.ifi_mclpool[me->ext_backend].mcl_alive--; + me->ext_ifp = NULL; + } while (all && (m = m->m_next)); +} + +void m_clget(struct mbuf *m, int how, struct ifnet *ifp, u_int pktlen) { struct pool *mclp; diff --git a/sys/net/if.c b/sys/net/if.c index 62529c17933..ebe573a28fd 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.183 2008/11/26 19:07:33 deraadt Exp $ */ +/* $OpenBSD: if.c,v 1.184 2008/12/11 16:45:45 deraadt Exp $ */ /* $NetBSD: if.c,v 1.35 1996/05/07 05:26:04 thorpej Exp $ */ /* @@ -147,14 +147,12 @@ struct if_clone *if_clone_lookup(const char *, int *); void if_congestion_clear(void *); int if_group_egress_build(void); -void m_clinitifp(struct ifnet *); - TAILQ_HEAD(, ifg_group) ifg_head; LIST_HEAD(, if_clone) if_cloners = LIST_HEAD_INITIALIZER(if_cloners); int if_cloners_count; -int m_clticks; struct timeout m_cltick_tmo; +int m_clticks; /* * Record when the last timeout has been run. If the delta is @@ -165,6 +163,7 @@ static void m_cltick(void *arg) { extern int ticks; + extern void m_cltick(void *); m_clticks = ticks; timeout_add(&m_cltick_tmo, 1); @@ -2035,96 +2034,3 @@ sysctl_ifq(int *name, u_int namelen, void *oldp, size_t *oldlenp, } /* NOTREACHED */ } - -void -m_clinitifp(struct ifnet *ifp) -{ - extern u_int mclsizes[]; - int i; - - /* Initialize high water marks for use of cluster pools */ - for (i = 0; i < MCLPOOLS; i++) { - ifp->if_mclstat.mclpool[i].mcl_hwm = MAX(4, - ifp->if_mclstat.mclpool[i].mcl_lwm); - ifp->if_mclstat.mclpool[i].mcl_size = mclsizes[i]; - } -} - -void -m_clsetlwm(struct ifnet *ifp, u_int pktlen, u_int lwm) -{ - extern u_int mclsizes[]; - int i; - - for (i = 0; i < MCLPOOLS; i++) { - if (pktlen <= mclsizes[i]) - break; - } - if (i >= MCLPOOLS) - return; - - ifp->if_mclstat.mclpool[i].mcl_lwm = lwm; -} - -int -m_cldrop(struct ifnet *ifp, int pi) -{ - static int livelock, liveticks; - struct mclstat *mcls; - extern int ticks; - int i; - - if (livelock == 0 && ticks - m_clticks > 2) { - struct ifnet *aifp; - - /* - * Timeout did not run, so we are in some kind of livelock. - * Decrease the cluster allocation high water marks on all - * interfaces and prevent them from growth for the very near - * future. - */ - livelock = 1; - liveticks = ticks; - TAILQ_FOREACH(aifp, &ifnet, if_list) { - mcls = &aifp->if_mclstat; - for (i = 0; i < nitems(mcls->mclpool); i++) - mcls->mclpool[i].mcl_hwm = - max(mcls->mclpool[i].mcl_hwm / 2, - mcls->mclpool[i].mcl_lwm); - } - } else if (livelock && ticks - liveticks > 5) - livelock = 0; /* Let the high water marks grow again */ - - mcls = &ifp->if_mclstat; - if (mcls->mclpool[pi].mcl_alive <= 2 && - mcls->mclpool[pi].mcl_hwm < 32768 && - ISSET(ifp->if_flags, IFF_RUNNING) && livelock == 0) { - /* About to run out, so increase the watermark */ - mcls->mclpool[pi].mcl_hwm++; - } else if (mcls->mclpool[pi].mcl_alive >= mcls->mclpool[pi].mcl_hwm) - return (1); /* No more packets given */ - - return (0); -} - -void -m_clcount(struct ifnet *ifp, int pi) -{ - ifp->if_mclstat.mclpool[pi].mcl_alive++; -} - -void -m_cluncount(struct mbuf *m, int all) -{ - struct mbuf_ext *me; - - do { - me = &m->m_ext; - if (((m->m_flags & (M_EXT|M_CLUSTER)) != (M_EXT|M_CLUSTER)) || - (me->ext_ifp == NULL)) - continue; - - me->ext_ifp->if_mclstat.mclpool[me->ext_backend].mcl_alive--; - me->ext_ifp = NULL; - } while (all && (m = m->m_next)); -} diff --git a/sys/net/if.h b/sys/net/if.h index 4fe077e2458..74235314a51 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if.h,v 1.100 2008/11/30 00:14:42 brad Exp $ */ +/* $OpenBSD: if.h,v 1.101 2008/12/11 16:45:45 deraadt Exp $ */ /* $NetBSD: if.h,v 1.23 1996/05/07 02:40:27 thorpej Exp $ */ /* @@ -104,6 +104,15 @@ struct if_clonereq { char *ifcr_buffer; /* buffer for cloner names */ }; +#define MCLPOOLS 7 /* number of cluster pools */ + +struct mclpool { + u_short mcl_alive; + u_short mcl_hwm; + u_short mcl_size; + u_short mcl_lwm; +}; + /* * Structure defining statistics and other data kept regarding a network * interface. @@ -131,6 +140,9 @@ struct if_data { u_int64_t ifi_iqdrops; /* dropped on input, this interface */ u_int64_t ifi_noproto; /* destined for unsupported protocol */ struct timeval ifi_lastchange; /* last operational state change */ + + struct mclpool ifi_mclpool[MCLPOOLS]; + u_int64_t ifi_livelocks; /* livelocks migitaged */ }; /* @@ -146,17 +158,6 @@ struct ifqueue { struct timeout *ifq_congestion; }; -#define MCLPOOLS 7 /* number of cluster pools */ - -struct mclstat { - struct { - u_short mcl_alive; - u_short mcl_hwm; - u_short mcl_size; - u_short mcl_lwm; - } mclpool[MCLPOOLS]; -}; - /* * Values for if_link_state. */ @@ -235,8 +236,6 @@ struct ifnet { /* and the entries */ struct sockaddr_dl *if_sadl; /* pointer to our sockaddr_dl */ void *if_afdata[AF_MAX]; - - struct mclstat if_mclstat; /* mbuf cluster pool stats */ }; #define if_mtu if_data.ifi_mtu #define if_type if_data.ifi_type diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h index 315ccd85c9a..fc15c7d0813 100644 --- a/sys/sys/mbuf.h +++ b/sys/sys/mbuf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbuf.h,v 1.118 2008/11/26 17:36:23 dlg Exp $ */ +/* $OpenBSD: mbuf.h,v 1.119 2008/12/11 16:45:44 deraadt Exp $ */ /* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */ /* @@ -432,6 +432,7 @@ void m_clsetlwm(struct ifnet *, u_int, u_int); int m_cldrop(struct ifnet *, int); void m_clcount(struct ifnet *, int); void m_cluncount(struct mbuf *, int); +void m_clinitifp(struct ifnet *); void m_adj(struct mbuf *, int); void m_copyback(struct mbuf *, int, int, const void *); void m_freem(struct mbuf *); |