DPDK patches and discussions
 help / color / mirror / Atom feed
From: Zhiyong Yang <zhiyong.yang@intel.com>
To: dev@dpdk.org, yliu@fridaylinux.org, maxime.coquelin@redhat.com
Cc: wei.w.wang@intel.com, jianfeng.tan@intel.com,
	Zhiyong Yang <zhiyong.yang@intel.com>
Subject: [dpdk-dev] [PATCH 10/11] net/vhostpci: support RX/TX packets statistics
Date: Thu, 30 Nov 2017 17:46:56 +0800	[thread overview]
Message-ID: <20171130094657.11470-11-zhiyong.yang@intel.com> (raw)
In-Reply-To: <20171130094657.11470-1-zhiyong.yang@intel.com>

Add the functions to support for TX/RX pkts statistics.

Signed-off-by: Zhiyong Yang <zhiyong.yang@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

  parent reply	other threads:[~2017-11-30  9:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-30  9:46 [dpdk-dev] [PATCH 00/11] net/vhostpci: A new vhostpci PMD supporting VM2VM scenario Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 01/11] drivers/net: add vhostpci PMD base files Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 02/11] net/vhostpci: public header files Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 03/11] net/vhostpci: add debugging log macros Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 04/11] net/vhostpci: add basic framework Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 05/11] net/vhostpci: add queue setup Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 06/11] net/vhostpci: add support for link status change Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 07/11] net/vhostpci: get remote memory region and vring info Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 08/11] net/vhostpci: add RX function Zhiyong Yang
2017-11-30  9:46 ` [dpdk-dev] [PATCH 09/11] net/vhostpci: add TX function Zhiyong Yang
2017-11-30  9:46 ` Zhiyong Yang [this message]
2017-11-30  9:46 ` [dpdk-dev] [PATCH 11/11] net/vhostpci: update release note Zhiyong Yang
2017-12-05  6:59 ` [dpdk-dev] [PATCH 00/11] net/vhostpci: A new vhostpci PMD supporting VM2VM scenario Yang, Zhiyong
2017-12-05 14:08   ` Yuanhan Liu
2017-12-06  3:00     ` Wei Wang
2017-12-07  6:07   ` Yang, Zhiyong
2017-12-19 11:14 ` Maxime Coquelin
2017-12-20  1:51   ` Yang, Zhiyong
2017-12-21  5:52     ` Tan, Jianfeng
2017-12-21  6:21       ` Yang, Zhiyong
2017-12-21  6:26         ` Yang, Zhiyong
2017-12-21  8:26           ` Maxime Coquelin
2017-12-21  8:40             ` Yang, Zhiyong
2018-01-11 11:13   ` Yang, Zhiyong
2018-01-18  9:04     ` Maxime Coquelin
2018-01-19  1:56       ` Yang, Zhiyong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171130094657.11470-11-zhiyong.yang@intel.com \
    --to=zhiyong.yang@intel.com \
    --cc=dev@dpdk.org \
    --cc=jianfeng.tan@intel.com \
    --cc=maxime.coquelin@redhat.com \
    --cc=wei.w.wang@intel.com \
    --cc=yliu@fridaylinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).