From patchwork Wed Aug 18 21:19:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Narcisa Ana Maria Vasile X-Patchwork-Id: 97082 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 2C774A0C55; Wed, 18 Aug 2021 23:19:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CB380411F1; Wed, 18 Aug 2021 23:19:48 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 4D8EF4069C for ; Wed, 18 Aug 2021 23:19:45 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1059) id 903A720C335B; Wed, 18 Aug 2021 14:19:44 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 903A720C335B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1629321584; bh=i9+xnTh9K5TOp46rymmv8mM+/xhXF3T13c9UguTFVI8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=glTn+mYoaUrrcue1+LUmBCDOPqmUDk0s0bKZ1obb/PSUYUZDFNWSIx8HHYAvohXkY z4RRtw+cbAgaERLsy6/9aqeb2QyOAjReRzMX8GdditCpQlQZ8Qj1yx0UacZNMGVKLy rmxas0dcn4PRd/zbp5H690Nf9SXxGjX1S+gRvYSQ= From: Narcisa Ana Maria Vasile To: dev@dpdk.org, thomas@monjalon.net, dmitry.kozliuk@gmail.com, khot@microsoft.com, navasile@microsoft.com, dmitrym@microsoft.com, roretzla@microsoft.com, talshn@nvidia.com, ocardona@microsoft.com Cc: bruce.richardson@intel.com, david.marchand@redhat.com, pallavi.kadam@intel.com Date: Wed, 18 Aug 2021 14:19:35 -0700 Message-Id: <1629321579-10788-3-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1629321579-10788-1-git-send-email-navasile@linux.microsoft.com> References: <1629294247-5207-7-git-send-email-navasile@linux.microsoft.com> <1629321579-10788-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v4 2/6] eal: add function for control thread creation 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 Sender: "dev" From: Narcisa Vasile The existing rte_ctrl_thread_create() function will be replaced with rte_thread_ctrl_thread_create() that uses the internal EAL thread API. This patch only introduces the new control thread creation function. Replacing of the old function needs to be done according to the ABI change procedures, to avoid an ABI break. Signed-off-by: Narcisa Vasile --- lib/eal/common/eal_common_thread.c | 81 ++++++++++++++++++++++++++++++ lib/eal/include/rte_thread.h | 27 ++++++++++ lib/eal/version.map | 1 + 3 files changed, 109 insertions(+) diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c index 1a52f42a2b..79545c67d9 100644 --- a/lib/eal/common/eal_common_thread.c +++ b/lib/eal/common/eal_common_thread.c @@ -259,6 +259,87 @@ rte_ctrl_thread_create(pthread_t *thread, const char *name, return -ret; } +struct rte_thread_ctrl_ctx { + rte_thread_func start_routine; + void *arg; + const char *name; +}; + +static void *ctrl_thread_wrapper(void *arg) +{ + struct internal_config *conf = eal_get_internal_configuration(); + rte_cpuset_t *cpuset = &conf->ctrl_cpuset; + struct rte_thread_ctrl_ctx *ctx = arg; + rte_thread_func start_routine = ctx->start_routine; + void *routine_arg = ctx->arg; + + __rte_thread_init(rte_lcore_id(), cpuset); + + if (ctx->name != NULL) { + if (rte_thread_name_set(rte_thread_self(), ctx->name) < 0) + RTE_LOG(DEBUG, EAL, "Cannot set name for ctrl thread\n"); + } + + free(arg); + + return start_routine(routine_arg); +} + +int +rte_thread_ctrl_thread_create(rte_thread_t *thread, const char *name, + rte_thread_func start_routine, void *arg) +{ + int ret; + rte_thread_attr_t attr; + struct internal_config *conf = eal_get_internal_configuration(); + rte_cpuset_t *cpuset = &conf->ctrl_cpuset; + struct rte_thread_ctrl_ctx *ctx = NULL; + + if (start_routine == NULL) { + ret = EINVAL; + goto cleanup; + } + + ctx = malloc(sizeof(*ctx)); + if (ctx == NULL) { + ret = ENOMEM; + goto cleanup; + } + + ctx->start_routine = start_routine; + ctx->arg = arg; + ctx->name = name; + + ret = rte_thread_attr_init(&attr); + if (ret != 0) { + RTE_LOG(DEBUG, EAL, "Cannot init ctrl thread attributes\n"); + goto cleanup; + } + + ret = rte_thread_attr_set_affinity(&attr, cpuset); + if (ret != 0) { + RTE_LOG(DEBUG, EAL, "Cannot set afifnity attribute for ctrl thread\n"); + goto cleanup; + } + ret = rte_thread_attr_set_priority(&attr, RTE_THREAD_PRIORITY_NORMAL); + if (ret != 0) { + RTE_LOG(DEBUG, EAL, "Cannot set priority attribute for ctrl thread\n"); + goto cleanup; + } + + ret = rte_thread_create(thread, &attr, ctrl_thread_wrapper, ctx); + if (ret != 0) { + RTE_LOG(DEBUG, EAL, "Cannot create ctrl thread\n"); + goto cleanup; + } + + return 0; + +cleanup: + free(ctx); + return ret; +} + int rte_thread_register(void) { diff --git a/lib/eal/include/rte_thread.h b/lib/eal/include/rte_thread.h index 2f6258e336..e34101cc98 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -455,6 +455,33 @@ int rte_thread_barrier_destroy(rte_thread_barrier *barrier); __rte_experimental int rte_thread_name_set(rte_thread_t thread_id, const char *name); +/** + * Create a control thread. + * + * Set affinity and thread name. The affinity of the new thread is based + * on the CPU affinity retrieved at the time rte_eal_init() was called, + * the dataplane and service lcores are then excluded. + * + * @param thread + * Filled with the thread id of the new created thread. + * + * @param name + * The name of the control thread (max 16 characters including '\0'). + * + * @param start_routine + * Function to be executed by the new thread. + * + * @param arg + * Argument passed to start_routine. + * + * @return + * On success, return 0; + * On failure, return a positive errno-style error number. + */ +__rte_experimental +int rte_thread_ctrl_thread_create(rte_thread_t *thread, const char *name, + rte_thread_func start_routine, void *arg); + /** * Create a TLS data key visible to all threads in the process. * the created key is later used to get/set a value. diff --git a/lib/eal/version.map b/lib/eal/version.map index 7ce8dcea07..67569b1bf9 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -447,6 +447,7 @@ EXPERIMENTAL { rte_thread_barrier_wait; rte_thread_barrier_destroy; rte_thread_name_set; + rte_thread_ctrl_thread_create; }; INTERNAL {