All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v1] rte: add bit-rate metrics to xstats
@ 2016-08-24 14:58 Remy Horton
  2016-08-26 13:28 ` Pattan, Reshma
                   ` (2 more replies)
  0 siblings, 3 replies; 115+ messages in thread
From: Remy Horton @ 2016-08-24 14:58 UTC (permalink / raw)
  To: thomas.monjalon; +Cc: dev

This patch adds peak and average data-rate metrics to the extended
statistics. The intervals used to generate the statistics are
controlled by any application wishing to make use of these metrics.

Signed-off-by: Remy Horton <remy.horton@intel.com>
---
 doc/guides/rel_notes/release_16_11.rst |   5 ++
 lib/librte_ether/rte_ethdev.c          | 107 ++++++++++++++++++++++++++++++++-
 lib/librte_ether/rte_ethdev.h          |  41 +++++++++++++
 lib/librte_ether/rte_ether_version.map |   6 ++
 4 files changed, 157 insertions(+), 2 deletions(-)

diff --git a/doc/guides/rel_notes/release_16_11.rst b/doc/guides/rel_notes/release_16_11.rst
index 0b9022d..b319292 100644
--- a/doc/guides/rel_notes/release_16_11.rst
+++ b/doc/guides/rel_notes/release_16_11.rst
@@ -36,6 +36,11 @@ New Features
 
      This section is a comment. Make sure to start the actual text at the margin.
 
+   * **Added data-rate metrics to the extended statistics.**
+
+     Adds peak and average incoming and outgoing data-rate metrics to the
+     extended statistics, the calculation of which is controlled by
+     applications that wish for these to be derived.
 
 Resolved Issues
 ---------------
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index f62a9ec..71549b4 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -101,6 +101,7 @@ static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
 };
 
 #define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
+#define RTE_NB_DEV_STATS 4
 
 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_ipackets)},
@@ -1499,6 +1500,7 @@ void
 rte_eth_stats_reset(uint8_t port_id)
 {
 	struct rte_eth_dev *dev;
+	struct rte_eth_dev_stats *dev_stats;
 
 	RTE_ETH_VALID_PORTID_OR_RET(port_id);
 	dev = &rte_eth_devices[port_id];
@@ -1506,6 +1508,19 @@ rte_eth_stats_reset(uint8_t port_id)
 	RTE_FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset);
 	(*dev->dev_ops->stats_reset)(dev);
 	dev->data->rx_mbuf_alloc_failed = 0;
+
+	/* Clear device running stat counts */
+	dev_stats = &dev->data->stats;
+	memset(dev_stats->list_ibuckets, 0,
+		sizeof(uint64_t) * dev_stats->cnt_buckets);
+	memset(dev_stats->list_obuckets, 0,
+		sizeof(uint64_t) * dev_stats->cnt_buckets);
+	dev_stats->last_ibytes = 0;
+	dev_stats->last_obytes = 0;
+	dev_stats->peak_ibytes = 0;
+	dev_stats->peak_obytes = 0;
+	dev_stats->total_ibytes = 0;
+	dev_stats->total_obytes = 0;
 }
 
 static int
@@ -1522,7 +1537,7 @@ get_xstats_count(uint8_t port_id)
 			return count;
 	} else
 		count = 0;
-	count += RTE_NB_STATS;
+	count += RTE_NB_STATS + RTE_NB_DEV_STATS;
 	count += dev->data->nb_rx_queues * RTE_NB_RXQ_STATS;
 	count += dev->data->nb_tx_queues * RTE_NB_TXQ_STATS;
 	return count;
@@ -1574,6 +1589,19 @@ rte_eth_xstats_get_names(uint8_t port_id,
 		}
 	}
 
