Module Name: src Committed By: ryo Date: Fri Jan 17 05:16:33 UTC 2020
Modified Files: src/sys/dev/pci: if_aq.c Log Message: make counters per queue To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/sys/dev/pci/if_aq.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pci/if_aq.c diff -u src/sys/dev/pci/if_aq.c:1.2 src/sys/dev/pci/if_aq.c:1.3 --- src/sys/dev/pci/if_aq.c:1.2 Fri Jan 17 05:11:04 2020 +++ src/sys/dev/pci/if_aq.c Fri Jan 17 05:16:33 2020 @@ -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 @@ struct aq_txring { 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 @@ struct aq_rxring { 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 @@ aq_tx_intr(void *arg) 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 @@ aq_tx_intr(void *arg) 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 @@ aq_rx_intr(void *arg) 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 @@ aq_rx_intr(void *arg) * 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 @@ aq_rx_intr(void *arg) } } #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 @@ aq_send_common_locked(struct ifnet *ifp, 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 @@ aq_ioctl(struct ifnet *ifp, unsigned lon { 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);