[8/8] net/mvneta: add reset statistics callback

Message ID 1535469030-18647-9-git-send-email-amo@semihalf.com
State Superseded, archived
Delegated to: Ferruh Yigit
Headers show
Series
  • Add Marvell NETA PMD
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Andrzej Ostruszka Aug. 28, 2018, 3:10 p.m.
From: Natalie Samsonov <nsamsono@marvell.com>

Add support for reseting of driver statistics.

Singed-off-by: Natalie Samsonov <nsamsono@marvell.com>
---
 drivers/net/mvneta/mvneta_ethdev.c | 40 +++++++++++++++++++++++++++++++-------
 drivers/net/mvneta/mvneta_ethdev.h |  1 +
 2 files changed, 34 insertions(+), 7 deletions(-)

Patch

diff --git a/drivers/net/mvneta/mvneta_ethdev.c b/drivers/net/mvneta/mvneta_ethdev.c
index 9bff6c3..9bad2e3 100644
--- a/drivers/net/mvneta/mvneta_ethdev.c
+++ b/drivers/net/mvneta/mvneta_ethdev.c
@@ -1707,23 +1707,48 @@  mvneta_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 
 	stats->ipackets += ppio_stats.rx_packets +
 			ppio_stats.rx_broadcast_packets +
-			ppio_stats.rx_multicast_packets;
+			ppio_stats.rx_multicast_packets -
+			priv->prev_stats.ipackets;
 	stats->opackets += ppio_stats.tx_packets +
 			ppio_stats.tx_broadcast_packets +
-			ppio_stats.tx_multicast_packets;
-	stats->ibytes += ppio_stats.rx_bytes;
-	stats->obytes += ppio_stats.tx_bytes;
+			ppio_stats.tx_multicast_packets -
+			priv->prev_stats.opackets;
+	stats->ibytes += ppio_stats.rx_bytes - priv->prev_stats.ibytes;
+	stats->obytes += ppio_stats.tx_bytes - priv->prev_stats.obytes;
 	stats->imissed += ppio_stats.rx_discard +
-			  ppio_stats.rx_overrun;
+			  ppio_stats.rx_overrun -
+			  priv->prev_stats.imissed;
 
 	stats->ierrors = ppio_stats.rx_packets_err +
 			ppio_stats.rx_errors +
-			ppio_stats.rx_crc_error;
-	stats->oerrors = ppio_stats.tx_errors;
+			ppio_stats.rx_crc_error -
+			priv->prev_stats.ierrors;
+	stats->oerrors = ppio_stats.tx_errors - priv->prev_stats.oerrors;
 
 	return 0;
 }
 
+/**
+ * DPDK callback to clear device statistics.
+ *
+ * @param dev
+ *   Pointer to Ethernet device structure.
+ */
+static void
+mvneta_stats_reset(struct rte_eth_dev *dev)
+{
+	struct mvneta_priv *priv = dev->data->dev_private;
+	unsigned int ret;
+
+	if (!priv->ppio)
+		return;
+
+	ret = mvneta_stats_get(dev, &priv->prev_stats);
+	if (unlikely(ret))
+		RTE_LOG(ERR, PMD, "Failed to reset port statistics\n");
+}
+
+
 static const struct eth_dev_ops mvneta_ops = {
 	.dev_configure = mvneta_dev_configure,
 	.dev_start = mvneta_dev_start,
@@ -1739,6 +1764,7 @@  static const struct eth_dev_ops mvneta_ops = {
 	.mac_addr_set = mvneta_mac_addr_set,
 	.mtu_set = mvneta_mtu_set,
 	.stats_get = mvneta_stats_get,
+	.stats_reset = mvneta_stats_reset,
 	.dev_infos_get = mvneta_dev_infos_get,
 	.dev_supported_ptypes_get = mvneta_dev_supported_ptypes_get,
 	.rxq_info_get = mvneta_rxq_info_get,
diff --git a/drivers/net/mvneta/mvneta_ethdev.h b/drivers/net/mvneta/mvneta_ethdev.h
index a05566d..6aed170 100644
--- a/drivers/net/mvneta/mvneta_ethdev.h
+++ b/drivers/net/mvneta/mvneta_ethdev.h
@@ -77,6 +77,7 @@  struct mvneta_priv {
 	uint16_t nb_rx_queues;
 
 	uint64_t rate_max;
+	struct rte_eth_stats prev_stats;
 };
 
 /** Current log type. */