From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 747E51D8E for ; Wed, 6 Dec 2017 01:25:19 +0100 (CET) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Dec 2017 16:25:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,365,1508828400"; d="scan'208";a="156392802" Received: from ar11-dell-r730-21.jf.intel.com ([10.166.189.23]) by orsmga004.jf.intel.com with ESMTP; 05 Dec 2017 16:25:18 -0800 From: Elza Mathew To: thomas@monjalon.net Cc: dev@dpdk.org Date: Tue, 5 Dec 2017 16:25:07 -0800 Message-Id: <1512519907-62388-2-git-send-email-elza.mathew@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1512519907-62388-1-git-send-email-elza.mathew@intel.com> References: <1512519907-62388-1-git-send-email-elza.mathew@intel.com> Subject: [dpdk-dev] [PATCH 2/2] lib: optimize _xstats_by_ids 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: Wed, 06 Dec 2017 00:25:19 -0000 Introduced a check to detect if the stats IDs being requested are all basic stats IDs. In that case, ensured that only the basic stats would be retrieved. Previously, both basic stats and xstats were being retrieved even if all the IDs were basic stats IDs. Signed-off-by: Elza Mathew --- lib/librte_ether/rte_ethdev.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index dfe8e65..210600d 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -1688,7 +1688,9 @@ struct rte_eth_dev * { struct rte_eth_xstat_name *xstats_names_copy; unsigned int no_basic_stat_requested = 1; + unsigned int no_ext_stat_requested = 1; unsigned int expected_entries; + unsigned int basic_count; struct rte_eth_dev *dev; unsigned int i; int ret; @@ -1696,6 +1698,7 @@ struct rte_eth_dev * RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); dev = &rte_eth_devices[port_id]; + basic_count = get_xstats_basic_count(dev); ret = get_xstats_count(port_id); if (ret < 0) return ret; @@ -1713,7 +1716,6 @@ struct rte_eth_dev * return -EINVAL; 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++) { @@ -1752,8 +1754,22 @@ struct rte_eth_dev * return -ENOMEM; } + if (ids) { + for (i = 0; i < size; i++) { + if (ids[i] > basic_count) { + no_ext_stat_requested = 0; + break; + } + } + } + /* Fill xstats_names_copy structure */ - rte_eth_xstats_get_names(port_id, xstats_names_copy, expected_entries); + if (ids && no_ext_stat_requested) { + rte_eth_basic_stats_get_names(dev, xstats_names_copy); + } else { + rte_eth_xstats_get_names(port_id, xstats_names_copy, + expected_entries); + } /* Filter stats */ for (i = 0; i < size; i++) { @@ -1860,7 +1876,9 @@ struct rte_eth_dev * uint64_t *values, unsigned int size) { unsigned int no_basic_stat_requested = 1; + unsigned int no_ext_stat_requested = 1; unsigned int num_xstats_filled; + unsigned int basic_count; uint16_t expected_entries; struct rte_eth_dev *dev; unsigned int i; @@ -1870,6 +1888,7 @@ struct rte_eth_dev * expected_entries = get_xstats_count(port_id); struct rte_eth_xstat xstats[expected_entries]; dev = &rte_eth_devices[port_id]; + basic_count = get_xstats_basic_count(dev); /* Return max number of stats if no ids given */ if (!ids) { @@ -1904,8 +1923,21 @@ struct rte_eth_dev * values, size); } + if (ids) { + for (i = 0; i < size; i++) { + if (ids[i] > basic_count) { + no_ext_stat_requested = 0; + break; + } + } + } + /* Fill the xstats structure */ - ret = rte_eth_xstats_get(port_id, xstats, expected_entries); + if (ids && no_ext_stat_requested) + ret = rte_eth_basic_stats_get(port_id, xstats); + else + ret = rte_eth_xstats_get(port_id, xstats, expected_entries); + if (ret < 0) return ret; num_xstats_filled = (unsigned int)ret; -- 1.9.1