socsvn commit: r289689 - in soc2015/stefano/ptnetmap: head/sys/dev/virtio/network stable/10/sys/dev/virtio/network

stefano at FreeBSD.org stefano at FreeBSD.org
Thu Aug 13 14:30:58 UTC 2015


Author: stefano
Date: Thu Aug 13 14:30:57 2015
New Revision: 289689
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=289689

Log:
  [ptnetmap] fix virtio-net ptnetmap patch

Modified:
  soc2015/stefano/ptnetmap/head/sys/dev/virtio/network/if_vtnet.c
  soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c

Modified: soc2015/stefano/ptnetmap/head/sys/dev/virtio/network/if_vtnet.c
==============================================================================
--- soc2015/stefano/ptnetmap/head/sys/dev/virtio/network/if_vtnet.c	Thu Aug 13 13:38:09 2015	(r289688)
+++ soc2015/stefano/ptnetmap/head/sys/dev/virtio/network/if_vtnet.c	Thu Aug 13 14:30:57 2015	(r289689)
@@ -291,7 +291,7 @@
 #ifdef DEV_NETMAP
 #include <dev/netmap/if_vtnet_netmap.h>
 #else
-#define VTNET_PTNETMAP_ON(_na)        0
+#define VTNET_PTNETMAP_ON(_na)	0
 #endif /* DEV_NETMAP */
 
 static driver_t vtnet_driver = {
@@ -1859,7 +1859,8 @@
 	}
 
 	more = vtnet_rxq_eof(rxq);
