All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harry van Haaren <harry.van.haaren@intel.com>
To: thomas.monjalon@6wind.com
Cc: dev@dpdk.org
Subject: [PATCH] ethdev: expose link status and speed using xstats
Date: Wed, 20 Jan 2016 14:28:06 +0000	[thread overview]
Message-ID: <1453300086-3756-1-git-send-email-harry.van.haaren@intel.com> (raw)

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

Signed-off-by: Harry van Haaren <harry.van.haaren@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

             reply	other threads:[~2016-01-20 14:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-20 14:28 Harry van Haaren [this message]
2016-01-20 14:35 ` [PATCH] ethdev: expose link status and speed using xstats Kyle Larose
2016-01-20 14:45   ` Van Haaren, Harry
2016-01-20 15:03     ` Kyle Larose
2016-01-20 15:13       ` Thomas Monjalon
2016-01-20 15:58         ` Van Haaren, Harry
2016-01-20 18:36         ` Stephen Hemminger

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=1453300086-3756-1-git-send-email-harry.van.haaren@intel.com \
    --to=harry.van.haaren@intel.com \
    --cc=dev@dpdk.org \
    --cc=thomas.monjalon@6wind.com \
    /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 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.