From patchwork Fri Oct 20 00:03:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferruh Yigit X-Patchwork-Id: 30618 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 69B101B2F7; Fri, 20 Oct 2017 02:04:01 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 5225F1B2E9 for ; Fri, 20 Oct 2017 02:03:57 +0200 (CEST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2017 17:03:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,404,1503385200"; d="scan'208";a="165254446" Received: from silpixa00372839.ir.intel.com (HELO silpixa00372839.ger.corp.intel.com) ([10.237.222.154]) by fmsmga006.fm.intel.com with ESMTP; 19 Oct 2017 17:03:55 -0700 From: Ferruh Yigit To: Thomas Monjalon Cc: dev@dpdk.org, Ferruh Yigit , Ivan Malov , Harry Van Haaren , Lee Daly Date: Fri, 20 Oct 2017 01:03:50 +0100 Message-Id: <20171020000351.57868-2-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171020000351.57868-1-ferruh.yigit@intel.com> References: <20171020000351.57868-1-ferruh.yigit@intel.com> Subject: [dpdk-dev] [PATCH 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" ethdev xstat get by id APIs: rte_eth_xstats_get_names_by_id() rte_eth_xstats_get_by_id() Works on ids calculated as "basic stats + device specific stats" When an application asking for id less than "basic stats count", it is indeed asking basic stats nothing specific to device stats. The dev_ops PMDs implements xstats_get_names_by_id and xstats_get_by_id works on device specific ids. This patch adds a check if all stats requested by ids can be provided via device and if so converts ids to device specific ones. This conversion wasn't required before commit 8c49d5f1c219, because _by_id dev_ops were always used to get whole stats instead of specific 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 --- lib/librte_ether/rte_ethdev.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 798855e15..4ed2f6d5f 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 all_ids_from_pmd = 1; unsigned int expected_entries; struct rte_eth_dev *dev; unsigned int i; @@ -1663,9 +1664,23 @@ 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) { + all_ids_from_pmd = 0; + break; + } + + ids_copy[i] = ids[i] - basic_count; + } + + if (all_ids_from_pmd) + return (*dev->dev_ops->xstats_get_names_by_id)(dev, + xstats_names, ids_copy, size); + } /* Retrieve all stats */ if (!ids) { @@ -1772,6 +1787,7 @@ int rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, uint64_t *values, unsigned int size) { + unsigned int all_ids_from_pmd = 1; unsigned int num_xstats_filled; uint16_t expected_entries; struct rte_eth_dev *dev; @@ -1793,9 +1809,23 @@ 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) { + all_ids_from_pmd = 0; + break; + } + + ids_copy[i] = ids[i] - basic_count; + } + + if (all_ids_from_pmd) + 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,