[dpdk-dev] [PATCH] ethdev: expose link status and speed using xstats

Harry van Haaren harry.van.haaren at intel.com
Wed Jan 20 15:28:06 CET 2016


This patch exposes link duplex, speed, and status via the
existing xstats API.

Signed-off-by: Harry van Haaren <harry.van.haaren at intel.com>
---
 doc/guides/rel_notes/release_2_3.rst |  1 +
 lib/librte_ether/rte_ethdev.c        | 29 ++++++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/doc/guides/rel_notes/release_2_3.rst b/doc/guides/rel_notes/release_2_3.rst
index 99de186..c3449dc 100644
--- a/doc/guides/rel_notes/release_2_3.rst
+++ b/doc/guides/rel_notes/release_2_3.rst
@@ -19,6 +19,7 @@ Drivers
 Libraries
 ~~~~~~~~~
 
+* **Link Status added to extended statistics in ethdev**
 
 Examples
 ~~~~~~~~
diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index ed971b4..3c35e1b 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -1,7 +1,7 @@
 /*-
  *   BSD LICENSE
  *
- *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
+ *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -83,6 +83,15 @@ struct rte_eth_xstats_name_off {
 	unsigned offset;
 };
 
+/* Link Status display in xstats */
+static const char * const rte_eth_duplex_strings[] = {
+	"link_duplex_autonegotiate",
+	"link_duplex_half",
+	"link_duplex_full"
+};
+
+#define RTE_NB_LINK_STATUS_STATS 3
+
 static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
 	{"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
 	{"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
@@ -94,7 +103,10 @@ static const struct rte_eth_xstats_name_off rte_stats_strings[] = {
 		rx_nombuf)},
 };
 
-#define RTE_NB_STATS (sizeof(rte_stats_strings) / sizeof(rte_stats_strings[0]))
+#define RTE_GENERIC_STATS (sizeof(rte_stats_strings) / \
+		sizeof(rte_stats_strings[0]))
+
+#define RTE_NB_STATS (RTE_NB_LINK_STATUS_STATS + RTE_GENERIC_STATS)
 
 static const struct rte_eth_xstats_name_off rte_rxq_stats_strings[] = {
 	{"packets", offsetof(struct rte_eth_stats, q_ipackets)},
@@ -1466,6 +1478,7 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 {
 	struct rte_eth_stats eth_stats;
 	struct rte_eth_dev *dev;
+	struct rte_eth_link link;
 	unsigned count = 0, i, q;
 	signed xcount = 0;
 	uint64_t val, *stats_ptr;
@@ -1497,8 +1510,18 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats,
 	count = 0;
 	rte_eth_stats_get(port_id, &eth_stats);
 
+	/* link status */
+	rte_eth_link_get_nowait(port_id, &link);
+	snprintf(xstats[count].name, sizeof(xstats[count].name), "link_status");
+	xstats[count++].value = link.link_status;
+	snprintf(xstats[count].name, sizeof(xstats[count].name), "link_speed");
+	xstats[count++].value = link.link_speed;
+	snprintf(xstats[count].name, sizeof(xstats[count].name),
+		 "%s", rte_eth_duplex_strings[link.link_duplex]);
+	xstats[count++].value = 1;
+
 	/* global stats */
-	for (i = 0; i < RTE_NB_STATS; i++) {
+	for (i = 0; i < RTE_GENERIC_STATS; i++) {
 		stats_ptr = RTE_PTR_ADD(&eth_stats,
 					rte_stats_strings[i].offset);
 		val = *stats_ptr;
-- 
2.5.0



More information about the dev mailing list