From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 42F6F7CFA for ; Thu, 30 Nov 2017 10:47:38 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Nov 2017 01:47:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,341,1508828400"; d="scan'208";a="1250236865" Received: from unknown (HELO dpdk5.bj.intel.com) ([172.16.182.182]) by fmsmga002.fm.intel.com with ESMTP; 30 Nov 2017 01:47:36 -0800 From: Zhiyong Yang To: dev@dpdk.org, yliu@fridaylinux.org, maxime.coquelin@redhat.com Cc: wei.w.wang@intel.com, jianfeng.tan@intel.com, Zhiyong Yang Date: Thu, 30 Nov 2017 17:46:56 +0800 Message-Id: <20171130094657.11470-11-zhiyong.yang@intel.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20171130094657.11470-1-zhiyong.yang@intel.com> References: <20171130094657.11470-1-zhiyong.yang@intel.com> Subject: [dpdk-dev] [PATCH 10/11] net/vhostpci: support RX/TX packets statistics X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Nov 2017 09:47:39 -0000 Add the functions to support for TX/RX pkts statistics. Signed-off-by: Zhiyong Yang --- 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