Add the functions to support for TX/RX pkts statistics. Signed-off-by: Zhiyong Yang <zhiyong.y...@intel.com> --- drivers/net/vhostpci/vhostpci_ethdev.c | 73 ++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
diff --git a/drivers/net/vhostpci/vhostpci_ethdev.c b/drivers/net/vhostpci/vhostpci_ethdev.c index f233d85a8..3dd09e2ea 100644 --- a/drivers/net/vhostpci/vhostpci_ethdev.c +++ b/drivers/net/vhostpci/vhostpci_ethdev.c @@ -129,11 +129,19 @@ vhostpci_dev_stop(struct rte_eth_dev *dev); static int vhostpci_get_remote_mem(struct rte_eth_dev *dev); +static void +vhostpci_dev_stats_reset(struct rte_eth_dev *dev); + +static int +vhostpci_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats); + static const struct eth_dev_ops vhostpci_eth_dev_ops = { .dev_start = vhostpci_dev_start, .dev_stop = vhostpci_dev_stop, .dev_close = vhostpci_dev_close, .dev_infos_get = vhostpci_dev_info_get, + .stats_get = vhostpci_dev_stats_get, + .stats_reset = vhostpci_dev_stats_reset, .dev_configure = vhostpci_dev_configure, .link_update = vhostpci_dev_link_update, .rx_queue_setup = vhostpci_dev_rx_queue_setup, @@ -284,6 +292,71 @@ vhostpci_dev_configure(struct rte_eth_dev *dev __rte_unused) } static int +vhostpci_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) +{ + int i; + unsigned long rx_total = 0, tx_total = 0, tx_missed_total = 0; + unsigned long rx_total_bytes = 0, tx_total_bytes = 0; + struct vhostpci_queue *vq; + + for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && + i < dev->data->nb_rx_queues; i++) { + if (dev->data->rx_queues[i] == NULL) + continue; + vq = dev->data->rx_queues[i]; + stats->q_ipackets[i] = vq->stats.pkts; + rx_total += stats->q_ipackets[i]; + + stats->q_ibytes[i] = vq->stats.bytes; + rx_total_bytes += stats->q_ibytes[i]; + } + + for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS && + i < dev->data->nb_tx_queues; i++) { + if (dev->data->tx_queues[i] == NULL) + continue; + vq = dev->data->tx_queues[i]; + stats->q_opackets[i] = vq->stats.pkts; + tx_missed_total += vq->stats.missed_pkts; + tx_total += stats->q_opackets[i]; + + stats->q_obytes[i] = vq->stats.bytes; + tx_total_bytes += stats->q_obytes[i]; + } + + stats->ipackets = rx_total; + stats->opackets = tx_total; + stats->oerrors = tx_missed_total; + stats->ibytes = rx_total_bytes; + stats->obytes = tx_total_bytes; + + return 0; +} + +static void +vhostpci_dev_stats_reset(struct rte_eth_dev *dev) +{ + struct vhostpci_queue *vq; + int i; + + for (i = 0; i < dev->data->nb_rx_queues; i++) { + if (dev->data->rx_queues[i] == NULL) + continue; + vq = dev->data->rx_queues[i]; + vq->stats.pkts = 0; + vq->stats.bytes = 0; + } + for (i = 0; i < dev->data->nb_tx_queues; i++) { + if (dev->data->tx_queues[i] == NULL) + continue; + vq = dev->data->tx_queues[i]; + vq->stats.pkts = 0; + vq->stats.bytes = 0; + vq->stats.missed_pkts = 0; + } +} + +static int vhostpci_dev_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id, uint16_t nb_rx_desc __rte_unused, unsigned int socket_id, -- 2.13.3