DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>,
	Pravin Pathak <pravin.pathak@intel.com>,
	Tyler Retzlaff <roretzla@linux.microsoft.com>
Subject: [PATCH v2 3/3] eal: allow automatic mapping of high lcore ids
Date: Mon, 24 Mar 2025 17:30:29 +0000	[thread overview]
Message-ID: <20250324173030.3733517-4-bruce.richardson@intel.com> (raw)
In-Reply-To: <20250324173030.3733517-1-bruce.richardson@intel.com>

To use cores with IDs greater than RTE_MAX_LCORE the user must provide a
mapping of those higher core numbers to ids within the 0 - RTE_MAX_LCORE
range. This can be awkward to do manually when more than a few lcores
are involved, so instead we can provide an extra option to EAL to do
this manually.

This patch therefore introduces the "map-lcore-ids" flag, which
automatically maps all provided lcore numbers to start at zero.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 doc/guides/linux_gsg/eal_args.include.rst  | 26 ++++++++++++++++-
 drivers/event/dlb2/pf/base/dlb2_resource.c |  2 +-
 lib/eal/common/eal_common_options.c        | 34 +++++++++++++++-------
 lib/eal/common/eal_options.h               |  3 ++
 lib/eal/include/rte_eal.h                  |  4 ++-
 5 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/doc/guides/linux_gsg/eal_args.include.rst b/doc/guides/linux_gsg/eal_args.include.rst
index 9cfbf7de84..1d9525f73c 100644
--- a/doc/guides/linux_gsg/eal_args.include.rst
+++ b/doc/guides/linux_gsg/eal_args.include.rst
@@ -13,7 +13,7 @@ Lcore-related options
     List of cores to run on
 
     The argument format is ``<c1>[-c2][,c3[-c4],...]``
-    where ``c1``, ``c2``, etc are core indexes between 0 and 128.
+    where ``c1``, ``c2``, etc are core indexes between 0 and RTE_MAX_LCORE (default 128).
 
 *   ``--lcores <core map>``
 
@@ -29,10 +29,34 @@ Lcore-related options
     The grouping ``()`` can be omitted for single element group.
     The ``@`` can be omitted if cpus and lcores have the same value.
 
+.. Note::
+    When using ``--lcores`` parameter to map lcore ids to cpus,
+    the lcore ids must be in the range 0 to ``RTE_MAX_LCORE`` (default 128),
+    but the cpu ids need not be.
+
+    This allows an application to use cpus with ids greater than ``RTE_MAX_LCORE``,
+    so long as the total number of lcores is less than or equal to ``RTE_MAX_LCORE``.
+
 .. Note::
     At a given instance only one core option ``--lcores``, ``-l`` or ``-c`` can
     be used.
 
+*   ``--map-lcore-ids``, ``-M``
+
+    Automatically map the cpus given in a coremask using ``-c`` parameter,
+    or in a core list using ``-l`` parameter, to internal lcore-ids starting at 0.
+    (If ``--lcores`` parameter is provided, this parameter is ignored.)
+
+    This can provide a shorter way, compared to using ``--lcores`` parameter,
+    to use cpus with ids greater than ``RTE_MAX_LCORE`` in an application.
+
+    For example, ``-c 0x3000 --map-lcore-ids`` will cause cpus 12 and 13 to be used,
+    with application lcore ids of 0 and 1 respectively.
+    Similarly, ``-Ml 94,95,31-33`` is equivalent to ``--lcores=0@94,1@95,2@31,3@32,4@33``,
+    where the application lcore ids are 0-4,
+    mapped to the physical cpus 94, 95, 31, 32 and 33 respectively.
+
+
 *   ``--main-lcore <core ID>``
 
     Core ID that is used as main.
