Skip to contentSkip to conversation

rework EAL argument parsing in DPDK

RFC PATCH Superseded Bruce Richardson 6 participants 202 messages May 20, 2025 – Oct 20, 2025 Page 2 of 3

Subsystems (2)
lore
Share & tools
lore
#69 lore raw

v7 cover Simplify running with high-numbered CPUs

In reply to Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL args "--lcores-remapped", also shortened to just "-L", and "--lcoreid-base", are added to DPDK to support this. However, in order to enable the addition of these new flags, the first 10 patches of this set do cleanups, for reasons explained below.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

To do the initial argument gathering, this RFC uses the existing argparse library in DPDK. With recent changes, and a few additional patches at the start of this set, this library now meets our needs for EAL argument parsing and allows us to not need to do direct getopt argument processing inside EAL at all.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V7:
* expand the scope of the patchset beyond just cleanup to add in the extra 3 patches for -L and --lcoreid-base option.

V6:
* Rebase to apply cleanly on latest main

V5:
* Resubmit of V4, which didn't get sent correctly, or picked up correctly in patchwork.

V4:
* Updated patch 5 to auto-generate the arg struct definition from the same list of defines used to construct the argument list.

V3:
* Added 3 new initial patches, one for minor build-system addition, and two for functionality in argparse to allow the user-callback help function to be maintained as we move to argparse.
* Added doc updates in the first EAL patch adding the long options
* Fixed ASAN issues by adding a patch to properly clean up EAL init - both memory allocations and fixing the run-once flag
* Put ifdefs around the linux-only or unix-only options in EAL patch 2
* Updated args to handle numa-mem and numa-limit as equivalent socket-mem and socket-limit

Bruce Richardson (13):
build: add define for the OS environment name
argparse: export function to print help text for object
argparse: allow user-override of help printing
argparse: add documentation on supported value types
eal: add long options for each short option
eal: define the EAL parameters in argparse format
eal: gather EAL args before processing
eal: ensure proper cleanup on EAL init failure
eal: combine parameter validation checks
eal: simplify handling of conflicting cmdline options
argparse: add support for parsing core lists
eal: simplify running CPUs with ids above max lcores
eal: add warnings about ignored options

 app/test/test_argparse.c                  |  188 +++
 config/meson.build                        |    1 +
 doc/guides/contributing/design.rst        |    2 +-
 doc/guides/linux_gsg/eal_args.include.rst |   66 +-
 doc/guides/prog_guide/argparse_lib.rst    |  121 +-
 doc/guides/rel_notes/release_25_11.rst    |   16 +
 lib/argparse/rte_argparse.c               |  109 +-
 lib/argparse/rte_argparse.h               |   23 +-
 lib/eal/common/eal_common_memory.c        |    3 +-
 lib/eal/common/eal_common_options.c       | 1344 ++++++++++++---------
 lib/eal/common/eal_option_list.h          |   92 ++
 lib/eal/common/eal_options.h              |  102 +-
 lib/eal/common/eal_private.h              |   11 +
 lib/eal/freebsd/eal.c                     |  245 +---
 lib/eal/linux/eal.c                       |  470 +------
 lib/eal/linux/eal_memory.c                |    2 +-
 lib/eal/meson.build                       |    2 +-
 lib/eal/windows/eal.c                     |  156 +--
 lib/meson.build                           |    1 +
 19 files changed, 1500 insertions(+), 1454 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h

--
2.48.1

#70 lore raw

PATCH v7 1/13 build: add define for the OS environment name

Introduce a string define for the currently running OS, or execution environment.

Originally, with old make build system, CONFIG_RTE_EXEC_ENV used to hold this name string, but the variable seems to have been missed in the meson build system, until commit cadb255e25d6 ("eal: add OS defines for C conditional checks") which introduced the RTE_EXEC_ENV for a different purpose. Now we can fix the docs with the new name reference.

---
 config/meson.build                 | 1 +
 doc/guides/contributing/design.rst | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
index f31fef216c..40f33816aa 100644
@@ -20,6 +20,7 @@ foreach env, id:exec_envs
     dpdk_conf.set10('RTE_EXEC_ENV_IS_' + env.to_upper(), (exec_env == env))
 endforeach
 dpdk_conf.set('RTE_EXEC_ENV', exec_envs[exec_env])
+dpdk_conf.set_quoted('RTE_EXEC_ENV_NAME', exec_env)
 dpdk_conf.set('RTE_EXEC_ENV_' + exec_env.to_upper(), 1)
 
 # MS linker requires special treatment.
doc/guides/contributing/design.rst +1 -1
index b724177ba1..5517613424 100644
@@ -50,7 +50,7 @@ Per Execution Environment Sources
 
 The following macro options can be used:
 
-* ``RTE_EXEC_ENV`` is a string that contains the name of the executive environment.
+* ``RTE_EXEC_ENV_NAME`` is a string that contains the name of the executive environment.
 * ``RTE_EXEC_ENV_FREEBSD``, ``RTE_EXEC_ENV_LINUX`` or ``RTE_EXEC_ENV_WINDOWS`` are defined only if we are building for this execution environment.
 
 Mbuf features
Signature · 1 line
2.48.1
#71 lore raw

PATCH v7 2/13 argparse: export function to print help text for object

In reply to Bruce Richardson

Make the function to print out the help text for an argparse object a public function, which takes as a new parameter the file stream on which to print. This can be used in future to allow application to extend their own help information.

---
 lib/argparse/rte_argparse.c | 43 +++++++++++++++++++------------------
 lib/argparse/rte_argparse.h | 14 ++++++++++++
 2 files changed, 36 insertions(+), 21 deletions(-)
lib/argparse/rte_argparse.c +22 -21
index 331f05f01d..d3b32c6357 100644
@@ -716,23 +716,23 @@ calc_help_align(const struct rte_argparse *obj)
 }
 
 static void
-show_oneline_help(const struct rte_argparse_arg *arg, uint32_t width)
+show_oneline_help(FILE *stream, const struct rte_argparse_arg *arg, uint32_t width)
 {
 	uint32_t len = 0;
 	uint32_t i;
 
 	if (arg->name_short != NULL)
-		len = printf(" %s,", arg->name_short);
-	len += printf(" %s", arg->name_long);
+		len = fprintf(stream, " %s,", arg->name_short);
+	len += fprintf(stream, " %s", arg->name_long);
 
 	for (i = len; i < width; i++)
-		printf(" ");
+		fprintf(stream, " ");
 
-	printf("%s\n", arg->help);
+	fprintf(stream, "%s\n", arg->help);
 }
 
 static void
-show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
+show_args_pos_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	uint32_t position_count = calc_position_count(obj);
 	const struct rte_argparse_arg *arg;
@@ -741,19 +741,19 @@ show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
 	if (position_count == 0)
 		return;
 
-	printf("\npositional arguments:\n");
+	fprintf(stream, "\npositional arguments:\n");
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_positional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
 static void
-show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
+show_args_opt_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	static const struct rte_argparse_arg help = {
 		.name_long = "--help",
@@ -763,34 +763,35 @@ show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
 	const struct rte_argparse_arg *arg;
 	uint32_t i;
 
-	printf("\noptions:\n");
-	show_oneline_help(&help, align);
+	fprintf(stream, "\noptions:\n");
+	show_oneline_help(stream, &help, align);
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_optional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
-static void
-show_args_help(const struct rte_argparse *obj)
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_print_help, 25.07)
+void
+rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj)
 {
 	uint32_t align = calc_help_align(obj);
 
-	printf("usage: %s %s\n", obj->prog_name, obj->usage);
+	fprintf(stream, "usage: %s %s\n", obj->prog_name, obj->usage);
 	if (obj->descriptor != NULL)
-		printf("\ndescriptor: %s\n", obj->descriptor);
+		fprintf(stream, "\ndescriptor: %s\n", obj->descriptor);
 
-	show_args_pos_help(obj, align);
-	show_args_opt_help(obj, align);
+	show_args_pos_help(stream, obj, align);
+	show_args_opt_help(stream, obj, align);
 
 	if (obj->epilog != NULL)
-		printf("\n%s\n", obj->epilog);
+		fprintf(stream, "\n%s\n", obj->epilog);
 	else
-		printf("\n");
+		fprintf(stream, "\n");
 }
 
 RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_parse, 24.03)
@@ -820,7 +821,7 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		show_args_help(obj);
+		rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +14 -0
index 52bef34363..baf278f6b9 100644
@@ -189,6 +189,20 @@ struct rte_argparse {
 __rte_experimental
 int rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Output the help text information for the given argparse object.
+ *
+ * @param stream
+ *   Output file handle, e.g. stdout, stderr, on which to print the help text.
+ * @param obj
+ *   Parser object.
+ */
+__rte_experimental
+void rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.48.1
#72 lore raw

Re: [PATCH v7 02/13] argparse: export function to print help text for object

Quoted 12 lines · Bruce Richardson

Make the function to print out the help text for an argparse object a public function, which takes as a new parameter the file stream on which to print. This can be used in future to allow application to extend their own help information.

---
 lib/argparse/rte_argparse.c | 43 +++++++++++++++++++------------------
 lib/argparse/rte_argparse.h | 14 ++++++++++++
 2 files changed, 36 insertions(+), 21 deletions(-)

[snip]

lib/argparse/rte_argparse.c show_args_opt_help(const struct rte_argparse *obj, uint32_t align) · line 778

Quoted 6 lines
        }

}

lib/argparse/rte_argparse.c +1 -2
-static void
-show_args_help(const struct rte_argparse *obj)
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_print_help, 25.07)

Small rebase needed here, 25.11.

Signature · 1 line
David Marchand
#73 lore raw

PATCH v7 3/13 argparse: allow user-override of help printing

In reply to Bruce Richardson

When the arguments passed to argparse include -h/--help then usage information is automatically printed. Provide the capability for the user to supply their own help function for this.

---
 doc/guides/prog_guide/argparse_lib.rst | 16 ++++++++++++++++
 doc/guides/rel_notes/release_25_11.rst |  7 +++++++
 lib/argparse/rte_argparse.c            |  5 ++++-
 lib/argparse/rte_argparse.h            |  7 ++++++-
 4 files changed, 33 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +16 -0
index 9f11714890..b309260d20 100644
@@ -24,6 +24,8 @@ Features and Capabilities
   #. autosave: used for parsing known value types;
   #. callback: will invoke user callback to parse.
 
+- Supports automatic help and usage information.
+
 Usage Guide
 -----------
 
@@ -193,3 +195,17 @@ Then the user input could contain multiple ``--xyz`` arguments.
 
    The multiple times argument only support with optional argument
    and must be parsed by callback way.
+
+Help and Usage Information
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic generation of help and usage information.
+When the input arguments include ``-h`` or ``--help``,
+it will print the usage information to standard output.
+If the default help output is not what is wanted,
+the user can provide a custom help printing function by setting the ``print_help`` field in the ``rte_argparse`` object.
+(If this field is set to NULL, the default help printing function will be used.)
+
+If the custom help printing function wants to use the text produced by the default help function,
+it can call the function ``rte_argparse_print_help()`` to get the help text printed to an output stream,
+for example: stdout or stderr.
doc/guides/rel_notes/release_25_11.rst +7 -0
index ccad6d89ff..75bbd0e821 100644
@@ -55,6 +55,13 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Allow overriding the automatic usage/help generation in argparse library.**
+
+  The argparse library now supports overriding the automatic help text generation,
+  by allowing the user to provide a custom function to generate the output text.
+  The built-in help text function is available as a public function which can be reused by custom functions,
+  if so desired.
+
 
 Removed Items
 -------------
lib/argparse/rte_argparse.c +4 -1
index d3b32c6357..e7b9bf573d 100644
@@ -821,7 +821,10 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		rte_argparse_print_help(stdout, obj);
+		if (obj->print_help != NULL)
+			obj->print_help(obj);
+		else
+			rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +6 -1
index baf278f6b9..63b49ba220 100644
@@ -160,8 +160,13 @@ struct rte_argparse {
 	rte_arg_parser_t callback;
 	/** Opaque which used to invoke callback. */
 	void *opaque;
+	/**
+	 * Function pointer for printing usage when -h is passed.
+	 * If this is NULL, default printing function will be used.
+	 */
+	void (*print_help)(const struct rte_argparse *obj);
 	/** Reserved field used for future extension. */
-	void *reserved[16];
+	void *reserved[15];
 	/** Arguments configuration. Must ended with ARGPARSE_ARG_END(). */
 	struct rte_argparse_arg args[];
 };
Signature · 1 line
2.48.1
#74 lore raw

PATCH v7 4/13 argparse: add documentation on supported value types

In reply to Bruce Richardson

The different value types supported by the argparse library are not discussed in the documentation, so add some reference material about them.

---
 doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +71 -2
index b309260d20..7868af5672 100644
@@ -160,6 +160,75 @@ both use this way, the parsing is as follows:
 - For argument ``ooo``, it is positional argument,
   the ``ooo_val`` will be set to user input's value.
 
+Supported Value Types
+~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic parsing of several data types when using
+the autosave method. The parsed values are automatically converted from string
+input to the appropriate data type and stored in the ``val_saver`` field.
+
+Integer Types
+^^^^^^^^^^^^^
+
+The library supports parsing various integer types:
+
+- ``RTE_ARGPARSE_VALUE_TYPE_INT`` - signed integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U8`` - unsigned 8-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U16`` - unsigned 16-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U32`` - unsigned 32-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U64`` - unsigned 64-bit integer
+
+.. code-block:: C
+
+   static int my_int;
+   static uint16_t my_port;
+   static uint32_t my_count;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--number", "-n", "Integer value", &my_int, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_INT },
+         { "--port", "-p", "Port number", &my_port, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_U16 },
+         { "--count", "-c", "Count value", &my_count, (void *)1000, RTE_ARGPARSE_VALUE_OPTIONAL, RTE_ARGPARSE_VALUE_TYPE_U32 },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+String Type
+^^^^^^^^^^^
+
+String arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_STR``.
+When using this type, the input value is saved to the provided pointer without any parsing or validation.
+
+.. code-block:: C
+
+   static const char *my_string;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--name", "-n", "Name string", &my_string, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_STR },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+Boolean Type
+^^^^^^^^^^^^
+
+Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept the following input formats:
+
+- ``true``, ``false`` (case-sensitive)
+- ``1``, ``0`` (numeric format)
+
+.. code-block:: C
+
+   static bool my_flag;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--enable", "-e", "Enable feature", &my_flag, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_BOOL },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -167,8 +236,8 @@ It could also choose to use callback to parse,
 just define a unique index for the argument
 and make the ``val_save`` field to be NULL also zero value-type.
 
-In the above example, the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp``
-both use this way.
+In the example at the top of this section,
+the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp`` all use this way.
 
 Multiple times argument
 ~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.48.1
#75 lore raw

PATCH v7 5/13 eal: add long options for each short option

In reply to Bruce Richardson

To simplify future rework of the EAL arg handling, add a long-option equivalent for each short option that doesn't already have one.

When updating the docs with the new long options, standardize the format of options which have both short and long variants, and drop the deprecated service-coremask option from the docs, rather than adding its new long option.

---
 doc/guides/linux_gsg/eal_args.include.rst | 20 ++++++++------------
 lib/eal/common/eal_common_options.c       |  9 +++++++++
 lib/eal/common/eal_options.h              | 16 ++++++++++++++++
 3 files changed, 33 insertions(+), 12 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +8 -12
index 9ced54af40..0b17879d42 100644
@@ -4,7 +4,7 @@
 Lcore-related options
 ~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-l/--lcores <core list>``
+*   ``-l, --lcores <core list>``
 
     List of cores to run on
 
@@ -71,11 +71,7 @@ Lcore-related options
 
     Core ID that is used as main.
 
-*   ``-s <service core mask>``
-
-    Hexadecimal bitmask of cores to be used as service cores.
-
-*   ``-S <service core list>``
+*   ``-S, --service-corelist <service core list>``
 
     List of cores to be used as service cores.
 
@@ -108,7 +104,7 @@ Device-related options
 
        --vdev 'net_pcap0,rx_pcap=input.pcap,tx_pcap=output.pcap'
 
-*   ``-d <path to shared object or directory>``
+*   ``-d, --driver-path <path to shared object or directory>``
 
     Load external drivers. An argument can be a single shared object file, or a
     directory containing multiple driver shared objects. Multiple -d options are
@@ -134,15 +130,15 @@ Multiprocessing-related options
 Memory-related options
 ~~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-n <number of channels>``
+*   ``-n, --memory-channels <number of channels>``
 
     Set the number of memory channels to use.
 
-*   ``-r <number of ranks>``
+*   ``-r, --memory-ranks <number of ranks>``
 
     Set the number of memory ranks (auto-detected by default).
 
-*   ``-m <megabytes>``
+*   ``-m, --memory-size <megabytes>``
 
     Amount of memory to preallocate at startup.
 
@@ -236,11 +232,11 @@ Debugging options
 Other options
 ~~~~~~~~~~~~~
 
-*   ``-h``, ``--help``
+*   ``-h, --help``
 
     Display help message listing all EAL parameters.
 
-*   ``-v``
+*   ``-v, --version``
 
     Display the version information on startup.
 
lib/eal/common/eal_common_options.c +9 -0
index 3169dd069f..226acea467 100644
@@ -66,7 +66,9 @@ eal_short_options[] =
 const struct option
 eal_long_options[] = {
 	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
+	{OPT_COREMASK,          1, NULL, OPT_COREMASK_NUM        },
 	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
+	{OPT_DRIVER_PATH,       1, NULL, OPT_DRIVER_PATH_NUM     },
 	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
 	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
 	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
@@ -76,6 +78,11 @@ eal_long_options[] = {
 	{OPT_LOG_COLOR,		2, NULL, OPT_LOG_COLOR_NUM	  },
 	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
 	{OPT_LOG_TIMESTAMP,     2, NULL, OPT_LOG_TIMESTAMP_NUM    },
+	{OPT_MEMORY_CHANNELS,   1, NULL, OPT_MEMORY_CHANNELS_NUM },
+	{OPT_MEMORY_RANKS,      1, NULL, OPT_MEMORY_RANKS_NUM    },
+	{OPT_MEMORY_SIZE,       1, NULL, OPT_MEMORY_SIZE_NUM     },
+	{OPT_SERVICE_CORELIST,  1, NULL, OPT_SERVICE_CORELIST_NUM },
+	{OPT_SERVICE_COREMASK,  1, NULL, OPT_SERVICE_COREMASK_NUM },
 	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
 	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
 	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
@@ -109,6 +116,8 @@ 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_VERSION,           0, NULL, OPT_VERSION_NUM         },
+
 
 	{0,                     0, NULL, 0                        }
 };
lib/eal/common/eal_options.h +16 -0
index 7a56aa3810..6ef45559f0 100644
@@ -17,8 +17,24 @@ enum {
 	OPT_DEV_ALLOW_NUM       = 'a',
 #define OPT_DEV_BLOCK         "block"
 	OPT_DEV_BLOCK_NUM      = 'b',
+#define OPT_COREMASK          "coremask"
+	OPT_COREMASK_NUM       = 'c',
+#define OPT_DRIVER_PATH       "driver-path"
+	OPT_DRIVER_PATH_NUM    = 'd',
 #define OPT_LCORES            "lcores"
 	OPT_LCORES_NUM         = 'l',
+#define OPT_MEMORY_SIZE       "memory-size"
+	OPT_MEMORY_SIZE_NUM    = 'm',
+#define OPT_MEMORY_CHANNELS   "memory-channels"
+	OPT_MEMORY_CHANNELS_NUM = 'n',
+#define OPT_MEMORY_RANKS     "memory-ranks"
+	OPT_MEMORY_RANKS_NUM   = 'r',
+#define OPT_SERVICE_COREMASK  "service-coremask"
+	OPT_SERVICE_COREMASK_NUM = 's',
+#define OPT_SERVICE_CORELIST  "service-corelist"
+	OPT_SERVICE_CORELIST_NUM = 'S',
+#define OPT_VERSION           "version"
+	OPT_VERSION_NUM        = 'v',
 
 	/* first long only option value must be >= 256, so that we won't
 	 * conflict with short options */
Signature · 1 line
2.48.1
#76 lore raw

Re: [PATCH v7 05/13] eal: add long options for each short option

lib/eal/common/eal_common_options.c eal_long_options[] = { · line 121

Quoted 7 lines · Bruce Richardson
lib/eal/common/eal_common_options.c +2 -0
@@ -109,6 +116,8 @@ 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_VERSION,           0, NULL, OPT_VERSION_NUM         },
+
 

Nit: one empty line is enough.

Quoted 2 lines
lib/eal/common/eal_common_options.c +0 -0
        {0,                     0, NULL, 0                        }
 };
Signature · 1 line
David Marchand
#77 lore raw

PATCH v7 6/13 eal: define the EAL parameters in argparse format

In reply to Bruce Richardson

Create eal_option_list.h, containing all the possible EAL parameters, and basic info about them, such as type, whether they take a parameter or not. Each entry is defined using a macro, which will be then interpreted when the file is included.

First time this header in included in the eal_common_options.c file, the macros are defined in such a way as to define field elements for an "eal_init_args" structure, where each value is either a string type, if it takes a parameter, or boolean type if it doesn't. For those elements that take multiple values, i.e. are passed multiple times, we put them in a TAILQ.

The second time of inclusion, the macros are defined so as to define the arguments in an rte_argparse structure for EAL. For the basic string and boolean types, we just store the values in the appropriate field in the previous defined "eal_init_args" structure. For the list elements, we use the argparse callback to process those elements, adding them to the TAILQ as they are encountered.

---
 lib/eal/common/eal_common_options.c | 135 +++++++++++++++++++++++++++-
 lib/eal/common/eal_option_list.h    |  90 +++++++++++++++++++
 lib/eal/meson.build                 |   2 +-
 lib/meson.build                     |   1 +
 4 files changed, 224 insertions(+), 4 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h
lib/eal/common/eal_common_options.c +132 -3
index 226acea467..ebb9f7063d 100644
@@ -28,11 +28,13 @@
 #include <rte_version.h>
 #include <rte_devargs.h>
 #include <rte_memcpy.h>
+#include <sys/queue.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <rte_telemetry.h>
 #endif
 #include <rte_vect.h>
 
+#include <rte_argparse.h>
 #include <eal_export.h>
 #include "eal_internal_cfg.h"
 #include "eal_options.h"
@@ -47,6 +49,136 @@
 #define LCORE_OPT_LST 1
 #define LCORE_OPT_MSK 2
 
+/* Allow the application to print its usage message too if set */
+static rte_usage_hook_t rte_application_usage_hook;
+
+struct arg_list_elem {
+	TAILQ_ENTRY(arg_list_elem) next;
+	char *arg;
+};
+TAILQ_HEAD(arg_list, arg_list_elem);
+
+struct eal_init_args {
+	/* define a struct member for each EAL option, member name is the same as option name.
+	 * Parameters that take an argument e.g. -l, are char *,
+	 * parameters that take no options e.g. --no-huge, are bool.
+	 * parameters that can be given multiple times e.g. -a, are arg_lists,
+	 * parameters that are optional e.g. --huge-unlink,
+	 *   are char * but are set to (void *)1 if the parameter is not given.
+	 * for aliases, i.e. options under different names, no field needs to be output
+	 */
+#define LIST_ARG(long, short, help_str, fieldname) struct arg_list fieldname;
+#define STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define OPT_STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define BOOL_ARG(long, short, help_str, fieldname) bool fieldname;
+#define STR_ALIAS(long, short, help_str, fieldname)
+
+#define INCLUDE_ALL_ARG 1  /* for struct definition, include even unsupported values */
+#include "eal_option_list.h"
+#undef INCLUDE_ALL_ARG
+};
+struct eal_init_args args;
+
+/* an rte_argparse callback to append the argument to an arg_list
+ * in args. The index is the offset into the struct of the list.
+ */
+static int
+arg_list_callback(uint32_t index, const char *arg, void *init_args)
+{
+	struct arg_list *list = RTE_PTR_ADD(init_args, index);
+	struct arg_list_elem *elem;
+
+	elem = malloc(sizeof(*elem));
+	if (elem == NULL)
+		return -1;
+
+	elem->arg = strdup(arg);
+	if (elem->arg == NULL) {
+		free(elem);
+		return -1;
+	}
+
+	TAILQ_INSERT_TAIL(list, elem, next);
+	return 0;
+}
+
+static void
+eal_usage(const struct rte_argparse *obj)
+{
+	rte_argparse_print_help(stdout, obj);
+	if (rte_application_usage_hook != NULL)
+		rte_application_usage_hook(obj->prog_name);
+}
+
+/* undef the *_ARG macros before redefining to generate the argparse arg list */
+#undef LIST_ARG
+#undef STR_ARG
+#undef OPT_STR_ARG
+#undef BOOL_ARG
+#undef STR_ALIAS
+
+/* For arguments which have an arg_list type, they use callback (no val_saver),
+ * require a value, and have the SUPPORT_MULTI flag.
+ */
+#define LIST_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_set = (void *)offsetof(struct eal_init_args, fieldname), \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.flags = RTE_ARGPARSE_FLAG_SUPPORT_MULTI, \
+},
+/* For arguments which have a string type, they use val_saver (no callback),
+ * and normally REQUIRED_VALUE.
+ */
+#define STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For flags which have optional arguments, they use both val_saver and val_set,
+ * but still have a string type.
+ */
+#define OPT_STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_OPTIONAL, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For boolean arguments, they use val_saver and val_set, with NO_VALUE flag.
+ */
+#define BOOL_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_NONE, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_BOOL, \
+},
+#define STR_ALIAS STR_ARG
+
+struct rte_argparse eal_argparse  = {
+	.prog_name = "",
+	.usage = "<DPDK EAL options> -- <App options>",
+	.epilog = "For more information on EAL options, see the DPDK documentation at: \n"
+			"\thttps://doc.dpdk.org/guides/" RTE_EXEC_ENV_NAME "_gsg/",
+	.exit_on_error = true,
+	.callback = arg_list_callback,
+	.print_help = eal_usage,
+	.opaque = &args,
+	.args = {
+		#include "eal_option_list.h"
+		ARGPARSE_ARG_END(),
+	}
+};
+
 const char
 eal_short_options[] =
 	"a:" /* allow */
@@ -165,9 +297,6 @@ static int main_lcore_parsed;
 static int mem_parsed;
 static int core_parsed;
 
-/* Allow the application to print its usage message too if set */
-static rte_usage_hook_t rte_application_usage_hook;
-
 /* Returns rte_usage_hook_t */
 rte_usage_hook_t
 eal_get_application_usage_hook(void)
lib/eal/common/eal_option_list.h new file +90 -0

90 lines not on this page · raw message

lib/eal/meson.build +1 -1
index e1d6c4cf17..f9fcee24ee 100644
@@ -14,7 +14,7 @@ subdir(exec_env)
 
 subdir(arch_subdir)
 
-deps += ['log', 'kvargs']
+deps += ['argparse', 'kvargs']
 if not is_windows
     deps += ['telemetry']
 endif
lib/meson.build +1 -0
index 0d56b2083b..dec90059e1 100644
@@ -71,6 +71,7 @@ libraries = [
 ]
 
 always_enable = [
+        'argparse',
         'cmdline',
         'eal',
         'ethdev',
Signature · 1 line
2.48.1
#78 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

lib/eal/common/eal_common_options.c line 31

Quoted 9 lines · Bruce Richardson
lib/eal/common/eal_common_options.c +1 -0
index 226acea467..ebb9f7063d 100644
@@ -28,11 +28,13 @@
 #include <rte_version.h>
 #include <rte_devargs.h>
 #include <rte_memcpy.h>
+#include <sys/queue.h>

Nit: system headers are usually going in the first group of includes. This can be fixed when applying.

[snip]

lib/eal/common/eal_common_options.c line 171

Quoted 5 lines
lib/eal/common/eal_common_options.c +5 -0
+struct rte_argparse eal_argparse  = {
+       .prog_name = "",
+       .usage = "<DPDK EAL options> -- <App options>",
+       .epilog = "For more information on EAL options, see the DPDK documentation at: \n"
+                       "\thttps://doc.dpdk.org/guides/" RTE_EXEC_ENV_NAME "_gsg/",

It seems this comment got lost.

Options don't change that often, but I would prefer we point at the right release doc, rather than origin/main.
What do you think of:

@@ -164,11 +164,17 @@ eal_usage(const struct rte_argparse *obj)
},
#define STR_ALIAS STR_ARG

+#if RTE_VER_RELEASE == 99
+#define DOC_SUFFIX "-" RTE_STR(RTE_VER_MAJOR)
+#else
+#define DOC_SUFFIX
+#endif
+
struct rte_argparse eal_argparse = {
.prog_name = "",
.usage = "<DPDK EAL options> -- <App options>", .epilog = "For more information on EAL options, see the DPDK
documentation at: \n"
- "\thttps://doc.dpdk.org/guides/"
RTE_EXEC_ENV_NAME "_gsg/",
+ "\thttps://doc.dpdk.org/guides" DOC_SUFFIX "/"
RTE_EXEC_ENV_NAME "_gsg/",

.exit_on_error = true,
.callback = arg_list_callback,
.print_help = eal_usage,

Signature · 1 line
David Marchand
#79 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

Quoted 15 lines · David Marchand

lib/eal/common/eal_common_options.c line 31

Quoted 9 lines · Bruce Richardson
lib/eal/common/eal_common_options.c +1 -0
index 226acea467..ebb9f7063d 100644
@@ -28,11 +28,13 @@
 #include <rte_version.h>
 #include <rte_devargs.h>
 #include <rte_memcpy.h>
+#include <sys/queue.h>

Nit: system headers are usually going in the first group of includes. This can be fixed when applying.

I'll fix in this version anyway.

Quoted 30 lines

[snip]

lib/eal/common/eal_common_options.c line 171

Quoted 5 lines
lib/eal/common/eal_common_options.c +5 -0
+struct rte_argparse eal_argparse  = {
+       .prog_name = "",
+       .usage = "<DPDK EAL options> -- <App options>",
+       .epilog = "For more information on EAL options, see the DPDK documentation at: \n"
+                       "\thttps://doc.dpdk.org/guides/" RTE_EXEC_ENV_NAME "_gsg/",

It seems this comment got lost.

Options don't change that often, but I would prefer we point at the right release doc, rather than origin/main.
What do you think of:

(quoted diff) +6 -0
@@ -164,11 +164,17 @@ eal_usage(const struct rte_argparse *obj)
 },
 #define STR_ALIAS STR_ARG
 
+#if RTE_VER_RELEASE == 99
+#define DOC_SUFFIX "-" RTE_STR(RTE_VER_MAJOR)
+#else
+#define DOC_SUFFIX
+#endif
+
 struct rte_argparse eal_argparse  = {
        .prog_name = "",
        .usage = "<DPDK EAL options> -- <App options>",
        .epilog = "For more information on EAL options, see the DPDK
Quoted 6 lines

documentation at: \n"
- "\thttps://doc.dpdk.org/guides/"
RTE_EXEC_ENV_NAME "_gsg/",
+ "\thttps://doc.dpdk.org/guides" DOC_SUFFIX "/"
RTE_EXEC_ENV_NAME "_gsg/",

Yes, that can work, though RTE_VER_MAJOR doesn't exist that I can see. Will rework it a bit.

#80 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

Quoted 20 lines · Bruce Richardson
Quoted 20 lines

It seems this comment got lost.

Options don't change that often, but I would prefer we point at the right release doc, rather than origin/main.
What do you think of:

(quoted diff) +6 -0
@@ -164,11 +164,17 @@ eal_usage(const struct rte_argparse *obj)
 },
 #define STR_ALIAS STR_ARG
 
+#if RTE_VER_RELEASE == 99
+#define DOC_SUFFIX "-" RTE_STR(RTE_VER_MAJOR)
+#else
+#define DOC_SUFFIX
+#endif
+
 struct rte_argparse eal_argparse  = {
        .prog_name = "",
        .usage = "<DPDK EAL options> -- <App options>",
        .epilog = "For more information on EAL options, see the DPDK
Quoted 8 lines
Quoted 6 lines

documentation at: \n"
- "\thttps://doc.dpdk.org/guides/"
RTE_EXEC_ENV_NAME "_gsg/",
+ "\thttps://doc.dpdk.org/guides" DOC_SUFFIX "/"
RTE_EXEC_ENV_NAME "_gsg/",

Yes, that can work, though RTE_VER_MAJOR doesn't exist that I can see. Will rework it a bit.

Ah sorry, it was in my previous comment:
https://inbox.dpdk.org/dev/CAJFAV8y5_O3T6hLbZov0LqhXyAu2s_n0P3C3Y+WSGVUjd8gbtg@mail.gmail.com/

Signature · 1 line
David Marchand
#81 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

Quoted 31 lines · David Marchand
Quoted 20 lines · Bruce Richardson
Quoted 20 lines

It seems this comment got lost.

Options don't change that often, but I would prefer we point at the right release doc, rather than origin/main.
What do you think of:

(quoted diff) +6 -0
@@ -164,11 +164,17 @@ eal_usage(const struct rte_argparse *obj)
 },
 #define STR_ALIAS STR_ARG
 
+#if RTE_VER_RELEASE == 99
+#define DOC_SUFFIX "-" RTE_STR(RTE_VER_MAJOR)
+#else
+#define DOC_SUFFIX
+#endif
+
 struct rte_argparse eal_argparse  = {
        .prog_name = "",
        .usage = "<DPDK EAL options> -- <App options>",
        .epilog = "For more information on EAL options, see the DPDK
Quoted 8 lines
Quoted 6 lines

documentation at: \n"
- "\thttps://doc.dpdk.org/guides/"
RTE_EXEC_ENV_NAME "_gsg/",
+ "\thttps://doc.dpdk.org/guides" DOC_SUFFIX "/"
RTE_EXEC_ENV_NAME "_gsg/",

Yes, that can work, though RTE_VER_MAJOR doesn't exist that I can see. Will rework it a bit.

Quoted 3 lines

Ah sorry, it was in my previous comment:
https://inbox.dpdk.org/dev/CAJFAV8y5_O3T6hLbZov0LqhXyAu2s_n0P3C3Y+WSGVUjd8gbtg@mail.gmail.com/

Ah, ok, sorry I missed the comment the first time. I've implemented this without RTE_MAJOR for now anyway.

/Bruce

#82 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

In reply to Bruce Richardson
Quoted 8 lines · Bruce Richardson
lib/eal/common/eal_option_list.h new file +8 -0
+/*
+ * list of EAL arguments as struct rte_argparse_arg.
+ * Format of each entry: long name, short name, help string, struct member name.
+ */
+/* (Alphabetical) List of common options first */
+LIST_ARG("--allow", "-a", "Add device to allow-list, causing DPDK to only use specified devices", allow)
+STR_ARG("--base-virtaddr", NULL, "Base virtual address to reserve memory", base_virtaddr)
+LIST_ARG("--block", "-b", "Add device to block-list, preventing DPDK from using the device", block)

lib/eal/common/eal_option_list.h line 47

Quoted 10 lines
lib/eal/common/eal_option_list.h new file +10 -0
+STR_ARG("--coremask", "-c", "Hexadecimal bitmask of cores to use", coremask)
+LIST_ARG("--driver-path", "-d", "Path to external driver shared object, or directory of drivers", driver_path)
+STR_ARG("--force-max-simd-bitwidth", NULL, "Set max SIMD bitwidth to use in vector code paths", force_max_simd_bitwidth)
+OPT_STR_ARG("--huge-unlink", NULL, "Unlink hugetlbfs files on exit (existing|always|never)", huge_unlink)
+BOOL_ARG("--in-memory", NULL, "DPDK should not create shared mmap files in filesystem  (disables secondary process support)", in_memory)
+STR_ARG("--iova-mode", NULL, "IOVA mapping mode, physical (pa)/virtual (va)", iova_mode)
+STR_ARG("--lcores", "-l", "List of CPU cores to use", lcores)
+BOOL_ARG("--legacy-mem", NULL, "Enable legacy memory behavior", legacy_mem)
+OPT_STR_ARG("--log-color", NULL, "Enable/disable color in log output", log_color)
+STR_ARG("--log-level", NULL, "Log level for loggers; use log-level=help for list of log types and levels", log_level)

Previously, we could have multiple --log-level options. While here, I think we will keep only the last value.

Should it be a LIST_ARG?

Quoted 14 lines
lib/eal/common/eal_option_list.h new file +14 -0
+OPT_STR_ARG("--log-timestamp", NULL, "Enable/disable timestamp in log output", log_timestamp)
+STR_ARG("--main-lcore", NULL, "Select which core to use for the main thread", main_lcore)
+STR_ARG("--mbuf-pool-ops-name", NULL, "User defined mbuf default pool ops name", mbuf_pool_ops_name)
+STR_ARG("--memory-channels", "-n", "Number of memory channels per socket", memory_channels)
+STR_ARG("--memory-ranks", "-r", "Force number of memory ranks (don't detect)", memory_ranks)
+STR_ARG("--memory-size", "-m", "Total size of memory to allocate initially", memory_size)
+BOOL_ARG("--no-hpet", NULL, "Disable HPET timer", no_hpet)
+BOOL_ARG("--no-huge", NULL, "Disable hugetlbfs support", no_huge)
+BOOL_ARG("--no-pci", NULL, "Disable all PCI devices", no_pci)
+BOOL_ARG("--no-shconf", NULL, "Disable shared config file generation", no_shconf)
+BOOL_ARG("--no-telemetry", NULL, "Disable telemetry", no_telemetry)
+STR_ARG("--proc-type", NULL, "Type of process (primary|secondary|auto)", proc_type)
+STR_ARG("--service-corelist", "-S", "List of cores to use for service threads", service_corelist)
+STR_ARG("--service-coremask", "-s", "Hexadecimal bitmask of cores to use for service threads", service_coremask)

lib/eal/common/eal_option_list.h line 71

Quoted 10 lines
lib/eal/common/eal_option_list.h new file +10 -0
+BOOL_ARG("--single-file-segments", NULL, "Store all pages within single files (per-page-size, per-node)", single_file_segments)
+BOOL_ARG("--telemetry", NULL, "Enable telemetry", telemetry)
+LIST_ARG("--vdev", NULL, "Add a virtual device to the system; format=<driver><id>[,key=val,...]", vdev)
+BOOL_ARG("--vmware-tsc-map", NULL, "Use VMware TSC mapping instead of native RDTSC", vmware_tsc_map)
+BOOL_ARG("--version", "-v", "Show version", version)
+
+#if defined(INCLUDE_ALL_ARG) || !defined(RTE_EXEC_ENV_WINDOWS)
+/* Linux and FreeBSD options*/
+OPT_STR_ARG("--syslog", NULL, "Log to syslog (and optionally set facility)", syslog)
+STR_ARG("--trace", NULL, "Enable trace based on regular expression trace name", trace)

Same comment for --trace.

Quoted 19 lines
lib/eal/common/eal_option_list.h new file +19 -0
+STR_ARG("--trace-bufsz", NULL, "Trace buffer size", trace_bufsz)
+STR_ARG("--trace-dir", NULL, "Trace directory", trace_dir)
+STR_ARG("--trace-mode", NULL, "Trace mode", trace_mode)
+#endif
+
+#if defined(INCLUDE_ALL_ARG) || defined(RTE_EXEC_ENV_LINUX)
+/* Linux-only options */
+BOOL_ARG("--create-uio-dev", NULL, "Create /dev/uioX devices", create_uio_dev)
+STR_ARG("--file-prefix", NULL, "Base filename of hugetlbfs files", file_prefix)
+STR_ARG("--huge-dir", NULL, "Directory for hugepage files", huge_dir)
+OPT_STR_ARG("--huge-worker-stack", NULL, "Allocate worker thread stacks from hugepage memory, with optional size (kB)", huge_worker_stack)
+BOOL_ARG("--match-allocations", NULL, "Free hugepages exactly as allocated", match_allocations)
+STR_ARG("--numa-mem", NULL, "Memory to allocate on NUMA nodes (comma separated values)", numa_mem)
+STR_ARG("--numa-limit", NULL, "Limit memory allocation on NUMA nodes (comma separated values)", numa_limit)
+STR_ALIAS("--socket-mem", NULL, "Alias for --numa-mem", numa_mem)
+STR_ALIAS("--socket-limit", NULL, "Alias for --numa-limit", numa_limit)
+STR_ARG("--vfio-intr", NULL, "VFIO interrupt mode (legacy|msi|msix)", vfio_intr)
+STR_ARG("--vfio-vf-token", NULL, "VF token (UUID) shared between SR-IOV PF and VFs", vfio_vf_token)
+#endif
Signature · 1 line
David Marchand
#83 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

Quoted 24 lines · David Marchand
Quoted 8 lines · Bruce Richardson
lib/eal/common/eal_option_list.h new file +8 -0
+/*
+ * list of EAL arguments as struct rte_argparse_arg.
+ * Format of each entry: long name, short name, help string, struct member name.
+ */
+/* (Alphabetical) List of common options first */
+LIST_ARG("--allow", "-a", "Add device to allow-list, causing DPDK to only use specified devices", allow)
+STR_ARG("--base-virtaddr", NULL, "Base virtual address to reserve memory", base_virtaddr)
+LIST_ARG("--block", "-b", "Add device to block-list, preventing DPDK from using the device", block)

lib/eal/common/eal_option_list.h line 47

Quoted 10 lines
lib/eal/common/eal_option_list.h new file +10 -0
+STR_ARG("--coremask", "-c", "Hexadecimal bitmask of cores to use", coremask)
+LIST_ARG("--driver-path", "-d", "Path to external driver shared object, or directory of drivers", driver_path)
+STR_ARG("--force-max-simd-bitwidth", NULL, "Set max SIMD bitwidth to use in vector code paths", force_max_simd_bitwidth)
+OPT_STR_ARG("--huge-unlink", NULL, "Unlink hugetlbfs files on exit (existing|always|never)", huge_unlink)
+BOOL_ARG("--in-memory", NULL, "DPDK should not create shared mmap files in filesystem  (disables secondary process support)", in_memory)
+STR_ARG("--iova-mode", NULL, "IOVA mapping mode, physical (pa)/virtual (va)", iova_mode)
+STR_ARG("--lcores", "-l", "List of CPU cores to use", lcores)
+BOOL_ARG("--legacy-mem", NULL, "Enable legacy memory behavior", legacy_mem)
+OPT_STR_ARG("--log-color", NULL, "Enable/disable color in log output", log_color)
+STR_ARG("--log-level", NULL, "Log level for loggers; use log-level=help for list of log types and levels", log_level)

Previously, we could have multiple --log-level options. While here, I think we will keep only the last value.

Quoted 2 lines

Should it be a LIST_ARG?

Never thought of that. Will take a look. However, am I right in thinking that within a single log-level arg, you can have multiple level specifiers for different components?

Quoted 18 lines
Quoted 18 lines
lib/eal/common/eal_option_list.h new file +18 -0
+OPT_STR_ARG("--log-timestamp", NULL, "Enable/disable timestamp in log output", log_timestamp)
+STR_ARG("--main-lcore", NULL, "Select which core to use for the main thread", main_lcore)
+STR_ARG("--mbuf-pool-ops-name", NULL, "User defined mbuf default pool ops name", mbuf_pool_ops_name)
+STR_ARG("--memory-channels", "-n", "Number of memory channels per socket", memory_channels)
+STR_ARG("--memory-ranks", "-r", "Force number of memory ranks (don't detect)", memory_ranks)
+STR_ARG("--memory-size", "-m", "Total size of memory to allocate initially", memory_size)
+BOOL_ARG("--no-hpet", NULL, "Disable HPET timer", no_hpet)
+BOOL_ARG("--no-huge", NULL, "Disable hugetlbfs support", no_huge)
+BOOL_ARG("--no-pci", NULL, "Disable all PCI devices", no_pci)
+BOOL_ARG("--no-shconf", NULL, "Disable shared config file generation", no_shconf)
+BOOL_ARG("--no-telemetry", NULL, "Disable telemetry", no_telemetry)
+STR_ARG("--proc-type", NULL, "Type of process (primary|secondary|auto)", proc_type)
+STR_ARG("--service-corelist", "-S", "List of cores to use for service threads", service_corelist)
+STR_ARG("--service-coremask", "-s", "Hexadecimal bitmask of cores to use for service threads", service_coremask)
+BOOL_ARG("--single-file-segments", NULL, "Store all pages within single files (per-page-size, per-node)", single_file_segments)
+BOOL_ARG("--telemetry", NULL, "Enable telemetry", telemetry)
+LIST_ARG("--vdev", NULL, "Add a virtual device to the system; format=<driver><id>[,key=val,...]", vdev)
+BOOL_ARG("--vmware-tsc-map", NULL, "Use VMware TSC mapping instead of native RDTSC", vmware_tsc_map)
Quoted 10 lines

lib/eal/common/eal_option_list.h line 71

Quoted 6 lines
lib/eal/common/eal_option_list.h new file +6 -0
+BOOL_ARG("--version", "-v", "Show version", version)
+
+#if defined(INCLUDE_ALL_ARG) || !defined(RTE_EXEC_ENV_WINDOWS)
+/* Linux and FreeBSD options*/
+OPT_STR_ARG("--syslog", NULL, "Log to syslog (and optionally set facility)", syslog)
+STR_ARG("--trace", NULL, "Enable trace based on regular expression trace name", trace)

Same comment for --trace.

Ack.

Quoted 24 lines
Quoted 19 lines
lib/eal/common/eal_option_list.h new file +19 -0
+STR_ARG("--trace-bufsz", NULL, "Trace buffer size", trace_bufsz)
+STR_ARG("--trace-dir", NULL, "Trace directory", trace_dir)
+STR_ARG("--trace-mode", NULL, "Trace mode", trace_mode)
+#endif
+
+#if defined(INCLUDE_ALL_ARG) || defined(RTE_EXEC_ENV_LINUX)
+/* Linux-only options */
+BOOL_ARG("--create-uio-dev", NULL, "Create /dev/uioX devices", create_uio_dev)
+STR_ARG("--file-prefix", NULL, "Base filename of hugetlbfs files", file_prefix)
+STR_ARG("--huge-dir", NULL, "Directory for hugepage files", huge_dir)
+OPT_STR_ARG("--huge-worker-stack", NULL, "Allocate worker thread stacks from hugepage memory, with optional size (kB)", huge_worker_stack)
+BOOL_ARG("--match-allocations", NULL, "Free hugepages exactly as allocated", match_allocations)
+STR_ARG("--numa-mem", NULL, "Memory to allocate on NUMA nodes (comma separated values)", numa_mem)
+STR_ARG("--numa-limit", NULL, "Limit memory allocation on NUMA nodes (comma separated values)", numa_limit)
+STR_ALIAS("--socket-mem", NULL, "Alias for --numa-mem", numa_mem)
+STR_ALIAS("--socket-limit", NULL, "Alias for --numa-limit", numa_limit)
+STR_ARG("--vfio-intr", NULL, "VFIO interrupt mode (legacy|msi|msix)", vfio_intr)
+STR_ARG("--vfio-vf-token", NULL, "VF token (UUID) shared between SR-IOV PF and VFs", vfio_vf_token)
+#endif
Signature · 1 line
David Marchand
#84 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

Quoted 26 lines · Bruce Richardson
Quoted 24 lines · David Marchand
Quoted 8 lines · Bruce Richardson
lib/eal/common/eal_option_list.h new file +8 -0
+/*
+ * list of EAL arguments as struct rte_argparse_arg.
+ * Format of each entry: long name, short name, help string, struct member name.
+ */
+/* (Alphabetical) List of common options first */
+LIST_ARG("--allow", "-a", "Add device to allow-list, causing DPDK to only use specified devices", allow)
+STR_ARG("--base-virtaddr", NULL, "Base virtual address to reserve memory", base_virtaddr)
+LIST_ARG("--block", "-b", "Add device to block-list, preventing DPDK from using the device", block)

lib/eal/common/eal_option_list.h line 47

Quoted 10 lines
lib/eal/common/eal_option_list.h new file +10 -0
+STR_ARG("--coremask", "-c", "Hexadecimal bitmask of cores to use", coremask)
+LIST_ARG("--driver-path", "-d", "Path to external driver shared object, or directory of drivers", driver_path)
+STR_ARG("--force-max-simd-bitwidth", NULL, "Set max SIMD bitwidth to use in vector code paths", force_max_simd_bitwidth)
+OPT_STR_ARG("--huge-unlink", NULL, "Unlink hugetlbfs files on exit (existing|always|never)", huge_unlink)
+BOOL_ARG("--in-memory", NULL, "DPDK should not create shared mmap files in filesystem  (disables secondary process support)", in_memory)
+STR_ARG("--iova-mode", NULL, "IOVA mapping mode, physical (pa)/virtual (va)", iova_mode)
+STR_ARG("--lcores", "-l", "List of CPU cores to use", lcores)
+BOOL_ARG("--legacy-mem", NULL, "Enable legacy memory behavior", legacy_mem)
+OPT_STR_ARG("--log-color", NULL, "Enable/disable color in log output", log_color)
+STR_ARG("--log-level", NULL, "Log level for loggers; use log-level=help for list of log types and levels", log_level)

Previously, we could have multiple --log-level options. While here, I think we will keep only the last value.

Quoted 6 lines
Quoted 2 lines

Should it be a LIST_ARG?

Never thought of that. Will take a look. However, am I right in thinking that within a single log-level arg, you can have multiple level specifiers for different components?

All I see in eal_parse_log_level() is a difference in treatment between regex, and pattern:.
Am I missing something?

Signature · 1 line
David Marchand
#85 lore raw

Re: [PATCH v7 06/13] eal: define the EAL parameters in argparse format

In reply to Bruce Richardson
Quoted 12 lines · On Wed, 23 Jul 2025 17:20:04 +0100 Bruce Richardson…

Create eal_option_list.h, containing all the possible EAL parameters, and basic info about them, such as type, whether they take a parameter or not. Each entry is defined using a macro, which will be then interpreted when the file is included.

First time this header in included in the eal_common_options.c file, the macros are defined in such a way as to define field elements for an "eal_init_args" structure, where each value is either a string type, if it takes a parameter, or boolean type if it doesn't. For those elements that take multiple values, i.e. are passed multiple times, we put them in a TAILQ.

Quoted 8 lines

The second time of inclusion, the macros are defined so as to define the arguments in an rte_argparse structure for EAL. For the basic string and boolean types, we just store the values in the appropriate field in the previous defined "eal_init_args" structure. For the list elements, we use the argparse callback to process those elements, adding them to the TAILQ as they are encountered.

This patch introduces another case of shadowed arguments.

Suggest renaming the global args variable.

I do test builds with -Wshadow

[50/3660] Compiling C object lib/librte_eal.a.p/eal_common_eal_common_options.c.o ../lib/eal/common/eal_common_options.c: In function ‘handle_eal_info_request’:
../lib/eal/common/eal_common_options.c:342:16: warning: declaration of ‘args’ shadows a global declaration [-Wshadow]
342 | char **args;
| ^~~~
../lib/eal/common/eal_common_options.c:87:22: note: shadowed declaration is here
87 | struct eal_init_args args = {
| ^~~~

#86 lore raw

PATCH v7 7/13 eal: gather EAL args before processing

In reply to Bruce Richardson

DPDK traditionally has iterated through all args and processed them as they appear in the commandline. The arg processing logic can be simplified if instead we initially gather all arguments into a structure which is then processed with the arguments dealt with in a fixed/known order.

---
 lib/eal/common/eal_common_options.c | 878 ++++++++++++++--------------
 lib/eal/common/eal_options.h        |  10 +-
 lib/eal/common/eal_private.h        |  11 +
 lib/eal/freebsd/eal.c               | 164 +-----
 lib/eal/linux/eal.c                 | 379 +-----------
 lib/eal/windows/eal.c               | 113 +---
 6 files changed, 482 insertions(+), 1073 deletions(-)
lib/eal/common/eal_common_options.c +423 -455
index ebb9f7063d..aea2c813ed 100644
@@ -46,8 +46,7 @@
 #endif
 
 #define BITS_PER_HEX 4
-#define LCORE_OPT_LST 1
-#define LCORE_OPT_MSK 2
+#define NUMA_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
 
 /* Allow the application to print its usage message too if set */
 static rte_usage_hook_t rte_application_usage_hook;
@@ -179,80 +178,31 @@ struct rte_argparse eal_argparse  = {
 	}
 };
 
-const char
-eal_short_options[] =
-	"a:" /* allow */
-	"b:" /* block */
-	"c:" /* coremask */
-	"s:" /* service coremask */
-	"d:" /* driver */
-	"h"  /* help */
-	"l:" /* corelist */
-	"S:" /* service corelist */
-	"m:" /* memory size */
-	"n:" /* memory channels */
-	"r:" /* memory ranks */
-	"v"  /* version */
-	;
-
-const struct option
-eal_long_options[] = {
-	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
-	{OPT_COREMASK,          1, NULL, OPT_COREMASK_NUM        },
-	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
-	{OPT_DRIVER_PATH,       1, NULL, OPT_DRIVER_PATH_NUM     },
-	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
-	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
-	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
-	{OPT_HUGE_UNLINK,       2, NULL, OPT_HUGE_UNLINK_NUM      },
-	{OPT_IOVA_MODE,	        1, NULL, OPT_IOVA_MODE_NUM        },
-	{OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
-	{OPT_LOG_COLOR,		2, NULL, OPT_LOG_COLOR_NUM	  },
-	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
-	{OPT_LOG_TIMESTAMP,     2, NULL, OPT_LOG_TIMESTAMP_NUM    },
-	{OPT_MEMORY_CHANNELS,   1, NULL, OPT_MEMORY_CHANNELS_NUM },
-	{OPT_MEMORY_RANKS,      1, NULL, OPT_MEMORY_RANKS_NUM    },
-	{OPT_MEMORY_SIZE,       1, NULL, OPT_MEMORY_SIZE_NUM     },
-	{OPT_SERVICE_CORELIST,  1, NULL, OPT_SERVICE_CORELIST_NUM },
-	{OPT_SERVICE_COREMASK,  1, NULL, OPT_SERVICE_COREMASK_NUM },
-	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
-	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
-	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
-	{OPT_TRACE_MODE,        1, NULL, OPT_TRACE_MODE_NUM       },
-	{OPT_MAIN_LCORE,        1, NULL, OPT_MAIN_LCORE_NUM       },
-	{OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
-	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
-	{OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
-	{OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
-	{OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
-	{OPT_IN_MEMORY,         0, NULL, OPT_IN_MEMORY_NUM        },
-	{OPT_DEV_BLOCK,         1, NULL, OPT_DEV_BLOCK_NUM        },
-	{OPT_DEV_ALLOW,		1, NULL, OPT_DEV_ALLOW_NUM	  },
-	{OPT_PROC_TYPE,         1, NULL, OPT_PROC_TYPE_NUM        },
-	/* socket-mem/socket-limit are kept for backwards compatibility */
-	{OPT_SOCKET_MEM,        1, NULL, OPT_NUMA_MEM_NUM         },
-	{OPT_SOCKET_LIMIT,      1, NULL, OPT_NUMA_LIMIT_NUM       },
-	{OPT_NUMA_MEM,          1, NULL, OPT_NUMA_MEM_NUM         },
-	{OPT_NUMA_LIMIT,        1, NULL, OPT_NUMA_LIMIT_NUM       },
-#ifndef RTE_EXEC_ENV_WINDOWS
-	{OPT_SYSLOG,            2, NULL, OPT_SYSLOG_NUM           },
-#endif
-	{OPT_VDEV,              1, NULL, OPT_VDEV_NUM             },
-	{OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
-	{OPT_VFIO_VF_TOKEN,     1, NULL, OPT_VFIO_VF_TOKEN_NUM    },
-	{OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
-	{OPT_LEGACY_MEM,        0, NULL, OPT_LEGACY_MEM_NUM       },
-	{OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
-	{OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
-	{OPT_TELEMETRY,         0, NULL, OPT_TELEMETRY_NUM        },
-	{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_VERSION,           0, NULL, OPT_VERSION_NUM         },
-
-
-	{0,                     0, NULL, 0                        }
-};
+/* function to call into argparse library to parse the passed argc/argv parameters
+ * to the eal_init_args structure.
+ */
+int
+eal_collate_args(int argc, char **argv)
+{
+	if (argc < 1 || argv == NULL)
+		return -EINVAL;
+
+	/* initialize the list of arguments */
+	memset(&args, 0, sizeof(args));
+	TAILQ_INIT(&args.allow);
+	TAILQ_INIT(&args.block);
+	TAILQ_INIT(&args.driver_path);
+	TAILQ_INIT(&args.vdev);
+
+	/* parse the arguments */
+	eal_argparse.prog_name = argv[0];
+	int retval = rte_argparse_parse(&eal_argparse, argc, argv);
+	if (retval < 0)
+		return retval;
+
+	argv[retval - 1] = argv[0];
+	return retval - 1;
+}
 
 TAILQ_HEAD(shared_driver_list, shared_driver);
 
@@ -294,7 +244,6 @@ static struct device_option_list devopt_list =
 TAILQ_HEAD_INITIALIZER(devopt_list);
 
 static int main_lcore_parsed;
-static int mem_parsed;
 static int core_parsed;
 
 /* Returns rte_usage_hook_t */
@@ -318,7 +267,12 @@ rte_set_application_usage_hook(rte_usage_hook_t usage_func)
 	return old_func;
 }
 
-#ifndef RTE_EXEC_ENV_WINDOWS
+#ifdef RTE_EXEC_ENV_WINDOWS
+
+int
+eal_save_args(__rte_unused int argc, __rte_unused char **argv) { return 0; }
+
+#else /* RTE_EXEC_ENV_WINDOWS */
 static char **eal_args;
 static char **eal_app_args;
 
@@ -406,7 +360,7 @@ eal_save_args(int argc, char **argv)
 	eal_args = NULL;
 	return -1;
 }
-#endif
+#endif /* !RTE_EXEC_ENV_WINDOWS */
 
 static int
 eal_option_device_add(enum rte_devtype type, const char *optarg)
@@ -829,17 +783,6 @@ eal_parse_service_coremask(const char *coremask)
 	return 0;
 }
 
-static int
-eal_service_cores_parsed(void)
-{
-	int idx;
-	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		if (lcore_config[idx].core_role == ROLE_SERVICE)
-			return 1;
-	}
-	return 0;
-}
-
 static int
 update_lcore_config(int *cores)
 {
@@ -1666,361 +1609,486 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out)
 	return -1;
 }
 
-bool
-eal_option_is_log(int opt)
+/* Parse all arguments looking for log related ones */
+int
+eal_parse_log_options(void)
 {
-	switch (opt) {
-	case OPT_LOG_COLOR_NUM:
-	case OPT_LOG_LEVEL_NUM:
-	case OPT_LOG_TIMESTAMP_NUM:
-	case OPT_SYSLOG_NUM:
-		return true;
-	default:
-		return false;
+	if (args.log_level != NULL) {
+		if (eal_parse_log_level(args.log_level) < 0) {
+			EAL_LOG(ERR, "invalid log-level parameter");
+			return -1;
+		}
+	}
+	if (args.log_color != NULL) {
+		/* if value is 1, no argument specified, so pass NULL */
+		if (args.log_color == (void *)1)
+			args.log_color = NULL;
+		if (eal_log_color(args.log_color) < 0) {
+			EAL_LOG(ERR, "invalid log-color parameter");
+			return -1;
+		}
+	}
+	if (args.log_timestamp != NULL) {
+		/* similarly log_timestamp may be 1 */
+		if (args.log_timestamp == (void *)1)
+			args.log_timestamp = NULL;
+		if (eal_log_timestamp(args.log_timestamp) < 0) {
+			EAL_LOG(ERR, "invalid log-timestamp parameter");
+			return -1;
+		}
+	}
+	if (args.syslog != NULL) {
+#ifdef RTE_EXEC_ENV_WINDOWS
+		EAL_LOG(WARNING, "syslog is not supported on Windows, ignoring parameter");
+#else
+		/* also syslog parameter may be 1 */
+		if (args.syslog == (void *)1)
+			args.syslog = NULL;
+		if (eal_log_syslog(args.syslog) < 0) {
+			EAL_LOG(ERR, "invalid syslog parameter");
+			return -1;
+		}
+#endif
 	}
+	return 0;
 }
 
-/* Parse all arguments looking for log related ones */
-int
-eal_parse_log_options(int argc, char * const argv[])
+static int
+eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
 {
-	struct internal_config *internal_conf = eal_get_internal_configuration();
-	int option_index, opt;
-	const int old_optind = optind;
-	const int old_optopt = optopt;
-	const int old_opterr = opterr;
-	char *old_optarg = optarg;
-#ifdef RTE_EXEC_ENV_FREEBSD
-	const int old_optreset = optreset;
-	optreset = 1;
-#endif
+	char *arg[RTE_MAX_NUMA_NODES];
+	char *end;
+	int arg_num, i, len;
 
-	optind = 1;
-	opterr = 0;
+	len = strnlen(strval, NUMA_MEM_STRLEN);
+	if (len == NUMA_MEM_STRLEN) {
+		EAL_LOG(ERR, "--numa-mem/--socket-mem parameter is too long");
+		return -1;
+	}
 
-	while ((opt = getopt_long(argc, argv, eal_short_options,
-				  eal_long_options, &option_index)) != EOF) {
+	/* all other error cases will be caught later */
+	if (!isdigit(strval[len-1]))
+		return -1;
 
-		if (!eal_option_is_log(opt))
-			continue;
+	/* split the optarg into separate socket values */
+	arg_num = rte_strsplit(strval, len,
+			arg, RTE_MAX_NUMA_NODES, ',');
 
-		if (eal_parse_common_option(opt, optarg, internal_conf) < 0)
+	/* if split failed, or 0 arguments */
+	if (arg_num <= 0)
+		return -1;
+
+	/* parse each defined socket option */
+	errno = 0;
+	for (i = 0; i < arg_num; i++) {
+		uint64_t val;
+		end = NULL;
+		val = strtoull(arg[i], &end, 10);
+
+		/* check for invalid input */
+		if ((errno != 0)  ||
+				(arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
 			return -1;
+		val <<= 20;
+		socket_arg[i] = val;
 	}
 
-	/* restore getopt lib */
-	optind = old_optind;
-	optopt = old_optopt;
-	optarg = old_optarg;
-	opterr = old_opterr;
-#ifdef RTE_EXEC_ENV_FREEBSD
-	optreset = old_optreset;
+	return 0;
+}
+
+static int
+eal_parse_vfio_intr(const char *mode)
+{
+	struct internal_config *internal_conf =
+		eal_get_internal_configuration();
+	static struct {
+		const char *name;
+		enum rte_intr_mode value;
+	} map[] = {
+		{ "legacy", RTE_INTR_MODE_LEGACY },
+		{ "msi", RTE_INTR_MODE_MSI },
+		{ "msix", RTE_INTR_MODE_MSIX },
+	};
+
+	for (size_t i = 0; i < RTE_DIM(map); i++) {
+		if (!strcmp(mode, map[i].name)) {
+			internal_conf->vfio_intr_mode = map[i].value;
+			return 0;
+		}
+	}
+	return -1;
+}
+
+static int
+eal_parse_vfio_vf_token(const char *vf_token)
+{
+	struct internal_config *cfg = eal_get_internal_configuration();
+	rte_uuid_t uuid;
+
+	if (!rte_uuid_parse(vf_token, uuid)) {
+		rte_uuid_copy(cfg->vfio_vf_token, uuid);
+		return 0;
+	}
+
+	return -1;
+}
+
+static int
+eal_parse_huge_worker_stack(const char *arg)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	EAL_LOG(WARNING, "Cannot set worker stack size on Windows, parameter ignored");
+	RTE_SET_USED(arg);
+#else
+	struct internal_config *cfg = eal_get_internal_configuration();
+
+	if (arg == NULL || arg[0] == '\0') {
+		pthread_attr_t attr;
+		int ret;
+
+		if (pthread_attr_init(&attr) != 0) {
+			EAL_LOG(ERR, "Could not retrieve default stack size");
+			return -1;
+		}
+		ret = pthread_attr_getstacksize(&attr, &cfg->huge_worker_stack_size);
+		pthread_attr_destroy(&attr);
+		if (ret != 0) {
+			EAL_LOG(ERR, "Could not retrieve default stack size");
+			return -1;
+		}
+	} else {
+		unsigned long stack_size;
+		char *end;
+
+		errno = 0;
+		stack_size = strtoul(arg, &end, 10);
+		if (errno || end == NULL || stack_size == 0 ||
+				stack_size >= (size_t)-1 / 1024)
+			return -1;
+
+		cfg->huge_worker_stack_size = stack_size * 1024;
+	}
+
+	EAL_LOG(DEBUG, "Each worker thread will use %zu kB of DPDK memory as stack",
+		cfg->huge_worker_stack_size / 1024);
 #endif
 	return 0;
 }
 
+/* Parse the arguments given in the command line of the application */
 int
-eal_parse_common_option(int opt, const char *optarg,
-			struct internal_config *conf)
+eal_parse_args(void)
 {
-	static int b_used;
-	static int a_used;
-
-	switch (opt) {
-	case 'b':
-		if (a_used)
-			goto ba_conflict;
-		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0)
+	struct internal_config *int_cfg = eal_get_internal_configuration();
+	struct arg_list_elem *arg;
+
+	/* check for conflicting options */
+	/* both -a and -b cannot be used together (one list must be empty at least) */
+	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
+		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
+		return -1;
+	}
+	/* both -l and -c cannot be used at the same time */
+	if (args.coremask != NULL && args.lcores != NULL) {
+		EAL_LOG(ERR, "Options coremask (-c) and core list (-l) can't be used at the same time");
+		return -1;
+	}
+	/* both -s and -S cannot be used at the same time */
+	if (args.service_coremask != NULL && args.service_corelist != NULL) {
+		EAL_LOG(ERR, "Options service coremask (-s) and service core list (-S) can't be used at the same time");
+		return -1;
+	}
+	/* can't have both telemetry and no-telemetry */
+	if (args.no_telemetry && args.telemetry) {
+		EAL_LOG(ERR, "Options telemetry and no-telemetry can't be used at the same time");
+		return -1;
+	}
+	/* can't have both -m and --socket-mem */
+	if (args.memory_size != NULL && args.numa_mem != NULL) {
+		EAL_LOG(ERR, "Options -m and --socket-mem can't be used at the same time");
+		return -1;
+	}
+
+	/* parse options */
+	/* print version before anything else */
+	if (args.version) {
+		/* since message is explicitly requested by user, we write message
+		 * at highest log level so it can always be seen even if info or
+		 * warning messages are disabled
+		 */
+		EAL_LOG(CRIT, "RTE Version: '%s'", rte_version());
+	}
+
+	/* parse the process type */
+	if (args.proc_type != NULL) {
+		int_cfg->process_type = eal_parse_proc_type(args.proc_type);
+		if (int_cfg->process_type == RTE_PROC_INVALID) {
+			EAL_LOG(ERR, "invalid process type: %s", args.proc_type);
 			return -1;
-		b_used = 1;
-		break;
+		}
+	}
 
-	case 'a':
-		if (b_used)
-			goto ba_conflict;
-		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0)
+	/* device -a/-b/-vdev options*/
+	TAILQ_FOREACH(arg, &args.allow, next)
+		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, arg->arg) < 0)
 			return -1;
-		a_used = 1;
-		break;
-	/* coremask */
-	case 'c': {
+	TAILQ_FOREACH(arg, &args.block, next)
+		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, arg->arg) < 0)
+			return -1;
+	TAILQ_FOREACH(arg, &args.vdev, next)
+		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL, arg->arg) < 0)
+			return -1;
+	/* driver loading options */
+	TAILQ_FOREACH(arg, &args.driver_path, next)
+		if (eal_plugin_add(arg->arg) < 0)
+			return -1;
+
+	/* parse the coremask /core-list */
+	if (args.coremask != NULL) {
 		int lcore_indexes[RTE_MAX_LCORE];
 
-		if (eal_service_cores_parsed())
-			EAL_LOG(WARNING,
-				"Service cores parsed before dataplane cores. Please ensure -c is before -s or -S");
-		if (rte_eal_parse_coremask(optarg, lcore_indexes) < 0) {
+		if (rte_eal_parse_coremask(args.coremask, lcore_indexes) < 0) {
 			EAL_LOG(ERR, "invalid coremask syntax");
 			return -1;
 		}
 		if (update_lcore_config(lcore_indexes) < 0) {
 			char *available = available_cores();
 
-			EAL_LOG(ERR,
-				"invalid coremask, please check specified cores are part of %s",
-				available);
+			EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
+					args.coremask, available);
 			free(available);
 			return -1;
 		}
-
-		if (core_parsed) {
-			if (core_parsed == LCORE_OPT_MSK)
-				EAL_LOG(ERR, "Option '-c' passed multiple times to EAL");
-			else
-				EAL_LOG(ERR, "Option -c is ignored, because option -l/--lcores used");
+		core_parsed = 1;
+	} else if (args.lcores != NULL) {
+		if (eal_parse_lcores(args.lcores) < 0) {
+			EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
 			return -1;
 		}
-
-		core_parsed = LCORE_OPT_MSK;
-		break;
+		core_parsed = 1;
 	}
-	/* corelist */
-	case 'l': {
-		if (eal_service_cores_parsed())
-			EAL_LOG(WARNING,
-				"Service cores parsed before dataplane cores. Please ensure -l is before -s or -S");
-
-		if (eal_parse_lcores(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for -l/--" OPT_LCORES);
+	if (args.main_lcore != NULL) {
+		if (eal_parse_main_lcore(args.main_lcore) < 0) {
+			EAL_LOG(ERR, "invalid main-lcore parameter");
 			return -1;
 		}
+	}
 
-		if (core_parsed) {
-			if (core_parsed == LCORE_OPT_LST)
-				EAL_LOG(ERR, "Core list option passed multiple times to EAL");
-			else
-				EAL_LOG(ERR, "Option '-l/--lcores' is ignored, because coremask option used");
+	/* service core options */
+	if (args.service_coremask != NULL) {
+		if (eal_parse_service_coremask(args.service_coremask) < 0) {
+			EAL_LOG(ERR, "invalid service coremask: '%s'",
+					args.service_coremask);
 			return -1;
 		}
+	} else if (args.service_corelist != NULL) {
+		if (eal_parse_service_corelist(args.service_corelist) < 0) {
+			EAL_LOG(ERR, "invalid service core list: '%s'",
+					args.service_corelist);
+			return -1;
+		}
+	}
 
-		core_parsed = LCORE_OPT_LST;
-		break;
+	/* memory options */
+	if (args.memory_size != NULL) {
+		int_cfg->memory = atoi(args.memory_size);
+		int_cfg->memory *= 1024ULL;
+		int_cfg->memory *= 1024ULL;
 	}
-	/* service coremask */
-	case 's':
-		if (eal_parse_service_coremask(optarg) < 0) {
-			EAL_LOG(ERR, "invalid service coremask");
+	if (args.memory_channels != NULL) {
+		int_cfg->force_nchannel = atoi(args.memory_channels);
+		if (int_cfg->force_nchannel == 0) {
+			EAL_LOG(ERR, "invalid memory channel parameter");
 			return -1;
 		}
-		break;
-	/* service corelist */
-	case 'S':
-		if (eal_parse_service_corelist(optarg) < 0) {
-			EAL_LOG(ERR, "invalid service core list");
+	}
+	if (args.memory_ranks != NULL) {
+		int_cfg->force_nrank = atoi(args.memory_ranks);
+		if (int_cfg->force_nrank == 0 || int_cfg->force_nrank > 16) {
+			EAL_LOG(ERR, "invalid memory rank parameter");
 			return -1;
 		}
-		break;
-	/* size of memory */
-	case 'm':
-		conf->memory = atoi(optarg);
-		conf->memory *= 1024ULL;
-		conf->memory *= 1024ULL;
-		mem_parsed = 1;
-		break;
-	/* force number of channels */
-	case 'n':
-		conf->force_nchannel = atoi(optarg);
-		if (conf->force_nchannel == 0) {
-			EAL_LOG(ERR, "invalid channel number");
+	}
+	if (args.huge_unlink != NULL) {
+		if (args.huge_unlink == (void *)1)
+			args.huge_unlink = NULL;
+		if (eal_parse_huge_unlink(args.huge_unlink, &int_cfg->hugepage_file) < 0) {
+			EAL_LOG(ERR, "invalid huge-unlink parameter");
 			return -1;
 		}
-		break;
-	/* force number of ranks */
-	case 'r':
-		conf->force_nrank = atoi(optarg);
-		if (conf->force_nrank == 0 ||
-		    conf->force_nrank > 16) {
-			EAL_LOG(ERR, "invalid rank number");
+	}
+	if (args.no_huge) {
+		int_cfg->no_hugetlbfs = 1;
+		/* no-huge is legacy mem */
+		int_cfg->legacy_mem = 1;
+	}
+	if (args.in_memory) {
+		int_cfg->in_memory = 1;
+		/* in-memory is a superset of noshconf and huge-unlink */
+		int_cfg->no_shconf = 1;
+		int_cfg->hugepage_file.unlink_before_mapping = true;
+	}
+	if (args.legacy_mem)
+		int_cfg->legacy_mem = 1;
+	if (args.single_file_segments)
+		int_cfg->single_file_segments = 1;
+	if (args.huge_dir != NULL) {
+		free(int_cfg->hugepage_dir);  /* free old hugepage dir */
+		int_cfg->hugepage_dir = strdup(args.huge_dir);
+		if (int_cfg->hugepage_dir == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for hugepage dir parameter");
 			return -1;
 		}
-		break;
-	/* force loading of external driver */
-	case 'd':
-		if (eal_plugin_add(optarg) == -1)
+	}
+	if (args.file_prefix != NULL) {
+		free(int_cfg->hugefile_prefix);  /* free old file prefix */
+		int_cfg->hugefile_prefix = strdup(args.file_prefix);
+		if (int_cfg->hugefile_prefix == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for file prefix parameter");
 			return -1;
-		break;
-	case 'v':
-		/* since message is explicitly requested by user, we
-		 * write message at highest log level so it can always
-		 * be seen
-		 * even if info or warning messages are disabled */
-		EAL_LOG(CRIT, "RTE Version: '%s'", rte_version());
-		break;
-
-	/* long options */
-	case OPT_HUGE_UNLINK_NUM:
-		if (eal_parse_huge_unlink(optarg, &conf->hugepage_file) < 0) {
-			EAL_LOG(ERR, "invalid --"OPT_HUGE_UNLINK" option");
+		}
+	}
+	if (args.numa_mem != NULL) {
+		if (eal_parse_socket_arg(args.numa_mem, int_cfg->numa_mem) < 0) {
+			EAL_LOG(ERR, "invalid numa-mem parameter: '%s'", args.numa_mem);
 			return -1;
 		}
-		break;
-
-	case OPT_NO_HUGE_NUM:
-		conf->no_hugetlbfs = 1;
-		/* no-huge is legacy mem */
-		conf->legacy_mem = 1;
-		break;
-
-	case OPT_NO_PCI_NUM:
-		conf->no_pci = 1;
-		break;
-
-	case OPT_NO_HPET_NUM:
-		conf->no_hpet = 1;
-		break;
-
-	case OPT_VMWARE_TSC_MAP_NUM:
-		conf->vmware_tsc_map = 1;
-		break;
-
-	case OPT_NO_SHCONF_NUM:
-		conf->no_shconf = 1;
-		break;
-
-	case OPT_IN_MEMORY_NUM:
-		conf->in_memory = 1;
-		/* in-memory is a superset of noshconf and huge-unlink */
-		conf->no_shconf = 1;
-		conf->hugepage_file.unlink_before_mapping = true;
-		break;
-
-	case OPT_PROC_TYPE_NUM:
-		conf->process_type = eal_parse_proc_type(optarg);
-		break;
-
-	case OPT_MAIN_LCORE_NUM:
-		if (eal_parse_main_lcore(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_MAIN_LCORE);
+		int_cfg->force_numa = 1;
+	}
+	if (args.numa_limit != NULL) {
+		if (eal_parse_socket_arg(args.numa_limit, int_cfg->numa_limit) < 0) {
+			EAL_LOG(ERR, "invalid numa-limit parameter: '%s'", args.numa_limit);
 			return -1;
 		}
-		break;
+		int_cfg->force_numa_limits = 1;
+	}
 
-	case OPT_VDEV_NUM:
-		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
-				optarg) < 0) {
+	/* tracing settings, not supported on windows */
+#ifdef RTE_EXEC_ENV_WINDOWS
+	if (args.trace != NULL ||
+			args.trace_dir != NULL ||
+			args.trace_bufsz != NULL ||
+			args.trace_mode != NULL)
+		EAL_LOG(WARNING, "Tracing is not supported on Windows, ignoring tracing parameters");
+#else
+	if (args.trace != NULL) {
+		if (eal_trace_args_save(args.trace) < 0) {
+			EAL_LOG(ERR, "invalid trace parameter, '%s'", args.trace);
 			return -1;
 		}
-		break;
-
-#ifndef RTE_EXEC_ENV_WINDOWS
-	case OPT_SYSLOG_NUM:
-		if (eal_log_syslog(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-					OPT_SYSLOG);
+	}
+	if (args.trace_dir != NULL) {
+		if (eal_trace_dir_args_save(args.trace_dir) < 0) {
+			EAL_LOG(ERR, "invalid trace directory, '%s'", args.trace_dir);
 			return -1;
 		}
-		break;
-#endif
-
-	case OPT_LOG_LEVEL_NUM:
-		if (eal_parse_log_level(optarg) < 0) {
-			EAL_LOG(ERR,
-				"invalid parameters for --"
-				OPT_LOG_LEVEL);
+	}
+	if (args.trace_bufsz != NULL) {
+		if (eal_trace_bufsz_args_save(args.trace_bufsz) < 0) {
+			EAL_LOG(ERR, "invalid trace buffer size, '%s'", args.trace_bufsz);
 			return -1;
 		}
-		break;
-
-	case OPT_LOG_TIMESTAMP_NUM:
-		if (eal_log_timestamp(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_LOG_TIMESTAMP);
+	}
+	if (args.trace_mode != NULL) {
+		if (eal_trace_mode_args_save(args.trace_mode) < 0) {
+			EAL_LOG(ERR, "invalid trace mode, '%s'", args.trace_mode);
 			return -1;
 		}
-		break;
+	}
+#endif
 
-	case OPT_LOG_COLOR_NUM:
-		if (eal_log_color(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_LOG_COLOR);
+	/* simple flag settings
+	 * Only set these to 1, as we don't want to set them to 0 in case
+	 * other options above have already set them.
+	 */
+	if (args.no_pci)
+		int_cfg->no_pci = 1;
+	if (args.no_hpet)
+		int_cfg->no_hpet = 1;
+	if (args.vmware_tsc_map)
+		int_cfg->vmware_tsc_map = 1;
+	if (args.no_shconf)
+		int_cfg->no_shconf = 1;
+	if (args.no_telemetry)
+		int_cfg->no_telemetry = 1;
+	if (args.match_allocations)
+		int_cfg->match_allocations = 1;
+	if (args.create_uio_dev)
+		int_cfg->create_uio_dev = 1;
+
+
+	/* other misc settings */
+	if (args.iova_mode != NULL) {
+		if (eal_parse_iova_mode(args.iova_mode) < 0) {
+			EAL_LOG(ERR, "invalid iova mode parameter '%s'", args.iova_mode);
 			return -1;
 		}
-		break;
-
-#ifndef RTE_EXEC_ENV_WINDOWS
-	case OPT_TRACE_NUM: {
-		if (eal_trace_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE);
+	};
+	if (args.base_virtaddr != NULL) {
+		if (eal_parse_base_virtaddr(args.base_virtaddr) < 0) {
+			EAL_LOG(ERR, "invalid base virtaddr '%s'", args.base_virtaddr);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_DIR_NUM: {
-		if (eal_trace_dir_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_DIR);
+	if (args.force_max_simd_bitwidth != NULL) {
+		if (eal_parse_simd_bitwidth(args.force_max_simd_bitwidth) < 0) {
+			EAL_LOG(ERR, "invalid SIMD bitwidth parameter '%s'",
+					args.force_max_simd_bitwidth);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_BUF_SIZE_NUM: {
-		if (eal_trace_bufsz_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_BUF_SIZE);
+	if (args.vfio_intr != NULL) {
+		if (eal_parse_vfio_intr(args.vfio_intr) < 0) {
+			EAL_LOG(ERR, "invalid vfio interrupt parameter: '%s'", args.vfio_intr);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_MODE_NUM: {
-		if (eal_trace_mode_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_MODE);
+	if (args.vfio_vf_token != NULL) {
+		if (eal_parse_vfio_vf_token(args.vfio_vf_token) < 0) {
+			EAL_LOG(ERR, "invalid vfio vf token parameter: '%s'", args.vfio_vf_token);
 			return -1;
 		}
-		break;
 	}
-#endif /* !RTE_EXEC_ENV_WINDOWS */
 
-	case OPT_LEGACY_MEM_NUM:
-		conf->legacy_mem = 1;
-		break;
-	case OPT_SINGLE_FILE_SEGMENTS_NUM:
-		conf->single_file_segments = 1;
-		break;
-	case OPT_IOVA_MODE_NUM:
-		if (eal_parse_iova_mode(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_IOVA_MODE);
+	if (args.huge_worker_stack != NULL) {
+		if (args.huge_worker_stack == (void *)1)
+			args.huge_worker_stack = NULL;
+		if (eal_parse_huge_worker_stack(args.huge_worker_stack) < 0) {
+			EAL_LOG(ERR, "invalid huge worker stack parameter");
 			return -1;
 		}
-		break;
-	case OPT_BASE_VIRTADDR_NUM:
-		if (eal_parse_base_virtaddr(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_BASE_VIRTADDR);
+	}
+	if (args.mbuf_pool_ops_name != NULL) {
+		free(int_cfg->user_mbuf_pool_ops_name); /* free old ops name */
+		int_cfg->user_mbuf_pool_ops_name = strdup(args.mbuf_pool_ops_name);
+		if (int_cfg->user_mbuf_pool_ops_name == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for mbuf pool ops name parameter");
 			return -1;
 		}
-		break;
-	case OPT_TELEMETRY_NUM:
-		break;
-	case OPT_NO_TELEMETRY_NUM:
-		conf->no_telemetry = 1;
-		break;
-	case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM:
-		if (eal_parse_simd_bitwidth(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_FORCE_MAX_SIMD_BITWIDTH);
+	}
+
+#ifndef RTE_EXEC_ENV_WINDOWS
+	/* create runtime data directory. In no_shconf mode, skip any errors */
+	if (eal_create_runtime_dir() < 0) {
+		if (int_cfg->no_shconf == 0) {
+			EAL_LOG(ERR, "Cannot create runtime directory");
 			return -1;
 		}
-		break;
+		EAL_LOG(WARNING, "No DPDK runtime directory created");
+	}
+#endif
 
-	/* don't know what to do, leave this to caller */
-	default:
-		return 1;
+	if (eal_adjust_config(int_cfg) != 0) {
+		EAL_LOG(ERR, "Invalid configuration");
+		return -1;
+	}
 
+	if (eal_check_common_options(int_cfg) != 0) {
+		EAL_LOG(ERR, "Checking common options failed");
+		return -1;
 	}
 
 	return 0;
-
-ba_conflict:
-	EAL_LOG(ERR,
-		"Options allow (-a) and block (-b) can't be used at the same time");
-	return -1;
 }
 
 static void
@@ -2153,13 +2221,8 @@ eal_check_common_options(struct internal_config *internal_cfg)
 			"option");
 		return -1;
 	}
-	if (mem_parsed && internal_cfg->force_numa == 1) {
-		EAL_LOG(ERR, "Options -m and --"OPT_NUMA_MEM" cannot "
-			"be specified at the same time");
-		return -1;
-	}
 	if (internal_cfg->no_hugetlbfs && internal_cfg->force_numa == 1) {
-		EAL_LOG(ERR, "Option --"OPT_NUMA_MEM" cannot "
+		EAL_LOG(ERR, "Option --"OPT_SOCKET_MEM" cannot "
 			"be specified together with --"OPT_NO_HUGE);
 		return -1;
 	}
@@ -2245,98 +2308,3 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 	internal_conf->max_simd_bitwidth.bitwidth = bitwidth;
 	return 0;
 }
-
-void
-eal_common_usage(void)
-{
-	printf("[options]\n\n"
-	       "EAL common options:\n"
-	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
-	       "  -l, --"OPT_LCORES" CORELIST\n"
-	       "                      List of cores to run on\n"
-	       "                      The basic argument format is <c1>[-c2][,c3[-c4],...]\n"
-	       "                      where c1, c2, etc are core indexes between 0 and %d\n"
-	       "                      Can also be used to map lcore set to physical CPU set\n"
-	       "                      The argument format is\n"
-	       "                            '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
-	       "                      lcores and cpus list are grouped by '(' and ')'\n"
-	       "                      Within the group, '-' is used for range separator,\n"
-	       "                      ',' is used for single number separator.\n"
-	       "                      '( )' can be omitted for single element group,\n"
-	       "                      '@' can be omitted if cpus and lcores have the same value\n"
-	       "  -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
-	       "  -S SERVICE CORELIST List of cores to run services on\n"
-	       "  --"OPT_MAIN_LCORE" ID     Core ID that is used as main\n"
-	       "  --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
-	       "  -n CHANNELS         Number of memory channels\n"
-	       "  -m MB               Memory to allocate (see also --"OPT_NUMA_MEM")\n"
-	       "  -r RANKS            Force number of memory ranks (don't detect)\n"
-	       "  -b, --block         Add a device to the blocked list.\n"
-	       "                      Prevent EAL from using this device. The argument\n"
-	       "                      format for PCI devices is <domain:bus:devid.func>.\n"
-	       "  -a, --allow         Add a device to the allow list.\n"
-	       "                      Only use the specified devices. The argument format\n"
-	       "                      for PCI devices is <[domain:]bus:devid.func>.\n"
-	       "                      This option can be present several times.\n"
-	       "                      [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n"
-	       "  --"OPT_VDEV"              Add a virtual device.\n"
-	       "                      The argument format is <driver><id>[,key=val,...]\n"
-	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
-	       "                      'va' for IOVA_VA\n"
-	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
-	       "                      (can be used multiple times)\n"
-	       "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
-	       "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
-#ifndef RTE_EXEC_ENV_WINDOWS
-	       "  --"OPT_SYSLOG"[=<facility>] Enable use of syslog (and optionally set facility)\n"
-#endif
-	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
-	       "                      Set specific log level\n"
-	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
-	       "  --"OPT_LOG_TIMESTAMP"[=<format>]  Timestamp log output\n"
-	       "  --"OPT_LOG_COLOR"[=<when>] Colorize log messages\n"
-#ifndef RTE_EXEC_ENV_WINDOWS
-	       "  --"OPT_TRACE"=<regex-match>\n"
-	       "                      Enable trace based on regular expression trace name.\n"
-	       "                      By default, the trace is disabled.\n"
-	       "		      User must specify this option to enable trace.\n"
-	       "  --"OPT_TRACE_DIR"=<directory path>\n"
-	       "                      Specify trace directory for trace output.\n"
-	       "                      By default, trace output will created at\n"
-	       "                      $HOME directory and parameter must be\n"
-	       "                      specified once only.\n"
-	       "  --"OPT_TRACE_BUF_SIZE"=<int>\n"
-	       "                      Specify maximum size of allocated memory\n"
-	       "                      for trace output for each thread. Valid\n"
-	       "                      unit can be either 'B|K|M' for 'Bytes',\n"
-	       "                      'KBytes' and 'MBytes' respectively.\n"
-	       "                      Default is 1MB and parameter must be\n"
-	       "                      specified once only.\n"
-	       "  --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
-	       "                      Specify the mode of update of trace\n"
-	       "                      output file. Either update on a file can\n"
-	       "                      be wrapped or discarded when file size\n"
-	       "                      reaches its maximum limit.\n"
-	       "                      Default mode is 'overwrite' and parameter\n"
-	       "                      must be specified once only.\n"
-#endif /* !RTE_EXEC_ENV_WINDOWS */
-	       "  -v                  Display version information on startup\n"
-	       "  -h, --"OPT_HELP"          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
-	       "                      disable secondary process support\n"
-	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
-	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
-	       "\nEAL options for DEBUG use only:\n"
-	       "  --"OPT_HUGE_UNLINK"[=existing|always|never]\n"
-	       "                      When to unlink files in hugetlbfs\n"
-	       "                      ('existing' by default, no value means 'always')\n"
-	       "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
-	       "  --"OPT_NO_PCI"            Disable PCI\n"
-	       "  --"OPT_NO_HPET"           Disable HPET\n"
-	       "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
-	       "\n", RTE_MAX_LCORE);
-}
lib/eal/common/eal_options.h +2 -8
index 6ef45559f0..c4d2cc84dc 100644
@@ -115,18 +115,12 @@ enum {
 	OPT_LONG_MAX_NUM
 };
 
-extern const char eal_short_options[];
-extern const struct option eal_long_options[];
-
-bool eal_option_is_log(int opt);
-int eal_parse_log_options(int argc, char * const argv[]);
-int eal_parse_common_option(int opt, const char *argv,
-			    struct internal_config *conf);
+int eal_parse_log_options(void);
+int eal_parse_args(void);
 int eal_option_device_parse(void);
 int eal_adjust_config(struct internal_config *internal_cfg);
 int eal_cleanup_config(struct internal_config *internal_cfg);
 int eal_check_common_options(struct internal_config *internal_cfg);
-void eal_common_usage(void);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
lib/eal/common/eal_private.h +11 -0
index 5846917cc5..ab8b37b956 100644
@@ -72,6 +72,17 @@ struct rte_config {
  */
 struct rte_config *rte_eal_get_configuration(void);
 
+/**
+ * Put the argument list into a structure.
+ *
+ * This allows the arguments to then be processed out-of-order.
+ *
+ * @return
+ *  - 0 on success
+ * - Negative on error
+ */
+int eal_collate_args(int argc, char **argv);
+
 /**
  * Initialize the memzone subsystem (private to eal).
  *
lib/eal/freebsd/eal.c +17 -147

213 lines not on this page · raw message

lib/eal/linux/eal.c +13 -366

410 lines not on this page · raw message

lib/eal/windows/eal.c +16 -97

132 lines not on this page · raw message

Signature · 1 line
2.48.1
#87 lore raw

PATCH v7 8/13 eal: ensure proper cleanup on EAL init failure

In reply to Bruce Richardson

When rte_eal_init fails part way through, any saved EAL arguments need to be freed, and the run_once flag needs to be set back to zero again. The former task was never done on failure, and the latter was only done on some occasions. Rework the error handling to always go to an err_out label where cleanup is done.

To prevent memory leaks from the saved arguments when eal_init is called twice, the check for multiple calls must be done first before the argument saving and parsing is done.

This patch modifies all three eal.c files. Windows doesn't actually need changes, since there are no args saved, and no run_once sentinel value, but updating it keeps it consistent with FreeBSD and Linux versions.

---
NOTE: this patch can probably be squashed in with the changes in the previous one, but for easier review I've kept it separate for now.

---
 lib/eal/common/eal_common_options.c | 37 ++++++++----
 lib/eal/common/eal_options.h        |  1 +
 lib/eal/freebsd/eal.c               | 83 +++++++++++++-------------
 lib/eal/linux/eal.c                 | 90 ++++++++++++++---------------
 lib/eal/windows/eal.c               | 47 ++++++++-------
 5 files changed, 137 insertions(+), 121 deletions(-)
lib/eal/common/eal_common_options.c +25 -12
index aea2c813ed..9c27d44a96 100644
@@ -271,6 +271,8 @@ rte_set_application_usage_hook(rte_usage_hook_t usage_func)
 
 int
 eal_save_args(__rte_unused int argc, __rte_unused char **argv) { return 0; }
+void
+eal_clean_saved_args(void) { /* no-op */ }
 
 #else /* RTE_EXEC_ENV_WINDOWS */
 static char **eal_args;
@@ -302,6 +304,28 @@ handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 	return used;
 }
 
+void
+eal_clean_saved_args(void)
+{
+	int i;
+
+	if (eal_args == NULL)
+		return;
+
+	if (eal_app_args != NULL) {
+		i = 0;
+		while (eal_app_args[i] != NULL)
+			free(eal_app_args[i++]);
+		free(eal_app_args);
+		eal_app_args = NULL;
+	}
+	i = 0;
+	while (eal_args[i] != NULL)
+		free(eal_args[i++]);
+	free(eal_args);
+	eal_args = NULL;
+}
+
 int
 eal_save_args(int argc, char **argv)
 {
@@ -346,18 +370,7 @@ eal_save_args(int argc, char **argv)
 	return 0;
 
 error:
-	if (eal_app_args != NULL) {
-		i = 0;
-		while (eal_app_args[i] != NULL)
-			free(eal_app_args[i++]);
-		free(eal_app_args);
-		eal_app_args = NULL;
-	}
-	i = 0;
-	while (eal_args[i] != NULL)
-		free(eal_args[i++]);
-	free(eal_args);
-	eal_args = NULL;
+	eal_clean_saved_args();
 	return -1;
 }
 #endif /* !RTE_EXEC_ENV_WINDOWS */
lib/eal/common/eal_options.h +1 -0
index c4d2cc84dc..fd28111e73 100644
@@ -124,6 +124,7 @@ int eal_check_common_options(struct internal_config *internal_cfg);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
+void eal_clean_saved_args(void);
 int handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 		struct rte_tel_data *d);
 
lib/eal/freebsd/eal.c +41 -42

255 lines not on this page · raw message

lib/eal/linux/eal.c +45 -45

271 lines not on this page · raw message

lib/eal/windows/eal.c +25 -22

176 lines not on this page · raw message

Signature · 1 line
2.48.1
#88 lore raw

PATCH v7 9/13 eal: combine parameter validation checks

In reply to Bruce Richardson

Remove the separate function to check combinations of cmdline parameters. Instead, just do those checks when parsing the parameters since we have all info about what parameters are provided at that point.

---
 lib/eal/common/eal_common_memory.c  |   3 +-
 lib/eal/common/eal_common_options.c | 262 +++++++++++-----------------
 lib/eal/common/eal_options.h        | 107 ------------
 lib/eal/linux/eal.c                 |   5 +-
 lib/eal/linux/eal_memory.c          |   2 +-
 5 files changed, 106 insertions(+), 273 deletions(-)
lib/eal/common/eal_common_memory.c +1 -2
index 38ccc734e8..c62edf5e55 100644
@@ -258,8 +258,7 @@ eal_memseg_list_alloc(struct rte_memseg_list *msl, int reserve_flags)
 		 * including common code, so don't duplicate the message.
 		 */
 		if (rte_errno == EADDRNOTAVAIL)
-			EAL_LOG(ERR, "Cannot reserve %llu bytes at [%p] - "
-				"please use '--" OPT_BASE_VIRTADDR "' option",
+			EAL_LOG(ERR, "Cannot reserve %llu bytes at [%p] - please use '--base-virtaddr' option",
 				(unsigned long long)mem_sz, msl->base_va);
 #endif
 		return -1;
lib/eal/common/eal_common_options.c +102 -160

390 lines not on this page · raw message

lib/eal/common/eal_options.h +0 -107

118 lines not on this page · raw message

lib/eal/linux/eal.c +2 -3
index 210d461497..babd36bf37 100644
@@ -329,9 +329,8 @@ rte_eal_config_reattach(void)
 	if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
 		if (mem_config != MAP_FAILED) {
 			/* errno is stale, don't use */
-			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p]"
-				" - please use '--" OPT_BASE_VIRTADDR
-				"' option", rte_mem_cfg_addr, mem_config);
+			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p] - please use '--base-virtaddr' option",
+				 rte_mem_cfg_addr, mem_config);
 			munmap(mem_config, sizeof(struct rte_mem_config));
 			return -1;
 		}
lib/eal/linux/eal_memory.c +1 -1
index e433c1afee..a366083822 100644
@@ -1967,7 +1967,7 @@ rte_eal_memseg_init(void)
 	if (!internal_conf->legacy_mem && rte_socket_count() > 1) {
 		EAL_LOG(WARNING, "DPDK is running on a NUMA system, but is compiled without NUMA support.");
 		EAL_LOG(WARNING, "This will have adverse consequences for performance and usability.");
-		EAL_LOG(WARNING, "Please use --"OPT_LEGACY_MEM" option, or recompile with NUMA support.");
+		EAL_LOG(WARNING, "Please use --legacy-mem option, or recompile with NUMA support.");
 	}
 #endif
 
Signature · 1 line
2.48.1
#89 lore raw

PATCH v7 10/13 eal: simplify handling of conflicting cmdline options

In reply to Bruce Richardson

Use a utility function and macro to simplify the code for checking for conflicting cmdline options. The checking can also be done at the initial argument collating stage, shortening the argument processing function which is very much on the long side.

---
 lib/eal/common/eal_common_options.c | 119 +++++++++++-----------------
 1 file changed, 47 insertions(+), 72 deletions(-)
lib/eal/common/eal_common_options.c +47 -72
index 486e2ad854..c568e59ef3 100644
@@ -178,6 +178,29 @@ struct rte_argparse eal_argparse  = {
 	}
 };
 
+static inline bool
+conflicting_options(uintptr_t opt1, uintptr_t opt2, const char *opt1_name, const char *opt2_name)
+{
+	char name1[64];  /* should be the max length of any argument */
+	char name2[64];
+
+	strlcpy(name1, opt1_name, sizeof(name1));
+	strlcpy(name2, opt2_name, sizeof(name2));
+	for (int i = 0; name1[i] != '\0'; i++)
+		if (name1[i] == '_')
+			name1[i] = '-';
+	for (int i = 0; name2[i] != '\0'; i++)
+		if (name2[i] == '_')
+			name2[i] = '-';
+	if (opt1 && opt2) {
+		EAL_LOG(ERR, "Options '%s' and '%s' can't be used at the same time", name1, name2);
+		return true;
+	}
+	return false;  /* no conflicts */
+}
+#define CONFLICTING_OPTIONS(args, opt1, opt2) \
+	conflicting_options((uintptr_t)(args.opt1), (uintptr_t)(args.opt2), #opt1, #opt2)
+
 /* function to call into argparse library to parse the passed argc/argv parameters
  * to the eal_init_args structure.
  */
@@ -200,6 +223,30 @@ eal_collate_args(int argc, char **argv)
 	if (retval < 0)
 		return retval;
 
+	/* check for conflicting options */
+	/* both -a and -b cannot be used together (one list must be empty at least) */
+	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
+		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
+		return -1;
+	}
+
+	/* for non-list args, we can just check for zero/null values using macro */
+	if (CONFLICTING_OPTIONS(args, coremask, lcores) ||
+			CONFLICTING_OPTIONS(args, service_coremask, service_corelist) ||
+			CONFLICTING_OPTIONS(args, no_telemetry, telemetry) ||
+			CONFLICTING_OPTIONS(args, memory_size, numa_mem) ||
+			CONFLICTING_OPTIONS(args, no_huge, numa_mem) ||
+			CONFLICTING_OPTIONS(args, no_huge, huge_worker_stack) ||
+			CONFLICTING_OPTIONS(args, numa_limit, legacy_mem) ||
+			CONFLICTING_OPTIONS(args, legacy_mem, in_memory) ||
+			CONFLICTING_OPTIONS(args, legacy_mem, match_allocations) ||
+			CONFLICTING_OPTIONS(args, no_huge, match_allocations) ||
+			CONFLICTING_OPTIONS(args, no_huge, huge_unlink) ||
+			CONFLICTING_OPTIONS(args, single_file_segments, huge_unlink) ||
+			CONFLICTING_OPTIONS(args, no_huge, single_file_segments) ||
+			CONFLICTING_OPTIONS(args, in_memory, huge_unlink))
+		return -1;
+
 	argv[retval - 1] = argv[0];
 	return retval - 1;
 }
@@ -1780,78 +1827,6 @@ eal_parse_args(void)
 	struct rte_config *rte_cfg = rte_eal_get_configuration();
 	struct arg_list_elem *arg;
 
-	/* check for conflicting options */
-	/* both -a and -b cannot be used together (one list must be empty at least) */
-	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
-		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
-		return -1;
-	}
-	/* both -l and -c cannot be used at the same time */
-	if (args.coremask != NULL && args.lcores != NULL) {
-		EAL_LOG(ERR, "Options coremask (-c) and core list (-l) can't be used at the same time");
-		return -1;
-	}
-	/* both -s and -S cannot be used at the same time */
-	if (args.service_coremask != NULL && args.service_corelist != NULL) {
-		EAL_LOG(ERR, "Options service coremask (-s) and service core list (-S) can't be used at the same time");
-		return -1;
-	}
-	/* can't have both telemetry and no-telemetry */
-	if (args.no_telemetry && args.telemetry) {
-		EAL_LOG(ERR, "Options telemetry and no-telemetry can't be used at the same time");
-		return -1;
-	}
-	/* can't have both -m and --socket-mem */
-	if (args.memory_size != NULL && args.numa_mem != NULL) {
-		EAL_LOG(ERR, "Options -m and --numa-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use both no-huge and socket-mem */
-	if (args.no_huge && args.numa_mem) {
-		EAL_LOG(ERR, "Options --no-huge and --numa-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and huge-worker-stack */
-	if (args.huge_worker_stack != NULL && args.no_huge) {
-		EAL_LOG(ERR, "Options --no-huge and --huge-worker-stack can't be used at the same time");
-		return -1;
-	}
-	/* can't use socket-limit and legacy-mem */
-	if (args.numa_limit != NULL && args.legacy_mem) {
-		EAL_LOG(ERR, "Options --numa-limit and --legacy-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use legacy-mem and in-memory */
-	if (args.legacy_mem && args.in_memory) {
-		EAL_LOG(ERR, "Options --legacy-mem and --in-memory can't be used at the same time");
-		return -1;
-	}
-	/* can't use legacy-mem and match-allocations */
-	if (args.legacy_mem && args.match_allocations) {
-		EAL_LOG(ERR, "Options --legacy-mem and --match-allocations can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and match-allocations */
-	if (args.no_huge && args.match_allocations) {
-		EAL_LOG(ERR, "Options --no-huge and --match-allocations can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and huge-unlink */
-	if (args.no_huge && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --no-huge and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-	/* can't use single-file-segments and huge-unlink */
-	if (args.single_file_segments && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --single-file-segments and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-	/* can't use in-memory and huge-unlink */
-	if (args.in_memory && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --in-memory and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-
 	/* print version before anything else */
 	/* since message is explicitly requested by user, we write message
 	 * at highest log level so it can always be seen even if info or
Signature · 1 line
2.48.1
#90 lore raw

PATCH v7 11/13 argparse: add support for parsing core lists

In reply to Bruce Richardson

Core lists are widely used in DPDK, so add support for parsing them.

---
 app/test/test_argparse.c               | 188 +++++++++++++++++++++++++
 doc/guides/prog_guide/argparse_lib.rst |  32 +++++
 lib/argparse/rte_argparse.c            |  63 +++++++++
 lib/argparse/rte_argparse.h            |   2 +
 4 files changed, 285 insertions(+)
app/test/test_argparse.c +188 -0
index 0a229752fa..c829ea75e4 100644
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_argparse.h>
+#include <rte_os.h>
 
 #include "test.h"
 
@@ -500,6 +501,40 @@ test_argparse_opt_autosave_parse_int_of_optional_val(void)
 	return 0;
 }
 
+static int
+test_argparse_opt_parse_corelist_of_required_val(void)
+{
+	struct rte_argparse *obj;
+	rte_cpuset_t val_cpuset;
+	char *argv[3];
+	int ret;
+
+	/* test with long option and single core - this is known to work */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--corelist";
+	obj->args[0].name_short = "-c";
+	obj->args[0].val_saver = (void *)&val_cpuset;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_CORELIST;
+	obj->args[1].name_long = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("--corelist");
+	argv[2] = test_strdup("1,3-5");
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse(obj, 3, argv);
+	TEST_ASSERT(ret == 3, "Argparse parse expect success!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(3, &val_cpuset), "Core 3 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(4, &val_cpuset), "Core 4 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in corelist!");
+
+	return 0;
+}
+
 static int
 opt_callback_parse_int_of_no_val(uint32_t index, const char *value, void *opaque)
 {
@@ -782,6 +817,152 @@ test_argparse_pos_callback_parse_int(void)
 	return 0;
 }
 
+static int
+test_argparse_parse_type_corelist(void)
+{
+	char *corelist_valid_single = test_strdup("5");
+	char *corelist_valid_multiple = test_strdup("0,1,5");
+	char *corelist_valid_range = test_strdup("1-5");
+	char *corelist_valid_mixed = test_strdup("0,1,5-10,12-16,18,20");
+	char *corelist_valid_reverse_range = test_strdup("10-5");
+	char *corelist_valid_initial_spaces = test_strdup("   1,2,5-7");
+	char *corelist_valid_empty = test_strdup("");
+	char *corelist_invalid_spaces = test_strdup(" 1 , 2 , 5-7 ");
+	char *corelist_invalid_letters = test_strdup("1,a,3");
+	char *corelist_invalid_range_incomplete = test_strdup("1-");
+	char *corelist_invalid_range_double_dash = test_strdup("1--5");
+	char *corelist_invalid_special_chars = test_strdup("1,2@3");
+	char *corelist_invalid_comma_only = test_strdup(",");
+	char *corelist_invalid_out_of_range = test_strdup("70000");
+	rte_cpuset_t val_cpuset;
+	int ret;
+
+	/* test valid single core */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_single,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (single core) failed!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(1, &val_cpuset), "Core 1 should not be set in corelist!");
+
+	/* test valid multiple cores */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_multiple,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (multiple cores) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(3, &val_cpuset), "Core 3 should not be set in corelist!");
+
+	/* test valid range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (range) failed!");
+	for (int i = 1; i <= 5; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 1-5!", i);
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in range 1-5!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in range 1-5!");
+
+	/* test valid mixed corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_mixed,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (mixed) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in mixed corelist!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 5-10!", i);
+	for (int i = 12; i <= 16; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 12-16!", i);
+
+	TEST_ASSERT(CPU_ISSET(18, &val_cpuset), "Core 18 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(20, &val_cpuset), "Core 20 should be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(17, &val_cpuset), "Core 17 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(19, &val_cpuset), "Core 19 should not be set in mixed corelist!");
+
+	/* test valid reverse range (10-5 should be interpreted as 5-10) */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_reverse_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (reverse range) failed!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in reverse range 10-5!", i);
+	TEST_ASSERT(!CPU_ISSET(4, &val_cpuset), "Core 4 should not be set in reverse range 10-5!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in reverse range 10-5!");
+
+	/* test valid corelist with initial spaces only */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_initial_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (with initial spaces) failed!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in initial spaced corelist!");
+	TEST_ASSERT(CPU_ISSET(2, &val_cpuset), "Core 2 should be set in initial spaced corelist!");
+	for (int i = 5; i <= 7; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in initial spaced range 5-7!", i);
+
+	/* test valid empty corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_empty,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (empty) failed!");
+	/* Verify that no cores are set in empty corelist */
+	for (int i = 0; i < CPU_SETSIZE; i++)
+		TEST_ASSERT(!CPU_ISSET(i, &val_cpuset),
+				"Core %d should not be set in empty corelist!", i);
+
+	/* test invalid corelist with spaces */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with spaces) should have failed!");
+
+	/* test invalid corelist with letters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_letters,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with letters) should have failed!");
+
+	/* test invalid corelist with incomplete range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_incomplete,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (incomplete range) should have failed!");
+
+	/* test invalid corelist with double dash */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_double_dash,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (double dash) should have failed!");
+
+	/* test invalid corelist with special characters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_special_chars,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (special chars) should have failed!");
+
+	/* test invalid comma-only corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_comma_only,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (comma only) should have failed!");
+
+	/* test invalid out-of-range corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_out_of_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (out of range) should have failed!");
+
+	return 0;
+}
+
 static int
 test_argparse_parse_type(void)
 {
@@ -880,6 +1061,12 @@ test_argparse_parse_type(void)
 	ret = rte_argparse_parse_type(bool_numeric_invalid, RTE_ARGPARSE_VALUE_TYPE_BOOL,
 			&val_bool);
 	TEST_ASSERT(ret != 0, "Argparse parse type for bool (numeric invalid) passed unexpectedly!");
+
+	/* test for corelist parsing */
+	ret = test_argparse_parse_type_corelist();
+	if (ret != 0)
+		return ret;
+
 	return 0;
 }
 
@@ -900,6 +1087,7 @@ static struct unit_test_suite argparse_test_suite = {
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_optional_val),
+		TEST_CASE(test_argparse_opt_parse_corelist_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_optional_val),
doc/guides/prog_guide/argparse_lib.rst +32 -0
index 7868af5672..7882d910ab 100644
@@ -229,6 +229,38 @@ Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept t
       },
    };
 
+Corelist Type
+^^^^^^^^^^^^^
+
+The argparse library supports automatic parsing of CPU core lists using the
+``RTE_ARGPARSE_VALUE_TYPE_CORELIST`` value type. This feature allows users to
+specify CPU cores in a flexible format similar to other DPDK applications.
+
+.. code-block:: C
+
+   #include <rte_os.h>  /* for CPU set operations */
+
+   static rte_cpuset_t cores;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--cores", "-c", "CPU cores to use", &cores, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_CORELIST },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+The corelist parsing supports the following input formats:
+
+- **Single core**: ``--cores 5`` (sets core 5)
+- **Multiple cores**: ``--cores 1,2,5`` (sets cores 1, 2, and 5)
+- **Core ranges**: ``--cores 1-5`` (sets cores 1, 2, 3, 4, and 5)
+- **Mixed format**: ``--cores 0,2-4,7`` (sets cores 0, 2, 3, 4, and 7)
+- **Reverse ranges**: ``--cores 5-1`` (equivalent to 1-5, sets cores 1, 2, 3, 4, and 5)
+- **Empty corelist**: ``--cores ""`` (sets no cores)
+
+The parsed result is stored in an ``rte_cpuset_t`` structure that can be used
+with standard CPU set operations:
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
lib/argparse/rte_argparse.c +63 -0

90 lines not on this page · raw message

lib/argparse/rte_argparse.h +2 -0
index 63b49ba220..991f084927 100644
@@ -69,6 +69,8 @@ enum rte_argparse_value_type {
 	RTE_ARGPARSE_VALUE_TYPE_STR,
 	/** The argument's value is boolean flag type. */
 	RTE_ARGPARSE_VALUE_TYPE_BOOL,
+	/** The argument's value is a corelist */
+	RTE_ARGPARSE_VALUE_TYPE_CORELIST,
 };
 
 /** Additional flags which may be specified for each argument */
Signature · 1 line
2.48.1
#91 lore raw

PATCH v7 12/13 eal: simplify running CPUs with ids above max lcores

In reply to Bruce Richardson

To simplify use on systems with large numbers of cores, where it becomes more awkward to use CPU cores numbered above 128, we add to EAL the "-L" or "--lcores-remapped" option, which simply takes a list of cores to run on, and maps them to lcore ids starting at a defined base (0 by default).

To enable secondary process use of this, we also add in an extra flag --lcoreid-base, which changes the starting lcore id from 0. This flag is mandatory in secondary processes, to ensure that we don't have lcore ids that overlap between primary and secondary.

---
 doc/guides/linux_gsg/eal_args.include.rst | 46 ++++++++++++-
 doc/guides/rel_notes/release_25_11.rst    |  9 +++
 lib/eal/common/eal_common_options.c       | 79 +++++++++++++++++++++--
 lib/eal/common/eal_option_list.h          |  2 +
 4 files changed, 130 insertions(+), 6 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +45 -1
index 0b17879d42..d45d79b827 100644
@@ -4,6 +4,28 @@
 Lcore-related options
 ~~~~~~~~~~~~~~~~~~~~~
 
+*   ``-L, --lcores-remapped <core list>``
+
+    List of physical CPU cores to use,
+    with each core assigned a sequential logical core (lcore) ID starting from 0.
+    This is a simplified alternative to ``--lcores``, described below,
+    for cases where you want to use specific physical cores,
+    (some or all of which have physical ids greater than RTE_MAX_LCORE)
+    but don't need complex logical-to-physical core mappings.
+
+    The argument format is a standard core list: ``<c1>[-c2][,c3[-c4],...]``
+    where ``c1``, ``c2``, etc are physical core indexes.
+
+    Examples:
+
+    ``--lcores-remapped=3-5``
+      Use physical cores 3, 4, and 5 as logical cores 0, 1, and 2 respectively.
+      This is equivalent to ``--lcores=0@3,1@4,2@5``.
+
+    ``--lcores-remapped=150,152,154``
+      Use physical cores 150, 152, and 154 as logical cores 0, 1, and 2 respectively.
+      This is equivalent to ``--lcores=0@150,1@152,2@154``.
+
 *   ``-l, --lcores <core list>``
 
     List of cores to run on
@@ -64,9 +86,31 @@ Lcore-related options
 
 .. note::
 
-    At a given instance only one core option ``--lcores``, ``-l`` or ``-c`` can
+    At a given instance only one core option ``--lcores`` / ``-l``, or ``--lcores-remapped`` / ``-L`` can
     be used.
 
+*   ``--lcoreid-base <base ID>``
+
+    Adjust the base logical core ID for ``--lcores-remapped`` (default: 0).
+    When used with ``--lcores-remapped``,
+    logical core numbering starts from this value instead of 0.
+    This is particularly useful for secondary processes in a multi-process setup,
+    as lcore_ids must all be unique across all processes.
+
+    Example:
+
+    ``--lcores-remapped=3-5 --lcoreid-base=10``
+      Use physical cores 3, 4, and 5 as logical cores 10, 11, and 12 respectively.
+      This is equivalent to ``--lcores=10@3,11@4,12@5``.
+
+.. note::
+
+    The ``--lcores-remapped`` option is ignored if used with ``--lcores``, ``-l`` option.
+
+.. note::
+
+    For secondary processes, ``--lcoreid-base`` *must* be specified when using ``--lcores-remapped``.
+
 *   ``--main-lcore <core ID>``
 
     Core ID that is used as main.
doc/guides/rel_notes/release_25_11.rst +9 -0
index 75bbd0e821..39fc800f6e 100644
@@ -55,6 +55,15 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added EAL lcores-remapped(-L) argument to simplify running on higher-numbered cores.**
+
+  Added new EAL command line arguments ``-L, --lcores-remapped`` and ``--lcoreid-base``
+  that provide a simplified way to specify which physical CPU cores to use.
+  The ``--lcores-remapped`` argument allows specifying a list of physical cores on which the EAL threads are to be spawned,
+  with each thread being assigned an lcore id in sequence.
+  The lcore numbering starts at 0 by default, though this can be overridden using ``--lcoreid-base``.
+  See :doc:`../linux_gsg/eal_args.include` for more details.
+
 * **Allow overriding the automatic usage/help generation in argparse library.**
 
   The argparse library now supports overriding the automatic help text generation,
lib/eal/common/eal_common_options.c +74 -5

115 lines not on this page · raw message

lib/eal/common/eal_option_list.h +2 -0
index dd148b7fed..976df16347 100644
@@ -42,6 +42,8 @@ OPT_STR_ARG("--huge-unlink", NULL, "Unlink hugetlbfs files on exit (existing|alw
 BOOL_ARG("--in-memory", NULL, "DPDK should not create shared mmap files in filesystem  (disables secondary process support)", in_memory)
 STR_ARG("--iova-mode", NULL, "IOVA mapping mode, physical (pa)/virtual (va)", iova_mode)
 STR_ARG("--lcores", "-l", "List of CPU cores to use", lcores)
+STR_ARG("--lcores-remapped", "-L", "List of cores to use, assigning each a sequential lcore ID (start 0 by default)", lcores_remapped)
+STR_ARG("--lcoreid-base", NULL, "Number remapped lcores from <N>, rather than 0 (e.g. for secondary processes)", lcoreid_base)
 BOOL_ARG("--legacy-mem", NULL, "Enable legacy memory behavior", legacy_mem)
 OPT_STR_ARG("--log-color", NULL, "Enable/disable color in log output", log_color)
 STR_ARG("--log-level", NULL, "Log level for loggers; use log-level=help for list of log types and levels", log_level)
Signature · 1 line
2.48.1
#92 lore raw

PATCH v7 13/13 eal: add warnings about ignored options

In reply to Bruce Richardson

The lcoreid-base option only applies when used with the lcores-remapped option, so print a warning when it's used with an lcores or coremask flag, or when no core specification is given at all.

To do this, we add some generic infrastructure to allow us to warn about options which are ignored when either used together or not used together.

---
 lib/eal/common/eal_common_options.c | 47 +++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)
lib/eal/common/eal_common_options.c +47 -0
index af2bd33fd4..5992f4e43b 100644
@@ -201,6 +201,47 @@ conflicting_options(uintptr_t opt1, uintptr_t opt2, const char *opt1_name, const
 #define CONFLICTING_OPTIONS(args, opt1, opt2) \
 	conflicting_options((uintptr_t)(args.opt1), (uintptr_t)(args.opt2), #opt1, #opt2)
 
+enum when_ignored {
+	OPT_IGNORED_WITH,
+	OPT_IGNORED_WITHOUT,
+};
+static inline bool  /* return bool so we can track what warnings are printed */
+ignored_option(uintptr_t ignored, uintptr_t opt2, const char *ignored_name, const char *opt2_name,
+		enum when_ignored when)
+{
+	char name1[64];  /* should be the max length of any argument */
+	char name2[64];
+
+	if (!ignored)
+		return false;
+
+	strlcpy(name1, ignored_name, sizeof(name1));
+	strlcpy(name2, opt2_name, sizeof(name2));
+	for (int i = 0; name1[i] != '\0'; i++)
+		if (name1[i] == '_')
+			name1[i] = '-';
+	for (int i = 0; name2[i] != '\0'; i++)
+		if (name2[i] == '_')
+			name2[i] = '-';
+
+	if (when == OPT_IGNORED_WITH && opt2) {
+		EAL_LOG(WARNING, "Option '%s' ignored when used with option '%s'", name1, name2);
+		return true;
+	} else if (when == OPT_IGNORED_WITHOUT && !opt2) {
+		EAL_LOG(WARNING, "Option '%s' ignored without option '%s'", name1, name2);
+		return true;
+	}
+	return false;
+}
+/* prints a warning when option "ignored" is used *with* option "opt2" */
+#define IGNORE_OPTION_WITH(args, ignored, opt2) \
+	ignored_option((uintptr_t)(args.ignored), (uintptr_t)(args.opt2), #ignored, #opt2, \
+			OPT_IGNORED_WITH)
+/* prints a warning when option "ignored" is used *without* option "opt2" */
+#define IGNORE_OPTION_WITHOUT(args, ignored, opt2) \
+	ignored_option((uintptr_t)(args.ignored), (uintptr_t)(args.opt2), #ignored, #opt2, \
+			OPT_IGNORED_WITHOUT)
+
 /* function to call into argparse library to parse the passed argc/argv parameters
  * to the eal_init_args structure.
  */
@@ -249,6 +290,12 @@ eal_collate_args(int argc, char **argv)
 			CONFLICTING_OPTIONS(args, in_memory, huge_unlink))
 		return -1;
 
+	/* warn about some ignored options */
+	if (!IGNORE_OPTION_WITH(args, lcoreid_base, lcores) &&
+			!IGNORE_OPTION_WITH(args, lcoreid_base, coremask))
+		/* only warn about not having --lcores-remapped if we didn't already warn */
+		IGNORE_OPTION_WITHOUT(args, lcoreid_base, lcores_remapped);
+
 	argv[retval - 1] = argv[0];
 	return retval - 1;
 }
Signature · 1 line
2.48.1
#93 lore raw

Re: [PATCH v7 00/13] Simplify running with high-numbered CPUs

In reply to Bruce Richardson
Quoted 34 lines · Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL args "--lcores-remapped", also shortened to just "-L", and "--lcoreid-base", are added to DPDK to support this. However, in order to enable the addition of these new flags, the first 10 patches of this set do cleanups, for reasons explained below.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

To do the initial argument gathering, this RFC uses the existing argparse library in DPDK. With recent changes, and a few additional patches at the start of this set, this library now meets our needs for EAL argument parsing and allows us to not need to do direct getopt argument processing inside EAL at all.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Quoted 8 lines

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V7:
* expand the scope of the patchset beyond just cleanup to add in the extra 3 patches for -L and --lcoreid-base option.

Recheck-request: rebase=main, iol-abi-testing

#94 lore raw

v8 cover Simplify running with high-numbered CPUs

In reply to Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

V7:
* expand the scope of the patchset beyond just cleanup to add in the extra 3 patches for -L and --lcoreid-base option.

V6:
* Rebase to apply cleanly on latest main

V5:
* Resubmit of V4, which didn't get sent correctly, or picked up correctly in patchwork.

V4:
* Updated patch 5 to auto-generate the arg struct definition from the same list of defines used to construct the argument list.

V3:
* Added 3 new initial patches, one for minor build-system addition, and two for functionality in argparse to allow the user-callback help function to be maintained as we move to argparse.
* Added doc updates in the first EAL patch adding the long options
* Fixed ASAN issues by adding a patch to properly clean up EAL init - both memory allocations and fixing the run-once flag
* Put ifdefs around the linux-only or unix-only options in EAL patch 2
* Updated args to handle numa-mem and numa-limit as equivalent socket-mem and socket-limit

Bruce Richardson (18):
build: add define for the OS environment name
argparse: export function to print help text for object
argparse: allow user-override of help printing
argparse: add documentation on supported value types
argparse: add support for parsing core lists
eal: add long options for each short option
eal: define the EAL parameters in argparse format
eal: gather EAL args before processing
eal: ensure proper cleanup on EAL init failure
eal: combine parameter validation checks
eal: simplify handling of conflicting cmdline options
eal: automatically init arg list options
eal: add internal fn for converting cpuset to string
eal: use common cpuset to string function
eal: introduce lcore remapping option for coremasks
eal: rework internal coremask parsing to use cpu sets
eal: allow lcore id remapping with core lists
eal: allow lcore remapping with autodetected core affinity

 app/test/test_argparse.c                   |  188 +++
 config/meson.build                         |    1 +
 doc/guides/contributing/design.rst         |    2 +-
 doc/guides/linux_gsg/eal_args.include.rst  |   42 +-
 doc/guides/prog_guide/argparse_lib.rst     |  121 +-
 doc/guides/rel_notes/release_25_11.rst     |   18 +
 drivers/event/dlb2/dlb2_priv.h             |    2 +-
 drivers/event/dlb2/pf/base/dlb2_resource.c |   11 +-
 lib/argparse/rte_argparse.c                |  109 +-
 lib/argparse/rte_argparse.h                |   23 +-
 lib/eal/common/eal_common_lcore.c          |   13 +-
 lib/eal/common/eal_common_memory.c         |    3 +-
 lib/eal/common/eal_common_options.c        | 1417 +++++++++++---------
 lib/eal/common/eal_common_thread.c         |   43 +-
 lib/eal/common/eal_option_list.h           |   98 ++
 lib/eal/common/eal_options.h               |  104 +-
 lib/eal/common/eal_private.h               |   21 +
 lib/eal/common/eal_thread.h                |   13 +-
 lib/eal/freebsd/eal.c                      |  245 +---
 lib/eal/include/rte_eal.h                  |   20 -
 lib/eal/linux/eal.c                        |  470 +------
 lib/eal/linux/eal_memory.c                 |    2 +-
 lib/eal/meson.build                        |    2 +-
 lib/eal/windows/eal.c                      |  156 +--
 lib/meson.build                            |    1 +
 25 files changed, 1533 insertions(+), 1592 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h

--
2.48.1

#95 lore raw

PATCH v8 1/18 build: add define for the OS environment name

Introduce a string define for the currently running OS, or execution environment.

Originally, with old make build system, CONFIG_RTE_EXEC_ENV used to hold this name string, but the variable seems to have been missed in the meson build system, until commit cadb255e25d6 ("eal: add OS defines for C conditional checks") which introduced the RTE_EXEC_ENV for a different purpose. Now we can fix the docs with the new name reference.

---
 config/meson.build                 | 1 +
 doc/guides/contributing/design.rst | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
index 55497f0bf5..495245d527 100644
@@ -20,6 +20,7 @@ foreach env, id:exec_envs
     dpdk_conf.set10('RTE_EXEC_ENV_IS_' + env.to_upper(), (exec_env == env))
 endforeach
 dpdk_conf.set('RTE_EXEC_ENV', exec_envs[exec_env])
+dpdk_conf.set_quoted('RTE_EXEC_ENV_NAME', exec_env)
 dpdk_conf.set('RTE_EXEC_ENV_' + exec_env.to_upper(), 1)
 
 # MS linker requires special treatment.
doc/guides/contributing/design.rst +1 -1
index b724177ba1..5517613424 100644
@@ -50,7 +50,7 @@ Per Execution Environment Sources
 
 The following macro options can be used:
 
-* ``RTE_EXEC_ENV`` is a string that contains the name of the executive environment.
+* ``RTE_EXEC_ENV_NAME`` is a string that contains the name of the executive environment.
 * ``RTE_EXEC_ENV_FREEBSD``, ``RTE_EXEC_ENV_LINUX`` or ``RTE_EXEC_ENV_WINDOWS`` are defined only if we are building for this execution environment.
 
 Mbuf features
Signature · 1 line
2.48.1
#96 lore raw

PATCH v8 2/18 argparse: export function to print help text for object

In reply to Bruce Richardson

Make the function to print out the help text for an argparse object a public function, which takes as a new parameter the file stream on which to print. This can be used in future to allow application to extend their own help information.

---
 lib/argparse/rte_argparse.c | 43 +++++++++++++++++++------------------
 lib/argparse/rte_argparse.h | 14 ++++++++++++
 2 files changed, 36 insertions(+), 21 deletions(-)
lib/argparse/rte_argparse.c +22 -21
index 331f05f01d..f0c2c33178 100644
@@ -716,23 +716,23 @@ calc_help_align(const struct rte_argparse *obj)
 }
 
 static void
-show_oneline_help(const struct rte_argparse_arg *arg, uint32_t width)
+show_oneline_help(FILE *stream, const struct rte_argparse_arg *arg, uint32_t width)
 {
 	uint32_t len = 0;
 	uint32_t i;
 
 	if (arg->name_short != NULL)
-		len = printf(" %s,", arg->name_short);
-	len += printf(" %s", arg->name_long);
+		len = fprintf(stream, " %s,", arg->name_short);
+	len += fprintf(stream, " %s", arg->name_long);
 
 	for (i = len; i < width; i++)
-		printf(" ");
+		fprintf(stream, " ");
 
-	printf("%s\n", arg->help);
+	fprintf(stream, "%s\n", arg->help);
 }
 
 static void
-show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
+show_args_pos_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	uint32_t position_count = calc_position_count(obj);
 	const struct rte_argparse_arg *arg;
@@ -741,19 +741,19 @@ show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
 	if (position_count == 0)
 		return;
 
-	printf("\npositional arguments:\n");
+	fprintf(stream, "\npositional arguments:\n");
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_positional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
 static void
-show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
+show_args_opt_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	static const struct rte_argparse_arg help = {
 		.name_long = "--help",
@@ -763,34 +763,35 @@ show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
 	const struct rte_argparse_arg *arg;
 	uint32_t i;
 
-	printf("\noptions:\n");
-	show_oneline_help(&help, align);
+	fprintf(stream, "\noptions:\n");
+	show_oneline_help(stream, &help, align);
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_optional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
-static void
-show_args_help(const struct rte_argparse *obj)
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_print_help, 25.11)
+void
+rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj)
 {
 	uint32_t align = calc_help_align(obj);
 
-	printf("usage: %s %s\n", obj->prog_name, obj->usage);
+	fprintf(stream, "usage: %s %s\n", obj->prog_name, obj->usage);
 	if (obj->descriptor != NULL)
-		printf("\ndescriptor: %s\n", obj->descriptor);
+		fprintf(stream, "\ndescriptor: %s\n", obj->descriptor);
 
-	show_args_pos_help(obj, align);
-	show_args_opt_help(obj, align);
+	show_args_pos_help(stream, obj, align);
+	show_args_opt_help(stream, obj, align);
 
 	if (obj->epilog != NULL)
-		printf("\n%s\n", obj->epilog);
+		fprintf(stream, "\n%s\n", obj->epilog);
 	else
-		printf("\n");
+		fprintf(stream, "\n");
 }
 
 RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_parse, 24.03)
@@ -820,7 +821,7 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		show_args_help(obj);
+		rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +14 -0
index 52bef34363..baf278f6b9 100644
@@ -189,6 +189,20 @@ struct rte_argparse {
 __rte_experimental
 int rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Output the help text information for the given argparse object.
+ *
+ * @param stream
+ *   Output file handle, e.g. stdout, stderr, on which to print the help text.
+ * @param obj
+ *   Parser object.
+ */
+__rte_experimental
+void rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.48.1
#97 lore raw

PATCH v8 3/18 argparse: allow user-override of help printing

In reply to Bruce Richardson

When the arguments passed to argparse include -h/--help then usage information is automatically printed. Provide the capability for the user to supply their own help function for this.

---
 doc/guides/prog_guide/argparse_lib.rst | 16 ++++++++++++++++
 doc/guides/rel_notes/release_25_11.rst |  7 +++++++
 lib/argparse/rte_argparse.c            |  5 ++++-
 lib/argparse/rte_argparse.h            |  7 ++++++-
 4 files changed, 33 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +16 -0
index 9f11714890..b309260d20 100644
@@ -24,6 +24,8 @@ Features and Capabilities
   #. autosave: used for parsing known value types;
   #. callback: will invoke user callback to parse.
 
+- Supports automatic help and usage information.
+
 Usage Guide
 -----------
 
@@ -193,3 +195,17 @@ Then the user input could contain multiple ``--xyz`` arguments.
 
    The multiple times argument only support with optional argument
    and must be parsed by callback way.
+
+Help and Usage Information
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic generation of help and usage information.
+When the input arguments include ``-h`` or ``--help``,
+it will print the usage information to standard output.
+If the default help output is not what is wanted,
+the user can provide a custom help printing function by setting the ``print_help`` field in the ``rte_argparse`` object.
+(If this field is set to NULL, the default help printing function will be used.)
+
+If the custom help printing function wants to use the text produced by the default help function,
+it can call the function ``rte_argparse_print_help()`` to get the help text printed to an output stream,
+for example: stdout or stderr.
doc/guides/rel_notes/release_25_11.rst +7 -0
index c3b94e1896..f73bab1227 100644
@@ -76,6 +76,13 @@ New Features
   * Added multi-process per port.
   * Optimized code.
 
+* **Allow overriding the automatic usage/help generation in argparse library.**
+
+  The argparse library now supports overriding the automatic help text generation,
+  by allowing the user to provide a custom function to generate the output text.
+  The built-in help text function is available as a public function which can be reused by custom functions,
+  if so desired.
+
 
 Removed Items
 -------------
lib/argparse/rte_argparse.c +4 -1
index f0c2c33178..2b5da5f1db 100644
@@ -821,7 +821,10 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		rte_argparse_print_help(stdout, obj);
+		if (obj->print_help != NULL)
+			obj->print_help(obj);
+		else
+			rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +6 -1
index baf278f6b9..63b49ba220 100644
@@ -160,8 +160,13 @@ struct rte_argparse {
 	rte_arg_parser_t callback;
 	/** Opaque which used to invoke callback. */
 	void *opaque;
+	/**
+	 * Function pointer for printing usage when -h is passed.
+	 * If this is NULL, default printing function will be used.
+	 */
+	void (*print_help)(const struct rte_argparse *obj);
 	/** Reserved field used for future extension. */
-	void *reserved[16];
+	void *reserved[15];
 	/** Arguments configuration. Must ended with ARGPARSE_ARG_END(). */
 	struct rte_argparse_arg args[];
 };
Signature · 1 line
2.48.1
#98 lore raw

PATCH v8 4/18 argparse: add documentation on supported value types

In reply to Bruce Richardson

The different value types supported by the argparse library are not discussed in the documentation, so add some reference material about them.

---
 doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +71 -2
index b309260d20..7868af5672 100644
@@ -160,6 +160,75 @@ both use this way, the parsing is as follows:
 - For argument ``ooo``, it is positional argument,
   the ``ooo_val`` will be set to user input's value.
 
+Supported Value Types
+~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic parsing of several data types when using
+the autosave method. The parsed values are automatically converted from string
+input to the appropriate data type and stored in the ``val_saver`` field.
+
+Integer Types
+^^^^^^^^^^^^^
+
+The library supports parsing various integer types:
+
+- ``RTE_ARGPARSE_VALUE_TYPE_INT`` - signed integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U8`` - unsigned 8-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U16`` - unsigned 16-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U32`` - unsigned 32-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U64`` - unsigned 64-bit integer
+
+.. code-block:: C
+
+   static int my_int;
+   static uint16_t my_port;
+   static uint32_t my_count;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--number", "-n", "Integer value", &my_int, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_INT },
+         { "--port", "-p", "Port number", &my_port, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_U16 },
+         { "--count", "-c", "Count value", &my_count, (void *)1000, RTE_ARGPARSE_VALUE_OPTIONAL, RTE_ARGPARSE_VALUE_TYPE_U32 },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+String Type
+^^^^^^^^^^^
+
+String arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_STR``.
+When using this type, the input value is saved to the provided pointer without any parsing or validation.
+
+.. code-block:: C
+
+   static const char *my_string;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--name", "-n", "Name string", &my_string, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_STR },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+Boolean Type
+^^^^^^^^^^^^
+
+Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept the following input formats:
+
+- ``true``, ``false`` (case-sensitive)
+- ``1``, ``0`` (numeric format)
+
+.. code-block:: C
+
+   static bool my_flag;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--enable", "-e", "Enable feature", &my_flag, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_BOOL },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -167,8 +236,8 @@ It could also choose to use callback to parse,
 just define a unique index for the argument
 and make the ``val_save`` field to be NULL also zero value-type.
 
-In the above example, the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp``
-both use this way.
+In the example at the top of this section,
+the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp`` all use this way.
 
 Multiple times argument
 ~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.48.1
#99 lore raw

PATCH v8 5/18 argparse: add support for parsing core lists

In reply to Bruce Richardson

Core lists are widely used in DPDK, so add support for parsing them.

---
 app/test/test_argparse.c               | 188 +++++++++++++++++++++++++
 doc/guides/prog_guide/argparse_lib.rst |  32 +++++
 lib/argparse/rte_argparse.c            |  63 +++++++++
 lib/argparse/rte_argparse.h            |   2 +
 4 files changed, 285 insertions(+)
app/test/test_argparse.c +188 -0
index 0a229752fa..c829ea75e4 100644
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_argparse.h>
+#include <rte_os.h>
 
 #include "test.h"
 
@@ -500,6 +501,40 @@ test_argparse_opt_autosave_parse_int_of_optional_val(void)
 	return 0;
 }
 
+static int
+test_argparse_opt_parse_corelist_of_required_val(void)
+{
+	struct rte_argparse *obj;
+	rte_cpuset_t val_cpuset;
+	char *argv[3];
+	int ret;
+
+	/* test with long option and single core - this is known to work */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--corelist";
+	obj->args[0].name_short = "-c";
+	obj->args[0].val_saver = (void *)&val_cpuset;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_CORELIST;
+	obj->args[1].name_long = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("--corelist");
+	argv[2] = test_strdup("1,3-5");
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse(obj, 3, argv);
+	TEST_ASSERT(ret == 3, "Argparse parse expect success!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(3, &val_cpuset), "Core 3 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(4, &val_cpuset), "Core 4 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in corelist!");
+
+	return 0;
+}
+
 static int
 opt_callback_parse_int_of_no_val(uint32_t index, const char *value, void *opaque)
 {
@@ -782,6 +817,152 @@ test_argparse_pos_callback_parse_int(void)
 	return 0;
 }
 
+static int
+test_argparse_parse_type_corelist(void)
+{
+	char *corelist_valid_single = test_strdup("5");
+	char *corelist_valid_multiple = test_strdup("0,1,5");
+	char *corelist_valid_range = test_strdup("1-5");
+	char *corelist_valid_mixed = test_strdup("0,1,5-10,12-16,18,20");
+	char *corelist_valid_reverse_range = test_strdup("10-5");
+	char *corelist_valid_initial_spaces = test_strdup("   1,2,5-7");
+	char *corelist_valid_empty = test_strdup("");
+	char *corelist_invalid_spaces = test_strdup(" 1 , 2 , 5-7 ");
+	char *corelist_invalid_letters = test_strdup("1,a,3");
+	char *corelist_invalid_range_incomplete = test_strdup("1-");
+	char *corelist_invalid_range_double_dash = test_strdup("1--5");
+	char *corelist_invalid_special_chars = test_strdup("1,2@3");
+	char *corelist_invalid_comma_only = test_strdup(",");
+	char *corelist_invalid_out_of_range = test_strdup("70000");
+	rte_cpuset_t val_cpuset;
+	int ret;
+
+	/* test valid single core */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_single,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (single core) failed!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(1, &val_cpuset), "Core 1 should not be set in corelist!");
+
+	/* test valid multiple cores */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_multiple,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (multiple cores) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(3, &val_cpuset), "Core 3 should not be set in corelist!");
+
+	/* test valid range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (range) failed!");
+	for (int i = 1; i <= 5; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 1-5!", i);
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in range 1-5!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in range 1-5!");
+
+	/* test valid mixed corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_mixed,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (mixed) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in mixed corelist!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 5-10!", i);
+	for (int i = 12; i <= 16; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 12-16!", i);
+
+	TEST_ASSERT(CPU_ISSET(18, &val_cpuset), "Core 18 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(20, &val_cpuset), "Core 20 should be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(17, &val_cpuset), "Core 17 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(19, &val_cpuset), "Core 19 should not be set in mixed corelist!");
+
+	/* test valid reverse range (10-5 should be interpreted as 5-10) */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_reverse_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (reverse range) failed!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in reverse range 10-5!", i);
+	TEST_ASSERT(!CPU_ISSET(4, &val_cpuset), "Core 4 should not be set in reverse range 10-5!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in reverse range 10-5!");
+
+	/* test valid corelist with initial spaces only */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_initial_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (with initial spaces) failed!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in initial spaced corelist!");
+	TEST_ASSERT(CPU_ISSET(2, &val_cpuset), "Core 2 should be set in initial spaced corelist!");
+	for (int i = 5; i <= 7; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in initial spaced range 5-7!", i);
+
+	/* test valid empty corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_empty,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (empty) failed!");
+	/* Verify that no cores are set in empty corelist */
+	for (int i = 0; i < CPU_SETSIZE; i++)
+		TEST_ASSERT(!CPU_ISSET(i, &val_cpuset),
+				"Core %d should not be set in empty corelist!", i);
+
+	/* test invalid corelist with spaces */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with spaces) should have failed!");
+
+	/* test invalid corelist with letters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_letters,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with letters) should have failed!");
+
+	/* test invalid corelist with incomplete range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_incomplete,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (incomplete range) should have failed!");
+
+	/* test invalid corelist with double dash */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_double_dash,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (double dash) should have failed!");
+
+	/* test invalid corelist with special characters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_special_chars,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (special chars) should have failed!");
+
+	/* test invalid comma-only corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_comma_only,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (comma only) should have failed!");
+
+	/* test invalid out-of-range corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_out_of_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (out of range) should have failed!");
+
+	return 0;
+}
+
 static int
 test_argparse_parse_type(void)
 {
@@ -880,6 +1061,12 @@ test_argparse_parse_type(void)
 	ret = rte_argparse_parse_type(bool_numeric_invalid, RTE_ARGPARSE_VALUE_TYPE_BOOL,
 			&val_bool);
 	TEST_ASSERT(ret != 0, "Argparse parse type for bool (numeric invalid) passed unexpectedly!");
+
+	/* test for corelist parsing */
+	ret = test_argparse_parse_type_corelist();
+	if (ret != 0)
+		return ret;
+
 	return 0;
 }
 
@@ -900,6 +1087,7 @@ static struct unit_test_suite argparse_test_suite = {
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_optional_val),
+		TEST_CASE(test_argparse_opt_parse_corelist_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_optional_val),
doc/guides/prog_guide/argparse_lib.rst +32 -0
index 7868af5672..7882d910ab 100644
@@ -229,6 +229,38 @@ Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept t
       },
    };
 
+Corelist Type
+^^^^^^^^^^^^^
+
+The argparse library supports automatic parsing of CPU core lists using the
+``RTE_ARGPARSE_VALUE_TYPE_CORELIST`` value type. This feature allows users to
+specify CPU cores in a flexible format similar to other DPDK applications.
+
+.. code-block:: C
+
+   #include <rte_os.h>  /* for CPU set operations */
+
+   static rte_cpuset_t cores;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--cores", "-c", "CPU cores to use", &cores, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_CORELIST },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+The corelist parsing supports the following input formats:
+
+- **Single core**: ``--cores 5`` (sets core 5)
+- **Multiple cores**: ``--cores 1,2,5`` (sets cores 1, 2, and 5)
+- **Core ranges**: ``--cores 1-5`` (sets cores 1, 2, 3, 4, and 5)
+- **Mixed format**: ``--cores 0,2-4,7`` (sets cores 0, 2, 3, 4, and 7)
+- **Reverse ranges**: ``--cores 5-1`` (equivalent to 1-5, sets cores 1, 2, 3, 4, and 5)
+- **Empty corelist**: ``--cores ""`` (sets no cores)
+
+The parsed result is stored in an ``rte_cpuset_t`` structure that can be used
+with standard CPU set operations:
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
lib/argparse/rte_argparse.c +63 -0

90 lines not on this page · raw message

lib/argparse/rte_argparse.h +2 -0
index 63b49ba220..991f084927 100644
@@ -69,6 +69,8 @@ enum rte_argparse_value_type {
 	RTE_ARGPARSE_VALUE_TYPE_STR,
 	/** The argument's value is boolean flag type. */
 	RTE_ARGPARSE_VALUE_TYPE_BOOL,
+	/** The argument's value is a corelist */
+	RTE_ARGPARSE_VALUE_TYPE_CORELIST,
 };
 
 /** Additional flags which may be specified for each argument */
Signature · 1 line
2.48.1
#100 lore raw

PATCH v8 6/18 eal: add long options for each short option

In reply to Bruce Richardson

To simplify future rework of the EAL arg handling, add a long-option equivalent for each short option that doesn't already have one.

When updating the docs with the new long options, standardize the format of options which have both short and long variants, and drop the deprecated service-coremask option from the docs, rather than adding its new long option.

---
 doc/guides/linux_gsg/eal_args.include.rst | 20 ++++++++------------
 lib/eal/common/eal_common_options.c       |  8 ++++++++
 lib/eal/common/eal_options.h              | 16 ++++++++++++++++
 3 files changed, 32 insertions(+), 12 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +8 -12
index 9ced54af40..0b17879d42 100644
@@ -4,7 +4,7 @@
 Lcore-related options
 ~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-l/--lcores <core list>``
+*   ``-l, --lcores <core list>``
 
     List of cores to run on
 
@@ -71,11 +71,7 @@ Lcore-related options
 
     Core ID that is used as main.
 
-*   ``-s <service core mask>``
-
-    Hexadecimal bitmask of cores to be used as service cores.
-
-*   ``-S <service core list>``
+*   ``-S, --service-corelist <service core list>``
 
     List of cores to be used as service cores.
 
@@ -108,7 +104,7 @@ Device-related options
 
        --vdev 'net_pcap0,rx_pcap=input.pcap,tx_pcap=output.pcap'
 
-*   ``-d <path to shared object or directory>``
+*   ``-d, --driver-path <path to shared object or directory>``
 
     Load external drivers. An argument can be a single shared object file, or a
     directory containing multiple driver shared objects. Multiple -d options are
@@ -134,15 +130,15 @@ Multiprocessing-related options
 Memory-related options
 ~~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-n <number of channels>``
+*   ``-n, --memory-channels <number of channels>``
 
     Set the number of memory channels to use.
 
-*   ``-r <number of ranks>``
+*   ``-r, --memory-ranks <number of ranks>``
 
     Set the number of memory ranks (auto-detected by default).
 
-*   ``-m <megabytes>``
+*   ``-m, --memory-size <megabytes>``
 
     Amount of memory to preallocate at startup.
 
@@ -236,11 +232,11 @@ Debugging options
 Other options
 ~~~~~~~~~~~~~
 
-*   ``-h``, ``--help``
+*   ``-h, --help``
 
     Display help message listing all EAL parameters.
 
-*   ``-v``
+*   ``-v, --version``
 
     Display the version information on startup.
 
lib/eal/common/eal_common_options.c +8 -0
index 2f91b96190..675745d610 100644
@@ -66,7 +66,9 @@ eal_short_options[] =
 const struct option
 eal_long_options[] = {
 	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
+	{OPT_COREMASK,          1, NULL, OPT_COREMASK_NUM        },
 	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
+	{OPT_DRIVER_PATH,       1, NULL, OPT_DRIVER_PATH_NUM     },
 	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
 	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
 	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
@@ -76,6 +78,11 @@ eal_long_options[] = {
 	{OPT_LOG_COLOR,		2, NULL, OPT_LOG_COLOR_NUM	  },
 	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
 	{OPT_LOG_TIMESTAMP,     2, NULL, OPT_LOG_TIMESTAMP_NUM    },
+	{OPT_MEMORY_CHANNELS,   1, NULL, OPT_MEMORY_CHANNELS_NUM },
+	{OPT_MEMORY_RANKS,      1, NULL, OPT_MEMORY_RANKS_NUM    },
+	{OPT_MEMORY_SIZE,       1, NULL, OPT_MEMORY_SIZE_NUM     },
+	{OPT_SERVICE_CORELIST,  1, NULL, OPT_SERVICE_CORELIST_NUM },
+	{OPT_SERVICE_COREMASK,  1, NULL, OPT_SERVICE_COREMASK_NUM },
 	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
 	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
 	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
@@ -109,6 +116,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_VERSION,           0, NULL, OPT_VERSION_NUM         },
 
 	{0,                     0, NULL, 0                        }
 };
lib/eal/common/eal_options.h +16 -0
index 7a56aa3810..6ef45559f0 100644
@@ -17,8 +17,24 @@ enum {
 	OPT_DEV_ALLOW_NUM       = 'a',
 #define OPT_DEV_BLOCK         "block"
 	OPT_DEV_BLOCK_NUM      = 'b',
+#define OPT_COREMASK          "coremask"
+	OPT_COREMASK_NUM       = 'c',
+#define OPT_DRIVER_PATH       "driver-path"
+	OPT_DRIVER_PATH_NUM    = 'd',
 #define OPT_LCORES            "lcores"
 	OPT_LCORES_NUM         = 'l',
+#define OPT_MEMORY_SIZE       "memory-size"
+	OPT_MEMORY_SIZE_NUM    = 'm',
+#define OPT_MEMORY_CHANNELS   "memory-channels"
+	OPT_MEMORY_CHANNELS_NUM = 'n',
+#define OPT_MEMORY_RANKS     "memory-ranks"
+	OPT_MEMORY_RANKS_NUM   = 'r',
+#define OPT_SERVICE_COREMASK  "service-coremask"
+	OPT_SERVICE_COREMASK_NUM = 's',
+#define OPT_SERVICE_CORELIST  "service-corelist"
+	OPT_SERVICE_CORELIST_NUM = 'S',
+#define OPT_VERSION           "version"
+	OPT_VERSION_NUM        = 'v',
 
 	/* first long only option value must be >= 256, so that we won't
 	 * conflict with short options */
Signature · 1 line
2.48.1
#101 lore raw

PATCH v8 7/18 eal: define the EAL parameters in argparse format

In reply to Bruce Richardson

Create eal_option_list.h, containing all the possible EAL parameters, and basic info about them, such as type, whether they take a parameter or not. Each entry is defined using a macro, which will be then interpreted when the file is included.

First time this header in included in the eal_common_options.c file, the macros are defined in such a way as to define field elements for an "eal_init_args" structure, where each value is either a string type, if it takes a parameter, or boolean type if it doesn't. For those elements that take multiple values, i.e. are passed multiple times, we put them in a TAILQ.

The second time of inclusion, the macros are defined so as to define the arguments in an rte_argparse structure for EAL. For the basic string and boolean types, we just store the values in the appropriate field in the previous defined "eal_init_args" structure. For the list elements, we use the argparse callback to process those elements, adding them to the TAILQ as they are encountered.

---
 lib/eal/common/eal_common_options.c | 141 +++++++++++++++++++++++++++-
 lib/eal/common/eal_option_list.h    |  90 ++++++++++++++++++
 lib/eal/meson.build                 |   2 +-
 lib/meson.build                     |   1 +
 4 files changed, 230 insertions(+), 4 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h
lib/eal/common/eal_common_options.c +138 -3
index 675745d610..75d42d97aa 100644
@@ -10,6 +10,7 @@
 #include <limits.h>
 #include <errno.h>
 #include <getopt.h>
+#include <sys/queue.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <dlfcn.h>
 #include <libgen.h>
@@ -33,6 +34,7 @@
 #endif
 #include <rte_vect.h>
 
+#include <rte_argparse.h>
 #include <eal_export.h>
 #include "eal_internal_cfg.h"
 #include "eal_options.h"
@@ -47,6 +49,142 @@
 #define LCORE_OPT_LST 1
 #define LCORE_OPT_MSK 2
 
+/* Allow the application to print its usage message too if set */
+static rte_usage_hook_t rte_application_usage_hook;
+
+struct arg_list_elem {
+	TAILQ_ENTRY(arg_list_elem) next;
+	char *arg;
+};
+TAILQ_HEAD(arg_list, arg_list_elem);
+
+struct eal_init_args {
+	/* define a struct member for each EAL option, member name is the same as option name.
+	 * Parameters that take an argument e.g. -l, are char *,
+	 * parameters that take no options e.g. --no-huge, are bool.
+	 * parameters that can be given multiple times e.g. -a, are arg_lists,
+	 * parameters that are optional e.g. --huge-unlink,
+	 *   are char * but are set to (void *)1 if the parameter is not given.
+	 * for aliases, i.e. options under different names, no field needs to be output
+	 */
+#define LIST_ARG(long, short, help_str, fieldname) struct arg_list fieldname;
+#define STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define OPT_STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define BOOL_ARG(long, short, help_str, fieldname) bool fieldname;
+#define STR_ALIAS(long, short, help_str, fieldname)
+
+#define INCLUDE_ALL_ARG 1  /* for struct definition, include even unsupported values */
+#include "eal_option_list.h"
+#undef INCLUDE_ALL_ARG
+};
+struct eal_init_args args;
+
+/* an rte_argparse callback to append the argument to an arg_list
+ * in args. The index is the offset into the struct of the list.
+ */
+static int
+arg_list_callback(uint32_t index, const char *arg, void *init_args)
+{
+	struct arg_list *list = RTE_PTR_ADD(init_args, index);
+	struct arg_list_elem *elem;
+
+	elem = malloc(sizeof(*elem));
+	if (elem == NULL)
+		return -1;
+
+	elem->arg = strdup(arg);
+	if (elem->arg == NULL) {
+		free(elem);
+		return -1;
+	}
+
+	TAILQ_INSERT_TAIL(list, elem, next);
+	return 0;
+}
+
+static void
+eal_usage(const struct rte_argparse *obj)
+{
+	rte_argparse_print_help(stdout, obj);
+	if (rte_application_usage_hook != NULL)
+		rte_application_usage_hook(obj->prog_name);
+}
+
+/* undef the *_ARG macros before redefining to generate the argparse arg list */
+#undef LIST_ARG
+#undef STR_ARG
+#undef OPT_STR_ARG
+#undef BOOL_ARG
+#undef STR_ALIAS
+
+/* For arguments which have an arg_list type, they use callback (no val_saver),
+ * require a value, and have the SUPPORT_MULTI flag.
+ */
+#define LIST_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_set = (void *)offsetof(struct eal_init_args, fieldname), \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.flags = RTE_ARGPARSE_FLAG_SUPPORT_MULTI, \
+},
+/* For arguments which have a string type, they use val_saver (no callback),
+ * and normally REQUIRED_VALUE.
+ */
+#define STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For flags which have optional arguments, they use both val_saver and val_set,
+ * but still have a string type.
+ */
+#define OPT_STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_OPTIONAL, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For boolean arguments, they use val_saver and val_set, with NO_VALUE flag.
+ */
+#define BOOL_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_NONE, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_BOOL, \
+},
+#define STR_ALIAS STR_ARG
+
+#if RTE_VER_RELEASE == 99
+#define GUIDES_PATH "https://doc.dpdk.org/guides-" RTE_STR(RTE_VER_YEAR) "." RTE_STR(RTE_VER_MONTH)
+#else
+#define GUIDES_PATH "https://doc.dpdk.org/guides"
+#endif
+
+struct rte_argparse eal_argparse  = {
+	.prog_name = "",
+	.usage = "<DPDK EAL options> -- <App options>",
+	.epilog = "For more information on EAL options, see the DPDK documentation at: \n"
+			"\t" GUIDES_PATH "/" RTE_EXEC_ENV_NAME "_gsg/",
+	.exit_on_error = true,
+	.callback = arg_list_callback,
+	.print_help = eal_usage,
+	.opaque = &args,
+	.args = {
+		#include "eal_option_list.h"
+		ARGPARSE_ARG_END(),
+	}
+};
+
 const char
 eal_short_options[] =
 	"a:" /* allow */
@@ -164,9 +302,6 @@ static int main_lcore_parsed;
 static int mem_parsed;
 static int core_parsed;
 
-/* Allow the application to print its usage message too if set */
-static rte_usage_hook_t rte_application_usage_hook;
-
 /* Returns rte_usage_hook_t */
 rte_usage_hook_t
 eal_get_application_usage_hook(void)
lib/eal/common/eal_option_list.h new file +90 -0

90 lines not on this page · raw message

lib/eal/meson.build +1 -1
index e1d6c4cf17..f9fcee24ee 100644
@@ -14,7 +14,7 @@ subdir(exec_env)
 
 subdir(arch_subdir)
 
-deps += ['log', 'kvargs']
+deps += ['argparse', 'kvargs']
 if not is_windows
     deps += ['telemetry']
 endif
lib/meson.build +1 -0
index a67efaf718..a28d81d3e3 100644
@@ -71,6 +71,7 @@ libraries = [
 ]
 
 always_enable = [
+        'argparse',
         'cmdline',
         'eal',
         'ethdev',
Signature · 1 line
2.48.1
#102 lore raw

PATCH v8 8/18 eal: gather EAL args before processing

In reply to Bruce Richardson

DPDK traditionally has iterated through all args and processed them as they appear in the commandline. The arg processing logic can be simplified if instead we initially gather all arguments into a structure which is then processed with the arguments dealt with in a fixed/known order.

---
 lib/eal/common/eal_common_options.c | 880 ++++++++++++++--------------
 lib/eal/common/eal_options.h        |  10 +-
 lib/eal/common/eal_private.h        |  11 +
 lib/eal/freebsd/eal.c               | 164 +-----
 lib/eal/linux/eal.c                 | 379 +-----------
 lib/eal/windows/eal.c               | 113 +---
 6 files changed, 485 insertions(+), 1072 deletions(-)
lib/eal/common/eal_common_options.c +426 -454
index 75d42d97aa..72df7c5b48 100644
@@ -46,8 +46,7 @@
 #endif
 
 #define BITS_PER_HEX 4
-#define LCORE_OPT_LST 1
-#define LCORE_OPT_MSK 2
+#define NUMA_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
 
 /* Allow the application to print its usage message too if set */
 static rte_usage_hook_t rte_application_usage_hook;
@@ -185,79 +184,33 @@ struct rte_argparse eal_argparse  = {
 	}
 };
 
-const char
-eal_short_options[] =
-	"a:" /* allow */
-	"b:" /* block */
-	"c:" /* coremask */
-	"s:" /* service coremask */
-	"d:" /* driver */
-	"h"  /* help */
-	"l:" /* corelist */
-	"S:" /* service corelist */
-	"m:" /* memory size */
-	"n:" /* memory channels */
-	"r:" /* memory ranks */
-	"v"  /* version */
-	;
-
-const struct option
-eal_long_options[] = {
-	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
-	{OPT_COREMASK,          1, NULL, OPT_COREMASK_NUM        },
-	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
-	{OPT_DRIVER_PATH,       1, NULL, OPT_DRIVER_PATH_NUM     },
-	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
-	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
-	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
-	{OPT_HUGE_UNLINK,       2, NULL, OPT_HUGE_UNLINK_NUM      },
-	{OPT_IOVA_MODE,	        1, NULL, OPT_IOVA_MODE_NUM        },
-	{OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
-	{OPT_LOG_COLOR,		2, NULL, OPT_LOG_COLOR_NUM	  },
-	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
-	{OPT_LOG_TIMESTAMP,     2, NULL, OPT_LOG_TIMESTAMP_NUM    },
-	{OPT_MEMORY_CHANNELS,   1, NULL, OPT_MEMORY_CHANNELS_NUM },
-	{OPT_MEMORY_RANKS,      1, NULL, OPT_MEMORY_RANKS_NUM    },
-	{OPT_MEMORY_SIZE,       1, NULL, OPT_MEMORY_SIZE_NUM     },
-	{OPT_SERVICE_CORELIST,  1, NULL, OPT_SERVICE_CORELIST_NUM },
-	{OPT_SERVICE_COREMASK,  1, NULL, OPT_SERVICE_COREMASK_NUM },
-	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
-	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
-	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
-	{OPT_TRACE_MODE,        1, NULL, OPT_TRACE_MODE_NUM       },
-	{OPT_MAIN_LCORE,        1, NULL, OPT_MAIN_LCORE_NUM       },
-	{OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
-	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
-	{OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
-	{OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
-	{OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
-	{OPT_IN_MEMORY,         0, NULL, OPT_IN_MEMORY_NUM        },
-	{OPT_DEV_BLOCK,         1, NULL, OPT_DEV_BLOCK_NUM        },
-	{OPT_DEV_ALLOW,		1, NULL, OPT_DEV_ALLOW_NUM	  },
-	{OPT_PROC_TYPE,         1, NULL, OPT_PROC_TYPE_NUM        },
-	/* socket-mem/socket-limit are kept for backwards compatibility */
-	{OPT_SOCKET_MEM,        1, NULL, OPT_NUMA_MEM_NUM         },
-	{OPT_SOCKET_LIMIT,      1, NULL, OPT_NUMA_LIMIT_NUM       },
-	{OPT_NUMA_MEM,          1, NULL, OPT_NUMA_MEM_NUM         },
-	{OPT_NUMA_LIMIT,        1, NULL, OPT_NUMA_LIMIT_NUM       },
-#ifndef RTE_EXEC_ENV_WINDOWS
-	{OPT_SYSLOG,            2, NULL, OPT_SYSLOG_NUM           },
-#endif
-	{OPT_VDEV,              1, NULL, OPT_VDEV_NUM             },
-	{OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
-	{OPT_VFIO_VF_TOKEN,     1, NULL, OPT_VFIO_VF_TOKEN_NUM    },
-	{OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
-	{OPT_LEGACY_MEM,        0, NULL, OPT_LEGACY_MEM_NUM       },
-	{OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
-	{OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
-	{OPT_TELEMETRY,         0, NULL, OPT_TELEMETRY_NUM        },
-	{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_VERSION,           0, NULL, OPT_VERSION_NUM         },
-
-	{0,                     0, NULL, 0                        }
-};
+/* function to call into argparse library to parse the passed argc/argv parameters
+ * to the eal_init_args structure.
+ */
+int
+eal_collate_args(int argc, char **argv)
+{
+	if (argc < 1 || argv == NULL)
+		return -EINVAL;
+
+	/* initialize the list of arguments */
+	memset(&args, 0, sizeof(args));
+	TAILQ_INIT(&args.allow);
+	TAILQ_INIT(&args.block);
+	TAILQ_INIT(&args.driver_path);
+	TAILQ_INIT(&args.log_level);
+	TAILQ_INIT(&args.trace);
+	TAILQ_INIT(&args.vdev);
+
+	/* parse the arguments */
+	eal_argparse.prog_name = argv[0];
+	int retval = rte_argparse_parse(&eal_argparse, argc, argv);
+	if (retval < 0)
+		return retval;
+
+	argv[retval - 1] = argv[0];
+	return retval - 1;
+}
 
 TAILQ_HEAD(shared_driver_list, shared_driver);
 
@@ -299,7 +252,6 @@ static struct device_option_list devopt_list =
 TAILQ_HEAD_INITIALIZER(devopt_list);
 
 static int main_lcore_parsed;
-static int mem_parsed;
 static int core_parsed;
 
 /* Returns rte_usage_hook_t */
@@ -323,7 +275,12 @@ rte_set_application_usage_hook(rte_usage_hook_t usage_func)
 	return old_func;
 }
 
-#ifndef RTE_EXEC_ENV_WINDOWS
+#ifdef RTE_EXEC_ENV_WINDOWS
+
+int
+eal_save_args(__rte_unused int argc, __rte_unused char **argv) { return 0; }
+
+#else /* RTE_EXEC_ENV_WINDOWS */
 static char **eal_args;
 static char **eal_app_args;
 
@@ -411,7 +368,7 @@ eal_save_args(int argc, char **argv)
 	eal_args = NULL;
 	return -1;
 }
-#endif
+#endif /* !RTE_EXEC_ENV_WINDOWS */
 
 static int
 eal_option_device_add(enum rte_devtype type, const char *optarg)
@@ -839,17 +796,6 @@ eal_parse_service_coremask(const char *coremask)
 	return 0;
 }
 
-static int
-eal_service_cores_parsed(void)
-{
-	int idx;
-	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		if (lcore_config[idx].core_role == ROLE_SERVICE)
-			return 1;
-	}
-	return 0;
-}
-
 static int
 update_lcore_config(int *cores)
 {
@@ -1676,361 +1622,487 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out)
 	return -1;
 }
 
-bool
-eal_option_is_log(int opt)
+/* Parse all arguments looking for log related ones */
+int
+eal_parse_log_options(void)
 {
-	switch (opt) {
-	case OPT_LOG_COLOR_NUM:
-	case OPT_LOG_LEVEL_NUM:
-	case OPT_LOG_TIMESTAMP_NUM:
-	case OPT_SYSLOG_NUM:
-		return true;
-	default:
-		return false;
+	struct arg_list_elem *arg;
+	TAILQ_FOREACH(arg, &args.log_level, next) {
+		if (eal_parse_log_level(arg->arg) < 0) {
+			EAL_LOG(ERR, "invalid log-level parameter");
+			return -1;
+		}
+	}
+	if (args.log_color != NULL) {
+		/* if value is 1, no argument specified, so pass NULL */
+		if (args.log_color == (void *)1)
+			args.log_color = NULL;
+		if (eal_log_color(args.log_color) < 0) {
+			EAL_LOG(ERR, "invalid log-color parameter");
+			return -1;
+		}
+	}
+	if (args.log_timestamp != NULL) {
+		/* similarly log_timestamp may be 1 */
+		if (args.log_timestamp == (void *)1)
+			args.log_timestamp = NULL;
+		if (eal_log_timestamp(args.log_timestamp) < 0) {
+			EAL_LOG(ERR, "invalid log-timestamp parameter");
+			return -1;
+		}
+	}
+	if (args.syslog != NULL) {
+#ifdef RTE_EXEC_ENV_WINDOWS
+		EAL_LOG(WARNING, "syslog is not supported on Windows, ignoring parameter");
+#else
+		/* also syslog parameter may be 1 */
+		if (args.syslog == (void *)1)
+			args.syslog = NULL;
+		if (eal_log_syslog(args.syslog) < 0) {
+			EAL_LOG(ERR, "invalid syslog parameter");
+			return -1;
+		}
+#endif
 	}
+	return 0;
 }
 
-/* Parse all arguments looking for log related ones */
-int
-eal_parse_log_options(int argc, char * const argv[])
+static int
+eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
 {
-	struct internal_config *internal_conf = eal_get_internal_configuration();
-	int option_index, opt;
-	const int old_optind = optind;
-	const int old_optopt = optopt;
-	const int old_opterr = opterr;
-	char *old_optarg = optarg;
-#ifdef RTE_EXEC_ENV_FREEBSD
-	const int old_optreset = optreset;
-	optreset = 1;
-#endif
+	char *arg[RTE_MAX_NUMA_NODES];
+	char *end;
+	int arg_num, i, len;
 
-	optind = 1;
-	opterr = 0;
+	len = strnlen(strval, NUMA_MEM_STRLEN);
+	if (len == NUMA_MEM_STRLEN) {
+		EAL_LOG(ERR, "--numa-mem/--socket-mem parameter is too long");
+		return -1;
+	}
 
-	while ((opt = getopt_long(argc, argv, eal_short_options,
-				  eal_long_options, &option_index)) != EOF) {
+	/* all other error cases will be caught later */
+	if (!isdigit(strval[len-1]))
+		return -1;
 
-		if (!eal_option_is_log(opt))
-			continue;
+	/* split the optarg into separate socket values */
+	arg_num = rte_strsplit(strval, len,
+			arg, RTE_MAX_NUMA_NODES, ',');
 
-		if (eal_parse_common_option(opt, optarg, internal_conf) < 0)
+	/* if split failed, or 0 arguments */
+	if (arg_num <= 0)
+		return -1;
+
+	/* parse each defined socket option */
+	errno = 0;
+	for (i = 0; i < arg_num; i++) {
+		uint64_t val;
+		end = NULL;
+		val = strtoull(arg[i], &end, 10);
+
+		/* check for invalid input */
+		if ((errno != 0)  ||
+				(arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
 			return -1;
+		val <<= 20;
+		socket_arg[i] = val;
 	}
 
-	/* restore getopt lib */
-	optind = old_optind;
-	optopt = old_optopt;
-	optarg = old_optarg;
-	opterr = old_opterr;
-#ifdef RTE_EXEC_ENV_FREEBSD
-	optreset = old_optreset;
+	return 0;
+}
+
+static int
+eal_parse_vfio_intr(const char *mode)
+{
+	struct internal_config *internal_conf =
+		eal_get_internal_configuration();
+	static struct {
+		const char *name;
+		enum rte_intr_mode value;
+	} map[] = {
+		{ "legacy", RTE_INTR_MODE_LEGACY },
+		{ "msi", RTE_INTR_MODE_MSI },
+		{ "msix", RTE_INTR_MODE_MSIX },
+	};
+
+	for (size_t i = 0; i < RTE_DIM(map); i++) {
+		if (!strcmp(mode, map[i].name)) {
+			internal_conf->vfio_intr_mode = map[i].value;
+			return 0;
+		}
+	}
+	return -1;
+}
+
+static int
+eal_parse_vfio_vf_token(const char *vf_token)
+{
+	struct internal_config *cfg = eal_get_internal_configuration();
+	rte_uuid_t uuid;
+
+	if (!rte_uuid_parse(vf_token, uuid)) {
+		rte_uuid_copy(cfg->vfio_vf_token, uuid);
+		return 0;
+	}
+
+	return -1;
+}
+
+static int
+eal_parse_huge_worker_stack(const char *arg)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	EAL_LOG(WARNING, "Cannot set worker stack size on Windows, parameter ignored");
+	RTE_SET_USED(arg);
+#else
+	struct internal_config *cfg = eal_get_internal_configuration();
+
+	if (arg == NULL || arg[0] == '\0') {
+		pthread_attr_t attr;
+		int ret;
+
+		if (pthread_attr_init(&attr) != 0) {
+			EAL_LOG(ERR, "Could not retrieve default stack size");
+			return -1;
+		}
+		ret = pthread_attr_getstacksize(&attr, &cfg->huge_worker_stack_size);
+		pthread_attr_destroy(&attr);
+		if (ret != 0) {
+			EAL_LOG(ERR, "Could not retrieve default stack size");
+			return -1;
+		}
+	} else {
+		unsigned long stack_size;
+		char *end;
+
+		errno = 0;
+		stack_size = strtoul(arg, &end, 10);
+		if (errno || end == NULL || stack_size == 0 ||
+				stack_size >= (size_t)-1 / 1024)
+			return -1;
+
+		cfg->huge_worker_stack_size = stack_size * 1024;
+	}
+
+	EAL_LOG(DEBUG, "Each worker thread will use %zu kB of DPDK memory as stack",
+		cfg->huge_worker_stack_size / 1024);
 #endif
 	return 0;
 }
 
+/* Parse the arguments given in the command line of the application */
 int
-eal_parse_common_option(int opt, const char *optarg,
-			struct internal_config *conf)
+eal_parse_args(void)
 {
-	static int b_used;
-	static int a_used;
-
-	switch (opt) {
-	case 'b':
-		if (a_used)
-			goto ba_conflict;
-		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0)
+	struct internal_config *int_cfg = eal_get_internal_configuration();
+	struct arg_list_elem *arg;
+
+	/* check for conflicting options */
+	/* both -a and -b cannot be used together (one list must be empty at least) */
+	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
+		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
+		return -1;
+	}
+	/* both -l and -c cannot be used at the same time */
+	if (args.coremask != NULL && args.lcores != NULL) {
+		EAL_LOG(ERR, "Options coremask (-c) and core list (-l) can't be used at the same time");
+		return -1;
+	}
+	/* both -s and -S cannot be used at the same time */
+	if (args.service_coremask != NULL && args.service_corelist != NULL) {
+		EAL_LOG(ERR, "Options service coremask (-s) and service core list (-S) can't be used at the same time");
+		return -1;
+	}
+	/* can't have both telemetry and no-telemetry */
+	if (args.no_telemetry && args.telemetry) {
+		EAL_LOG(ERR, "Options telemetry and no-telemetry can't be used at the same time");
+		return -1;
+	}
+	/* can't have both -m and --socket-mem */
+	if (args.memory_size != NULL && args.numa_mem != NULL) {
+		EAL_LOG(ERR, "Options -m and --socket-mem can't be used at the same time");
+		return -1;
+	}
+
+	/* parse options */
+	/* print version before anything else */
+	if (args.version) {
+		/* since message is explicitly requested by user, we write message
+		 * at highest log level so it can always be seen even if info or
+		 * warning messages are disabled
+		 */
+		EAL_LOG(CRIT, "RTE Version: '%s'", rte_version());
+	}
+
+	/* parse the process type */
+	if (args.proc_type != NULL) {
+		int_cfg->process_type = eal_parse_proc_type(args.proc_type);
+		if (int_cfg->process_type == RTE_PROC_INVALID) {
+			EAL_LOG(ERR, "invalid process type: %s", args.proc_type);
 			return -1;
-		b_used = 1;
-		break;
+		}
+	}
 
-	case 'a':
-		if (b_used)
-			goto ba_conflict;
-		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0)
+	/* device -a/-b/-vdev options*/
+	TAILQ_FOREACH(arg, &args.allow, next)
+		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, arg->arg) < 0)
 			return -1;
-		a_used = 1;
-		break;
-	/* coremask */
-	case 'c': {
+	TAILQ_FOREACH(arg, &args.block, next)
+		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, arg->arg) < 0)
+			return -1;
+	TAILQ_FOREACH(arg, &args.vdev, next)
+		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL, arg->arg) < 0)
+			return -1;
+	/* driver loading options */
+	TAILQ_FOREACH(arg, &args.driver_path, next)
+		if (eal_plugin_add(arg->arg) < 0)
+			return -1;
+
+	/* parse the coremask /core-list */
+	if (args.coremask != NULL) {
 		int lcore_indexes[RTE_MAX_LCORE];
 
-		if (eal_service_cores_parsed())
-			EAL_LOG(WARNING,
-				"Service cores parsed before dataplane cores. Please ensure -c is before -s or -S");
-		if (rte_eal_parse_coremask(optarg, lcore_indexes) < 0) {
+		if (rte_eal_parse_coremask(args.coremask, lcore_indexes) < 0) {
 			EAL_LOG(ERR, "invalid coremask syntax");
 			return -1;
 		}
 		if (update_lcore_config(lcore_indexes) < 0) {
 			char *available = available_cores();
 
-			EAL_LOG(ERR,
-				"invalid coremask, please check specified cores are part of %s",
-				available);
+			EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
+					args.coremask, available);
 			free(available);
 			return -1;
 		}
-
-		if (core_parsed) {
-			if (core_parsed == LCORE_OPT_MSK)
-				EAL_LOG(ERR, "Option '-c' passed multiple times to EAL");
-			else
-				EAL_LOG(ERR, "Option -c is ignored, because option -l/--lcores used");
+		core_parsed = 1;
+	} else if (args.lcores != NULL) {
+		if (eal_parse_lcores(args.lcores) < 0) {
+			EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
 			return -1;
 		}
-
-		core_parsed = LCORE_OPT_MSK;
-		break;
+		core_parsed = 1;
 	}
-	/* corelist */
-	case 'l': {
-		if (eal_service_cores_parsed())
-			EAL_LOG(WARNING,
-				"Service cores parsed before dataplane cores. Please ensure -l is before -s or -S");
-
-		if (eal_parse_lcores(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for -l/--" OPT_LCORES);
+	if (args.main_lcore != NULL) {
+		if (eal_parse_main_lcore(args.main_lcore) < 0) {
+			EAL_LOG(ERR, "invalid main-lcore parameter");
 			return -1;
 		}
+	}
 
-		if (core_parsed) {
-			if (core_parsed == LCORE_OPT_LST)
-				EAL_LOG(ERR, "Core list option passed multiple times to EAL");
-			else
-				EAL_LOG(ERR, "Option '-l/--lcores' is ignored, because coremask option used");
+	/* service core options */
+	if (args.service_coremask != NULL) {
+		if (eal_parse_service_coremask(args.service_coremask) < 0) {
+			EAL_LOG(ERR, "invalid service coremask: '%s'",
+					args.service_coremask);
 			return -1;
 		}
+	} else if (args.service_corelist != NULL) {
+		if (eal_parse_service_corelist(args.service_corelist) < 0) {
+			EAL_LOG(ERR, "invalid service core list: '%s'",
+					args.service_corelist);
+			return -1;
+		}
+	}
 
-		core_parsed = LCORE_OPT_LST;
-		break;
+	/* memory options */
+	if (args.memory_size != NULL) {
+		int_cfg->memory = atoi(args.memory_size);
+		int_cfg->memory *= 1024ULL;
+		int_cfg->memory *= 1024ULL;
 	}
-	/* service coremask */
-	case 's':
-		if (eal_parse_service_coremask(optarg) < 0) {
-			EAL_LOG(ERR, "invalid service coremask");
+	if (args.memory_channels != NULL) {
+		int_cfg->force_nchannel = atoi(args.memory_channels);
+		if (int_cfg->force_nchannel == 0) {
+			EAL_LOG(ERR, "invalid memory channel parameter");
 			return -1;
 		}
-		break;
-	/* service corelist */
-	case 'S':
-		if (eal_parse_service_corelist(optarg) < 0) {
-			EAL_LOG(ERR, "invalid service core list");
+	}
+	if (args.memory_ranks != NULL) {
+		int_cfg->force_nrank = atoi(args.memory_ranks);
+		if (int_cfg->force_nrank == 0 || int_cfg->force_nrank > 16) {
+			EAL_LOG(ERR, "invalid memory rank parameter");
 			return -1;
 		}
-		break;
-	/* size of memory */
-	case 'm':
-		conf->memory = atoi(optarg);
-		conf->memory *= 1024ULL;
-		conf->memory *= 1024ULL;
-		mem_parsed = 1;
-		break;
-	/* force number of channels */
-	case 'n':
-		conf->force_nchannel = atoi(optarg);
-		if (conf->force_nchannel == 0) {
-			EAL_LOG(ERR, "invalid channel number");
+	}
+	if (args.huge_unlink != NULL) {
+		if (args.huge_unlink == (void *)1)
+			args.huge_unlink = NULL;
+		if (eal_parse_huge_unlink(args.huge_unlink, &int_cfg->hugepage_file) < 0) {
+			EAL_LOG(ERR, "invalid huge-unlink parameter");
 			return -1;
 		}
-		break;
-	/* force number of ranks */
-	case 'r':
-		conf->force_nrank = atoi(optarg);
-		if (conf->force_nrank == 0 ||
-		    conf->force_nrank > 16) {
-			EAL_LOG(ERR, "invalid rank number");
+	}
+	if (args.no_huge) {
+		int_cfg->no_hugetlbfs = 1;
+		/* no-huge is legacy mem */
+		int_cfg->legacy_mem = 1;
+	}
+	if (args.in_memory) {
+		int_cfg->in_memory = 1;
+		/* in-memory is a superset of noshconf and huge-unlink */
+		int_cfg->no_shconf = 1;
+		int_cfg->hugepage_file.unlink_before_mapping = true;
+	}
+	if (args.legacy_mem)
+		int_cfg->legacy_mem = 1;
+	if (args.single_file_segments)
+		int_cfg->single_file_segments = 1;
+	if (args.huge_dir != NULL) {
+		free(int_cfg->hugepage_dir);  /* free old hugepage dir */
+		int_cfg->hugepage_dir = strdup(args.huge_dir);
+		if (int_cfg->hugepage_dir == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for hugepage dir parameter");
 			return -1;
 		}
-		break;
-	/* force loading of external driver */
-	case 'd':
-		if (eal_plugin_add(optarg) == -1)
+	}
+	if (args.file_prefix != NULL) {
+		free(int_cfg->hugefile_prefix);  /* free old file prefix */
+		int_cfg->hugefile_prefix = strdup(args.file_prefix);
+		if (int_cfg->hugefile_prefix == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for file prefix parameter");
 			return -1;
-		break;
-	case 'v':
-		/* since message is explicitly requested by user, we
-		 * write message at highest log level so it can always
-		 * be seen
-		 * even if info or warning messages are disabled */
-		EAL_LOG(CRIT, "RTE Version: '%s'", rte_version());
-		break;
-
-	/* long options */
-	case OPT_HUGE_UNLINK_NUM:
-		if (eal_parse_huge_unlink(optarg, &conf->hugepage_file) < 0) {
-			EAL_LOG(ERR, "invalid --"OPT_HUGE_UNLINK" option");
+		}
+	}
+	if (args.numa_mem != NULL) {
+		if (eal_parse_socket_arg(args.numa_mem, int_cfg->numa_mem) < 0) {
+			EAL_LOG(ERR, "invalid numa-mem parameter: '%s'", args.numa_mem);
 			return -1;
 		}
-		break;
-
-	case OPT_NO_HUGE_NUM:
-		conf->no_hugetlbfs = 1;
-		/* no-huge is legacy mem */
-		conf->legacy_mem = 1;
-		break;
-
-	case OPT_NO_PCI_NUM:
-		conf->no_pci = 1;
-		break;
-
-	case OPT_NO_HPET_NUM:
-		conf->no_hpet = 1;
-		break;
-
-	case OPT_VMWARE_TSC_MAP_NUM:
-		conf->vmware_tsc_map = 1;
-		break;
-
-	case OPT_NO_SHCONF_NUM:
-		conf->no_shconf = 1;
-		break;
-
-	case OPT_IN_MEMORY_NUM:
-		conf->in_memory = 1;
-		/* in-memory is a superset of noshconf and huge-unlink */
-		conf->no_shconf = 1;
-		conf->hugepage_file.unlink_before_mapping = true;
-		break;
-
-	case OPT_PROC_TYPE_NUM:
-		conf->process_type = eal_parse_proc_type(optarg);
-		break;
-
-	case OPT_MAIN_LCORE_NUM:
-		if (eal_parse_main_lcore(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_MAIN_LCORE);
+		int_cfg->force_numa = 1;
+	}
+	if (args.numa_limit != NULL) {
+		if (eal_parse_socket_arg(args.numa_limit, int_cfg->numa_limit) < 0) {
+			EAL_LOG(ERR, "invalid numa-limit parameter: '%s'", args.numa_limit);
 			return -1;
 		}
-		break;
+		int_cfg->force_numa_limits = 1;
+	}
 
-	case OPT_VDEV_NUM:
-		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
-				optarg) < 0) {
+	/* tracing settings, not supported on windows */
+#ifdef RTE_EXEC_ENV_WINDOWS
+	if (!TAILQ_EMPTY(&args.trace) ||
+			args.trace_dir != NULL ||
+			args.trace_bufsz != NULL ||
+			args.trace_mode != NULL)
+		EAL_LOG(WARNING, "Tracing is not supported on Windows, ignoring tracing parameters");
+#else
+	TAILQ_FOREACH(arg, &args.trace, next) {
+		if (eal_trace_args_save(arg->arg) < 0) {
+			EAL_LOG(ERR, "invalid trace parameter, '%s'", arg->arg);
 			return -1;
 		}
-		break;
-
-#ifndef RTE_EXEC_ENV_WINDOWS
-	case OPT_SYSLOG_NUM:
-		if (eal_log_syslog(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-					OPT_SYSLOG);
+	}
+	if (args.trace_dir != NULL) {
+		if (eal_trace_dir_args_save(args.trace_dir) < 0) {
+			EAL_LOG(ERR, "invalid trace directory, '%s'", args.trace_dir);
 			return -1;
 		}
-		break;
-#endif
-
-	case OPT_LOG_LEVEL_NUM:
-		if (eal_parse_log_level(optarg) < 0) {
-			EAL_LOG(ERR,
-				"invalid parameters for --"
-				OPT_LOG_LEVEL);
+	}
+	if (args.trace_bufsz != NULL) {
+		if (eal_trace_bufsz_args_save(args.trace_bufsz) < 0) {
+			EAL_LOG(ERR, "invalid trace buffer size, '%s'", args.trace_bufsz);
 			return -1;
 		}
-		break;
-
-	case OPT_LOG_TIMESTAMP_NUM:
-		if (eal_log_timestamp(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_LOG_TIMESTAMP);
+	}
+	if (args.trace_mode != NULL) {
+		if (eal_trace_mode_args_save(args.trace_mode) < 0) {
+			EAL_LOG(ERR, "invalid trace mode, '%s'", args.trace_mode);
 			return -1;
 		}
-		break;
+	}
+#endif
 
-	case OPT_LOG_COLOR_NUM:
-		if (eal_log_color(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_LOG_COLOR);
+	/* simple flag settings
+	 * Only set these to 1, as we don't want to set them to 0 in case
+	 * other options above have already set them.
+	 */
+	if (args.no_pci)
+		int_cfg->no_pci = 1;
+	if (args.no_hpet)
+		int_cfg->no_hpet = 1;
+	if (args.vmware_tsc_map)
+		int_cfg->vmware_tsc_map = 1;
+	if (args.no_shconf)
+		int_cfg->no_shconf = 1;
+	if (args.no_telemetry)
+		int_cfg->no_telemetry = 1;
+	if (args.match_allocations)
+		int_cfg->match_allocations = 1;
+	if (args.create_uio_dev)
+		int_cfg->create_uio_dev = 1;
+
+
+	/* other misc settings */
+	if (args.iova_mode != NULL) {
+		if (eal_parse_iova_mode(args.iova_mode) < 0) {
+			EAL_LOG(ERR, "invalid iova mode parameter '%s'", args.iova_mode);
 			return -1;
 		}
-		break;
-
-#ifndef RTE_EXEC_ENV_WINDOWS
-	case OPT_TRACE_NUM: {
-		if (eal_trace_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE);
+	};
+	if (args.base_virtaddr != NULL) {
+		if (eal_parse_base_virtaddr(args.base_virtaddr) < 0) {
+			EAL_LOG(ERR, "invalid base virtaddr '%s'", args.base_virtaddr);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_DIR_NUM: {
-		if (eal_trace_dir_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_DIR);
+	if (args.force_max_simd_bitwidth != NULL) {
+		if (eal_parse_simd_bitwidth(args.force_max_simd_bitwidth) < 0) {
+			EAL_LOG(ERR, "invalid SIMD bitwidth parameter '%s'",
+					args.force_max_simd_bitwidth);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_BUF_SIZE_NUM: {
-		if (eal_trace_bufsz_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_BUF_SIZE);
+	if (args.vfio_intr != NULL) {
+		if (eal_parse_vfio_intr(args.vfio_intr) < 0) {
+			EAL_LOG(ERR, "invalid vfio interrupt parameter: '%s'", args.vfio_intr);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_MODE_NUM: {
-		if (eal_trace_mode_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_MODE);
+	if (args.vfio_vf_token != NULL) {
+		if (eal_parse_vfio_vf_token(args.vfio_vf_token) < 0) {
+			EAL_LOG(ERR, "invalid vfio vf token parameter: '%s'", args.vfio_vf_token);
 			return -1;
 		}
-		break;
 	}
-#endif /* !RTE_EXEC_ENV_WINDOWS */
 
-	case OPT_LEGACY_MEM_NUM:
-		conf->legacy_mem = 1;
-		break;
-	case OPT_SINGLE_FILE_SEGMENTS_NUM:
-		conf->single_file_segments = 1;
-		break;
-	case OPT_IOVA_MODE_NUM:
-		if (eal_parse_iova_mode(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_IOVA_MODE);
+	if (args.huge_worker_stack != NULL) {
+		if (args.huge_worker_stack == (void *)1)
+			args.huge_worker_stack = NULL;
+		if (eal_parse_huge_worker_stack(args.huge_worker_stack) < 0) {
+			EAL_LOG(ERR, "invalid huge worker stack parameter");
 			return -1;
 		}
-		break;
-	case OPT_BASE_VIRTADDR_NUM:
-		if (eal_parse_base_virtaddr(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_BASE_VIRTADDR);
+	}
+	if (args.mbuf_pool_ops_name != NULL) {
+		free(int_cfg->user_mbuf_pool_ops_name); /* free old ops name */
+		int_cfg->user_mbuf_pool_ops_name = strdup(args.mbuf_pool_ops_name);
+		if (int_cfg->user_mbuf_pool_ops_name == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for mbuf pool ops name parameter");
 			return -1;
 		}
-		break;
-	case OPT_TELEMETRY_NUM:
-		break;
-	case OPT_NO_TELEMETRY_NUM:
-		conf->no_telemetry = 1;
-		break;
-	case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM:
-		if (eal_parse_simd_bitwidth(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_FORCE_MAX_SIMD_BITWIDTH);
+	}
+
+#ifndef RTE_EXEC_ENV_WINDOWS
+	/* create runtime data directory. In no_shconf mode, skip any errors */
+	if (eal_create_runtime_dir() < 0) {
+		if (int_cfg->no_shconf == 0) {
+			EAL_LOG(ERR, "Cannot create runtime directory");
 			return -1;
 		}
-		break;
+		EAL_LOG(WARNING, "No DPDK runtime directory created");
+	}
+#endif
 
-	/* don't know what to do, leave this to caller */
-	default:
-		return 1;
+	if (eal_adjust_config(int_cfg) != 0) {
+		EAL_LOG(ERR, "Invalid configuration");
+		return -1;
+	}
 
+	if (eal_check_common_options(int_cfg) != 0) {
+		EAL_LOG(ERR, "Checking common options failed");
+		return -1;
 	}
 
 	return 0;
-
-ba_conflict:
-	EAL_LOG(ERR,
-		"Options allow (-a) and block (-b) can't be used at the same time");
-	return -1;
 }
 
 static void
@@ -2163,13 +2235,8 @@ eal_check_common_options(struct internal_config *internal_cfg)
 			"option");
 		return -1;
 	}
-	if (mem_parsed && internal_cfg->force_numa == 1) {
-		EAL_LOG(ERR, "Options -m and --"OPT_NUMA_MEM" cannot "
-			"be specified at the same time");
-		return -1;
-	}
 	if (internal_cfg->no_hugetlbfs && internal_cfg->force_numa == 1) {
-		EAL_LOG(ERR, "Option --"OPT_NUMA_MEM" cannot "
+		EAL_LOG(ERR, "Option --"OPT_SOCKET_MEM" cannot "
 			"be specified together with --"OPT_NO_HUGE);
 		return -1;
 	}
@@ -2255,98 +2322,3 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 	internal_conf->max_simd_bitwidth.bitwidth = bitwidth;
 	return 0;
 }
-
-void
-eal_common_usage(void)
-{
-	printf("[options]\n\n"
-	       "EAL common options:\n"
-	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
-	       "  -l, --"OPT_LCORES" CORELIST\n"
-	       "                      List of cores to run on\n"
-	       "                      The basic argument format is <c1>[-c2][,c3[-c4],...]\n"
-	       "                      where c1, c2, etc are core indexes between 0 and %d\n"
-	       "                      Can also be used to map lcore set to physical CPU set\n"
-	       "                      The argument format is\n"
-	       "                            '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
-	       "                      lcores and cpus list are grouped by '(' and ')'\n"
-	       "                      Within the group, '-' is used for range separator,\n"
-	       "                      ',' is used for single number separator.\n"
-	       "                      '( )' can be omitted for single element group,\n"
-	       "                      '@' can be omitted if cpus and lcores have the same value\n"
-	       "  -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
-	       "  -S SERVICE CORELIST List of cores to run services on\n"
-	       "  --"OPT_MAIN_LCORE" ID     Core ID that is used as main\n"
-	       "  --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
-	       "  -n CHANNELS         Number of memory channels\n"
-	       "  -m MB               Memory to allocate (see also --"OPT_NUMA_MEM")\n"
-	       "  -r RANKS            Force number of memory ranks (don't detect)\n"
-	       "  -b, --block         Add a device to the blocked list.\n"
-	       "                      Prevent EAL from using this device. The argument\n"
-	       "                      format for PCI devices is <domain:bus:devid.func>.\n"
-	       "  -a, --allow         Add a device to the allow list.\n"
-	       "                      Only use the specified devices. The argument format\n"
-	       "                      for PCI devices is <[domain:]bus:devid.func>.\n"
-	       "                      This option can be present several times.\n"
-	       "                      [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n"
-	       "  --"OPT_VDEV"              Add a virtual device.\n"
-	       "                      The argument format is <driver><id>[,key=val,...]\n"
-	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
-	       "                      'va' for IOVA_VA\n"
-	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
-	       "                      (can be used multiple times)\n"
-	       "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
-	       "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
-#ifndef RTE_EXEC_ENV_WINDOWS
-	       "  --"OPT_SYSLOG"[=<facility>] Enable use of syslog (and optionally set facility)\n"
-#endif
-	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
-	       "                      Set specific log level\n"
-	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
-	       "  --"OPT_LOG_TIMESTAMP"[=<format>]  Timestamp log output\n"
-	       "  --"OPT_LOG_COLOR"[=<when>] Colorize log messages\n"
-#ifndef RTE_EXEC_ENV_WINDOWS
-	       "  --"OPT_TRACE"=<regex-match>\n"
-	       "                      Enable trace based on regular expression trace name.\n"
-	       "                      By default, the trace is disabled.\n"
-	       "		      User must specify this option to enable trace.\n"
-	       "  --"OPT_TRACE_DIR"=<directory path>\n"
-	       "                      Specify trace directory for trace output.\n"
-	       "                      By default, trace output will created at\n"
-	       "                      $HOME directory and parameter must be\n"
-	       "                      specified once only.\n"
-	       "  --"OPT_TRACE_BUF_SIZE"=<int>\n"
-	       "                      Specify maximum size of allocated memory\n"
-	       "                      for trace output for each thread. Valid\n"
-	       "                      unit can be either 'B|K|M' for 'Bytes',\n"
-	       "                      'KBytes' and 'MBytes' respectively.\n"
-	       "                      Default is 1MB and parameter must be\n"
-	       "                      specified once only.\n"
-	       "  --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
-	       "                      Specify the mode of update of trace\n"
-	       "                      output file. Either update on a file can\n"
-	       "                      be wrapped or discarded when file size\n"
-	       "                      reaches its maximum limit.\n"
-	       "                      Default mode is 'overwrite' and parameter\n"
-	       "                      must be specified once only.\n"
-#endif /* !RTE_EXEC_ENV_WINDOWS */
-	       "  -v                  Display version information on startup\n"
-	       "  -h, --"OPT_HELP"          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
-	       "                      disable secondary process support\n"
-	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
-	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
-	       "\nEAL options for DEBUG use only:\n"
-	       "  --"OPT_HUGE_UNLINK"[=existing|always|never]\n"
-	       "                      When to unlink files in hugetlbfs\n"
-	       "                      ('existing' by default, no value means 'always')\n"
-	       "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
-	       "  --"OPT_NO_PCI"            Disable PCI\n"
-	       "  --"OPT_NO_HPET"           Disable HPET\n"
-	       "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
-	       "\n", RTE_MAX_LCORE);
-}
lib/eal/common/eal_options.h +2 -8
index 6ef45559f0..c4d2cc84dc 100644
@@ -115,18 +115,12 @@ enum {
 	OPT_LONG_MAX_NUM
 };
 
-extern const char eal_short_options[];
-extern const struct option eal_long_options[];
-
-bool eal_option_is_log(int opt);
-int eal_parse_log_options(int argc, char * const argv[]);
-int eal_parse_common_option(int opt, const char *argv,
-			    struct internal_config *conf);
+int eal_parse_log_options(void);
+int eal_parse_args(void);
 int eal_option_device_parse(void);
 int eal_adjust_config(struct internal_config *internal_cfg);
 int eal_cleanup_config(struct internal_config *internal_cfg);
 int eal_check_common_options(struct internal_config *internal_cfg);
-void eal_common_usage(void);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
lib/eal/common/eal_private.h +11 -0
index 5846917cc5..ab8b37b956 100644
@@ -72,6 +72,17 @@ struct rte_config {
  */
 struct rte_config *rte_eal_get_configuration(void);
 
+/**
+ * Put the argument list into a structure.
+ *
+ * This allows the arguments to then be processed out-of-order.
+ *
+ * @return
+ *  - 0 on success
+ * - Negative on error
+ */
+int eal_collate_args(int argc, char **argv);
+
 /**
  * Initialize the memzone subsystem (private to eal).
  *
lib/eal/freebsd/eal.c +17 -147

213 lines not on this page · raw message

lib/eal/linux/eal.c +13 -366

410 lines not on this page · raw message

lib/eal/windows/eal.c +16 -97

132 lines not on this page · raw message

Signature · 1 line
2.48.1
#103 lore raw

PATCH v8 9/18 eal: ensure proper cleanup on EAL init failure

In reply to Bruce Richardson

When rte_eal_init fails part way through, any saved EAL arguments need to be freed, and the run_once flag needs to be set back to zero again. The former task was never done on failure, and the latter was only done on some occasions. Rework the error handling to always go to an err_out label where cleanup is done.

To prevent memory leaks from the saved arguments when eal_init is called twice, the check for multiple calls must be done first before the argument saving and parsing is done.

This patch modifies all three eal.c files. Windows doesn't actually need changes, since there are no args saved, and no run_once sentinel value, but updating it keeps it consistent with FreeBSD and Linux versions.

---
 lib/eal/common/eal_common_options.c | 37 ++++++++----
 lib/eal/common/eal_options.h        |  1 +
 lib/eal/freebsd/eal.c               | 83 +++++++++++++-------------
 lib/eal/linux/eal.c                 | 90 ++++++++++++++---------------
 lib/eal/windows/eal.c               | 47 ++++++++-------
 5 files changed, 137 insertions(+), 121 deletions(-)
lib/eal/common/eal_common_options.c +25 -12
index 72df7c5b48..e3e3deb7f4 100644
@@ -279,6 +279,8 @@ rte_set_application_usage_hook(rte_usage_hook_t usage_func)
 
 int
 eal_save_args(__rte_unused int argc, __rte_unused char **argv) { return 0; }
+void
+eal_clean_saved_args(void) { /* no-op */ }
 
 #else /* RTE_EXEC_ENV_WINDOWS */
 static char **eal_args;
@@ -310,6 +312,28 @@ handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 	return used;
 }
 
+void
+eal_clean_saved_args(void)
+{
+	int i;
+
+	if (eal_args == NULL)
+		return;
+
+	if (eal_app_args != NULL) {
+		i = 0;
+		while (eal_app_args[i] != NULL)
+			free(eal_app_args[i++]);
+		free(eal_app_args);
+		eal_app_args = NULL;
+	}
+	i = 0;
+	while (eal_args[i] != NULL)
+		free(eal_args[i++]);
+	free(eal_args);
+	eal_args = NULL;
+}
+
 int
 eal_save_args(int argc, char **argv)
 {
@@ -354,18 +378,7 @@ eal_save_args(int argc, char **argv)
 	return 0;
 
 error:
-	if (eal_app_args != NULL) {
-		i = 0;
-		while (eal_app_args[i] != NULL)
-			free(eal_app_args[i++]);
-		free(eal_app_args);
-		eal_app_args = NULL;
-	}
-	i = 0;
-	while (eal_args[i] != NULL)
-		free(eal_args[i++]);
-	free(eal_args);
-	eal_args = NULL;
+	eal_clean_saved_args();
 	return -1;
 }
 #endif /* !RTE_EXEC_ENV_WINDOWS */
lib/eal/common/eal_options.h +1 -0
index c4d2cc84dc..fd28111e73 100644
@@ -124,6 +124,7 @@ int eal_check_common_options(struct internal_config *internal_cfg);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
+void eal_clean_saved_args(void);
 int handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 		struct rte_tel_data *d);
 
lib/eal/freebsd/eal.c +41 -42

255 lines not on this page · raw message

lib/eal/linux/eal.c +45 -45

271 lines not on this page · raw message

lib/eal/windows/eal.c +25 -22

176 lines not on this page · raw message

Signature · 1 line
2.48.1
#104 lore raw

PATCH v8 10/18 eal: combine parameter validation checks

In reply to Bruce Richardson

Remove the separate function to check combinations of cmdline parameters. Instead, just do those checks when parsing the parameters since we have all info about what parameters are provided at that point.

---
 lib/eal/common/eal_common_memory.c  |   3 +-
 lib/eal/common/eal_common_options.c | 262 +++++++++++-----------------
 lib/eal/common/eal_options.h        | 107 ------------
 lib/eal/linux/eal.c                 |   5 +-
 lib/eal/linux/eal_memory.c          |   2 +-
 5 files changed, 106 insertions(+), 273 deletions(-)
lib/eal/common/eal_common_memory.c +1 -2
index 38ccc734e8..c62edf5e55 100644
@@ -258,8 +258,7 @@ eal_memseg_list_alloc(struct rte_memseg_list *msl, int reserve_flags)
 		 * including common code, so don't duplicate the message.
 		 */
 		if (rte_errno == EADDRNOTAVAIL)
-			EAL_LOG(ERR, "Cannot reserve %llu bytes at [%p] - "
-				"please use '--" OPT_BASE_VIRTADDR "' option",
+			EAL_LOG(ERR, "Cannot reserve %llu bytes at [%p] - please use '--base-virtaddr' option",
 				(unsigned long long)mem_sz, msl->base_va);
 #endif
 		return -1;
lib/eal/common/eal_common_options.c +102 -160

390 lines not on this page · raw message

lib/eal/common/eal_options.h +0 -107

118 lines not on this page · raw message

lib/eal/linux/eal.c +2 -3
index 3359f29e8b..1b4372323d 100644
@@ -329,9 +329,8 @@ rte_eal_config_reattach(void)
 	if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
 		if (mem_config != MAP_FAILED) {
 			/* errno is stale, don't use */
-			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p]"
-				" - please use '--" OPT_BASE_VIRTADDR
-				"' option", rte_mem_cfg_addr, mem_config);
+			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p] - please use '--base-virtaddr' option",
+				 rte_mem_cfg_addr, mem_config);
 			munmap(mem_config, sizeof(struct rte_mem_config));
 			return -1;
 		}
lib/eal/linux/eal_memory.c +1 -1
index ee964446c7..8e1763e890 100644
@@ -1960,7 +1960,7 @@ rte_eal_memseg_init(void)
 	if (!internal_conf->legacy_mem && rte_socket_count() > 1) {
 		EAL_LOG(WARNING, "DPDK is running on a NUMA system, but is compiled without NUMA support.");
 		EAL_LOG(WARNING, "This will have adverse consequences for performance and usability.");
-		EAL_LOG(WARNING, "Please use --"OPT_LEGACY_MEM" option, or recompile with NUMA support.");
+		EAL_LOG(WARNING, "Please use --legacy-mem option, or recompile with NUMA support.");
 	}
 #endif
 
Signature · 1 line
2.48.1
#105 lore raw

PATCH v8 11/18 eal: simplify handling of conflicting cmdline options

In reply to Bruce Richardson

Use a utility function and macro to simplify the code for checking for conflicting cmdline options. The checking can also be done at the initial argument collating stage, shortening the argument processing function which is very much on the long side.

---
 lib/eal/common/eal_common_options.c | 119 +++++++++++-----------------
 1 file changed, 47 insertions(+), 72 deletions(-)
lib/eal/common/eal_common_options.c +47 -72
index b6aeeadd8d..db74bf2c61 100644
@@ -184,6 +184,29 @@ struct rte_argparse eal_argparse  = {
 	}
 };
 
+static inline bool
+conflicting_options(uintptr_t opt1, uintptr_t opt2, const char *opt1_name, const char *opt2_name)
+{
+	char name1[64];  /* should be the max length of any argument */
+	char name2[64];
+
+	strlcpy(name1, opt1_name, sizeof(name1));
+	strlcpy(name2, opt2_name, sizeof(name2));
+	for (int i = 0; name1[i] != '\0'; i++)
+		if (name1[i] == '_')
+			name1[i] = '-';
+	for (int i = 0; name2[i] != '\0'; i++)
+		if (name2[i] == '_')
+			name2[i] = '-';
+	if (opt1 && opt2) {
+		EAL_LOG(ERR, "Options '%s' and '%s' can't be used at the same time", name1, name2);
+		return true;
+	}
+	return false;  /* no conflicts */
+}
+#define CONFLICTING_OPTIONS(args, opt1, opt2) \
+	conflicting_options((uintptr_t)(args.opt1), (uintptr_t)(args.opt2), #opt1, #opt2)
+
 /* function to call into argparse library to parse the passed argc/argv parameters
  * to the eal_init_args structure.
  */
@@ -208,6 +231,30 @@ eal_collate_args(int argc, char **argv)
 	if (retval < 0)
 		return retval;
 
+	/* check for conflicting options */
+	/* both -a and -b cannot be used together (one list must be empty at least) */
+	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
+		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
+		return -1;
+	}
+
+	/* for non-list args, we can just check for zero/null values using macro */
+	if (CONFLICTING_OPTIONS(args, coremask, lcores) ||
+			CONFLICTING_OPTIONS(args, service_coremask, service_corelist) ||
+			CONFLICTING_OPTIONS(args, no_telemetry, telemetry) ||
+			CONFLICTING_OPTIONS(args, memory_size, numa_mem) ||
+			CONFLICTING_OPTIONS(args, no_huge, numa_mem) ||
+			CONFLICTING_OPTIONS(args, no_huge, huge_worker_stack) ||
+			CONFLICTING_OPTIONS(args, numa_limit, legacy_mem) ||
+			CONFLICTING_OPTIONS(args, legacy_mem, in_memory) ||
+			CONFLICTING_OPTIONS(args, legacy_mem, match_allocations) ||
+			CONFLICTING_OPTIONS(args, no_huge, match_allocations) ||
+			CONFLICTING_OPTIONS(args, no_huge, huge_unlink) ||
+			CONFLICTING_OPTIONS(args, single_file_segments, huge_unlink) ||
+			CONFLICTING_OPTIONS(args, no_huge, single_file_segments) ||
+			CONFLICTING_OPTIONS(args, in_memory, huge_unlink))
+		return -1;
+
 	argv[retval - 1] = argv[0];
 	return retval - 1;
 }
@@ -1794,78 +1841,6 @@ eal_parse_args(void)
 	struct rte_config *rte_cfg = rte_eal_get_configuration();
 	struct arg_list_elem *arg;
 
-	/* check for conflicting options */
-	/* both -a and -b cannot be used together (one list must be empty at least) */
-	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
-		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
-		return -1;
-	}
-	/* both -l and -c cannot be used at the same time */
-	if (args.coremask != NULL && args.lcores != NULL) {
-		EAL_LOG(ERR, "Options coremask (-c) and core list (-l) can't be used at the same time");
-		return -1;
-	}
-	/* both -s and -S cannot be used at the same time */
-	if (args.service_coremask != NULL && args.service_corelist != NULL) {
-		EAL_LOG(ERR, "Options service coremask (-s) and service core list (-S) can't be used at the same time");
-		return -1;
-	}
-	/* can't have both telemetry and no-telemetry */
-	if (args.no_telemetry && args.telemetry) {
-		EAL_LOG(ERR, "Options telemetry and no-telemetry can't be used at the same time");
-		return -1;
-	}
-	/* can't have both -m and --socket-mem */
-	if (args.memory_size != NULL && args.numa_mem != NULL) {
-		EAL_LOG(ERR, "Options -m and --numa-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use both no-huge and socket-mem */
-	if (args.no_huge && args.numa_mem) {
-		EAL_LOG(ERR, "Options --no-huge and --numa-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and huge-worker-stack */
-	if (args.huge_worker_stack != NULL && args.no_huge) {
-		EAL_LOG(ERR, "Options --no-huge and --huge-worker-stack can't be used at the same time");
-		return -1;
-	}
-	/* can't use socket-limit and legacy-mem */
-	if (args.numa_limit != NULL && args.legacy_mem) {
-		EAL_LOG(ERR, "Options --numa-limit and --legacy-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use legacy-mem and in-memory */
-	if (args.legacy_mem && args.in_memory) {
-		EAL_LOG(ERR, "Options --legacy-mem and --in-memory can't be used at the same time");
-		return -1;
-	}
-	/* can't use legacy-mem and match-allocations */
-	if (args.legacy_mem && args.match_allocations) {
-		EAL_LOG(ERR, "Options --legacy-mem and --match-allocations can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and match-allocations */
-	if (args.no_huge && args.match_allocations) {
-		EAL_LOG(ERR, "Options --no-huge and --match-allocations can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and huge-unlink */
-	if (args.no_huge && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --no-huge and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-	/* can't use single-file-segments and huge-unlink */
-	if (args.single_file_segments && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --single-file-segments and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-	/* can't use in-memory and huge-unlink */
-	if (args.in_memory && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --in-memory and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-
 	/* print version before anything else */
 	/* since message is explicitly requested by user, we write message
 	 * at highest log level so it can always be seen even if info or
Signature · 1 line
2.48.1
#106 lore raw

PATCH v8 12/18 eal: automatically init arg list options

In reply to Bruce Richardson

The tailq list options from commandline require initialization before being used. This was being done by explicitly initing those values in the collate function. A better option is to do so using macros at time of structure definition, that way, adding a new list option does not require any other code changes to initialize it.

Since we are now including the same header 3 times, and need to undefine the macros between inclusions, we simplify things by just doing the undef calls at the end of the included header.

---
 lib/eal/common/eal_common_options.c | 30 ++++++++++++-----------------
 lib/eal/common/eal_option_list.h    |  7 +++++++
 2 files changed, 19 insertions(+), 18 deletions(-)
lib/eal/common/eal_common_options.c +12 -18
index db74bf2c61..d7a8263f08 100644
@@ -74,9 +74,19 @@ struct eal_init_args {
 
 #define INCLUDE_ALL_ARG 1  /* for struct definition, include even unsupported values */
 #include "eal_option_list.h"
-#undef INCLUDE_ALL_ARG
 };
-struct eal_init_args args;
+
+/* define the structure itself, with initializers. Only the LIST_ARGS need init */
+#define LIST_ARG(long, short, help_str, fieldname) .fieldname = TAILQ_HEAD_INITIALIZER(args.fieldname),
+#define STR_ARG(long, short, help_str, fieldname)
+#define OPT_STR_ARG(long, short, help_str, fieldname)
+#define BOOL_ARG(long, short, help_str, fieldname)
+#define STR_ALIAS(long, short, help_str, fieldname)
+
+struct eal_init_args args = {
+	#include "eal_option_list.h"
+};
+#undef INCLUDE_ALL_ARG
 
 /* an rte_argparse callback to append the argument to an arg_list
  * in args. The index is the offset into the struct of the list.
@@ -109,13 +119,6 @@ eal_usage(const struct rte_argparse *obj)
 		rte_application_usage_hook(obj->prog_name);
 }
 
-/* undef the *_ARG macros before redefining to generate the argparse arg list */
-#undef LIST_ARG
-#undef STR_ARG
-#undef OPT_STR_ARG
-#undef BOOL_ARG
-#undef STR_ALIAS
-
 /* For arguments which have an arg_list type, they use callback (no val_saver),
  * require a value, and have the SUPPORT_MULTI flag.
  */
@@ -216,15 +219,6 @@ eal_collate_args(int argc, char **argv)
 	if (argc < 1 || argv == NULL)
 		return -EINVAL;
 
-	/* initialize the list of arguments */
-	memset(&args, 0, sizeof(args));
-	TAILQ_INIT(&args.allow);
-	TAILQ_INIT(&args.block);
-	TAILQ_INIT(&args.driver_path);
-	TAILQ_INIT(&args.log_level);
-	TAILQ_INIT(&args.trace);
-	TAILQ_INIT(&args.vdev);
-
 	/* parse the arguments */
 	eal_argparse.prog_name = argv[0];
 	int retval = rte_argparse_parse(&eal_argparse, argc, argv);
lib/eal/common/eal_option_list.h +7 -0
index 6a0c501680..f5c21c8376 100644
@@ -88,3 +88,10 @@ STR_ALIAS("--socket-limit", NULL, "Alias for --numa-limit", numa_limit)
 STR_ARG("--vfio-intr", NULL, "VFIO interrupt mode (legacy|msi|msix)", vfio_intr)
 STR_ARG("--vfio-vf-token", NULL, "VF token (UUID) shared between SR-IOV PF and VFs", vfio_vf_token)
 #endif
+
+/* undefine all used defines */
+#undef LIST_ARG
+#undef STR_ARG
+#undef OPT_STR_ARG
+#undef BOOL_ARG
+#undef STR_ALIAS
Signature · 1 line
2.48.1
#107 lore raw

PATCH v8 13/18 eal: add internal fn for converting cpuset to string

In reply to Bruce Richardson

The existing "available_cores" function in eal_common_options.c has general code for converting a set of cores to a printable string. Generalize this code into an "eal_cpuset_to_str" function which takes a cpuset as parameter, and create a new "available_cores" function using this new utility function.

---
 lib/eal/common/eal_common_options.c | 33 ++++++++++++++++++++++-------
 lib/eal/common/eal_private.h        | 10 +++++++++
 2 files changed, 35 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_options.c +25 -8
index d7a8263f08..e89ca615b8 100644
@@ -1570,8 +1570,8 @@ eal_parse_base_virtaddr(const char *arg)
 }
 
 /* caller is responsible for freeing the returned string */
-static char *
-available_cores(void)
+char *
+eal_cpuset_to_str(const rte_cpuset_t *cpuset)
 {
 	char *str = NULL;
 	int previous;
@@ -1579,13 +1579,13 @@ available_cores(void)
 	char *tmp;
 	int idx;
 
-	/* find the first available cpu */
-	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		if (eal_cpu_detected(idx) == 0)
+	/* find the first set cpu */
+	for (idx = 0; idx < CPU_SETSIZE; idx++) {
+		if (!CPU_ISSET(idx, cpuset))
 			continue;
 		break;
 	}
-	if (idx >= RTE_MAX_LCORE)
+	if (idx >= CPU_SETSIZE)
 		return NULL;
 
 	/* first sequence */
@@ -1594,8 +1594,8 @@ available_cores(void)
 	previous = idx;
 	sequence = 0;
 
-	for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
-		if (eal_cpu_detected(idx) == 0)
+	for (idx++ ; idx < CPU_SETSIZE; idx++) {
+		if (!CPU_ISSET(idx, cpuset))
 			continue;
 
 		if (idx == previous + 1) {
@@ -1638,6 +1638,23 @@ available_cores(void)
 	return str;
 }
 
+/* caller is responsible for freeing the returned string */
+static char *
+available_cores(void)
+{
+	rte_cpuset_t cpuset;
+	int idx;
+
+	/* build cpuset of available cores */
+	CPU_ZERO(&cpuset);
+	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
+		if (eal_cpu_detected(idx))
+			CPU_SET(idx, &cpuset);
+	}
+
+	return eal_cpuset_to_str(&cpuset);
+}
+
 #define HUGE_UNLINK_NEVER "never"
 
 static int
lib/eal/common/eal_private.h +10 -0
index ab8b37b956..e032dd10c9 100644
@@ -83,6 +83,16 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int eal_collate_args(int argc, char **argv);
 
+/**
+ * Convert an rte_cpuset_t to string form suitable for parsing by argparse.
+ *
+ * @param cpuset
+ *   The cpuset to convert to string form.
+ * @return
+ *   String representation of the cpuset (caller must free), or NULL on error.
+ */
+char *eal_cpuset_to_str(const rte_cpuset_t *cpuset);
+
 /**
  * Initialize the memzone subsystem (private to eal).
  *
Signature · 1 line
2.48.1
#108 lore raw

PATCH v8 14/18 eal: use common cpuset to string function

In reply to Bruce Richardson

Use the new cpuset to string function to replace other thread-specific functions which did similar work. Also use it for additional debug logs.

---
 lib/eal/common/eal_common_lcore.c   | 13 ++++-----
 lib/eal/common/eal_common_options.c | 22 +++++++++++++++
 lib/eal/common/eal_common_thread.c  | 43 ++++++++---------------------
 lib/eal/common/eal_thread.h         | 13 ++-------
 4 files changed, 42 insertions(+), 49 deletions(-)
lib/eal/common/eal_common_lcore.c +6 -7
index 5c8b0f9aa2..39411f9370 100644
@@ -481,12 +481,11 @@ static int
 lcore_dump_cb(unsigned int lcore_id, void *arg)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
-	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char *cpuset;
 	struct rte_lcore_usage usage;
 	rte_lcore_usage_cb usage_cb;
 	char *usage_str = NULL;
 	FILE *f = arg;
-	int ret;
 
 	/* The callback may not set all the fields in the structure, so clear it here. */
 	memset(&usage, 0, sizeof(usage));
@@ -499,12 +498,12 @@ lcore_dump_cb(unsigned int lcore_id, void *arg)
 			return -ENOMEM;
 		}
 	}
-	ret = eal_thread_dump_affinity(&lcore_config[lcore_id].cpuset, cpuset,
-		sizeof(cpuset));
-	fprintf(f, "lcore %u, socket %u, role %s, cpuset %s%s%s\n", lcore_id,
+	cpuset = eal_cpuset_to_str(&lcore_config[lcore_id].cpuset);
+	fprintf(f, "lcore %u, socket %u, role %s, cpuset %s\n", lcore_id,
 		rte_lcore_to_socket_id(lcore_id),
-		lcore_role_str(cfg->lcore_role[lcore_id]), cpuset,
-		ret == 0 ? "" : "...", usage_str != NULL ? usage_str : "");
+		lcore_role_str(cfg->lcore_role[lcore_id]),
+		cpuset != NULL ? cpuset : "<unknown>");
+	free(cpuset);
 	free(usage_str);
 
 	return 0;
lib/eal/common/eal_common_options.c +22 -0
index e89ca615b8..0f3db158f6 100644
@@ -1049,6 +1049,21 @@ eal_parse_service_corelist(const char *corelist)
 			"Please ensure -c or -l includes service cores");
 	}
 
+	/* log the configured service cores for debugging */
+	rte_cpuset_t service_cpuset;
+	CPU_ZERO(&service_cpuset);
+	for (i = 0; i < RTE_MAX_LCORE; i++) {
+		if (lcore_config[i].core_role == ROLE_SERVICE)
+			CPU_SET(i, &service_cpuset);
+	}
+	if (CPU_COUNT(&service_cpuset) > 0) {
+		char *cpuset_str = eal_cpuset_to_str(&service_cpuset);
+		if (cpuset_str != NULL) {
+			EAL_LOG(DEBUG, "Service cores configured: %s", cpuset_str);
+			free(cpuset_str);
+		}
+	}
+
 	return 0;
 }
 
@@ -2195,6 +2210,13 @@ compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 		memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset,
 			sizeof(*cpuset));
 	}
+
+	/* log the computed control thread cpuset for debugging */
+	char *cpuset_str = eal_cpuset_to_str(cpuset);
+	if (cpuset_str != NULL) {
+		EAL_LOG(DEBUG, "Control threads will use cores: %s", cpuset_str);
+		free(cpuset_str);
+	}
 }
 
 int
lib/eal/common/eal_common_thread.c +12 -31

55 lines not on this page · raw message

lib/eal/common/eal_thread.h +2 -11
index 1c3c3442d3..586de05081 100644
@@ -33,28 +33,19 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);
 #define RTE_CPU_AFFINITY_STR_LEN            256
 
 /**
- * Dump the cpuset as a human readable string.
+ * Dump the current thread cpuset as a human readable string.
  * This function is private to EAL.
  *
  * Note:
  *   If the dump size is greater than the size of given buffer,
  *   the string will be truncated and with '\0' at the end.
  *
- * @param cpuset
- *   The CPU affinity object to dump.
  * @param str
  *   The string buffer the cpuset will dump to.
  * @param size
  *   The string buffer size.
  * @return
- *   0 for success, -1 if truncation happens.
- */
-int
-eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);
-
-/**
- * Dump the current thread cpuset.
- * This is a wrapper on eal_thread_dump_affinity().
+ *   0 for success, -1 if error or truncation happens.
  */
 int
 eal_thread_dump_current_affinity(char *str, unsigned int size);
Signature · 1 line
2.48.1
#109 lore raw

PATCH v8 15/18 eal: introduce lcore remapping option for coremasks

In reply to Bruce Richardson

Add the new "--remap-lcore-ids" or "-R" option to signify that lcore ids are to start at a low range. This takes an optional parameter to specify the value to start from. Initially, use this to adjust the core mappings when using a coremask.

As well as remapping within the range of RTE_MAX_LCORE, to allow use of cores >=RTE_MAX_LCORE we need to expand the internal arrays of cores to be CPU_SETSIZE big, and limit the checks for RTE_MAX_LCORE to only cases where we are not remapping. This requires an additional parameter to the internal API rte_eal_parse_coremask, having a small knock-on effect on DLB driver as the only other user of this API.

---
 drivers/event/dlb2/dlb2_priv.h             |  2 +-
 drivers/event/dlb2/pf/base/dlb2_resource.c |  4 +-
 lib/eal/common/eal_common_options.c        | 54 +++++++++++++++++-----
 lib/eal/common/eal_option_list.h           |  1 +
 lib/eal/include/rte_eal.h                  |  6 ++-
 5 files changed, 50 insertions(+), 17 deletions(-)
drivers/event/dlb2/dlb2_priv.h +1 -1
index 7a5cbcca1e..6e0a5bc936 100644
@@ -750,7 +750,7 @@ void dlb2_event_build_hcws(struct dlb2_port *qm_port,
 			   uint8_t *queue_id);
 
 /* Extern functions */
-extern int rte_eal_parse_coremask(const char *coremask, int *cores);
+extern int rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
 
 /* Extern globals */
 extern struct process_local_port_data dlb2_port[][DLB2_NUM_PORT_TYPES];
drivers/event/dlb2/pf/base/dlb2_resource.c +2 -2
index 98f2f5ef92..6742c470f1 100644
@@ -922,13 +922,13 @@ dlb2_resource_probe(struct dlb2_hw *hw, const void *probe_args)
 {
 	const struct dlb2_devargs *args = (const struct dlb2_devargs *)probe_args;
 	const char *mask = args ? args->producer_coremask : NULL;
-	int cpu = 0, cnt = 0, cores[RTE_MAX_LCORE], i;
+	int cpu = 0, cnt = 0, cores[CPU_SETSIZE], i;
 
 	if (args) {
 		mask = (const char *)args->producer_coremask;
 	}
 
-	if (mask && rte_eal_parse_coremask(mask, cores)) {
+	if (mask && rte_eal_parse_coremask(mask, cores, true)) {
 		DLB2_HW_ERR(hw, ": Invalid producer coremask=%s\n", mask);
 		return -1;
 	}
lib/eal/common/eal_common_options.c +42 -12

118 lines not on this page · raw message

lib/eal/common/eal_option_list.h +1 -0
index f5c21c8376..e4a849e78e 100644
@@ -57,6 +57,7 @@ BOOL_ARG("--no-pci", NULL, "Disable all PCI devices", no_pci)
 BOOL_ARG("--no-shconf", NULL, "Disable shared config file generation", no_shconf)
 BOOL_ARG("--no-telemetry", NULL, "Disable telemetry", no_telemetry)
 STR_ARG("--proc-type", NULL, "Type of process (primary|secondary|auto)", proc_type)
+OPT_STR_ARG("--remap-lcore-ids", "-R", "Remap lcore IDs to be contiguous starting from 0, or supplied value", remap_lcore_ids)
 STR_ARG("--service-corelist", "-S", "List of cores to use for service threads", service_corelist)
 STR_ARG("--service-coremask", "-s", "[Deprecated] Bitmask of cores to use for service threads", service_coremask)
 BOOL_ARG("--single-file-segments", NULL, "Store all pages within single files (per-page-size, per-node)", single_file_segments)
lib/eal/include/rte_eal.h +4 -2
index 08977c61d3..bc58254ece 100644
@@ -503,13 +503,15 @@ rte_eal_get_runtime_dir(void);
  *   A string describing a mask of core ids.
  * @param cores
  *   An array where to store the core ids orders.
- *   This array must be at least RTE_MAX_LCORE large.
+ *   This array must be at least CPU_SETSIZE large.
+ * @param limit_range
+ *   If set, return an error if any cores in the mask are >= RTE_MAX_LCORE.
  * @return
  *   0 on success, -1 if the string content was invalid.
  */
 __rte_internal
 int
-rte_eal_parse_coremask(const char *coremask, int *cores);
+rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.48.1
#110 lore raw

PATCH v8 16/18 eal: rework internal coremask parsing to use cpu sets

In reply to Bruce Richardson

Rather than working off arrays of lcore values, update the coremask handling to use rte_cpuset_t. The use of the array provides no additional value for coremasks, since the order of the bits set will always be from lowest core number to highest, making the tracking of what core was 0, 1, 2 etc. pointless.

As part of this change, move the prototype for the parse_coremask function from rte_eal.h to eal_options.h, for two reasons:

1. This is an internal function that should not be used by apps and so there is no need to have it in a public header.
2. If the compilation command is run without the _GNU_SOURCE flag, we miss definitions from sched.h and so get build errors for the rte_cpuset_t type when compiling examples against an installed DPDK.

---
 drivers/event/dlb2/dlb2_priv.h             |  2 +-
 drivers/event/dlb2/pf/base/dlb2_resource.c | 11 ++++----
 lib/eal/common/eal_common_options.c        | 30 ++++++++--------------
 lib/eal/common/eal_options.h               |  2 ++
 lib/eal/include/rte_eal.h                  | 22 ----------------
 5 files changed, 19 insertions(+), 48 deletions(-)
drivers/event/dlb2/dlb2_priv.h +1 -1
index 6e0a5bc936..607b4d24d0 100644
@@ -750,7 +750,7 @@ void dlb2_event_build_hcws(struct dlb2_port *qm_port,
 			   uint8_t *queue_id);
 
 /* Extern functions */
-extern int rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
+extern int rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_range);
 
 /* Extern globals */
 extern struct process_local_port_data dlb2_port[][DLB2_NUM_PORT_TYPES];
drivers/event/dlb2/pf/base/dlb2_resource.c +6 -5
index 6742c470f1..490dcaf7dd 100644
@@ -922,28 +922,29 @@ dlb2_resource_probe(struct dlb2_hw *hw, const void *probe_args)
 {
 	const struct dlb2_devargs *args = (const struct dlb2_devargs *)probe_args;
 	const char *mask = args ? args->producer_coremask : NULL;
-	int cpu = 0, cnt = 0, cores[CPU_SETSIZE], i;
+	rte_cpuset_t cpuset;
+	int cpu = 0, cnt = 0, i, set_count = 0;
 
 	if (args) {
 		mask = (const char *)args->producer_coremask;
 	}
 
-	if (mask && rte_eal_parse_coremask(mask, cores, true)) {
+	if (mask && rte_eal_parse_coremask(mask, &cpuset, true)) {
 		DLB2_HW_ERR(hw, ": Invalid producer coremask=%s\n", mask);
 		return -1;
 	}
 
 	hw->num_prod_cores = 0;
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		bool is_pcore = (mask && cores[i] != -1);
+		bool is_pcore = (mask && CPU_ISSET(i, &cpuset));
 
 		if (rte_lcore_is_enabled(i)) {
 			if (is_pcore) {
 				/*
 				 * Populate the producer cores from parsed
-				 * coremask
+				 * coremask using the set_count as index.
 				 */
-				hw->prod_core_list[cores[i]] = i;
+				hw->prod_core_list[set_count++] = i;
 				hw->num_prod_cores++;
 
 			} else if ((++cnt == DLB2_EAL_PROBE_CORE ||
lib/eal/common/eal_common_options.c +10 -20
index 95081c9f54..86351535ee 100644
@@ -841,7 +841,7 @@ eal_parse_service_coremask(const char *coremask)
 }
 
 static int
-update_lcore_config(int *cores, bool remap, uint16_t remap_base)
+update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
 	unsigned int count = 0;
@@ -855,9 +855,9 @@ update_lcore_config(int *cores, bool remap, uint16_t remap_base)
 		lcore_config[i].core_index = -1;
 	}
 
-	/* now go through the core mask */
+	/* now go through the cpuset */
 	for (i = 0; i < CPU_SETSIZE; i++) {
-		if (cores[i] != -1) {
+		if (CPU_ISSET(i, cpuset)) {
 			if (eal_cpu_detected(i) == 0) {
 				EAL_LOG(ERR, "lcore %u unavailable", i);
 				ret = -1;
@@ -866,7 +866,7 @@ update_lcore_config(int *cores, bool remap, uint16_t remap_base)
 			if (!remap)
 				lcore_id = i;
 			cfg->lcore_role[lcore_id] = ROLE_RTE;
-			lcore_config[lcore_id].core_index = cores[i];
+			lcore_config[lcore_id].core_index = count;
 			CPU_ZERO(&lcore_config[lcore_id].cpuset);
 			CPU_SET(i, &lcore_config[lcore_id].cpuset);
 			EAL_LOG(DEBUG, "lcore %u mapped to physical core %u", lcore_id, i);
@@ -919,7 +919,7 @@ check_core_list(int *lcores, unsigned int count)
 
 RTE_EXPORT_INTERNAL_SYMBOL(rte_eal_parse_coremask)
 int
-rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
+rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_range)
 {
 	const char *coremask_orig = coremask;
 	int lcores[CPU_SETSIZE];
@@ -928,8 +928,7 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
 	int val;
 	char c;
 
-	for (idx = 0; idx < CPU_SETSIZE; idx++)
-		cores[idx] = -1;
+	CPU_ZERO(cpuset);
 	idx = 0;
 
 	EAL_LOG(WARNING, "'-c <coremask>' option is deprecated, and will be removed in a future release");
@@ -975,6 +974,7 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
 					return -1;
 				}
 				lcores[count++] = idx;
+				CPU_SET(idx, cpuset);
 			}
 		}
 	}
@@ -988,16 +988,6 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
 	if (limit_range && check_core_list(lcores, count) != 0)
 		return -1;
 
-	/*
-	 * Now that we've got a list of cores no longer than RTE_MAX_LCORE,
-	 * and no lcore in that list is greater than RTE_MAX_LCORE, populate
-	 * the cores array.
-	 */
-	do {
-		count--;
-		cores[lcores[count]] = count;
-	} while (count != 0);
-
 	return 0;
 }
 
@@ -1931,13 +1921,13 @@ eal_parse_args(void)
 
 	/* parse the core list arguments */
 	if (args.coremask != NULL) {
-		int lcore_indexes[CPU_SETSIZE];
+		rte_cpuset_t cpuset;
 
-		if (rte_eal_parse_coremask(args.coremask, lcore_indexes, !remap_lcores) < 0) {
+		if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) {
 			EAL_LOG(ERR, "invalid coremask syntax");
 			return -1;
 		}
-		if (update_lcore_config(lcore_indexes, remap_lcores, lcore_id_base) < 0) {
+		if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
 			char *available = available_cores();
 
 			EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
lib/eal/common/eal_options.h +2 -0
index 4a8a0f1df7..f5e7905609 100644
@@ -20,5 +20,7 @@ int eal_save_args(int argc, char **argv);
 void eal_clean_saved_args(void);
 int handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 		struct rte_tel_data *d);
+__rte_internal
+int rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_range);
 
 #endif /* EAL_OPTIONS_H */
lib/eal/include/rte_eal.h +0 -22
index bc58254ece..619b8fbade 100644
@@ -491,28 +491,6 @@ rte_eal_mbuf_user_pool_ops(void);
 const char *
 rte_eal_get_runtime_dir(void);
 
-/**
- * Convert a string describing a mask of core ids into an array of core ids.
- *
- * On success, the passed array is filled with the orders of the core ids
- * present in the mask (-1 indicating that a core id is absent).
- * For example, passing a 0xa coremask results in cores[1] = 0, cores[3] = 1,
- * and the rest of the array is set to -1.
- *
- * @param coremask
- *   A string describing a mask of core ids.
- * @param cores
- *   An array where to store the core ids orders.
- *   This array must be at least CPU_SETSIZE large.
- * @param limit_range
- *   If set, return an error if any cores in the mask are >= RTE_MAX_LCORE.
- * @return
- *   0 on success, -1 if the string content was invalid.
- */
-__rte_internal
-int
-rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
-
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
2.48.1
#111 lore raw

PATCH v8 17/18 eal: allow lcore id remapping with core lists

In reply to Bruce Richardson

Allow the "-R" flag to be used with core lists so that we can specify lists with core ids >= RTE_MAX_LCORE in them, e.g. -l 140-148. In order to do so, we limit the use of the "@" symbol for per-core remapping when specifying a core list for automatic/global remapping, rather than dealing with the situation of some cores being manually remapped and others automatically.

---
 doc/guides/linux_gsg/eal_args.include.rst | 22 +++++++++++++++++
 doc/guides/rel_notes/release_25_11.rst    | 11 +++++++++
 lib/eal/common/eal_common_options.c       | 29 ++++++++++++++++++++---
 3 files changed, 59 insertions(+), 3 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +22 -0
index 0b17879d42..4a3c4d9b5f 100644
@@ -67,6 +67,28 @@ Lcore-related options
     At a given instance only one core option ``--lcores``, ``-l`` or ``-c`` can
     be used.
 
+*  ``-R, --remap-lcore-ids [<start lcore id>]``
+
+   Enable automatic remapping of lcore-ids to a contiguous set starting from 0,
+   or from a user-provided value.
+
+   When this flag is passed, the lcores specified by core mask or core list options
+   are taken as the physical cores on which the application will run,
+   and one thread will be started per core, with sequential lcore-ids.
+
+   For example: ``dpdk-test -l 20-24 -R``
+   will start 5 threads with lcore-ids 0 to 4 on physical cores 20 to 24.
+
+   Another example: ``dpdk-test -l 140-144 -R=10``
+   will start 5 threads with lcore-ids 10 to 14 on physical cores 140 to 144.
+
+.. note::
+
+    When using with the ``--lcores`` option, only simple core lists are allowed.
+    The ``@`` symbol to bind lcores to physical cpus,
+    and the use of ``()`` for core groupings,
+    are not allowed when ``-R`` or ``--remap-lcore-ids`` is also used.
+
 *   ``--main-lcore <core ID>``
 
     Core ID that is used as main.
doc/guides/rel_notes/release_25_11.rst +11 -0
index f73bab1227..4443ebbe92 100644
@@ -55,6 +55,17 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added automatic lcore-id remapping option.**
+
+  Added the EAL option ``--remap-lcore-ids`` or ``-R``
+  to enable automatic remapping of lcore-ids to a contiguous set starting from 0,
+  or from a user-provided value.
+  When this flag is passed, the lcores specified by core mask or core list options
+  are taken as the physical cores on which the application will run,
+  and one thread will be started per core, with sequential lcore-ids.
+  For example: ``dpdk-test -l 140-144 -R``
+  will start 5 threads with lcore-ids 0 to 4 on physical cores 140 to 144.
+
 * **Added speed 800G.**
 
   Added Ethernet link speed for 800 Gb/s as it is well standardized in IEEE,
lib/eal/common/eal_common_options.c +26 -3
index 86351535ee..c754c19511 100644
@@ -1937,9 +1937,32 @@ eal_parse_args(void)
 		}
 		core_parsed = 1;
 	} else if (args.lcores != NULL) {
-		if (eal_parse_lcores(args.lcores) < 0) {
-			EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
-			return -1;
+		if (!remap_lcores) {
+			if (eal_parse_lcores(args.lcores) < 0) {
+				EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
+				return -1;
+			}
+		} else {
+			rte_cpuset_t cpuset;
+
+			if (strchr(args.lcores, '@') != NULL || strchr(args.lcores, '(') != NULL) {
+				EAL_LOG(ERR, "cannot use '@' or core groupings '()' in lcore list when remapping lcores");
+				return -1;
+			}
+			if (rte_argparse_parse_type(args.lcores,
+					RTE_ARGPARSE_VALUE_TYPE_CORELIST, &cpuset) != 0) {
+				EAL_LOG(ERR, "Error parsing lcore list: '%s'", args.lcores);
+				return -1;
+			}
+
+			if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
+				char *available = available_cores();
+
+				EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
+						args.coremask, available);
+				free(available);
+				return -1;
+			}
 		}
 		core_parsed = 1;
 	}
Signature · 1 line
2.48.1
#112 lore raw

PATCH v8 18/18 eal: allow lcore remapping with autodetected core affinity

In reply to Bruce Richardson

When run without an coremask or core list parameters, EAL detects the working set of cores allowed for the current process and uses that as a core list for use. Currently, this does not work for cores which are numbered >= RTE_MAX_LCORE.

We can fix this by allowing the remap option to also be used with these auto-detected cores. In the process we simplify the code by taking advantage of that fact that we know up-front when processing parameters if any core parameter is passed, so we no longer need a flag and to auto-detect at the end. Instead, we take advantage of the fact that our core-arg processing routines now all work with cpusets, to have a simple tri-state option for remapping (if we don't have manual remapping done by --lcores-parameter):
* parse coremask to cpuset
* parse core list to cpuset
* query OS for current thread's cpuset
Once that is done, we have common code for processing, and optionally remapping, the resulting cpuset.

---
 lib/eal/common/eal_common_options.c | 110 +++++++++++-----------------
 1 file changed, 43 insertions(+), 67 deletions(-)
lib/eal/common/eal_common_options.c +43 -67
index c754c19511..b1830aa9d7 100644
@@ -292,8 +292,6 @@ struct device_option {
 static struct device_option_list devopt_list =
 TAILQ_HEAD_INITIALIZER(devopt_list);
 
-static int core_parsed;
-
 /* Returns rte_usage_hook_t */
 rte_usage_hook_t
 eal_get_application_usage_hook(void)
@@ -830,7 +828,7 @@ eal_parse_service_coremask(const char *coremask)
 	if (count == 0)
 		return -1;
 
-	if (core_parsed && taken_lcore_count != count) {
+	if (taken_lcore_count != count) {
 		EAL_LOG(WARNING,
 			"Not all service cores are in the coremask. "
 			"Please ensure -c or -l includes service cores");
@@ -1051,7 +1049,7 @@ eal_parse_service_corelist(const char *corelist)
 	if (count == 0)
 		return -1;
 
-	if (core_parsed && taken_lcore_count != count) {
+	if (taken_lcore_count != count) {
 		EAL_LOG(WARNING,
 			"Not all service cores were in the coremask. "
 			"Please ensure -c or -l includes service cores");
@@ -1919,32 +1917,31 @@ eal_parse_args(void)
 		}
 	}
 
-	/* parse the core list arguments */
-	if (args.coremask != NULL) {
-		rte_cpuset_t cpuset;
 
-		if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) {
-			EAL_LOG(ERR, "invalid coremask syntax");
-			return -1;
-		}
-		if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
-			char *available = available_cores();
-
-			EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
-					args.coremask, available);
-			free(available);
+	/* parse the core list arguments
+	 * First handle the special case where we have explicit core mapping/remapping
+	 */
+	if (args.lcores != NULL && !remap_lcores) {
+		if (eal_parse_lcores(args.lcores) < 0) {
+			EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
 			return -1;
 		}
-		core_parsed = 1;
-	} else if (args.lcores != NULL) {
-		if (!remap_lcores) {
-			if (eal_parse_lcores(args.lcores) < 0) {
-				EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
+	} else {
+		/* otherwise get a cpuset of the cores to be used and then handle that
+		 * taking mappings into account. Cpuset comes from either:
+		 * 1. coremask parameter
+		 * 2. core list parameter
+		 * 3. autodetecting current thread affinities
+		 */
+		rte_cpuset_t cpuset;
+		const char *cpuset_source;
+		if (args.coremask != NULL) {
+			if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) {
+				EAL_LOG(ERR, "invalid coremask syntax");
 				return -1;
 			}
-		} else {
-			rte_cpuset_t cpuset;
-
+			cpuset_source = "coremask";
+		} else if (args.lcores != NULL) {
 			if (strchr(args.lcores, '@') != NULL || strchr(args.lcores, '(') != NULL) {
 				EAL_LOG(ERR, "cannot use '@' or core groupings '()' in lcore list when remapping lcores");
 				return -1;
@@ -1954,18 +1951,29 @@ eal_parse_args(void)
 				EAL_LOG(ERR, "Error parsing lcore list: '%s'", args.lcores);
 				return -1;
 			}
-
-			if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
-				char *available = available_cores();
-
-				EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
-						args.coremask, available);
-				free(available);
+			cpuset_source = "core list";
+		} else {
+			if (rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset) != 0) {
+				EAL_LOG(ERR, "Error querying current process thread affinities");
 				return -1;
 			}
+			cpuset_source = "affinity auto-detection";
+		}
+		char *cpuset_str = eal_cpuset_to_str(&cpuset);
+		if (cpuset_str != NULL) {
+			EAL_LOG(DEBUG, "Cores selected by %s: %s", cpuset_source, cpuset_str);
+			free(cpuset_str);
+		}
+		if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
+			char *available = available_cores();
+
+			EAL_LOG(ERR, "invalid coremask or core-list parameter, please check specified cores are part of %s",
+					available);
+			free(available);
+			return -1;
 		}
-		core_parsed = 1;
 	}
+
 	/* service core options */
 	if (args.service_coremask != NULL) {
 		if (eal_parse_service_coremask(args.service_coremask) < 0) {
@@ -2208,27 +2216,6 @@ eal_parse_args(void)
 	return 0;
 }
 
-static void
-eal_auto_detect_cores(struct rte_config *cfg)
-{
-	unsigned int lcore_id;
-	unsigned int removed = 0;
-	rte_cpuset_t affinity_set;
-
-	if (rte_thread_get_affinity_by_id(rte_thread_self(), &affinity_set) != 0)
-		CPU_ZERO(&affinity_set);
-
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
-		    !CPU_ISSET(lcore_id, &affinity_set)) {
-			cfg->lcore_role[lcore_id] = ROLE_OFF;
-			removed++;
-		}
-	}
-
-	cfg->lcore_count -= removed;
-}
-
 static void
 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 {
@@ -2276,20 +2263,9 @@ int
 eal_adjust_config(struct internal_config *internal_cfg)
 {
 	int i;
-	struct rte_config *cfg = rte_eal_get_configuration();
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
-
-	if (!core_parsed)
-		eal_auto_detect_cores(cfg);
-
-	if (cfg->lcore_count == 0) {
-		EAL_LOG(ERR, "No detected lcore is enabled, please check the core list");
-		return -1;
-	}
 
-	if (internal_conf->process_type == RTE_PROC_AUTO)
-		internal_conf->process_type = eal_proc_type_detect();
+	if (internal_cfg->process_type == RTE_PROC_AUTO)
+		internal_cfg->process_type = eal_proc_type_detect();
 
 	compute_ctrl_threads_cpuset(internal_cfg);
 
Signature · 1 line
2.48.1
#113 lore raw

Re: [PATCH v8 00/18] Simplify running with high-numbered CPUs

In reply to Bruce Richardson
Quoted 5 lines · Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

CI is complaining that it can't apply this. V9 upcoming rebased on latest main.

#114 lore raw

RE: [PATCH v8 00/18] Simplify running with high-numbered CPUs

In reply to Bruce Richardson

Bruce,

cpu_set_t is a fixed size array, with the size CPU_SETSIZE. This is part of libc.

However, the kernel may be built with support for a different number of CPUs.
This means that e.g. sched_getaffinity() will fail with EINVAL if cpusetsize is smaller than the number of CPUs the kernel was built for. For more information, refer to the description about "Dynamically sized CPU sets" here:
https://linux.die.net/man/3/cpu_alloc_size

With this series, consider ensuring that all DPDK functions taking a cpu set parameter also take a cpu set size parameter, to align with kernel APIs. E.g.:
int sched_getaffinity(pid_t pid,
size_t cpusetsize, cpu_set_t *mask), and
void CPU_ZERO_S(size_t setsize, cpu_set_t *set),
instead of:
void CPU_ZERO(cpu_set_t *set).

<feature creep>
Consider not using fixed size cpu sets (and CPU_SETSIZE) at all, but dynamically allocated cpu sets. </feature creep>

<joke>
Consider not using fixed size lcore arrays (and RTE_MAX_LCORE) at all, but dynamically allocated lcore arrays. </joke>

Venlig hilsen / Kind regards,
-Morten Brørup

#115 lore raw

Re: [PATCH v8 00/18] Simplify running with high-numbered CPUs

Quoted 10 lines · Morten Brørup

Bruce,

cpu_set_t is a fixed size array, with the size CPU_SETSIZE. This is part of libc.

However, the kernel may be built with support for a different number of CPUs.
This means that e.g. sched_getaffinity() will fail with EINVAL if cpusetsize is smaller than the number of CPUs the kernel was built for. For more information, refer to the description about "Dynamically sized CPU sets" here:
https://linux.die.net/man/3/cpu_alloc_size

Quoted 8 lines

With this series, consider ensuring that all DPDK functions taking a cpu set parameter also take a cpu set size parameter, to align with kernel APIs. E.g.:
int sched_getaffinity(pid_t pid,
size_t cpusetsize, cpu_set_t *mask), and
void CPU_ZERO_S(size_t setsize, cpu_set_t *set),
instead of:
void CPU_ZERO(cpu_set_t *set).

Ok, that seems a feasible change.

Quoted 4 lines

<feature creep>
Consider not using fixed size cpu sets (and CPU_SETSIZE) at all, but dynamically allocated cpu sets. </feature creep>

Will have to see what that involves. If it's fairly easy, I'll give it a go, but we are rather late in this release cycle, so if it's taking too long I'll have to give this bit a miss.

/Bruce

#116 lore raw

Re: [PATCH v8 00/18] Simplify running with high-numbered CPUs

Quoted 22 lines · Bruce Richardson
Quoted 10 lines · Morten Brørup

Bruce,

cpu_set_t is a fixed size array, with the size CPU_SETSIZE. This is part of libc.

However, the kernel may be built with support for a different number of CPUs.
This means that e.g. sched_getaffinity() will fail with EINVAL if cpusetsize is smaller than the number of CPUs the kernel was built for. For more information, refer to the description about "Dynamically sized CPU sets" here:
https://linux.die.net/man/3/cpu_alloc_size

Quoted 8 lines

With this series, consider ensuring that all DPDK functions taking a cpu set parameter also take a cpu set size parameter, to align with kernel APIs. E.g.:
int sched_getaffinity(pid_t pid,
size_t cpusetsize, cpu_set_t *mask), and
void CPU_ZERO_S(size_t setsize, cpu_set_t *set),
instead of:
void CPU_ZERO(cpu_set_t *set).

Ok, that seems a feasible change.

Quoted 9 lines
Quoted 4 lines

<feature creep>
Consider not using fixed size cpu sets (and CPU_SETSIZE) at all, but dynamically allocated cpu sets. </feature creep>

Will have to see what that involves. If it's fairly easy, I'll give it a go, but we are rather late in this release cycle, so if it's taking too long I'll have to give this bit a miss.

Looking at these requests, while initially it seems easy, there is actually enough work in it, that I don't think I can feasibly implement and still have this work in this release. For example:

* the cpuset macros aren't present on windows, so we need to add to rte_os.h the equivalents of them.
- do we do like for RTE_CPU_AND or RTE_CPU_FILL and produce RTE_* versions?
- if so, can we then take some liberties like making the size parameter the bitsize rather than the bytesize parameter - which would make use far easier. [With current CPU_*_S macros in the code I find myself having to always track two values each time, bitsize for range checking and bytesize just to pass to the libc macros]
* the argparse library doesn't have the option to take additional parameters such as a cpuset size when parsing arguments - it's either a cpuset value or not. [I've prototyped working around that by adding a new API specifying the expected cpuset size]
* even if all the arg parsing in EAL is set up to handle variably sized cpu sets, the actual lcore_config data structure would need to be set up for dynamically allocated cpusets to actually handle them.

Given all that, the major blocker is actually the first one - deciding about putting the macros/inlines for this in rte_os.h. If we are going to make the variable sized functions available in DPDK, I'd like to have a bit of thought and discussion about how first. As well as possibly changing macro parameters, we could even go further and create a wrapper struct for cpusets which actually tracks the length - thereby possibly making things simpler to use and less error prone.

/Bruce

#117 lore raw

v9 cover Simplify running with high-numbered CPUs

In reply to Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V9: rebase to latest main. CI complains cannot apply v8 patches.

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

V7:
* expand the scope of the patchset beyond just cleanup to add in the extra 3 patches for -L and --lcoreid-base option.

V6:
* Rebase to apply cleanly on latest main

V5:
* Resubmit of V4, which didn't get sent correctly, or picked up correctly in patchwork.

V4:
* Updated patch 5 to auto-generate the arg struct definition from the same list of defines used to construct the argument list.

V3:
* Added 3 new initial patches, one for minor build-system addition, and two for functionality in argparse to allow the user-callback help function to be maintained as we move to argparse.
* Added doc updates in the first EAL patch adding the long options
* Fixed ASAN issues by adding a patch to properly clean up EAL init - both memory allocations and fixing the run-once flag
* Put ifdefs around the linux-only or unix-only options in EAL patch 2
* Updated args to handle numa-mem and numa-limit as equivalent socket-mem and socket-limit

Bruce Richardson (18):
build: add define for the OS environment name
argparse: export function to print help text for object
argparse: allow user-override of help printing
argparse: add documentation on supported value types
argparse: add support for parsing core lists
eal: add long options for each short option
eal: define the EAL parameters in argparse format
eal: gather EAL args before processing
eal: ensure proper cleanup on EAL init failure
eal: combine parameter validation checks
eal: simplify handling of conflicting cmdline options
eal: automatically init arg list options
eal: add internal fn for converting cpuset to string
eal: use common cpuset to string function
eal: introduce lcore remapping option for coremasks
eal: rework internal coremask parsing to use cpu sets
eal: allow lcore id remapping with core lists
eal: allow lcore remapping with autodetected core affinity

 app/test/test_argparse.c                   |  188 +++
 config/meson.build                         |    1 +
 doc/guides/contributing/design.rst         |    2 +-
 doc/guides/linux_gsg/eal_args.include.rst  |   42 +-
 doc/guides/prog_guide/argparse_lib.rst     |  121 +-
 doc/guides/rel_notes/release_25_11.rst     |   18 +
 drivers/event/dlb2/dlb2_priv.h             |    2 +-
 drivers/event/dlb2/pf/base/dlb2_resource.c |   11 +-
 lib/argparse/rte_argparse.c                |  109 +-
 lib/argparse/rte_argparse.h                |   23 +-
 lib/eal/common/eal_common_lcore.c          |   13 +-
 lib/eal/common/eal_common_memory.c         |    3 +-
 lib/eal/common/eal_common_options.c        | 1417 +++++++++++---------
 lib/eal/common/eal_common_thread.c         |   43 +-
 lib/eal/common/eal_option_list.h           |   98 ++
 lib/eal/common/eal_options.h               |  104 +-
 lib/eal/common/eal_private.h               |   21 +
 lib/eal/common/eal_thread.h                |   13 +-
 lib/eal/freebsd/eal.c                      |  245 +---
 lib/eal/include/rte_eal.h                  |   20 -
 lib/eal/linux/eal.c                        |  470 +------
 lib/eal/linux/eal_memory.c                 |    2 +-
 lib/eal/meson.build                        |    2 +-
 lib/eal/windows/eal.c                      |  156 +--
 lib/meson.build                            |    1 +
 25 files changed, 1533 insertions(+), 1592 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h

--
2.48.1

#118 lore raw

PATCH v9 1/18 build: add define for the OS environment name

Introduce a string define for the currently running OS, or execution environment.

Originally, with old make build system, CONFIG_RTE_EXEC_ENV used to hold this name string, but the variable seems to have been missed in the meson build system, until commit cadb255e25d6 ("eal: add OS defines for C conditional checks") which introduced the RTE_EXEC_ENV for a different purpose. Now we can fix the docs with the new name reference.

---
 config/meson.build                 | 1 +
 doc/guides/contributing/design.rst | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
index ca63ee10b1..b8c1f127a2 100644
@@ -20,6 +20,7 @@ foreach env, id:exec_envs
     dpdk_conf.set10('RTE_EXEC_ENV_IS_' + env.to_upper(), (exec_env == env))
 endforeach
 dpdk_conf.set('RTE_EXEC_ENV', exec_envs[exec_env])
+dpdk_conf.set_quoted('RTE_EXEC_ENV_NAME', exec_env)
 dpdk_conf.set('RTE_EXEC_ENV_' + exec_env.to_upper(), 1)
 
 # MS linker requires special treatment.
doc/guides/contributing/design.rst +1 -1
index b724177ba1..5517613424 100644
@@ -50,7 +50,7 @@ Per Execution Environment Sources
 
 The following macro options can be used:
 
-* ``RTE_EXEC_ENV`` is a string that contains the name of the executive environment.
+* ``RTE_EXEC_ENV_NAME`` is a string that contains the name of the executive environment.
 * ``RTE_EXEC_ENV_FREEBSD``, ``RTE_EXEC_ENV_LINUX`` or ``RTE_EXEC_ENV_WINDOWS`` are defined only if we are building for this execution environment.
 
 Mbuf features
Signature · 1 line
2.48.1
#119 lore raw

PATCH v9 2/18 argparse: export function to print help text for object

In reply to Bruce Richardson

Make the function to print out the help text for an argparse object a public function, which takes as a new parameter the file stream on which to print. This can be used in future to allow application to extend their own help information.

---
 lib/argparse/rte_argparse.c | 43 +++++++++++++++++++------------------
 lib/argparse/rte_argparse.h | 14 ++++++++++++
 2 files changed, 36 insertions(+), 21 deletions(-)
lib/argparse/rte_argparse.c +22 -21
index 331f05f01d..f0c2c33178 100644
@@ -716,23 +716,23 @@ calc_help_align(const struct rte_argparse *obj)
 }
 
 static void
-show_oneline_help(const struct rte_argparse_arg *arg, uint32_t width)
+show_oneline_help(FILE *stream, const struct rte_argparse_arg *arg, uint32_t width)
 {
 	uint32_t len = 0;
 	uint32_t i;
 
 	if (arg->name_short != NULL)
-		len = printf(" %s,", arg->name_short);
-	len += printf(" %s", arg->name_long);
+		len = fprintf(stream, " %s,", arg->name_short);
+	len += fprintf(stream, " %s", arg->name_long);
 
 	for (i = len; i < width; i++)
-		printf(" ");
+		fprintf(stream, " ");
 
-	printf("%s\n", arg->help);
+	fprintf(stream, "%s\n", arg->help);
 }
 
 static void
-show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
+show_args_pos_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	uint32_t position_count = calc_position_count(obj);
 	const struct rte_argparse_arg *arg;
@@ -741,19 +741,19 @@ show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
 	if (position_count == 0)
 		return;
 
-	printf("\npositional arguments:\n");
+	fprintf(stream, "\npositional arguments:\n");
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_positional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
 static void
-show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
+show_args_opt_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	static const struct rte_argparse_arg help = {
 		.name_long = "--help",
@@ -763,34 +763,35 @@ show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
 	const struct rte_argparse_arg *arg;
 	uint32_t i;
 
-	printf("\noptions:\n");
-	show_oneline_help(&help, align);
+	fprintf(stream, "\noptions:\n");
+	show_oneline_help(stream, &help, align);
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_optional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
-static void
-show_args_help(const struct rte_argparse *obj)
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_print_help, 25.11)
+void
+rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj)
 {
 	uint32_t align = calc_help_align(obj);
 
-	printf("usage: %s %s\n", obj->prog_name, obj->usage);
+	fprintf(stream, "usage: %s %s\n", obj->prog_name, obj->usage);
 	if (obj->descriptor != NULL)
-		printf("\ndescriptor: %s\n", obj->descriptor);
+		fprintf(stream, "\ndescriptor: %s\n", obj->descriptor);
 
-	show_args_pos_help(obj, align);
-	show_args_opt_help(obj, align);
+	show_args_pos_help(stream, obj, align);
+	show_args_opt_help(stream, obj, align);
 
 	if (obj->epilog != NULL)
-		printf("\n%s\n", obj->epilog);
+		fprintf(stream, "\n%s\n", obj->epilog);
 	else
-		printf("\n");
+		fprintf(stream, "\n");
 }
 
 RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_parse, 24.03)
@@ -820,7 +821,7 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		show_args_help(obj);
+		rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +14 -0
index 52bef34363..baf278f6b9 100644
@@ -189,6 +189,20 @@ struct rte_argparse {
 __rte_experimental
 int rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Output the help text information for the given argparse object.
+ *
+ * @param stream
+ *   Output file handle, e.g. stdout, stderr, on which to print the help text.
+ * @param obj
+ *   Parser object.
+ */
+__rte_experimental
+void rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.48.1
#120 lore raw

PATCH v9 3/18 argparse: allow user-override of help printing

In reply to Bruce Richardson

When the arguments passed to argparse include -h/--help then usage information is automatically printed. Provide the capability for the user to supply their own help function for this.

---
 doc/guides/prog_guide/argparse_lib.rst | 16 ++++++++++++++++
 doc/guides/rel_notes/release_25_11.rst |  7 +++++++
 lib/argparse/rte_argparse.c            |  5 ++++-
 lib/argparse/rte_argparse.h            |  7 ++++++-
 4 files changed, 33 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +16 -0
index 9f11714890..b309260d20 100644
@@ -24,6 +24,8 @@ Features and Capabilities
   #. autosave: used for parsing known value types;
   #. callback: will invoke user callback to parse.
 
+- Supports automatic help and usage information.
+
 Usage Guide
 -----------
 
@@ -193,3 +195,17 @@ Then the user input could contain multiple ``--xyz`` arguments.
 
    The multiple times argument only support with optional argument
    and must be parsed by callback way.
+
+Help and Usage Information
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic generation of help and usage information.
+When the input arguments include ``-h`` or ``--help``,
+it will print the usage information to standard output.
+If the default help output is not what is wanted,
+the user can provide a custom help printing function by setting the ``print_help`` field in the ``rte_argparse`` object.
+(If this field is set to NULL, the default help printing function will be used.)
+
+If the custom help printing function wants to use the text produced by the default help function,
+it can call the function ``rte_argparse_print_help()`` to get the help text printed to an output stream,
+for example: stdout or stderr.
doc/guides/rel_notes/release_25_11.rst +7 -0
index c3b94e1896..f73bab1227 100644
@@ -76,6 +76,13 @@ New Features
   * Added multi-process per port.
   * Optimized code.
 
+* **Allow overriding the automatic usage/help generation in argparse library.**
+
+  The argparse library now supports overriding the automatic help text generation,
+  by allowing the user to provide a custom function to generate the output text.
+  The built-in help text function is available as a public function which can be reused by custom functions,
+  if so desired.
+
 
 Removed Items
 -------------
lib/argparse/rte_argparse.c +4 -1
index f0c2c33178..2b5da5f1db 100644
@@ -821,7 +821,10 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		rte_argparse_print_help(stdout, obj);
+		if (obj->print_help != NULL)
+			obj->print_help(obj);
+		else
+			rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +6 -1
index baf278f6b9..63b49ba220 100644
@@ -160,8 +160,13 @@ struct rte_argparse {
 	rte_arg_parser_t callback;
 	/** Opaque which used to invoke callback. */
 	void *opaque;
+	/**
+	 * Function pointer for printing usage when -h is passed.
+	 * If this is NULL, default printing function will be used.
+	 */
+	void (*print_help)(const struct rte_argparse *obj);
 	/** Reserved field used for future extension. */
-	void *reserved[16];
+	void *reserved[15];
 	/** Arguments configuration. Must ended with ARGPARSE_ARG_END(). */
 	struct rte_argparse_arg args[];
 };
Signature · 1 line
2.48.1
#121 lore raw

PATCH v9 4/18 argparse: add documentation on supported value types

In reply to Bruce Richardson

The different value types supported by the argparse library are not discussed in the documentation, so add some reference material about them.

---
 doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +71 -2
index b309260d20..7868af5672 100644
@@ -160,6 +160,75 @@ both use this way, the parsing is as follows:
 - For argument ``ooo``, it is positional argument,
   the ``ooo_val`` will be set to user input's value.
 
+Supported Value Types
+~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic parsing of several data types when using
+the autosave method. The parsed values are automatically converted from string
+input to the appropriate data type and stored in the ``val_saver`` field.
+
+Integer Types
+^^^^^^^^^^^^^
+
+The library supports parsing various integer types:
+
+- ``RTE_ARGPARSE_VALUE_TYPE_INT`` - signed integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U8`` - unsigned 8-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U16`` - unsigned 16-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U32`` - unsigned 32-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U64`` - unsigned 64-bit integer
+
+.. code-block:: C
+
+   static int my_int;
+   static uint16_t my_port;
+   static uint32_t my_count;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--number", "-n", "Integer value", &my_int, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_INT },
+         { "--port", "-p", "Port number", &my_port, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_U16 },
+         { "--count", "-c", "Count value", &my_count, (void *)1000, RTE_ARGPARSE_VALUE_OPTIONAL, RTE_ARGPARSE_VALUE_TYPE_U32 },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+String Type
+^^^^^^^^^^^
+
+String arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_STR``.
+When using this type, the input value is saved to the provided pointer without any parsing or validation.
+
+.. code-block:: C
+
+   static const char *my_string;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--name", "-n", "Name string", &my_string, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_STR },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+Boolean Type
+^^^^^^^^^^^^
+
+Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept the following input formats:
+
+- ``true``, ``false`` (case-sensitive)
+- ``1``, ``0`` (numeric format)
+
+.. code-block:: C
+
+   static bool my_flag;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--enable", "-e", "Enable feature", &my_flag, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_BOOL },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -167,8 +236,8 @@ It could also choose to use callback to parse,
 just define a unique index for the argument
 and make the ``val_save`` field to be NULL also zero value-type.
 
-In the above example, the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp``
-both use this way.
+In the example at the top of this section,
+the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp`` all use this way.
 
 Multiple times argument
 ~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.48.1
#122 lore raw

PATCH v9 5/18 argparse: add support for parsing core lists

In reply to Bruce Richardson

Core lists are widely used in DPDK, so add support for parsing them.

---
 app/test/test_argparse.c               | 188 +++++++++++++++++++++++++
 doc/guides/prog_guide/argparse_lib.rst |  32 +++++
 lib/argparse/rte_argparse.c            |  63 +++++++++
 lib/argparse/rte_argparse.h            |   2 +
 4 files changed, 285 insertions(+)
app/test/test_argparse.c +188 -0
index 0a229752fa..c829ea75e4 100644
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_argparse.h>
+#include <rte_os.h>
 
 #include "test.h"
 
@@ -500,6 +501,40 @@ test_argparse_opt_autosave_parse_int_of_optional_val(void)
 	return 0;
 }
 
+static int
+test_argparse_opt_parse_corelist_of_required_val(void)
+{
+	struct rte_argparse *obj;
+	rte_cpuset_t val_cpuset;
+	char *argv[3];
+	int ret;
+
+	/* test with long option and single core - this is known to work */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--corelist";
+	obj->args[0].name_short = "-c";
+	obj->args[0].val_saver = (void *)&val_cpuset;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_CORELIST;
+	obj->args[1].name_long = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("--corelist");
+	argv[2] = test_strdup("1,3-5");
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse(obj, 3, argv);
+	TEST_ASSERT(ret == 3, "Argparse parse expect success!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(3, &val_cpuset), "Core 3 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(4, &val_cpuset), "Core 4 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in corelist!");
+
+	return 0;
+}
+
 static int
 opt_callback_parse_int_of_no_val(uint32_t index, const char *value, void *opaque)
 {
@@ -782,6 +817,152 @@ test_argparse_pos_callback_parse_int(void)
 	return 0;
 }
 
+static int
+test_argparse_parse_type_corelist(void)
+{
+	char *corelist_valid_single = test_strdup("5");
+	char *corelist_valid_multiple = test_strdup("0,1,5");
+	char *corelist_valid_range = test_strdup("1-5");
+	char *corelist_valid_mixed = test_strdup("0,1,5-10,12-16,18,20");
+	char *corelist_valid_reverse_range = test_strdup("10-5");
+	char *corelist_valid_initial_spaces = test_strdup("   1,2,5-7");
+	char *corelist_valid_empty = test_strdup("");
+	char *corelist_invalid_spaces = test_strdup(" 1 , 2 , 5-7 ");
+	char *corelist_invalid_letters = test_strdup("1,a,3");
+	char *corelist_invalid_range_incomplete = test_strdup("1-");
+	char *corelist_invalid_range_double_dash = test_strdup("1--5");
+	char *corelist_invalid_special_chars = test_strdup("1,2@3");
+	char *corelist_invalid_comma_only = test_strdup(",");
+	char *corelist_invalid_out_of_range = test_strdup("70000");
+	rte_cpuset_t val_cpuset;
+	int ret;
+
+	/* test valid single core */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_single,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (single core) failed!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(1, &val_cpuset), "Core 1 should not be set in corelist!");
+
+	/* test valid multiple cores */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_multiple,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (multiple cores) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(3, &val_cpuset), "Core 3 should not be set in corelist!");
+
+	/* test valid range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (range) failed!");
+	for (int i = 1; i <= 5; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 1-5!", i);
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in range 1-5!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in range 1-5!");
+
+	/* test valid mixed corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_mixed,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (mixed) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in mixed corelist!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 5-10!", i);
+	for (int i = 12; i <= 16; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 12-16!", i);
+
+	TEST_ASSERT(CPU_ISSET(18, &val_cpuset), "Core 18 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(20, &val_cpuset), "Core 20 should be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(17, &val_cpuset), "Core 17 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(19, &val_cpuset), "Core 19 should not be set in mixed corelist!");
+
+	/* test valid reverse range (10-5 should be interpreted as 5-10) */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_reverse_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (reverse range) failed!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in reverse range 10-5!", i);
+	TEST_ASSERT(!CPU_ISSET(4, &val_cpuset), "Core 4 should not be set in reverse range 10-5!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in reverse range 10-5!");
+
+	/* test valid corelist with initial spaces only */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_initial_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (with initial spaces) failed!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in initial spaced corelist!");
+	TEST_ASSERT(CPU_ISSET(2, &val_cpuset), "Core 2 should be set in initial spaced corelist!");
+	for (int i = 5; i <= 7; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in initial spaced range 5-7!", i);
+
+	/* test valid empty corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_empty,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (empty) failed!");
+	/* Verify that no cores are set in empty corelist */
+	for (int i = 0; i < CPU_SETSIZE; i++)
+		TEST_ASSERT(!CPU_ISSET(i, &val_cpuset),
+				"Core %d should not be set in empty corelist!", i);
+
+	/* test invalid corelist with spaces */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with spaces) should have failed!");
+
+	/* test invalid corelist with letters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_letters,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with letters) should have failed!");
+
+	/* test invalid corelist with incomplete range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_incomplete,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (incomplete range) should have failed!");
+
+	/* test invalid corelist with double dash */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_double_dash,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (double dash) should have failed!");
+
+	/* test invalid corelist with special characters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_special_chars,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (special chars) should have failed!");
+
+	/* test invalid comma-only corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_comma_only,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (comma only) should have failed!");
+
+	/* test invalid out-of-range corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_out_of_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (out of range) should have failed!");
+
+	return 0;
+}
+
 static int
 test_argparse_parse_type(void)
 {
@@ -880,6 +1061,12 @@ test_argparse_parse_type(void)
 	ret = rte_argparse_parse_type(bool_numeric_invalid, RTE_ARGPARSE_VALUE_TYPE_BOOL,
 			&val_bool);
 	TEST_ASSERT(ret != 0, "Argparse parse type for bool (numeric invalid) passed unexpectedly!");
+
+	/* test for corelist parsing */
+	ret = test_argparse_parse_type_corelist();
+	if (ret != 0)
+		return ret;
+
 	return 0;
 }
 
@@ -900,6 +1087,7 @@ static struct unit_test_suite argparse_test_suite = {
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_optional_val),
+		TEST_CASE(test_argparse_opt_parse_corelist_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_optional_val),
doc/guides/prog_guide/argparse_lib.rst +32 -0
index 7868af5672..7882d910ab 100644
@@ -229,6 +229,38 @@ Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept t
       },
    };
 
+Corelist Type
+^^^^^^^^^^^^^
+
+The argparse library supports automatic parsing of CPU core lists using the
+``RTE_ARGPARSE_VALUE_TYPE_CORELIST`` value type. This feature allows users to
+specify CPU cores in a flexible format similar to other DPDK applications.
+
+.. code-block:: C
+
+   #include <rte_os.h>  /* for CPU set operations */
+
+   static rte_cpuset_t cores;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--cores", "-c", "CPU cores to use", &cores, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_CORELIST },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+The corelist parsing supports the following input formats:
+
+- **Single core**: ``--cores 5`` (sets core 5)
+- **Multiple cores**: ``--cores 1,2,5`` (sets cores 1, 2, and 5)
+- **Core ranges**: ``--cores 1-5`` (sets cores 1, 2, 3, 4, and 5)
+- **Mixed format**: ``--cores 0,2-4,7`` (sets cores 0, 2, 3, 4, and 7)
+- **Reverse ranges**: ``--cores 5-1`` (equivalent to 1-5, sets cores 1, 2, 3, 4, and 5)
+- **Empty corelist**: ``--cores ""`` (sets no cores)
+
+The parsed result is stored in an ``rte_cpuset_t`` structure that can be used
+with standard CPU set operations:
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
lib/argparse/rte_argparse.c +63 -0

90 lines not on this page · raw message

lib/argparse/rte_argparse.h +2 -0
index 63b49ba220..991f084927 100644
@@ -69,6 +69,8 @@ enum rte_argparse_value_type {
 	RTE_ARGPARSE_VALUE_TYPE_STR,
 	/** The argument's value is boolean flag type. */
 	RTE_ARGPARSE_VALUE_TYPE_BOOL,
+	/** The argument's value is a corelist */
+	RTE_ARGPARSE_VALUE_TYPE_CORELIST,
 };
 
 /** Additional flags which may be specified for each argument */
Signature · 1 line
2.48.1
#123 lore raw

PATCH v9 6/18 eal: add long options for each short option

In reply to Bruce Richardson

To simplify future rework of the EAL arg handling, add a long-option equivalent for each short option that doesn't already have one.

When updating the docs with the new long options, standardize the format of options which have both short and long variants, and drop the deprecated service-coremask option from the docs, rather than adding its new long option.

---
 doc/guides/linux_gsg/eal_args.include.rst | 20 ++++++++------------
 lib/eal/common/eal_common_options.c       |  8 ++++++++
 lib/eal/common/eal_options.h              | 16 ++++++++++++++++
 3 files changed, 32 insertions(+), 12 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +8 -12
index 9ced54af40..0b17879d42 100644
@@ -4,7 +4,7 @@
 Lcore-related options
 ~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-l/--lcores <core list>``
+*   ``-l, --lcores <core list>``
 
     List of cores to run on
 
@@ -71,11 +71,7 @@ Lcore-related options
 
     Core ID that is used as main.
 
-*   ``-s <service core mask>``
-
-    Hexadecimal bitmask of cores to be used as service cores.
-
-*   ``-S <service core list>``
+*   ``-S, --service-corelist <service core list>``
 
     List of cores to be used as service cores.
 
@@ -108,7 +104,7 @@ Device-related options
 
        --vdev 'net_pcap0,rx_pcap=input.pcap,tx_pcap=output.pcap'
 
-*   ``-d <path to shared object or directory>``
+*   ``-d, --driver-path <path to shared object or directory>``
 
     Load external drivers. An argument can be a single shared object file, or a
     directory containing multiple driver shared objects. Multiple -d options are
@@ -134,15 +130,15 @@ Multiprocessing-related options
 Memory-related options
 ~~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-n <number of channels>``
+*   ``-n, --memory-channels <number of channels>``
 
     Set the number of memory channels to use.
 
-*   ``-r <number of ranks>``
+*   ``-r, --memory-ranks <number of ranks>``
 
     Set the number of memory ranks (auto-detected by default).
 
-*   ``-m <megabytes>``
+*   ``-m, --memory-size <megabytes>``
 
     Amount of memory to preallocate at startup.
 
@@ -236,11 +232,11 @@ Debugging options
 Other options
 ~~~~~~~~~~~~~
 
-*   ``-h``, ``--help``
+*   ``-h, --help``
 
     Display help message listing all EAL parameters.
 
-*   ``-v``
+*   ``-v, --version``
 
     Display the version information on startup.
 
lib/eal/common/eal_common_options.c +8 -0
index 2f91b96190..675745d610 100644
@@ -66,7 +66,9 @@ eal_short_options[] =
 const struct option
 eal_long_options[] = {
 	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
+	{OPT_COREMASK,          1, NULL, OPT_COREMASK_NUM        },
 	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
+	{OPT_DRIVER_PATH,       1, NULL, OPT_DRIVER_PATH_NUM     },
 	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
 	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
 	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
@@ -76,6 +78,11 @@ eal_long_options[] = {
 	{OPT_LOG_COLOR,		2, NULL, OPT_LOG_COLOR_NUM	  },
 	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
 	{OPT_LOG_TIMESTAMP,     2, NULL, OPT_LOG_TIMESTAMP_NUM    },
+	{OPT_MEMORY_CHANNELS,   1, NULL, OPT_MEMORY_CHANNELS_NUM },
+	{OPT_MEMORY_RANKS,      1, NULL, OPT_MEMORY_RANKS_NUM    },
+	{OPT_MEMORY_SIZE,       1, NULL, OPT_MEMORY_SIZE_NUM     },
+	{OPT_SERVICE_CORELIST,  1, NULL, OPT_SERVICE_CORELIST_NUM },
+	{OPT_SERVICE_COREMASK,  1, NULL, OPT_SERVICE_COREMASK_NUM },
 	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
 	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
 	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
@@ -109,6 +116,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_VERSION,           0, NULL, OPT_VERSION_NUM         },
 
 	{0,                     0, NULL, 0                        }
 };
lib/eal/common/eal_options.h +16 -0
index 7a56aa3810..6ef45559f0 100644
@@ -17,8 +17,24 @@ enum {
 	OPT_DEV_ALLOW_NUM       = 'a',
 #define OPT_DEV_BLOCK         "block"
 	OPT_DEV_BLOCK_NUM      = 'b',
+#define OPT_COREMASK          "coremask"
+	OPT_COREMASK_NUM       = 'c',
+#define OPT_DRIVER_PATH       "driver-path"
+	OPT_DRIVER_PATH_NUM    = 'd',
 #define OPT_LCORES            "lcores"
 	OPT_LCORES_NUM         = 'l',
+#define OPT_MEMORY_SIZE       "memory-size"
+	OPT_MEMORY_SIZE_NUM    = 'm',
+#define OPT_MEMORY_CHANNELS   "memory-channels"
+	OPT_MEMORY_CHANNELS_NUM = 'n',
+#define OPT_MEMORY_RANKS     "memory-ranks"
+	OPT_MEMORY_RANKS_NUM   = 'r',
+#define OPT_SERVICE_COREMASK  "service-coremask"
+	OPT_SERVICE_COREMASK_NUM = 's',
+#define OPT_SERVICE_CORELIST  "service-corelist"
+	OPT_SERVICE_CORELIST_NUM = 'S',
+#define OPT_VERSION           "version"
+	OPT_VERSION_NUM        = 'v',
 
 	/* first long only option value must be >= 256, so that we won't
 	 * conflict with short options */
Signature · 1 line
2.48.1
#124 lore raw

PATCH v9 7/18 eal: define the EAL parameters in argparse format

In reply to Bruce Richardson

Create eal_option_list.h, containing all the possible EAL parameters, and basic info about them, such as type, whether they take a parameter or not. Each entry is defined using a macro, which will be then interpreted when the file is included.

First time this header in included in the eal_common_options.c file, the macros are defined in such a way as to define field elements for an "eal_init_args" structure, where each value is either a string type, if it takes a parameter, or boolean type if it doesn't. For those elements that take multiple values, i.e. are passed multiple times, we put them in a TAILQ.

The second time of inclusion, the macros are defined so as to define the arguments in an rte_argparse structure for EAL. For the basic string and boolean types, we just store the values in the appropriate field in the previous defined "eal_init_args" structure. For the list elements, we use the argparse callback to process those elements, adding them to the TAILQ as they are encountered.

---
 lib/eal/common/eal_common_options.c | 141 +++++++++++++++++++++++++++-
 lib/eal/common/eal_option_list.h    |  90 ++++++++++++++++++
 lib/eal/meson.build                 |   2 +-
 lib/meson.build                     |   1 +
 4 files changed, 230 insertions(+), 4 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h
lib/eal/common/eal_common_options.c +138 -3
index 675745d610..75d42d97aa 100644
@@ -10,6 +10,7 @@
 #include <limits.h>
 #include <errno.h>
 #include <getopt.h>
+#include <sys/queue.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <dlfcn.h>
 #include <libgen.h>
@@ -33,6 +34,7 @@
 #endif
 #include <rte_vect.h>
 
+#include <rte_argparse.h>
 #include <eal_export.h>
 #include "eal_internal_cfg.h"
 #include "eal_options.h"
@@ -47,6 +49,142 @@
 #define LCORE_OPT_LST 1
 #define LCORE_OPT_MSK 2
 
+/* Allow the application to print its usage message too if set */
+static rte_usage_hook_t rte_application_usage_hook;
+
+struct arg_list_elem {
+	TAILQ_ENTRY(arg_list_elem) next;
+	char *arg;
+};
+TAILQ_HEAD(arg_list, arg_list_elem);
+
+struct eal_init_args {
+	/* define a struct member for each EAL option, member name is the same as option name.
+	 * Parameters that take an argument e.g. -l, are char *,
+	 * parameters that take no options e.g. --no-huge, are bool.
+	 * parameters that can be given multiple times e.g. -a, are arg_lists,
+	 * parameters that are optional e.g. --huge-unlink,
+	 *   are char * but are set to (void *)1 if the parameter is not given.
+	 * for aliases, i.e. options under different names, no field needs to be output
+	 */
+#define LIST_ARG(long, short, help_str, fieldname) struct arg_list fieldname;
+#define STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define OPT_STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define BOOL_ARG(long, short, help_str, fieldname) bool fieldname;
+#define STR_ALIAS(long, short, help_str, fieldname)
+
+#define INCLUDE_ALL_ARG 1  /* for struct definition, include even unsupported values */
+#include "eal_option_list.h"
+#undef INCLUDE_ALL_ARG
+};
+struct eal_init_args args;
+
+/* an rte_argparse callback to append the argument to an arg_list
+ * in args. The index is the offset into the struct of the list.
+ */
+static int
+arg_list_callback(uint32_t index, const char *arg, void *init_args)
+{
+	struct arg_list *list = RTE_PTR_ADD(init_args, index);
+	struct arg_list_elem *elem;
+
+	elem = malloc(sizeof(*elem));
+	if (elem == NULL)
+		return -1;
+
+	elem->arg = strdup(arg);
+	if (elem->arg == NULL) {
+		free(elem);
+		return -1;
+	}
+
+	TAILQ_INSERT_TAIL(list, elem, next);
+	return 0;
+}
+
+static void
+eal_usage(const struct rte_argparse *obj)
+{
+	rte_argparse_print_help(stdout, obj);
+	if (rte_application_usage_hook != NULL)
+		rte_application_usage_hook(obj->prog_name);
+}
+
+/* undef the *_ARG macros before redefining to generate the argparse arg list */
+#undef LIST_ARG
+#undef STR_ARG
+#undef OPT_STR_ARG
+#undef BOOL_ARG
+#undef STR_ALIAS
+
+/* For arguments which have an arg_list type, they use callback (no val_saver),
+ * require a value, and have the SUPPORT_MULTI flag.
+ */
+#define LIST_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_set = (void *)offsetof(struct eal_init_args, fieldname), \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.flags = RTE_ARGPARSE_FLAG_SUPPORT_MULTI, \
+},
+/* For arguments which have a string type, they use val_saver (no callback),
+ * and normally REQUIRED_VALUE.
+ */
+#define STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For flags which have optional arguments, they use both val_saver and val_set,
+ * but still have a string type.
+ */
+#define OPT_STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_OPTIONAL, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For boolean arguments, they use val_saver and val_set, with NO_VALUE flag.
+ */
+#define BOOL_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_NONE, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_BOOL, \
+},
+#define STR_ALIAS STR_ARG
+
+#if RTE_VER_RELEASE == 99
+#define GUIDES_PATH "https://doc.dpdk.org/guides-" RTE_STR(RTE_VER_YEAR) "." RTE_STR(RTE_VER_MONTH)
+#else
+#define GUIDES_PATH "https://doc.dpdk.org/guides"
+#endif
+
+struct rte_argparse eal_argparse  = {
+	.prog_name = "",
+	.usage = "<DPDK EAL options> -- <App options>",
+	.epilog = "For more information on EAL options, see the DPDK documentation at: \n"
+			"\t" GUIDES_PATH "/" RTE_EXEC_ENV_NAME "_gsg/",
+	.exit_on_error = true,
+	.callback = arg_list_callback,
+	.print_help = eal_usage,
+	.opaque = &args,
+	.args = {
+		#include "eal_option_list.h"
+		ARGPARSE_ARG_END(),
+	}
+};
+
 const char
 eal_short_options[] =
 	"a:" /* allow */
@@ -164,9 +302,6 @@ static int main_lcore_parsed;
 static int mem_parsed;
 static int core_parsed;
 
-/* Allow the application to print its usage message too if set */
-static rte_usage_hook_t rte_application_usage_hook;
-
 /* Returns rte_usage_hook_t */
 rte_usage_hook_t
 eal_get_application_usage_hook(void)
lib/eal/common/eal_option_list.h new file +90 -0

90 lines not on this page · raw message

lib/eal/meson.build +1 -1
index e1d6c4cf17..f9fcee24ee 100644
@@ -14,7 +14,7 @@ subdir(exec_env)
 
 subdir(arch_subdir)
 
-deps += ['log', 'kvargs']
+deps += ['argparse', 'kvargs']
 if not is_windows
     deps += ['telemetry']
 endif
lib/meson.build +1 -0
index d79740a4c3..c8f4270868 100644
@@ -71,6 +71,7 @@ libraries = [
 ]
 
 always_enable = [
+        'argparse',
         'cmdline',
         'eal',
         'ethdev',
Signature · 1 line
2.48.1
#125 lore raw

PATCH v9 8/18 eal: gather EAL args before processing

In reply to Bruce Richardson

DPDK traditionally has iterated through all args and processed them as they appear in the commandline. The arg processing logic can be simplified if instead we initially gather all arguments into a structure which is then processed with the arguments dealt with in a fixed/known order.

---
 lib/eal/common/eal_common_options.c | 880 ++++++++++++++--------------
 lib/eal/common/eal_options.h        |  10 +-
 lib/eal/common/eal_private.h        |  11 +
 lib/eal/freebsd/eal.c               | 164 +-----
 lib/eal/linux/eal.c                 | 379 +-----------
 lib/eal/windows/eal.c               | 113 +---
 6 files changed, 485 insertions(+), 1072 deletions(-)
lib/eal/common/eal_common_options.c +426 -454
index 75d42d97aa..72df7c5b48 100644
@@ -46,8 +46,7 @@
 #endif
 
 #define BITS_PER_HEX 4
-#define LCORE_OPT_LST 1
-#define LCORE_OPT_MSK 2
+#define NUMA_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
 
 /* Allow the application to print its usage message too if set */
 static rte_usage_hook_t rte_application_usage_hook;
@@ -185,79 +184,33 @@ struct rte_argparse eal_argparse  = {
 	}
 };
 
-const char
-eal_short_options[] =
-	"a:" /* allow */
-	"b:" /* block */
-	"c:" /* coremask */
-	"s:" /* service coremask */
-	"d:" /* driver */
-	"h"  /* help */
-	"l:" /* corelist */
-	"S:" /* service corelist */
-	"m:" /* memory size */
-	"n:" /* memory channels */
-	"r:" /* memory ranks */
-	"v"  /* version */
-	;
-
-const struct option
-eal_long_options[] = {
-	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
-	{OPT_COREMASK,          1, NULL, OPT_COREMASK_NUM        },
-	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
-	{OPT_DRIVER_PATH,       1, NULL, OPT_DRIVER_PATH_NUM     },
-	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
-	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
-	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
-	{OPT_HUGE_UNLINK,       2, NULL, OPT_HUGE_UNLINK_NUM      },
-	{OPT_IOVA_MODE,	        1, NULL, OPT_IOVA_MODE_NUM        },
-	{OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
-	{OPT_LOG_COLOR,		2, NULL, OPT_LOG_COLOR_NUM	  },
-	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
-	{OPT_LOG_TIMESTAMP,     2, NULL, OPT_LOG_TIMESTAMP_NUM    },
-	{OPT_MEMORY_CHANNELS,   1, NULL, OPT_MEMORY_CHANNELS_NUM },
-	{OPT_MEMORY_RANKS,      1, NULL, OPT_MEMORY_RANKS_NUM    },
-	{OPT_MEMORY_SIZE,       1, NULL, OPT_MEMORY_SIZE_NUM     },
-	{OPT_SERVICE_CORELIST,  1, NULL, OPT_SERVICE_CORELIST_NUM },
-	{OPT_SERVICE_COREMASK,  1, NULL, OPT_SERVICE_COREMASK_NUM },
-	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
-	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
-	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
-	{OPT_TRACE_MODE,        1, NULL, OPT_TRACE_MODE_NUM       },
-	{OPT_MAIN_LCORE,        1, NULL, OPT_MAIN_LCORE_NUM       },
-	{OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
-	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
-	{OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
-	{OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
-	{OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
-	{OPT_IN_MEMORY,         0, NULL, OPT_IN_MEMORY_NUM        },
-	{OPT_DEV_BLOCK,         1, NULL, OPT_DEV_BLOCK_NUM        },
-	{OPT_DEV_ALLOW,		1, NULL, OPT_DEV_ALLOW_NUM	  },
-	{OPT_PROC_TYPE,         1, NULL, OPT_PROC_TYPE_NUM        },
-	/* socket-mem/socket-limit are kept for backwards compatibility */
-	{OPT_SOCKET_MEM,        1, NULL, OPT_NUMA_MEM_NUM         },
-	{OPT_SOCKET_LIMIT,      1, NULL, OPT_NUMA_LIMIT_NUM       },
-	{OPT_NUMA_MEM,          1, NULL, OPT_NUMA_MEM_NUM         },
-	{OPT_NUMA_LIMIT,        1, NULL, OPT_NUMA_LIMIT_NUM       },
-#ifndef RTE_EXEC_ENV_WINDOWS
-	{OPT_SYSLOG,            2, NULL, OPT_SYSLOG_NUM           },
-#endif
-	{OPT_VDEV,              1, NULL, OPT_VDEV_NUM             },
-	{OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
-	{OPT_VFIO_VF_TOKEN,     1, NULL, OPT_VFIO_VF_TOKEN_NUM    },
-	{OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
-	{OPT_LEGACY_MEM,        0, NULL, OPT_LEGACY_MEM_NUM       },
-	{OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
-	{OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
-	{OPT_TELEMETRY,         0, NULL, OPT_TELEMETRY_NUM        },
-	{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_VERSION,           0, NULL, OPT_VERSION_NUM         },
-
-	{0,                     0, NULL, 0                        }
-};
+/* function to call into argparse library to parse the passed argc/argv parameters
+ * to the eal_init_args structure.
+ */
+int
+eal_collate_args(int argc, char **argv)
+{
+	if (argc < 1 || argv == NULL)
+		return -EINVAL;
+
+	/* initialize the list of arguments */
+	memset(&args, 0, sizeof(args));
+	TAILQ_INIT(&args.allow);
+	TAILQ_INIT(&args.block);
+	TAILQ_INIT(&args.driver_path);
+	TAILQ_INIT(&args.log_level);
+	TAILQ_INIT(&args.trace);
+	TAILQ_INIT(&args.vdev);
+
+	/* parse the arguments */
+	eal_argparse.prog_name = argv[0];
+	int retval = rte_argparse_parse(&eal_argparse, argc, argv);
+	if (retval < 0)
+		return retval;
+
+	argv[retval - 1] = argv[0];
+	return retval - 1;
+}
 
 TAILQ_HEAD(shared_driver_list, shared_driver);
 
@@ -299,7 +252,6 @@ static struct device_option_list devopt_list =
 TAILQ_HEAD_INITIALIZER(devopt_list);
 
 static int main_lcore_parsed;
-static int mem_parsed;
 static int core_parsed;
 
 /* Returns rte_usage_hook_t */
@@ -323,7 +275,12 @@ rte_set_application_usage_hook(rte_usage_hook_t usage_func)
 	return old_func;
 }
 
-#ifndef RTE_EXEC_ENV_WINDOWS
+#ifdef RTE_EXEC_ENV_WINDOWS
+
+int
+eal_save_args(__rte_unused int argc, __rte_unused char **argv) { return 0; }
+
+#else /* RTE_EXEC_ENV_WINDOWS */
 static char **eal_args;
 static char **eal_app_args;
 
@@ -411,7 +368,7 @@ eal_save_args(int argc, char **argv)
 	eal_args = NULL;
 	return -1;
 }
-#endif
+#endif /* !RTE_EXEC_ENV_WINDOWS */
 
 static int
 eal_option_device_add(enum rte_devtype type, const char *optarg)
@@ -839,17 +796,6 @@ eal_parse_service_coremask(const char *coremask)
 	return 0;
 }
 
-static int
-eal_service_cores_parsed(void)
-{
-	int idx;
-	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		if (lcore_config[idx].core_role == ROLE_SERVICE)
-			return 1;
-	}
-	return 0;
-}
-
 static int
 update_lcore_config(int *cores)
 {
@@ -1676,361 +1622,487 @@ eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out)
 	return -1;
 }
 
-bool
-eal_option_is_log(int opt)
+/* Parse all arguments looking for log related ones */
+int
+eal_parse_log_options(void)
 {
-	switch (opt) {
-	case OPT_LOG_COLOR_NUM:
-	case OPT_LOG_LEVEL_NUM:
-	case OPT_LOG_TIMESTAMP_NUM:
-	case OPT_SYSLOG_NUM:
-		return true;
-	default:
-		return false;
+	struct arg_list_elem *arg;
+	TAILQ_FOREACH(arg, &args.log_level, next) {
+		if (eal_parse_log_level(arg->arg) < 0) {
+			EAL_LOG(ERR, "invalid log-level parameter");
+			return -1;
+		}
+	}
+	if (args.log_color != NULL) {
+		/* if value is 1, no argument specified, so pass NULL */
+		if (args.log_color == (void *)1)
+			args.log_color = NULL;
+		if (eal_log_color(args.log_color) < 0) {
+			EAL_LOG(ERR, "invalid log-color parameter");
+			return -1;
+		}
+	}
+	if (args.log_timestamp != NULL) {
+		/* similarly log_timestamp may be 1 */
+		if (args.log_timestamp == (void *)1)
+			args.log_timestamp = NULL;
+		if (eal_log_timestamp(args.log_timestamp) < 0) {
+			EAL_LOG(ERR, "invalid log-timestamp parameter");
+			return -1;
+		}
+	}
+	if (args.syslog != NULL) {
+#ifdef RTE_EXEC_ENV_WINDOWS
+		EAL_LOG(WARNING, "syslog is not supported on Windows, ignoring parameter");
+#else
+		/* also syslog parameter may be 1 */
+		if (args.syslog == (void *)1)
+			args.syslog = NULL;
+		if (eal_log_syslog(args.syslog) < 0) {
+			EAL_LOG(ERR, "invalid syslog parameter");
+			return -1;
+		}
+#endif
 	}
+	return 0;
 }
 
-/* Parse all arguments looking for log related ones */
-int
-eal_parse_log_options(int argc, char * const argv[])
+static int
+eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
 {
-	struct internal_config *internal_conf = eal_get_internal_configuration();
-	int option_index, opt;
-	const int old_optind = optind;
-	const int old_optopt = optopt;
-	const int old_opterr = opterr;
-	char *old_optarg = optarg;
-#ifdef RTE_EXEC_ENV_FREEBSD
-	const int old_optreset = optreset;
-	optreset = 1;
-#endif
+	char *arg[RTE_MAX_NUMA_NODES];
+	char *end;
+	int arg_num, i, len;
 
-	optind = 1;
-	opterr = 0;
+	len = strnlen(strval, NUMA_MEM_STRLEN);
+	if (len == NUMA_MEM_STRLEN) {
+		EAL_LOG(ERR, "--numa-mem/--socket-mem parameter is too long");
+		return -1;
+	}
 
-	while ((opt = getopt_long(argc, argv, eal_short_options,
-				  eal_long_options, &option_index)) != EOF) {
+	/* all other error cases will be caught later */
+	if (!isdigit(strval[len-1]))
+		return -1;
 
-		if (!eal_option_is_log(opt))
-			continue;
+	/* split the optarg into separate socket values */
+	arg_num = rte_strsplit(strval, len,
+			arg, RTE_MAX_NUMA_NODES, ',');
 
-		if (eal_parse_common_option(opt, optarg, internal_conf) < 0)
+	/* if split failed, or 0 arguments */
+	if (arg_num <= 0)
+		return -1;
+
+	/* parse each defined socket option */
+	errno = 0;
+	for (i = 0; i < arg_num; i++) {
+		uint64_t val;
+		end = NULL;
+		val = strtoull(arg[i], &end, 10);
+
+		/* check for invalid input */
+		if ((errno != 0)  ||
+				(arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
 			return -1;
+		val <<= 20;
+		socket_arg[i] = val;
 	}
 
-	/* restore getopt lib */
-	optind = old_optind;
-	optopt = old_optopt;
-	optarg = old_optarg;
-	opterr = old_opterr;
-#ifdef RTE_EXEC_ENV_FREEBSD
-	optreset = old_optreset;
+	return 0;
+}
+
+static int
+eal_parse_vfio_intr(const char *mode)
+{
+	struct internal_config *internal_conf =
+		eal_get_internal_configuration();
+	static struct {
+		const char *name;
+		enum rte_intr_mode value;
+	} map[] = {
+		{ "legacy", RTE_INTR_MODE_LEGACY },
+		{ "msi", RTE_INTR_MODE_MSI },
+		{ "msix", RTE_INTR_MODE_MSIX },
+	};
+
+	for (size_t i = 0; i < RTE_DIM(map); i++) {
+		if (!strcmp(mode, map[i].name)) {
+			internal_conf->vfio_intr_mode = map[i].value;
+			return 0;
+		}
+	}
+	return -1;
+}
+
+static int
+eal_parse_vfio_vf_token(const char *vf_token)
+{
+	struct internal_config *cfg = eal_get_internal_configuration();
+	rte_uuid_t uuid;
+
+	if (!rte_uuid_parse(vf_token, uuid)) {
+		rte_uuid_copy(cfg->vfio_vf_token, uuid);
+		return 0;
+	}
+
+	return -1;
+}
+
+static int
+eal_parse_huge_worker_stack(const char *arg)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+	EAL_LOG(WARNING, "Cannot set worker stack size on Windows, parameter ignored");
+	RTE_SET_USED(arg);
+#else
+	struct internal_config *cfg = eal_get_internal_configuration();
+
+	if (arg == NULL || arg[0] == '\0') {
+		pthread_attr_t attr;
+		int ret;
+
+		if (pthread_attr_init(&attr) != 0) {
+			EAL_LOG(ERR, "Could not retrieve default stack size");
+			return -1;
+		}
+		ret = pthread_attr_getstacksize(&attr, &cfg->huge_worker_stack_size);
+		pthread_attr_destroy(&attr);
+		if (ret != 0) {
+			EAL_LOG(ERR, "Could not retrieve default stack size");
+			return -1;
+		}
+	} else {
+		unsigned long stack_size;
+		char *end;
+
+		errno = 0;
+		stack_size = strtoul(arg, &end, 10);
+		if (errno || end == NULL || stack_size == 0 ||
+				stack_size >= (size_t)-1 / 1024)
+			return -1;
+
+		cfg->huge_worker_stack_size = stack_size * 1024;
+	}
+
+	EAL_LOG(DEBUG, "Each worker thread will use %zu kB of DPDK memory as stack",
+		cfg->huge_worker_stack_size / 1024);
 #endif
 	return 0;
 }
 
+/* Parse the arguments given in the command line of the application */
 int
-eal_parse_common_option(int opt, const char *optarg,
-			struct internal_config *conf)
+eal_parse_args(void)
 {
-	static int b_used;
-	static int a_used;
-
-	switch (opt) {
-	case 'b':
-		if (a_used)
-			goto ba_conflict;
-		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0)
+	struct internal_config *int_cfg = eal_get_internal_configuration();
+	struct arg_list_elem *arg;
+
+	/* check for conflicting options */
+	/* both -a and -b cannot be used together (one list must be empty at least) */
+	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
+		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
+		return -1;
+	}
+	/* both -l and -c cannot be used at the same time */
+	if (args.coremask != NULL && args.lcores != NULL) {
+		EAL_LOG(ERR, "Options coremask (-c) and core list (-l) can't be used at the same time");
+		return -1;
+	}
+	/* both -s and -S cannot be used at the same time */
+	if (args.service_coremask != NULL && args.service_corelist != NULL) {
+		EAL_LOG(ERR, "Options service coremask (-s) and service core list (-S) can't be used at the same time");
+		return -1;
+	}
+	/* can't have both telemetry and no-telemetry */
+	if (args.no_telemetry && args.telemetry) {
+		EAL_LOG(ERR, "Options telemetry and no-telemetry can't be used at the same time");
+		return -1;
+	}
+	/* can't have both -m and --socket-mem */
+	if (args.memory_size != NULL && args.numa_mem != NULL) {
+		EAL_LOG(ERR, "Options -m and --socket-mem can't be used at the same time");
+		return -1;
+	}
+
+	/* parse options */
+	/* print version before anything else */
+	if (args.version) {
+		/* since message is explicitly requested by user, we write message
+		 * at highest log level so it can always be seen even if info or
+		 * warning messages are disabled
+		 */
+		EAL_LOG(CRIT, "RTE Version: '%s'", rte_version());
+	}
+
+	/* parse the process type */
+	if (args.proc_type != NULL) {
+		int_cfg->process_type = eal_parse_proc_type(args.proc_type);
+		if (int_cfg->process_type == RTE_PROC_INVALID) {
+			EAL_LOG(ERR, "invalid process type: %s", args.proc_type);
 			return -1;
-		b_used = 1;
-		break;
+		}
+	}
 
-	case 'a':
-		if (b_used)
-			goto ba_conflict;
-		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0)
+	/* device -a/-b/-vdev options*/
+	TAILQ_FOREACH(arg, &args.allow, next)
+		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, arg->arg) < 0)
 			return -1;
-		a_used = 1;
-		break;
-	/* coremask */
-	case 'c': {
+	TAILQ_FOREACH(arg, &args.block, next)
+		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, arg->arg) < 0)
+			return -1;
+	TAILQ_FOREACH(arg, &args.vdev, next)
+		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL, arg->arg) < 0)
+			return -1;
+	/* driver loading options */
+	TAILQ_FOREACH(arg, &args.driver_path, next)
+		if (eal_plugin_add(arg->arg) < 0)
+			return -1;
+
+	/* parse the coremask /core-list */
+	if (args.coremask != NULL) {
 		int lcore_indexes[RTE_MAX_LCORE];
 
-		if (eal_service_cores_parsed())
-			EAL_LOG(WARNING,
-				"Service cores parsed before dataplane cores. Please ensure -c is before -s or -S");
-		if (rte_eal_parse_coremask(optarg, lcore_indexes) < 0) {
+		if (rte_eal_parse_coremask(args.coremask, lcore_indexes) < 0) {
 			EAL_LOG(ERR, "invalid coremask syntax");
 			return -1;
 		}
 		if (update_lcore_config(lcore_indexes) < 0) {
 			char *available = available_cores();
 
-			EAL_LOG(ERR,
-				"invalid coremask, please check specified cores are part of %s",
-				available);
+			EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
+					args.coremask, available);
 			free(available);
 			return -1;
 		}
-
-		if (core_parsed) {
-			if (core_parsed == LCORE_OPT_MSK)
-				EAL_LOG(ERR, "Option '-c' passed multiple times to EAL");
-			else
-				EAL_LOG(ERR, "Option -c is ignored, because option -l/--lcores used");
+		core_parsed = 1;
+	} else if (args.lcores != NULL) {
+		if (eal_parse_lcores(args.lcores) < 0) {
+			EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
 			return -1;
 		}
-
-		core_parsed = LCORE_OPT_MSK;
-		break;
+		core_parsed = 1;
 	}
-	/* corelist */
-	case 'l': {
-		if (eal_service_cores_parsed())
-			EAL_LOG(WARNING,
-				"Service cores parsed before dataplane cores. Please ensure -l is before -s or -S");
-
-		if (eal_parse_lcores(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for -l/--" OPT_LCORES);
+	if (args.main_lcore != NULL) {
+		if (eal_parse_main_lcore(args.main_lcore) < 0) {
+			EAL_LOG(ERR, "invalid main-lcore parameter");
 			return -1;
 		}
+	}
 
-		if (core_parsed) {
-			if (core_parsed == LCORE_OPT_LST)
-				EAL_LOG(ERR, "Core list option passed multiple times to EAL");
-			else
-				EAL_LOG(ERR, "Option '-l/--lcores' is ignored, because coremask option used");
+	/* service core options */
+	if (args.service_coremask != NULL) {
+		if (eal_parse_service_coremask(args.service_coremask) < 0) {
+			EAL_LOG(ERR, "invalid service coremask: '%s'",
+					args.service_coremask);
 			return -1;
 		}
+	} else if (args.service_corelist != NULL) {
+		if (eal_parse_service_corelist(args.service_corelist) < 0) {
+			EAL_LOG(ERR, "invalid service core list: '%s'",
+					args.service_corelist);
+			return -1;
+		}
+	}
 
-		core_parsed = LCORE_OPT_LST;
-		break;
+	/* memory options */
+	if (args.memory_size != NULL) {
+		int_cfg->memory = atoi(args.memory_size);
+		int_cfg->memory *= 1024ULL;
+		int_cfg->memory *= 1024ULL;
 	}
-	/* service coremask */
-	case 's':
-		if (eal_parse_service_coremask(optarg) < 0) {
-			EAL_LOG(ERR, "invalid service coremask");
+	if (args.memory_channels != NULL) {
+		int_cfg->force_nchannel = atoi(args.memory_channels);
+		if (int_cfg->force_nchannel == 0) {
+			EAL_LOG(ERR, "invalid memory channel parameter");
 			return -1;
 		}
-		break;
-	/* service corelist */
-	case 'S':
-		if (eal_parse_service_corelist(optarg) < 0) {
-			EAL_LOG(ERR, "invalid service core list");
+	}
+	if (args.memory_ranks != NULL) {
+		int_cfg->force_nrank = atoi(args.memory_ranks);
+		if (int_cfg->force_nrank == 0 || int_cfg->force_nrank > 16) {
+			EAL_LOG(ERR, "invalid memory rank parameter");
 			return -1;
 		}
-		break;
-	/* size of memory */
-	case 'm':
-		conf->memory = atoi(optarg);
-		conf->memory *= 1024ULL;
-		conf->memory *= 1024ULL;
-		mem_parsed = 1;
-		break;
-	/* force number of channels */
-	case 'n':
-		conf->force_nchannel = atoi(optarg);
-		if (conf->force_nchannel == 0) {
-			EAL_LOG(ERR, "invalid channel number");
+	}
+	if (args.huge_unlink != NULL) {
+		if (args.huge_unlink == (void *)1)
+			args.huge_unlink = NULL;
+		if (eal_parse_huge_unlink(args.huge_unlink, &int_cfg->hugepage_file) < 0) {
+			EAL_LOG(ERR, "invalid huge-unlink parameter");
 			return -1;
 		}
-		break;
-	/* force number of ranks */
-	case 'r':
-		conf->force_nrank = atoi(optarg);
-		if (conf->force_nrank == 0 ||
-		    conf->force_nrank > 16) {
-			EAL_LOG(ERR, "invalid rank number");
+	}
+	if (args.no_huge) {
+		int_cfg->no_hugetlbfs = 1;
+		/* no-huge is legacy mem */
+		int_cfg->legacy_mem = 1;
+	}
+	if (args.in_memory) {
+		int_cfg->in_memory = 1;
+		/* in-memory is a superset of noshconf and huge-unlink */
+		int_cfg->no_shconf = 1;
+		int_cfg->hugepage_file.unlink_before_mapping = true;
+	}
+	if (args.legacy_mem)
+		int_cfg->legacy_mem = 1;
+	if (args.single_file_segments)
+		int_cfg->single_file_segments = 1;
+	if (args.huge_dir != NULL) {
+		free(int_cfg->hugepage_dir);  /* free old hugepage dir */
+		int_cfg->hugepage_dir = strdup(args.huge_dir);
+		if (int_cfg->hugepage_dir == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for hugepage dir parameter");
 			return -1;
 		}
-		break;
-	/* force loading of external driver */
-	case 'd':
-		if (eal_plugin_add(optarg) == -1)
+	}
+	if (args.file_prefix != NULL) {
+		free(int_cfg->hugefile_prefix);  /* free old file prefix */
+		int_cfg->hugefile_prefix = strdup(args.file_prefix);
+		if (int_cfg->hugefile_prefix == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for file prefix parameter");
 			return -1;
-		break;
-	case 'v':
-		/* since message is explicitly requested by user, we
-		 * write message at highest log level so it can always
-		 * be seen
-		 * even if info or warning messages are disabled */
-		EAL_LOG(CRIT, "RTE Version: '%s'", rte_version());
-		break;
-
-	/* long options */
-	case OPT_HUGE_UNLINK_NUM:
-		if (eal_parse_huge_unlink(optarg, &conf->hugepage_file) < 0) {
-			EAL_LOG(ERR, "invalid --"OPT_HUGE_UNLINK" option");
+		}
+	}
+	if (args.numa_mem != NULL) {
+		if (eal_parse_socket_arg(args.numa_mem, int_cfg->numa_mem) < 0) {
+			EAL_LOG(ERR, "invalid numa-mem parameter: '%s'", args.numa_mem);
 			return -1;
 		}
-		break;
-
-	case OPT_NO_HUGE_NUM:
-		conf->no_hugetlbfs = 1;
-		/* no-huge is legacy mem */
-		conf->legacy_mem = 1;
-		break;
-
-	case OPT_NO_PCI_NUM:
-		conf->no_pci = 1;
-		break;
-
-	case OPT_NO_HPET_NUM:
-		conf->no_hpet = 1;
-		break;
-
-	case OPT_VMWARE_TSC_MAP_NUM:
-		conf->vmware_tsc_map = 1;
-		break;
-
-	case OPT_NO_SHCONF_NUM:
-		conf->no_shconf = 1;
-		break;
-
-	case OPT_IN_MEMORY_NUM:
-		conf->in_memory = 1;
-		/* in-memory is a superset of noshconf and huge-unlink */
-		conf->no_shconf = 1;
-		conf->hugepage_file.unlink_before_mapping = true;
-		break;
-
-	case OPT_PROC_TYPE_NUM:
-		conf->process_type = eal_parse_proc_type(optarg);
-		break;
-
-	case OPT_MAIN_LCORE_NUM:
-		if (eal_parse_main_lcore(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_MAIN_LCORE);
+		int_cfg->force_numa = 1;
+	}
+	if (args.numa_limit != NULL) {
+		if (eal_parse_socket_arg(args.numa_limit, int_cfg->numa_limit) < 0) {
+			EAL_LOG(ERR, "invalid numa-limit parameter: '%s'", args.numa_limit);
 			return -1;
 		}
-		break;
+		int_cfg->force_numa_limits = 1;
+	}
 
-	case OPT_VDEV_NUM:
-		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
-				optarg) < 0) {
+	/* tracing settings, not supported on windows */
+#ifdef RTE_EXEC_ENV_WINDOWS
+	if (!TAILQ_EMPTY(&args.trace) ||
+			args.trace_dir != NULL ||
+			args.trace_bufsz != NULL ||
+			args.trace_mode != NULL)
+		EAL_LOG(WARNING, "Tracing is not supported on Windows, ignoring tracing parameters");
+#else
+	TAILQ_FOREACH(arg, &args.trace, next) {
+		if (eal_trace_args_save(arg->arg) < 0) {
+			EAL_LOG(ERR, "invalid trace parameter, '%s'", arg->arg);
 			return -1;
 		}
-		break;
-
-#ifndef RTE_EXEC_ENV_WINDOWS
-	case OPT_SYSLOG_NUM:
-		if (eal_log_syslog(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-					OPT_SYSLOG);
+	}
+	if (args.trace_dir != NULL) {
+		if (eal_trace_dir_args_save(args.trace_dir) < 0) {
+			EAL_LOG(ERR, "invalid trace directory, '%s'", args.trace_dir);
 			return -1;
 		}
-		break;
-#endif
-
-	case OPT_LOG_LEVEL_NUM:
-		if (eal_parse_log_level(optarg) < 0) {
-			EAL_LOG(ERR,
-				"invalid parameters for --"
-				OPT_LOG_LEVEL);
+	}
+	if (args.trace_bufsz != NULL) {
+		if (eal_trace_bufsz_args_save(args.trace_bufsz) < 0) {
+			EAL_LOG(ERR, "invalid trace buffer size, '%s'", args.trace_bufsz);
 			return -1;
 		}
-		break;
-
-	case OPT_LOG_TIMESTAMP_NUM:
-		if (eal_log_timestamp(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_LOG_TIMESTAMP);
+	}
+	if (args.trace_mode != NULL) {
+		if (eal_trace_mode_args_save(args.trace_mode) < 0) {
+			EAL_LOG(ERR, "invalid trace mode, '%s'", args.trace_mode);
 			return -1;
 		}
-		break;
+	}
+#endif
 
-	case OPT_LOG_COLOR_NUM:
-		if (eal_log_color(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_LOG_COLOR);
+	/* simple flag settings
+	 * Only set these to 1, as we don't want to set them to 0 in case
+	 * other options above have already set them.
+	 */
+	if (args.no_pci)
+		int_cfg->no_pci = 1;
+	if (args.no_hpet)
+		int_cfg->no_hpet = 1;
+	if (args.vmware_tsc_map)
+		int_cfg->vmware_tsc_map = 1;
+	if (args.no_shconf)
+		int_cfg->no_shconf = 1;
+	if (args.no_telemetry)
+		int_cfg->no_telemetry = 1;
+	if (args.match_allocations)
+		int_cfg->match_allocations = 1;
+	if (args.create_uio_dev)
+		int_cfg->create_uio_dev = 1;
+
+
+	/* other misc settings */
+	if (args.iova_mode != NULL) {
+		if (eal_parse_iova_mode(args.iova_mode) < 0) {
+			EAL_LOG(ERR, "invalid iova mode parameter '%s'", args.iova_mode);
 			return -1;
 		}
-		break;
-
-#ifndef RTE_EXEC_ENV_WINDOWS
-	case OPT_TRACE_NUM: {
-		if (eal_trace_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE);
+	};
+	if (args.base_virtaddr != NULL) {
+		if (eal_parse_base_virtaddr(args.base_virtaddr) < 0) {
+			EAL_LOG(ERR, "invalid base virtaddr '%s'", args.base_virtaddr);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_DIR_NUM: {
-		if (eal_trace_dir_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_DIR);
+	if (args.force_max_simd_bitwidth != NULL) {
+		if (eal_parse_simd_bitwidth(args.force_max_simd_bitwidth) < 0) {
+			EAL_LOG(ERR, "invalid SIMD bitwidth parameter '%s'",
+					args.force_max_simd_bitwidth);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_BUF_SIZE_NUM: {
-		if (eal_trace_bufsz_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_BUF_SIZE);
+	if (args.vfio_intr != NULL) {
+		if (eal_parse_vfio_intr(args.vfio_intr) < 0) {
+			EAL_LOG(ERR, "invalid vfio interrupt parameter: '%s'", args.vfio_intr);
 			return -1;
 		}
-		break;
 	}
-
-	case OPT_TRACE_MODE_NUM: {
-		if (eal_trace_mode_args_save(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_TRACE_MODE);
+	if (args.vfio_vf_token != NULL) {
+		if (eal_parse_vfio_vf_token(args.vfio_vf_token) < 0) {
+			EAL_LOG(ERR, "invalid vfio vf token parameter: '%s'", args.vfio_vf_token);
 			return -1;
 		}
-		break;
 	}
-#endif /* !RTE_EXEC_ENV_WINDOWS */
 
-	case OPT_LEGACY_MEM_NUM:
-		conf->legacy_mem = 1;
-		break;
-	case OPT_SINGLE_FILE_SEGMENTS_NUM:
-		conf->single_file_segments = 1;
-		break;
-	case OPT_IOVA_MODE_NUM:
-		if (eal_parse_iova_mode(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameters for --"
-				OPT_IOVA_MODE);
+	if (args.huge_worker_stack != NULL) {
+		if (args.huge_worker_stack == (void *)1)
+			args.huge_worker_stack = NULL;
+		if (eal_parse_huge_worker_stack(args.huge_worker_stack) < 0) {
+			EAL_LOG(ERR, "invalid huge worker stack parameter");
 			return -1;
 		}
-		break;
-	case OPT_BASE_VIRTADDR_NUM:
-		if (eal_parse_base_virtaddr(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_BASE_VIRTADDR);
+	}
+	if (args.mbuf_pool_ops_name != NULL) {
+		free(int_cfg->user_mbuf_pool_ops_name); /* free old ops name */
+		int_cfg->user_mbuf_pool_ops_name = strdup(args.mbuf_pool_ops_name);
+		if (int_cfg->user_mbuf_pool_ops_name == NULL) {
+			EAL_LOG(ERR, "failed to allocate memory for mbuf pool ops name parameter");
 			return -1;
 		}
-		break;
-	case OPT_TELEMETRY_NUM:
-		break;
-	case OPT_NO_TELEMETRY_NUM:
-		conf->no_telemetry = 1;
-		break;
-	case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM:
-		if (eal_parse_simd_bitwidth(optarg) < 0) {
-			EAL_LOG(ERR, "invalid parameter for --"
-					OPT_FORCE_MAX_SIMD_BITWIDTH);
+	}
+
+#ifndef RTE_EXEC_ENV_WINDOWS
+	/* create runtime data directory. In no_shconf mode, skip any errors */
+	if (eal_create_runtime_dir() < 0) {
+		if (int_cfg->no_shconf == 0) {
+			EAL_LOG(ERR, "Cannot create runtime directory");
 			return -1;
 		}
-		break;
+		EAL_LOG(WARNING, "No DPDK runtime directory created");
+	}
+#endif
 
-	/* don't know what to do, leave this to caller */
-	default:
-		return 1;
+	if (eal_adjust_config(int_cfg) != 0) {
+		EAL_LOG(ERR, "Invalid configuration");
+		return -1;
+	}
 
+	if (eal_check_common_options(int_cfg) != 0) {
+		EAL_LOG(ERR, "Checking common options failed");
+		return -1;
 	}
 
 	return 0;
-
-ba_conflict:
-	EAL_LOG(ERR,
-		"Options allow (-a) and block (-b) can't be used at the same time");
-	return -1;
 }
 
 static void
@@ -2163,13 +2235,8 @@ eal_check_common_options(struct internal_config *internal_cfg)
 			"option");
 		return -1;
 	}
-	if (mem_parsed && internal_cfg->force_numa == 1) {
-		EAL_LOG(ERR, "Options -m and --"OPT_NUMA_MEM" cannot "
-			"be specified at the same time");
-		return -1;
-	}
 	if (internal_cfg->no_hugetlbfs && internal_cfg->force_numa == 1) {
-		EAL_LOG(ERR, "Option --"OPT_NUMA_MEM" cannot "
+		EAL_LOG(ERR, "Option --"OPT_SOCKET_MEM" cannot "
 			"be specified together with --"OPT_NO_HUGE);
 		return -1;
 	}
@@ -2255,98 +2322,3 @@ rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
 	internal_conf->max_simd_bitwidth.bitwidth = bitwidth;
 	return 0;
 }
-
-void
-eal_common_usage(void)
-{
-	printf("[options]\n\n"
-	       "EAL common options:\n"
-	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
-	       "  -l, --"OPT_LCORES" CORELIST\n"
-	       "                      List of cores to run on\n"
-	       "                      The basic argument format is <c1>[-c2][,c3[-c4],...]\n"
-	       "                      where c1, c2, etc are core indexes between 0 and %d\n"
-	       "                      Can also be used to map lcore set to physical CPU set\n"
-	       "                      The argument format is\n"
-	       "                            '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
-	       "                      lcores and cpus list are grouped by '(' and ')'\n"
-	       "                      Within the group, '-' is used for range separator,\n"
-	       "                      ',' is used for single number separator.\n"
-	       "                      '( )' can be omitted for single element group,\n"
-	       "                      '@' can be omitted if cpus and lcores have the same value\n"
-	       "  -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
-	       "  -S SERVICE CORELIST List of cores to run services on\n"
-	       "  --"OPT_MAIN_LCORE" ID     Core ID that is used as main\n"
-	       "  --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
-	       "  -n CHANNELS         Number of memory channels\n"
-	       "  -m MB               Memory to allocate (see also --"OPT_NUMA_MEM")\n"
-	       "  -r RANKS            Force number of memory ranks (don't detect)\n"
-	       "  -b, --block         Add a device to the blocked list.\n"
-	       "                      Prevent EAL from using this device. The argument\n"
-	       "                      format for PCI devices is <domain:bus:devid.func>.\n"
-	       "  -a, --allow         Add a device to the allow list.\n"
-	       "                      Only use the specified devices. The argument format\n"
-	       "                      for PCI devices is <[domain:]bus:devid.func>.\n"
-	       "                      This option can be present several times.\n"
-	       "                      [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n"
-	       "  --"OPT_VDEV"              Add a virtual device.\n"
-	       "                      The argument format is <driver><id>[,key=val,...]\n"
-	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
-	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
-	       "                      'va' for IOVA_VA\n"
-	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
-	       "                      (can be used multiple times)\n"
-	       "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
-	       "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
-#ifndef RTE_EXEC_ENV_WINDOWS
-	       "  --"OPT_SYSLOG"[=<facility>] Enable use of syslog (and optionally set facility)\n"
-#endif
-	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
-	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
-	       "                      Set specific log level\n"
-	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
-	       "  --"OPT_LOG_TIMESTAMP"[=<format>]  Timestamp log output\n"
-	       "  --"OPT_LOG_COLOR"[=<when>] Colorize log messages\n"
-#ifndef RTE_EXEC_ENV_WINDOWS
-	       "  --"OPT_TRACE"=<regex-match>\n"
-	       "                      Enable trace based on regular expression trace name.\n"
-	       "                      By default, the trace is disabled.\n"
-	       "		      User must specify this option to enable trace.\n"
-	       "  --"OPT_TRACE_DIR"=<directory path>\n"
-	       "                      Specify trace directory for trace output.\n"
-	       "                      By default, trace output will created at\n"
-	       "                      $HOME directory and parameter must be\n"
-	       "                      specified once only.\n"
-	       "  --"OPT_TRACE_BUF_SIZE"=<int>\n"
-	       "                      Specify maximum size of allocated memory\n"
-	       "                      for trace output for each thread. Valid\n"
-	       "                      unit can be either 'B|K|M' for 'Bytes',\n"
-	       "                      'KBytes' and 'MBytes' respectively.\n"
-	       "                      Default is 1MB and parameter must be\n"
-	       "                      specified once only.\n"
-	       "  --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
-	       "                      Specify the mode of update of trace\n"
-	       "                      output file. Either update on a file can\n"
-	       "                      be wrapped or discarded when file size\n"
-	       "                      reaches its maximum limit.\n"
-	       "                      Default mode is 'overwrite' and parameter\n"
-	       "                      must be specified once only.\n"
-#endif /* !RTE_EXEC_ENV_WINDOWS */
-	       "  -v                  Display version information on startup\n"
-	       "  -h, --"OPT_HELP"          This help\n"
-	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
-	       "                      disable secondary process support\n"
-	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
-	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
-	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
-	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
-	       "\nEAL options for DEBUG use only:\n"
-	       "  --"OPT_HUGE_UNLINK"[=existing|always|never]\n"
-	       "                      When to unlink files in hugetlbfs\n"
-	       "                      ('existing' by default, no value means 'always')\n"
-	       "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
-	       "  --"OPT_NO_PCI"            Disable PCI\n"
-	       "  --"OPT_NO_HPET"           Disable HPET\n"
-	       "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
-	       "\n", RTE_MAX_LCORE);
-}
lib/eal/common/eal_options.h +2 -8
index 6ef45559f0..c4d2cc84dc 100644
@@ -115,18 +115,12 @@ enum {
 	OPT_LONG_MAX_NUM
 };
 
-extern const char eal_short_options[];
-extern const struct option eal_long_options[];
-
-bool eal_option_is_log(int opt);
-int eal_parse_log_options(int argc, char * const argv[]);
-int eal_parse_common_option(int opt, const char *argv,
-			    struct internal_config *conf);
+int eal_parse_log_options(void);
+int eal_parse_args(void);
 int eal_option_device_parse(void);
 int eal_adjust_config(struct internal_config *internal_cfg);
 int eal_cleanup_config(struct internal_config *internal_cfg);
 int eal_check_common_options(struct internal_config *internal_cfg);
-void eal_common_usage(void);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
lib/eal/common/eal_private.h +11 -0
index 5846917cc5..ab8b37b956 100644
@@ -72,6 +72,17 @@ struct rte_config {
  */
 struct rte_config *rte_eal_get_configuration(void);
 
+/**
+ * Put the argument list into a structure.
+ *
+ * This allows the arguments to then be processed out-of-order.
+ *
+ * @return
+ *  - 0 on success
+ * - Negative on error
+ */
+int eal_collate_args(int argc, char **argv);
+
 /**
  * Initialize the memzone subsystem (private to eal).
  *
lib/eal/freebsd/eal.c +17 -147

213 lines not on this page · raw message

lib/eal/linux/eal.c +13 -366

410 lines not on this page · raw message

lib/eal/windows/eal.c +16 -97

132 lines not on this page · raw message

Signature · 1 line
2.48.1
#126 lore raw

PATCH v9 9/18 eal: ensure proper cleanup on EAL init failure

In reply to Bruce Richardson

When rte_eal_init fails part way through, any saved EAL arguments need to be freed, and the run_once flag needs to be set back to zero again. The former task was never done on failure, and the latter was only done on some occasions. Rework the error handling to always go to an err_out label where cleanup is done.

To prevent memory leaks from the saved arguments when eal_init is called twice, the check for multiple calls must be done first before the argument saving and parsing is done.

This patch modifies all three eal.c files. Windows doesn't actually need changes, since there are no args saved, and no run_once sentinel value, but updating it keeps it consistent with FreeBSD and Linux versions.

---
 lib/eal/common/eal_common_options.c | 37 ++++++++----
 lib/eal/common/eal_options.h        |  1 +
 lib/eal/freebsd/eal.c               | 83 +++++++++++++-------------
 lib/eal/linux/eal.c                 | 90 ++++++++++++++---------------
 lib/eal/windows/eal.c               | 47 ++++++++-------
 5 files changed, 137 insertions(+), 121 deletions(-)
lib/eal/common/eal_common_options.c +25 -12
index 72df7c5b48..e3e3deb7f4 100644
@@ -279,6 +279,8 @@ rte_set_application_usage_hook(rte_usage_hook_t usage_func)
 
 int
 eal_save_args(__rte_unused int argc, __rte_unused char **argv) { return 0; }
+void
+eal_clean_saved_args(void) { /* no-op */ }
 
 #else /* RTE_EXEC_ENV_WINDOWS */
 static char **eal_args;
@@ -310,6 +312,28 @@ handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 	return used;
 }
 
+void
+eal_clean_saved_args(void)
+{
+	int i;
+
+	if (eal_args == NULL)
+		return;
+
+	if (eal_app_args != NULL) {
+		i = 0;
+		while (eal_app_args[i] != NULL)
+			free(eal_app_args[i++]);
+		free(eal_app_args);
+		eal_app_args = NULL;
+	}
+	i = 0;
+	while (eal_args[i] != NULL)
+		free(eal_args[i++]);
+	free(eal_args);
+	eal_args = NULL;
+}
+
 int
 eal_save_args(int argc, char **argv)
 {
@@ -354,18 +378,7 @@ eal_save_args(int argc, char **argv)
 	return 0;
 
 error:
-	if (eal_app_args != NULL) {
-		i = 0;
-		while (eal_app_args[i] != NULL)
-			free(eal_app_args[i++]);
-		free(eal_app_args);
-		eal_app_args = NULL;
-	}
-	i = 0;
-	while (eal_args[i] != NULL)
-		free(eal_args[i++]);
-	free(eal_args);
-	eal_args = NULL;
+	eal_clean_saved_args();
 	return -1;
 }
 #endif /* !RTE_EXEC_ENV_WINDOWS */
lib/eal/common/eal_options.h +1 -0
index c4d2cc84dc..fd28111e73 100644
@@ -124,6 +124,7 @@ int eal_check_common_options(struct internal_config *internal_cfg);
 enum rte_proc_type_t eal_proc_type_detect(void);
 int eal_plugins_init(void);
 int eal_save_args(int argc, char **argv);
+void eal_clean_saved_args(void);
 int handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 		struct rte_tel_data *d);
 
lib/eal/freebsd/eal.c +41 -42

255 lines not on this page · raw message

lib/eal/linux/eal.c +45 -45

271 lines not on this page · raw message

lib/eal/windows/eal.c +25 -22

176 lines not on this page · raw message

Signature · 1 line
2.48.1
#127 lore raw

PATCH v9 10/18 eal: combine parameter validation checks

In reply to Bruce Richardson

Remove the separate function to check combinations of cmdline parameters. Instead, just do those checks when parsing the parameters since we have all info about what parameters are provided at that point.

---
 lib/eal/common/eal_common_memory.c  |   3 +-
 lib/eal/common/eal_common_options.c | 262 +++++++++++-----------------
 lib/eal/common/eal_options.h        | 107 ------------
 lib/eal/linux/eal.c                 |   5 +-
 lib/eal/linux/eal_memory.c          |   2 +-
 5 files changed, 106 insertions(+), 273 deletions(-)
lib/eal/common/eal_common_memory.c +1 -2
index 38ccc734e8..c62edf5e55 100644
@@ -258,8 +258,7 @@ eal_memseg_list_alloc(struct rte_memseg_list *msl, int reserve_flags)
 		 * including common code, so don't duplicate the message.
 		 */
 		if (rte_errno == EADDRNOTAVAIL)
-			EAL_LOG(ERR, "Cannot reserve %llu bytes at [%p] - "
-				"please use '--" OPT_BASE_VIRTADDR "' option",
+			EAL_LOG(ERR, "Cannot reserve %llu bytes at [%p] - please use '--base-virtaddr' option",
 				(unsigned long long)mem_sz, msl->base_va);
 #endif
 		return -1;
lib/eal/common/eal_common_options.c +102 -160

390 lines not on this page · raw message

lib/eal/common/eal_options.h +0 -107

118 lines not on this page · raw message

lib/eal/linux/eal.c +2 -3
index 9fd426f214..b12f325ddd 100644
@@ -329,9 +329,8 @@ rte_eal_config_reattach(void)
 	if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
 		if (mem_config != MAP_FAILED) {
 			/* errno is stale, don't use */
-			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p]"
-				" - please use '--" OPT_BASE_VIRTADDR
-				"' option", rte_mem_cfg_addr, mem_config);
+			EAL_LOG(ERR, "Cannot mmap memory for rte_config at [%p], got [%p] - please use '--base-virtaddr' option",
+				 rte_mem_cfg_addr, mem_config);
 			munmap(mem_config, sizeof(struct rte_mem_config));
 			return -1;
 		}
lib/eal/linux/eal_memory.c +1 -1
index ee964446c7..8e1763e890 100644
@@ -1960,7 +1960,7 @@ rte_eal_memseg_init(void)
 	if (!internal_conf->legacy_mem && rte_socket_count() > 1) {
 		EAL_LOG(WARNING, "DPDK is running on a NUMA system, but is compiled without NUMA support.");
 		EAL_LOG(WARNING, "This will have adverse consequences for performance and usability.");
-		EAL_LOG(WARNING, "Please use --"OPT_LEGACY_MEM" option, or recompile with NUMA support.");
+		EAL_LOG(WARNING, "Please use --legacy-mem option, or recompile with NUMA support.");
 	}
 #endif
 
Signature · 1 line
2.48.1
#128 lore raw

PATCH v9 11/18 eal: simplify handling of conflicting cmdline options

In reply to Bruce Richardson

Use a utility function and macro to simplify the code for checking for conflicting cmdline options. The checking can also be done at the initial argument collating stage, shortening the argument processing function which is very much on the long side.

---
 lib/eal/common/eal_common_options.c | 119 +++++++++++-----------------
 1 file changed, 47 insertions(+), 72 deletions(-)
lib/eal/common/eal_common_options.c +47 -72
index b6aeeadd8d..db74bf2c61 100644
@@ -184,6 +184,29 @@ struct rte_argparse eal_argparse  = {
 	}
 };
 
+static inline bool
+conflicting_options(uintptr_t opt1, uintptr_t opt2, const char *opt1_name, const char *opt2_name)
+{
+	char name1[64];  /* should be the max length of any argument */
+	char name2[64];
+
+	strlcpy(name1, opt1_name, sizeof(name1));
+	strlcpy(name2, opt2_name, sizeof(name2));
+	for (int i = 0; name1[i] != '\0'; i++)
+		if (name1[i] == '_')
+			name1[i] = '-';
+	for (int i = 0; name2[i] != '\0'; i++)
+		if (name2[i] == '_')
+			name2[i] = '-';
+	if (opt1 && opt2) {
+		EAL_LOG(ERR, "Options '%s' and '%s' can't be used at the same time", name1, name2);
+		return true;
+	}
+	return false;  /* no conflicts */
+}
+#define CONFLICTING_OPTIONS(args, opt1, opt2) \
+	conflicting_options((uintptr_t)(args.opt1), (uintptr_t)(args.opt2), #opt1, #opt2)
+
 /* function to call into argparse library to parse the passed argc/argv parameters
  * to the eal_init_args structure.
  */
@@ -208,6 +231,30 @@ eal_collate_args(int argc, char **argv)
 	if (retval < 0)
 		return retval;
 
+	/* check for conflicting options */
+	/* both -a and -b cannot be used together (one list must be empty at least) */
+	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
+		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
+		return -1;
+	}
+
+	/* for non-list args, we can just check for zero/null values using macro */
+	if (CONFLICTING_OPTIONS(args, coremask, lcores) ||
+			CONFLICTING_OPTIONS(args, service_coremask, service_corelist) ||
+			CONFLICTING_OPTIONS(args, no_telemetry, telemetry) ||
+			CONFLICTING_OPTIONS(args, memory_size, numa_mem) ||
+			CONFLICTING_OPTIONS(args, no_huge, numa_mem) ||
+			CONFLICTING_OPTIONS(args, no_huge, huge_worker_stack) ||
+			CONFLICTING_OPTIONS(args, numa_limit, legacy_mem) ||
+			CONFLICTING_OPTIONS(args, legacy_mem, in_memory) ||
+			CONFLICTING_OPTIONS(args, legacy_mem, match_allocations) ||
+			CONFLICTING_OPTIONS(args, no_huge, match_allocations) ||
+			CONFLICTING_OPTIONS(args, no_huge, huge_unlink) ||
+			CONFLICTING_OPTIONS(args, single_file_segments, huge_unlink) ||
+			CONFLICTING_OPTIONS(args, no_huge, single_file_segments) ||
+			CONFLICTING_OPTIONS(args, in_memory, huge_unlink))
+		return -1;
+
 	argv[retval - 1] = argv[0];
 	return retval - 1;
 }
@@ -1794,78 +1841,6 @@ eal_parse_args(void)
 	struct rte_config *rte_cfg = rte_eal_get_configuration();
 	struct arg_list_elem *arg;
 
-	/* check for conflicting options */
-	/* both -a and -b cannot be used together (one list must be empty at least) */
-	if (!TAILQ_EMPTY(&args.allow) && !TAILQ_EMPTY(&args.block)) {
-		EAL_LOG(ERR, "Options allow (-a) and block (-b) can't be used at the same time");
-		return -1;
-	}
-	/* both -l and -c cannot be used at the same time */
-	if (args.coremask != NULL && args.lcores != NULL) {
-		EAL_LOG(ERR, "Options coremask (-c) and core list (-l) can't be used at the same time");
-		return -1;
-	}
-	/* both -s and -S cannot be used at the same time */
-	if (args.service_coremask != NULL && args.service_corelist != NULL) {
-		EAL_LOG(ERR, "Options service coremask (-s) and service core list (-S) can't be used at the same time");
-		return -1;
-	}
-	/* can't have both telemetry and no-telemetry */
-	if (args.no_telemetry && args.telemetry) {
-		EAL_LOG(ERR, "Options telemetry and no-telemetry can't be used at the same time");
-		return -1;
-	}
-	/* can't have both -m and --socket-mem */
-	if (args.memory_size != NULL && args.numa_mem != NULL) {
-		EAL_LOG(ERR, "Options -m and --numa-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use both no-huge and socket-mem */
-	if (args.no_huge && args.numa_mem) {
-		EAL_LOG(ERR, "Options --no-huge and --numa-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and huge-worker-stack */
-	if (args.huge_worker_stack != NULL && args.no_huge) {
-		EAL_LOG(ERR, "Options --no-huge and --huge-worker-stack can't be used at the same time");
-		return -1;
-	}
-	/* can't use socket-limit and legacy-mem */
-	if (args.numa_limit != NULL && args.legacy_mem) {
-		EAL_LOG(ERR, "Options --numa-limit and --legacy-mem can't be used at the same time");
-		return -1;
-	}
-	/* can't use legacy-mem and in-memory */
-	if (args.legacy_mem && args.in_memory) {
-		EAL_LOG(ERR, "Options --legacy-mem and --in-memory can't be used at the same time");
-		return -1;
-	}
-	/* can't use legacy-mem and match-allocations */
-	if (args.legacy_mem && args.match_allocations) {
-		EAL_LOG(ERR, "Options --legacy-mem and --match-allocations can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and match-allocations */
-	if (args.no_huge && args.match_allocations) {
-		EAL_LOG(ERR, "Options --no-huge and --match-allocations can't be used at the same time");
-		return -1;
-	}
-	/* can't use no-huge and huge-unlink */
-	if (args.no_huge && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --no-huge and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-	/* can't use single-file-segments and huge-unlink */
-	if (args.single_file_segments && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --single-file-segments and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-	/* can't use in-memory and huge-unlink */
-	if (args.in_memory && args.huge_unlink) {
-		EAL_LOG(ERR, "Options --in-memory and --huge-unlink can't be used at the same time");
-		return -1;
-	}
-
 	/* print version before anything else */
 	/* since message is explicitly requested by user, we write message
 	 * at highest log level so it can always be seen even if info or
Signature · 1 line
2.48.1
#129 lore raw

PATCH v9 12/18 eal: automatically init arg list options

In reply to Bruce Richardson

The tailq list options from commandline require initialization before being used. This was being done by explicitly initing those values in the collate function. A better option is to do so using macros at time of structure definition, that way, adding a new list option does not require any other code changes to initialize it.

Since we are now including the same header 3 times, and need to undefine the macros between inclusions, we simplify things by just doing the undef calls at the end of the included header.

---
 lib/eal/common/eal_common_options.c | 30 ++++++++++++-----------------
 lib/eal/common/eal_option_list.h    |  7 +++++++
 2 files changed, 19 insertions(+), 18 deletions(-)
lib/eal/common/eal_common_options.c +12 -18
index db74bf2c61..d7a8263f08 100644
@@ -74,9 +74,19 @@ struct eal_init_args {
 
 #define INCLUDE_ALL_ARG 1  /* for struct definition, include even unsupported values */
 #include "eal_option_list.h"
-#undef INCLUDE_ALL_ARG
 };
-struct eal_init_args args;
+
+/* define the structure itself, with initializers. Only the LIST_ARGS need init */
+#define LIST_ARG(long, short, help_str, fieldname) .fieldname = TAILQ_HEAD_INITIALIZER(args.fieldname),
+#define STR_ARG(long, short, help_str, fieldname)
+#define OPT_STR_ARG(long, short, help_str, fieldname)
+#define BOOL_ARG(long, short, help_str, fieldname)
+#define STR_ALIAS(long, short, help_str, fieldname)
+
+struct eal_init_args args = {
+	#include "eal_option_list.h"
+};
+#undef INCLUDE_ALL_ARG
 
 /* an rte_argparse callback to append the argument to an arg_list
  * in args. The index is the offset into the struct of the list.
@@ -109,13 +119,6 @@ eal_usage(const struct rte_argparse *obj)
 		rte_application_usage_hook(obj->prog_name);
 }
 
-/* undef the *_ARG macros before redefining to generate the argparse arg list */
-#undef LIST_ARG
-#undef STR_ARG
-#undef OPT_STR_ARG
-#undef BOOL_ARG
-#undef STR_ALIAS
-
 /* For arguments which have an arg_list type, they use callback (no val_saver),
  * require a value, and have the SUPPORT_MULTI flag.
  */
@@ -216,15 +219,6 @@ eal_collate_args(int argc, char **argv)
 	if (argc < 1 || argv == NULL)
 		return -EINVAL;
 
-	/* initialize the list of arguments */
-	memset(&args, 0, sizeof(args));
-	TAILQ_INIT(&args.allow);
-	TAILQ_INIT(&args.block);
-	TAILQ_INIT(&args.driver_path);
-	TAILQ_INIT(&args.log_level);
-	TAILQ_INIT(&args.trace);
-	TAILQ_INIT(&args.vdev);
-
 	/* parse the arguments */
 	eal_argparse.prog_name = argv[0];
 	int retval = rte_argparse_parse(&eal_argparse, argc, argv);
lib/eal/common/eal_option_list.h +7 -0
index 6a0c501680..f5c21c8376 100644
@@ -88,3 +88,10 @@ STR_ALIAS("--socket-limit", NULL, "Alias for --numa-limit", numa_limit)
 STR_ARG("--vfio-intr", NULL, "VFIO interrupt mode (legacy|msi|msix)", vfio_intr)
 STR_ARG("--vfio-vf-token", NULL, "VF token (UUID) shared between SR-IOV PF and VFs", vfio_vf_token)
 #endif
+
+/* undefine all used defines */
+#undef LIST_ARG
+#undef STR_ARG
+#undef OPT_STR_ARG
+#undef BOOL_ARG
+#undef STR_ALIAS
Signature · 1 line
2.48.1
#130 lore raw

PATCH v9 13/18 eal: add internal fn for converting cpuset to string

In reply to Bruce Richardson

The existing "available_cores" function in eal_common_options.c has general code for converting a set of cores to a printable string. Generalize this code into an "eal_cpuset_to_str" function which takes a cpuset as parameter, and create a new "available_cores" function using this new utility function.

---
 lib/eal/common/eal_common_options.c | 33 ++++++++++++++++++++++-------
 lib/eal/common/eal_private.h        | 10 +++++++++
 2 files changed, 35 insertions(+), 8 deletions(-)
lib/eal/common/eal_common_options.c +25 -8
index d7a8263f08..e89ca615b8 100644
@@ -1570,8 +1570,8 @@ eal_parse_base_virtaddr(const char *arg)
 }
 
 /* caller is responsible for freeing the returned string */
-static char *
-available_cores(void)
+char *
+eal_cpuset_to_str(const rte_cpuset_t *cpuset)
 {
 	char *str = NULL;
 	int previous;
@@ -1579,13 +1579,13 @@ available_cores(void)
 	char *tmp;
 	int idx;
 
-	/* find the first available cpu */
-	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
-		if (eal_cpu_detected(idx) == 0)
+	/* find the first set cpu */
+	for (idx = 0; idx < CPU_SETSIZE; idx++) {
+		if (!CPU_ISSET(idx, cpuset))
 			continue;
 		break;
 	}
-	if (idx >= RTE_MAX_LCORE)
+	if (idx >= CPU_SETSIZE)
 		return NULL;
 
 	/* first sequence */
@@ -1594,8 +1594,8 @@ available_cores(void)
 	previous = idx;
 	sequence = 0;
 
-	for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
-		if (eal_cpu_detected(idx) == 0)
+	for (idx++ ; idx < CPU_SETSIZE; idx++) {
+		if (!CPU_ISSET(idx, cpuset))
 			continue;
 
 		if (idx == previous + 1) {
@@ -1638,6 +1638,23 @@ available_cores(void)
 	return str;
 }
 
+/* caller is responsible for freeing the returned string */
+static char *
+available_cores(void)
+{
+	rte_cpuset_t cpuset;
+	int idx;
+
+	/* build cpuset of available cores */
+	CPU_ZERO(&cpuset);
+	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
+		if (eal_cpu_detected(idx))
+			CPU_SET(idx, &cpuset);
+	}
+
+	return eal_cpuset_to_str(&cpuset);
+}
+
 #define HUGE_UNLINK_NEVER "never"
 
 static int
lib/eal/common/eal_private.h +10 -0
index ab8b37b956..e032dd10c9 100644
@@ -83,6 +83,16 @@ struct rte_config *rte_eal_get_configuration(void);
  */
 int eal_collate_args(int argc, char **argv);
 
+/**
+ * Convert an rte_cpuset_t to string form suitable for parsing by argparse.
+ *
+ * @param cpuset
+ *   The cpuset to convert to string form.
+ * @return
+ *   String representation of the cpuset (caller must free), or NULL on error.
+ */
+char *eal_cpuset_to_str(const rte_cpuset_t *cpuset);
+
 /**
  * Initialize the memzone subsystem (private to eal).
  *
Signature · 1 line
2.48.1
#131 lore raw

PATCH v9 14/18 eal: use common cpuset to string function

In reply to Bruce Richardson

Use the new cpuset to string function to replace other thread-specific functions which did similar work. Also use it for additional debug logs.

---
 lib/eal/common/eal_common_lcore.c   | 13 ++++-----
 lib/eal/common/eal_common_options.c | 22 +++++++++++++++
 lib/eal/common/eal_common_thread.c  | 43 ++++++++---------------------
 lib/eal/common/eal_thread.h         | 13 ++-------
 4 files changed, 42 insertions(+), 49 deletions(-)
lib/eal/common/eal_common_lcore.c +6 -7
index 5c8b0f9aa2..39411f9370 100644
@@ -481,12 +481,11 @@ static int
 lcore_dump_cb(unsigned int lcore_id, void *arg)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
-	char cpuset[RTE_CPU_AFFINITY_STR_LEN];
+	char *cpuset;
 	struct rte_lcore_usage usage;
 	rte_lcore_usage_cb usage_cb;
 	char *usage_str = NULL;
 	FILE *f = arg;
-	int ret;
 
 	/* The callback may not set all the fields in the structure, so clear it here. */
 	memset(&usage, 0, sizeof(usage));
@@ -499,12 +498,12 @@ lcore_dump_cb(unsigned int lcore_id, void *arg)
 			return -ENOMEM;
 		}
 	}
-	ret = eal_thread_dump_affinity(&lcore_config[lcore_id].cpuset, cpuset,
-		sizeof(cpuset));
-	fprintf(f, "lcore %u, socket %u, role %s, cpuset %s%s%s\n", lcore_id,
+	cpuset = eal_cpuset_to_str(&lcore_config[lcore_id].cpuset);
+	fprintf(f, "lcore %u, socket %u, role %s, cpuset %s\n", lcore_id,
 		rte_lcore_to_socket_id(lcore_id),
-		lcore_role_str(cfg->lcore_role[lcore_id]), cpuset,
-		ret == 0 ? "" : "...", usage_str != NULL ? usage_str : "");
+		lcore_role_str(cfg->lcore_role[lcore_id]),
+		cpuset != NULL ? cpuset : "<unknown>");
+	free(cpuset);
 	free(usage_str);
 
 	return 0;
lib/eal/common/eal_common_options.c +22 -0
index e89ca615b8..0f3db158f6 100644
@@ -1049,6 +1049,21 @@ eal_parse_service_corelist(const char *corelist)
 			"Please ensure -c or -l includes service cores");
 	}
 
+	/* log the configured service cores for debugging */
+	rte_cpuset_t service_cpuset;
+	CPU_ZERO(&service_cpuset);
+	for (i = 0; i < RTE_MAX_LCORE; i++) {
+		if (lcore_config[i].core_role == ROLE_SERVICE)
+			CPU_SET(i, &service_cpuset);
+	}
+	if (CPU_COUNT(&service_cpuset) > 0) {
+		char *cpuset_str = eal_cpuset_to_str(&service_cpuset);
+		if (cpuset_str != NULL) {
+			EAL_LOG(DEBUG, "Service cores configured: %s", cpuset_str);
+			free(cpuset_str);
+		}
+	}
+
 	return 0;
 }
 
@@ -2195,6 +2210,13 @@ compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 		memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset,
 			sizeof(*cpuset));
 	}
+
+	/* log the computed control thread cpuset for debugging */
+	char *cpuset_str = eal_cpuset_to_str(cpuset);
+	if (cpuset_str != NULL) {
+		EAL_LOG(DEBUG, "Control threads will use cores: %s", cpuset_str);
+		free(cpuset_str);
+	}
 }
 
 int
lib/eal/common/eal_common_thread.c +12 -31

55 lines not on this page · raw message

lib/eal/common/eal_thread.h +2 -11
index 1c3c3442d3..586de05081 100644
@@ -33,28 +33,19 @@ unsigned eal_cpu_socket_id(unsigned cpu_id);
 #define RTE_CPU_AFFINITY_STR_LEN            256
 
 /**
- * Dump the cpuset as a human readable string.
+ * Dump the current thread cpuset as a human readable string.
  * This function is private to EAL.
  *
  * Note:
  *   If the dump size is greater than the size of given buffer,
  *   the string will be truncated and with '\0' at the end.
  *
- * @param cpuset
- *   The CPU affinity object to dump.
  * @param str
  *   The string buffer the cpuset will dump to.
  * @param size
  *   The string buffer size.
  * @return
- *   0 for success, -1 if truncation happens.
- */
-int
-eal_thread_dump_affinity(rte_cpuset_t *cpuset, char *str, unsigned int size);
-
-/**
- * Dump the current thread cpuset.
- * This is a wrapper on eal_thread_dump_affinity().
+ *   0 for success, -1 if error or truncation happens.
  */
 int
 eal_thread_dump_current_affinity(char *str, unsigned int size);
Signature · 1 line
2.48.1
#132 lore raw

PATCH v9 15/18 eal: introduce lcore remapping option for coremasks

In reply to Bruce Richardson

Add the new "--remap-lcore-ids" or "-R" option to signify that lcore ids are to start at a low range. This takes an optional parameter to specify the value to start from. Initially, use this to adjust the core mappings when using a coremask.

As well as remapping within the range of RTE_MAX_LCORE, to allow use of cores >=RTE_MAX_LCORE we need to expand the internal arrays of cores to be CPU_SETSIZE big, and limit the checks for RTE_MAX_LCORE to only cases where we are not remapping. This requires an additional parameter to the internal API rte_eal_parse_coremask, having a small knock-on effect on DLB driver as the only other user of this API.

---
 drivers/event/dlb2/dlb2_priv.h             |  2 +-
 drivers/event/dlb2/pf/base/dlb2_resource.c |  4 +-
 lib/eal/common/eal_common_options.c        | 54 +++++++++++++++++-----
 lib/eal/common/eal_option_list.h           |  1 +
 lib/eal/include/rte_eal.h                  |  6 ++-
 5 files changed, 50 insertions(+), 17 deletions(-)
drivers/event/dlb2/dlb2_priv.h +1 -1
index 7a5cbcca1e..6e0a5bc936 100644
@@ -750,7 +750,7 @@ void dlb2_event_build_hcws(struct dlb2_port *qm_port,
 			   uint8_t *queue_id);
 
 /* Extern functions */
-extern int rte_eal_parse_coremask(const char *coremask, int *cores);
+extern int rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
 
 /* Extern globals */
 extern struct process_local_port_data dlb2_port[][DLB2_NUM_PORT_TYPES];
drivers/event/dlb2/pf/base/dlb2_resource.c +2 -2
index 98f2f5ef92..6742c470f1 100644
@@ -922,13 +922,13 @@ dlb2_resource_probe(struct dlb2_hw *hw, const void *probe_args)
 {
 	const struct dlb2_devargs *args = (const struct dlb2_devargs *)probe_args;
 	const char *mask = args ? args->producer_coremask : NULL;
-	int cpu = 0, cnt = 0, cores[RTE_MAX_LCORE], i;
+	int cpu = 0, cnt = 0, cores[CPU_SETSIZE], i;
 
 	if (args) {
 		mask = (const char *)args->producer_coremask;
 	}
 
-	if (mask && rte_eal_parse_coremask(mask, cores)) {
+	if (mask && rte_eal_parse_coremask(mask, cores, true)) {
 		DLB2_HW_ERR(hw, ": Invalid producer coremask=%s\n", mask);
 		return -1;
 	}
lib/eal/common/eal_common_options.c +42 -12

118 lines not on this page · raw message

lib/eal/common/eal_option_list.h +1 -0
index f5c21c8376..e4a849e78e 100644
@@ -57,6 +57,7 @@ BOOL_ARG("--no-pci", NULL, "Disable all PCI devices", no_pci)
 BOOL_ARG("--no-shconf", NULL, "Disable shared config file generation", no_shconf)
 BOOL_ARG("--no-telemetry", NULL, "Disable telemetry", no_telemetry)
 STR_ARG("--proc-type", NULL, "Type of process (primary|secondary|auto)", proc_type)
+OPT_STR_ARG("--remap-lcore-ids", "-R", "Remap lcore IDs to be contiguous starting from 0, or supplied value", remap_lcore_ids)
 STR_ARG("--service-corelist", "-S", "List of cores to use for service threads", service_corelist)
 STR_ARG("--service-coremask", "-s", "[Deprecated] Bitmask of cores to use for service threads", service_coremask)
 BOOL_ARG("--single-file-segments", NULL, "Store all pages within single files (per-page-size, per-node)", single_file_segments)
lib/eal/include/rte_eal.h +4 -2
index 08977c61d3..bc58254ece 100644
@@ -503,13 +503,15 @@ rte_eal_get_runtime_dir(void);
  *   A string describing a mask of core ids.
  * @param cores
  *   An array where to store the core ids orders.
- *   This array must be at least RTE_MAX_LCORE large.
+ *   This array must be at least CPU_SETSIZE large.
+ * @param limit_range
+ *   If set, return an error if any cores in the mask are >= RTE_MAX_LCORE.
  * @return
  *   0 on success, -1 if the string content was invalid.
  */
 __rte_internal
 int
-rte_eal_parse_coremask(const char *coremask, int *cores);
+rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
 
 #ifdef __cplusplus
 }
Signature · 1 line
2.48.1
#133 lore raw

PATCH v9 16/18 eal: rework internal coremask parsing to use cpu sets

In reply to Bruce Richardson

Rather than working off arrays of lcore values, update the coremask handling to use rte_cpuset_t. The use of the array provides no additional value for coremasks, since the order of the bits set will always be from lowest core number to highest, making the tracking of what core was 0, 1, 2 etc. pointless.

As part of this change, move the prototype for the parse_coremask function from rte_eal.h to eal_options.h, for two reasons:

1. This is an internal function that should not be used by apps and so there is no need to have it in a public header.
2. If the compilation command is run without the _GNU_SOURCE flag, we miss definitions from sched.h and so get build errors for the rte_cpuset_t type when compiling examples against an installed DPDK.

---
 drivers/event/dlb2/dlb2_priv.h             |  2 +-
 drivers/event/dlb2/pf/base/dlb2_resource.c | 11 ++++----
 lib/eal/common/eal_common_options.c        | 30 ++++++++--------------
 lib/eal/common/eal_options.h               |  2 ++
 lib/eal/include/rte_eal.h                  | 22 ----------------
 5 files changed, 19 insertions(+), 48 deletions(-)
drivers/event/dlb2/dlb2_priv.h +1 -1
index 6e0a5bc936..607b4d24d0 100644
@@ -750,7 +750,7 @@ void dlb2_event_build_hcws(struct dlb2_port *qm_port,
 			   uint8_t *queue_id);
 
 /* Extern functions */
-extern int rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
+extern int rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_range);
 
 /* Extern globals */
 extern struct process_local_port_data dlb2_port[][DLB2_NUM_PORT_TYPES];
drivers/event/dlb2/pf/base/dlb2_resource.c +6 -5
index 6742c470f1..490dcaf7dd 100644
@@ -922,28 +922,29 @@ dlb2_resource_probe(struct dlb2_hw *hw, const void *probe_args)
 {
 	const struct dlb2_devargs *args = (const struct dlb2_devargs *)probe_args;
 	const char *mask = args ? args->producer_coremask : NULL;
-	int cpu = 0, cnt = 0, cores[CPU_SETSIZE], i;
+	rte_cpuset_t cpuset;
+	int cpu = 0, cnt = 0, i, set_count = 0;
 
 	if (args) {
 		mask = (const char *)args->producer_coremask;
 	}
 
-	if (mask && rte_eal_parse_coremask(mask, cores, true)) {
+	if (mask && rte_eal_parse_coremask(mask, &cpuset, true)) {
 		DLB2_HW_ERR(hw, ": Invalid producer coremask=%s\n", mask);
 		return -1;
 	}
 
 	hw->num_prod_cores = 0;
 	for (i = 0; i < RTE_MAX_LCORE; i++) {
-		bool is_pcore = (mask && cores[i] != -1);
+		bool is_pcore = (mask && CPU_ISSET(i, &cpuset));
 
 		if (rte_lcore_is_enabled(i)) {
 			if (is_pcore) {
 				/*
 				 * Populate the producer cores from parsed
-				 * coremask
+				 * coremask using the set_count as index.
 				 */
-				hw->prod_core_list[cores[i]] = i;
+				hw->prod_core_list[set_count++] = i;
 				hw->num_prod_cores++;
 
 			} else if ((++cnt == DLB2_EAL_PROBE_CORE ||
lib/eal/common/eal_common_options.c +10 -20
index 95081c9f54..86351535ee 100644
@@ -841,7 +841,7 @@ eal_parse_service_coremask(const char *coremask)
 }
 
 static int
-update_lcore_config(int *cores, bool remap, uint16_t remap_base)
+update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base)
 {
 	struct rte_config *cfg = rte_eal_get_configuration();
 	unsigned int count = 0;
@@ -855,9 +855,9 @@ update_lcore_config(int *cores, bool remap, uint16_t remap_base)
 		lcore_config[i].core_index = -1;
 	}
 
-	/* now go through the core mask */
+	/* now go through the cpuset */
 	for (i = 0; i < CPU_SETSIZE; i++) {
-		if (cores[i] != -1) {
+		if (CPU_ISSET(i, cpuset)) {
 			if (eal_cpu_detected(i) == 0) {
 				EAL_LOG(ERR, "lcore %u unavailable", i);
 				ret = -1;
@@ -866,7 +866,7 @@ update_lcore_config(int *cores, bool remap, uint16_t remap_base)
 			if (!remap)
 				lcore_id = i;
 			cfg->lcore_role[lcore_id] = ROLE_RTE;
-			lcore_config[lcore_id].core_index = cores[i];
+			lcore_config[lcore_id].core_index = count;
 			CPU_ZERO(&lcore_config[lcore_id].cpuset);
 			CPU_SET(i, &lcore_config[lcore_id].cpuset);
 			EAL_LOG(DEBUG, "lcore %u mapped to physical core %u", lcore_id, i);
@@ -919,7 +919,7 @@ check_core_list(int *lcores, unsigned int count)
 
 RTE_EXPORT_INTERNAL_SYMBOL(rte_eal_parse_coremask)
 int
-rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
+rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_range)
 {
 	const char *coremask_orig = coremask;
 	int lcores[CPU_SETSIZE];
@@ -928,8 +928,7 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
 	int val;
 	char c;
 
-	for (idx = 0; idx < CPU_SETSIZE; idx++)
-		cores[idx] = -1;
+	CPU_ZERO(cpuset);
 	idx = 0;
 
 	EAL_LOG(WARNING, "'-c <coremask>' option is deprecated, and will be removed in a future release");
@@ -975,6 +974,7 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
 					return -1;
 				}
 				lcores[count++] = idx;
+				CPU_SET(idx, cpuset);
 			}
 		}
 	}
@@ -988,16 +988,6 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)
 	if (limit_range && check_core_list(lcores, count) != 0)
 		return -1;
 
-	/*
-	 * Now that we've got a list of cores no longer than RTE_MAX_LCORE,
-	 * and no lcore in that list is greater than RTE_MAX_LCORE, populate
-	 * the cores array.
-	 */
-	do {
-		count--;
-		cores[lcores[count]] = count;
-	} while (count != 0);
-
 	return 0;
 }
 
@@ -1931,13 +1921,13 @@ eal_parse_args(void)
 
 	/* parse the core list arguments */
 	if (args.coremask != NULL) {
-		int lcore_indexes[CPU_SETSIZE];
+		rte_cpuset_t cpuset;
 
-		if (rte_eal_parse_coremask(args.coremask, lcore_indexes, !remap_lcores) < 0) {
+		if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) {
 			EAL_LOG(ERR, "invalid coremask syntax");
 			return -1;
 		}
-		if (update_lcore_config(lcore_indexes, remap_lcores, lcore_id_base) < 0) {
+		if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
 			char *available = available_cores();
 
 			EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
lib/eal/common/eal_options.h +2 -0
index 4a8a0f1df7..f5e7905609 100644
@@ -20,5 +20,7 @@ int eal_save_args(int argc, char **argv);
 void eal_clean_saved_args(void);
 int handle_eal_info_request(const char *cmd, const char *params __rte_unused,
 		struct rte_tel_data *d);
+__rte_internal
+int rte_eal_parse_coremask(const char *coremask, rte_cpuset_t *cpuset, bool limit_range);
 
 #endif /* EAL_OPTIONS_H */
lib/eal/include/rte_eal.h +0 -22
index bc58254ece..619b8fbade 100644
@@ -491,28 +491,6 @@ rte_eal_mbuf_user_pool_ops(void);
 const char *
 rte_eal_get_runtime_dir(void);
 
-/**
- * Convert a string describing a mask of core ids into an array of core ids.
- *
- * On success, the passed array is filled with the orders of the core ids
- * present in the mask (-1 indicating that a core id is absent).
- * For example, passing a 0xa coremask results in cores[1] = 0, cores[3] = 1,
- * and the rest of the array is set to -1.
- *
- * @param coremask
- *   A string describing a mask of core ids.
- * @param cores
- *   An array where to store the core ids orders.
- *   This array must be at least CPU_SETSIZE large.
- * @param limit_range
- *   If set, return an error if any cores in the mask are >= RTE_MAX_LCORE.
- * @return
- *   0 on success, -1 if the string content was invalid.
- */
-__rte_internal
-int
-rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range);
-
 #ifdef __cplusplus
 }
 #endif
Signature · 1 line
2.48.1
#134 lore raw

PATCH v9 17/18 eal: allow lcore id remapping with core lists

In reply to Bruce Richardson

Allow the "-R" flag to be used with core lists so that we can specify lists with core ids >= RTE_MAX_LCORE in them, e.g. -l 140-148. In order to do so, we limit the use of the "@" symbol for per-core remapping when specifying a core list for automatic/global remapping, rather than dealing with the situation of some cores being manually remapped and others automatically.

---
 doc/guides/linux_gsg/eal_args.include.rst | 22 +++++++++++++++++
 doc/guides/rel_notes/release_25_11.rst    | 11 +++++++++
 lib/eal/common/eal_common_options.c       | 29 ++++++++++++++++++++---
 3 files changed, 59 insertions(+), 3 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +22 -0
index 0b17879d42..4a3c4d9b5f 100644
@@ -67,6 +67,28 @@ Lcore-related options
     At a given instance only one core option ``--lcores``, ``-l`` or ``-c`` can
     be used.
 
+*  ``-R, --remap-lcore-ids [<start lcore id>]``
+
+   Enable automatic remapping of lcore-ids to a contiguous set starting from 0,
+   or from a user-provided value.
+
+   When this flag is passed, the lcores specified by core mask or core list options
+   are taken as the physical cores on which the application will run,
+   and one thread will be started per core, with sequential lcore-ids.
+
+   For example: ``dpdk-test -l 20-24 -R``
+   will start 5 threads with lcore-ids 0 to 4 on physical cores 20 to 24.
+
+   Another example: ``dpdk-test -l 140-144 -R=10``
+   will start 5 threads with lcore-ids 10 to 14 on physical cores 140 to 144.
+
+.. note::
+
+    When using with the ``--lcores`` option, only simple core lists are allowed.
+    The ``@`` symbol to bind lcores to physical cpus,
+    and the use of ``()`` for core groupings,
+    are not allowed when ``-R`` or ``--remap-lcore-ids`` is also used.
+
 *   ``--main-lcore <core ID>``
 
     Core ID that is used as main.
doc/guides/rel_notes/release_25_11.rst +11 -0
index f73bab1227..4443ebbe92 100644
@@ -55,6 +55,17 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added automatic lcore-id remapping option.**
+
+  Added the EAL option ``--remap-lcore-ids`` or ``-R``
+  to enable automatic remapping of lcore-ids to a contiguous set starting from 0,
+  or from a user-provided value.
+  When this flag is passed, the lcores specified by core mask or core list options
+  are taken as the physical cores on which the application will run,
+  and one thread will be started per core, with sequential lcore-ids.
+  For example: ``dpdk-test -l 140-144 -R``
+  will start 5 threads with lcore-ids 0 to 4 on physical cores 140 to 144.
+
 * **Added speed 800G.**
 
   Added Ethernet link speed for 800 Gb/s as it is well standardized in IEEE,
lib/eal/common/eal_common_options.c +26 -3
index 86351535ee..c754c19511 100644
@@ -1937,9 +1937,32 @@ eal_parse_args(void)
 		}
 		core_parsed = 1;
 	} else if (args.lcores != NULL) {
-		if (eal_parse_lcores(args.lcores) < 0) {
-			EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
-			return -1;
+		if (!remap_lcores) {
+			if (eal_parse_lcores(args.lcores) < 0) {
+				EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
+				return -1;
+			}
+		} else {
+			rte_cpuset_t cpuset;
+
+			if (strchr(args.lcores, '@') != NULL || strchr(args.lcores, '(') != NULL) {
+				EAL_LOG(ERR, "cannot use '@' or core groupings '()' in lcore list when remapping lcores");
+				return -1;
+			}
+			if (rte_argparse_parse_type(args.lcores,
+					RTE_ARGPARSE_VALUE_TYPE_CORELIST, &cpuset) != 0) {
+				EAL_LOG(ERR, "Error parsing lcore list: '%s'", args.lcores);
+				return -1;
+			}
+
+			if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
+				char *available = available_cores();
+
+				EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
+						args.coremask, available);
+				free(available);
+				return -1;
+			}
 		}
 		core_parsed = 1;
 	}
Signature · 1 line
2.48.1
#135 lore raw

PATCH v9 18/18 eal: allow lcore remapping with autodetected core affinity

In reply to Bruce Richardson

When run without an coremask or core list parameters, EAL detects the working set of cores allowed for the current process and uses that as a core list for use. Currently, this does not work for cores which are numbered >= RTE_MAX_LCORE.

We can fix this by allowing the remap option to also be used with these auto-detected cores. In the process we simplify the code by taking advantage of that fact that we know up-front when processing parameters if any core parameter is passed, so we no longer need a flag and to auto-detect at the end. Instead, we take advantage of the fact that our core-arg processing routines now all work with cpusets, to have a simple tri-state option for remapping (if we don't have manual remapping done by --lcores-parameter):
* parse coremask to cpuset
* parse core list to cpuset
* query OS for current thread's cpuset
Once that is done, we have common code for processing, and optionally remapping, the resulting cpuset.

---
 lib/eal/common/eal_common_options.c | 110 +++++++++++-----------------
 1 file changed, 43 insertions(+), 67 deletions(-)
lib/eal/common/eal_common_options.c +43 -67
index c754c19511..b1830aa9d7 100644
@@ -292,8 +292,6 @@ struct device_option {
 static struct device_option_list devopt_list =
 TAILQ_HEAD_INITIALIZER(devopt_list);
 
-static int core_parsed;
-
 /* Returns rte_usage_hook_t */
 rte_usage_hook_t
 eal_get_application_usage_hook(void)
@@ -830,7 +828,7 @@ eal_parse_service_coremask(const char *coremask)
 	if (count == 0)
 		return -1;
 
-	if (core_parsed && taken_lcore_count != count) {
+	if (taken_lcore_count != count) {
 		EAL_LOG(WARNING,
 			"Not all service cores are in the coremask. "
 			"Please ensure -c or -l includes service cores");
@@ -1051,7 +1049,7 @@ eal_parse_service_corelist(const char *corelist)
 	if (count == 0)
 		return -1;
 
-	if (core_parsed && taken_lcore_count != count) {
+	if (taken_lcore_count != count) {
 		EAL_LOG(WARNING,
 			"Not all service cores were in the coremask. "
 			"Please ensure -c or -l includes service cores");
@@ -1919,32 +1917,31 @@ eal_parse_args(void)
 		}
 	}
 
-	/* parse the core list arguments */
-	if (args.coremask != NULL) {
-		rte_cpuset_t cpuset;
 
-		if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) {
-			EAL_LOG(ERR, "invalid coremask syntax");
-			return -1;
-		}
-		if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
-			char *available = available_cores();
-
-			EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
-					args.coremask, available);
-			free(available);
+	/* parse the core list arguments
+	 * First handle the special case where we have explicit core mapping/remapping
+	 */
+	if (args.lcores != NULL && !remap_lcores) {
+		if (eal_parse_lcores(args.lcores) < 0) {
+			EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
 			return -1;
 		}
-		core_parsed = 1;
-	} else if (args.lcores != NULL) {
-		if (!remap_lcores) {
-			if (eal_parse_lcores(args.lcores) < 0) {
-				EAL_LOG(ERR, "invalid lcore list: '%s'", args.lcores);
+	} else {
+		/* otherwise get a cpuset of the cores to be used and then handle that
+		 * taking mappings into account. Cpuset comes from either:
+		 * 1. coremask parameter
+		 * 2. core list parameter
+		 * 3. autodetecting current thread affinities
+		 */
+		rte_cpuset_t cpuset;
+		const char *cpuset_source;
+		if (args.coremask != NULL) {
+			if (rte_eal_parse_coremask(args.coremask, &cpuset, !remap_lcores) < 0) {
+				EAL_LOG(ERR, "invalid coremask syntax");
 				return -1;
 			}
-		} else {
-			rte_cpuset_t cpuset;
-
+			cpuset_source = "coremask";
+		} else if (args.lcores != NULL) {
 			if (strchr(args.lcores, '@') != NULL || strchr(args.lcores, '(') != NULL) {
 				EAL_LOG(ERR, "cannot use '@' or core groupings '()' in lcore list when remapping lcores");
 				return -1;
@@ -1954,18 +1951,29 @@ eal_parse_args(void)
 				EAL_LOG(ERR, "Error parsing lcore list: '%s'", args.lcores);
 				return -1;
 			}
-
-			if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
-				char *available = available_cores();
-
-				EAL_LOG(ERR, "invalid coremask '%s', please check specified cores are part of %s",
-						args.coremask, available);
-				free(available);
+			cpuset_source = "core list";
+		} else {
+			if (rte_thread_get_affinity_by_id(rte_thread_self(), &cpuset) != 0) {
+				EAL_LOG(ERR, "Error querying current process thread affinities");
 				return -1;
 			}
+			cpuset_source = "affinity auto-detection";
+		}
+		char *cpuset_str = eal_cpuset_to_str(&cpuset);
+		if (cpuset_str != NULL) {
+			EAL_LOG(DEBUG, "Cores selected by %s: %s", cpuset_source, cpuset_str);
+			free(cpuset_str);
+		}
+		if (update_lcore_config(&cpuset, remap_lcores, lcore_id_base) < 0) {
+			char *available = available_cores();
+
+			EAL_LOG(ERR, "invalid coremask or core-list parameter, please check specified cores are part of %s",
+					available);
+			free(available);
+			return -1;
 		}
-		core_parsed = 1;
 	}
+
 	/* service core options */
 	if (args.service_coremask != NULL) {
 		if (eal_parse_service_coremask(args.service_coremask) < 0) {
@@ -2208,27 +2216,6 @@ eal_parse_args(void)
 	return 0;
 }
 
-static void
-eal_auto_detect_cores(struct rte_config *cfg)
-{
-	unsigned int lcore_id;
-	unsigned int removed = 0;
-	rte_cpuset_t affinity_set;
-
-	if (rte_thread_get_affinity_by_id(rte_thread_self(), &affinity_set) != 0)
-		CPU_ZERO(&affinity_set);
-
-	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
-		if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
-		    !CPU_ISSET(lcore_id, &affinity_set)) {
-			cfg->lcore_role[lcore_id] = ROLE_OFF;
-			removed++;
-		}
-	}
-
-	cfg->lcore_count -= removed;
-}
-
 static void
 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 {
@@ -2276,20 +2263,9 @@ int
 eal_adjust_config(struct internal_config *internal_cfg)
 {
 	int i;
-	struct rte_config *cfg = rte_eal_get_configuration();
-	struct internal_config *internal_conf =
-		eal_get_internal_configuration();
-
-	if (!core_parsed)
-		eal_auto_detect_cores(cfg);
-
-	if (cfg->lcore_count == 0) {
-		EAL_LOG(ERR, "No detected lcore is enabled, please check the core list");
-		return -1;
-	}
 
-	if (internal_conf->process_type == RTE_PROC_AUTO)
-		internal_conf->process_type = eal_proc_type_detect();
+	if (internal_cfg->process_type == RTE_PROC_AUTO)
+		internal_cfg->process_type = eal_proc_type_detect();
 
 	compute_ctrl_threads_cpuset(internal_cfg);
 
Signature · 1 line
2.48.1
#136 lore raw

Re: [PATCH v9 00/18] Simplify running with high-numbered CPUs

In reply to Bruce Richardson
Quoted 36 lines · Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V9: rebase to latest main. CI complains cannot apply v8 patches.

Quoted 13 lines

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

I was planning to merge the first part of the series (before reaching the cpuset rework and addition of remap option).

I am facing two issues for which I prefer other's opinions.

- First, I see a change in how non-option arguments are handled with the switch to argparse.

$ ./build-mini/app/dpdk-test --no-huge -m 2048 -l 0,1 func_reentrancy_autotest
ARGPARSE: too many positional arguments func_reentrancy_autotest!

Passing the test name after -- does work, but it was working without -- before the patch, so we are introducing a regression here.

- Second, stopping at patch "eal: gather EAL args before processing", I see a crash in this same func_reentrancy_autotest unit test.

Here, I would fix the unit test itself, as it passes a NULL argv[0] which is invalid according to the C standard.
I fixed this unit test not so long ago (978ead0144c1 ("test/func_reentrancy: fix EAL init call")), but the fix is incomplete.
And if you wonder why the CI did not catch this, the next patch hides the issue for the unit test, as the run_once flag gets set earlier, which makes rte_eal_init fail before evaluating argv[0].

On the other hand, even if DPDK does not really care about argv[0] content (well, until eal_save_args is called and crashes), we are introducing a change in behavior for (arguably) non standard argv[0] == NULL, and some programs, which are not passing C library argv[] and instead building a argv[] array, may rely on this... ?

Signature · 1 line
David Marchand
#137 lore raw

Re: [PATCH v9 00/18] Simplify running with high-numbered CPUs

Quoted 79 lines · David Marchand
Quoted 36 lines · Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V9: rebase to latest main. CI complains cannot apply v8 patches.

Quoted 13 lines

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

I was planning to merge the first part of the series (before reaching the cpuset rework and addition of remap option).

I am facing two issues for which I prefer other's opinions.

- First, I see a change in how non-option arguments are handled with the switch to argparse.

$ ./build-mini/app/dpdk-test --no-huge -m 2048 -l 0,1 func_reentrancy_autotest
ARGPARSE: too many positional arguments func_reentrancy_autotest!

Passing the test name after -- does work, but it was working without -- before the patch, so we are introducing a regression here.

- Second, stopping at patch "eal: gather EAL args before processing", I see a crash in this same func_reentrancy_autotest unit test.

Here, I would fix the unit test itself, as it passes a NULL argv[0] which is invalid according to the C standard.
I fixed this unit test not so long ago (978ead0144c1 ("test/func_reentrancy: fix EAL init call")), but the fix is incomplete.
And if you wonder why the CI did not catch this, the next patch hides the issue for the unit test, as the run_once flag gets set earlier, which makes rte_eal_init fail before evaluating argv[0].

Quoted 6 lines

On the other hand, even if DPDK does not really care about argv[0] content (well, until eal_save_args is called and crashes), we are introducing a change in behavior for (arguably) non standard argv[0] == NULL, and some programs, which are not passing C library argv[] and instead building a argv[] array, may rely on this... ?

The second should be relatively easy to fix, I hope, so I think it should be fixed both in a new version of this set, and also in the unit test that has the bad behaviour

/Bruce

#138 lore raw

Re: [PATCH v9 00/18] Simplify running with high-numbered CPUs

In reply to David Marchand
Quoted 58 lines · David Marchand
Quoted 36 lines · Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V9: rebase to latest main. CI complains cannot apply v8 patches.

Quoted 13 lines

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

I was planning to merge the first part of the series (before reaching the cpuset rework and addition of remap option).

I am facing two issues for which I prefer other's opinions.

Quoted 8 lines

- First, I see a change in how non-option arguments are handled with the switch to argparse.

$ ./build-mini/app/dpdk-test --no-huge -m 2048 -l 0,1 func_reentrancy_autotest
ARGPARSE: too many positional arguments func_reentrancy_autotest!

Passing the test name after -- does work, but it was working without -- before the patch, so we are introducing a regression here.

Looking for input on how much we need to handle here.

The quick patch below adds support for ignoring trailing args in argparse, which means that the command above would work. However, gnu getopt also does argument reordering which means that this command works right now (on linux anyway):

	./build/app/dpdk-test -l 0,1 lcores_autotest --no-huge

since getopt moves the lcores_autotest to the end.

Is this behaviour what we need to emulate too, or is adding a flag to ignore trailing args sufficient? [I'd tend toward it being sufficient - mixing app args and EAL args together is not a great idea IMHO]

Quoted 6 lines

- Second, stopping at patch "eal: gather EAL args before processing", I see a crash in this same func_reentrancy_autotest unit test.

Here, I would fix the unit test itself, as it passes a NULL argv[0] which is invalid according to the C standard.

For this, I think the easiest (and most correct) fix is just to catch the null argv[0] condition and return error, rather than actually trying to continue arg parsing. I see right now that my patches only check for argc==0 and argv==NULL. I suggest just extending that to also check that final argv[0] == NULL condition.

/Bruce

lib/argparse/rte_argparse.c +16 -2
index e4851bd046..de57400e74 100644
@@ -695,8 +695,22 @@ parse_args(const struct rte_argparse *obj, bool *arg_parsed,
                        /* process positional parameters. */
                        position_index++;
                        if (position_index > position_count) {
-                               ARGPARSE_LOG(ERR, "too many positional arguments %s!", curr_argv);
-                               return -EINVAL;
+                               if (!obj->ignore_trailing_args) {
+                                       ARGPARSE_LOG(ERR, "too many positional arguments %s!",
+                                               curr_argv);
+                                       return -EINVAL;
+                               }
+                               /* check if this is a trailing non-flag argument i.e. no more
+                                * flag arguments are present.
+                                */
+                               for (int j = i + 1; j < argc; j++) {
+                                       if (argv[j][0] == '-') {
+                                               ARGPARSE_LOG(ERR, "unexpected non-flag argument \"%s\"",
+                                                       argv[j]);
+                                               return -EINVAL;
+                                       }
+                               }
+                               break;
                        }
                        arg = find_position_arg(obj, position_index);
                        ret = parse_arg_val(obj, arg->name_long, arg, curr_argv);
lib/argparse/rte_argparse.h +2 -0
index 991f084927..760d59fd8a 100644
@@ -158,6 +158,8 @@ struct rte_argparse {
        const char *epilog;
        /** Whether exit when error. */
        bool exit_on_error;
+       /** Don't error out if trailing non-flag arguments are present, ignore them. */
+       bool ignore_trailing_args;
        /** User callback for parsing arguments. */
        rte_arg_parser_t callback;
        /** Opaque which used to invoke callback. */
#139 lore raw

Re: [PATCH v9 00/18] Simplify running with high-numbered CPUs

07/10/2025 18:15, Bruce Richardson:

Quoted 75 lines · David Marchand
Quoted 58 lines
Quoted 36 lines · Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V9: rebase to latest main. CI complains cannot apply v8 patches.

Quoted 13 lines

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

I was planning to merge the first part of the series (before reaching the cpuset rework and addition of remap option).

I am facing two issues for which I prefer other's opinions.

Quoted 8 lines

- First, I see a change in how non-option arguments are handled with the switch to argparse.

$ ./build-mini/app/dpdk-test --no-huge -m 2048 -l 0,1 func_reentrancy_autotest
ARGPARSE: too many positional arguments func_reentrancy_autotest!

Passing the test name after -- does work, but it was working without -- before the patch, so we are introducing a regression here.

Looking for input on how much we need to handle here.

The quick patch below adds support for ignoring trailing args in argparse, which means that the command above would work. However, gnu getopt also does argument reordering which means that this command works right now (on linux anyway):

Quoted 7 lines
	./build/app/dpdk-test -l 0,1 lcores_autotest --no-huge

since getopt moves the lcores_autotest to the end.

Is this behaviour what we need to emulate too, or is adding a flag to ignore trailing args sufficient? [I'd tend toward it being sufficient - mixing app args and EAL args together is not a great idea IMHO]

I am in favor of being tolerant.
I agree mixing args is not a great idea,
but rejecting them is not really kind, and is a regression.

#140 lore raw

Re: [PATCH v9 00/18] Simplify running with high-numbered CPUs

Quoted 80 lines · Thomas Monjalon

07/10/2025 18:15, Bruce Richardson:

Quoted 79 lines · David Marchand
Quoted 58 lines
Quoted 36 lines · Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V9: rebase to latest main. CI complains cannot apply v8 patches.

Quoted 13 lines

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

I was planning to merge the first part of the series (before reaching the cpuset rework and addition of remap option).

I am facing two issues for which I prefer other's opinions.

Quoted 8 lines

- First, I see a change in how non-option arguments are handled with the switch to argparse.

$ ./build-mini/app/dpdk-test --no-huge -m 2048 -l 0,1 func_reentrancy_autotest
ARGPARSE: too many positional arguments func_reentrancy_autotest!

Passing the test name after -- does work, but it was working without -- before the patch, so we are introducing a regression here.

Looking for input on how much we need to handle here.

The quick patch below adds support for ignoring trailing args in argparse, which means that the command above would work. However, gnu getopt also does argument reordering which means that this command works right now (on linux anyway):

	./build/app/dpdk-test -l 0,1 lcores_autotest --no-huge

since getopt moves the lcores_autotest to the end.

Quoted 8 lines
Quoted 3 lines

Is this behaviour what we need to emulate too, or is adding a flag to ignore trailing args sufficient? [I'd tend toward it being sufficient - mixing app args and EAL args together is not a great idea IMHO]

I am in favor of being tolerant.
I agree mixing args is not a great idea,
but rejecting them is not really kind, and is a regression.

Disagree on it not being kind :-) but agree its a regression.

I'll work on a new version of the set based on your feedback.

/Bruce

#141 lore raw

v10 cover Simplify running with high-numbered CPUs

In reply to Bruce Richardson

The ultimate of this patchset is to make it easier to run on systems with large numbers of cores, by simplifying the process of using core numbers >RTE_MAX_LCORE. The new EAL arg ``-remap-lcore-ids``, also shortened to ``-R``, is added to DPDK to support this.

However, in order to add this new flag easily, the first dozen or more patches rework the argument handling in EAL to simplify things, using the argparse library for argument handling.

When processing cmdline arguments in DPDK, we always do so with very little context. So, for example, when processing the "-l" flag, we have no idea whether there will be later a --proc-type=secondary flag. We have all sorts of post-arg-processing checks in place to try and catch these scenarios.

To improve this situation, this patchset tries to simplify the handling of argument processing, by explicitly doing an initial pass to collate all arguments into a structure. Thereafter, the actual arg parsing is done in a fixed order, meaning that e.g. when processing the --main-lcore flag, we have already processed the service core flags. We also can far quicker and easier check for conflicting options, since they can all be checked for NULL/non-NULL in the arg structure immediately after the struct has been populated.

An additional benefit of this work is that the argument parsing for EAL is much more centralised into common options and the options list file. This single list with ifdefs makes it clear to the viewer what options are common across OS's, vs what are unix-only or linux-only.

Once the cleanup and rework is done, adding the new options for remapping cores becomes a lot simpler, since we can very easily check for scenarios like multi-process and handle those appropriately.

V10:
* add patch 2 to fix func_reentrancy test bug reported mid-way through the series.
* added patches 7 & 8 to resolve arg parsing compat issues:
- support reordering args to have non-flag parameters at the end so we can e.g. mix autotest names in with EAL args
- support having optional params with single-letter args without having to use "=" syntax, i.e. -l4 rather than -l=4
* fixed issues with the final patch when the autodetected range of cores was >RTE_MAX_LCORE

V9: rebase to latest main. CI complains cannot apply v8 patches.

V8:
* dropped the final two patches from the series, dropping the new -L option in favour of the -R modifier.
* reordered patch 11 to be with the other argparse patches (now patch 5)
* added patch 12, which uses macros to initialize the args structure from the arguments header file, avoiding potential issues when we add new args.
* simplified and consolidated lcore mask and core list parsing to always work off cpusets rather than arrays of uint8
* enhanced debug printouts to also work better with cpusets and handle core values in those sets >= RTE_MAX_LCORE
* for completeness, ensure the new -R option works for coremasks, and for cases where no explicit core-list or coremask is specified.

V7:
* expand the scope of the patchset beyond just cleanup to add in the extra 3 patches for -L and --lcoreid-base option.

V6:
* Rebase to apply cleanly on latest main

V5:
* Resubmit of V4, which didn't get sent correctly, or picked up correctly in patchwork.

V4:
* Updated patch 5 to auto-generate the arg struct definition from the same list of defines used to construct the argument list.

V3:
* Added 3 new initial patches, one for minor build-system addition, and two for functionality in argparse to allow the user-callback help function to be maintained as we move to argparse.
* Added doc updates in the first EAL patch adding the long options
* Fixed ASAN issues by adding a patch to properly clean up EAL init - both memory allocations and fixing the run-once flag
* Put ifdefs around the linux-only or unix-only options in EAL patch 2
* Updated args to handle numa-mem and numa-limit as equivalent socket-mem and socket-limit

Bruce Richardson (21):
build: add define for the OS environment name test/func_reentrancy: fix args to EAL init call
argparse: export function to print help text for object
argparse: allow user-override of help printing
argparse: add documentation on supported value types
argparse: add support for parsing core lists
argparse: allow optional flag reordering
argparse: support parameters to short options without "="
eal: add long options for each short option
eal: define the EAL parameters in argparse format
eal: gather EAL args before processing
eal: ensure proper cleanup on EAL init failure
eal: combine parameter validation checks
eal: simplify handling of conflicting cmdline options
eal: automatically init arg list options
eal: add internal fn for converting cpuset to string
eal: use common cpuset to string function
eal: introduce lcore remapping option for coremasks
eal: rework internal coremask parsing to use cpu sets
eal: allow lcore ID remapping with core lists
eal: allow lcore remapping with autodetected core affinity

 app/test/test_argparse.c                   |  695 ++++++++++
 app/test/test_func_reentrancy.c            |    5 +-
 config/meson.build                         |    1 +
 doc/guides/contributing/design.rst         |    2 +-
 doc/guides/linux_gsg/eal_args.include.rst  |   42 +-
 doc/guides/prog_guide/argparse_lib.rst     |  138 +-
 doc/guides/rel_notes/release_25_11.rst     |   18 +
 drivers/event/dlb2/dlb2_priv.h             |    2 +-
 drivers/event/dlb2/pf/base/dlb2_resource.c |   11 +-
 lib/argparse/rte_argparse.c                |  181 ++-
 lib/argparse/rte_argparse.h                |   29 +-
 lib/eal/common/eal_common_lcore.c          |   13 +-
 lib/eal/common/eal_common_memory.c         |    3 +-
 lib/eal/common/eal_common_options.c        | 1439 +++++++++++---------
 lib/eal/common/eal_common_thread.c         |   43 +-
 lib/eal/common/eal_option_list.h           |   98 ++
 lib/eal/common/eal_options.h               |  104 +-
 lib/eal/common/eal_private.h               |   21 +
 lib/eal/common/eal_thread.h                |   13 +-
 lib/eal/freebsd/eal.c                      |  245 +---
 lib/eal/include/rte_eal.h                  |   20 -
 lib/eal/linux/eal.c                        |  470 +------
 lib/eal/linux/eal_memory.c                 |    2 +-
 lib/eal/meson.build                        |    2 +-
 lib/eal/windows/eal.c                      |  156 +--
 lib/meson.build                            |    1 +
 26 files changed, 2148 insertions(+), 1606 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h

--
2.48.1

#142 lore raw

PATCH v10 1/21 build: add define for the OS environment name

Introduce a string define for the currently running OS, or execution environment.

Originally, with old make build system, CONFIG_RTE_EXEC_ENV used to hold this name string, but the variable seems to have been missed in the meson build system, until commit cadb255e25d6 ("eal: add OS defines for C conditional checks") which introduced the RTE_EXEC_ENV for a different purpose. Now we can fix the docs with the new name reference.

---
 config/meson.build                 | 1 +
 doc/guides/contributing/design.rst | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
config/meson.build +1 -0
index ca63ee10b1..b8c1f127a2 100644
@@ -20,6 +20,7 @@ foreach env, id:exec_envs
     dpdk_conf.set10('RTE_EXEC_ENV_IS_' + env.to_upper(), (exec_env == env))
 endforeach
 dpdk_conf.set('RTE_EXEC_ENV', exec_envs[exec_env])
+dpdk_conf.set_quoted('RTE_EXEC_ENV_NAME', exec_env)
 dpdk_conf.set('RTE_EXEC_ENV_' + exec_env.to_upper(), 1)
 
 # MS linker requires special treatment.
doc/guides/contributing/design.rst +1 -1
index b724177ba1..5517613424 100644
@@ -50,7 +50,7 @@ Per Execution Environment Sources
 
 The following macro options can be used:
 
-* ``RTE_EXEC_ENV`` is a string that contains the name of the executive environment.
+* ``RTE_EXEC_ENV_NAME`` is a string that contains the name of the executive environment.
 * ``RTE_EXEC_ENV_FREEBSD``, ``RTE_EXEC_ENV_LINUX`` or ``RTE_EXEC_ENV_WINDOWS`` are defined only if we are building for this execution environment.
 
 Mbuf features
Signature · 1 line
2.48.1
#143 lore raw

PATCH v10 2/21 test/func_reentrancy: fix args to EAL init call

In reply to Bruce Richardson

The unit test for EAL init was passing in a NULL argv[0] value which is invalid. Update to have a valid string for argv[0].

Fixes 104a92bd026f ("app: add reentrancy tests")
Fixes 978ead0144c1 ("test/func_reentrancy: fix EAL init call")
---
 app/test/test_func_reentrancy.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
app/test/test_func_reentrancy.c +3 -2
index f4c6cbc548..51e3069611 100644
@@ -66,10 +66,11 @@ static RTE_ATOMIC(uint32_t) synchro;
  * rte_eal_init only init once
  */
 static int
-test_eal_init_once(void *arg)
+test_eal_init_once(__rte_unused void *arg)
 {
+	char appname[] = __FILE__;
 	unsigned lcore_self =  rte_lcore_id();
-	char *argv[] = { arg, NULL };
+	char *argv[] = { appname, NULL };
 
 	WAIT_SYNCHRO_FOR_WORKERS();
 
Signature · 1 line
2.48.1
#144 lore raw

PATCH v10 3/21 argparse: export function to print help text for object

In reply to Bruce Richardson

Make the function to print out the help text for an argparse object a public function, which takes as a new parameter the file stream on which to print. This can be used in future to allow application to extend their own help information.

---
 lib/argparse/rte_argparse.c | 43 +++++++++++++++++++------------------
 lib/argparse/rte_argparse.h | 14 ++++++++++++
 2 files changed, 36 insertions(+), 21 deletions(-)
lib/argparse/rte_argparse.c +22 -21
index 331f05f01d..f0c2c33178 100644
@@ -716,23 +716,23 @@ calc_help_align(const struct rte_argparse *obj)
 }
 
 static void
-show_oneline_help(const struct rte_argparse_arg *arg, uint32_t width)
+show_oneline_help(FILE *stream, const struct rte_argparse_arg *arg, uint32_t width)
 {
 	uint32_t len = 0;
 	uint32_t i;
 
 	if (arg->name_short != NULL)
-		len = printf(" %s,", arg->name_short);
-	len += printf(" %s", arg->name_long);
+		len = fprintf(stream, " %s,", arg->name_short);
+	len += fprintf(stream, " %s", arg->name_long);
 
 	for (i = len; i < width; i++)
-		printf(" ");
+		fprintf(stream, " ");
 
-	printf("%s\n", arg->help);
+	fprintf(stream, "%s\n", arg->help);
 }
 
 static void
-show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
+show_args_pos_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	uint32_t position_count = calc_position_count(obj);
 	const struct rte_argparse_arg *arg;
@@ -741,19 +741,19 @@ show_args_pos_help(const struct rte_argparse *obj, uint32_t align)
 	if (position_count == 0)
 		return;
 
-	printf("\npositional arguments:\n");
+	fprintf(stream, "\npositional arguments:\n");
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_positional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
 static void
-show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
+show_args_opt_help(FILE *stream, const struct rte_argparse *obj, uint32_t align)
 {
 	static const struct rte_argparse_arg help = {
 		.name_long = "--help",
@@ -763,34 +763,35 @@ show_args_opt_help(const struct rte_argparse *obj, uint32_t align)
 	const struct rte_argparse_arg *arg;
 	uint32_t i;
 
-	printf("\noptions:\n");
-	show_oneline_help(&help, align);
+	fprintf(stream, "\noptions:\n");
+	show_oneline_help(stream, &help, align);
 	for (i = 0; /* NULL */; i++) {
 		arg = &obj->args[i];
 		if (arg->name_long == NULL)
 			break;
 		if (!is_arg_optional(arg))
 			continue;
-		show_oneline_help(arg, align);
+		show_oneline_help(stream, arg, align);
 	}
 }
 
-static void
-show_args_help(const struct rte_argparse *obj)
+RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_print_help, 25.11)
+void
+rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj)
 {
 	uint32_t align = calc_help_align(obj);
 
-	printf("usage: %s %s\n", obj->prog_name, obj->usage);
+	fprintf(stream, "usage: %s %s\n", obj->prog_name, obj->usage);
 	if (obj->descriptor != NULL)
-		printf("\ndescriptor: %s\n", obj->descriptor);
+		fprintf(stream, "\ndescriptor: %s\n", obj->descriptor);
 
-	show_args_pos_help(obj, align);
-	show_args_opt_help(obj, align);
+	show_args_pos_help(stream, obj, align);
+	show_args_opt_help(stream, obj, align);
 
 	if (obj->epilog != NULL)
-		printf("\n%s\n", obj->epilog);
+		fprintf(stream, "\n%s\n", obj->epilog);
 	else
-		printf("\n");
+		fprintf(stream, "\n");
 }
 
 RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_argparse_parse, 24.03)
@@ -820,7 +821,7 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		show_args_help(obj);
+		rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +14 -0
index 52bef34363..baf278f6b9 100644
@@ -189,6 +189,20 @@ struct rte_argparse {
 __rte_experimental
 int rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Output the help text information for the given argparse object.
+ *
+ * @param stream
+ *   Output file handle, e.g. stdout, stderr, on which to print the help text.
+ * @param obj
+ *   Parser object.
+ */
+__rte_experimental
+void rte_argparse_print_help(FILE *stream, const struct rte_argparse *obj);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
Signature · 1 line
2.48.1
#145 lore raw

PATCH v10 4/21 argparse: allow user-override of help printing

In reply to Bruce Richardson

When the arguments passed to argparse include -h/--help then usage information is automatically printed. Provide the capability for the user to supply their own help function for this.

---
 doc/guides/prog_guide/argparse_lib.rst | 16 ++++++++++++++++
 doc/guides/rel_notes/release_25_11.rst |  7 +++++++
 lib/argparse/rte_argparse.c            |  5 ++++-
 lib/argparse/rte_argparse.h            |  7 ++++++-
 4 files changed, 33 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +16 -0
index 9f11714890..b309260d20 100644
@@ -24,6 +24,8 @@ Features and Capabilities
   #. autosave: used for parsing known value types;
   #. callback: will invoke user callback to parse.
 
+- Supports automatic help and usage information.
+
 Usage Guide
 -----------
 
@@ -193,3 +195,17 @@ Then the user input could contain multiple ``--xyz`` arguments.
 
    The multiple times argument only support with optional argument
    and must be parsed by callback way.
+
+Help and Usage Information
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic generation of help and usage information.
+When the input arguments include ``-h`` or ``--help``,
+it will print the usage information to standard output.
+If the default help output is not what is wanted,
+the user can provide a custom help printing function by setting the ``print_help`` field in the ``rte_argparse`` object.
+(If this field is set to NULL, the default help printing function will be used.)
+
+If the custom help printing function wants to use the text produced by the default help function,
+it can call the function ``rte_argparse_print_help()`` to get the help text printed to an output stream,
+for example: stdout or stderr.
doc/guides/rel_notes/release_25_11.rst +7 -0
index c3b94e1896..f73bab1227 100644
@@ -76,6 +76,13 @@ New Features
   * Added multi-process per port.
   * Optimized code.
 
+* **Allow overriding the automatic usage/help generation in argparse library.**
+
+  The argparse library now supports overriding the automatic help text generation,
+  by allowing the user to provide a custom function to generate the output text.
+  The built-in help text function is available as a public function which can be reused by custom functions,
+  if so desired.
+
 
 Removed Items
 -------------
lib/argparse/rte_argparse.c +4 -1
index f0c2c33178..2b5da5f1db 100644
@@ -821,7 +821,10 @@ rte_argparse_parse(const struct rte_argparse *obj, int argc, char **argv)
 		goto error;
 
 	if (show_help) {
-		rte_argparse_print_help(stdout, obj);
+		if (obj->print_help != NULL)
+			obj->print_help(obj);
+		else
+			rte_argparse_print_help(stdout, obj);
 		exit(0);
 	}
 
lib/argparse/rte_argparse.h +6 -1
index baf278f6b9..63b49ba220 100644
@@ -160,8 +160,13 @@ struct rte_argparse {
 	rte_arg_parser_t callback;
 	/** Opaque which used to invoke callback. */
 	void *opaque;
+	/**
+	 * Function pointer for printing usage when -h is passed.
+	 * If this is NULL, default printing function will be used.
+	 */
+	void (*print_help)(const struct rte_argparse *obj);
 	/** Reserved field used for future extension. */
-	void *reserved[16];
+	void *reserved[15];
 	/** Arguments configuration. Must ended with ARGPARSE_ARG_END(). */
 	struct rte_argparse_arg args[];
 };
Signature · 1 line
2.48.1
#146 lore raw

PATCH v10 5/21 argparse: add documentation on supported value types

In reply to Bruce Richardson

The different value types supported by the argparse library are not discussed in the documentation, so add some reference material about them.

---
 doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++-
 1 file changed, 71 insertions(+), 2 deletions(-)
doc/guides/prog_guide/argparse_lib.rst +71 -2
index b309260d20..7868af5672 100644
@@ -160,6 +160,75 @@ both use this way, the parsing is as follows:
 - For argument ``ooo``, it is positional argument,
   the ``ooo_val`` will be set to user input's value.
 
+Supported Value Types
+~~~~~~~~~~~~~~~~~~~~~
+
+The argparse library supports automatic parsing of several data types when using
+the autosave method. The parsed values are automatically converted from string
+input to the appropriate data type and stored in the ``val_saver`` field.
+
+Integer Types
+^^^^^^^^^^^^^
+
+The library supports parsing various integer types:
+
+- ``RTE_ARGPARSE_VALUE_TYPE_INT`` - signed integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U8`` - unsigned 8-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U16`` - unsigned 16-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U32`` - unsigned 32-bit integer
+- ``RTE_ARGPARSE_VALUE_TYPE_U64`` - unsigned 64-bit integer
+
+.. code-block:: C
+
+   static int my_int;
+   static uint16_t my_port;
+   static uint32_t my_count;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--number", "-n", "Integer value", &my_int, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_INT },
+         { "--port", "-p", "Port number", &my_port, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_U16 },
+         { "--count", "-c", "Count value", &my_count, (void *)1000, RTE_ARGPARSE_VALUE_OPTIONAL, RTE_ARGPARSE_VALUE_TYPE_U32 },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+String Type
+^^^^^^^^^^^
+
+String arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_STR``.
+When using this type, the input value is saved to the provided pointer without any parsing or validation.
+
+.. code-block:: C
+
+   static const char *my_string;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--name", "-n", "Name string", &my_string, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_STR },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+Boolean Type
+^^^^^^^^^^^^
+
+Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept the following input formats:
+
+- ``true``, ``false`` (case-sensitive)
+- ``1``, ``0`` (numeric format)
+
+.. code-block:: C
+
+   static bool my_flag;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--enable", "-e", "Enable feature", &my_flag, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_BOOL },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
@@ -167,8 +236,8 @@ It could also choose to use callback to parse,
 just define a unique index for the argument
 and make the ``val_save`` field to be NULL also zero value-type.
 
-In the above example, the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp``
-both use this way.
+In the example at the top of this section,
+the arguments ``--ddd``/``--eee``/``--fff`` and ``ppp`` all use this way.
 
 Multiple times argument
 ~~~~~~~~~~~~~~~~~~~~~~~
Signature · 1 line
2.48.1
#147 lore raw

PATCH v10 6/21 argparse: add support for parsing core lists

In reply to Bruce Richardson

Core lists are widely used in DPDK, so add support for parsing them.

---
 app/test/test_argparse.c               | 188 +++++++++++++++++++++++++
 doc/guides/prog_guide/argparse_lib.rst |  32 +++++
 lib/argparse/rte_argparse.c            |  63 +++++++++
 lib/argparse/rte_argparse.h            |   2 +
 4 files changed, 285 insertions(+)
app/test/test_argparse.c +188 -0
index 0a229752fa..c829ea75e4 100644
@@ -6,6 +6,7 @@
 #include <string.h>
 
 #include <rte_argparse.h>
+#include <rte_os.h>
 
 #include "test.h"
 
@@ -500,6 +501,40 @@ test_argparse_opt_autosave_parse_int_of_optional_val(void)
 	return 0;
 }
 
+static int
+test_argparse_opt_parse_corelist_of_required_val(void)
+{
+	struct rte_argparse *obj;
+	rte_cpuset_t val_cpuset;
+	char *argv[3];
+	int ret;
+
+	/* test with long option and single core - this is known to work */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--corelist";
+	obj->args[0].name_short = "-c";
+	obj->args[0].val_saver = (void *)&val_cpuset;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_CORELIST;
+	obj->args[1].name_long = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("--corelist");
+	argv[2] = test_strdup("1,3-5");
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse(obj, 3, argv);
+	TEST_ASSERT(ret == 3, "Argparse parse expect success!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(3, &val_cpuset), "Core 3 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(4, &val_cpuset), "Core 4 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in corelist!");
+
+	return 0;
+}
+
 static int
 opt_callback_parse_int_of_no_val(uint32_t index, const char *value, void *opaque)
 {
@@ -782,6 +817,152 @@ test_argparse_pos_callback_parse_int(void)
 	return 0;
 }
 
+static int
+test_argparse_parse_type_corelist(void)
+{
+	char *corelist_valid_single = test_strdup("5");
+	char *corelist_valid_multiple = test_strdup("0,1,5");
+	char *corelist_valid_range = test_strdup("1-5");
+	char *corelist_valid_mixed = test_strdup("0,1,5-10,12-16,18,20");
+	char *corelist_valid_reverse_range = test_strdup("10-5");
+	char *corelist_valid_initial_spaces = test_strdup("   1,2,5-7");
+	char *corelist_valid_empty = test_strdup("");
+	char *corelist_invalid_spaces = test_strdup(" 1 , 2 , 5-7 ");
+	char *corelist_invalid_letters = test_strdup("1,a,3");
+	char *corelist_invalid_range_incomplete = test_strdup("1-");
+	char *corelist_invalid_range_double_dash = test_strdup("1--5");
+	char *corelist_invalid_special_chars = test_strdup("1,2@3");
+	char *corelist_invalid_comma_only = test_strdup(",");
+	char *corelist_invalid_out_of_range = test_strdup("70000");
+	rte_cpuset_t val_cpuset;
+	int ret;
+
+	/* test valid single core */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_single,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (single core) failed!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(1, &val_cpuset), "Core 1 should not be set in corelist!");
+
+	/* test valid multiple cores */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_multiple,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (multiple cores) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in corelist!");
+	TEST_ASSERT(CPU_ISSET(5, &val_cpuset), "Core 5 should be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in corelist!");
+	TEST_ASSERT(!CPU_ISSET(3, &val_cpuset), "Core 3 should not be set in corelist!");
+
+	/* test valid range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (range) failed!");
+	for (int i = 1; i <= 5; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 1-5!", i);
+	TEST_ASSERT(!CPU_ISSET(0, &val_cpuset), "Core 0 should not be set in range 1-5!");
+	TEST_ASSERT(!CPU_ISSET(6, &val_cpuset), "Core 6 should not be set in range 1-5!");
+
+	/* test valid mixed corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_mixed,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (mixed) failed!");
+	TEST_ASSERT(CPU_ISSET(0, &val_cpuset), "Core 0 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in mixed corelist!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 5-10!", i);
+	for (int i = 12; i <= 16; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset), "Core %d should be set in range 12-16!", i);
+
+	TEST_ASSERT(CPU_ISSET(18, &val_cpuset), "Core 18 should be set in mixed corelist!");
+	TEST_ASSERT(CPU_ISSET(20, &val_cpuset), "Core 20 should be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(2, &val_cpuset), "Core 2 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(17, &val_cpuset), "Core 17 should not be set in mixed corelist!");
+	TEST_ASSERT(!CPU_ISSET(19, &val_cpuset), "Core 19 should not be set in mixed corelist!");
+
+	/* test valid reverse range (10-5 should be interpreted as 5-10) */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_reverse_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (reverse range) failed!");
+	for (int i = 5; i <= 10; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in reverse range 10-5!", i);
+	TEST_ASSERT(!CPU_ISSET(4, &val_cpuset), "Core 4 should not be set in reverse range 10-5!");
+	TEST_ASSERT(!CPU_ISSET(11, &val_cpuset), "Core 11 should not be set in reverse range 10-5!");
+
+	/* test valid corelist with initial spaces only */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_initial_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (with initial spaces) failed!");
+	TEST_ASSERT(CPU_ISSET(1, &val_cpuset), "Core 1 should be set in initial spaced corelist!");
+	TEST_ASSERT(CPU_ISSET(2, &val_cpuset), "Core 2 should be set in initial spaced corelist!");
+	for (int i = 5; i <= 7; i++)
+		TEST_ASSERT(CPU_ISSET(i, &val_cpuset),
+				"Core %d should be set in initial spaced range 5-7!", i);
+
+	/* test valid empty corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_valid_empty,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret == 0, "Argparse parse type for corelist (empty) failed!");
+	/* Verify that no cores are set in empty corelist */
+	for (int i = 0; i < CPU_SETSIZE; i++)
+		TEST_ASSERT(!CPU_ISSET(i, &val_cpuset),
+				"Core %d should not be set in empty corelist!", i);
+
+	/* test invalid corelist with spaces */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_spaces,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with spaces) should have failed!");
+
+	/* test invalid corelist with letters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_letters,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (with letters) should have failed!");
+
+	/* test invalid corelist with incomplete range */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_incomplete,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (incomplete range) should have failed!");
+
+	/* test invalid corelist with double dash */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_range_double_dash,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (double dash) should have failed!");
+
+	/* test invalid corelist with special characters */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_special_chars,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (special chars) should have failed!");
+
+	/* test invalid comma-only corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_comma_only,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (comma only) should have failed!");
+
+	/* test invalid out-of-range corelist */
+	CPU_ZERO(&val_cpuset);
+	ret = rte_argparse_parse_type(corelist_invalid_out_of_range,
+			RTE_ARGPARSE_VALUE_TYPE_CORELIST, &val_cpuset);
+	TEST_ASSERT(ret != 0, "Argparse parse type for corelist (out of range) should have failed!");
+
+	return 0;
+}
+
 static int
 test_argparse_parse_type(void)
 {
@@ -880,6 +1061,12 @@ test_argparse_parse_type(void)
 	ret = rte_argparse_parse_type(bool_numeric_invalid, RTE_ARGPARSE_VALUE_TYPE_BOOL,
 			&val_bool);
 	TEST_ASSERT(ret != 0, "Argparse parse type for bool (numeric invalid) passed unexpectedly!");
+
+	/* test for corelist parsing */
+	ret = test_argparse_parse_type_corelist();
+	if (ret != 0)
+		return ret;
+
 	return 0;
 }
 
@@ -900,6 +1087,7 @@ static struct unit_test_suite argparse_test_suite = {
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_autosave_parse_int_of_optional_val),
+		TEST_CASE(test_argparse_opt_parse_corelist_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_no_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_required_val),
 		TEST_CASE(test_argparse_opt_callback_parse_int_of_optional_val),
doc/guides/prog_guide/argparse_lib.rst +32 -0
index 7868af5672..7882d910ab 100644
@@ -229,6 +229,38 @@ Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept t
       },
    };
 
+Corelist Type
+^^^^^^^^^^^^^
+
+The argparse library supports automatic parsing of CPU core lists using the
+``RTE_ARGPARSE_VALUE_TYPE_CORELIST`` value type. This feature allows users to
+specify CPU cores in a flexible format similar to other DPDK applications.
+
+.. code-block:: C
+
+   #include <rte_os.h>  /* for CPU set operations */
+
+   static rte_cpuset_t cores;
+
+   static struct rte_argparse obj = {
+      .args = {
+         { "--cores", "-c", "CPU cores to use", &cores, NULL, RTE_ARGPARSE_VALUE_REQUIRED, RTE_ARGPARSE_VALUE_TYPE_CORELIST },
+         ARGPARSE_ARG_END(),
+      },
+   };
+
+The corelist parsing supports the following input formats:
+
+- **Single core**: ``--cores 5`` (sets core 5)
+- **Multiple cores**: ``--cores 1,2,5`` (sets cores 1, 2, and 5)
+- **Core ranges**: ``--cores 1-5`` (sets cores 1, 2, 3, 4, and 5)
+- **Mixed format**: ``--cores 0,2-4,7`` (sets cores 0, 2, 3, 4, and 7)
+- **Reverse ranges**: ``--cores 5-1`` (equivalent to 1-5, sets cores 1, 2, 3, 4, and 5)
+- **Empty corelist**: ``--cores ""`` (sets no cores)
+
+The parsed result is stored in an ``rte_cpuset_t`` structure that can be used
+with standard CPU set operations:
+
 Parsing by callback way
 ~~~~~~~~~~~~~~~~~~~~~~~
 
lib/argparse/rte_argparse.c +63 -0

90 lines not on this page · raw message

lib/argparse/rte_argparse.h +2 -0
index 63b49ba220..991f084927 100644
@@ -69,6 +69,8 @@ enum rte_argparse_value_type {
 	RTE_ARGPARSE_VALUE_TYPE_STR,
 	/** The argument's value is boolean flag type. */
 	RTE_ARGPARSE_VALUE_TYPE_BOOL,
+	/** The argument's value is a corelist */
+	RTE_ARGPARSE_VALUE_TYPE_CORELIST,
 };
 
 /** Additional flags which may be specified for each argument */
Signature · 1 line
2.48.1
#148 lore raw

PATCH v10 7/21 argparse: allow optional flag reordering

In reply to Bruce Richardson

Allow argparse to behave like getopt in ignoring non-flag arguments and moving them to the end of the list. This will allow use in DPDK for EAL args where, for example:

  ./dpdk-test -l 1,2 lcores_autotest --no-huge -- argparse_autotest

will return from getopt processing in rte_eal_init as:

  ./dpdk-test -l 1,2 --no-huge -- lcores_autotest argparse_autotest

with EAL init function then replacing the "--" with argv[0] before returning to the app with the return value of 5, for the 5 args (including the "--") processed.

Since this is a significant behavioural change for argparse, which, unlike getopt, has the idea of positional arguments, we place this behaviour behind a new flag for argparse. If this new "ignore_non_flag_args" option is set, then positional arguments are disallowed and getopt behaviour is used for non-flag args.

---
 app/test/test_argparse.c               | 376 +++++++++++++++++++++++++
 doc/guides/prog_guide/argparse_lib.rst |  17 ++
 lib/argparse/rte_argparse.c            |  62 +++-
 lib/argparse/rte_argparse.h            |   6 +
 4 files changed, 453 insertions(+), 8 deletions(-)
app/test/test_argparse.c +376 -0
index c829ea75e4..2f9b644493 100644
@@ -1070,6 +1070,371 @@ test_argparse_parse_type(void)
 	return 0;
 }
 
+static int
+test_argparse_ignore_non_flag_args_disabled(void)
+{
+	struct rte_argparse *obj;
+	char *argv[6];
+	int ret;
+
+	/* Test that without ignore_non_flag_args, non-flag args cause an error */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = false;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("nonflagvalue");
+	argv[3] = test_strdup("-x");
+	ret = rte_argparse_parse(obj, 4, argv);
+	TEST_ASSERT(ret == -EINVAL, "Argparse should fail with non-flag arg when flag is disabled!");
+
+	/* Test with non-flag args mixed with flags */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = false;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("nonflagvalue1");
+	argv[2] = test_strdup("-a");
+	argv[3] = test_strdup("-x");
+	argv[4] = test_strdup("nonflagvalue2");
+	ret = rte_argparse_parse(obj, 5, argv);
+	TEST_ASSERT(ret == -EINVAL, "Argparse should fail with non-flag args when flag is disabled!");
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_basic(void)
+{
+	struct rte_argparse *obj;
+	char *argv[8];
+	int ret;
+
+	/* Test basic reordering: ['app', '-a', 'nonflagvalue', '-x']
+	 * Should process -a and -x, return 2 processed args, move nonflagvalue to end
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("nonflagvalue");
+	argv[3] = test_strdup("-x");
+	ret = rte_argparse_parse(obj, 4, argv);
+	TEST_ASSERT(ret == 3, "Argparse should return 3 (processed all but 1 non-flag), got %d!",
+			ret);
+	TEST_ASSERT(strcmp(argv[3], "nonflagvalue") == 0,
+		"Non-flag arg should be moved to end, but argv[3]='%s'!", argv[3]);
+
+	/* Test with multiple non-flag args:
+	 * ['app', '-a', 'nonflag1', '-x', 'nonflag2']
+	 * Should process -a and -x, return 3, reorder to [..., 'nonflag1', 'nonflag2']
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("nonflag1");
+	argv[3] = test_strdup("-x");
+	argv[4] = test_strdup("nonflag2");
+	ret = rte_argparse_parse(obj, 5, argv);
+	TEST_ASSERT(ret == 3, "Argparse should return 3 (processed all but 2 non-flags), got %d!",
+			ret);
+	TEST_ASSERT(strcmp(argv[3], "nonflag1") == 0,
+		"First non-flag arg should be at position 3, but argv[3]='%s'!", argv[3]);
+	TEST_ASSERT(strcmp(argv[4], "nonflag2") == 0,
+		"Second non-flag arg should be at position 4, but argv[4]='%s'!", argv[4]);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_with_values(void)
+{
+	struct rte_argparse *obj;
+	int val_a = 0, val_x = 0;
+	char *argv[10];
+	int ret;
+
+	/* Test with flags that take values:
+	 * ['app', '-a', 'avalue', 'nonflag1', '-x', 'xvalue', 'nonflag2']
+	 * Should process -a avalue and -x xvalue, move non-flags to end
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = (void *)&val_a;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].val_saver = (void *)&val_x;
+	obj->args[1].val_set = NULL;
+	obj->args[1].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[1].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("100");
+	argv[3] = test_strdup("nonflag1");
+	argv[4] = test_strdup("-x");
+	argv[5] = test_strdup("200");
+	argv[6] = test_strdup("nonflag2");
+	ret = rte_argparse_parse(obj, 7, argv);
+	TEST_ASSERT(ret == 5, "Argparse should return 5 (app + 4 flag-related + 0 non-flags), got %d!",
+			ret);
+	TEST_ASSERT(val_a == 100, "Value for -a should be parsed correctly, got %d!", val_a);
+	TEST_ASSERT(val_x == 200, "Value for -x should be parsed correctly, got %d!", val_x);
+	TEST_ASSERT(strcmp(argv[5], "nonflag1") == 0,
+		"First non-flag arg should be at position 5, but argv[5]='%s'!", argv[5]);
+	TEST_ASSERT(strcmp(argv[6], "nonflag2") == 0,
+		"Second non-flag arg should be at position 6, but argv[6]='%s'!", argv[6]);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_complex_order(void)
+{
+	struct rte_argparse *obj;
+	int val_a = 0;
+	char *argv[10];
+	int ret;
+
+	/* Test complex reordering matching example from requirements:
+	 * ['app', '-a', 'avalue', 'nonflag1', '-x', 'nonflag2']
+	 * Should become: ['app', '-a', 'avalue', '-x', 'nonflag1', 'nonflag2']
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = (void *)&val_a;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("50");
+	argv[3] = test_strdup("nonflag1");
+	argv[4] = test_strdup("-x");
+	argv[5] = test_strdup("nonflag2");
+	ret = rte_argparse_parse(obj, 6, argv);
+	TEST_ASSERT(ret == 4, "Argparse should return 4 (app + 3 flag-related), got %d!", ret);
+	TEST_ASSERT(val_a == 50, "Value for -a should be parsed correctly, got %d!", val_a);
+	/* Verify reordering */
+	TEST_ASSERT(strcmp(argv[4], "nonflag1") == 0,
+		"First non-flag should be at position 4, but argv[4]='%s'!", argv[4]);
+	TEST_ASSERT(strcmp(argv[5], "nonflag2") == 0,
+		"Second non-flag should be at position 5, but argv[5]='%s'!", argv[5]);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_only_non_flags(void)
+{
+	struct rte_argparse *obj;
+	char *argv[5];
+	int ret;
+
+	/* Edge case: only non-flag args
+	 * ['app', 'nonflag1', 'nonflag2', 'nonflag3']
+	 * Should return 1 (only app name processed), argv unchanged
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("nonflag1");
+	argv[2] = test_strdup("nonflag2");
+	argv[3] = test_strdup("nonflag3");
+	ret = rte_argparse_parse(obj, 4, argv);
+	TEST_ASSERT(ret == 1, "Argparse should return 1 (only app name processed), got %d!", ret);
+	TEST_ASSERT(strcmp(argv[1], "nonflag1") == 0,
+		"First non-flag should remain at position 1, but argv[1]='%s'!", argv[1]);
+	TEST_ASSERT(strcmp(argv[2], "nonflag2") == 0,
+		"Second non-flag should remain at position 2, but argv[2]='%s'!", argv[2]);
+	TEST_ASSERT(strcmp(argv[3], "nonflag3") == 0,
+		"Third non-flag should remain at position 3, but argv[3]='%s'!", argv[3]);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_no_non_flags(void)
+{
+	struct rte_argparse *obj;
+	char *argv[4];
+	int ret;
+
+	/* Edge case: no non-flag args, only flags
+	 * ['app', '-a', '-x']
+	 * Should process all args normally
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("-x");
+	ret = rte_argparse_parse(obj, 3, argv);
+	TEST_ASSERT(ret == 3, "Argparse should return 3 (all args processed), got %d!", ret);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_with_double_dash(void)
+{
+	struct rte_argparse *obj;
+	char *argv[8];
+	int ret;
+
+	/* Test with -- separator:
+	 * ['app', '-a', 'nonflag1', '--', 'arg1', 'arg2']
+	 * Should process -a, stop at --, and move nonflag1 after --
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("nonflag1");
+	argv[3] = test_strdup("--");
+	argv[4] = test_strdup("arg1");
+	argv[5] = test_strdup("arg2");
+	ret = rte_argparse_parse(obj, 6, argv);
+	/* Should return position of first flag after -- */
+	TEST_ASSERT(ret == 3, "Argparse should return 3 (app + -a, stopped at --), got %d!", ret);
+	TEST_ASSERT(strcmp(argv[2], "--") == 0,
+		"-- should be moved to position 2, but argv[2]='%s'!", argv[2]);
+	TEST_ASSERT(strcmp(argv[3], "nonflag1") == 0,
+		"Non-flag should be moved after --, but argv[3]='%s'!", argv[3]);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_leading_non_flags(void)
+{
+	struct rte_argparse *obj;
+	char *argv[7];
+	int ret;
+
+	/* Test with leading non-flag args:
+	 * ['app', 'nonflag1', 'nonflag2', '-a', '-x']
+	 * Should process -a and -x, move non-flags to end
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("nonflag1");
+	argv[2] = test_strdup("nonflag2");
+	argv[3] = test_strdup("-a");
+	argv[4] = test_strdup("-x");
+	ret = rte_argparse_parse(obj, 5, argv);
+	TEST_ASSERT(ret == 3, "Argparse should return 3 (app + 2 flags), got %d!", ret);
+	TEST_ASSERT(strcmp(argv[3], "nonflag1") == 0,
+		"First non-flag should be at position 3, but argv[3]='%s'!", argv[3]);
+	TEST_ASSERT(strcmp(argv[4], "nonflag2") == 0,
+		"Second non-flag should be at position 4, but argv[4]='%s'!", argv[4]);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_trailing_non_flags(void)
+{
+	struct rte_argparse *obj;
+	char *argv[7];
+	int ret;
+
+	/* Test with trailing non-flag args:
+	 * ['app', '-a', '-x', 'nonflag1', 'nonflag2']
+	 * Should process -a and -x, non-flags already at end
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-a");
+	argv[2] = test_strdup("-x");
+	argv[3] = test_strdup("nonflag1");
+	argv[4] = test_strdup("nonflag2");
+	ret = rte_argparse_parse(obj, 5, argv);
+	TEST_ASSERT(ret == 3, "Argparse should return 3 (app + 2 flags), got %d!", ret);
+	TEST_ASSERT(strcmp(argv[3], "nonflag1") == 0,
+		"First non-flag should remain at position 3, but argv[3]='%s'!", argv[3]);
+	TEST_ASSERT(strcmp(argv[4], "nonflag2") == 0,
+		"Second non-flag should remain at position 4, but argv[4]='%s'!", argv[4]);
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_with_positional(void)
+{
+	struct rte_argparse *obj;
+	char *argv[5];
+	int ret;
+
+	/* Test that ignore_non_flag_args cannot be used with positional args
+	 * This should fail during validation
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].name_long = "positional";
+	obj->args[0].name_short = NULL;
+	obj->args[0].val_saver = (void *)1;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("100");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == -EINVAL,
+		"Argparse should fail when ignore_non_flag_args is used with positional args!");
+
+	return 0;
+}
+
+static int
+test_argparse_ignore_non_flag_args_short_and_long(void)
+{
+	struct rte_argparse *obj;
+	char *argv[8];
+	int ret;
+
+	/* Test with both short and long options:
+	 * ['app', '--abc', 'nonflag1', '-x', 'nonflag2']
+	 */
+	obj = test_argparse_init_obj();
+	obj->ignore_non_flag_args = true;
+	obj->args[0].val_saver = NULL;
+	obj->args[1].val_saver = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("--abc");
+	argv[2] = test_strdup("nonflag1");
+	argv[3] = test_strdup("-x");
+	argv[4] = test_strdup("nonflag2");
+	ret = rte_argparse_parse(obj, 5, argv);
+	TEST_ASSERT(ret == 3, "Argparse should return 3 (app + 2 flags), got %d!", ret);
+	TEST_ASSERT(strcmp(argv[3], "nonflag1") == 0,
+		"First non-flag should be at position 3, but argv[3]='%s'!", argv[3]);
+	TEST_ASSERT(strcmp(argv[4], "nonflag2") == 0,
+		"Second non-flag should be at position 4, but argv[4]='%s'!", argv[4]);
+
+	return 0;
+}
+
 static struct unit_test_suite argparse_test_suite = {
 	.suite_name = "Argparse Unit Test Suite",
 	.setup = test_argparse_setup,
@@ -1094,6 +1459,17 @@ static struct unit_test_suite argparse_test_suite = {
 		TEST_CASE(test_argparse_pos_autosave_parse_int),
 		TEST_CASE(test_argparse_pos_callback_parse_int),
 		TEST_CASE(test_argparse_parse_type),
+		TEST_CASE(test_argparse_ignore_non_flag_args_disabled),
+		TEST_CASE(test_argparse_ignore_non_flag_args_basic),
+		TEST_CASE(test_argparse_ignore_non_flag_args_with_values),
+		TEST_CASE(test_argparse_ignore_non_flag_args_complex_order),
+		TEST_CASE(test_argparse_ignore_non_flag_args_only_non_flags),
+		TEST_CASE(test_argparse_ignore_non_flag_args_no_non_flags),
+		TEST_CASE(test_argparse_ignore_non_flag_args_with_double_dash),
+		TEST_CASE(test_argparse_ignore_non_flag_args_leading_non_flags),
+		TEST_CASE(test_argparse_ignore_non_flag_args_trailing_non_flags),
+		TEST_CASE(test_argparse_ignore_non_flag_args_with_positional),
+		TEST_CASE(test_argparse_ignore_non_flag_args_short_and_long),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
doc/guides/prog_guide/argparse_lib.rst +17 -0
index 7882d910ab..eff8f94a2d 100644
@@ -15,6 +15,8 @@ Features and Capabilities
 
 - Support parsing positional argument (which must take with required-value).
 
+- Support getopt-style argument reordering for non-flag arguments as an alternative to positional arguments.
+
 - Support automatic generate usage information.
 
 - Support issue errors when provide with invalid arguments.
@@ -160,6 +162,21 @@ both use this way, the parsing is as follows:
 - For argument ``ooo``, it is positional argument,
   the ``ooo_val`` will be set to user input's value.
 
+Support of non-flag/positional arguments
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+For arguments which are not flags (i.e. don't start with a hyphen '-'),
+there are two ways in which they can be handled by the library:
+
+#. Positional arguments: these are defined in the ``args`` array with a NULL ``short_name`` field,
+   and long_name field that does not start with a hyphen '-'.
+   They are parsed as required-value arguments.
+
+#. As ignored, or unhandled arguments: if the ``ignore_non_flag_args`` field in the ``rte_argparse`` object is set to true,
+   then any non-flag arguments will be ignored by the parser and moved to the end of the argument list.
+   In this mode, no positional arguments are allowed.
+   The return value from ``rte_argparse_parse()`` will indicate the position of the first ignored non-flag argument.
+
 Supported Value Types
 ~~~~~~~~~~~~~~~~~~~~~
 
lib/argparse/rte_argparse.c +54 -8

133 lines not on this page · raw message

lib/argparse/rte_argparse.h +6 -0
index 991f084927..ecf04396e9 100644
@@ -158,6 +158,12 @@ struct rte_argparse {
 	const char *epilog;
 	/** Whether exit when error. */
 	bool exit_on_error;
+	/** behave like getopt and move non-flag args to the end, ignoring them otherwise.
+	 * If this flag is specified, no positional args are allowed.
+	 */
+	bool ignore_non_flag_args;
+	/* reserved for future flags/other use */
+	bool reserved_flags[6];
 	/** User callback for parsing arguments. */
 	rte_arg_parser_t callback;
 	/** Opaque which used to invoke callback. */
Signature · 1 line
2.48.1
#149 lore raw

PATCH v10 8/21 argparse: support parameters to short options without "="

In reply to Bruce Richardson

When passing an optional parameter to a argparse argument, the only way to do so has been to pass the argument using "=arg" on the end of the option, for example "--foo=bar". However, for short options, i.e. those of the form "-x", this requirement is unusual as getopt also supports taking additional characters after the option as the parameter, e.g. "-xarg".

Add support for this form of parameter for short options to argparse.

---
 app/test/test_argparse.c    | 131 ++++++++++++++++++++++++++++++++++++
 lib/argparse/rte_argparse.c |  10 +--
 2 files changed, 137 insertions(+), 4 deletions(-)
app/test/test_argparse.c +131 -0
index 2f9b644493..32dfbf95e1 100644
@@ -1435,6 +1435,136 @@ test_argparse_ignore_non_flag_args_short_and_long(void)
 	return 0;
 }
 
+static int
+test_argparse_short_opt_value_without_equal(void)
+{
+	struct rte_argparse *obj;
+	int val_saver = 0;
+	char *argv[3];
+	int ret;
+
+	/* Test short option with required value using -a3 syntax (no '=') */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--test-long";
+	obj->args[0].name_short = "-t";
+	obj->args[0].val_saver = (void *)&val_saver;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].name_long = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-t42");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == 2, "Argparse parse with -t42 expect success, got %d!", ret);
+	TEST_ASSERT(val_saver == 42, "Argparse parse -t42 should set value to 42, got %d!",
+			val_saver);
+
+	/* Test short option with optional value using -t100 syntax (no '=') */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--test-long";
+	obj->args[0].name_short = "-t";
+	obj->args[0].val_saver = (void *)&val_saver;
+	obj->args[0].val_set = (void *)99;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_OPTIONAL;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].name_long = NULL;
+	val_saver = 0;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-t123");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == 2, "Argparse parse with -t123 expect success, got %d!", ret);
+	TEST_ASSERT(val_saver == 123, "Argparse parse -t123 should set value to 123, got %d!",
+			val_saver);
+
+	/* Test that -t alone with optional value uses default */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--test-long";
+	obj->args[0].name_short = "-t";
+	obj->args[0].val_saver = (void *)&val_saver;
+	obj->args[0].val_set = (void *)99;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_OPTIONAL;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].name_long = NULL;
+	val_saver = 0;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-t");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == 2, "Argparse parse with -t expect success, got %d!", ret);
+	TEST_ASSERT(val_saver == 99, "Argparse parse -t should use default 99, got %d!",
+			val_saver);
+
+	/* Test short option with '=' still works */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--test-long";
+	obj->args[0].name_short = "-t";
+	obj->args[0].val_saver = (void *)&val_saver;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].name_long = NULL;
+	val_saver = 0;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-t=55");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == 2, "Argparse parse with -t=55 expect success, got %d!", ret);
+	TEST_ASSERT(val_saver == 55, "Argparse parse -t=55 should set value to 55, got %d!",
+			val_saver);
+
+	/* Test that long option with value works with '=' */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--test-long";
+	obj->args[0].name_short = "-t";
+	obj->args[0].val_saver = (void *)&val_saver;
+	obj->args[0].val_set = (void *)88;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_OPTIONAL;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].name_long = NULL;
+	val_saver = 0;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("--test-long=66");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == 2, "Argparse parse with --test-long=66 expect success, got %d!", ret);
+	TEST_ASSERT(val_saver == 66, "Argparse parse --test-long=66 should set value to 66, got %d!",
+			val_saver);
+
+	/* Test short option with string value without '=' */
+	const char *str_saver = NULL;
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--test-string";
+	obj->args[0].name_short = "-s";
+	obj->args[0].val_saver = (void *)&str_saver;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_STR;
+	obj->args[1].name_long = NULL;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-shello");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == 2, "Argparse parse with -shello expect success, got %d!", ret);
+	TEST_ASSERT(str_saver != NULL && strcmp(str_saver, "hello") == 0,
+		"Argparse parse -shello should set string to 'hello', got '%s'!",
+		str_saver ? str_saver : "(null)");
+
+	/* Test short option with negative number without '=' */
+	obj = test_argparse_init_obj();
+	obj->args[0].name_long = "--test-long";
+	obj->args[0].name_short = "-t";
+	obj->args[0].val_saver = (void *)&val_saver;
+	obj->args[0].val_set = NULL;
+	obj->args[0].value_required = RTE_ARGPARSE_VALUE_REQUIRED;
+	obj->args[0].value_type = RTE_ARGPARSE_VALUE_TYPE_INT;
+	obj->args[1].name_long = NULL;
+	val_saver = 0;
+	argv[0] = test_strdup(obj->prog_name);
+	argv[1] = test_strdup("-t-42");
+	ret = rte_argparse_parse(obj, 2, argv);
+	TEST_ASSERT(ret == 2, "Argparse parse with -t-42 expect success, got %d!", ret);
+	TEST_ASSERT(val_saver == -42, "Argparse parse -t-42 should set value to -42, got %d!",
+			val_saver);
+
+	return 0;
+}
+
 static struct unit_test_suite argparse_test_suite = {
 	.suite_name = "Argparse Unit Test Suite",
 	.setup = test_argparse_setup,
@@ -1470,6 +1600,7 @@ static struct unit_test_suite argparse_test_suite = {
 		TEST_CASE(test_argparse_ignore_non_flag_args_trailing_non_flags),
 		TEST_CASE(test_argparse_ignore_non_flag_args_with_positional),
 		TEST_CASE(test_argparse_ignore_non_flag_args_short_and_long),
+		TEST_CASE(test_argparse_short_opt_value_without_equal),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}
lib/argparse/rte_argparse.c +6 -4
index 26a1371f36..21b35098c1 100644
@@ -691,7 +691,6 @@ parse_args(const struct rte_argparse *obj, bool *arg_parsed,
 	char **args_to_move;
 	uint32_t arg_idx;
 	char *curr_argv;
-	char *has_equal;
 	char *value;
 	int ret;
 	int i;
@@ -738,9 +737,11 @@ parse_args(const struct rte_argparse *obj, bool *arg_parsed,
 			continue;
 		}
 
-		has_equal = strchr(curr_argv, '=');
+		value = strchr(curr_argv, '=');
+		if (value == NULL && curr_argv[1] != '-' && strlen(curr_argv) > 2)
+			value = &curr_argv[2];
 		arg_name = NULL;
-		arg = find_option_arg(obj, &arg_idx, curr_argv, has_equal, &arg_name);
+		arg = find_option_arg(obj, &arg_idx, curr_argv, value, &arg_name);
 		if (arg == NULL || arg_name == NULL) {
 			ARGPARSE_LOG(ERR, "unknown argument %s!", curr_argv);
 			ret = -EINVAL;
@@ -753,7 +754,8 @@ parse_args(const struct rte_argparse *obj, bool *arg_parsed,
 			goto err_out;
 		}
 
-		value = (has_equal != NULL ? has_equal + 1 : NULL);
+		if (value != NULL && value[0] == '=')
+			value++; /* skip '=' */
 		if (arg->value_required == RTE_ARGPARSE_VALUE_NONE) {
 			if (value != NULL) {
 				ARGPARSE_LOG(ERR, "argument %s should not take value!", arg_name);
Signature · 1 line
2.48.1
#150 lore raw

PATCH v10 9/21 eal: add long options for each short option

In reply to Bruce Richardson

To simplify future rework of the EAL arg handling, add a long-option equivalent for each short option that doesn't already have one.

When updating the docs with the new long options, standardize the format of options which have both short and long variants, and drop the deprecated service-coremask option from the docs, rather than adding its new long option.

---
 doc/guides/linux_gsg/eal_args.include.rst | 20 ++++++++------------
 lib/eal/common/eal_common_options.c       |  8 ++++++++
 lib/eal/common/eal_options.h              | 16 ++++++++++++++++
 3 files changed, 32 insertions(+), 12 deletions(-)
doc/guides/linux_gsg/eal_args.include.rst +8 -12
index 9ced54af40..0b17879d42 100644
@@ -4,7 +4,7 @@
 Lcore-related options
 ~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-l/--lcores <core list>``
+*   ``-l, --lcores <core list>``
 
     List of cores to run on
 
@@ -71,11 +71,7 @@ Lcore-related options
 
     Core ID that is used as main.
 
-*   ``-s <service core mask>``
-
-    Hexadecimal bitmask of cores to be used as service cores.
-
-*   ``-S <service core list>``
+*   ``-S, --service-corelist <service core list>``
 
     List of cores to be used as service cores.
 
@@ -108,7 +104,7 @@ Device-related options
 
        --vdev 'net_pcap0,rx_pcap=input.pcap,tx_pcap=output.pcap'
 
-*   ``-d <path to shared object or directory>``
+*   ``-d, --driver-path <path to shared object or directory>``
 
     Load external drivers. An argument can be a single shared object file, or a
     directory containing multiple driver shared objects. Multiple -d options are
@@ -134,15 +130,15 @@ Multiprocessing-related options
 Memory-related options
 ~~~~~~~~~~~~~~~~~~~~~~
 
-*   ``-n <number of channels>``
+*   ``-n, --memory-channels <number of channels>``
 
     Set the number of memory channels to use.
 
-*   ``-r <number of ranks>``
+*   ``-r, --memory-ranks <number of ranks>``
 
     Set the number of memory ranks (auto-detected by default).
 
-*   ``-m <megabytes>``
+*   ``-m, --memory-size <megabytes>``
 
     Amount of memory to preallocate at startup.
 
@@ -236,11 +232,11 @@ Debugging options
 Other options
 ~~~~~~~~~~~~~
 
-*   ``-h``, ``--help``
+*   ``-h, --help``
 
     Display help message listing all EAL parameters.
 
-*   ``-v``
+*   ``-v, --version``
 
     Display the version information on startup.
 
lib/eal/common/eal_common_options.c +8 -0
index 2f91b96190..675745d610 100644
@@ -66,7 +66,9 @@ eal_short_options[] =
 const struct option
 eal_long_options[] = {
 	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
+	{OPT_COREMASK,          1, NULL, OPT_COREMASK_NUM        },
 	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
+	{OPT_DRIVER_PATH,       1, NULL, OPT_DRIVER_PATH_NUM     },
 	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
 	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
 	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
@@ -76,6 +78,11 @@ eal_long_options[] = {
 	{OPT_LOG_COLOR,		2, NULL, OPT_LOG_COLOR_NUM	  },
 	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
 	{OPT_LOG_TIMESTAMP,     2, NULL, OPT_LOG_TIMESTAMP_NUM    },
+	{OPT_MEMORY_CHANNELS,   1, NULL, OPT_MEMORY_CHANNELS_NUM },
+	{OPT_MEMORY_RANKS,      1, NULL, OPT_MEMORY_RANKS_NUM    },
+	{OPT_MEMORY_SIZE,       1, NULL, OPT_MEMORY_SIZE_NUM     },
+	{OPT_SERVICE_CORELIST,  1, NULL, OPT_SERVICE_CORELIST_NUM },
+	{OPT_SERVICE_COREMASK,  1, NULL, OPT_SERVICE_COREMASK_NUM },
 	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
 	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
 	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
@@ -109,6 +116,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_VERSION,           0, NULL, OPT_VERSION_NUM         },
 
 	{0,                     0, NULL, 0                        }
 };
lib/eal/common/eal_options.h +16 -0
index 7a56aa3810..6ef45559f0 100644
@@ -17,8 +17,24 @@ enum {
 	OPT_DEV_ALLOW_NUM       = 'a',
 #define OPT_DEV_BLOCK         "block"
 	OPT_DEV_BLOCK_NUM      = 'b',
+#define OPT_COREMASK          "coremask"
+	OPT_COREMASK_NUM       = 'c',
+#define OPT_DRIVER_PATH       "driver-path"
+	OPT_DRIVER_PATH_NUM    = 'd',
 #define OPT_LCORES            "lcores"
 	OPT_LCORES_NUM         = 'l',
+#define OPT_MEMORY_SIZE       "memory-size"
+	OPT_MEMORY_SIZE_NUM    = 'm',
+#define OPT_MEMORY_CHANNELS   "memory-channels"
+	OPT_MEMORY_CHANNELS_NUM = 'n',
+#define OPT_MEMORY_RANKS     "memory-ranks"
+	OPT_MEMORY_RANKS_NUM   = 'r',
+#define OPT_SERVICE_COREMASK  "service-coremask"
+	OPT_SERVICE_COREMASK_NUM = 's',
+#define OPT_SERVICE_CORELIST  "service-corelist"
+	OPT_SERVICE_CORELIST_NUM = 'S',
+#define OPT_VERSION           "version"
+	OPT_VERSION_NUM        = 'v',
 
 	/* first long only option value must be >= 256, so that we won't
 	 * conflict with short options */
Signature · 1 line
2.48.1
#151 lore raw

PATCH v10 10/21 eal: define the EAL parameters in argparse format

In reply to Bruce Richardson

Create eal_option_list.h, containing all the possible EAL parameters, and basic info about them, such as type, whether they take a parameter or not. Each entry is defined using a macro, which will be then interpreted when the file is included.

First time this header in included in the eal_common_options.c file, the macros are defined in such a way as to define field elements for an "eal_init_args" structure, where each value is either a string type, if it takes a parameter, or boolean type if it doesn't. For those elements that take multiple values, i.e. are passed multiple times, we put them in a TAILQ.

The second time of inclusion, the macros are defined so as to define the arguments in an rte_argparse structure for EAL. For the basic string and boolean types, we just store the values in the appropriate field in the previous defined "eal_init_args" structure. For the list elements, we use the argparse callback to process those elements, adding them to the TAILQ as they are encountered.

---
 lib/eal/common/eal_common_options.c | 142 +++++++++++++++++++++++++++-
 lib/eal/common/eal_option_list.h    |  90 ++++++++++++++++++
 lib/eal/meson.build                 |   2 +-
 lib/meson.build                     |   1 +
 4 files changed, 231 insertions(+), 4 deletions(-)
 create mode 100644 lib/eal/common/eal_option_list.h
lib/eal/common/eal_common_options.c +139 -3
index 675745d610..c07f121d05 100644
@@ -10,6 +10,7 @@
 #include <limits.h>
 #include <errno.h>
 #include <getopt.h>
+#include <sys/queue.h>
 #ifndef RTE_EXEC_ENV_WINDOWS
 #include <dlfcn.h>
 #include <libgen.h>
@@ -33,6 +34,7 @@
 #endif
 #include <rte_vect.h>
 
+#include <rte_argparse.h>
 #include <eal_export.h>
 #include "eal_internal_cfg.h"
 #include "eal_options.h"
@@ -47,6 +49,143 @@
 #define LCORE_OPT_LST 1
 #define LCORE_OPT_MSK 2
 
+/* Allow the application to print its usage message too if set */
+static rte_usage_hook_t rte_application_usage_hook;
+
+struct arg_list_elem {
+	TAILQ_ENTRY(arg_list_elem) next;
+	char *arg;
+};
+TAILQ_HEAD(arg_list, arg_list_elem);
+
+struct eal_init_args {
+	/* define a struct member for each EAL option, member name is the same as option name.
+	 * Parameters that take an argument e.g. -l, are char *,
+	 * parameters that take no options e.g. --no-huge, are bool.
+	 * parameters that can be given multiple times e.g. -a, are arg_lists,
+	 * parameters that are optional e.g. --huge-unlink,
+	 *   are char * but are set to (void *)1 if the parameter is not given.
+	 * for aliases, i.e. options under different names, no field needs to be output
+	 */
+#define LIST_ARG(long, short, help_str, fieldname) struct arg_list fieldname;
+#define STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define OPT_STR_ARG(long, short, help_str, fieldname) char *fieldname;
+#define BOOL_ARG(long, short, help_str, fieldname) bool fieldname;
+#define STR_ALIAS(long, short, help_str, fieldname)
+
+#define INCLUDE_ALL_ARG 1  /* for struct definition, include even unsupported values */
+#include "eal_option_list.h"
+#undef INCLUDE_ALL_ARG
+};
+struct eal_init_args args;
+
+/* an rte_argparse callback to append the argument to an arg_list
+ * in args. The index is the offset into the struct of the list.
+ */
+static int
+arg_list_callback(uint32_t index, const char *arg, void *init_args)
+{
+	struct arg_list *list = RTE_PTR_ADD(init_args, index);
+	struct arg_list_elem *elem;
+
+	elem = malloc(sizeof(*elem));
+	if (elem == NULL)
+		return -1;
+
+	elem->arg = strdup(arg);
+	if (elem->arg == NULL) {
+		free(elem);
+		return -1;
+	}
+
+	TAILQ_INSERT_TAIL(list, elem, next);
+	return 0;
+}
+
+static void
+eal_usage(const struct rte_argparse *obj)
+{
+	rte_argparse_print_help(stdout, obj);
+	if (rte_application_usage_hook != NULL)
+		rte_application_usage_hook(obj->prog_name);
+}
+
+/* undef the *_ARG macros before redefining to generate the argparse arg list */
+#undef LIST_ARG
+#undef STR_ARG
+#undef OPT_STR_ARG
+#undef BOOL_ARG
+#undef STR_ALIAS
+
+/* For arguments which have an arg_list type, they use callback (no val_saver),
+ * require a value, and have the SUPPORT_MULTI flag.
+ */
+#define LIST_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_set = (void *)offsetof(struct eal_init_args, fieldname), \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.flags = RTE_ARGPARSE_FLAG_SUPPORT_MULTI, \
+},
+/* For arguments which have a string type, they use val_saver (no callback),
+ * and normally REQUIRED_VALUE.
+ */
+#define STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.value_required = RTE_ARGPARSE_VALUE_REQUIRED, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For flags which have optional arguments, they use both val_saver and val_set,
+ * but still have a string type.
+ */
+#define OPT_STR_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_OPTIONAL, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_STR, \
+},
+/* For boolean arguments, they use val_saver and val_set, with NO_VALUE flag.
+ */
+#define BOOL_ARG(long, short, help_str, fieldname) { \
+	.name_long = long, \
+	.name_short = short, \
+	.help = help_str, \
+	.val_saver = &args.fieldname, \
+	.val_set = (void *)1, \
+	.value_required = RTE_ARGPARSE_VALUE_NONE, \
+	.value_type = RTE_ARGPARSE_VALUE_TYPE_BOOL, \
+},
+#define STR_ALIAS STR_ARG
+
+#if RTE_VER_RELEASE == 99
+#define GUIDES_PATH "https://doc.dpdk.org/guides-" RTE_STR(RTE_VER_YEAR) "." RTE_STR(RTE_VER_MONTH)
+#else
+#define GUIDES_PATH "https://doc.dpdk.org/guides"
+#endif
+
+struct rte_argparse eal_argparse  = {
+	.prog_name = "",
+	.usage = "<DPDK EAL options> -- <App options>",
+	.epilog = "For more information on EAL options, see the DPDK documentation at: \n"
+			"\t" GUIDES_PATH "/" RTE_EXEC_ENV_NAME "_gsg/",
+	.exit_on_error = true,
+	.ignore_non_flag_args = true,
+	.callback = arg_list_callback,
+	.print_help = eal_usage,
+	.opaque = &args,
+	.args = {
+		#include "eal_option_list.h"
+		ARGPARSE_ARG_END(),
+	}
+};
+
 const char
 eal_short_options[] =
 	"a:" /* allow */
@@ -164,9 +303,6 @@ static int main_lcore_parsed;
 static int mem_parsed;
 static int core_parsed;
 
-/* Allow the application to print its usage message too if set */
-static rte_usage_hook_t rte_application_usage_hook;
-
 /* Returns rte_usage_hook_t */
 rte_usage_hook_t
 eal_get_application_usage_hook(void)
lib/eal/common/eal_option_list.h new file +90 -0

90 lines not on this page · raw message

lib/eal/meson.build +1 -1
index e1d6c4cf17..f9fcee24ee 100644
@@ -14,7 +14,7 @@ subdir(exec_env)
 
 subdir(arch_subdir)
 
-deps += ['log', 'kvargs']
+deps += ['argparse', 'kvargs']
 if not is_windows
     deps += ['telemetry']
 endif
lib/meson.build +1 -0
index d79740a4c3..c8f4270868 100644
@@ -71,6 +71,7 @@ libraries = [
 ]
 
 always_enable = [
+        'argparse',
         'cmdline',
         'eal',
         'ethdev',
Signature · 1 line
2.48.1