From patchwork Mon Aug 21 12:58:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 27692 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 4DA7D7D8E; Mon, 21 Aug 2017 14:58:42 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 5C4D27D23 for ; Mon, 21 Aug 2017 14:58:36 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP; 21 Aug 2017 05:58:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,409,1498546800"; d="scan'208"; a="1208383323" Received: from silpixa00398672.ir.intel.com ([10.237.223.128]) by fmsmga002.fm.intel.com with ESMTP; 21 Aug 2017 05:58:34 -0700 From: Harry van Haaren To: dev@dpdk.org Cc: Harry van Haaren Date: Mon, 21 Aug 2017 13:58:10 +0100 Message-Id: <1503320296-51122-10-git-send-email-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503320296-51122-1-git-send-email-harry.van.haaren@intel.com> References: <1502800360-15782-1-git-send-email-harry.van.haaren@intel.com> <1503320296-51122-1-git-send-email-harry.van.haaren@intel.com> Subject: [dpdk-dev] [PATCH v2 09/15] service: fix loops to always scan all services 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" Services can be registered and unregistered, and "holes" can appear in the contiguous array of services if a service is unregistered. As a result, we must never iterate to the number of services (as counted by rte_service_count), instead scanning the service array and checking if the service is valid. After this commit, the rte_service_count variable is only used for its intended purpose; tracking the number of services that are present. Fixes: 21698354c832 ("service: introduce service cores concept") Signed-off-by: Harry van Haaren --- lib/librte_eal/common/rte_service.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/rte_service.c b/lib/librte_eal/common/rte_service.c index 6291c0c..a5fbcf9 100644 --- a/lib/librte_eal/common/rte_service.c +++ b/lib/librte_eal/common/rte_service.c @@ -323,7 +323,10 @@ rte_service_runner_func(void *arg) while (lcore_states[lcore].runstate == RUNSTATE_RUNNING) { const uint64_t service_mask = cs->service_mask; - for (i = 0; i < rte_service_count; i++) { + + for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { + if (!service_valid(i)) + continue; struct rte_service_spec_impl *s = &rte_services[i]; if (s->runstate != RUNSTATE_RUNNING || !(service_mask & (UINT64_C(1) << i))) @@ -655,7 +658,8 @@ int32_t rte_service_dump(FILE *f, uint32_t id) int print_one = (id != UINT32_MAX); uint64_t total_cycles = 0; - for (i = 0; i < rte_service_count; i++) { + + for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { if (!service_valid(i)) continue; total_cycles += rte_services[i].cycles_spent; @@ -673,7 +677,9 @@ int32_t rte_service_dump(FILE *f, uint32_t id) /* print all services, as UINT32_MAX was passed as id */ fprintf(f, "Services Summary\n"); - for (i = 0; i < rte_service_count; i++) { + for (i = 0; i < RTE_SERVICE_NUM_MAX; i++) { + if (!service_valid(i)) + continue; uint32_t reset = 1; rte_service_dump_one(f, &rte_services[i], total_cycles, reset); }