diff --git a/drivers/event/dlb2/pf/base/dlb2_resource.c b/drivers/event/dlb2/pf/base/dlb2_resource.c
index 9b087b03b5..d38aa5115e 100644
--- a/drivers/event/dlb2/pf/base/dlb2_resource.c
+++ b/drivers/event/dlb2/pf/base/dlb2_resource.c
@@ -931,7 +931,7 @@ dlb2_resource_probe(struct dlb2_hw *hw, const void *probe_args)
 	cpu = rte_get_next_lcore(-1, 1, 0);
 	hw->num_prod_cores = 0;
 	if (mask) {
-		int n = rte_eal_expand_coremask(mask, hw->prod_core_list);
+		int n = rte_eal_expand_coremask(mask, hw->prod_core_list, true);
 		if (n <= 0) {
 			DLB2_HW_ERR(hw, ": Invalid producer coremask=%s\n", mask);
 			return -1;
diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index 22ea6b24e4..25061ffb9b 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -56,6 +56,7 @@ eal_short_options[] =
 	"d:" /* driver */
 	"h"  /* help */
 	"l:" /* corelist */
+	"M" /* map lcore ids to zero*/
 	"S:" /* service corelist */
 	"m:" /* memory size */
 	"n:" /* memory channels */
@@ -106,6 +107,7 @@ eal_long_options[] = {
 	{OPT_NO_TELEMETRY,      0, NULL, OPT_NO_TELEMETRY_NUM     },
 	{OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM},
 	{OPT_HUGE_WORKER_STACK, 2, NULL, OPT_HUGE_WORKER_STACK_NUM     },
+	{OPT_MAP_LCORE_IDS,     0, NULL, OPT_MAP_LCORE_IDS_NUM    },
 
 	{0,                     0, NULL, 0                        }
 };
@@ -152,6 +154,7 @@ TAILQ_HEAD_INITIALIZER(devopt_list);
 static int main_lcore_parsed;
 static int mem_parsed;
 static struct lcore_options {
+	bool map_lcore_ids;
 	const char *core_mask_opt;
 	const char *core_list_opt;
 	const char *core_map_opt;
@@ -723,13 +726,14 @@ check_core_list(int *lcores, unsigned int count)
 	if (len > 0)
 		lcorestr[len - 1] = 0;
 	EAL_LOG(ERR, "To use high physical core ids, "
-		"please use --lcores to map them to lcore ids below RTE_MAX_LCORE, "
+		"please use --map-lcore-ids/-M flag to map core ids automatically, "
+		"or use --lcores to map them manually to lcore ids below RTE_MAX_LCORE, "
 		"e.g. --lcores %s", lcorestr);
 	return -1;
 }
 
 int
-rte_eal_expand_coremask(const char *coremask, int *cores)
+rte_eal_expand_coremask(const char *coremask, int *cores, bool no_check)
 {
 	const char *coremask_orig = coremask;
 	unsigned int count = 0;
@@ -784,7 +788,7 @@ rte_eal_expand_coremask(const char *coremask, int *cores)
 		return -1;
 	}
 
-	if (check_core_list(cores, count) != 0)
+	if (!no_check && check_core_list(cores, count) != 0)
 		return -1;
 
 	return count;
@@ -869,7 +873,7 @@ eal_parse_service_corelist(const char *corelist)
 }
 
 static int
-eal_parse_corelist(const char *corelist, int *cores)
+eal_parse_corelist(const char *corelist, int *cores, bool no_check)
 {
 	unsigned int count = 0, i;
 	char *end = NULL;
@@ -932,7 +936,7 @@ eal_parse_corelist(const char *corelist, int *cores)
 		return -1;
 	}
 
-	if (check_core_list(cores, count))
+	if (!no_check && check_core_list(cores, count))
 		return -1;
 
 	return count;
@@ -1558,6 +1562,10 @@ eal_parse_common_option(int opt, const char *optarg,
 	case 'l':
 		lcore_options.core_list_opt = optarg;
 		break;
+	/* map lcore ids */
+	case 'M':
+		lcore_options.map_lcore_ids = true;
+		break;
 	/* service coremask */
 	case 's':
 		lcore_options.service_mask_opt = optarg;
@@ -1866,10 +1874,11 @@ eal_adjust_config(struct internal_config *internal_cfg)
 
 
 	if (lcore_options.core_mask_opt || lcore_options.core_list_opt) {
-		int lcore_indexes[RTE_MAX_LCORE];
+		bool map_ids = lcore_options.map_lcore_ids;
+		int idxs[RTE_MAX_LCORE];
 		int nb_indexes = lcore_options.core_list_opt ?
-				eal_parse_corelist(lcore_options.core_list_opt, lcore_indexes) :
-				rte_eal_expand_coremask(lcore_options.core_mask_opt, lcore_indexes);
+				eal_parse_corelist(lcore_options.core_list_opt, idxs, map_ids) :
+				rte_eal_expand_coremask(lcore_options.core_mask_opt, idxs, map_ids);
 
 		if (nb_indexes < 0)
 			return -1;
@@ -1877,13 +1886,16 @@ eal_adjust_config(struct internal_config *internal_cfg)
 		char *core_map_opt = malloc(RTE_MAX_LCORE * 10);
 		size_t core_map_len = 0;
 		for (i = 0; i < nb_indexes; i++) {
-			if (!eal_cpu_detected(lcore_indexes[i])) {
-				EAL_LOG(ERR, "core %d not present", lcore_indexes[i]);
+			if (!eal_cpu_detected(idxs[i])) {
+				EAL_LOG(ERR, "core %d not present", idxs[i]);
 				return -1;
 			}
 			int n = snprintf(core_map_opt + core_map_len,
 					(RTE_MAX_LCORE * 10) - core_map_len,
-					"%s%d", i == 0 ? "" : ",", lcore_indexes[i]);
+					"%s%d@%d",
+					i == 0 ? "" : ",",
+					map_ids ? i : idxs[i],
+					idxs[i]);
 			if (n < 0 || (size_t)n >= (RTE_MAX_LCORE * 10) - core_map_len) {
 				EAL_LOG(ERR, "core map string too long");
 				return -1;
diff --git a/lib/eal/common/eal_options.h b/lib/eal/common/eal_options.h
index 95fb4f6108..1344bce9ba 100644
--- a/lib/eal/common/eal_options.h
+++ b/lib/eal/common/eal_options.h
@@ -17,6 +17,9 @@ enum {
 	OPT_DEV_ALLOW_NUM       = 'a',
 #define OPT_DEV_BLOCK         "block"
 	OPT_DEV_BLOCK_NUM      = 'b',
+#define OPT_MAP_LCORE_IDS  "map-lcore-ids"
+	OPT_MAP_LCORE_IDS_NUM  = 'M',
+
 
 	/* first long only option value must be >= 256, so that we won't
 	 * conflict with short options */
diff --git a/lib/eal/include/rte_eal.h b/lib/eal/include/rte_eal.h
index 013075487c..2f7a7dcfbe 100644
--- a/lib/eal/include/rte_eal.h
+++ b/lib/eal/include/rte_eal.h
@@ -500,13 +500,15 @@ rte_eal_get_runtime_dir(void);
  * @param cores
  *   The output array to store the core ids.
  *   This array must be at least RTE_MAX_LCORE large.
+ * @param nocheck
+ *   If true, skip checking that the core ids are between 0..RTE_MAX_LCORE
  * @return
  *  The number of cores in the coremask, and in the returned "cores" array,
  *  -1 if the string content was invalid.
  */
 __rte_internal
 int
-rte_eal_expand_coremask(const char *coremask, int *cores);
+rte_eal_expand_coremask(const char *coremask, int *cores, bool nocheck);
 
 #ifdef __cplusplus
 }
-- 
2.45.2


      parent reply	other threads:[~2025-03-24 17:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 11:38 [RFC PATCH 0/3] allow easier use of high lcore-ids Bruce Richardson
2025-03-13 11:38 ` [RFC PATCH 1/3] eal: centralize core parameter parsing Bruce Richardson
2025-03-13 11:38 ` [RFC PATCH 2/3] eal: convert core masks and lists to core sets Bruce Richardson
2025-03-13 11:38 ` [RFC PATCH 3/3] eal: allow automatic mapping of high lcore ids Bruce Richardson
2025-03-24 17:30 ` [PATCH v2 0/3] allow easier use of high lcore-ids Bruce Richardson
2025-03-24 17:30   ` [PATCH v2 1/3] eal: centralize core parameter parsing Bruce Richardson
2025-03-24 17:30   ` [PATCH v2 2/3] eal: convert core masks and lists to core sets Bruce Richardson
2025-03-24 17:30   ` Bruce Richardson [this message]

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=20250324173030.3733517-4-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=pravin.pathak@intel.com \
    --cc=roretzla@linux.microsoft.com \
    /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).