From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by dpdk.org (Postfix) with ESMTP id 005661B6F0 for ; Tue, 24 Oct 2017 01:15:46 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP; 23 Oct 2017 16:15:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,424,1503385200"; d="scan'208";a="1028475947" Received: from silpixa00372839.ir.intel.com (HELO silpixa00372839.ger.corp.intel.com) ([10.237.222.154]) by orsmga003.jf.intel.com with ESMTP; 23 Oct 2017 16:15:44 -0700 From: Ferruh Yigit To: Thomas Monjalon Cc: dev@dpdk.org, Ferruh Yigit , Ivan Malov , Harry Van Haaren , Lee Daly Date: Tue, 24 Oct 2017 00:15:33 +0100 Message-Id: <20171023231534.90996-2-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171023231534.90996-1-ferruh.yigit@intel.com> References: <20171023231251.90845-1-ferruh.yigit@intel.com> <20171023231534.90996-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH v2 2/3] ethdev: fix xstats get by id APIS X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Oct 2017 23:15:47 -0000 xstats _by_id() APIs are broken because ids known by user sent directly to the PMDs. ethdev xstat get by id APIs: rte_eth_xstats_get_names_by_id() and rte_eth_xstats_get_by_id() work on ids calculated as "basic stats + extended stats" When an application asking for id less than "basic stats count", it is indeed asking basic stats not extended stats. The dev_ops PMDs implements work on extended stats ids. This patch adds a check if all requested stats are xstats and if so converts ids to xstats ids before passing them to PMDs. This conversion wasn't required before commit 8c49d5f1c219, because _by_id dev_ops were always used to get whole stats via NULL ids. Fixes: 8c49d5f1c219 ("ethdev: rework xstats retrieve by id") Signed-off-by: Ferruh Yigit Reviewed-by: Ivan Malov Tested-by: Ivan Malov --- Cc: Ivan Malov Cc: Harry Van Haaren Cc: Lee Daly v2: * variable renamed, all_ids_from_pmd -> no_basic_stat_requested * xstats id conversion commented. --- lib/librte_ether/rte_ethdev.c | 50 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 798855e15..15ed2df10 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1644,6 +1644,7 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id, uint64_t *ids) { struct rte_eth_xstat_name *xstats_names_copy; + unsigned int no_basic_stat_requested = 1; unsigned int expected_entries; struct rte_eth_dev *dev; unsigned int i; @@ -1663,9 +1664,27 @@ rte_eth_xstats_get_names_by_id(uint16_t port_id, if (ids && !xstats_names) return -EINVAL; - if (dev->dev_ops->xstats_get_names_by_id != NULL) - return (*dev->dev_ops->xstats_get_names_by_id)( - dev, xstats_names, ids, size); + if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) { + unsigned int basic_count = get_xstats_basic_count(dev); + uint64_t ids_copy[size]; + + for (i = 0; i < size; i++) { + if (ids[i] < basic_count) { + no_basic_stat_requested = 0; + break; + } + + /* + * Convert ids to xstats ids that PMD knows. + * ids known by user are basic + extended stats. + */ + ids_copy[i] = ids[i] - basic_count; + } + + if (no_basic_stat_requested) + return (*dev->dev_ops->xstats_get_names_by_id)(dev, + xstats_names, ids_copy, size); + } /* Retrieve all stats */ if (!ids) { @@ -1772,6 +1791,7 @@ int rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, uint64_t *values, unsigned int size) { + unsigned int no_basic_stat_requested = 1; unsigned int num_xstats_filled; uint16_t expected_entries; struct rte_eth_dev *dev; @@ -1793,9 +1813,27 @@ rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, if (ids && !values) return -EINVAL; - if (dev->dev_ops->xstats_get_by_id != NULL) - return (*dev->dev_ops->xstats_get_by_id)(dev, ids, values, - size); + if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) { + unsigned int basic_count = get_xstats_basic_count(dev); + uint64_t ids_copy[size]; + + for (i = 0; i < size; i++) { + if (ids[i] < basic_count) { + no_basic_stat_requested = 0; + break; + } + + /* + * Convert ids to xstats ids that PMD knows. + * ids known by user are basic + extended stats. + */ + ids_copy[i] = ids[i] - basic_count; + } + + if (no_basic_stat_requested) + return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy, + values, size); + } /* Fill the xstats structure */ num_xstats_filled = rte_eth_xstats_get(port_id, xstats, -- 2.13.6