From patchwork Wed Jan 20 14:28:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 10000 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id AD2A88E63; Wed, 20 Jan 2016 15:28:23 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C93648E62 for ; Wed, 20 Jan 2016 15:28:21 +0100 (CET) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 20 Jan 2016 06:28:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,321,1449561600"; d="scan'208";a="32973825" Received: from sie-lab-212-120.ir.intel.com (HELO silpixa00394367.ir.intel.com) ([10.237.212.120]) by fmsmga004.fm.intel.com with ESMTP; 20 Jan 2016 06:28:20 -0800 From: Harry van Haaren To: thomas.monjalon@6wind.com Date: Wed, 20 Jan 2016 14:28:06 +0000 Message-Id: <1453300086-3756-1-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.5.0 Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH] ethdev: expose link status and speed using xstats X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch exposes link duplex, speed, and status via the existing xstats API. Signed-off-by: Harry van Haaren --- 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, ð_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(ð_stats, rte_stats_strings[i].offset); val = *stats_ptr;