Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci make counters per queue



details:   https://anonhg.NetBSD.org/src/rev/8ee704b3b0c6
branches:  trunk
changeset: 467187:8ee704b3b0c6
user:      ryo <ryo%NetBSD.org@localhost>
date:      Fri Jan 17 05:16:33 2020 +0000

description:
make counters per queue

diffstat:

 sys/dev/pci/if_aq.c |  88 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 78 insertions(+), 10 deletions(-)

diffs (175 lines):

diff -r d750a810bf7f -r 8ee704b3b0c6 sys/dev/pci/if_aq.c
--- a/sys/dev/pci/if_aq.c       Fri Jan 17 05:11:04 2020 +0000
+++ b/sys/dev/pci/if_aq.c       Fri Jan 17 05:16:33 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_aq.c,v 1.2 2020/01/17 05:11:04 ryo Exp $    */
+/*     $NetBSD: if_aq.c,v 1.3 2020/01/17 05:16:33 ryo Exp $    */
 
 /**
  * aQuantia Corporation Network Driver
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.2 2020/01/17 05:11:04 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_aq.c,v 1.3 2020/01/17 05:16:33 ryo Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_if_aq.h"
@@ -862,6 +862,12 @@
        unsigned int txr_prodidx;
        unsigned int txr_considx;
        int txr_nfree;
+
+       /* counters */
+       uint64_t txr_opackets;
+       uint64_t txr_obytes;
+       uint64_t txr_omcasts;
+       uint64_t txr_oerrors;
 };
 
 struct aq_rxring {
@@ -879,6 +885,12 @@
                bus_dmamap_t dmamap;
        } rxr_mbufs[AQ_RXD_NUM];
        unsigned int rxr_readidx;
+
+       /* counters */
+       uint64_t rxr_ipackets;
+       uint64_t rxr_ibytes;
+       uint64_t rxr_ierrors;
+       uint64_t rxr_iqdrops;
 };
 
 struct aq_queue {
@@ -4015,6 +4027,7 @@
        struct aq_txring *txring = arg;
        struct aq_softc *sc = txring->txr_sc;
        struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+       struct mbuf *m;
        const int ringidx = txring->txr_index;
        unsigned int idx, hw_head, n = 0;
 
@@ -4032,12 +4045,17 @@
        for (idx = txring->txr_considx; idx != hw_head;
            idx = TXRING_NEXTIDX(idx), n++) {
 
-               if (txring->txr_mbufs[idx].m != NULL) {
+               if ((m = txring->txr_mbufs[idx].m) != NULL) {
                        bus_dmamap_unload(sc->sc_dmat,
                            txring->txr_mbufs[idx].dmamap);
-                       m_freem(txring->txr_mbufs[idx].m);
+
+                       txring->txr_opackets++;
+                       txring->txr_obytes += m->m_pkthdr.len;
+                       if (m->m_flags & M_MCAST)
+                               txring->txr_omcasts++;
+
+                       m_freem(m);
                        txring->txr_mbufs[idx].m = NULL;
-                       ifp->if_opackets++;
                }
 
                txring->txr_nfree++;
@@ -4105,7 +4123,7 @@
 
                if ((rxd_status & RXDESC_STATUS_MACERR) ||
                    (rxd_type & RXDESC_TYPE_MAC_DMA_ERR)) {
-                       ifp->if_ierrors++;
+                       rxring->rxr_ierrors++;
                        goto rx_next;
                }
 
@@ -4120,6 +4138,7 @@
                         * cannot allocate new mbuf.
                         * discard this packet, and reuse mbuf for next.
                         */
+                       rxring->rxr_iqdrops++;
                        goto rx_next;
                }
                rxring->rxr_mbufs[idx].m = NULL;
@@ -4220,10 +4239,10 @@
                                }
                        }
 #endif
-
                        m_set_rcvif(m0, ifp);
+                       rxring->rxr_ipackets++;
+                       rxring->rxr_ibytes += m0->m_pkthdr.len;
                        if_percpuq_enqueue(ifp->if_percpuq, m0);
-
                        m0 = mprev = NULL;
                }
 
@@ -4361,7 +4380,7 @@
                if (error != 0) {
                        /* too many mbuf chains? or not enough descriptors? */
                        m_freem(m);
-                       ifp->if_oerrors++;
+                       txring->txr_oerrors++;
                        if (txring->txr_index == 0 && error == ENOBUFS)
                                ifp->if_flags |= IFF_OACTIVE;
                        break;
@@ -4518,12 +4537,61 @@
 {
        struct aq_softc *sc __unused;
        struct ifreq *ifr __unused;
-       int error, s;
+       uint64_t opackets, oerrors, obytes, omcasts;
+       uint64_t ipackets, ierrors, ibytes, iqdrops;
+       int error, i, s;
 
        sc = (struct aq_softc *)ifp->if_softc;
        ifr = (struct ifreq *)data;
        error = 0;
 
+       switch (cmd) {
+       case SIOCGIFDATA:
+       case SIOCZIFDATA:
+               opackets = oerrors = obytes = omcasts = 0;
+               ipackets = ierrors = ibytes = iqdrops = 0;
+               for (i = 0; i < sc->sc_nqueues; i++) {
+                       struct aq_txring *txring = &sc->sc_queue[i].txring;
+                       mutex_enter(&txring->txr_mutex);
+                       if (cmd == SIOCZIFDATA) {
+                               txring->txr_opackets = 0;
+                               txring->txr_obytes = 0;
+                               txring->txr_omcasts = 0;
+                               txring->txr_oerrors = 0;
+                       } else {
+                               opackets += txring->txr_opackets;
+                               oerrors += txring->txr_oerrors;
+                               obytes += txring->txr_obytes;
+                               omcasts += txring->txr_omcasts;
+                       }
+                       mutex_exit(&txring->txr_mutex);
+
+                       struct aq_rxring *rxring = &sc->sc_queue[i].rxring;
+                       mutex_enter(&rxring->rxr_mutex);
+                       if (cmd == SIOCZIFDATA) {
+                               rxring->rxr_ipackets = 0;
+                               rxring->rxr_ibytes = 0;
+                               rxring->rxr_ierrors = 0;
+                               rxring->rxr_iqdrops = 0;
+                       } else {
+                               ipackets += rxring->rxr_ipackets;
+                               ierrors += rxring->rxr_ierrors;
+                               ibytes += rxring->rxr_ibytes;
+                               iqdrops += rxring->rxr_iqdrops;
+                       }
+                       mutex_exit(&rxring->rxr_mutex);
+               }
+               ifp->if_opackets = opackets;
+               ifp->if_oerrors = oerrors;
+               ifp->if_obytes = obytes;
+               ifp->if_omcasts = omcasts;
+               ifp->if_ipackets = ipackets;
+               ifp->if_ierrors = ierrors;
+               ifp->if_ibytes = ibytes;
+               ifp->if_iqdrops = iqdrops;
+               break;
+       }
+
        s = splnet();
        error = ether_ioctl(ifp, cmd, data);
        splx(s);



Home | Main Index | Thread Index | Old Index