-	if (!VTNET_PTNETMAP_ON(NA(ifp)) && (more || vtnet_rxq_enable_intr(rxq) != 0)) {
+	if (!VTNET_PTNETMAP_ON(NA(ifp)) &&
+			(more || vtnet_rxq_enable_intr(rxq) != 0)) {
 		if (!more)
 			vtnet_rxq_disable_intr(rxq);
 		/*
@@ -1896,7 +1897,8 @@
 	}
 
 	more = vtnet_rxq_eof(rxq);
-	if (!VTNET_PTNETMAP_ON(NA(ifp)) && (more || vtnet_rxq_enable_intr(rxq) != 0)) {
+	if (!VTNET_PTNETMAP_ON(NA(ifp)) &&
+			(more || vtnet_rxq_enable_intr(rxq) != 0)) {
 		if (!more)
 			vtnet_rxq_disable_intr(rxq);
 		rxq->vtnrx_stats.vrxs_rescheduled++;

Modified: soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c
==============================================================================
--- soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c	Thu Aug 13 13:38:09 2015	(r289688)
+++ soc2015/stefano/ptnetmap/stable/10/sys/dev/virtio/network/if_vtnet.c	Thu Aug 13 14:30:57 2015	(r289689)
@@ -30,7 +30,6 @@
 __FBSDID("$FreeBSD$");
 
 #include <sys/param.h>
-#include <sys/eventhandler.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/sockio.h>
@@ -51,7 +50,6 @@
 
 #include <net/ethernet.h>
 #include <net/if.h>
-#include <net/if_var.h>
 #include <net/if_arp.h>
 #include <net/if_dl.h>
 #include <net/if_types.h>
@@ -107,7 +105,6 @@
 static int	vtnet_setup_interface(struct vtnet_softc *);
 static int	vtnet_change_mtu(struct vtnet_softc *, int);
 static int	vtnet_ioctl(struct ifnet *, u_long, caddr_t);
-static uint64_t	vtnet_get_counter(struct ifnet *, ift_counter);
 
 static int	vtnet_rxq_populate(struct vtnet_rxq *);
 static void	vtnet_rxq_free_mbufs(struct vtnet_rxq *);
@@ -161,8 +158,11 @@
 #endif
 
 static int	vtnet_watchdog(struct vtnet_txq *);
-static void	vtnet_accum_stats(struct vtnet_softc *,
-		    struct vtnet_rxq_stats *, struct vtnet_txq_stats *);
+static void	vtnet_rxq_accum_stats(struct vtnet_rxq *,
+		    struct vtnet_rxq_stats *);
+static void	vtnet_txq_accum_stats(struct vtnet_txq *,
+		    struct vtnet_txq_stats *);
+static void	vtnet_accumulate_stats(struct vtnet_softc *);
 static void	vtnet_tick(void *);
 
 static void	vtnet_start_taskqueues(struct vtnet_softc *);
@@ -267,7 +267,7 @@
 	{ VIRTIO_NET_F_GUEST_ANNOUNCE,	"GuestAnnounce"	},
 	{ VIRTIO_NET_F_MQ,		"Multiqueue"	},
 	{ VIRTIO_NET_F_CTRL_MAC_ADDR,	"SetMacAddress"	},
-	{ VIRTIO_NET_F_PTNETMAP,	"PTNetmap"	},
+	{ VIRTIO_NET_F_PTNETMAP,i	"PTNetmap"	},
 
 	{ 0, NULL }
 };
@@ -291,7 +291,7 @@
 #ifdef DEV_NETMAP
 #include <dev/netmap/if_vtnet_netmap.h>
 #else
-#define VTNET_PTNETMAP_ON(_na)        0
+#define VTNET_PTNETMAP_ON(_na)	0
 #endif /* DEV_NETMAP */
 
 static driver_t vtnet_driver = {
@@ -301,8 +301,6 @@
 };
 static devclass_t vtnet_devclass;
 
-DRIVER_MODULE(vtnet, virtio_mmio, vtnet_driver, vtnet_devclass,
-    vtnet_modevent, 0);
 DRIVER_MODULE(vtnet, virtio_pci, vtnet_driver, vtnet_devclass,
     vtnet_modevent, 0);
 MODULE_VERSION(vtnet, 1);
@@ -921,12 +919,12 @@
 	}
 
 	if_initname(ifp, device_get_name(dev), device_get_unit(dev));
-	ifp->if_baudrate = IF_Gbps(10);	/* Approx. */
+	if_initbaudrate(ifp, IF_Gbps(10));	/* Approx. */
 	ifp->if_softc = sc;
 	ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 	ifp->if_init = vtnet_init;
 	ifp->if_ioctl = vtnet_ioctl;
-	ifp->if_get_counter = vtnet_get_counter;
+
 #ifndef VTNET_LEGACY_TX
 	ifp->if_transmit = vtnet_txq_mq_start;
 	ifp->if_qflush = vtnet_qflush;
@@ -952,7 +950,7 @@
 		ifp->if_capabilities |= IFCAP_LINKSTATE;
 
 	/* Tell the upper layer(s) we support long frames. */
-	ifp->if_hdrlen = sizeof(struct ether_vlan_header);
+	ifp->if_data.ifi_hdrlen = sizeof(struct ether_vlan_header);
 	ifp->if_capabilities |= IFCAP_JUMBO_MTU | IFCAP_VLAN_MTU;
 
 	if (virtio_with_feature(dev, VIRTIO_NET_F_CSUM)) {
@@ -1859,7 +1857,8 @@
 	}
 
 	more = vtnet_rxq_eof(rxq);
-	if (!VTNET_PTNETMAP_ON(NA(ifp)) && (more || vtnet_rxq_enable_intr(rxq) != 0)) {
+	if (!VTNET_PTNETMAP_ON(NA(ifp)) &&
+			(more || vtnet_rxq_enable_intr(rxq) != 0)) {
 		if (!more)
 			vtnet_rxq_disable_intr(rxq);
 		/*
@@ -1896,7 +1895,8 @@
 	}
 
 	more = vtnet_rxq_eof(rxq);
-	if (!VTNET_PTNETMAP_ON(NA(ifp)) && (more || vtnet_rxq_enable_intr(rxq) != 0)) {
+	if (!VTNET_PTNETMAP_ON(NA(ifp)) &&
+			(more || vtnet_rxq_enable_intr(rxq) != 0)) {
 		if (!more)
 			vtnet_rxq_disable_intr(rxq);
 		rxq->vtnrx_stats.vrxs_rescheduled++;
@@ -2578,62 +2578,74 @@
 }
 
 static void
-vtnet_accum_stats(struct vtnet_softc *sc, struct vtnet_rxq_stats *rxacc,
-    struct vtnet_txq_stats *txacc)
+vtnet_rxq_accum_stats(struct vtnet_rxq *rxq, struct vtnet_rxq_stats *accum)
 {
+	struct vtnet_rxq_stats *st;
 
-	bzero(rxacc, sizeof(struct vtnet_rxq_stats));
-	bzero(txacc, sizeof(struct vtnet_txq_stats));
+	st = &rxq->vtnrx_stats;
 
-	for (int i = 0; i < sc->vtnet_max_vq_pairs; i++) {
-		struct vtnet_rxq_stats *rxst;
-		struct vtnet_txq_stats *txst;
+	accum->vrxs_ipackets += st->vrxs_ipackets;
+	accum->vrxs_ibytes += st->vrxs_ibytes;
+	accum->vrxs_iqdrops += st->vrxs_iqdrops;
+	accum->vrxs_csum += st->vrxs_csum;
+	accum->vrxs_csum_failed += st->vrxs_csum_failed;
+	accum->vrxs_rescheduled += st->vrxs_rescheduled;
+}
+
+static void
+vtnet_txq_accum_stats(struct vtnet_txq *txq, struct vtnet_txq_stats *accum)
+{
+	struct vtnet_txq_stats *st;
 
-		rxst = &sc->vtnet_rxqs[i].vtnrx_stats;
-		rxacc->vrxs_ipackets += rxst->vrxs_ipackets;
-		rxacc->vrxs_ibytes += rxst->vrxs_ibytes;
-		rxacc->vrxs_iqdrops += rxst->vrxs_iqdrops;
-		rxacc->vrxs_csum += rxst->vrxs_csum;
-		rxacc->vrxs_csum_failed += rxst->vrxs_csum_failed;
-		rxacc->vrxs_rescheduled += rxst->vrxs_rescheduled;
+	st = &txq->vtntx_stats;
 
-		txst = &sc->vtnet_txqs[i].vtntx_stats;
-		txacc->vtxs_opackets += txst->vtxs_opackets;
-		txacc->vtxs_obytes += txst->vtxs_obytes;
-		txacc->vtxs_csum += txst->vtxs_csum;
-		txacc->vtxs_tso += txst->vtxs_tso;
-		txacc->vtxs_rescheduled += txst->vtxs_rescheduled;
-	}
+	accum->vtxs_opackets += st->vtxs_opackets;
+	accum->vtxs_obytes += st->vtxs_obytes;
+	accum->vtxs_csum += st->vtxs_csum;
+	accum->vtxs_tso += st->vtxs_tso;
+	accum->vtxs_rescheduled += st->vtxs_rescheduled;
 }
 
-static uint64_t
-vtnet_get_counter(if_t ifp, ift_counter cnt)
+static void
+vtnet_accumulate_stats(struct vtnet_softc *sc)
 {
-	struct vtnet_softc *sc;
+	struct ifnet *ifp;
+	struct vtnet_statistics *st;
 	struct vtnet_rxq_stats rxaccum;
 	struct vtnet_txq_stats txaccum;
+	int i;
+
+	ifp = sc->vtnet_ifp;
+	st = &sc->vtnet_stats;
+	bzero(&rxaccum, sizeof(struct vtnet_rxq_stats));
+	bzero(&txaccum, sizeof(struct vtnet_txq_stats));
 
-	sc = if_getsoftc(ifp);
-	vtnet_accum_stats(sc, &rxaccum, &txaccum);
+	for (i = 0; i < sc->vtnet_max_vq_pairs; i++) {
+		vtnet_rxq_accum_stats(&sc->vtnet_rxqs[i], &rxaccum);
+		vtnet_txq_accum_stats(&sc->vtnet_txqs[i], &txaccum);
+	}
 
-	switch (cnt) {
-	case IFCOUNTER_IPACKETS:
-		return (rxaccum.vrxs_ipackets);
-	case IFCOUNTER_IQDROPS:
-		return (rxaccum.vrxs_iqdrops);
-	case IFCOUNTER_IERRORS:
-		return (rxaccum.vrxs_ierrors);
-	case IFCOUNTER_OPACKETS:
-		return (txaccum.vtxs_opackets);
+	st->rx_csum_offloaded = rxaccum.vrxs_csum;
+	st->rx_csum_failed = rxaccum.vrxs_csum_failed;
+	st->rx_task_rescheduled = rxaccum.vrxs_rescheduled;
+	st->tx_csum_offloaded = txaccum.vtxs_csum;
+	st->tx_tso_offloaded = txaccum.vtxs_tso;
+	st->tx_task_rescheduled = txaccum.vtxs_rescheduled;
+
+	/*
+	 * With the exception of if_ierrors, these ifnet statistics are
+	 * only updated in the driver, so just set them to our accumulated
+	 * values. if_ierrors is updated in ether_input() for malformed
+	 * frames that we should have already discarded.
+	 */
+	ifp->if_ipackets = rxaccum.vrxs_ipackets;
+	ifp->if_iqdrops = rxaccum.vrxs_iqdrops;
+	ifp->if_ierrors = rxaccum.vrxs_ierrors;
+	ifp->if_opackets = txaccum.vtxs_opackets;
 #ifndef VTNET_LEGACY_TX
-	case IFCOUNTER_OBYTES:
-		return (txaccum.vtxs_obytes);
-	case IFCOUNTER_OMCASTS:
-		return (txaccum.vtxs_omcasts);
+	ifp->if_obytes = txaccum.vtxs_obytes;
+	ifp->if_omcasts = txaccum.vtxs_omcasts;
 #endif
-	default:
-		return (if_get_counter_default(ifp, cnt));
-	}
 }
 
 static void
@@ -2648,6 +2660,7 @@
 	timedout = 0;
 
 	VTNET_CORE_LOCK_ASSERT(sc);
+	vtnet_accumulate_stats(sc);
 
 	for (i = 0; i < sc->vtnet_act_vq_pairs; i++)
 		timedout |= vtnet_watchdog(&sc->vtnet_txqs[i]);
@@ -3759,18 +3772,8 @@
     struct sysctl_oid_list *child, struct vtnet_softc *sc)
 {
 	struct vtnet_statistics *stats;
-	struct vtnet_rxq_stats rxaccum;
-	struct vtnet_txq_stats txaccum;
-
-	vtnet_accum_stats(sc, &rxaccum, &txaccum);
 
 	stats = &sc->vtnet_stats;
-	stats->rx_csum_offloaded = rxaccum.vrxs_csum;
-	stats->rx_csum_failed = rxaccum.vrxs_csum_failed;
-	stats->rx_task_rescheduled = rxaccum.vrxs_rescheduled;
-	stats->tx_csum_offloaded = txaccum.vtxs_csum;
-	stats->tx_tso_offloaded = txaccum.vtxs_tso;
-	stats->tx_task_rescheduled = txaccum.vtxs_rescheduled;
 
 	SYSCTL_ADD_UQUAD(ctx, child, OID_AUTO, "mbuf_alloc_failed",
 	    CTLFLAG_RD, &stats->mbuf_alloc_failed,


More information about the svn-soc-all mailing list