Author: glebius
Date: Thu Sep 25 05:45:52 2014
New Revision: 272090
URL: http://svnweb.freebsd.org/changeset/base/272090

Log:
  - Provide mxge_get_counter() to return counters that are not collected,
    but taken from hardware.
  - Mechanically convert to if_inc_counter() the rest of counters.

Modified:
  head/sys/dev/mxge/if_mxge.c

Modified: head/sys/dev/mxge/if_mxge.c
==============================================================================
--- head/sys/dev/mxge/if_mxge.c Thu Sep 25 02:26:05 2014        (r272089)
+++ head/sys/dev/mxge/if_mxge.c Thu Sep 25 05:45:52 2014        (r272090)
@@ -2678,7 +2678,7 @@ mxge_rx_done_big(struct mxge_slice_state
        /* try to replace the received mbuf */
        if (mxge_get_buf_big(ss, rx->extra_map, idx)) {
                /* drop the frame -- the old mbuf is re-cycled */
-               ifp->if_ierrors++;
+               if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
                return;
        }
 
@@ -2747,7 +2747,7 @@ mxge_rx_done_small(struct mxge_slice_sta
        /* try to replace the received mbuf */
        if (mxge_get_buf_small(ss, rx->extra_map, idx)) {
                /* drop the frame -- the old mbuf is re-cycled */
-               ifp->if_ierrors++;
+               if_inc_counter(ifp, IFCOUNTER_IERRORS, 1);
                return;
        }
 
@@ -4036,43 +4036,45 @@ mxge_watchdog(mxge_softc_t *sc)
        return (err);
 }
 
-static u_long
-mxge_update_stats(mxge_softc_t *sc)
+static uint64_t
+mxge_get_counter(struct ifnet *ifp, ift_counter cnt)
 {
-       struct mxge_slice_state *ss;
-       u_long pkts = 0;
-       u_long ipackets = 0;
-       u_long opackets = 0;
-#ifdef IFNET_BUF_RING
-       u_long obytes = 0;
-       u_long omcasts = 0;
-       u_long odrops = 0;
-#endif
-       u_long oerrors = 0;
-       int slice;
+       struct mxge_softc *sc;
+       uint64_t rv;
 
-       for (slice = 0; slice < sc->num_slices; slice++) {
-               ss = &sc->ss[slice];
-               ipackets += ss->ipackets;
-               opackets += ss->opackets;
-#ifdef IFNET_BUF_RING
-               obytes += ss->obytes;
-               omcasts += ss->omcasts;
-               odrops += ss->tx.br->br_drops;
-#endif
-               oerrors += ss->oerrors;
-       }
-       pkts = (ipackets - sc->ifp->if_ipackets);
-       pkts += (opackets - sc->ifp->if_opackets);
-       sc->ifp->if_ipackets = ipackets;
-       sc->ifp->if_opackets = opackets;
+       sc = if_getsoftc(ifp);
+       rv = 0;
+
+       switch (cnt) {
+       case IFCOUNTER_IPACKETS:
+               for (int s = 0; s < sc->num_slices; s++)
+                       rv += sc->ss[s].ipackets;
+               return (rv);
+       case IFCOUNTER_OPACKETS:
+               for (int s = 0; s < sc->num_slices; s++)
+                       rv += sc->ss[s].opackets;
+               return (rv);
+       case IFCOUNTER_OERRORS:
+               for (int s = 0; s < sc->num_slices; s++)
+                       rv += sc->ss[s].oerrors;
+               return (rv);
 #ifdef IFNET_BUF_RING
-       sc->ifp->if_obytes = obytes;
-       sc->ifp->if_omcasts = omcasts;
-       sc->ifp->if_oqdrops = odrops;
+       case IFCOUNTER_OBYTES:
+               for (int s = 0; s < sc->num_slices; s++)
+                       rv += sc->ss[s].obytes;
+               return (rv);
+       case IFCOUNTER_OMCASTS:
+               for (int s = 0; s < sc->num_slices; s++)
+                       rv += sc->ss[s].omcasts;
+               return (rv);
+       case IFCOUNTER_OQDROPS:
+               for (int s = 0; s < sc->num_slices; s++)
+                       rv += sc->ss[s].tx.br->br_drops;
+               return (rv);
 #endif
-       sc->ifp->if_oerrors = oerrors;
-       return pkts;
+       default:
+               return (if_get_counter_default(ifp, cnt));
+       }
 }
 
 static void
@@ -4087,8 +4089,6 @@ mxge_tick(void *arg)
        ticks = mxge_ticks;
        running = sc->ifp->if_drv_flags & IFF_DRV_RUNNING;
        if (running) {
-               /* aggregate stats from different slices */
-               pkts = mxge_update_stats(sc);
                if (!sc->watchdog_countdown) {
                        err = mxge_watchdog(sc);
                        sc->watchdog_countdown = 4;
@@ -4925,6 +4925,7 @@ mxge_attach(device_t dev)
         ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
         ifp->if_ioctl = mxge_ioctl;
         ifp->if_start = mxge_start;
+       ifp->if_get_counter = mxge_get_counter;
        /* Initialise the ifmedia structure */
        ifmedia_init(&sc->media, 0, mxge_media_change, 
                     mxge_media_status);
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to