rework EAL argument parsing in DPDK
Subsystems (2)
PATCH v10 11/21 eal: gather EAL args before processing
In reply to Bruce RichardsonDPDK 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
@@ -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;
@@ -186,79 +185,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 || argv[0 ] ==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);
@@ -300,7 +253,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 */
@@ -324,7 +276,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;
@@ -412,7 +369,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)
@@ -840,17 +797,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) {
@@ -1677,361 +1623,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
@@ -2164,13 +2236,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 ; }
@@ -2256,98 +2323,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
@@ -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
@@ -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
PATCH v10 12/21 eal: ensure proper cleanup on EAL init failure
In reply to Bruce RichardsonWhen 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
@@ -280,6 +280,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;
@@ -311,6 +313,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) {
@@ -355,18 +379,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
@@ -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
PATCH v10 13/21 eal: combine parameter validation checks
In reply to Bruce RichardsonRemove 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
@@ -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
@@ -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
@@ -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
PATCH v10 14/21 eal: simplify handling of conflicting cmdline options
In reply to Bruce RichardsonUse 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
@@ -185,6 +185,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. */
@@ -209,6 +232,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 ; }
@@ -1795,78 +1842,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
PATCH v10 15/21 eal: automatically init arg list options
In reply to Bruce RichardsonThe 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
@@ -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. */
@@ -217,15 +220,6 @@ eal_collate_args(int argc, char **argv)if (argc <1 || argv ==NULL || argv[0 ] ==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
@@ -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
PATCH v10 16/21 eal: add internal fn for converting cpuset to string
In reply to Bruce RichardsonThe 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
@@ -1571,8 +1571,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;
@@ -1580,13 +1580,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 */
@@ -1595,8 +1595,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 ) {
@@ -1639,6 +1639,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
@@ -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
PATCH v10 17/21 eal: use common cpuset to string function
In reply to Bruce RichardsonUse 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
@@ -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
@@ -1050,6 +1050,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 ; }
@@ -2196,6 +2211,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
@@ -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
PATCH v10 18/21 eal: introduce lcore remapping option for coremasks
In reply to Bruce RichardsonAdd 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v10 19/21 eal: rework internal coremask parsing to use cpu sets
In reply to Bruce RichardsonRather 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
@@ -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
@@ -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
@@ -842,7 +842,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 ;
@@ -856,9 +856,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 ;
@@ -867,7 +867,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);
@@ -920,7 +920,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 ];
@@ -929,8 +929,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" );
@@ -976,6 +975,7 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)return -1 ; } lcores[count++] = idx; +CPU_SET (idx, cpuset); } } }
@@ -989,16 +989,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 ; }
@@ -1932,13 +1922,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
@@ -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
@@ -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
PATCH v10 20/21 eal: allow lcore ID remapping with core lists
In reply to Bruce RichardsonAllow 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
@@ -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
@@ -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
@@ -1938,9 +1938,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
PATCH v10 21/21 eal: allow lcore remapping with autodetected core affinity
In reply to Bruce RichardsonWhen 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 | 135 ++++++++++++++-------------- 1 file changed, 66 insertions(+), 69 deletions(-)
lib/eal/common/eal_common_options.c +66 -69
@@ -293,8 +293,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 )
@@ -831,7 +829,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" );
@@ -864,8 +862,21 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base) ret =-1 ;continue ; } + +if (count >=RTE_MAX_LCORE ) { +EAL_LOG (WARNING ,"Too many lcores provided (>=RTE_MAX_LCORE[%d]). All remaining lcores will be skipped." , +RTE_MAX_LCORE ); +break ; + } +if (!remap) lcore_id = i; +if (lcore_id >=RTE_MAX_LCORE ) { +EAL_LOG (ERR ,"lcore %u >= RTE_MAX_LCORE (%d), skipping lcore" , + lcore_id,RTE_MAX_LCORE ); +continue ; + } + cfg->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_index = count;CPU_ZERO (&lcore_config[lcore_id].cpuset);
@@ -875,6 +886,10 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base) count++; } } +if (count ==0 ) { +EAL_LOG (ERR ,"No valid lcores in core list" ); + ret =-1 ; + }if (!ret) cfg->lcore_count = count;return ret;
@@ -1052,7 +1067,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" );
@@ -1920,53 +1935,67 @@ eal_parse_args(void) } } +/* parse the core list arguments */ -if (args.coremask !=NULL ) { -rte_cpuset_t cpuset; +/* check if we are using manual mapping */ +bool manual_lcore_mapping = (args.lcores !=NULL ) && + ((strchr (args.lcores,'@' ) !=NULL ||strchr (args.lcores,'(' ) !=NULL )); -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 (); +if (manual_lcore_mapping && remap_lcores) { +EAL_LOG (ERR ,"cannot use '@' or core groupings '()' in lcore list when remapping lcores" ); +return -1 ; + } -EAL_LOG (ERR ,"invalid coremask '%s', please check specified cores are part of %s" , - args.coremask, available); -free (available); +/* First handle the special case where we have explicit core mapping/remapping */ +if (manual_lcore_mapping) { +if (eal_parse_lcores (args.lcores) <0 ) { +EAL_LOG (ERR ,"invalid lcore mapping 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); -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" ); + }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 ; } + cpuset_source ="coremask" ; + }else if (args.lcores !=NULL ) {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); + 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 ) {
@@ -2209,27 +2238,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) {
@@ -2277,20 +2285,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
Re: [PATCH v10 00/21] Simplify running with high-numbered CPUs
In reply to Bruce RichardsonQuoted 139 lines · On Wed, 8 Oct 2025 21:42:23 +0100 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 fixfunc_reentrancytest 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_LCOREV9: 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 mainV5:
* 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-limitBruce 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 affinityapp/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
Quoted 3 lines
--
2.48.1
There is one other thing about eal_init. The arguments in argv can not be const right now, since there are cases where args are modified. Could we fix that. Code like dpdk-dumpcap has to strdup() the args.
Re: [PATCH v10 00/21] Simplify running with high-numbered CPUs
Quoted 142 lines · Stephen Hemminger
Quoted 139 lines · On Wed, 8 Oct 2025 21:42:23 +0100 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 fixfunc_reentrancytest 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_LCOREV9: 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 mainV5:
* 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-limitBruce 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 affinityapp/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
Quoted 7 lines
Quoted 3 lines
--
2.48.1There is one other thing about
eal_init. The arguments in argv can not be const right now, since there are cases where args are modified. Could we fix that. Code like dpdk-dumpcap has tostrdup()the args.
I looked a little at adding some const-ness when looking at this. Two things are preventing this:
1. While ideally we should not be modifying the individual args themselves, simply changing the argv type to "const char **argv" won't work, as you can't safely cast "char **argv" to that and you get the compiler complaining. [Took a bit of googling on my part to understand why this is not allowed, it's non-obvious IMHO!]
2. We can't make the pointers const because of getopt behaviour now optionally mirrored in argparse too, where it reorders non-option arguments to the end of the argv list.
/Bruce
v11 cover [PATCH v11 00/21]
In reply to Bruce RichardsonThe 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.
V11:
* fix issues flagged by unit tests in CI and subsequent testing:
- when passing in an lcore >= MAX_LCORES, return error rather than ignoring it. (compatibility issue)
- return error when an invalid lcore set of "1-3-5" is passed in, rather than just treating it as "3-5".
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 | 702 ++++++++++ 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 | 183 ++- 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 | 1440 +++++++++++--------- 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, 2158 insertions(+), 1606 deletions(-) create mode 100644 lib/eal/common/eal_option_list.h
--
2.48.1
PATCH v11 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
@@ -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
@@ -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
Re: [PATCH v11 01/21] build: add define for the OS environment name
Quoted 10 lines · Bruce Richardson
Introduce a string define for the currently running OS, or execution environment.
Originally, with old make build system,
CONFIG_RTE_EXEC_ENVused to hold this name string, but the variable seems to have been missed in the meson build system, until commitcadb255e25d6("eal: add OS defines for C conditional checks") which introduced theRTE_EXEC_ENVfor a different purpose. Now we can fix the docs with the new name reference.Signed-off-by Bruce Richardson <[email protected]>
PATCH v11 2/21 test/func_reentrancy: fix args to EAL init call
In reply to Bruce RichardsonThe 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].
--- app/test/test_func_reentrancy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
app/test/test_func_reentrancy.c +3 -2
@@ -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
Re: [PATCH v11 02/21] test/func_reentrancy: fix args to EAL init call
Quoted 9 lines · 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")Signed-off-by Bruce Richardson <[email protected]>
Signature · 1 line
David Marchand
Re: [PATCH v11 02/21] test/func_reentrancy: fix args to EAL init call
In reply to Bruce RichardsonQuoted 8 lines · 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")Signed-off-by Bruce Richardson <[email protected]>
PATCH v11 3/21 argparse: export function to print help text for object
In reply to Bruce RichardsonMake 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
@@ -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
@@ -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
Re: [PATCH v11 03/21] argparse: export function to print help text for object
Quoted 6 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.
Signed-off-by Bruce Richardson<[email protected]>
PATCH v11 4/21 argparse: allow user-override of help printing
In reply to Bruce RichardsonWhen 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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH v11 04/21] argparse: allow user-override of help printing
Quoted 5 lines · 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.
Signed-off-by Bruce Richardson<[email protected]>
PATCH v11 5/21 argparse: add documentation on supported value types
In reply to Bruce RichardsonThe 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
@@ -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
Re: [PATCH v11 05/21] argparse: add documentation on supported value types
Minor comment on paragraph layout, with that fixed:
Quoted 14 lines · Bruce Richardson
The different value types supported by the argparse library are not discussed in the documentation, so add some reference material about them.
Signed-off-by Bruce Richardson <[email protected]>--- doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)doc/guides/prog_guide/argparse_lib.rst +0
-0
doc/guides/prog_guide/argparse_lib.rst both use this way, the parsing is as follows: · line 164
Quoted 5 lines
doc/guides/prog_guide/argparse_lib.rst +2
-0@@ -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 +~~~~~~~~~~~~~~~~~~~~~
This paragraph should be the inner paragraph of 'Parsing by autosave way' I suggest delete the ~~~~~, and move the whole after "Parsing by autosave way"
Quoted 81 lines
doc/guides/prog_guide/argparse_lib.rst +69
-2+ +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 ~~~~~~~~~~~~~~~~~~~~~~~
Re: [PATCH v11 05/21] argparse: add documentation on supported value types
Quoted 21 lines · fengchengwen
Minor comment on paragraph layout, with that fixed:
Acked-by Chengwen Feng <[email protected]>Quoted 17 lines · Bruce Richardson
The different value types supported by the argparse library are not discussed in the documentation, so add some reference material about them.
Signed-off-by Bruce Richardson <[email protected]>--- doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)doc/guides/prog_guide/argparse_lib.rst +0
-0@@ -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.
Quoted 6 lines
doc/guides/prog_guide/argparse_lib.rst both use this way, the parsing is as follows: · line 164
Quoted 2 lines
doc/guides/prog_guide/argparse_lib.rst +2
-0+Supported Value Types +~~~~~~~~~~~~~~~~~~~~~This paragraph should be the inner paragraph of 'Parsing by autosave way' I suggest delete the ~~~~~, and move the whole after "Parsing by autosave way"
I actually disagree on this. I think the value types needs its own subsection to hold the various value-type sub-subsections together. I had originally considered making this a subsection of the autosave one, but that left us with too many levels of nesting. I think having it at this level works ok.
Re: [PATCH v11 05/21] argparse: add documentation on supported value types
Quoted 27 lines · Bruce Richardson
Quoted 21 lines · fengchengwen
Minor comment on paragraph layout, with that fixed:
Acked-by Chengwen Feng <[email protected]>Quoted 17 lines · Bruce Richardson
The different value types supported by the argparse library are not discussed in the documentation, so add some reference material about them.
Signed-off-by Bruce Richardson <[email protected]>--- doc/guides/prog_guide/argparse_lib.rst | 73 +++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)doc/guides/prog_guide/argparse_lib.rst +0
-0@@ -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.Quoted 5 lines
doc/guides/prog_guide/argparse_lib.rst both use this way, the parsing is as follows: · line 164
Quoted 2 lines
doc/guides/prog_guide/argparse_lib.rst +2
-0+Supported Value Types +~~~~~~~~~~~~~~~~~~~~~This paragraph should be the inner paragraph of 'Parsing by autosave way' I suggest delete the ~~~~~, and move the whole after "Parsing by autosave way"
Quoted 5 lines
I actually disagree on this. I think the value types needs its own subsection to hold the various value-type sub-subsections together. I had originally considered making this a subsection of the autosave one, but that left us with too many levels of nesting. I think having it at this level works ok.
okay
Quoted 2 lines
PATCH v11 6/21 argparse: add support for parsing core lists
In reply to Bruce RichardsonCore lists are widely used in DPDK, so add support for parsing them.
--- app/test/test_argparse.c | 195 +++++++++++++++++++++++++ doc/guides/prog_guide/argparse_lib.rst | 32 ++++ lib/argparse/rte_argparse.c | 65 +++++++++ lib/argparse/rte_argparse.h | 2 + 4 files changed, 294 insertions(+)
app/test/test_argparse.c +195 -0
@@ -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,159 @@ 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_range_double_range =test_strdup ("1-3-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 double dash */ +CPU_ZERO (&val_cpuset); + ret =rte_argparse_parse_type (corelist_invalid_range_double_range, +RTE_ARGPARSE_VALUE_TYPE_CORELIST , &val_cpuset); +TEST_ASSERT (ret !=0 ,"Argparse parse type for corelist (double range) 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 +1068,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 +1094,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
@@ -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 +65 -0
92 lines not on this page · raw message
lib/argparse/rte_argparse.h +2 -0
@@ -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
Re: [PATCH v11 06/21] argparse: add support for parsing core lists
Minor comment on paragraph layout, with that fixed:
Quoted 273 lines · Bruce Richardson
Core lists are widely used in DPDK, so add support for parsing them.
Signed-off-by Bruce Richardson <[email protected]>--- app/test/test_argparse.c | 195 +++++++++++++++++++++++++ doc/guides/prog_guide/argparse_lib.rst | 32 ++++ lib/argparse/rte_argparse.c | 65 +++++++++ lib/argparse/rte_argparse.h | 2 + 4 files changed, 294 insertions(+)app/test/test_argparse.c +195
-0@@ -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,159 @@ 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_range_double_range =test_strdup ("1-3-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 double dash */ +CPU_ZERO (&val_cpuset); + ret =rte_argparse_parse_type (corelist_invalid_range_double_range, +RTE_ARGPARSE_VALUE_TYPE_CORELIST , &val_cpuset); +TEST_ASSERT (ret !=0 ,"Argparse parse type for corelist (double range) 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 +1068,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 +1094,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 +21
-0@@ -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:
doc/guides/prog_guide/argparse_lib.rst Boolean arguments are parsed using ``RTE_ARGPARSE_VALUE_TYPE_BOOL`` and accept t · line 262
Quoted 10 lines
doc/guides/prog_guide/argparse_lib.rst +10
-0+ +- **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:
the : should be .
Quoted 45 lines
doc/guides/prog_guide/argparse_lib.rst +1
-0+ Parsing by callback way ~~~~~~~~~~~~~~~~~~~~~~~lib/argparse/rte_argparse.c +16
-0@@ -5,9 +5,11 @@#include <errno.h> #include <stdlib.h> #include <string.h> +#include <ctype.h> #include <eal_export.h> #include <rte_log.h> +#include <rte_os.h> #include "rte_argparse.h" @@ -53,6 +55,7 @@ is_valid_value_type_field(const struct rte_argparse_arg *arg)case RTE_ARGPARSE_VALUE_TYPE_U64 :case RTE_ARGPARSE_VALUE_TYPE_STR :case RTE_ARGPARSE_VALUE_TYPE_BOOL : +case RTE_ARGPARSE_VALUE_TYPE_CORELIST :return true;/* omit default case so compiler warns on any missing enum values */ }@@ -554,6 +557,66 @@ parse_arg_bool(const struct rte_argparse_arg *arg, const char *value)return 0 ; } +static int +parse_arg_corelist (const struct rte_argparse_arg *arg,const char *value) +{ +rte_cpuset_t *cpuset = arg->val_saver; +const char *last = value; +int min =-1 ; + +if (value ==NULL ) { + *cpuset = *(rte_cpuset_t *)arg->val_set; +return 0 ; + } + +CPU_ZERO (cpuset);
lib/argparse/rte_argparse.c parse_arg_bool(const struct rte_argparse_arg *arg, const char *value) · line 582
Quoted 10 lines
lib/argparse/rte_argparse.c +10
-0+while (*last !='\0' ) { +char *end; +int64_t idx; +int32_t max; + +while (isblank (*value)) + value++; + +if (!isdigit (*value)) +return -1 ;
Suggest add detail trace (ARGPARSE_LOG(ERR, xxx)) when error
Quoted 54 lines
lib/argparse/rte_argparse.c +39
-0+ + errno =0 ; + idx =strtol (value, &end,10 ); + last = end; +if (errno || idx >UINT16_MAX ) +return -1 ; + +if (*end =='-' ) { +if (min !=-1 )/* can't have '-' within a range */ +return -1 ; + min = idx;/* start of range, move to next loop stage */ + }else if (*end ==',' || *end =='\0' ) { +/* single value followed by comma or end (min is set only by '-') */ +if (min ==-1 ) { + min = max = idx; + }else if (min > idx) { +/* we have range from high to low */ + max = min; + min = idx; + }else { +/* range from low to high */ + max = idx; + } + +for (; min <= max; min++) +CPU_SET (min, cpuset); + + min =-1 ;/* no longer in a range */ + }else { +/* end is an unexpected character, return error */ +return -1 ; + } + value = last +1 ; + } +return 0 ; +} +static int parse_arg_autosave (const struct rte_argparse_arg *arg,const char *value) {@@ -575,6 +638,8 @@ parse_arg_autosave(const struct rte_argparse_arg *arg, const char *value)return parse_arg_str (arg, value);case RTE_ARGPARSE_VALUE_TYPE_BOOL :return parse_arg_bool (arg, value); +case RTE_ARGPARSE_VALUE_TYPE_CORELIST : +return parse_arg_corelist (arg, value);/* omit default case so compiler warns on missing enum values */ }return -EINVAL ;lib/argparse/rte_argparse.h +0
-0
lib/argparse/rte_argparse.h enum rte_argparse_value_type { · line 72
Quoted 4 lines
lib/argparse/rte_argparse.h +1
-0@@ -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 */
please add a period at the end.
Quoted 4 lines
lib/argparse/rte_argparse.h +1
-0+ RTE_ARGPARSE_VALUE_TYPE_CORELIST, };/** Additional flags which may be specified for each argument */
PATCH v11 7/21 argparse: allow optional flag reordering
In reply to Bruce RichardsonAllow 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
@@ -1077,6 +1077,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,
@@ -1101,6 +1466,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
@@ -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
@@ -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
PATCH v11 8/21 argparse: support parameters to short options without "="
In reply to Bruce RichardsonWhen 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
@@ -1442,6 +1442,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,
@@ -1477,6 +1607,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
@@ -693,7 +693,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;
@@ -740,9 +739,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 ;
@@ -755,7 +756,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
Re: [PATCH v11 08/21] argparse: support parameters to short options without "="
Please add document about this,
Quoted 10 lines · 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.
Signed-off-by Bruce Richardson<[email protected]>
PATCH v11 9/21 eal: add long options for each short option
In reply to Bruce RichardsonTo 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
@@ -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
@@ -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
@@ -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
Re: [PATCH v11 09/21] eal: add long options for each short option
Quoted 9 lines · 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.
Signed-off-by Bruce Richardson<[email protected]>
PATCH v11 10/21 eal: define the EAL parameters in argparse format
In reply to Bruce RichardsonCreate 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
@@ -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
@@ -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
@@ -71,6 +71,7 @@ libraries = [ ] always_enable = [ + 'argparse', 'cmdline', 'eal', 'ethdev',
Signature · 1 line
2.48.1
Re: [PATCH v11 10/21] eal: define the EAL parameters in argparse format
Quoted 20 lines · 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.cfile, 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_argparsestructure 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.Signed-off-by Bruce Richardson<[email protected]>
PATCH v11 11/21 eal: gather EAL args before processing
In reply to Bruce RichardsonDPDK 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
@@ -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;
@@ -186,79 +185,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 || argv[0 ] ==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);
@@ -300,7 +253,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 */
@@ -324,7 +276,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;
@@ -412,7 +369,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)
@@ -840,17 +797,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) {
@@ -1677,361 +1623,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
@@ -2164,13 +2236,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 ; }
@@ -2256,98 +2323,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
@@ -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
@@ -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
Re: [PATCH v11 11/21] eal: gather EAL args before processing
Quoted 7 lines · 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.
Signed-off-by Bruce Richardson<[email protected]>
PATCH v11 12/21 eal: ensure proper cleanup on EAL init failure
In reply to Bruce RichardsonWhen 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
@@ -280,6 +280,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;
@@ -311,6 +313,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) {
@@ -355,18 +379,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
@@ -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
PATCH v11 13/21 eal: combine parameter validation checks
In reply to Bruce RichardsonRemove 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
@@ -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
@@ -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
@@ -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
PATCH v11 14/21 eal: simplify handling of conflicting cmdline options
In reply to Bruce RichardsonUse 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
@@ -185,6 +185,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. */
@@ -209,6 +232,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 ; }
@@ -1795,78 +1842,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
PATCH v11 15/21 eal: automatically init arg list options
In reply to Bruce RichardsonThe 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
@@ -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. */
@@ -217,15 +220,6 @@ eal_collate_args(int argc, char **argv)if (argc <1 || argv ==NULL || argv[0 ] ==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
@@ -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
PATCH v11 16/21 eal: add internal fn for converting cpuset to string
In reply to Bruce RichardsonThe 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
@@ -1571,8 +1571,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;
@@ -1580,13 +1580,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 */
@@ -1595,8 +1595,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 ) {
@@ -1639,6 +1639,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
@@ -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
PATCH v11 17/21 eal: use common cpuset to string function
In reply to Bruce RichardsonUse 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
@@ -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
@@ -1050,6 +1050,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 ; }
@@ -2196,6 +2211,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
@@ -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
PATCH v11 18/21 eal: introduce lcore remapping option for coremasks
In reply to Bruce RichardsonAdd 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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v11 19/21 eal: rework internal coremask parsing to use cpu sets
In reply to Bruce RichardsonRather 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
@@ -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
@@ -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
@@ -842,7 +842,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 ;
@@ -856,9 +856,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 ;
@@ -867,7 +867,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);
@@ -920,7 +920,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 ];
@@ -929,8 +929,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" );
@@ -976,6 +975,7 @@ rte_eal_parse_coremask(const char *coremask, int *cores, bool limit_range)return -1 ; } lcores[count++] = idx; +CPU_SET (idx, cpuset); } } }
@@ -989,16 +989,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 ; }
@@ -1932,13 +1922,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
@@ -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
@@ -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
PATCH v11 20/21 eal: allow lcore ID remapping with core lists
In reply to Bruce RichardsonAllow 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
@@ -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
@@ -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
@@ -1938,9 +1938,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
PATCH v11 21/21 eal: allow lcore remapping with autodetected core affinity
In reply to Bruce RichardsonWhen 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 | 136 ++++++++++++++-------------- 1 file changed, 67 insertions(+), 69 deletions(-)
lib/eal/common/eal_common_options.c +67 -69
@@ -293,8 +293,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 )
@@ -831,7 +829,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" );
@@ -864,8 +862,22 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base) ret =-1 ;continue ; } + +if (count >=RTE_MAX_LCORE ) { +EAL_LOG (WARNING ,"Too many lcores provided (>=RTE_MAX_LCORE[%d]). All remaining lcores will be skipped." , +RTE_MAX_LCORE ); +break ; + } +if (!remap) lcore_id = i; +if (lcore_id >=RTE_MAX_LCORE ) { +EAL_LOG (ERR ,"lcore %u >= RTE_MAX_LCORE (%d), cannot use." , + lcore_id,RTE_MAX_LCORE ); + ret =-1 ; +continue ; + } + cfg->lcore_role[lcore_id] =ROLE_RTE ; lcore_config[lcore_id].core_index = count;CPU_ZERO (&lcore_config[lcore_id].cpuset);
@@ -875,6 +887,10 @@ update_lcore_config(const rte_cpuset_t *cpuset, bool remap, uint16_t remap_base) count++; } } +if (count ==0 ) { +EAL_LOG (ERR ,"No valid lcores in core list" ); + ret =-1 ; + }if (!ret) cfg->lcore_count = count;return ret;
@@ -1052,7 +1068,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" );
@@ -1920,53 +1936,67 @@ eal_parse_args(void) } } +/* parse the core list arguments */ -if (args.coremask !=NULL ) { -rte_cpuset_t cpuset; +/* check if we are using manual mapping */ +bool manual_lcore_mapping = (args.lcores !=NULL ) && + ((strchr (args.lcores,'@' ) !=NULL ||strchr (args.lcores,'(' ) !=NULL )); -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 (); +if (manual_lcore_mapping && remap_lcores) { +EAL_LOG (ERR ,"cannot use '@' or core groupings '()' in lcore list when remapping lcores" ); +return -1 ; + } -EAL_LOG (ERR ,"invalid coremask '%s', please check specified cores are part of %s" , - args.coremask, available); -free (available); +/* First handle the special case where we have explicit core mapping/remapping */ +if (manual_lcore_mapping) { +if (eal_parse_lcores (args.lcores) <0 ) { +EAL_LOG (ERR ,"invalid lcore mapping 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); -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" ); + }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 ; } + cpuset_source ="coremask" ; + }else if (args.lcores !=NULL ) {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); + 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 ) {
@@ -2209,27 +2239,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) {
@@ -2277,20 +2286,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
Re: [PATCH v11 00/21]
In reply to Bruce RichardsonHello Bruce,
Quoted 35 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.
Quoted 6 lines
V11:
* fix issues flagged by unit tests in CI and subsequent testing:
- when passing in an lcore >=MAX_LCORES, return error rather than ignoring it. (compatibility issue)
- return error when an invalid lcore set of "1-3-5" is passed in, rather than just treating it as "3-5".
I did some tweaking on the series (and put my sob for taking the bullet if I broke something ;-)), namely:
- squashed the init arg list patch into the initial patch that introduces eal_option_list.h,
- inverted order of the patch on coremask rework with the one introducing lcore remapping,
- I updated patch 6 as Chengwen requested, and I fixed return codes for parse_arg_corelist(),
- I updated the doc for patch 8 as Chengwen requested,
I fixed a few reintroductions of socket-mem (should be numa-mem) in intermediate patches.
I noticed that the leak reported earlier on patch "eal: gather EAL args before processing" is still present when stopping at this commit, and it is fixed in the next commit.
We could have avoid this transient issue, but I did not spend time to fix as it is just a leak in the event wrong EAL options are passed.
There were some little checkpatch issues I fixed (plus some spurious empty lines/spaces).
But I left the options definitions as is (wrt line length warning).
Wrt storing the cores as a fixed size cpuset, this storage is internal and we can change in the future (no ABI concern afaics).
Series applied.
Thanks Chengwen for the reviews on argparse.
Thanks Bruce, this was kind of an unexpected long road.
This is a nice cleanup and I like this auto magic option and the debug logs.
I have two questions which could be addressed in followup patches but seem more risky than what I touched, and require a new round of CI:
- are we missing a build check on RTE_MAX_LCORE < CPU_SETSIZE?
- should eal_clean_saved_args() be called in rte_eal_cleanup()?
And finally my dumb idea:
Do you think it would be feasible to extend this remapping mechanism for multi process?
I would like to start all processes with only the -R option (and each application has a dedicated cpu affinity, set by an external mechanism out of DPDK).
Then some exchanges between primary and secondary processes are done at init, with secondary announcing a number of lcores it needs, and the primary replying with a lcoreid base for remapping.
One problem is that it would require tracking life and death of the secondary processes to that primary can reallocate unused lcores ranges.
Signature · 1 line
David Marchand
Re: [PATCH v11 00/21]
Quoted 46 lines · David Marchand
Hello Bruce,
Quoted 35 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.
Quoted 6 lines
V11:
* fix issues flagged by unit tests in CI and subsequent testing:
- when passing in an lcore >=MAX_LCORES, return error rather than ignoring it. (compatibility issue)
- return error when an invalid lcore set of "1-3-5" is passed in, rather than just treating it as "3-5".
Quoted 10 lines
I did some tweaking on the series (and put my sob for taking the bullet if I broke something ;-)), namely:
- squashed the init arg list patch into the initial patch that introduceseal_option_list.h,
- inverted order of the patch on coremask rework with the one introducing lcore remapping,
- I updated patch 6 as Chengwen requested, and I fixed return codes forparse_arg_corelist(),
- I updated the doc for patch 8 as Chengwen requested,
Thanks for the rework.
Quoted 3 lines
I fixed a few reintroductions of socket-mem (should be numa-mem) in intermediate patches.
Are both not needing to be supported? With current implementation I think they are just aliases for another. [Though maybe I'm missunderstanding the rework here]
Quoted 10 lines
I noticed that the leak reported earlier on patch "eal: gather EAL args before processing" is still present when stopping at this commit, and it is fixed in the next commit.
We could have avoid this transient issue, but I did not spend time to fix as it is just a leak in the event wrong EAL options are passed.There were some little checkpatch issues I fixed (plus some spurious empty lines/spaces).
But I left the options definitions as is (wrt line length warning).
Thanks. I think the options are better kept one-per-line irrespective of checkpatch warnings.
Quoted 10 lines
Wrt storing the cores as a fixed size cpuset, this storage is internal and we can change in the future (no ABI concern afaics).
Series applied.
Thanks Chengwen for the reviews on argparse.
Thanks Bruce, this was kind of an unexpected long road.
This is a nice cleanup and I like this auto magic option and the debug logs.
Thanks. It was indeed a long road, and far more churn than expected, since I started out with only 5 or 7 patches in initial versions and ended up with over 20!
Quoted 4 lines
I have two questions which could be addressed in followup patches but seem more risky than what I touched, and require a new round of CI:
- are we missing a build check onRTE_MAX_LCORE<CPU_SETSIZE?
Maybe. However, I think be best way to fix that is as part of any cleanup work to eliminate any dependency on CPU_SETSIZE. That will probably be its own epic patchset!
Quoted 5 lines
- should
eal_clean_saved_args()be called inrte_eal_cleanup()?And finally my dumb idea:
Quoted 12 lines
Do you think it would be feasible to extend this remapping mechanism for multi process?
I would like to start all processes with only the -R option (and each application has a dedicated cpu affinity, set by an external mechanism out of DPDK).
Then some exchanges between primary and secondary processes are done at init, with secondary announcing a number of lcores it needs, and the primary replying with a lcoreid base for remapping.
One problem is that it would require tracking life and death of the secondary processes to that primary can reallocate unused lcores ranges.
I think that is a tough ask. I don't think I'll attempt to implement that. Having users of secondary processes manage each process own starting lcore id is probably not a massive ask.
Thanks again for all the reviews.
/Bruce