From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5099A43067; Tue, 15 Aug 2023 03:39:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F0E8F43279; Tue, 15 Aug 2023 03:38:46 +0200 (CEST) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by mails.dpdk.org (Postfix) with ESMTP id CDD9843251 for ; Tue, 15 Aug 2023 03:38:39 +0200 (CEST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D86C6133D for ; Tue, 15 Aug 2023 01:38:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80D94C433CA; Tue, 15 Aug 2023 01:38:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692063518; bh=UbZct1QFrYwLo+HTrCgJoL0nQvWSvUSISHA9M4IuOLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j+3/9OWuMfd8PDXZFPGhCgzT1DM2iJobiYhOXKm+uwmg50Ym4QpPp/wq4Eml4QHbk AI3vsOAsLjM9ZDp9PLGgDQ5hxaPF4qSUH4CgyVxspjin24BvITcb6r6XQPk0/bozky WNd81qR1WM6L6umnW7BpHo9i6zfVWdZkKHOhYUDfPmCcIfBuauOqKe/Ayyrl8xpMIg ki/751OHX3qfavPs5gp1ug7luZRkSqPFsLJWs+Twa7CVOGzdYv/CZ/xqSnSuJMShCh QYCpZivx3qtSuK5HNdg44vXgobQWnw29qOs7+ZDNaxM+e7ZrS6GaU0d9wx/HkzxJ12 f5+FiIkfZSo0w== From: okaya@kernel.org To: Cc: dev@dpdk.org, Sinan Kaya Subject: [PATCH v1 7/7] eal: initialize worker threads once Date: Mon, 14 Aug 2023 21:38:26 -0400 Message-Id: <20230815013826.1288972-8-okaya@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230815013826.1288972-1-okaya@kernel.org> References: <20230815013826.1288972-1-okaya@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Sinan Kaya Signed-off-by: Sinan Kaya --- lib/eal/linux/eal.c | 68 ++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c index 5fd81d71cb..63190a4e70 100644 --- a/lib/eal/linux/eal.c +++ b/lib/eal/linux/eal.c @@ -1236,46 +1236,50 @@ rte_eal_init(int argc, char **argv) config->main_lcore, (uintptr_t)pthread_self(), cpuset, ret == 0 ? "" : "..."); - RTE_LCORE_FOREACH_WORKER(i) { + static int worker_initialized = 0; + if (worker_initialized == 0) { + RTE_LCORE_FOREACH_WORKER(i) { /* * create communication pipes between main thread * and children */ - if (pipe(lcore_config[i].pipe_main2worker) < 0) - rte_panic("Cannot create pipe\n"); - if (pipe(lcore_config[i].pipe_worker2main) < 0) - rte_panic("Cannot create pipe\n"); - - lcore_config[i].state = WAIT; - - /* create a thread for each lcore */ - ret = eal_worker_thread_create(i); - if (ret != 0) - rte_panic("Cannot create thread\n"); - - /* Set thread_name for aid in debugging. */ - snprintf(thread_name, sizeof(thread_name), - "rte-worker-%d", i); - ret = rte_thread_setname(lcore_config[i].thread_id, - thread_name); - if (ret != 0) - RTE_LOG(DEBUG, EAL, - "Cannot set name for lcore thread\n"); + if (pipe(lcore_config[i].pipe_main2worker) < 0) + rte_panic("Cannot create pipe\n"); + if (pipe(lcore_config[i].pipe_worker2main) < 0) + rte_panic("Cannot create pipe\n"); + + lcore_config[i].state = WAIT; + + /* create a thread for each lcore */ + ret = eal_worker_thread_create(i); + if (ret != 0) + rte_panic("Cannot create thread\n"); + + /* Set thread_name for aid in debugging. */ + snprintf(thread_name, sizeof(thread_name), + "rte-worker-%d", i); + ret = rte_thread_setname(lcore_config[i].thread_id, + thread_name); + if (ret != 0) + RTE_LOG(DEBUG, EAL, + "Cannot set name for lcore thread\n"); + + ret = pthread_setaffinity_np(lcore_config[i].thread_id, + sizeof(rte_cpuset_t), &lcore_config[i].cpuset); + if (ret != 0) + rte_panic("Cannot set affinity\n"); + } - ret = pthread_setaffinity_np(lcore_config[i].thread_id, - sizeof(rte_cpuset_t), &lcore_config[i].cpuset); - if (ret != 0) - rte_panic("Cannot set affinity\n"); + /* + * Launch a dummy function on all worker lcores, so that main lcore + * knows they are all ready when this function returns. + */ + rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MAIN); + rte_eal_mp_wait_lcore(); + worker_initialized = 1; } - /* - * Launch a dummy function on all worker lcores, so that main lcore - * knows they are all ready when this function returns. - */ - rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MAIN); - rte_eal_mp_wait_lcore(); - /* initialize services so vdevs register service during bus_probe. */ ret = rte_service_init(); if (ret) { -- 2.25.1