From: Hiroshi Shimamoto <h-shimam...@ct.jp.nec.com> Implement packet accounting of MEMNIC on TX/RX.
Signed-off-by: Hiroshi Shimamoto <h-shimamoto at ct.jp.nec.com> Reviewed-by: Hayato Momma <h-momma at ce.jp.nec.com> --- pmd/pmd_memnic.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/pmd/pmd_memnic.c b/pmd/pmd_memnic.c index fc2d990..abfd437 100644 --- a/pmd/pmd_memnic.c +++ b/pmd/pmd_memnic.c @@ -255,18 +255,23 @@ static uint16_t memnic_recv_pkts(void *rx_queue, struct memnic_packet *p; struct rte_mbuf *mb; uint16_t nr; + uint64_t pkts, bytes, errs; int idx; + struct rte_eth_stats *st = &adapter->stats[rte_lcore_id()]; if (!adapter->nic->hdr.valid) return 0; + pkts = bytes = errs = 0; idx = adapter->up_idx; for (nr = 0; nr < nb_pkts; nr++) { p = &data->packets[idx]; if (p->status != MEMNIC_PKT_ST_FILLED) break; - if (p->len > MEMNIC_MAX_FRAME_LEN) + if (p->len > MEMNIC_MAX_FRAME_LEN) { + errs++; goto drop; + } mb = rte_pktmbuf_alloc(adapter->mp); if (!mb) break; @@ -279,6 +284,9 @@ static uint16_t memnic_recv_pkts(void *rx_queue, mb->pkt.data_len = p->len; rx_pkts[nr] = mb; + pkts++; + bytes += p->len; + drop: rte_mb(); p->status = MEMNIC_PKT_ST_FREE; @@ -288,6 +296,13 @@ drop: } adapter->up_idx = idx; + /* stats */ + st->ipackets += pkts; + st->ibytes += bytes; + st->ierrors += errs; + st->q_ipackets[0] += pkts; + st->q_ibytes[0] += bytes; + return nr; } @@ -300,14 +315,21 @@ static uint16_t memnic_xmit_pkts(void *tx_queue, struct memnic_packet *p; uint16_t nr; int idx, old; + struct rte_eth_stats *st = &adapter->stats[rte_lcore_id()]; + uint64_t pkts, bytes, errs; if (!adapter->nic->hdr.valid) return 0; + pkts = bytes = errs = 0; + for (nr = 0; nr < nb_pkts; nr++) { int len = rte_pktmbuf_data_len(tx_pkts[nr]); - if (len > MEMNIC_MAX_FRAME_LEN) + + if (len > MEMNIC_MAX_FRAME_LEN) { + errs++; break; + } retry: idx = ACCESS_ONCE(adapter->down_idx); p = &data->packets[idx]; @@ -315,6 +337,7 @@ retry: if (old != MEMNIC_PKT_ST_FREE) { if (old == MEMNIC_PKT_ST_FILLED && idx == ACCESS_ONCE(adapter->down_idx)) { + errs++; break; } goto retry; @@ -337,12 +360,22 @@ retry: rte_memcpy(p->data, rte_pktmbuf_mtod(tx_pkts[nr], void *), len); + pkts++; + bytes += len; + rte_mb(); p->status = MEMNIC_PKT_ST_FILLED; rte_pktmbuf_free(tx_pkts[nr]); } + /* stats */ + st->opackets += pkts; + st->obytes += bytes; + st->oerrors += errs; + st->q_opackets[0] += pkts; + st->q_obytes[0] += bytes; + return nr; } -- 1.8.4