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 5/6] eal: set affinity and priority attributes
Date: Wed, 18 Aug 2021 14:19:38 -0700 [thread overview]
Message-ID: <1629321579-10788-6-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>
If the user doesn't specify the priority through the command
line arguments, initialize the thread priority to 'normal'.
Set thread priority for eal threads.
Signed-off-by: Narcisa Vasile <navasile@microsoft.com>
---
lib/eal/common/eal_common_thread.c | 11 ++++++++
lib/eal/common/eal_thread.h | 6 ++++
lib/eal/freebsd/eal.c | 41 +++++++++++++++++++++++-----
lib/eal/linux/eal.c | 39 +++++++++++++++++++++-----
lib/eal/windows/eal.c | 44 ++++++++++++++++++++++++++++--
5 files changed, 125 insertions(+), 16 deletions(-)
diff --git a/lib/eal/common/eal_common_thread.c b/lib/eal/common/eal_common_thread.c
index 62d28e7b28..fa537db7ac 100644
--- a/lib/eal/common/eal_common_thread.c
+++ b/lib/eal/common/eal_common_thread.c
@@ -388,3 +388,14 @@ rte_thread_unregister(void)
RTE_LOG(DEBUG, EAL, "Unregistered non-EAL thread (was lcore %u).\n",
lcore_id);
}
+
+void rte_thread_priority_init(void)
+{
+ struct internal_config *internal_conf =
+ eal_get_internal_configuration();
+
+ /* If the user doesn't specify the priority through the command
+ * line arguments, the default 'normal' value will be used.
+ */
+ internal_conf->thread_priority = RTE_THREAD_PRIORITY_NORMAL;
+}
diff --git a/lib/eal/common/eal_thread.h b/lib/eal/common/eal_thread.h
index 4a49117be8..7b3b884463 100644
--- a/lib/eal/common/eal_thread.h
+++ b/lib/eal/common/eal_thread.h
@@ -58,4 +58,10 @@ eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);
int
eal_thread_dump_current_affinity(char *str, unsigned int size);
+/**
+ * Set the initial thread priority in the internal configuration
+ * to the default value of RTE_THREAD_PRIORITY_NORMAL.
+ */
+void rte_thread_priority_init(void);
+
#endif /* EAL_THREAD_H */
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index c92fdaa598..1570da2a36 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -678,6 +678,8 @@ rte_eal_init(int argc, char **argv)
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ rte_thread_priority_init();
+
/* checks if the machine is adequate */
if (!rte_cpu_is_supported()) {
rte_eal_init_alert("unsupported cpu type.");
@@ -856,6 +858,14 @@ rte_eal_init(int argc, char **argv)
eal_check_mem_on_local_socket();
+ ret = rte_thread_set_priority(rte_thread_self(),
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority");
+ rte_errno = ret;
+ return -1;
+ }
+
if (rte_thread_set_affinity_by_id(rte_thread_self(),
&lcore_config[config->main_lcore].cpuset) != 0) {
rte_eal_init_alert("Cannot set affinity");
@@ -871,6 +881,22 @@ rte_eal_init(int argc, char **argv)
config->main_lcore, (void *)thread_id.opaque_id, cpuset,
ret == 0 ? "" : "...");
+ rte_thread_attr_t thread_attr;
+ ret = rte_thread_attr_init(&thread_attr);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot initialize thread attributes");
+ rte_errno = ret;
+ return -1;
+ }
+
+ ret = rte_thread_attr_set_priority(&thread_attr,
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority attribute");
+ rte_errno = ret;
+ return -1;
+ }
+
RTE_LCORE_FOREACH_WORKER(i) {
/*
@@ -884,9 +910,15 @@ rte_eal_init(int argc, char **argv)
lcore_config[i].state = WAIT;
+ ret = rte_thread_attr_set_affinity(&thread_attr,
+ &lcore_config[i].cpuset);
+
+ if (ret != 0)
+ rte_panic("Cannot set affinity\n");
+
/* create a thread for each lcore */
- ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ ret = rte_thread_create(&lcore_config[i].thread_id,
+ &thread_attr, eal_thread_loop, NULL);
if (ret != 0)
rte_panic("Cannot create thread\n");
@@ -894,11 +926,6 @@ rte_eal_init(int argc, char **argv)
snprintf(thread_name, sizeof(thread_name),
"lcore-worker-%d", i);
rte_thread_name_set(lcore_config[i].thread_id, thread_name);
-
- ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
- &lcore_config[i].cpuset);
- if (ret != 0)
- rte_panic("Cannot set affinity\n");
}
/*
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index cd5e9953d0..c02390ed58 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -977,6 +977,8 @@ rte_eal_init(int argc, char **argv)
struct internal_config *internal_conf =
eal_get_internal_configuration();
+ rte_thread_priority_init();
+
/* checks if the machine is adequate */
if (!rte_cpu_is_supported()) {
rte_eal_init_alert("unsupported cpu type.");
@@ -1221,6 +1223,14 @@ rte_eal_init(int argc, char **argv)
eal_check_mem_on_local_socket();
+ ret = rte_thread_set_priority(rte_thread_self(),
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority");
+ rte_errno = ret;
+ return -1;
+ }
+
if (rte_thread_set_affinity_by_id(rte_thread_self(),
&lcore_config[config->main_lcore].cpuset) != 0) {
rte_eal_init_alert("Cannot set affinity");
@@ -1235,6 +1245,23 @@ rte_eal_init(int argc, char **argv)
config->main_lcore, (void *)thread_id.opaque_id, cpuset,
ret == 0 ? "" : "...");
+ rte_thread_attr_t thread_attr;
+ ret = rte_thread_attr_init(&thread_attr);
+ if (ret != 0) {
+ RTE_LOG(DEBUG, EAL, "Cannot initialize thread attributes,"
+ "ret = %d\n", ret);
+ rte_errno = ret;
+ return -1;
+ }
+ ret = rte_thread_attr_set_priority(&thread_attr,
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ RTE_LOG(DEBUG, EAL, "Cannot set thread priority attribute,"
+ "ret = %d\n", ret);
+ rte_errno = ret;
+ return -1;
+ }
+
RTE_LCORE_FOREACH_WORKER(i) {
/*
@@ -1248,9 +1275,12 @@ rte_eal_init(int argc, char **argv)
lcore_config[i].state = WAIT;
+ rte_thread_attr_set_affinity(&thread_attr,
+ &lcore_config[i].cpuset);
+
/* create a thread for each lcore */
- ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ ret = rte_thread_create(&lcore_config[i].thread_id,
+ &thread_attr, eal_thread_loop, NULL);
if (ret != 0)
rte_panic("Cannot create thread\n");
@@ -1262,11 +1292,6 @@ rte_eal_init(int argc, char **argv)
if (ret != 0)
RTE_LOG(DEBUG, EAL,
"Cannot set name for lcore thread\n");
-
- ret = rte_thread_set_affinity_by_id(lcore_config[i].thread_id,
- &lcore_config[i].cpuset);
- if (ret != 0)
- rte_panic("Cannot set affinity\n");
}
/*
diff --git a/lib/eal/windows/eal.c b/lib/eal/windows/eal.c
index d90c635ddc..4eca6a3ab6 100644
--- a/lib/eal/windows/eal.c
+++ b/lib/eal/windows/eal.c
@@ -278,6 +278,8 @@ rte_eal_init(int argc, char **argv)
eal_get_internal_configuration();
int ret;
+ rte_thread_priority_init();
+
eal_log_init(NULL, 0);
eal_log_level_parse(argc, argv);
@@ -379,6 +381,36 @@ rte_eal_init(int argc, char **argv)
return -1;
}
+ if (rte_thread_set_affinity_by_id(rte_thread_self(),
+ &lcore_config[config->main_lcore].cpuset) != 0) {
+ rte_eal_init_alert("Cannot set affinity");
+ rte_errno = EINVAL;
+ return -1;
+ }
+
+ ret = rte_thread_set_priority(rte_thread_self(),
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority");
+ rte_errno = ret;
+ return -1;
+ }
+
+ rte_thread_attr_t thread_attr;
+ ret = rte_thread_attr_init(&thread_attr);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot initialize thread attributes");
+ rte_errno = ret;
+ return -1;
+ }
+ ret = rte_thread_attr_set_priority(&thread_attr,
+ internal_conf->thread_priority);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread priority attribute");
+ rte_errno = ret;
+ return -1;
+ }
+
RTE_LCORE_FOREACH_WORKER(i) {
/*
@@ -394,9 +426,17 @@ rte_eal_init(int argc, char **argv)
lcore_config[i].state = WAIT;
+ ret = rte_thread_attr_set_affinity(&thread_attr,
+ &lcore_config[i].cpuset);
+ if (ret != 0) {
+ rte_eal_init_alert("Cannot set thread affinity attribute");
+ rte_errno = ret;
+ return -1;
+ }
+
/* create a thread for each lcore */
- ret = rte_thread_create(&lcore_config[i].thread_id, NULL,
- eal_thread_loop, NULL);
+ ret = rte_thread_create(&lcore_config[i].thread_id,
+ &thread_attr, eal_thread_loop, NULL);
if (ret != 0)
rte_panic("Cannot create thread\n");
}
--
2.31.0.vfs.0.1
next prev parent reply other threads:[~2021-08-18 21:20 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 ` [dpdk-dev] [PATCH v4 2/6] eal: add function for control thread creation Narcisa Ana Maria Vasile
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 ` Narcisa Ana Maria Vasile [this message]
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-6-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).