From patchwork Tue Jan 31 19:46:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 122764 X-Patchwork-Delegate: david.marchand@redhat.com 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 82E4E41B92; Tue, 31 Jan 2023 20:47:15 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B5C1F42D0C; Tue, 31 Jan 2023 20:46:58 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 3DC0E410E6 for ; Tue, 31 Jan 2023 20:46:55 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 6DDA420DDD0A; Tue, 31 Jan 2023 11:46:54 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6DDA420DDD0A From: Tyler Retzlaff To: dev@dpdk.org Cc: david.marchand@redhat.com, thomas@monjalon.net, olivier.matz@6wind.com, stephen@networkplumber.org, mb@smartsharesystems.com, hofors@lysator.liu.se, Tyler Retzlaff Subject: [PATCH v5 1/3] eal: add rte control thread create API Date: Tue, 31 Jan 2023 11:46:46 -0800 Message-Id: <1675194408-5199-2-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675194408-5199-1-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com> <1675194408-5199-1-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> MIME-Version: 1.0 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: Tyler Retzlaff 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. 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 Acked-by: Morten Brørup Reviewed-by: Mattias Rönnblom --- app/test/test_lcores.c | 41 ++++++++++++++++++ lib/eal/common/eal_common_thread.c | 85 ++++++++++++++++++++++++++++++++++---- lib/eal/include/rte_thread.h | 33 +++++++++++++++ lib/eal/version.map | 1 + 4 files changed, 152 insertions(+), 8 deletions(-) diff --git a/app/test/test_lcores.c b/app/test/test_lcores.c index 5b43aa5..9766f78 100644 --- a/app/test/test_lcores.c +++ b/app/test/test_lcores.c @@ -353,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) { @@ -380,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(&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(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; @@ -409,6 +447,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; } diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 3181515..7ea216e 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -232,7 +232,10 @@ enum __rte_ctrl_thread_status { }; struct rte_thread_ctrl_params { - void *(*start_routine)(void *); + union { + void *(*ctrl_start_routine)(void *arg); + rte_thread_func control_start_routine; + } u; void *arg; int ret; /* Control thread status. @@ -241,27 +244,47 @@ 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 = rte_thread_set_affinity_by_id(rte_thread_self(), cpuset); 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 @@ -277,12 +300,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; @@ -315,6 +338,52 @@ 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) + rte_thread_set_name(*thread, name); + + /* Wait for the control thread to initialize successfully */ + while ((ctrl_thread_status = + __atomic_load_n(¶ms->ctrl_thread_status, + __ATOMIC_ACQUIRE)) == CTRL_THREAD_LAUNCHING) { + 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 d247930..792d8b0 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -98,6 +98,39 @@ int rte_thread_create(rte_thread_t *thread_id, * @warning * @b EXPERIMENTAL: this API may change without prior notice. * + * 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. + * * Waits for the thread identified by 'thread_id' to terminate * * @param thread_id diff --git a/lib/eal/version.map b/lib/eal/version.map index 6523102..a9d0a03 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -441,6 +441,7 @@ EXPERIMENTAL { rte_thread_join; # added in 23.03 + rte_control_thread_create; rte_thread_set_name; }; From patchwork Tue Jan 31 19:46:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 122763 X-Patchwork-Delegate: david.marchand@redhat.com 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 171FE41B92; Tue, 31 Jan 2023 20:47:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9FC1E4282D; Tue, 31 Jan 2023 20:46:57 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 3522B40684 for ; Tue, 31 Jan 2023 20:46:55 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 7A43320DE342; Tue, 31 Jan 2023 11:46:54 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7A43320DE342 From: Tyler Retzlaff To: dev@dpdk.org Cc: david.marchand@redhat.com, thomas@monjalon.net, olivier.matz@6wind.com, stephen@networkplumber.org, mb@smartsharesystems.com, hofors@lysator.liu.se, Tyler Retzlaff Subject: [PATCH v5 2/3] doc: add missing index entry for thread Date: Tue, 31 Jan 2023 11:46:47 -0800 Message-Id: <1675194408-5199-3-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675194408-5199-1-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com> <1675194408-5199-1-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> 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: Tyler Retzlaff Add missing thread index referencing rte_thread.h under the basic topic. Signed-off-by: Tyler Retzlaff --- doc/api/doxy-api-index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/api/doxy-api-index.md b/doc/api/doxy-api-index.md index de488c7..e8ed51a 100644 --- a/doc/api/doxy-api-index.md +++ b/doc/api/doxy-api-index.md @@ -211,6 +211,7 @@ The public API headers are grouped by topics: [config file](@ref rte_cfgfile.h), [key/value args](@ref rte_kvargs.h), [string](@ref rte_string_fns.h) + [thread](@ref rte_thread.h) - **debug**: [jobstats](@ref rte_jobstats.h), From patchwork Tue Jan 31 19:46:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tyler Retzlaff X-Patchwork-Id: 122761 X-Patchwork-Delegate: david.marchand@redhat.com 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 DEACE41B92; Tue, 31 Jan 2023 20:46:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BB0E840684; Tue, 31 Jan 2023 20:46:55 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 3961140EF0 for ; Tue, 31 Jan 2023 20:46:55 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id 862AF20DE346; Tue, 31 Jan 2023 11:46:54 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 862AF20DE346 From: Tyler Retzlaff To: dev@dpdk.org Cc: david.marchand@redhat.com, thomas@monjalon.net, olivier.matz@6wind.com, stephen@networkplumber.org, mb@smartsharesystems.com, hofors@lysator.liu.se, Tyler Retzlaff Subject: [PATCH v5 3/3] doc: announce deprecation of thread ctrl create function Date: Tue, 31 Jan 2023 11:46:48 -0800 Message-Id: <1675194408-5199-4-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1675194408-5199-1-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1670271868-11364-1-git-send-email-roretzla@linux.microsoft.com> <1675194408-5199-1-git-send-email-roretzla@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> MIME-Version: 1.0 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: Tyler Retzlaff Notify deprecation of rte_ctrl_thread_create API, it will be removed as it exposes platform-specific thread details. Signed-off-by: Tyler Retzlaff Acked-by: Morten Brørup Reviewed-by: Mattias Rönnblom --- doc/guides/rel_notes/deprecation.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index eea99b4..c6e7d04 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -23,6 +23,11 @@ Deprecation Notices rte_thread_set_name being marked as stable, and planned to be removed by the 23.11 release. +* eal: The function ``rte_ctrl_thread_create`` is planned to be deprecated + starting with the 23.07 release, subject to the replacement API + rte_control_thread_create being marked as stable, and planned to be removed + by the 23.11 release. + * rte_atomicNN_xxx: These APIs do not take memory order parameter. This does not allow for writing optimized code for all the CPU architectures supported in DPDK. DPDK has adopted the atomic operations from