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 65D3DA0A0C; Fri, 18 Jun 2021 23:55:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 237D041120; Fri, 18 Jun 2021 23:55:37 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 36EB0410FE for ; Fri, 18 Jun 2021 23:55:34 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1059) id 8DAF720B6C50; Fri, 18 Jun 2021 14:55:33 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8DAF720B6C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1624053333; bh=+tA1bbEAjzvQnUH4Ug5SJeb99BN/wHNVlSad1AnKjHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WfQpqV9jcq3gQBMtJbgxJOCpM2gLJpX1vA88wlgWhw4EOKHcalc/TnuYnHDliuGIE XG73RqVVJaeKENOW7nytSdL/aeNm+F81jKeYhp6acBm6WIBBkQ833W75ZjkjbGc7BI djQGHMuepydrZUOTJEXk50rSl8DNrCd1wFlCBUCw= 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 14:54:50 -0700 Message-Id: <1624053294-31255-3-git-send-email-navasile@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1624053294-31255-1-git-send-email-navasile@linux.microsoft.com> References: <1624053294-31255-1-git-send-email-navasile@linux.microsoft.com> Subject: [dpdk-dev] [PATCH 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 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 { -- 2.31.0.vfs.0.1