From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olivier MATZ Subject: xstats performance Date: Wed, 29 Jun 2016 17:38:33 +0200 Message-ID: <5773EB79.1090509@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit To: "dev@dpdk.org" , Remy Horton Return-path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id 0392B1396 for ; Wed, 29 Jun 2016 17:38:33 +0200 (CEST) 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" Hi Remy, While adapting an application to the new xstats API, I discovered that it may not be so efficient to display the statistics and their names. I think the test-pmd code illustrates the issue pretty well: /* Display xstats */ for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) for (idx_name = 0; idx_name < cnt_xstats; idx_name++) if (xstats_names[idx_name].id == xstats[idx_xstat].id) { printf("%s: %"PRIu64"\n", xstats_names[idx_name].name, xstats[idx_xstat].value); break; } The displaying is in O(n^2). It's possible to enhance the code to have it in O(n), but it requires an intermediate table. Why not changing this: struct rte_eth_xstat { uint64_t id; uint64_t value; }; struct rte_eth_xstat_name { char name[RTE_ETH_XSTATS_NAME_SIZE]; uint64_t id; }; Into this: struct rte_eth_xstat { uint64_t id; uint64_t value; }; struct rte_eth_xstat_name { char name[RTE_ETH_XSTATS_NAME_SIZE]; /* No identifier */ }; And assume that the id field in rte_eth_xstat corresponds to the index in the rte_eth_xstat_name table? The test-pmd code would be something like this: /* Display xstats */ for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { printf("%s: %"PRIu64"\n", xstats_names[xstats[idx_xstats].id].name, xstats[idx_xstat].value); } What do you think? Regards Olivier