/* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) { int opt, ret; char **argvopt; int option_index; char *prgname = argv[0]; struct shared_driver *solib; argvopt = argv; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { int ret; /* getopt is not happy, stop right now */ if (opt == '?') { eal_usage(prgname); return -1; } ret = eal_parse_common_option(opt, optarg, &internal_config); /* common parser is not happy */ if (ret < 0) { eal_usage(prgname); return -1; } /* common parser handled this option */ if (ret == 0) continue; switch (opt) { case 'h': eal_usage(prgname); exit(EXIT_SUCCESS); /* force loading of external driver */ case 'd': solib = malloc(sizeof(*solib)); if (solib == NULL) { RTE_LOG(ERR, EAL, "malloc(solib) failed\n"); return -1; } memset(solib, 0, sizeof(*solib)); strncpy(solib->name, optarg, PATH_MAX-1); solib->name[PATH_MAX-1] = 0; TAILQ_INSERT_TAIL(&solib_list, solib, next); break; /* long options */ case OPT_XEN_DOM0_NUM: #ifdef RTE_LIBRTE_XEN_DOM0 internal_config.xen_dom0_support = 1; #else RTE_LOG(ERR, EAL, "Can't support DPDK app " "running on Dom0, please configure" " RTE_LIBRTE_XEN_DOM0=y\n"); return -1; #endif break; case OPT_HUGE_DIR_NUM: internal_config.hugepage_dir = optarg; break; case OPT_FILE_PREFIX_NUM: internal_config.hugefile_prefix = optarg; break; case OPT_SOCKET_MEM_NUM: if (eal_parse_socket_mem(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_SOCKET_MEM "\n"); eal_usage(prgname); return -1; } break; case OPT_BASE_VIRTADDR_NUM: if (eal_parse_base_virtaddr(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameter for --" OPT_BASE_VIRTADDR "\n"); eal_usage(prgname); return -1; } break; case OPT_VFIO_INTR_NUM: if (eal_parse_vfio_intr(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_VFIO_INTR "\n"); eal_usage(prgname); return -1; } break; case OPT_CREATE_UIO_DEV_NUM: internal_config.create_uio_dev = 1; break; default: if (opt < OPT_LONG_MIN_NUM && isprint(opt)) { RTE_LOG(ERR, EAL, "Option %c is not supported " "on Linux\n", opt); } else if (opt >= OPT_LONG_MIN_NUM && opt < OPT_LONG_MAX_NUM) { RTE_LOG(ERR, EAL, "Option %s is not supported " "on Linux\n", eal_long_options[option_index].name); } else { RTE_LOG(ERR, EAL, "Option %d is not supported " "on Linux\n", opt); } eal_usage(prgname); return -1; } } if (eal_adjust_config(&internal_config) != 0) return -1; /* sanity checks */ if (eal_check_common_options(&internal_config) != 0) { eal_usage(prgname); return -1; } /* --xen-dom0 doesn't make sense with --socket-mem */ if (internal_config.xen_dom0_support && internal_config.force_sockets == 1) { RTE_LOG(ERR, EAL, "Options --"OPT_SOCKET_MEM" cannot be specified " "together with --"OPT_XEN_DOM0"\n"); eal_usage(prgname); return -1; } if (optind >= 0) argv[optind-1] = prgname; ret = optind-1; optind = 0; /* reset getopt lib */ return ret; }
/* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) { int opt, ret, i; char **argvopt; int option_index; int coremask_ok = 0; char *prgname = argv[0]; static struct option lgopts[] = { {OPT_NO_HUGE, 0, 0, 0}, {OPT_NO_PCI, 0, 0, 0}, {OPT_NO_HPET, 0, 0, 0}, {OPT_VMWARE_TSC_MAP, 0, 0, 0}, {OPT_HUGE_DIR, 1, 0, 0}, {OPT_NO_SHCONF, 0, 0, 0}, {OPT_PROC_TYPE, 1, 0, 0}, {OPT_FILE_PREFIX, 1, 0, 0}, {OPT_SOCKET_MEM, 1, 0, 0}, {OPT_PCI_WHITELIST, 1, 0, 0}, {OPT_PCI_BLACKLIST, 1, 0, 0}, {OPT_VDEV, 1, 0, 0}, {OPT_SYSLOG, 1, NULL, 0}, {OPT_VFIO_INTR, 1, NULL, 0}, {OPT_BASE_VIRTADDR, 1, 0, 0}, {OPT_XEN_DOM0, 0, 0, 0}, {OPT_CREATE_UIO_DEV, 1, NULL, 0}, {0, 0, 0, 0} }; struct shared_driver *solib; argvopt = argv; internal_config.memory = 0; internal_config.force_nrank = 0; internal_config.force_nchannel = 0; internal_config.hugefile_prefix = HUGEFILE_PREFIX_DEFAULT; internal_config.hugepage_dir = NULL; internal_config.force_sockets = 0; internal_config.syslog_facility = LOG_DAEMON; internal_config.xen_dom0_support = 0; /* if set to NONE, interrupt mode is determined automatically */ internal_config.vfio_intr_mode = RTE_INTR_MODE_NONE; #ifdef RTE_LIBEAL_USE_HPET internal_config.no_hpet = 0; #else internal_config.no_hpet = 1; #endif /* zero out the NUMA config */ for (i = 0; i < RTE_MAX_NUMA_NODES; i++) internal_config.socket_mem[i] = 0; /* zero out hugedir descriptors */ for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) internal_config.hugepage_info[i].lock_descriptor = -1; internal_config.vmware_tsc_map = 0; internal_config.base_virtaddr = 0; while ((opt = getopt_long(argc, argvopt, "b:w:c:d:m:n:r:v", lgopts, &option_index)) != EOF) { switch (opt) { /* blacklist */ case 'b': if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI, optarg) < 0) { eal_usage(prgname); return (-1); } break; /* whitelist */ case 'w': if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, optarg) < 0) { eal_usage(prgname); return -1; } break; /* coremask */ case 'c': if (eal_parse_coremask(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid coremask\n"); eal_usage(prgname); return -1; } coremask_ok = 1; break; /* force loading of external driver */ case 'd': solib = malloc(sizeof(*solib)); if (solib == NULL) { RTE_LOG(ERR, EAL, "malloc(solib) failed\n"); return -1; } memset(solib, 0, sizeof(*solib)); strncpy(solib->name, optarg, PATH_MAX-1); solib->name[PATH_MAX-1] = 0; TAILQ_INSERT_TAIL(&solib_list, solib, next); break; /* size of memory */ case 'm': internal_config.memory = atoi(optarg); internal_config.memory *= 1024ULL; internal_config.memory *= 1024ULL; break; /* force number of channels */ case 'n': internal_config.force_nchannel = atoi(optarg); if (internal_config.force_nchannel == 0 || internal_config.force_nchannel > 4) { RTE_LOG(ERR, EAL, "invalid channel number\n"); eal_usage(prgname); return -1; } break; /* force number of ranks */ case 'r': internal_config.force_nrank = atoi(optarg); if (internal_config.force_nrank == 0 || internal_config.force_nrank > 16) { RTE_LOG(ERR, EAL, "invalid rank number\n"); eal_usage(prgname); 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 */ RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version()); break; /* long options */ case 0: if (!strcmp(lgopts[option_index].name, OPT_NO_HUGE)) { internal_config.no_hugetlbfs = 1; } if (!strcmp(lgopts[option_index].name, OPT_XEN_DOM0)) { #ifdef RTE_LIBRTE_XEN_DOM0 internal_config.xen_dom0_support = 1; #else RTE_LOG(ERR, EAL, "Can't support DPDK app " "running on Dom0, please configure" " RTE_LIBRTE_XEN_DOM0=y\n"); return -1; #endif } else if (!strcmp(lgopts[option_index].name, OPT_NO_PCI)) { internal_config.no_pci = 1; } else if (!strcmp(lgopts[option_index].name, OPT_NO_HPET)) { internal_config.no_hpet = 1; } else if (!strcmp(lgopts[option_index].name, OPT_VMWARE_TSC_MAP)) { internal_config.vmware_tsc_map = 1; } else if (!strcmp(lgopts[option_index].name, OPT_NO_SHCONF)) { internal_config.no_shconf = 1; } else if (!strcmp(lgopts[option_index].name, OPT_HUGE_DIR)) { internal_config.hugepage_dir = optarg; } else if (!strcmp(lgopts[option_index].name, OPT_PROC_TYPE)) { internal_config.process_type = eal_parse_proc_type(optarg); } else if (!strcmp(lgopts[option_index].name, OPT_FILE_PREFIX)) { internal_config.hugefile_prefix = optarg; } else if (!strcmp(lgopts[option_index].name, OPT_SOCKET_MEM)) { if (eal_parse_socket_mem(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_SOCKET_MEM "\n"); eal_usage(prgname); return -1; } } else if (!strcmp(lgopts[option_index].name, OPT_USE_DEVICE)) { printf("The --use-device option is deprecated, please use\n" "--whitelist or --vdev instead.\n"); eal_usage(prgname); return -1; } else if (!strcmp(lgopts[option_index].name, OPT_PCI_BLACKLIST)) { if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI, optarg) < 0) { eal_usage(prgname); return -1; } } else if (!strcmp(lgopts[option_index].name, OPT_PCI_WHITELIST)) { if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI, optarg) < 0) { eal_usage(prgname); return -1; } } else if (!strcmp(lgopts[option_index].name, OPT_VDEV)) { if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, optarg) < 0) { eal_usage(prgname); return -1; } } else if (!strcmp(lgopts[option_index].name, OPT_SYSLOG)) { if (eal_parse_syslog(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_SYSLOG "\n"); eal_usage(prgname); return -1; } } else if (!strcmp(lgopts[option_index].name, OPT_BASE_VIRTADDR)) { if (eal_parse_base_virtaddr(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameter for --" OPT_BASE_VIRTADDR "\n"); eal_usage(prgname); return -1; } } else if (!strcmp(lgopts[option_index].name, OPT_VFIO_INTR)) { if (eal_parse_vfio_intr(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_VFIO_INTR "\n"); eal_usage(prgname); return -1; } } else if (!strcmp(lgopts[option_index].name, OPT_CREATE_UIO_DEV)) { internal_config.create_uio_dev = 1; } break; default: eal_usage(prgname); return -1; } } /* sanity checks */ if (!coremask_ok) { RTE_LOG(ERR, EAL, "coremask not specified\n"); eal_usage(prgname); return -1; } if (internal_config.process_type == RTE_PROC_AUTO){ internal_config.process_type = eal_proc_type_detect(); } if (internal_config.process_type == RTE_PROC_INVALID){ RTE_LOG(ERR, EAL, "Invalid process type specified\n"); eal_usage(prgname); return -1; } if (internal_config.process_type == RTE_PROC_PRIMARY && internal_config.force_nchannel == 0) { RTE_LOG(ERR, EAL, "Number of memory channels (-n) not specified\n"); eal_usage(prgname); return -1; } if (index(internal_config.hugefile_prefix,'%') != NULL){ RTE_LOG(ERR, EAL, "Invalid char, '%%', in '"OPT_FILE_PREFIX"' option\n"); eal_usage(prgname); return -1; } if (internal_config.memory > 0 && internal_config.force_sockets == 1) { RTE_LOG(ERR, EAL, "Options -m and --socket-mem cannot be specified " "at the same time\n"); eal_usage(prgname); return -1; } /* --no-huge doesn't make sense with either -m or --socket-mem */ if (internal_config.no_hugetlbfs && (internal_config.memory > 0 || internal_config.force_sockets == 1)) { RTE_LOG(ERR, EAL, "Options -m or --socket-mem cannot be specified " "together with --no-huge!\n"); eal_usage(prgname); return -1; } /* --xen-dom0 doesn't make sense with --socket-mem */ if (internal_config.xen_dom0_support && internal_config.force_sockets == 1) { RTE_LOG(ERR, EAL, "Options --socket-mem cannot be specified " "together with --xen_dom0!\n"); eal_usage(prgname); return -1; } if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 && rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) { RTE_LOG(ERR, EAL, "Error: blacklist [-b] and whitelist " "[-w] options cannot be used at the same time\n"); eal_usage(prgname); return -1; } if (optind >= 0) argv[optind-1] = prgname; /* if no memory amounts were requested, this will result in 0 and * will be overriden later, right after eal_hugepage_info_init() */ for (i = 0; i < RTE_MAX_NUMA_NODES; i++) internal_config.memory += internal_config.socket_mem[i]; ret = optind-1; optind = 0; /* reset getopt lib */ return ret; }
/* Parse the argument given in the command line of the application */ static int eal_parse_args(int argc, char **argv) { int opt, ret; char **argvopt; int option_index; char *prgname = argv[0]; const int old_optind = optind; const int old_optopt = optopt; char * const old_optarg = optarg; argvopt = argv; optind = 1; while ((opt = getopt_long(argc, argvopt, eal_short_options, eal_long_options, &option_index)) != EOF) { /* getopt is not happy, stop right now */ if (opt == '?') { eal_usage(prgname); ret = -1; goto out; } ret = eal_parse_common_option(opt, optarg, &internal_config); /* common parser is not happy */ if (ret < 0) { eal_usage(prgname); ret = -1; goto out; } /* common parser handled this option */ if (ret == 0) continue; switch (opt) { case 'h': eal_usage(prgname); exit(EXIT_SUCCESS); /* long options */ case OPT_XEN_DOM0_NUM: #ifdef RTE_LIBRTE_XEN_DOM0 internal_config.xen_dom0_support = 1; #else RTE_LOG(ERR, EAL, "Can't support DPDK app " "running on Dom0, please configure" " RTE_LIBRTE_XEN_DOM0=y\n"); ret = -1; goto out; #endif break; case OPT_HUGE_DIR_NUM: internal_config.hugepage_dir = optarg; break; case OPT_FILE_PREFIX_NUM: internal_config.hugefile_prefix = optarg; break; case OPT_SOCKET_MEM_NUM: if (eal_parse_socket_mem(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_SOCKET_MEM "\n"); eal_usage(prgname); ret = -1; goto out; } break; case OPT_BASE_VIRTADDR_NUM: if (eal_parse_base_virtaddr(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameter for --" OPT_BASE_VIRTADDR "\n"); eal_usage(prgname); ret = -1; goto out; } break; case OPT_VFIO_INTR_NUM: if (eal_parse_vfio_intr(optarg) < 0) { RTE_LOG(ERR, EAL, "invalid parameters for --" OPT_VFIO_INTR "\n"); eal_usage(prgname); ret = -1; goto out; } break; case OPT_CREATE_UIO_DEV_NUM: internal_config.create_uio_dev = 1; break; default: if (opt < OPT_LONG_MIN_NUM && isprint(opt)) { RTE_LOG(ERR, EAL, "Option %c is not supported " "on Linux\n", opt); } else if (opt >= OPT_LONG_MIN_NUM && opt < OPT_LONG_MAX_NUM) { RTE_LOG(ERR, EAL, "Option %s is not supported " "on Linux\n", eal_long_options[option_index].name); } else { RTE_LOG(ERR, EAL, "Option %d is not supported " "on Linux\n", opt); } eal_usage(prgname); ret = -1; goto out; } } if (eal_adjust_config(&internal_config) != 0) { ret = -1; goto out; } /* sanity checks */ if (eal_check_common_options(&internal_config) != 0) { eal_usage(prgname); ret = -1; goto out; } /* --xen-dom0 doesn't make sense with --socket-mem */ if (internal_config.xen_dom0_support && internal_config.force_sockets == 1) { RTE_LOG(ERR, EAL, "Options --"OPT_SOCKET_MEM" cannot be specified " "together with --"OPT_XEN_DOM0"\n"); eal_usage(prgname); ret = -1; goto out; } if (optind >= 0) argv[optind-1] = prgname; ret = optind-1; out: /* restore getopt lib */ optind = old_optind; optopt = old_optopt; optarg = old_optarg; return ret; }