From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [dpdk-dev] [PATCH] eal: support using 0 as coremask for no-affinitization
Date: Tue, 16 Feb 2021 09:43:00 +0000 [thread overview]
Message-ID: <20210216094300.27889-1-bruce.richardson@intel.com> (raw)
Allow the user to specify that they don't want any core pinning from DPDK
by passing in the coremask of 0.
---
lib/librte_eal/common/eal_common_options.c | 18 +++++++++++++++---
lib/librte_eal/common/eal_internal_cfg.h | 1 +
lib/librte_eal/freebsd/eal.c | 5 +++--
lib/librte_eal/linux/eal.c | 5 +++--
4 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc429..94029bf7f1 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -1522,9 +1522,21 @@ eal_parse_common_option(int opt, const char *optarg,
if (eal_service_cores_parsed())
RTE_LOG(WARNING, EAL,
"Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
- if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
- RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
- return -1;
+
+ if (strcmp(optarg, "0") == 0 || strcmp(optarg, "0x0") == 0) {
+ /* if -c 0 passed, don't affinitize anything, so set
+ * up a single core 0 as active, but mark it not to have
+ * pthread_setaffinity called on it.
+ */
+ memset(lcore_indexes, -1, sizeof(lcore_indexes));
+ conf->no_main_affinity = 1;
+ lcore_indexes[0] = 0;
+ RTE_CPU_FILL(&lcore_config[0].cpuset);
+ } else {
+ if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
+ RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
+ return -1;
+ }
}
if (update_lcore_config(lcore_indexes) < 0) {
char *available = available_cores();
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2b..db46c49b84 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h
@@ -50,6 +50,7 @@ struct internal_config {
unsigned hugepage_unlink; /**< true to unlink backing files */
volatile unsigned no_pci; /**< true to disable PCI */
volatile unsigned no_hpet; /**< true to disable HPET */
+ volatile unsigned no_main_affinity; /**< disable main lcore CPU pinning */
volatile unsigned vmware_tsc_map; /**< true to use VMware TSC mapping
* instead of native TSC */
volatile unsigned no_shconf; /**< true if there is no shared config */
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 51478358c7..a30a6e54d4 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -850,8 +850,9 @@ rte_eal_init(int argc, char **argv)
eal_check_mem_on_local_socket();
- if (pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
- &lcore_config[config->main_lcore].cpuset) != 0) {
+ if (!internal_conf->no_main_affinity &&
+ pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
+ &lcore_config[config->main_lcore].cpuset) != 0) {
rte_eal_init_alert("Cannot set affinity");
rte_errno = EINVAL;
return -1;
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index 32b48c3de9..e3390766ca 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -1214,8 +1214,9 @@ rte_eal_init(int argc, char **argv)
eal_check_mem_on_local_socket();
- if (pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
- &lcore_config[config->main_lcore].cpuset) != 0) {
+ if (!internal_conf->no_main_affinity &&
+ pthread_setaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
+ &lcore_config[config->main_lcore].cpuset) != 0) {
rte_eal_init_alert("Cannot set affinity");
rte_errno = EINVAL;
return -1;
--
2.27.0
next reply other threads:[~2021-02-16 9:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-16 9:43 Bruce Richardson [this message]
2021-02-16 9:51 ` Bruce Richardson
2021-04-14 16:15 ` David Marchand
2021-04-14 16:29 ` Stephen Hemminger
2021-04-14 17:02 ` Bruce Richardson
2021-04-14 16:55 ` Bruce Richardson
2021-02-16 10:36 ` Burakov, Anatoly
2021-02-16 10:46 ` Bruce Richardson
2021-02-16 10:52 ` Burakov, Anatoly
2021-02-16 17:22 ` Van Haaren, Harry
2021-02-16 17:30 ` Bruce Richardson
2021-02-16 17:44 ` Van Haaren, Harry
2021-02-17 12:09 ` Burakov, Anatoly
2021-02-17 12:14 ` Van Haaren, Harry
2021-02-17 13:26 ` Bruce Richardson
2021-02-17 13:37 ` Burakov, Anatoly
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=20210216094300.27889-1-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
/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).