From: Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>
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
Subject: [dpdk-dev] [PATCH v4 2/6] eal: add function for control thread creation
Date: Wed, 18 Aug 2021 14:19:35 -0700 [thread overview]
Message-ID: <1629321579-10788-3-git-send-email-navasile@linux.microsoft.com> (raw)
In-Reply-To: <1629321579-10788-1-git-send-email-navasile@linux.microsoft.com>
From: Narcisa Vasile <navasile@microsoft.com>
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 <navasile@microsoft.com>
---
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 {
--
2.31.0.vfs.0.1
next prev parent reply other threads:[~2021-08-18 21:19 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-18 21:54 [dpdk-dev] [PATCH 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-06-18 21:54 ` [dpdk-dev] [PATCH 6/6] Allow choice between internal EAL thread API and external lib Narcisa Ana Maria Vasile
2021-06-19 1:57 ` [dpdk-dev] [PATCH v2 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-06-19 1:57 ` [dpdk-dev] [PATCH v2 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-06-20 23:53 ` Dmitry Kozlyuk
2021-06-19 1:57 ` [dpdk-dev] [PATCH v2 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
2021-06-19 1:57 ` [dpdk-dev] [PATCH v2 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-06-19 1:57 ` [dpdk-dev] [PATCH v2 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-06-19 1:57 ` [dpdk-dev] [PATCH v2 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-06-19 1:57 ` [dpdk-dev] [PATCH v2 6/6] Allow choice between internal EAL thread API and external lib Narcisa Ana Maria Vasile
2021-08-18 13:44 ` [dpdk-dev] [PATCH v3 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-08-18 13:44 ` [dpdk-dev] [PATCH v3 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-08-18 19:42 ` Tal Shnaiderman
2021-08-18 13:44 ` [dpdk-dev] [PATCH v3 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
2021-08-18 13:44 ` [dpdk-dev] [PATCH v3 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-08-18 13:44 ` [dpdk-dev] [PATCH v3 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-08-18 13:44 ` [dpdk-dev] [PATCH v3 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-08-18 13:44 ` [dpdk-dev] [PATCH v3 6/6] Allow choice between internal EAL thread API and external lib Narcisa Ana Maria Vasile
2021-08-18 21:19 ` [dpdk-dev] [PATCH v4 0/6] Enable the internal EAL thread API Narcisa Ana Maria Vasile
2021-08-18 21:19 ` [dpdk-dev] [PATCH v4 1/6] eal: add function that sets thread name Narcisa Ana Maria Vasile
2021-08-18 21:19 ` Narcisa Ana Maria Vasile [this message]
2021-08-18 21:19 ` [dpdk-dev] [PATCH v4 3/6] Enable the new EAL thread API in app, drivers and examples Narcisa Ana Maria Vasile
2021-08-18 21:19 ` [dpdk-dev] [PATCH v4 4/6] lib: enable the new EAL thread API Narcisa Ana Maria Vasile
2021-08-18 21:19 ` [dpdk-dev] [PATCH v4 5/6] eal: set affinity and priority attributes Narcisa Ana Maria Vasile
2021-08-18 21:19 ` [dpdk-dev] [PATCH v4 6/6] Allow choice between internal EAL thread API and external lib Narcisa Ana Maria Vasile
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1629321579-10788-3-git-send-email-navasile@linux.microsoft.com \
--to=navasile@linux.microsoft.com \
--cc=bruce.richardson@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=dmitry.kozliuk@gmail.com \
--cc=dmitrym@microsoft.com \
--cc=khot@microsoft.com \
--cc=navasile@microsoft.com \
--cc=ocardona@microsoft.com \
--cc=pallavi.kadam@intel.com \
--cc=roretzla@microsoft.com \
--cc=talshn@nvidia.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).