+	snprintf(xstats_names[cnt_used_entries++].name,
+		sizeof(xstats_names[0].name),
+		"tx_peak_bytes");
+	snprintf(xstats_names[cnt_used_entries++].name,
+		sizeof(xstats_names[0].name),
+		"tx_mean_bytes");
+	snprintf(xstats_names[cnt_used_entries++].name,
+		sizeof(xstats_names[0].name),
+		"rx_peak_bytes");
+	snprintf(xstats_names[cnt_used_entries++].name,
+		sizeof(xstats_names[0].name),
+		"rx_mean_bytes");
+
 	if (dev->dev_ops->xstats_get_names != NULL) {
 		/* If there are any driver-specific xstats, append them
 		 * to end of list.
@@ -1600,14 +1628,16 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
 	unsigned count = 0, i, q;
 	signed xcount = 0;
 	uint64_t val, *stats_ptr;
+	struct rte_eth_dev_stats *dev_stats;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
 
 	dev = &rte_eth_devices[port_id];
+	dev_stats = &dev->data->stats;
 
 	/* Return generic statistics */
 	count = RTE_NB_STATS + (dev->data->nb_rx_queues * RTE_NB_RXQ_STATS) +
-		(dev->data->nb_tx_queues * RTE_NB_TXQ_STATS);
+		(dev->data->nb_tx_queues * RTE_NB_TXQ_STATS) + RTE_NB_DEV_STATS;
 
 	/* implemented by the driver */
 	if (dev->dev_ops->xstats_get != NULL) {
@@ -1659,12 +1689,85 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
 		}
 	}
 
+	xstats[count++].value = dev_stats->peak_obytes;
+	xstats[count++].value =
+		dev_stats->total_obytes / dev_stats->cnt_buckets;
+	xstats[count++].value = dev_stats->peak_ibytes;
+	xstats[count++].value =
+		dev_stats->total_ibytes / dev_stats->cnt_buckets;
+
 	for (i = 0; i < count + xcount; i++)
 		xstats[i].id = i;
 
 	return count + xcount;
 }
 
+int
+rte_eth_dev_stats_init(uint8_t port_id, uint32_t cnt_buckets)
+{
+	struct rte_eth_dev *dev;
+	struct rte_eth_dev_stats *stats;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
+	dev = &rte_eth_devices[port_id];
+	stats = &dev->data->stats;
+
+	memset(stats, 0, sizeof(struct rte_eth_dev_stats));
+	stats->list_ibuckets = rte_zmalloc(
+		NULL, sizeof(uint64_t) * cnt_buckets, 0);
+	stats->list_obuckets = rte_zmalloc(
+		NULL, sizeof(uint64_t) * cnt_buckets, 0);
+	if (stats->list_ibuckets == NULL || stats->list_obuckets == NULL)
+		return -ENOMEM;
+	stats->cnt_buckets = cnt_buckets;
+	return 0;
+}
+
+int
+rte_eth_dev_stats_calc(uint8_t port_id)
+{
+	struct rte_eth_dev *dev;
+	uint64_t *metric;
+	uint64_t cnt_bytes_in_bucket;
+	struct rte_eth_dev_stats *stats;
+	struct rte_eth_stats eth_stats;
+	unsigned ret_code;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL);
+	dev = &rte_eth_devices[port_id];
+	stats = &dev->data->stats;
+
+	ret_code = rte_eth_stats_get(port_id, &eth_stats);
+	if (ret_code != 0)
+		return ret_code;
+
+	/* tx_good_bytes */
+	metric = RTE_PTR_ADD(&eth_stats, rte_stats_strings[3].offset);
+	cnt_bytes_in_bucket = *metric - stats->last_obytes;
+	stats->last_obytes = *metric;
+	if (cnt_bytes_in_bucket > stats->peak_obytes)
+		stats->peak_obytes = cnt_bytes_in_bucket;
+	stats->total_obytes -= stats->list_obuckets[stats->next_bucket];
+	stats->total_obytes += cnt_bytes_in_bucket;
+	stats->list_obuckets[stats->next_bucket] = cnt_bytes_in_bucket;
+
+	/* rx_good_bytes */
+	metric = RTE_PTR_ADD(&eth_stats, rte_stats_strings[2].offset);
+	cnt_bytes_in_bucket = *metric - stats->last_ibytes;
+	stats->last_ibytes = *metric;
+	if (cnt_bytes_in_bucket > stats->peak_ibytes)
+		stats->peak_ibytes = cnt_bytes_in_bucket;
+	stats->total_ibytes -= stats->list_ibuckets[stats->next_bucket];
+	stats->total_ibytes += cnt_bytes_in_bucket;
+	stats->list_ibuckets[stats->next_bucket] = cnt_bytes_in_bucket;
+
+	/* index wraparound */
+	if (++stats->next_bucket == stats->cnt_buckets)
+		stats->next_bucket = 0;
+
+	return 0;
+}
+
 /* reset ethdev extended statistics */
 void
 rte_eth_xstats_reset(uint8_t port_id)
diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h
index b0fe033..4b1b47b 100644
--- a/lib/librte_ether/rte_ethdev.h
+++ b/lib/librte_ether/rte_ethdev.h
@@ -1656,6 +1656,19 @@ struct rte_eth_dev_sriov {
 
 #define RTE_ETH_NAME_MAX_LEN (32)
 
+struct rte_eth_dev_stats {
+	uint64_t *list_ibuckets;
+	uint64_t *list_obuckets;
+	uint32_t cnt_buckets;
+	uint32_t next_bucket;
+	uint64_t last_ibytes;
+	uint64_t last_obytes;
+	uint64_t peak_ibytes;
+	uint64_t peak_obytes;
+	uint64_t total_ibytes;
+	uint64_t total_obytes;
+};
+
 /**
  * @internal
  * The data part, with no function pointers, associated with each ethernet device.
@@ -1670,6 +1683,7 @@ struct rte_eth_dev_data {
 	void **tx_queues; /**< Array of pointers to TX queues. */
 	uint16_t nb_rx_queues; /**< Number of RX queues. */
 	uint16_t nb_tx_queues; /**< Number of TX queues. */
+	struct rte_eth_dev_stats stats; /**< Device stats metrics */
 
 	struct rte_eth_dev_sriov sriov;    /**< SRIOV data */
 
@@ -2328,6 +2342,33 @@ int rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstat *xstats,
 		unsigned n);
 
 /**
+ *  Initialise device statistics.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device
+ * @param cnt_buckets
+ *   Number of sampling buckets within sampling window.
+ * @return
+ *   - Zero on success.
+ *   - Negative value on error.
+ */
+int rte_eth_dev_stats_init(uint8_t port_id, uint32_t cnt_buckets);
+
+/**
+ *  Calculate device statistics.
+ *  This function need to be called periodically. The time between each
+ *  invocation is the sampling period of an individual time bucket within
+ *  the sampling window.
+ *
+ * @param port_id
+ *   The port identifier of the Ethernet device
+ * @return
+ *   - Zero on success.
+ *   - Negative value on error.
+ */
+int rte_eth_dev_stats_calc(uint8_t port_id);
+
+/**
  * Reset extended statistics of an Ethernet device.
  *
  * @param port_id
diff --git a/lib/librte_ether/rte_ether_version.map b/lib/librte_ether/rte_ether_version.map
index 45ddf44..bb7d1cf 100644
--- a/lib/librte_ether/rte_ether_version.map
+++ b/lib/librte_ether/rte_ether_version.map
@@ -139,3 +139,9 @@ DPDK_16.07 {
 	rte_eth_dev_get_port_by_name;
 	rte_eth_xstats_get_names;
 } DPDK_16.04;
+
+DPDK_16.11 {
+	global:
+
+	rte_eth_dev_stats_calc;
+} DPDK_16.07;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 115+ messages in thread

end of thread, other threads:[~2017-03-10  9:48 UTC | newest]

Thread overview: 115+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-24 14:58 [RFC PATCH v1] rte: add bit-rate metrics to xstats Remy Horton
2016-08-26 13:28 ` Pattan, Reshma
2016-08-29 10:01 ` Pattan, Reshma
2016-08-29 11:19   ` Remy Horton
2016-10-28  1:04 ` [PATCH v2 0/3] expanded statistic reporting Remy Horton
2016-10-28  1:04   ` [RFC PATCH v2 1/3] lib: add information metrics library Remy Horton
2016-10-28  1:04   ` [RFC PATCH v2 2/3] lib: add bitrate statistics library Remy Horton
2016-10-28  1:12     ` Stephen Hemminger
2016-10-28  7:48       ` Remy Horton
2016-10-28  7:39     ` Morten Brørup
2016-11-01  1:53       ` Remy Horton
2016-10-28  1:04   ` [RFC PATCH v2 3/3] app/test-pmd: add support for bitrate statistics Remy Horton
2016-11-04  3:36   ` [PATCH v3 0/3] Expanded statistics reporting Remy Horton
2016-11-04  3:36     ` [PATCH v3 1/3] lib: add information metrics library Remy Horton
2016-11-04 16:42       ` Pattan, Reshma
2016-11-07 15:25         ` Pattan, Reshma
2016-11-08  3:19           ` Remy Horton
2016-11-04  3:36     ` [PATCH v3 2/3] lib: add bitrate statistics library Remy Horton
2016-11-04  3:36     ` [PATCH v3 3/3] app/test-pmd: add support for bitrate statistics Remy Horton
2016-11-15  7:15     ` [PATCH v4 0/3] Expanded statistics reporting Remy Horton
2016-11-15  7:15       ` [PATCH v4 1/3] lib: add information metrics library Remy Horton
2016-11-15  7:15       ` [PATCH v4 2/3] lib: add bitrate statistics library Remy Horton
2016-11-15 15:17         ` Pattan, Reshma
2016-11-15  7:15       ` [PATCH v4 3/3] app/test-pmd: add support for bitrate statistics Remy Horton
2016-11-18  8:00       ` [PATCH v5 0/4] Expanded statistics reporting Remy Horton
2016-11-18  8:00         ` [PATCH v5 1/4] lib: add information metrics library Remy Horton
2016-11-18  8:00         ` [PATCH v5 2/4] lib: add bitrate statistics library Remy Horton
2016-11-18  8:00         ` [PATCH v5 3/4] app/test-pmd: add support for bitrate statistics Remy Horton
2016-11-18  8:00         ` [PATCH v5 4/4] latencystats: added new library for latency stats Remy Horton
2017-01-11 16:03         ` [PATCH v6 0/4] Expanded statistics reporting Remy Horton
2017-01-11 16:03           ` [PATCH v6 1/4] lib: add information metrics library Remy Horton
2017-01-12 13:22             ` Thomas Monjalon
2017-01-12 15:30               ` Remy Horton
2017-01-12 19:05                 ` Thomas Monjalon
2017-01-16 10:27                   ` Remy Horton
2017-01-11 16:03           ` [PATCH v6 2/4] lib: add bitrate statistics library Remy Horton
2017-01-11 16:15             ` Stephen Hemminger
2017-01-16 13:18               ` Remy Horton
2017-01-11 16:03           ` [PATCH v6 3/4] app/test-pmd: add support for bitrate statistics Remy Horton
2017-01-12 13:32             ` Thomas Monjalon
2017-01-11 16:03           ` [PATCH v6 4/4] latencystats: added new library for latency stats Remy Horton
2017-01-12 13:41             ` Thomas Monjalon
2017-01-12 14:44               ` Remy Horton
2017-01-13  9:45               ` Mcnamara, John
2017-01-13  9:53                 ` Thomas Monjalon
2017-01-16 16:18                   ` Mcnamara, John
2017-01-11 16:58           ` [PATCH v6 0/4] Expanded statistics reporting Thomas Monjalon
2017-01-16 16:19           ` [PATCH v7 0/6] " Remy Horton
2017-01-16 16:19             ` [PATCH v7 1/6] lib: add information metrics library Remy Horton
2017-01-17 11:01               ` Van Haaren, Harry
2017-01-17 13:40                 ` Remy Horton
2017-01-17 14:23                   ` Van Haaren, Harry
2017-01-16 16:19             ` [PATCH v7 2/6] app/proc_info: add metrics displaying Remy Horton
2017-01-17 11:08               ` Van Haaren, Harry
2017-01-17 14:27                 ` Remy Horton
2017-01-16 16:19             ` [PATCH v7 3/6] lib: add bitrate statistics library Remy Horton
2017-01-17 11:16               ` Van Haaren, Harry
2017-01-17 15:37                 ` Remy Horton
2017-01-16 16:19             ` [PATCH v7 4/6] app/test-pmd: add bitrate statistics calculation Remy Horton
2017-01-17 11:19               ` Van Haaren, Harry
2017-01-16 16:19             ` [PATCH v7 5/6] lib: added new library for latency stats Remy Horton
2017-01-17  4:29               ` Jerin Jacob
2017-01-17  6:48                 ` Remy Horton
2017-01-17  7:35                   ` Jerin Jacob
2017-01-17 11:19                 ` Mcnamara, John
2017-01-17 12:34                   ` Jerin Jacob
2017-01-17 14:53                     ` Mcnamara, John
2017-01-17 16:25                       ` Jerin Jacob
2017-01-18 20:11                         ` Olivier Matz
2017-01-24 15:24                           ` Olivier MATZ
2017-01-17 11:41               ` Van Haaren, Harry
2017-01-16 16:19             ` [PATCH v7 6/6] app/test-pmd: add latency statistics calculation Remy Horton
2017-01-17 11:45               ` Van Haaren, Harry
2017-01-17 23:24             ` [PATCH v8 0/7] Expanded statistics reporting Remy Horton
2017-01-17 23:24               ` [PATCH v8 1/7] lib: add information metrics library Remy Horton
2017-01-17 23:24               ` [PATCH v8 2/7] app/proc_info: add metrics displaying Remy Horton
2017-01-17 23:24               ` [PATCH v8 3/7] lib: add bitrate statistics library Remy Horton
2017-01-17 23:24               ` [PATCH v8 4/7] app/test-pmd: add bitrate statistics calculation Remy Horton
2017-01-17 23:24               ` [PATCH v8 5/7] mbuf: add a timestamp to the mbuf for latencystats Remy Horton
2017-01-17 23:24               ` [PATCH v8 6/7] lib: added new library for latency stats Remy Horton
2017-01-17 23:24               ` [PATCH v8 7/7] app/test-pmd: add latency statistics calculation Remy Horton
2017-01-18 15:05               ` [PATCH v9 0/7] Expanded statistics reporting Remy Horton
2017-01-18 15:05                 ` [PATCH v9 1/7] lib: add information metrics library Remy Horton
2017-01-30 15:50                   ` Thomas Monjalon
2017-01-30 21:44                     ` Remy Horton
2017-01-31 13:13                     ` Mcnamara, John
2017-01-31 13:28                       ` Bruce Richardson
2017-02-02 17:22                         ` Thomas Monjalon
2017-01-18 15:05                 ` [PATCH v9 2/7] app/proc_info: add metrics displaying Remy Horton
2017-01-18 15:05                 ` [PATCH v9 3/7] lib: add bitrate statistics library Remy Horton
2017-01-18 15:05                 ` [PATCH v9 4/7] app/test-pmd: add bitrate statistics calculation Remy Horton
2017-01-18 15:05                 ` [PATCH v9 5/7] mbuf: add a timestamp to the mbuf for latencystats Remy Horton
2017-01-18 15:05                 ` [PATCH v9 6/7] lib: added new library for latency stats Remy Horton
2017-01-18 15:05                 ` [PATCH v9 7/7] app/test-pmd: add latency statistics calculation Remy Horton
2017-02-03 10:33                 ` [PATCH v10 0/7] Expanded statistics reporting Remy Horton
2017-02-03 10:33                   ` [PATCH v10 1/7] lib: add information metrics library Remy Horton
2017-02-03 10:33                   ` [PATCH v10 2/7] app/proc_info: add metrics displaying Remy Horton
2017-02-03 10:33                   ` [PATCH v10 3/7] lib: add bitrate statistics library Remy Horton
2017-02-03 10:33                   ` [PATCH v10 4/7] app/test-pmd: add bitrate statistics calculation Remy Horton
2017-02-03 10:33                   ` [PATCH v10 5/7] mbuf: add a timestamp to the mbuf for latencystats Remy Horton
2017-02-03 10:33                   ` [PATCH v10 6/7] lib: added new library for latency stats Remy Horton
2017-02-03 10:33                   ` [PATCH v10 7/7] app/test-pmd: add latency statistics calculation Remy Horton
2017-02-16 10:53                   ` [PATCH v10 0/7] Expanded statistics reporting Thomas Monjalon
2017-02-23  7:09                     ` Remy Horton
2017-02-23  8:45                       ` Thomas Monjalon
2017-03-09 16:25                   ` [PATCH v11 " Remy Horton
2017-03-09 16:25                     ` [PATCH v11 1/7] lib: add information metrics library Remy Horton
2017-03-09 16:25                     ` [PATCH v11 2/7] app/proc_info: add metrics displaying Remy Horton
2017-03-09 16:25                     ` [PATCH v11 3/7] lib: add bitrate statistics library Remy Horton
2017-03-09 16:25                     ` [PATCH v11 4/7] app/test-pmd: add bitrate statistics calculation Remy Horton
2017-03-09 16:25                     ` [PATCH v11 5/7] mbuf: add a timestamp to the mbuf for latencystats Remy Horton
2017-03-09 19:02                       ` Stephen Hemminger
2017-03-10  9:48                         ` Van Haaren, Harry
2017-03-09 16:25                     ` [PATCH v11 6/7] lib: added new library for latency stats Remy Horton
2017-03-09 16:25                     ` [PATCH v11 7/7] app/test-pmd: add latency statistics calculation Remy Horton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.