From patchwork Sat Jun 19 01:57:54 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: 94534 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 36EA2A0A0C; Sat, 19 Jun 2021 03:58:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB46940E32; Sat, 19 Jun 2021 03:58:12 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 22B5940696 for ; Sat, 19 Jun 2021 03:58:11 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1059) id 69A8520B6AEE; Fri, 18 Jun 2021 18:58:10 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 69A8520B6AEE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1624067890; bh=JnoqRbwQvWfl6C+84wDuVi6CbkoVqD5S0VlamIV3/mc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QRDPQPl8LvTUn8tkbNg8p0BhBgna+p8awsz1H2Z9sngPrJR7EfclPFLrbXHcjfwts aAmVIBJ90iNU/q9BZhzbnEcCJmQR8DZpAp05VIoTEO9Zss1X71OJqEz7LPMpsrhzo0 ZmSlvW/vQnuk8vvOICGc3329LywVqWb61CSk6+b0= 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: Fri, 18 Jun 2021 18:57:54 -0700 Message-Id: <1624067878-2130-3-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1624067878-2130-1-git-send-email-navasile@linux.microsoft.com> References: <1624053294-31255-1-git-send-email-navasile@linux.microsoft.com> <1624067878-2130-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH v2 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. Depends-on: series-17402 ("eal: Add EAL API for threading") 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 c65cfd8c9e..4da800ae27 100644 --- a/lib/eal/include/rte_thread.h +++ b/lib/eal/include/rte_thread.h @@ -457,6 +457,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 2a566c04af..02455a1c8d 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -444,6 +444,7 @@ EXPERIMENTAL { rte_thread_barrier_wait; rte_thread_barrier_destroy; rte_thread_name_set; + rte_thread_ctrl_thread_create; }; INTERNAL {