All of lore.kernel.org
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] eal: support using 0 as coremask for no-affinitization
@ 2021-02-16  9:43 Bruce Richardson
  2021-02-16  9:51 ` Bruce Richardson
  2021-02-16 10:36 ` Burakov, Anatoly
  0 siblings, 2 replies; 16+ messages in thread
From: Bruce Richardson @ 2021-02-16  9:43 UTC (permalink / raw)
  To: dev; +Cc: Bruce Richardson

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


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-04-14 17:03 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-16  9:43 [dpdk-dev] [PATCH] eal: support using 0 as coremask for no-affinitization Bruce Richardson
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.