svn commit: r332338 - in user/markj/netdump/sys: dev/alc dev/bge dev/bxe dev/cxgb dev/mlx4/mlx4_en dev/re dev/virtio/network kern net netinet/netdump sys
Mark Johnston
markj at FreeBSD.org
Mon Apr 9 21:37:41 UTC 2018
Author: markj
Date: Mon Apr 9 21:37:39 2018
New Revision: 332338
URL: https://svnweb.freebsd.org/changeset/base/332338
Log:
Query the driver for its rx buffer size rather than forcing MCLBYTES.
Reinitialize the netdump mbuf pool from the generic SIOCSIFMTU handler.
Modified:
user/markj/netdump/sys/dev/alc/if_alc.c
user/markj/netdump/sys/dev/bge/if_bge.c
user/markj/netdump/sys/dev/bxe/bxe.c
user/markj/netdump/sys/dev/cxgb/cxgb_main.c
user/markj/netdump/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c
user/markj/netdump/sys/dev/re/if_re.c
user/markj/netdump/sys/dev/virtio/network/if_vtnet.c
user/markj/netdump/sys/kern/kern_mbuf.c
user/markj/netdump/sys/net/if.c
user/markj/netdump/sys/net/iflib.c
user/markj/netdump/sys/netinet/netdump/netdump.h
user/markj/netdump/sys/netinet/netdump/netdump_client.c
user/markj/netdump/sys/sys/mbuf.h
Modified: user/markj/netdump/sys/dev/alc/if_alc.c
==============================================================================
--- user/markj/netdump/sys/dev/alc/if_alc.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/dev/alc/if_alc.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -4658,25 +4658,20 @@ sysctl_hw_alc_int_mod(SYSCTL_HANDLER_ARGS)
#ifdef NETDUMP
static void
-alc_netdump_init(struct ifnet *ifp __unused, int *nrxr)
+alc_netdump_init(struct ifnet *ifp, int *nrxr, int *clsize)
{
+ struct alc_softc *sc;
+ sc = if_getsoftc(ifp);
+ KASSERT(sc->alc_buf_size <= MCLBYTES, ("incorrect cluster size"));
+
*nrxr = ALC_RX_RING_CNT;
+ *clsize = MCLBYTES;
}
static void
-alc_netdump_event(struct ifnet *ifp, enum netdump_ev event)
+alc_netdump_event(struct ifnet *ifp __unused, enum netdump_ev event __unused)
{
- struct alc_softc *sc;
-
- sc = if_getsoftc(ifp);
- switch (event) {
- case NETDUMP_START:
- sc->alc_buf_size = imin(sc->alc_buf_size, MCLBYTES);
- break;
- default:
- break;
- }
}
static int
Modified: user/markj/netdump/sys/dev/bge/if_bge.c
==============================================================================
--- user/markj/netdump/sys/dev/bge/if_bge.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/dev/bge/if_bge.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -6811,27 +6811,25 @@ bge_get_counter(if_t ifp, ift_counter cnt)
#ifdef NETDUMP
static void
-bge_netdump_init(if_t ifp, int *nrxr)
+bge_netdump_init(if_t ifp, int *nrxr, int *clsize)
{
struct bge_softc *sc;
sc = if_getsoftc(ifp);
+ BGE_LOCK(sc);
*nrxr = sc->bge_return_ring_cnt;
+ if ((sc->bge_flags & BGE_FLAG_JUMBO_STD) != 0 &&
+ (if_getmtu(sc->bge_ifp) + ETHER_HDR_LEN + ETHER_CRC_LEN +
+ ETHER_VLAN_ENCAP_LEN > (MCLBYTES - ETHER_ALIGN)))
+ *clsize = MJUM9BYTES;
+ else
+ *clsize = MCLBYTES;
+ BGE_UNLOCK(sc);
}
static void
-bge_netdump_event(if_t ifp, enum netdump_ev event)
+bge_netdump_event(if_t ifp __unused, enum netdump_ev event __unused)
{
- struct bge_softc *sc;
-
- sc = if_getsoftc(ifp);
- switch (event) {
- case NETDUMP_START:
- sc->bge_flags &= ~BGE_FLAG_JUMBO_STD;
- break;
- default:
- break;
- }
}
static int
Modified: user/markj/netdump/sys/dev/bxe/bxe.c
==============================================================================
--- user/markj/netdump/sys/dev/bxe/bxe.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/dev/bxe/bxe.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -19172,12 +19172,15 @@ bxe_eioctl(struct cdev *dev, u_long cmd, caddr_t data,
#ifdef NETDUMP
static void
-bxe_netdump_init(struct ifnet *ifp, int *nrxr)
+bxe_netdump_init(struct ifnet *ifp, int *nrxr, int *clsize)
{
struct bxe_softc *sc;
sc = if_getsoftc(ifp);
+ BXE_CORE_LOCK(sc);
*nrxr = sc->num_queues;
+ *clsize = sc->fp[0].mbuf_alloc_size;
+ BXE_CORE_UNLOCK(sc);
}
static void
Modified: user/markj/netdump/sys/dev/cxgb/cxgb_main.c
==============================================================================
--- user/markj/netdump/sys/dev/cxgb/cxgb_main.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/dev/cxgb/cxgb_main.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -3587,10 +3587,17 @@ cxgbc_mod_event(module_t mod, int cmd, void *arg)
#ifdef NETDUMP
static void
-cxgb_netdump_init(struct ifnet *ifp, int *nrxr)
+cxgb_netdump_init(struct ifnet *ifp, int *nrxr, int *clsize)
{
+ struct port_info *pi;
+ adapter_t *adap;
+ pi = if_getsoftc(ifp);
+ adap = pi->adapter;
+ ADAPTER_LOCK(adap);
*nrxr = SGE_QSETS;
+ *clsize = adap->sge.qs[0].fl[1].buf_size;
+ ADAPTER_UNLOCK(adap);
}
static void
@@ -3607,7 +3614,7 @@ cxgb_netdump_event(struct ifnet *ifp, enum netdump_ev
/* Need to reinit after netdump_mbuf_dump(). */
qs->fl[0].zone = zone_pack;
- qs->fl[1].zone = zone_pack;
+ qs->fl[1].zone = zone_clust;
qs->lro.enabled = 0;
}
}
Modified: user/markj/netdump/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c
==============================================================================
--- user/markj/netdump/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -2886,12 +2886,15 @@ static void mlx4_en_sysctl_stat(struct mlx4_en_priv *p
#ifdef NETDUMP
static void
-mlx4_en_netdump_init(struct ifnet *dev, int *nrxr)
+mlx4_en_netdump_init(struct ifnet *dev, int *nrxr, int *clsize)
{
struct mlx4_en_priv *priv;
priv = if_getsoftc(dev);
+ mutex_lock(&priv->mdev->state_lock);
*nrxr = priv->rx_ring_num;
+ *clsize = priv->rx_mb_size;
+ mutex_unlock(&priv->mdev->state_lock);
}
static void
Modified: user/markj/netdump/sys/dev/re/if_re.c
==============================================================================
--- user/markj/netdump/sys/dev/re/if_re.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/dev/re/if_re.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -4095,27 +4095,21 @@ sysctl_hw_re_int_mod(SYSCTL_HANDLER_ARGS)
#ifdef NETDUMP
static void
-re_netdump_init(struct ifnet *ifp, int *nrxr)
+re_netdump_init(struct ifnet *ifp, int *nrxr, int *clsize)
{
struct rl_softc *sc;
sc = if_getsoftc(ifp);
+ RL_LOCK(sc);
*nrxr = sc->rl_ldata.rl_rx_desc_cnt;
+ *clsize = (ifp->if_mtu > RL_MTU &&
+ (sc->rl_flags & RL_FLAG_JUMBOV2) != 0) ? MJUM9BYTES : MCLBYTES;
+ RL_UNLOCK(sc);
}
static void
-re_netdump_event(struct ifnet *ifp, enum netdump_ev event)
+re_netdump_event(struct ifnet *ifp __unused, enum netdump_ev event __unused)
{
- struct rl_softc *sc;
-
- sc = if_getsoftc(ifp);
- switch (event) {
- case NETDUMP_START:
- sc->rl_flags &= ~RL_FLAG_JUMBOV2;
- break;
- default:
- break;
- }
}
static int
Modified: user/markj/netdump/sys/dev/virtio/network/if_vtnet.c
==============================================================================
--- user/markj/netdump/sys/dev/virtio/network/if_vtnet.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/dev/virtio/network/if_vtnet.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -3984,12 +3984,16 @@ vtnet_tunable_int(struct vtnet_softc *sc, const char *
#ifdef NETDUMP
static void
-vtnet_netdump_init(struct ifnet *ifp, int *nrxr)
+vtnet_netdump_init(struct ifnet *ifp, int *nrxr, int *clsize)
{
struct vtnet_softc *sc;
sc = if_getsoftc(ifp);
+
+ VTNET_CORE_LOCK(sc);
*nrxr = sc->vtnet_max_vq_pairs;
+ *clsize = sc->vtnet_rx_clsize;
+ VTNET_CORE_UNLOCK(sc);
/*
* We need to allocate from this zone in the transmit path, so ensure
@@ -4002,18 +4006,8 @@ vtnet_netdump_init(struct ifnet *ifp, int *nrxr)
}
static void
-vtnet_netdump_event(struct ifnet *ifp, enum netdump_ev event)
+vtnet_netdump_event(struct ifnet *ifp __unused, enum netdump_ev event __unused)
{
- struct vtnet_softc *sc;
-
- sc = if_getsoftc(ifp);
- switch (event) {
- case NETDUMP_START:
- sc->vtnet_rx_clsize = MCLBYTES;
- break;
- default:
- break;
- }
}
static int
Modified: user/markj/netdump/sys/kern/kern_mbuf.c
==============================================================================
--- user/markj/netdump/sys/kern/kern_mbuf.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/kern/kern_mbuf.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -381,9 +381,12 @@ mbuf_init(void *dummy)
SYSINIT(mbuf, SI_SUB_MBUF, SI_ORDER_FIRST, mbuf_init, NULL);
#ifdef NETDUMP
-static struct mbufq nd_mbufq;
-static struct mbufq nd_clustq;
+static struct mbufq nd_mbufq =
+ { STAILQ_HEAD_INITIALIZER(nd_mbufq.mq_head), 0, INT_MAX };
+static struct mbufq nd_clustq =
+ { STAILQ_HEAD_INITIALIZER(nd_clustq.mq_head), 0, INT_MAX };
+static int nd_clsize;
static uma_zone_t nd_zone_mbuf;
static uma_zone_t nd_zone_clust;
static uma_zone_t nd_zone_pack;
@@ -402,6 +405,7 @@ nd_buf_import(void *arg, void **store, int count, int
m = mbufq_dequeue(q);
if (m == NULL)
break;
+ trash_init(m, q == &nd_mbufq ? MSIZE : nd_clsize, flags);
store[i] = m;
}
return (i);
@@ -439,7 +443,6 @@ nd_pack_import(void *arg __unused, void **store, int c
m_free(m);
break;
}
-
mb_ctor_clust(clust, MCLBYTES, m, 0);
store[i] = m;
}
@@ -461,8 +464,54 @@ nd_pack_release(void *arg __unused, void **store, int
}
}
+void
+netdump_mbuf_drain(void)
+{
+ struct mbuf *m;
+ void *item;
+
+ if (nd_zone_mbuf != NULL) {
+ uma_zdestroy(nd_zone_mbuf);
+ nd_zone_mbuf = NULL;
+ }
+ if (nd_zone_clust != NULL) {
+ uma_zdestroy(nd_zone_clust);
+ nd_zone_clust = NULL;
+ }
+ if (nd_zone_pack != NULL) {
+ uma_zdestroy(nd_zone_pack);
+ nd_zone_pack = NULL;
+ }
+
+ while ((m = mbufq_dequeue(&nd_mbufq)) != NULL)
+ m_free(m);
+ while ((item = mbufq_dequeue(&nd_clustq)) != NULL)
+ uma_zfree(m_getzone(nd_clsize), item);
+}
+
/*
- * Initialize zones used to cache netdump packet buffers. At panic-time, we
+ * Callback invoked immediately prior to starting a netdump.
+ */
+void
+netdump_mbuf_dump(void)
+{
+
+ /*
+ * All cluster zones return buffers of the size requested by the
+ * drivers. It's up to the driver to reinitialize the zones if the
+ * MTU of a netdump-enabled interface changes.
+ */
+ printf("netdump: overwriting mbuf zone pointers\n");
+ zone_mbuf = nd_zone_mbuf;
+ zone_clust = nd_zone_clust;
+ zone_pack = nd_zone_pack;
+ zone_jumbop = nd_zone_clust;
+ zone_jumbo9 = nd_zone_clust;
+ zone_jumbo16 = nd_zone_clust;
+}
+
+/*
+ * (Re-)Initialize zones used to cache netdump packet buffers. At panic-time, we
* swap out the regular mbuf/cluster zones with these, ensuring that drivers and
* the protocol code can allocate buffers from a preallocated pool, rather than
* relying on memory allocation to succeed after a panic.
@@ -471,14 +520,15 @@ nd_pack_release(void *arg __unused, void **store, int
* purpose of caching clusters, we treat them as mbufs.
*/
void
-netdump_mbuf_init(int nmbuf, int nclust)
+netdump_mbuf_reinit(int nmbuf, int nclust, int clsize)
{
struct mbuf *m;
void *item;
- mbufq_init(&nd_mbufq, INT_MAX);
- mbufq_init(&nd_clustq, INT_MAX);
+ netdump_mbuf_drain();
+ nd_clsize = clsize;
+
nd_zone_mbuf = uma_zcache_create("netdump_" MBUF_MEM_NAME,
MSIZE, mb_ctor_mbuf, mb_dtor_mbuf,
#ifdef INVARIANTS
@@ -490,7 +540,7 @@ netdump_mbuf_init(int nmbuf, int nclust)
&nd_mbufq, UMA_ZONE_NOBUCKET);
nd_zone_clust = uma_zcache_create("netdump_" MBUF_CLUSTER_MEM_NAME,
- MCLBYTES, mb_ctor_clust,
+ clsize, mb_ctor_clust,
#ifdef INVARIANTS
trash_dtor, trash_init, trash_fini,
#else
@@ -509,59 +559,9 @@ netdump_mbuf_init(int nmbuf, int nclust)
uma_zfree(nd_zone_mbuf, m);
}
while (nclust-- > 0) {
- item = uma_zalloc(zone_clust, M_WAITOK);
+ item = uma_zalloc(m_getzone(nd_clsize), M_WAITOK);
uma_zfree(nd_zone_clust, item);
}
-}
-
-/*
- * Free preallocated mbufs and clusters and destroy netdump cache zones.
- */
-void
-netdump_mbuf_drain(void)
-{
- struct mbuf *m;
- void *item;
-
- while ((m = mbufq_dequeue(&nd_mbufq)) != NULL)
- m_free(m);
- while ((item = mbufq_dequeue(&nd_clustq)) != NULL)
- uma_zfree(zone_clust, item);
-
- if (nd_zone_mbuf != NULL) {
- uma_zdestroy(nd_zone_mbuf);
- nd_zone_mbuf = NULL;
- }
- if (nd_zone_clust != NULL) {
- uma_zdestroy(nd_zone_clust);
- nd_zone_clust = NULL;
- }
- if (nd_zone_pack != NULL) {
- uma_zdestroy(nd_zone_pack);
- nd_zone_pack = NULL;
- }
-}
-
-/*
- * Callback invoked immediately prior to starting a netdump.
- */
-void
-netdump_mbuf_dump(void)
-{
-
- /*
- * All cluster zones return 2KB buffers. It's up to the per-driver
- * netdump hooks to ensure that no attempts are made to use larger
- * clusters. netdump ACKs fit easily within an mbuf, let alone a 2KB
- * cluster, so there's no need to preallocate larger buffers.
- */
- printf("netdump: overwriting mbuf zone pointers\n");
- zone_mbuf = nd_zone_mbuf;
- zone_clust = nd_zone_clust;
- zone_pack = nd_zone_pack;
- zone_jumbop = nd_zone_clust;
- zone_jumbo9 = nd_zone_clust;
- zone_jumbo16 = nd_zone_clust;
}
#endif /* NETDUMP */
Modified: user/markj/netdump/sys/net/if.c
==============================================================================
--- user/markj/netdump/sys/net/if.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/net/if.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -88,6 +88,7 @@
#include <netinet/ip_carp.h>
#ifdef INET
#include <netinet/if_ether.h>
+#include <netinet/netdump/netdump.h>
#endif /* INET */
#ifdef INET6
#include <netinet6/in6_var.h>
@@ -2707,6 +2708,9 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data,
if (error == 0) {
getmicrotime(&ifp->if_lastchange);
rt_ifmsg(ifp);
+#ifdef INET
+ NETDUMP_REINIT(ifp);
+#endif
}
/*
* If the link MTU changed, do network layer specific procedure.
Modified: user/markj/netdump/sys/net/iflib.c
==============================================================================
--- user/markj/netdump/sys/net/iflib.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/net/iflib.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -5974,12 +5974,15 @@ iflib_fixup_rx(struct mbuf *m)
#ifdef NETDUMP
static void
-iflib_netdump_init(struct ifnet *ifp, int *nrxr)
+iflib_netdump_init(struct ifnet *ifp, int *nrxr, int *clsize)
{
if_ctx_t ctx;
ctx = if_getsoftc(ifp);
+ CTX_LOCK(ctx);
*nrxr = NRXQSETS(ctx);
+ *clsize = ctx->ifc_rxqs[0].ifr_fl->ifl_buf_size;
+ CTX_UNLOCK(ctx);
}
static void
@@ -5987,15 +5990,22 @@ iflib_netdump_event(struct ifnet *ifp, enum netdump_ev
{
if_ctx_t ctx;
if_softc_ctx_t scctx;
- int i;
+ iflib_fl_t fl;
+ iflib_rxq_t rxq;
+ int i, j;
ctx = if_getsoftc(ifp);
scctx = &ctx->ifc_softc_ctx;
switch (event) {
case NETDUMP_START:
- for (i = 0; i < scctx->isc_nrxqsets; i++)
- ctx->ifc_rxqs[i].ifr_fl->ifl_buf_size = MCLBYTES;
+ for (i = 0; i < scctx->isc_nrxqsets; i++) {
+ rxq = &ctx->ifc_rxqs[i];
+ for (j = 0; j < rxq->ifr_nfl; j++) {
+ fl = rxq->ifr_fl;
+ fl->ifl_zone = m_getzone(fl->ifl_buf_size);
+ }
+ }
iflib_no_tx_batch = 1;
break;
default:
Modified: user/markj/netdump/sys/netinet/netdump/netdump.h
==============================================================================
--- user/markj/netdump/sys/netinet/netdump/netdump.h Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/netinet/netdump/netdump.h Mon Apr 9 21:37:39 2018 (r332338)
@@ -86,7 +86,9 @@ enum netdump_ev {
struct ifnet;
struct mbuf;
-typedef void netdump_init_t(struct ifnet *, int *nrxr);
+void netdump_reinit(struct ifnet *);
+
+typedef void netdump_init_t(struct ifnet *, int *nrxr, int *clsize);
typedef void netdump_event_t(struct ifnet *, enum netdump_ev);
typedef int netdump_transmit_t(struct ifnet *, struct mbuf *);
typedef int netdump_poll_t(struct ifnet *, int);
@@ -111,12 +113,15 @@ struct netdump_methods {
.nd_poll = driver##_netdump_poll, \
}
+#define NETDUMP_REINIT(ifp) netdump_reinit(ifp)
+
#define NETDUMP_SET(ifp, driver) \
(ifp)->if_netdump_methods = &driver##_netdump_methods
#else /* !NETDUMP */
#define NETDUMP_DEFINE(driver)
+#define NETDUMP_REINIT(ifp)
#define NETDUMP_SET(ifp, driver)
#endif /* NETDUMP */
Modified: user/markj/netdump/sys/netinet/netdump/netdump_client.c
==============================================================================
--- user/markj/netdump/sys/netinet/netdump/netdump_client.c Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/netinet/netdump/netdump_client.c Mon Apr 9 21:37:39 2018 (r332338)
@@ -1048,7 +1048,6 @@ static int
netdump_configure(struct netdump_conf *conf)
{
struct ifnet *ifp;
- int nmbuf, nclust, nrxr;
IFNET_RLOCK_NOSLEEP();
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
@@ -1067,7 +1066,27 @@ netdump_configure(struct netdump_conf *conf)
return (1);
}
- ifp->if_netdump_methods->nd_init(ifp, &nrxr);
+ nd_ifp = ifp;
+ netdump_reinit(ifp);
+ memcpy(&nd_conf, conf, sizeof(nd_conf));
+ nd_enabled = 1;
+ return (0);
+}
+
+/*
+ * Reinitialize the mbuf pool used by drivers while dumping. This is called
+ * from the generic ioctl handler for SIOCSIFMTU after the driver has
+ * reconfigured itself.
+ */
+void
+netdump_reinit(struct ifnet *ifp)
+{
+ int clsize, nmbuf, nclust, nrxr;
+
+ if (ifp != nd_ifp)
+ return;
+
+ ifp->if_netdump_methods->nd_init(ifp, &nrxr, &clsize);
KASSERT(nrxr > 0, ("invalid receive ring count %d", nrxr));
/*
@@ -1076,12 +1095,7 @@ netdump_configure(struct netdump_conf *conf)
*/
nmbuf = NETDUMP_MAX_IN_FLIGHT * (4 + nrxr);
nclust = NETDUMP_MAX_IN_FLIGHT * nrxr;
- netdump_mbuf_init(nmbuf, nclust);
-
- nd_ifp = ifp;
- memcpy(&nd_conf, conf, sizeof(nd_conf));
- nd_enabled = 1;
- return (0);
+ netdump_mbuf_reinit(nmbuf, nclust, clsize);
}
/*
Modified: user/markj/netdump/sys/sys/mbuf.h
==============================================================================
--- user/markj/netdump/sys/sys/mbuf.h Mon Apr 9 21:16:28 2018 (r332337)
+++ user/markj/netdump/sys/sys/mbuf.h Mon Apr 9 21:37:39 2018 (r332338)
@@ -1375,9 +1375,9 @@ mbuf_tstmp2timespec(struct mbuf *m, struct timespec *t
#ifdef NETDUMP
/* Invoked from the netdump client code. */
-void netdump_mbuf_init(int, int);
void netdump_mbuf_drain(void);
void netdump_mbuf_dump(void);
+void netdump_mbuf_reinit(int nmbuf, int nclust, int clsize);
#endif
#endif /* _KERNEL */
More information about the svn-src-user
mailing list