[dpdk-dev] [PATCH 3/3] pcap: add byte and error counters into statistics

Tero Aho tero.aho at coriant.com
Fri Feb 27 14:42:40 CET 2015


Added input/ouput byte counters into pcap interface statistics,
also calls pcap_stats to add dropped packets into input errors.

Signed-off-by: Tero Aho <tero.aho at coriant.com>
---
 lib/librte_pmd_pcap/rte_eth_pcap.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c
index 3f23f0a..1c472ac 100644
--- a/lib/librte_pmd_pcap/rte_eth_pcap.c
+++ b/lib/librte_pmd_pcap/rte_eth_pcap.c
@@ -71,6 +71,7 @@ struct pcap_rx_queue {
        uint8_t in_port;
        struct rte_mempool *mb_pool;
        volatile unsigned long rx_pkts;
+       volatile unsigned long rx_octs;
        volatile unsigned long err_pkts;
        const char *name;
        const char *type;
@@ -80,6 +81,7 @@ struct pcap_tx_queue {
        pcap_dumper_t *dumper;
        pcap_t *pcap;
        volatile unsigned long tx_pkts;
+       volatile unsigned long tx_octs;
        volatile unsigned long err_pkts;
        const char *name;
        const char *type;
@@ -218,6 +220,7 @@ eth_pcap_rx(void *queue,
                                break;
                        }
                }
+               pcap_q->rx_octs += header.len;
                mbuf->pkt_len = (uint16_t)header.len;
                mbuf->port = pcap_q->in_port;
                bufs[num_rx] = mbuf;
@@ -261,6 +264,7 @@ eth_pcap_tx_dumper(void *queue,
                calculate_timestamp(&header.ts);
                header.len = mbuf->data_len;
                header.caplen = header.len;
+               dumper_q->tx_octs += header.len;
                pcap_dump((u_char *)dumper_q->dumper, &header,
                                rte_pktmbuf_mtod(mbuf, void*));
                rte_pktmbuf_free(mbuf);
@@ -324,9 +328,11 @@ eth_pcap_tx(void *queue,
                                              mbuf->data_len);
                else
                        ret = eth_pcap_tx_jumbo(tx_queue->pcap, mbuf);
+
                if (unlikely(ret != 0))
                        break;
                num_tx++;
+               tx_queue->tx_octs += mbuf->pkt_len;
                rte_pktmbuf_free(mbuf);
        }

@@ -471,26 +477,38 @@ eth_stats_get(struct rte_eth_dev *dev,
                struct rte_eth_stats *igb_stats)
 {
        unsigned i;
-       unsigned long rx_total = 0, tx_total = 0, tx_err_total = 0;
+       struct pcap_stat ps;
+       unsigned long ipackets = 0, ibytes = 0, ierrors = 0;
+       unsigned long opackets = 0, obytes = 0, oerrors = 0;
        const struct pmd_internals *internal = dev->data->dev_private;

        for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < internal->nb_rx_queues;
                        i++) {
                igb_stats->q_ipackets[i] = internal->rx_queue[i].rx_pkts;
-               rx_total += igb_stats->q_ipackets[i];
+               igb_stats->q_ibytes[i] = internal->rx_queue[i].rx_octs;
+               if (!pcap_stats(internal->rx_queue[i].pcap, &ps))
+                       igb_stats->q_errors[i] = ps.ps_drop;
+               ipackets += igb_stats->q_ipackets[i];
+               ibytes += igb_stats->q_ibytes[i];
+               ierrors += igb_stats->q_errors[i];
        }

        for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && i < internal->nb_tx_queues;
                        i++) {
                igb_stats->q_opackets[i] = internal->tx_queue[i].tx_pkts;
+               igb_stats->q_obytes[i] = internal->tx_queue[i].tx_octs;
                igb_stats->q_errors[i] = internal->tx_queue[i].err_pkts;
-               tx_total += igb_stats->q_opackets[i];
-               tx_err_total += igb_stats->q_errors[i];
+               opackets += igb_stats->q_opackets[i];
+               obytes += igb_stats->q_obytes[i];
+               oerrors += igb_stats->q_errors[i];
        }

-       igb_stats->ipackets = rx_total;
-       igb_stats->opackets = tx_total;
-       igb_stats->oerrors = tx_err_total;
+       igb_stats->ipackets = ipackets;
+       igb_stats->ibytes = ibytes;
+       igb_stats->ierrors = ierrors;
+       igb_stats->opackets = opackets;
+       igb_stats->obytes = obytes;
+       igb_stats->oerrors = oerrors;
 }

 static void
@@ -498,10 +516,13 @@ eth_stats_reset(struct rte_eth_dev *dev)
 {
        unsigned i;
        struct pmd_internals *internal = dev->data->dev_private;
-       for (i = 0; i < internal->nb_rx_queues; i++)
+       for (i = 0; i < internal->nb_rx_queues; i++) {
                internal->rx_queue[i].rx_pkts = 0;
+               internal->rx_queue[i].rx_octs = 0;
+       }
        for (i = 0; i < internal->nb_tx_queues; i++) {
                internal->tx_queue[i].tx_pkts = 0;
+               internal->tx_queue[i].tx_octs = 0;
                internal->tx_queue[i].err_pkts = 0;
        }
 }
--
1.9.1


============================================================
The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader
of this message is not the intended recipient, or an employee
or agent responsible for delivering this message to the
intended recipient, you are hereby notified that any reproduction,
dissemination or distribution of this communication is strictly
prohibited. If you have received this communication in error,
please notify us immediately by replying to the message and
deleting it from your computer. Thank you. Coriant-Tellabs
============================================================


More information about the dev mailing list