From mboxrd@z Thu Jan 1 00:00:00 1970 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) Received: from [10.16.0.195] (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id CA55E25152; Wed, 29 Jun 2016 17:38:32 +0200 (CEST) To: "dev@dpdk.org" , Remy Horton From: Olivier MATZ Message-ID: <5773EB79.1090509@6wind.com> Date: Wed, 29 Jun 2016 17:38:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: [dpdk-dev] xstats performance 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: , X-List-Received-Date: Wed, 29 Jun 2016 15:38:33 -0000 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