From patchwork Wed Dec 7 20:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 120543 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E85C5A00C3; Wed, 7 Dec 2022 21:31:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BD85B42D2C; Wed, 7 Dec 2022 21:31:34 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 8DAD440156 for ; Wed, 7 Dec 2022 21:31:31 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id C824A20B83E2; Wed, 7 Dec 2022 12:31:30 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C824A20B83E2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1670445090; bh=oq4ARCkuv488Wl+cZAx50LYb0kZ+a/yBl1U8eaYCIP4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=enFhNA53OibW855w5Oxs8ldvKGwr4RkK8PLUTroyO/qSO2KBLdCY/i8nqAm4K0re2 p6SyUe/SUIWNDdHiMqQSu0c+00d3t/VBAgqkzZuejEPmNn6ZuIY/UTHA0/TwhHcfOZ gJ0wNARtBIlGqmVGrGvC1XrQ9iDwkJpgY/Gg7Nc4= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, david.marchand@redhat.com, stephen@networkplumber.org, olivier.matz@6wind.com, Tyler Retzlaff Subject: [PATCH v3 1/3] eal: add rte control thread create API Date: Wed, 7 Dec 2022 12:31:27 -0800 Message-Id: <1670445089-23898-2-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1670445089-23898-1-git-send-email-roretzla@linux.microsoft.com> References: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com> <1670445089-23898-1-git-send-email-roretzla@linux.microsoft.com> 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 Add rte_control_thread_create API as a replacement for rte_ctrl_thread_create to allow deprecation of the use of platform specific types in DPDK public API. Signed-off-by: Tyler Retzlaff --- lib/eal/common/eal_common_thread.c | 93 ++++++++++++++++++++++++++++++++++---- lib/eal/include/rte_thread.h | 30 ++++++++++++ lib/eal/version.map | 3 ++ 3 files changed, 118 insertions(+), 8 deletions(-) diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index c5d8b43..7c2552d 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -234,7 +234,10 @@ enum __rte_ctrl_thread_status { }; struct rte_thread_ctrl_params { - void *(*start_routine)(void *); + union { + void *(*ctrl_start_routine)(void *); + rte_thread_func control_start_routine; + } u; void *arg; int ret; /* Control thread status. @@ -243,14 +246,12 @@ struct rte_thread_ctrl_params { enum __rte_ctrl_thread_status ctrl_thread_status; }; -static void *ctrl_thread_init(void *arg) +static int ctrl_thread_init(void *arg) { struct internal_config *internal_conf = eal_get_internal_configuration(); rte_cpuset_t *cpuset = &internal_conf->ctrl_cpuset; struct rte_thread_ctrl_params *params = arg; - void *(*start_routine)(void *) = params->start_routine; - void *routine_arg = params->arg; __rte_thread_init(rte_lcore_id(), cpuset); params->ret = pthread_setaffinity_np(pthread_self(), sizeof(*cpuset), @@ -258,13 +259,35 @@ static void *ctrl_thread_init(void *arg) if (params->ret != 0) { __atomic_store_n(¶ms->ctrl_thread_status, CTRL_THREAD_ERROR, __ATOMIC_RELEASE); - return NULL; + return params->ret; } __atomic_store_n(¶ms->ctrl_thread_status, CTRL_THREAD_RUNNING, __ATOMIC_RELEASE); - return start_routine(routine_arg); + return 0; +} + +static void *ctrl_thread_start(void *arg) +{ + struct rte_thread_ctrl_params *params = arg; + void *(*start_routine)(void *) = params->u.ctrl_start_routine; + + if (ctrl_thread_init(arg) != 0) + return NULL; + + return start_routine(params->arg); +} + +static uint32_t control_thread_start(void *arg) +{ + struct rte_thread_ctrl_params *params = arg; + rte_thread_func start_routine = params->u.control_start_routine; + + if (ctrl_thread_init(arg) != 0) + return params->ret; + + return start_routine(params->arg); } int @@ -280,12 +303,12 @@ static void *ctrl_thread_init(void *arg) if (!params) return -ENOMEM; - params->start_routine = start_routine; + params->u.ctrl_start_routine = start_routine; params->arg = arg; params->ret = 0; params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; - ret = pthread_create(thread, attr, ctrl_thread_init, (void *)params); + ret = pthread_create(thread, attr, ctrl_thread_start, (void *)params); if (ret != 0) { free(params); return -ret; @@ -322,6 +345,60 @@ static void *ctrl_thread_init(void *arg) } int +rte_control_thread_create(rte_thread_t *thread, const char *name, + const rte_thread_attr_t *attr, + rte_thread_func start_routine, void *arg) +{ + struct rte_thread_ctrl_params *params; + enum __rte_ctrl_thread_status ctrl_thread_status; + int ret; + + params = malloc(sizeof(*params)); + if (params == NULL) + return -ENOMEM; + + params->u.control_start_routine = start_routine; + params->arg = arg; + params->ret = 0; + params->ctrl_thread_status = CTRL_THREAD_LAUNCHING; + + ret = rte_thread_create(thread, attr, control_thread_start, params); + if (ret != 0) { + free(params); + return -ret; + } + + if (name != NULL) { + ret = rte_thread_setname((pthread_t)thread->opaque_id, name); + if (ret < 0) + RTE_LOG(DEBUG, EAL, + "Cannot set name for ctrl thread\n"); + } + + /* Wait for the control thread to initialize successfully */ + while ((ctrl_thread_status = + __atomic_load_n(¶ms->ctrl_thread_status, + __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) { + /* Yield the CPU. Using sched_yield call requires maintaining + * another implementation for Windows as sched_yield is not + * supported on Windows. + */ + rte_delay_us_sleep(1); + } + + /* Check if the control thread encountered an error */ + if (ctrl_thread_status == CTRL_THREAD_ERROR) { + /* ctrl thread is exiting */ + rte_thread_join(*thread, NULL); + } + + ret = params->ret; + free(params); + + return ret; +} + +int rte_thread_register(void) { unsigned int lcore_id; diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index b9edf70..97c27a9 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -95,6 +95,36 @@ int rte_thread_create(rte_thread_t *thread_id, rte_thread_func thread_func, void *arg); /** + * Create a control thread. + * + * Creates a control thread with the given name and attributes. The + * affinity of the new thread is based on the CPU affinity retrieved + * at the time rte_eal_init() was called, the EAL threads are then + * excluded. If setting the name of the thread fails, the error is + * ignored and a debug message is logged. + * + * @param thread + * Filled with the thread id of the new created thread. + * @param name + * The name of the control thread + * (max RTE_MAX_THREAD_NAME_LEN characters including '\0'). + * @param thread_attr + * Attributes for the new thread. + * @param thread_func + * Function to be executed by the new thread. + * @param arg + * Argument passed to start_routine. + * @return + * On success, returns 0; on error, it returns a negative value + * corresponding to the error number. + */ +__rte_experimental +int +rte_control_thread_create(rte_thread_t *thread, const char *name, + const rte_thread_attr_t *thread_attr, + rte_thread_func thread_func, void *arg); + +/** * @warning * @b EXPERIMENTAL: this API may change without prior notice. * diff --git a/lib/eal/version.map b/lib/eal/version.map index 7ad12a7..8f9eeb9 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -440,6 +440,9 @@ EXPERIMENTAL { rte_thread_detach; rte_thread_equal; rte_thread_join; + + # added in 23.03 + rte_control_thread_create; }; INTERNAL { From patchwork Wed Dec 7 20:31:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 120544 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5DB38A00C3; Wed, 7 Dec 2022 21:31:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AF2FC42D35; Wed, 7 Dec 2022 21:31:35 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id D625241611 for ; Wed, 7 Dec 2022 21:31:31 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id D49CA20B83E5; Wed, 7 Dec 2022 12:31:30 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D49CA20B83E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1670445090; bh=SQYNN+yT8b7GVewPS95EotHSnyqDvRDS5QWrUxCkDXE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y/IDqeCmh8Myb0yUiO+PSN7O//QOTA65BWRzai9Tt8ApbRqFNOsVbtUAI4ltlWZJy llksK3ItgfkeQnUv/a0DLEi1g3XIkpHu0tytMY9nWgZQH3zl3hbYy6xmXk24eplXOk Bp9uZOWHyuQHARV//vEMNHo+TxyEY0hUDCpz8Ivw= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, david.marchand@redhat.com, stephen@networkplumber.org, olivier.matz@6wind.com, Tyler Retzlaff Subject: [PATCH v3 2/3] test: add rte control thread create API test Date: Wed, 7 Dec 2022 12:31:28 -0800 Message-Id: <1670445089-23898-3-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1670445089-23898-1-git-send-email-roretzla@linux.microsoft.com> References: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com> <1670445089-23898-1-git-send-email-roretzla@linux.microsoft.com> 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 Duplicate the rte_ctrl_thread_create test adapted to use rte_control_thread create to keep both apis under test until rte_ctrl_thread_create is removed. Signed-off-by: Tyler Retzlaff --- app/test/test_lcores.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c index a6bb412..375ecdb 100644 --- a/app/test/test_lcores.c +++ b/app/test/test_lcores.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "test.h" @@ -352,6 +353,18 @@ static void *ctrl_thread_loop(void *arg) return NULL; } +static uint32_t control_thread_loop(void *arg) +{ + struct thread_context *t = arg; + + printf("Control thread running successfully\n"); + + /* Set the thread state to DONE */ + t->state = Thread_DONE; + + return 0; +} + static int test_ctrl_thread(void) { @@ -379,6 +392,32 @@ static void *ctrl_thread_loop(void *arg) } static int +test_control_thread(void) +{ + struct thread_context ctrl_thread_context; + struct thread_context *t; + + /* Create one control thread */ + t = &ctrl_thread_context; + t->state = Thread_INIT; + if (rte_control_thread_create((rte_thread_t *)&t->id, "test_control_threads", + NULL, control_thread_loop, t) != 0) + return -1; + + /* Wait till the control thread exits. + * This also acts as the barrier such that the memory operations + * in control thread are visible to this thread. + */ + rte_thread_join((rte_thread_t){(uintptr_t)t->id}, NULL); + + /* Check if the control thread set the correct state */ + if (t->state != Thread_DONE) + return -1; + + return 0; +} + +static int test_lcores(void) { unsigned int eal_threads_count = 0; @@ -411,6 +450,9 @@ static void *ctrl_thread_loop(void *arg) if (test_ctrl_thread() < 0) return TEST_FAILED; + if (test_control_thread() < 0) + return TEST_FAILED; + return TEST_SUCCESS; } From patchwork Wed Dec 7 20:31:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 120542 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8D569A00C3; Wed, 7 Dec 2022 21:31:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E43AC42D1D; Wed, 7 Dec 2022 21:31:33 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 977DD410FB for ; Wed, 7 Dec 2022 21:31:31 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id E0EDD20B83E7; Wed, 7 Dec 2022 12:31:30 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E0EDD20B83E7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1670445090; bh=azUCI+9yF9g2J/BoVgZzr+1vg2zUWBmkXYoFjmzM0vI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T2/ZTsayG8MbUjdXtvsrSC1/DM4SMTsrTxjYEaaqR7D0jIfIT4eFgFkW29hgcCZJZ wHwhbllORBU3fnyH3DLQ5XyHWRjiJDoDg8X3NDv3aTBt9RUpOZsW1sW0Ags8kAfdiv QcPnI0C1eiC4Hy8Br9keWVKT1EAq3mbc+OefTJ8k= From: Tyler Retzlaff To: dev@dpdk.org Cc: thomas@monjalon.net, david.marchand@redhat.com, stephen@networkplumber.org, olivier.matz@6wind.com, Tyler Retzlaff Subject: [PATCH v3 3/3] eal: deprecate pthread control thread create API Date: Wed, 7 Dec 2022 12:31:29 -0800 Message-Id: <1670445089-23898-4-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1670445089-23898-1-git-send-email-roretzla@linux.microsoft.com> References: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com> <1670445089-23898-1-git-send-email-roretzla@linux.microsoft.com> 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 Give notice of rte_ctrl_thread_create deprecation. Signed-off-by: Tyler Retzlaff --- doc/guides/rel_notes/deprecation.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index b9b02dc..cb74e08 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -119,3 +119,7 @@ Deprecation Notices Its removal has been postponed to let potential users report interest in maintaining it. In the absence of such interest, this library will be removed in DPDK 23.11. + +* eal: The function ``rte_ctrl_thread_create`` will be removed and + replaced by the new ``rte_control_thread_create``api, continuing the + effort to decouple eal from platform-specific thread implementations.