199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2010-2014 Intel Corporation. 399a2dd95SBruce Richardson * Copyright(c) 2014 6WIND S.A. 499a2dd95SBruce Richardson */ 599a2dd95SBruce Richardson 699a2dd95SBruce Richardson #include <stdlib.h> 799a2dd95SBruce Richardson #include <unistd.h> 899a2dd95SBruce Richardson #include <string.h> 999a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 1099a2dd95SBruce Richardson #include <syslog.h> 1199a2dd95SBruce Richardson #endif 1299a2dd95SBruce Richardson #include <ctype.h> 1399a2dd95SBruce Richardson #include <limits.h> 1499a2dd95SBruce Richardson #include <errno.h> 1599a2dd95SBruce Richardson #include <getopt.h> 1699a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 1799a2dd95SBruce Richardson #include <dlfcn.h> 1899a2dd95SBruce Richardson #include <libgen.h> 1999a2dd95SBruce Richardson #endif 2099a2dd95SBruce Richardson #include <sys/types.h> 2199a2dd95SBruce Richardson #include <sys/stat.h> 2299a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 2399a2dd95SBruce Richardson #include <dirent.h> 2499a2dd95SBruce Richardson #endif 2599a2dd95SBruce Richardson 2699a2dd95SBruce Richardson #include <rte_string_fns.h> 2799a2dd95SBruce Richardson #include <rte_eal.h> 2899a2dd95SBruce Richardson #include <rte_log.h> 2999a2dd95SBruce Richardson #include <rte_lcore.h> 3099a2dd95SBruce Richardson #include <rte_memory.h> 3199a2dd95SBruce Richardson #include <rte_tailq.h> 3299a2dd95SBruce Richardson #include <rte_version.h> 3399a2dd95SBruce Richardson #include <rte_devargs.h> 3499a2dd95SBruce Richardson #include <rte_memcpy.h> 3599a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 3699a2dd95SBruce Richardson #include <rte_telemetry.h> 3799a2dd95SBruce Richardson #endif 3899a2dd95SBruce Richardson #include <rte_vect.h> 3999a2dd95SBruce Richardson 4099a2dd95SBruce Richardson #include "eal_internal_cfg.h" 4199a2dd95SBruce Richardson #include "eal_options.h" 4299a2dd95SBruce Richardson #include "eal_filesystem.h" 4399a2dd95SBruce Richardson #include "eal_private.h" 4499a2dd95SBruce Richardson #include "eal_log.h" 4599a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 4699a2dd95SBruce Richardson #include "eal_trace.h" 4799a2dd95SBruce Richardson #endif 4899a2dd95SBruce Richardson 4999a2dd95SBruce Richardson #define BITS_PER_HEX 4 5099a2dd95SBruce Richardson #define LCORE_OPT_LST 1 5199a2dd95SBruce Richardson #define LCORE_OPT_MSK 2 5299a2dd95SBruce Richardson #define LCORE_OPT_MAP 3 5399a2dd95SBruce Richardson 5499a2dd95SBruce Richardson const char 5599a2dd95SBruce Richardson eal_short_options[] = 5699a2dd95SBruce Richardson "a:" /* allow */ 5799a2dd95SBruce Richardson "b:" /* block */ 5899a2dd95SBruce Richardson "c:" /* coremask */ 5999a2dd95SBruce Richardson "s:" /* service coremask */ 6099a2dd95SBruce Richardson "d:" /* driver */ 6199a2dd95SBruce Richardson "h" /* help */ 6299a2dd95SBruce Richardson "l:" /* corelist */ 6399a2dd95SBruce Richardson "S:" /* service corelist */ 6499a2dd95SBruce Richardson "m:" /* memory size */ 6599a2dd95SBruce Richardson "n:" /* memory channels */ 6699a2dd95SBruce Richardson "r:" /* memory ranks */ 6799a2dd95SBruce Richardson "v" /* version */ 6899a2dd95SBruce Richardson "w:" /* pci-whitelist (deprecated) */ 6999a2dd95SBruce Richardson ; 7099a2dd95SBruce Richardson 7199a2dd95SBruce Richardson const struct option 7299a2dd95SBruce Richardson eal_long_options[] = { 7399a2dd95SBruce Richardson {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM }, 7499a2dd95SBruce Richardson {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM }, 7599a2dd95SBruce Richardson {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM }, 7699a2dd95SBruce Richardson {OPT_HELP, 0, NULL, OPT_HELP_NUM }, 7799a2dd95SBruce Richardson {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM }, 7899a2dd95SBruce Richardson {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM }, 7999a2dd95SBruce Richardson {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, 8099a2dd95SBruce Richardson {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, 8199a2dd95SBruce Richardson {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, 8299a2dd95SBruce Richardson {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, 8399a2dd95SBruce Richardson {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, 8499a2dd95SBruce Richardson {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, 8599a2dd95SBruce Richardson {OPT_TRACE_MODE, 1, NULL, OPT_TRACE_MODE_NUM }, 8699a2dd95SBruce Richardson {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM }, 8799a2dd95SBruce Richardson {OPT_MAIN_LCORE, 1, NULL, OPT_MAIN_LCORE_NUM }, 8899a2dd95SBruce Richardson {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM}, 8999a2dd95SBruce Richardson {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM }, 9099a2dd95SBruce Richardson {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM }, 9199a2dd95SBruce Richardson {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM }, 9299a2dd95SBruce Richardson {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM }, 9399a2dd95SBruce Richardson {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM }, 9499a2dd95SBruce Richardson {OPT_DEV_BLOCK, 1, NULL, OPT_DEV_BLOCK_NUM }, 9599a2dd95SBruce Richardson {OPT_DEV_ALLOW, 1, NULL, OPT_DEV_ALLOW_NUM }, 9699a2dd95SBruce Richardson {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM }, 9799a2dd95SBruce Richardson {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM }, 9899a2dd95SBruce Richardson {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM }, 9999a2dd95SBruce Richardson {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM }, 10099a2dd95SBruce Richardson {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, 10199a2dd95SBruce Richardson {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, 10299a2dd95SBruce Richardson {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM }, 10399a2dd95SBruce Richardson {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM }, 10499a2dd95SBruce Richardson {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM }, 10599a2dd95SBruce Richardson {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM}, 10699a2dd95SBruce Richardson {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM}, 10799a2dd95SBruce Richardson {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, 10899a2dd95SBruce Richardson {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, 10999a2dd95SBruce Richardson {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, 11099a2dd95SBruce Richardson 11199a2dd95SBruce Richardson /* legacy options that will be removed in future */ 11299a2dd95SBruce Richardson {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM }, 11399a2dd95SBruce Richardson {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM }, 11499a2dd95SBruce Richardson 11599a2dd95SBruce Richardson {0, 0, NULL, 0 } 11699a2dd95SBruce Richardson }; 11799a2dd95SBruce Richardson 11899a2dd95SBruce Richardson TAILQ_HEAD(shared_driver_list, shared_driver); 11999a2dd95SBruce Richardson 12099a2dd95SBruce Richardson /* Definition for shared object drivers. */ 12199a2dd95SBruce Richardson struct shared_driver { 12299a2dd95SBruce Richardson TAILQ_ENTRY(shared_driver) next; 12399a2dd95SBruce Richardson 12499a2dd95SBruce Richardson char name[PATH_MAX]; 12599a2dd95SBruce Richardson void* lib_handle; 12699a2dd95SBruce Richardson }; 12799a2dd95SBruce Richardson 12899a2dd95SBruce Richardson /* List of external loadable drivers */ 12999a2dd95SBruce Richardson static struct shared_driver_list solib_list = 13099a2dd95SBruce Richardson TAILQ_HEAD_INITIALIZER(solib_list); 13199a2dd95SBruce Richardson 13299a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 13399a2dd95SBruce Richardson /* Default path of external loadable drivers */ 13499a2dd95SBruce Richardson static const char *default_solib_dir = RTE_EAL_PMD_PATH; 13599a2dd95SBruce Richardson #endif 13699a2dd95SBruce Richardson 13799a2dd95SBruce Richardson /* 13899a2dd95SBruce Richardson * Stringified version of solib path used by dpdk-pmdinfo.py 13999a2dd95SBruce Richardson * Note: PLEASE DO NOT ALTER THIS without making a corresponding 14099a2dd95SBruce Richardson * change to usertools/dpdk-pmdinfo.py 14199a2dd95SBruce Richardson */ 14299a2dd95SBruce Richardson static const char dpdk_solib_path[] __rte_used = 14399a2dd95SBruce Richardson "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH; 14499a2dd95SBruce Richardson 14599a2dd95SBruce Richardson TAILQ_HEAD(device_option_list, device_option); 14699a2dd95SBruce Richardson 14799a2dd95SBruce Richardson struct device_option { 14899a2dd95SBruce Richardson TAILQ_ENTRY(device_option) next; 14999a2dd95SBruce Richardson 15099a2dd95SBruce Richardson enum rte_devtype type; 15199a2dd95SBruce Richardson char arg[]; 15299a2dd95SBruce Richardson }; 15399a2dd95SBruce Richardson 15499a2dd95SBruce Richardson static struct device_option_list devopt_list = 15599a2dd95SBruce Richardson TAILQ_HEAD_INITIALIZER(devopt_list); 15699a2dd95SBruce Richardson 15799a2dd95SBruce Richardson static int main_lcore_parsed; 15899a2dd95SBruce Richardson static int mem_parsed; 15999a2dd95SBruce Richardson static int core_parsed; 16099a2dd95SBruce Richardson 16199a2dd95SBruce Richardson /* Allow the application to print its usage message too if set */ 16299a2dd95SBruce Richardson static rte_usage_hook_t rte_application_usage_hook; 16399a2dd95SBruce Richardson 16499a2dd95SBruce Richardson /* Returns rte_usage_hook_t */ 16599a2dd95SBruce Richardson rte_usage_hook_t 16699a2dd95SBruce Richardson eal_get_application_usage_hook(void) 16799a2dd95SBruce Richardson { 16899a2dd95SBruce Richardson return rte_application_usage_hook; 16999a2dd95SBruce Richardson } 17099a2dd95SBruce Richardson 17199a2dd95SBruce Richardson /* Set a per-application usage message */ 17299a2dd95SBruce Richardson rte_usage_hook_t 17399a2dd95SBruce Richardson rte_set_application_usage_hook(rte_usage_hook_t usage_func) 17499a2dd95SBruce Richardson { 17599a2dd95SBruce Richardson rte_usage_hook_t old_func; 17699a2dd95SBruce Richardson 17799a2dd95SBruce Richardson /* Will be NULL on the first call to denote the last usage routine. */ 17899a2dd95SBruce Richardson old_func = rte_application_usage_hook; 17999a2dd95SBruce Richardson rte_application_usage_hook = usage_func; 18099a2dd95SBruce Richardson 18199a2dd95SBruce Richardson return old_func; 18299a2dd95SBruce Richardson } 18399a2dd95SBruce Richardson 18499a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 18599a2dd95SBruce Richardson static char **eal_args; 18699a2dd95SBruce Richardson static char **eal_app_args; 18799a2dd95SBruce Richardson 18899a2dd95SBruce Richardson #define EAL_PARAM_REQ "/eal/params" 18999a2dd95SBruce Richardson #define EAL_APP_PARAM_REQ "/eal/app_params" 19099a2dd95SBruce Richardson 19199a2dd95SBruce Richardson /* callback handler for telemetry library to report out EAL flags */ 19299a2dd95SBruce Richardson int 19399a2dd95SBruce Richardson handle_eal_info_request(const char *cmd, const char *params __rte_unused, 19499a2dd95SBruce Richardson struct rte_tel_data *d) 19599a2dd95SBruce Richardson { 19699a2dd95SBruce Richardson char **args; 19799a2dd95SBruce Richardson int used = 0; 19899a2dd95SBruce Richardson int i = 0; 19999a2dd95SBruce Richardson 20099a2dd95SBruce Richardson if (strcmp(cmd, EAL_PARAM_REQ) == 0) 20199a2dd95SBruce Richardson args = eal_args; 20299a2dd95SBruce Richardson else 20399a2dd95SBruce Richardson args = eal_app_args; 20499a2dd95SBruce Richardson 20599a2dd95SBruce Richardson rte_tel_data_start_array(d, RTE_TEL_STRING_VAL); 20699a2dd95SBruce Richardson if (args == NULL || args[0] == NULL) 20799a2dd95SBruce Richardson return 0; 20899a2dd95SBruce Richardson 20999a2dd95SBruce Richardson for ( ; args[i] != NULL; i++) 21099a2dd95SBruce Richardson used = rte_tel_data_add_array_string(d, args[i]); 21199a2dd95SBruce Richardson return used; 21299a2dd95SBruce Richardson } 21399a2dd95SBruce Richardson 21499a2dd95SBruce Richardson int 21599a2dd95SBruce Richardson eal_save_args(int argc, char **argv) 21699a2dd95SBruce Richardson { 21799a2dd95SBruce Richardson int i, j; 21899a2dd95SBruce Richardson 21999a2dd95SBruce Richardson rte_telemetry_register_cmd(EAL_PARAM_REQ, handle_eal_info_request, 22099a2dd95SBruce Richardson "Returns EAL commandline parameters used. Takes no parameters"); 22199a2dd95SBruce Richardson rte_telemetry_register_cmd(EAL_APP_PARAM_REQ, handle_eal_info_request, 22299a2dd95SBruce Richardson "Returns app commandline parameters used. Takes no parameters"); 22399a2dd95SBruce Richardson 22499a2dd95SBruce Richardson /* clone argv to report out later. We overprovision, but 22599a2dd95SBruce Richardson * this does not waste huge amounts of memory 22699a2dd95SBruce Richardson */ 22799a2dd95SBruce Richardson eal_args = calloc(argc + 1, sizeof(*eal_args)); 22899a2dd95SBruce Richardson if (eal_args == NULL) 22999a2dd95SBruce Richardson return -1; 23099a2dd95SBruce Richardson 23199a2dd95SBruce Richardson for (i = 0; i < argc; i++) { 23299a2dd95SBruce Richardson eal_args[i] = strdup(argv[i]); 23399a2dd95SBruce Richardson if (strcmp(argv[i], "--") == 0) 23499a2dd95SBruce Richardson break; 23599a2dd95SBruce Richardson } 23699a2dd95SBruce Richardson eal_args[i++] = NULL; /* always finish with NULL */ 23799a2dd95SBruce Richardson 23899a2dd95SBruce Richardson /* allow reporting of any app args we know about too */ 23999a2dd95SBruce Richardson if (i >= argc) 24099a2dd95SBruce Richardson return 0; 24199a2dd95SBruce Richardson 24299a2dd95SBruce Richardson eal_app_args = calloc(argc - i + 1, sizeof(*eal_args)); 24399a2dd95SBruce Richardson if (eal_app_args == NULL) 24499a2dd95SBruce Richardson return -1; 24599a2dd95SBruce Richardson 24699a2dd95SBruce Richardson for (j = 0; i < argc; j++, i++) 24799a2dd95SBruce Richardson eal_app_args[j] = strdup(argv[i]); 24899a2dd95SBruce Richardson eal_app_args[j] = NULL; 24999a2dd95SBruce Richardson 25099a2dd95SBruce Richardson return 0; 25199a2dd95SBruce Richardson } 25299a2dd95SBruce Richardson #endif 25399a2dd95SBruce Richardson 25499a2dd95SBruce Richardson static int 25599a2dd95SBruce Richardson eal_option_device_add(enum rte_devtype type, const char *optarg) 25699a2dd95SBruce Richardson { 25799a2dd95SBruce Richardson struct device_option *devopt; 25899a2dd95SBruce Richardson size_t optlen; 25999a2dd95SBruce Richardson int ret; 26099a2dd95SBruce Richardson 26199a2dd95SBruce Richardson optlen = strlen(optarg) + 1; 26299a2dd95SBruce Richardson devopt = calloc(1, sizeof(*devopt) + optlen); 26399a2dd95SBruce Richardson if (devopt == NULL) { 26499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Unable to allocate device option\n"); 26599a2dd95SBruce Richardson return -ENOMEM; 26699a2dd95SBruce Richardson } 26799a2dd95SBruce Richardson 26899a2dd95SBruce Richardson devopt->type = type; 26999a2dd95SBruce Richardson ret = strlcpy(devopt->arg, optarg, optlen); 27099a2dd95SBruce Richardson if (ret < 0) { 27199a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Unable to copy device option\n"); 27299a2dd95SBruce Richardson free(devopt); 27399a2dd95SBruce Richardson return -EINVAL; 27499a2dd95SBruce Richardson } 27599a2dd95SBruce Richardson TAILQ_INSERT_TAIL(&devopt_list, devopt, next); 27699a2dd95SBruce Richardson return 0; 27799a2dd95SBruce Richardson } 27899a2dd95SBruce Richardson 27999a2dd95SBruce Richardson int 28099a2dd95SBruce Richardson eal_option_device_parse(void) 28199a2dd95SBruce Richardson { 28299a2dd95SBruce Richardson struct device_option *devopt; 28399a2dd95SBruce Richardson void *tmp; 28499a2dd95SBruce Richardson int ret = 0; 28599a2dd95SBruce Richardson 28699a2dd95SBruce Richardson TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) { 28799a2dd95SBruce Richardson if (ret == 0) { 28899a2dd95SBruce Richardson ret = rte_devargs_add(devopt->type, devopt->arg); 28999a2dd95SBruce Richardson if (ret) 29099a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n", 29199a2dd95SBruce Richardson devopt->arg); 29299a2dd95SBruce Richardson } 29399a2dd95SBruce Richardson TAILQ_REMOVE(&devopt_list, devopt, next); 29499a2dd95SBruce Richardson free(devopt); 29599a2dd95SBruce Richardson } 29699a2dd95SBruce Richardson return ret; 29799a2dd95SBruce Richardson } 29899a2dd95SBruce Richardson 29999a2dd95SBruce Richardson const char * 30099a2dd95SBruce Richardson eal_get_hugefile_prefix(void) 30199a2dd95SBruce Richardson { 30299a2dd95SBruce Richardson const struct internal_config *internal_conf = 30399a2dd95SBruce Richardson eal_get_internal_configuration(); 30499a2dd95SBruce Richardson 30599a2dd95SBruce Richardson if (internal_conf->hugefile_prefix != NULL) 30699a2dd95SBruce Richardson return internal_conf->hugefile_prefix; 30799a2dd95SBruce Richardson return HUGEFILE_PREFIX_DEFAULT; 30899a2dd95SBruce Richardson } 30999a2dd95SBruce Richardson 31099a2dd95SBruce Richardson void 31199a2dd95SBruce Richardson eal_reset_internal_config(struct internal_config *internal_cfg) 31299a2dd95SBruce Richardson { 31399a2dd95SBruce Richardson int i; 31499a2dd95SBruce Richardson 31599a2dd95SBruce Richardson internal_cfg->memory = 0; 31699a2dd95SBruce Richardson internal_cfg->force_nrank = 0; 31799a2dd95SBruce Richardson internal_cfg->force_nchannel = 0; 31899a2dd95SBruce Richardson internal_cfg->hugefile_prefix = NULL; 31999a2dd95SBruce Richardson internal_cfg->hugepage_dir = NULL; 32099a2dd95SBruce Richardson internal_cfg->force_sockets = 0; 32199a2dd95SBruce Richardson /* zero out the NUMA config */ 32299a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_NUMA_NODES; i++) 32399a2dd95SBruce Richardson internal_cfg->socket_mem[i] = 0; 32499a2dd95SBruce Richardson internal_cfg->force_socket_limits = 0; 32599a2dd95SBruce Richardson /* zero out the NUMA limits config */ 32699a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_NUMA_NODES; i++) 32799a2dd95SBruce Richardson internal_cfg->socket_limit[i] = 0; 32899a2dd95SBruce Richardson /* zero out hugedir descriptors */ 32999a2dd95SBruce Richardson for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) { 33099a2dd95SBruce Richardson memset(&internal_cfg->hugepage_info[i], 0, 33199a2dd95SBruce Richardson sizeof(internal_cfg->hugepage_info[0])); 33299a2dd95SBruce Richardson internal_cfg->hugepage_info[i].lock_descriptor = -1; 33399a2dd95SBruce Richardson } 33499a2dd95SBruce Richardson internal_cfg->base_virtaddr = 0; 33599a2dd95SBruce Richardson 33699a2dd95SBruce Richardson #ifdef LOG_DAEMON 33799a2dd95SBruce Richardson internal_cfg->syslog_facility = LOG_DAEMON; 33899a2dd95SBruce Richardson #endif 33999a2dd95SBruce Richardson 34099a2dd95SBruce Richardson /* if set to NONE, interrupt mode is determined automatically */ 34199a2dd95SBruce Richardson internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE; 34299a2dd95SBruce Richardson memset(internal_cfg->vfio_vf_token, 0, 34399a2dd95SBruce Richardson sizeof(internal_cfg->vfio_vf_token)); 34499a2dd95SBruce Richardson 34599a2dd95SBruce Richardson #ifdef RTE_LIBEAL_USE_HPET 34699a2dd95SBruce Richardson internal_cfg->no_hpet = 0; 34799a2dd95SBruce Richardson #else 34899a2dd95SBruce Richardson internal_cfg->no_hpet = 1; 34999a2dd95SBruce Richardson #endif 35099a2dd95SBruce Richardson internal_cfg->vmware_tsc_map = 0; 35199a2dd95SBruce Richardson internal_cfg->create_uio_dev = 0; 35299a2dd95SBruce Richardson internal_cfg->iova_mode = RTE_IOVA_DC; 35399a2dd95SBruce Richardson internal_cfg->user_mbuf_pool_ops_name = NULL; 35499a2dd95SBruce Richardson CPU_ZERO(&internal_cfg->ctrl_cpuset); 35599a2dd95SBruce Richardson internal_cfg->init_complete = 0; 35699a2dd95SBruce Richardson internal_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH; 35799a2dd95SBruce Richardson internal_cfg->max_simd_bitwidth.forced = 0; 35899a2dd95SBruce Richardson } 35999a2dd95SBruce Richardson 36099a2dd95SBruce Richardson static int 36199a2dd95SBruce Richardson eal_plugin_add(const char *path) 36299a2dd95SBruce Richardson { 36399a2dd95SBruce Richardson struct shared_driver *solib; 36499a2dd95SBruce Richardson 36599a2dd95SBruce Richardson solib = malloc(sizeof(*solib)); 36699a2dd95SBruce Richardson if (solib == NULL) { 36799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "malloc(solib) failed\n"); 36899a2dd95SBruce Richardson return -1; 36999a2dd95SBruce Richardson } 37099a2dd95SBruce Richardson memset(solib, 0, sizeof(*solib)); 37199a2dd95SBruce Richardson strlcpy(solib->name, path, PATH_MAX); 37299a2dd95SBruce Richardson TAILQ_INSERT_TAIL(&solib_list, solib, next); 37399a2dd95SBruce Richardson 37499a2dd95SBruce Richardson return 0; 37599a2dd95SBruce Richardson } 37699a2dd95SBruce Richardson 37799a2dd95SBruce Richardson #ifdef RTE_EXEC_ENV_WINDOWS 37899a2dd95SBruce Richardson int 37999a2dd95SBruce Richardson eal_plugins_init(void) 38099a2dd95SBruce Richardson { 38199a2dd95SBruce Richardson return 0; 38299a2dd95SBruce Richardson } 38399a2dd95SBruce Richardson #else 38499a2dd95SBruce Richardson 38599a2dd95SBruce Richardson static int 38699a2dd95SBruce Richardson eal_plugindir_init(const char *path) 38799a2dd95SBruce Richardson { 38899a2dd95SBruce Richardson DIR *d = NULL; 38999a2dd95SBruce Richardson struct dirent *dent = NULL; 39099a2dd95SBruce Richardson char sopath[PATH_MAX]; 39199a2dd95SBruce Richardson 39299a2dd95SBruce Richardson if (path == NULL || *path == '\0') 39399a2dd95SBruce Richardson return 0; 39499a2dd95SBruce Richardson 39599a2dd95SBruce Richardson d = opendir(path); 39699a2dd95SBruce Richardson if (d == NULL) { 39799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n", 39899a2dd95SBruce Richardson path, strerror(errno)); 39999a2dd95SBruce Richardson return -1; 40099a2dd95SBruce Richardson } 40199a2dd95SBruce Richardson 40299a2dd95SBruce Richardson while ((dent = readdir(d)) != NULL) { 40399a2dd95SBruce Richardson struct stat sb; 40499a2dd95SBruce Richardson int nlen = strnlen(dent->d_name, sizeof(dent->d_name)); 40599a2dd95SBruce Richardson 40699a2dd95SBruce Richardson /* check if name ends in .so or .so.ABI_VERSION */ 40799a2dd95SBruce Richardson if (strcmp(&dent->d_name[nlen - 3], ".so") != 0 && 40899a2dd95SBruce Richardson strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)], 40999a2dd95SBruce Richardson ".so."ABI_VERSION) != 0) 41099a2dd95SBruce Richardson continue; 41199a2dd95SBruce Richardson 41299a2dd95SBruce Richardson snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name); 41399a2dd95SBruce Richardson 41499a2dd95SBruce Richardson /* if a regular file, add to list to load */ 41599a2dd95SBruce Richardson if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode))) 41699a2dd95SBruce Richardson continue; 41799a2dd95SBruce Richardson 41899a2dd95SBruce Richardson if (eal_plugin_add(sopath) == -1) 41999a2dd95SBruce Richardson break; 42099a2dd95SBruce Richardson } 42199a2dd95SBruce Richardson 42299a2dd95SBruce Richardson closedir(d); 42399a2dd95SBruce Richardson /* XXX this ignores failures from readdir() itself */ 42499a2dd95SBruce Richardson return (dent == NULL) ? 0 : -1; 42599a2dd95SBruce Richardson } 42699a2dd95SBruce Richardson 42799a2dd95SBruce Richardson static int 42899a2dd95SBruce Richardson verify_perms(const char *dirpath) 42999a2dd95SBruce Richardson { 43099a2dd95SBruce Richardson struct stat st; 43199a2dd95SBruce Richardson 43299a2dd95SBruce Richardson /* if not root, check down one level first */ 43399a2dd95SBruce Richardson if (strcmp(dirpath, "/") != 0) { 43499a2dd95SBruce Richardson static __thread char last_dir_checked[PATH_MAX]; 43599a2dd95SBruce Richardson char copy[PATH_MAX]; 43699a2dd95SBruce Richardson const char *dir; 43799a2dd95SBruce Richardson 43899a2dd95SBruce Richardson strlcpy(copy, dirpath, PATH_MAX); 43999a2dd95SBruce Richardson dir = dirname(copy); 44099a2dd95SBruce Richardson if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) { 44199a2dd95SBruce Richardson if (verify_perms(dir) != 0) 44299a2dd95SBruce Richardson return -1; 44399a2dd95SBruce Richardson strlcpy(last_dir_checked, dir, PATH_MAX); 44499a2dd95SBruce Richardson } 44599a2dd95SBruce Richardson } 44699a2dd95SBruce Richardson 44799a2dd95SBruce Richardson /* call stat to check for permissions and ensure not world writable */ 44899a2dd95SBruce Richardson if (stat(dirpath, &st) != 0) { 44999a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Error with stat on %s, %s\n", 45099a2dd95SBruce Richardson dirpath, strerror(errno)); 45199a2dd95SBruce Richardson return -1; 45299a2dd95SBruce Richardson } 45399a2dd95SBruce Richardson if (st.st_mode & S_IWOTH) { 45499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 45599a2dd95SBruce Richardson "Error, directory path %s is world-writable and insecure\n", 45699a2dd95SBruce Richardson dirpath); 45799a2dd95SBruce Richardson return -1; 45899a2dd95SBruce Richardson } 45999a2dd95SBruce Richardson 46099a2dd95SBruce Richardson return 0; 46199a2dd95SBruce Richardson } 46299a2dd95SBruce Richardson 46399a2dd95SBruce Richardson static void * 46499a2dd95SBruce Richardson eal_dlopen(const char *pathname) 46599a2dd95SBruce Richardson { 46699a2dd95SBruce Richardson void *retval = NULL; 46799a2dd95SBruce Richardson char *realp = realpath(pathname, NULL); 46899a2dd95SBruce Richardson 46999a2dd95SBruce Richardson if (realp == NULL && errno == ENOENT) { 47099a2dd95SBruce Richardson /* not a full or relative path, try a load from system dirs */ 47199a2dd95SBruce Richardson retval = dlopen(pathname, RTLD_NOW); 47299a2dd95SBruce Richardson if (retval == NULL) 47399a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "%s\n", dlerror()); 47499a2dd95SBruce Richardson return retval; 47599a2dd95SBruce Richardson } 47699a2dd95SBruce Richardson if (realp == NULL) { 47799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Error with realpath for %s, %s\n", 47899a2dd95SBruce Richardson pathname, strerror(errno)); 47999a2dd95SBruce Richardson goto out; 48099a2dd95SBruce Richardson } 48199a2dd95SBruce Richardson if (strnlen(realp, PATH_MAX) == PATH_MAX) { 48299a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n"); 48399a2dd95SBruce Richardson goto out; 48499a2dd95SBruce Richardson } 48599a2dd95SBruce Richardson 48699a2dd95SBruce Richardson /* do permissions checks */ 48799a2dd95SBruce Richardson if (verify_perms(realp) != 0) 48899a2dd95SBruce Richardson goto out; 48999a2dd95SBruce Richardson 49099a2dd95SBruce Richardson retval = dlopen(realp, RTLD_NOW); 49199a2dd95SBruce Richardson if (retval == NULL) 49299a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "%s\n", dlerror()); 49399a2dd95SBruce Richardson out: 49499a2dd95SBruce Richardson free(realp); 49599a2dd95SBruce Richardson return retval; 49699a2dd95SBruce Richardson } 49799a2dd95SBruce Richardson 49899a2dd95SBruce Richardson static int 49999a2dd95SBruce Richardson is_shared_build(void) 50099a2dd95SBruce Richardson { 50199a2dd95SBruce Richardson #define EAL_SO "librte_eal.so" 50299a2dd95SBruce Richardson char soname[32]; 50399a2dd95SBruce Richardson size_t len, minlen = strlen(EAL_SO); 50499a2dd95SBruce Richardson 50599a2dd95SBruce Richardson len = strlcpy(soname, EAL_SO"."ABI_VERSION, sizeof(soname)); 50699a2dd95SBruce Richardson if (len > sizeof(soname)) { 50799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Shared lib name too long in shared build check\n"); 50899a2dd95SBruce Richardson len = sizeof(soname) - 1; 50999a2dd95SBruce Richardson } 51099a2dd95SBruce Richardson 51199a2dd95SBruce Richardson while (len >= minlen) { 512*b81bf1efSDavid Marchand void *handle; 513*b81bf1efSDavid Marchand 51499a2dd95SBruce Richardson /* check if we have this .so loaded, if so - shared build */ 51599a2dd95SBruce Richardson RTE_LOG(DEBUG, EAL, "Checking presence of .so '%s'\n", soname); 516*b81bf1efSDavid Marchand handle = dlopen(soname, RTLD_LAZY | RTLD_NOLOAD); 517*b81bf1efSDavid Marchand if (handle != NULL) { 51899a2dd95SBruce Richardson RTE_LOG(INFO, EAL, "Detected shared linkage of DPDK\n"); 519*b81bf1efSDavid Marchand dlclose(handle); 52099a2dd95SBruce Richardson return 1; 52199a2dd95SBruce Richardson } 52299a2dd95SBruce Richardson 52399a2dd95SBruce Richardson /* remove any version numbers off the end to retry */ 52499a2dd95SBruce Richardson while (len-- > 0) 52599a2dd95SBruce Richardson if (soname[len] == '.') { 52699a2dd95SBruce Richardson soname[len] = '\0'; 52799a2dd95SBruce Richardson break; 52899a2dd95SBruce Richardson } 52999a2dd95SBruce Richardson } 53099a2dd95SBruce Richardson 53199a2dd95SBruce Richardson RTE_LOG(INFO, EAL, "Detected static linkage of DPDK\n"); 53299a2dd95SBruce Richardson return 0; 53399a2dd95SBruce Richardson } 53499a2dd95SBruce Richardson 53599a2dd95SBruce Richardson int 53699a2dd95SBruce Richardson eal_plugins_init(void) 53799a2dd95SBruce Richardson { 53899a2dd95SBruce Richardson struct shared_driver *solib = NULL; 53999a2dd95SBruce Richardson struct stat sb; 54099a2dd95SBruce Richardson 54199a2dd95SBruce Richardson /* If we are not statically linked, add default driver loading 54299a2dd95SBruce Richardson * path if it exists as a directory. 54399a2dd95SBruce Richardson * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL 54499a2dd95SBruce Richardson * shared library is not already loaded i.e. it's statically linked.) 54599a2dd95SBruce Richardson */ 54699a2dd95SBruce Richardson if (is_shared_build() && 54799a2dd95SBruce Richardson *default_solib_dir != '\0' && 54899a2dd95SBruce Richardson stat(default_solib_dir, &sb) == 0 && 54999a2dd95SBruce Richardson S_ISDIR(sb.st_mode)) 55099a2dd95SBruce Richardson eal_plugin_add(default_solib_dir); 55199a2dd95SBruce Richardson 55299a2dd95SBruce Richardson TAILQ_FOREACH(solib, &solib_list, next) { 55399a2dd95SBruce Richardson 55499a2dd95SBruce Richardson if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) { 55599a2dd95SBruce Richardson if (eal_plugindir_init(solib->name) == -1) { 55699a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 55799a2dd95SBruce Richardson "Cannot init plugin directory %s\n", 55899a2dd95SBruce Richardson solib->name); 55999a2dd95SBruce Richardson return -1; 56099a2dd95SBruce Richardson } 56199a2dd95SBruce Richardson } else { 56299a2dd95SBruce Richardson RTE_LOG(DEBUG, EAL, "open shared lib %s\n", 56399a2dd95SBruce Richardson solib->name); 56499a2dd95SBruce Richardson solib->lib_handle = eal_dlopen(solib->name); 56599a2dd95SBruce Richardson if (solib->lib_handle == NULL) 56699a2dd95SBruce Richardson return -1; 56799a2dd95SBruce Richardson } 56899a2dd95SBruce Richardson 56999a2dd95SBruce Richardson } 57099a2dd95SBruce Richardson return 0; 57199a2dd95SBruce Richardson } 57299a2dd95SBruce Richardson #endif 57399a2dd95SBruce Richardson 57499a2dd95SBruce Richardson /* 57599a2dd95SBruce Richardson * Parse the coremask given as argument (hexadecimal string) and fill 57699a2dd95SBruce Richardson * the global configuration (core role and core count) with the parsed 57799a2dd95SBruce Richardson * value. 57899a2dd95SBruce Richardson */ 57999a2dd95SBruce Richardson static int xdigit2val(unsigned char c) 58099a2dd95SBruce Richardson { 58199a2dd95SBruce Richardson int val; 58299a2dd95SBruce Richardson 58399a2dd95SBruce Richardson if (isdigit(c)) 58499a2dd95SBruce Richardson val = c - '0'; 58599a2dd95SBruce Richardson else if (isupper(c)) 58699a2dd95SBruce Richardson val = c - 'A' + 10; 58799a2dd95SBruce Richardson else 58899a2dd95SBruce Richardson val = c - 'a' + 10; 58999a2dd95SBruce Richardson return val; 59099a2dd95SBruce Richardson } 59199a2dd95SBruce Richardson 59299a2dd95SBruce Richardson static int 59399a2dd95SBruce Richardson eal_parse_service_coremask(const char *coremask) 59499a2dd95SBruce Richardson { 59599a2dd95SBruce Richardson struct rte_config *cfg = rte_eal_get_configuration(); 59699a2dd95SBruce Richardson int i, j, idx = 0; 59799a2dd95SBruce Richardson unsigned int count = 0; 59899a2dd95SBruce Richardson char c; 59999a2dd95SBruce Richardson int val; 60099a2dd95SBruce Richardson uint32_t taken_lcore_count = 0; 60199a2dd95SBruce Richardson 60299a2dd95SBruce Richardson if (coremask == NULL) 60399a2dd95SBruce Richardson return -1; 60499a2dd95SBruce Richardson /* Remove all blank characters ahead and after . 60599a2dd95SBruce Richardson * Remove 0x/0X if exists. 60699a2dd95SBruce Richardson */ 60799a2dd95SBruce Richardson while (isblank(*coremask)) 60899a2dd95SBruce Richardson coremask++; 60999a2dd95SBruce Richardson if (coremask[0] == '0' && ((coremask[1] == 'x') 61099a2dd95SBruce Richardson || (coremask[1] == 'X'))) 61199a2dd95SBruce Richardson coremask += 2; 61299a2dd95SBruce Richardson i = strlen(coremask); 61399a2dd95SBruce Richardson while ((i > 0) && isblank(coremask[i - 1])) 61499a2dd95SBruce Richardson i--; 61599a2dd95SBruce Richardson 61699a2dd95SBruce Richardson if (i == 0) 61799a2dd95SBruce Richardson return -1; 61899a2dd95SBruce Richardson 61999a2dd95SBruce Richardson for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) { 62099a2dd95SBruce Richardson c = coremask[i]; 62199a2dd95SBruce Richardson if (isxdigit(c) == 0) { 62299a2dd95SBruce Richardson /* invalid characters */ 62399a2dd95SBruce Richardson return -1; 62499a2dd95SBruce Richardson } 62599a2dd95SBruce Richardson val = xdigit2val(c); 62699a2dd95SBruce Richardson for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; 62799a2dd95SBruce Richardson j++, idx++) { 62899a2dd95SBruce Richardson if ((1 << j) & val) { 62999a2dd95SBruce Richardson /* handle main lcore already parsed */ 63099a2dd95SBruce Richardson uint32_t lcore = idx; 63199a2dd95SBruce Richardson if (main_lcore_parsed && 63299a2dd95SBruce Richardson cfg->main_lcore == lcore) { 63399a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 63499a2dd95SBruce Richardson "lcore %u is main lcore, cannot use as service core\n", 63599a2dd95SBruce Richardson idx); 63699a2dd95SBruce Richardson return -1; 63799a2dd95SBruce Richardson } 63899a2dd95SBruce Richardson 63999a2dd95SBruce Richardson if (eal_cpu_detected(idx) == 0) { 64099a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 64199a2dd95SBruce Richardson "lcore %u unavailable\n", idx); 64299a2dd95SBruce Richardson return -1; 64399a2dd95SBruce Richardson } 64499a2dd95SBruce Richardson 64599a2dd95SBruce Richardson if (cfg->lcore_role[idx] == ROLE_RTE) 64699a2dd95SBruce Richardson taken_lcore_count++; 64799a2dd95SBruce Richardson 64899a2dd95SBruce Richardson lcore_config[idx].core_role = ROLE_SERVICE; 64999a2dd95SBruce Richardson count++; 65099a2dd95SBruce Richardson } 65199a2dd95SBruce Richardson } 65299a2dd95SBruce Richardson } 65399a2dd95SBruce Richardson 65499a2dd95SBruce Richardson for (; i >= 0; i--) 65599a2dd95SBruce Richardson if (coremask[i] != '0') 65699a2dd95SBruce Richardson return -1; 65799a2dd95SBruce Richardson 65899a2dd95SBruce Richardson for (; idx < RTE_MAX_LCORE; idx++) 65999a2dd95SBruce Richardson lcore_config[idx].core_index = -1; 66099a2dd95SBruce Richardson 66199a2dd95SBruce Richardson if (count == 0) 66299a2dd95SBruce Richardson return -1; 66399a2dd95SBruce Richardson 66499a2dd95SBruce Richardson if (core_parsed && taken_lcore_count != count) { 66599a2dd95SBruce Richardson RTE_LOG(WARNING, EAL, 66699a2dd95SBruce Richardson "Not all service cores are in the coremask. " 66799a2dd95SBruce Richardson "Please ensure -c or -l includes service cores\n"); 66899a2dd95SBruce Richardson } 66999a2dd95SBruce Richardson 67099a2dd95SBruce Richardson cfg->service_lcore_count = count; 67199a2dd95SBruce Richardson return 0; 67299a2dd95SBruce Richardson } 67399a2dd95SBruce Richardson 67499a2dd95SBruce Richardson static int 67599a2dd95SBruce Richardson eal_service_cores_parsed(void) 67699a2dd95SBruce Richardson { 67799a2dd95SBruce Richardson int idx; 67899a2dd95SBruce Richardson for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 67999a2dd95SBruce Richardson if (lcore_config[idx].core_role == ROLE_SERVICE) 68099a2dd95SBruce Richardson return 1; 68199a2dd95SBruce Richardson } 68299a2dd95SBruce Richardson return 0; 68399a2dd95SBruce Richardson } 68499a2dd95SBruce Richardson 68599a2dd95SBruce Richardson static int 68699a2dd95SBruce Richardson update_lcore_config(int *cores) 68799a2dd95SBruce Richardson { 68899a2dd95SBruce Richardson struct rte_config *cfg = rte_eal_get_configuration(); 68999a2dd95SBruce Richardson unsigned int count = 0; 69099a2dd95SBruce Richardson unsigned int i; 69199a2dd95SBruce Richardson int ret = 0; 69299a2dd95SBruce Richardson 69399a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_LCORE; i++) { 69499a2dd95SBruce Richardson if (cores[i] != -1) { 69599a2dd95SBruce Richardson if (eal_cpu_detected(i) == 0) { 69699a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i); 69799a2dd95SBruce Richardson ret = -1; 69899a2dd95SBruce Richardson continue; 69999a2dd95SBruce Richardson } 70099a2dd95SBruce Richardson cfg->lcore_role[i] = ROLE_RTE; 70199a2dd95SBruce Richardson count++; 70299a2dd95SBruce Richardson } else { 70399a2dd95SBruce Richardson cfg->lcore_role[i] = ROLE_OFF; 70499a2dd95SBruce Richardson } 70599a2dd95SBruce Richardson lcore_config[i].core_index = cores[i]; 70699a2dd95SBruce Richardson } 70799a2dd95SBruce Richardson if (!ret) 70899a2dd95SBruce Richardson cfg->lcore_count = count; 70999a2dd95SBruce Richardson return ret; 71099a2dd95SBruce Richardson } 71199a2dd95SBruce Richardson 71299a2dd95SBruce Richardson static int 71399a2dd95SBruce Richardson eal_parse_coremask(const char *coremask, int *cores) 71499a2dd95SBruce Richardson { 71599a2dd95SBruce Richardson unsigned count = 0; 71699a2dd95SBruce Richardson int i, j, idx; 71799a2dd95SBruce Richardson int val; 71899a2dd95SBruce Richardson char c; 71999a2dd95SBruce Richardson 72099a2dd95SBruce Richardson for (idx = 0; idx < RTE_MAX_LCORE; idx++) 72199a2dd95SBruce Richardson cores[idx] = -1; 72299a2dd95SBruce Richardson idx = 0; 72399a2dd95SBruce Richardson 72499a2dd95SBruce Richardson /* Remove all blank characters ahead and after . 72599a2dd95SBruce Richardson * Remove 0x/0X if exists. 72699a2dd95SBruce Richardson */ 72799a2dd95SBruce Richardson while (isblank(*coremask)) 72899a2dd95SBruce Richardson coremask++; 72999a2dd95SBruce Richardson if (coremask[0] == '0' && ((coremask[1] == 'x') 73099a2dd95SBruce Richardson || (coremask[1] == 'X'))) 73199a2dd95SBruce Richardson coremask += 2; 73299a2dd95SBruce Richardson i = strlen(coremask); 73399a2dd95SBruce Richardson while ((i > 0) && isblank(coremask[i - 1])) 73499a2dd95SBruce Richardson i--; 73599a2dd95SBruce Richardson if (i == 0) 73699a2dd95SBruce Richardson return -1; 73799a2dd95SBruce Richardson 73899a2dd95SBruce Richardson for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) { 73999a2dd95SBruce Richardson c = coremask[i]; 74099a2dd95SBruce Richardson if (isxdigit(c) == 0) { 74199a2dd95SBruce Richardson /* invalid characters */ 74299a2dd95SBruce Richardson return -1; 74399a2dd95SBruce Richardson } 74499a2dd95SBruce Richardson val = xdigit2val(c); 74599a2dd95SBruce Richardson for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++) 74699a2dd95SBruce Richardson { 74799a2dd95SBruce Richardson if ((1 << j) & val) { 74899a2dd95SBruce Richardson cores[idx] = count; 74999a2dd95SBruce Richardson count++; 75099a2dd95SBruce Richardson } 75199a2dd95SBruce Richardson } 75299a2dd95SBruce Richardson } 75399a2dd95SBruce Richardson for (; i >= 0; i--) 75499a2dd95SBruce Richardson if (coremask[i] != '0') 75599a2dd95SBruce Richardson return -1; 75699a2dd95SBruce Richardson if (count == 0) 75799a2dd95SBruce Richardson return -1; 75899a2dd95SBruce Richardson return 0; 75999a2dd95SBruce Richardson } 76099a2dd95SBruce Richardson 76199a2dd95SBruce Richardson static int 76299a2dd95SBruce Richardson eal_parse_service_corelist(const char *corelist) 76399a2dd95SBruce Richardson { 76499a2dd95SBruce Richardson struct rte_config *cfg = rte_eal_get_configuration(); 76597ca1e78SChengwen Feng int i; 76699a2dd95SBruce Richardson unsigned count = 0; 76799a2dd95SBruce Richardson char *end = NULL; 76897ca1e78SChengwen Feng uint32_t min, max, idx; 76999a2dd95SBruce Richardson uint32_t taken_lcore_count = 0; 77099a2dd95SBruce Richardson 77199a2dd95SBruce Richardson if (corelist == NULL) 77299a2dd95SBruce Richardson return -1; 77399a2dd95SBruce Richardson 77499a2dd95SBruce Richardson /* Remove all blank characters ahead and after */ 77599a2dd95SBruce Richardson while (isblank(*corelist)) 77699a2dd95SBruce Richardson corelist++; 77799a2dd95SBruce Richardson i = strlen(corelist); 77899a2dd95SBruce Richardson while ((i > 0) && isblank(corelist[i - 1])) 77999a2dd95SBruce Richardson i--; 78099a2dd95SBruce Richardson 78199a2dd95SBruce Richardson /* Get list of cores */ 78299a2dd95SBruce Richardson min = RTE_MAX_LCORE; 78399a2dd95SBruce Richardson do { 78499a2dd95SBruce Richardson while (isblank(*corelist)) 78599a2dd95SBruce Richardson corelist++; 78699a2dd95SBruce Richardson if (*corelist == '\0') 78799a2dd95SBruce Richardson return -1; 78899a2dd95SBruce Richardson errno = 0; 78999a2dd95SBruce Richardson idx = strtoul(corelist, &end, 10); 79099a2dd95SBruce Richardson if (errno || end == NULL) 79199a2dd95SBruce Richardson return -1; 79297ca1e78SChengwen Feng if (idx >= RTE_MAX_LCORE) 79397ca1e78SChengwen Feng return -1; 79499a2dd95SBruce Richardson while (isblank(*end)) 79599a2dd95SBruce Richardson end++; 79699a2dd95SBruce Richardson if (*end == '-') { 79799a2dd95SBruce Richardson min = idx; 79899a2dd95SBruce Richardson } else if ((*end == ',') || (*end == '\0')) { 79999a2dd95SBruce Richardson max = idx; 80099a2dd95SBruce Richardson if (min == RTE_MAX_LCORE) 80199a2dd95SBruce Richardson min = idx; 80299a2dd95SBruce Richardson for (idx = min; idx <= max; idx++) { 80399a2dd95SBruce Richardson if (cfg->lcore_role[idx] != ROLE_SERVICE) { 80499a2dd95SBruce Richardson /* handle main lcore already parsed */ 80599a2dd95SBruce Richardson uint32_t lcore = idx; 80699a2dd95SBruce Richardson if (cfg->main_lcore == lcore && 80799a2dd95SBruce Richardson main_lcore_parsed) { 80899a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 80999a2dd95SBruce Richardson "Error: lcore %u is main lcore, cannot use as service core\n", 81099a2dd95SBruce Richardson idx); 81199a2dd95SBruce Richardson return -1; 81299a2dd95SBruce Richardson } 81399a2dd95SBruce Richardson if (cfg->lcore_role[idx] == ROLE_RTE) 81499a2dd95SBruce Richardson taken_lcore_count++; 81599a2dd95SBruce Richardson 81699a2dd95SBruce Richardson lcore_config[idx].core_role = 81799a2dd95SBruce Richardson ROLE_SERVICE; 81899a2dd95SBruce Richardson count++; 81999a2dd95SBruce Richardson } 82099a2dd95SBruce Richardson } 82199a2dd95SBruce Richardson min = RTE_MAX_LCORE; 82299a2dd95SBruce Richardson } else 82399a2dd95SBruce Richardson return -1; 82499a2dd95SBruce Richardson corelist = end + 1; 82599a2dd95SBruce Richardson } while (*end != '\0'); 82699a2dd95SBruce Richardson 82799a2dd95SBruce Richardson if (count == 0) 82899a2dd95SBruce Richardson return -1; 82999a2dd95SBruce Richardson 83099a2dd95SBruce Richardson if (core_parsed && taken_lcore_count != count) { 83199a2dd95SBruce Richardson RTE_LOG(WARNING, EAL, 83299a2dd95SBruce Richardson "Not all service cores were in the coremask. " 83399a2dd95SBruce Richardson "Please ensure -c or -l includes service cores\n"); 83499a2dd95SBruce Richardson } 83599a2dd95SBruce Richardson 83699a2dd95SBruce Richardson return 0; 83799a2dd95SBruce Richardson } 83899a2dd95SBruce Richardson 83999a2dd95SBruce Richardson static int 84099a2dd95SBruce Richardson eal_parse_corelist(const char *corelist, int *cores) 84199a2dd95SBruce Richardson { 84299a2dd95SBruce Richardson unsigned count = 0; 84399a2dd95SBruce Richardson char *end = NULL; 84499a2dd95SBruce Richardson int min, max; 84599a2dd95SBruce Richardson int idx; 84699a2dd95SBruce Richardson 84799a2dd95SBruce Richardson for (idx = 0; idx < RTE_MAX_LCORE; idx++) 84899a2dd95SBruce Richardson cores[idx] = -1; 84999a2dd95SBruce Richardson 85099a2dd95SBruce Richardson /* Remove all blank characters ahead */ 85199a2dd95SBruce Richardson while (isblank(*corelist)) 85299a2dd95SBruce Richardson corelist++; 85399a2dd95SBruce Richardson 85499a2dd95SBruce Richardson /* Get list of cores */ 85599a2dd95SBruce Richardson min = RTE_MAX_LCORE; 85699a2dd95SBruce Richardson do { 85799a2dd95SBruce Richardson while (isblank(*corelist)) 85899a2dd95SBruce Richardson corelist++; 85999a2dd95SBruce Richardson if (*corelist == '\0') 86099a2dd95SBruce Richardson return -1; 86199a2dd95SBruce Richardson errno = 0; 86299a2dd95SBruce Richardson idx = strtol(corelist, &end, 10); 86399a2dd95SBruce Richardson if (errno || end == NULL) 86499a2dd95SBruce Richardson return -1; 86599a2dd95SBruce Richardson if (idx < 0 || idx >= RTE_MAX_LCORE) 86699a2dd95SBruce Richardson return -1; 86799a2dd95SBruce Richardson while (isblank(*end)) 86899a2dd95SBruce Richardson end++; 86999a2dd95SBruce Richardson if (*end == '-') { 87099a2dd95SBruce Richardson min = idx; 87199a2dd95SBruce Richardson } else if ((*end == ',') || (*end == '\0')) { 87299a2dd95SBruce Richardson max = idx; 87399a2dd95SBruce Richardson if (min == RTE_MAX_LCORE) 87499a2dd95SBruce Richardson min = idx; 87599a2dd95SBruce Richardson for (idx = min; idx <= max; idx++) { 87699a2dd95SBruce Richardson if (cores[idx] == -1) { 87799a2dd95SBruce Richardson cores[idx] = count; 87899a2dd95SBruce Richardson count++; 87999a2dd95SBruce Richardson } 88099a2dd95SBruce Richardson } 88199a2dd95SBruce Richardson min = RTE_MAX_LCORE; 88299a2dd95SBruce Richardson } else 88399a2dd95SBruce Richardson return -1; 88499a2dd95SBruce Richardson corelist = end + 1; 88599a2dd95SBruce Richardson } while (*end != '\0'); 88699a2dd95SBruce Richardson 88799a2dd95SBruce Richardson if (count == 0) 88899a2dd95SBruce Richardson return -1; 88999a2dd95SBruce Richardson return 0; 89099a2dd95SBruce Richardson } 89199a2dd95SBruce Richardson 89299a2dd95SBruce Richardson /* Changes the lcore id of the main thread */ 89399a2dd95SBruce Richardson static int 89499a2dd95SBruce Richardson eal_parse_main_lcore(const char *arg) 89599a2dd95SBruce Richardson { 89699a2dd95SBruce Richardson char *parsing_end; 89799a2dd95SBruce Richardson struct rte_config *cfg = rte_eal_get_configuration(); 89899a2dd95SBruce Richardson 89999a2dd95SBruce Richardson errno = 0; 90099a2dd95SBruce Richardson cfg->main_lcore = (uint32_t) strtol(arg, &parsing_end, 0); 90199a2dd95SBruce Richardson if (errno || parsing_end[0] != 0) 90299a2dd95SBruce Richardson return -1; 90399a2dd95SBruce Richardson if (cfg->main_lcore >= RTE_MAX_LCORE) 90499a2dd95SBruce Richardson return -1; 90599a2dd95SBruce Richardson main_lcore_parsed = 1; 90699a2dd95SBruce Richardson 90799a2dd95SBruce Richardson /* ensure main core is not used as service core */ 90899a2dd95SBruce Richardson if (lcore_config[cfg->main_lcore].core_role == ROLE_SERVICE) { 90999a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 91099a2dd95SBruce Richardson "Error: Main lcore is used as a service core\n"); 91199a2dd95SBruce Richardson return -1; 91299a2dd95SBruce Richardson } 91399a2dd95SBruce Richardson 91499a2dd95SBruce Richardson return 0; 91599a2dd95SBruce Richardson } 91699a2dd95SBruce Richardson 91799a2dd95SBruce Richardson /* 91899a2dd95SBruce Richardson * Parse elem, the elem could be single number/range or '(' ')' group 91999a2dd95SBruce Richardson * 1) A single number elem, it's just a simple digit. e.g. 9 92099a2dd95SBruce Richardson * 2) A single range elem, two digits with a '-' between. e.g. 2-6 92199a2dd95SBruce Richardson * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6) 92299a2dd95SBruce Richardson * Within group elem, '-' used for a range separator; 92399a2dd95SBruce Richardson * ',' used for a single number. 92499a2dd95SBruce Richardson */ 92599a2dd95SBruce Richardson static int 92699a2dd95SBruce Richardson eal_parse_set(const char *input, rte_cpuset_t *set) 92799a2dd95SBruce Richardson { 92899a2dd95SBruce Richardson unsigned idx; 92999a2dd95SBruce Richardson const char *str = input; 93099a2dd95SBruce Richardson char *end = NULL; 93199a2dd95SBruce Richardson unsigned min, max; 93299a2dd95SBruce Richardson 93399a2dd95SBruce Richardson CPU_ZERO(set); 93499a2dd95SBruce Richardson 93599a2dd95SBruce Richardson while (isblank(*str)) 93699a2dd95SBruce Richardson str++; 93799a2dd95SBruce Richardson 93899a2dd95SBruce Richardson /* only digit or left bracket is qualify for start point */ 93999a2dd95SBruce Richardson if ((!isdigit(*str) && *str != '(') || *str == '\0') 94099a2dd95SBruce Richardson return -1; 94199a2dd95SBruce Richardson 94299a2dd95SBruce Richardson /* process single number or single range of number */ 94399a2dd95SBruce Richardson if (*str != '(') { 94499a2dd95SBruce Richardson errno = 0; 94599a2dd95SBruce Richardson idx = strtoul(str, &end, 10); 94699a2dd95SBruce Richardson if (errno || end == NULL || idx >= CPU_SETSIZE) 94799a2dd95SBruce Richardson return -1; 94899a2dd95SBruce Richardson else { 94999a2dd95SBruce Richardson while (isblank(*end)) 95099a2dd95SBruce Richardson end++; 95199a2dd95SBruce Richardson 95299a2dd95SBruce Richardson min = idx; 95399a2dd95SBruce Richardson max = idx; 95499a2dd95SBruce Richardson if (*end == '-') { 95599a2dd95SBruce Richardson /* process single <number>-<number> */ 95699a2dd95SBruce Richardson end++; 95799a2dd95SBruce Richardson while (isblank(*end)) 95899a2dd95SBruce Richardson end++; 95999a2dd95SBruce Richardson if (!isdigit(*end)) 96099a2dd95SBruce Richardson return -1; 96199a2dd95SBruce Richardson 96299a2dd95SBruce Richardson errno = 0; 96399a2dd95SBruce Richardson idx = strtoul(end, &end, 10); 96499a2dd95SBruce Richardson if (errno || end == NULL || idx >= CPU_SETSIZE) 96599a2dd95SBruce Richardson return -1; 96699a2dd95SBruce Richardson max = idx; 96799a2dd95SBruce Richardson while (isblank(*end)) 96899a2dd95SBruce Richardson end++; 96999a2dd95SBruce Richardson if (*end != ',' && *end != '\0') 97099a2dd95SBruce Richardson return -1; 97199a2dd95SBruce Richardson } 97299a2dd95SBruce Richardson 97399a2dd95SBruce Richardson if (*end != ',' && *end != '\0' && 97499a2dd95SBruce Richardson *end != '@') 97599a2dd95SBruce Richardson return -1; 97699a2dd95SBruce Richardson 97799a2dd95SBruce Richardson for (idx = RTE_MIN(min, max); 97899a2dd95SBruce Richardson idx <= RTE_MAX(min, max); idx++) 97999a2dd95SBruce Richardson CPU_SET(idx, set); 98099a2dd95SBruce Richardson 98199a2dd95SBruce Richardson return end - input; 98299a2dd95SBruce Richardson } 98399a2dd95SBruce Richardson } 98499a2dd95SBruce Richardson 98599a2dd95SBruce Richardson /* process set within bracket */ 98699a2dd95SBruce Richardson str++; 98799a2dd95SBruce Richardson while (isblank(*str)) 98899a2dd95SBruce Richardson str++; 98999a2dd95SBruce Richardson if (*str == '\0') 99099a2dd95SBruce Richardson return -1; 99199a2dd95SBruce Richardson 99299a2dd95SBruce Richardson min = RTE_MAX_LCORE; 99399a2dd95SBruce Richardson do { 99499a2dd95SBruce Richardson 99599a2dd95SBruce Richardson /* go ahead to the first digit */ 99699a2dd95SBruce Richardson while (isblank(*str)) 99799a2dd95SBruce Richardson str++; 99899a2dd95SBruce Richardson if (!isdigit(*str)) 99999a2dd95SBruce Richardson return -1; 100099a2dd95SBruce Richardson 100199a2dd95SBruce Richardson /* get the digit value */ 100299a2dd95SBruce Richardson errno = 0; 100399a2dd95SBruce Richardson idx = strtoul(str, &end, 10); 100499a2dd95SBruce Richardson if (errno || end == NULL || idx >= CPU_SETSIZE) 100599a2dd95SBruce Richardson return -1; 100699a2dd95SBruce Richardson 100799a2dd95SBruce Richardson /* go ahead to separator '-',',' and ')' */ 100899a2dd95SBruce Richardson while (isblank(*end)) 100999a2dd95SBruce Richardson end++; 101099a2dd95SBruce Richardson if (*end == '-') { 101199a2dd95SBruce Richardson if (min == RTE_MAX_LCORE) 101299a2dd95SBruce Richardson min = idx; 101399a2dd95SBruce Richardson else /* avoid continuous '-' */ 101499a2dd95SBruce Richardson return -1; 101599a2dd95SBruce Richardson } else if ((*end == ',') || (*end == ')')) { 101699a2dd95SBruce Richardson max = idx; 101799a2dd95SBruce Richardson if (min == RTE_MAX_LCORE) 101899a2dd95SBruce Richardson min = idx; 101999a2dd95SBruce Richardson for (idx = RTE_MIN(min, max); 102099a2dd95SBruce Richardson idx <= RTE_MAX(min, max); idx++) 102199a2dd95SBruce Richardson CPU_SET(idx, set); 102299a2dd95SBruce Richardson 102399a2dd95SBruce Richardson min = RTE_MAX_LCORE; 102499a2dd95SBruce Richardson } else 102599a2dd95SBruce Richardson return -1; 102699a2dd95SBruce Richardson 102799a2dd95SBruce Richardson str = end + 1; 102899a2dd95SBruce Richardson } while (*end != '\0' && *end != ')'); 102999a2dd95SBruce Richardson 103099a2dd95SBruce Richardson /* 103199a2dd95SBruce Richardson * to avoid failure that tail blank makes end character check fail 103299a2dd95SBruce Richardson * in eal_parse_lcores( ) 103399a2dd95SBruce Richardson */ 103499a2dd95SBruce Richardson while (isblank(*str)) 103599a2dd95SBruce Richardson str++; 103699a2dd95SBruce Richardson 103799a2dd95SBruce Richardson return str - input; 103899a2dd95SBruce Richardson } 103999a2dd95SBruce Richardson 104099a2dd95SBruce Richardson static int 104199a2dd95SBruce Richardson check_cpuset(rte_cpuset_t *set) 104299a2dd95SBruce Richardson { 104399a2dd95SBruce Richardson unsigned int idx; 104499a2dd95SBruce Richardson 104599a2dd95SBruce Richardson for (idx = 0; idx < CPU_SETSIZE; idx++) { 104699a2dd95SBruce Richardson if (!CPU_ISSET(idx, set)) 104799a2dd95SBruce Richardson continue; 104899a2dd95SBruce Richardson 104999a2dd95SBruce Richardson if (eal_cpu_detected(idx) == 0) { 105099a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "core %u " 105199a2dd95SBruce Richardson "unavailable\n", idx); 105299a2dd95SBruce Richardson return -1; 105399a2dd95SBruce Richardson } 105499a2dd95SBruce Richardson } 105599a2dd95SBruce Richardson return 0; 105699a2dd95SBruce Richardson } 105799a2dd95SBruce Richardson 105899a2dd95SBruce Richardson /* 105999a2dd95SBruce Richardson * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]' 106099a2dd95SBruce Richardson * lcores, cpus could be a single digit/range or a group. 106199a2dd95SBruce Richardson * '(' and ')' are necessary if it's a group. 106299a2dd95SBruce Richardson * If not supply '@cpus', the value of cpus uses the same as lcores. 106399a2dd95SBruce Richardson * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below 106499a2dd95SBruce Richardson * lcore 0 runs on cpuset 0x41 (cpu 0,6) 106599a2dd95SBruce Richardson * lcore 1 runs on cpuset 0x2 (cpu 1) 106699a2dd95SBruce Richardson * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7) 106799a2dd95SBruce Richardson * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2) 106899a2dd95SBruce Richardson * lcore 6 runs on cpuset 0x41 (cpu 0,6) 106999a2dd95SBruce Richardson * lcore 7 runs on cpuset 0x80 (cpu 7) 107099a2dd95SBruce Richardson * lcore 8 runs on cpuset 0x100 (cpu 8) 107199a2dd95SBruce Richardson */ 107299a2dd95SBruce Richardson static int 107399a2dd95SBruce Richardson eal_parse_lcores(const char *lcores) 107499a2dd95SBruce Richardson { 107599a2dd95SBruce Richardson struct rte_config *cfg = rte_eal_get_configuration(); 107699a2dd95SBruce Richardson rte_cpuset_t lcore_set; 107799a2dd95SBruce Richardson unsigned int set_count; 107899a2dd95SBruce Richardson unsigned idx = 0; 107999a2dd95SBruce Richardson unsigned count = 0; 108099a2dd95SBruce Richardson const char *lcore_start = NULL; 108199a2dd95SBruce Richardson const char *end = NULL; 108299a2dd95SBruce Richardson int offset; 108399a2dd95SBruce Richardson rte_cpuset_t cpuset; 108499a2dd95SBruce Richardson int lflags; 108599a2dd95SBruce Richardson int ret = -1; 108699a2dd95SBruce Richardson 108799a2dd95SBruce Richardson if (lcores == NULL) 108899a2dd95SBruce Richardson return -1; 108999a2dd95SBruce Richardson 109099a2dd95SBruce Richardson /* Remove all blank characters ahead and after */ 109199a2dd95SBruce Richardson while (isblank(*lcores)) 109299a2dd95SBruce Richardson lcores++; 109399a2dd95SBruce Richardson 109499a2dd95SBruce Richardson CPU_ZERO(&cpuset); 109599a2dd95SBruce Richardson 109699a2dd95SBruce Richardson /* Reset lcore config */ 109799a2dd95SBruce Richardson for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 109899a2dd95SBruce Richardson cfg->lcore_role[idx] = ROLE_OFF; 109999a2dd95SBruce Richardson lcore_config[idx].core_index = -1; 110099a2dd95SBruce Richardson CPU_ZERO(&lcore_config[idx].cpuset); 110199a2dd95SBruce Richardson } 110299a2dd95SBruce Richardson 110399a2dd95SBruce Richardson /* Get list of cores */ 110499a2dd95SBruce Richardson do { 110599a2dd95SBruce Richardson while (isblank(*lcores)) 110699a2dd95SBruce Richardson lcores++; 110799a2dd95SBruce Richardson if (*lcores == '\0') 110899a2dd95SBruce Richardson goto err; 110999a2dd95SBruce Richardson 111099a2dd95SBruce Richardson lflags = 0; 111199a2dd95SBruce Richardson 111299a2dd95SBruce Richardson /* record lcore_set start point */ 111399a2dd95SBruce Richardson lcore_start = lcores; 111499a2dd95SBruce Richardson 111599a2dd95SBruce Richardson /* go across a complete bracket */ 111699a2dd95SBruce Richardson if (*lcore_start == '(') { 111799a2dd95SBruce Richardson lcores += strcspn(lcores, ")"); 111899a2dd95SBruce Richardson if (*lcores++ == '\0') 111999a2dd95SBruce Richardson goto err; 112099a2dd95SBruce Richardson } 112199a2dd95SBruce Richardson 112299a2dd95SBruce Richardson /* scan the separator '@', ','(next) or '\0'(finish) */ 112399a2dd95SBruce Richardson lcores += strcspn(lcores, "@,"); 112499a2dd95SBruce Richardson 112599a2dd95SBruce Richardson if (*lcores == '@') { 112699a2dd95SBruce Richardson /* explicit assign cpuset and update the end cursor */ 112799a2dd95SBruce Richardson offset = eal_parse_set(lcores + 1, &cpuset); 112899a2dd95SBruce Richardson if (offset < 0) 112999a2dd95SBruce Richardson goto err; 113099a2dd95SBruce Richardson end = lcores + 1 + offset; 113199a2dd95SBruce Richardson } else { /* ',' or '\0' */ 113299a2dd95SBruce Richardson /* haven't given cpuset, current loop done */ 113399a2dd95SBruce Richardson end = lcores; 113499a2dd95SBruce Richardson 113599a2dd95SBruce Richardson /* go back to check <number>-<number> */ 113699a2dd95SBruce Richardson offset = strcspn(lcore_start, "(-"); 113799a2dd95SBruce Richardson if (offset < (end - lcore_start) && 113899a2dd95SBruce Richardson *(lcore_start + offset) != '(') 113999a2dd95SBruce Richardson lflags = 1; 114099a2dd95SBruce Richardson } 114199a2dd95SBruce Richardson 114299a2dd95SBruce Richardson if (*end != ',' && *end != '\0') 114399a2dd95SBruce Richardson goto err; 114499a2dd95SBruce Richardson 114599a2dd95SBruce Richardson /* parse lcore_set from start point */ 114699a2dd95SBruce Richardson if (eal_parse_set(lcore_start, &lcore_set) < 0) 114799a2dd95SBruce Richardson goto err; 114899a2dd95SBruce Richardson 114999a2dd95SBruce Richardson /* without '@', by default using lcore_set as cpuset */ 115099a2dd95SBruce Richardson if (*lcores != '@') 115199a2dd95SBruce Richardson rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset)); 115299a2dd95SBruce Richardson 115399a2dd95SBruce Richardson set_count = CPU_COUNT(&lcore_set); 115499a2dd95SBruce Richardson /* start to update lcore_set */ 115599a2dd95SBruce Richardson for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 115699a2dd95SBruce Richardson if (!CPU_ISSET(idx, &lcore_set)) 115799a2dd95SBruce Richardson continue; 115899a2dd95SBruce Richardson set_count--; 115999a2dd95SBruce Richardson 116099a2dd95SBruce Richardson if (cfg->lcore_role[idx] != ROLE_RTE) { 116199a2dd95SBruce Richardson lcore_config[idx].core_index = count; 116299a2dd95SBruce Richardson cfg->lcore_role[idx] = ROLE_RTE; 116399a2dd95SBruce Richardson count++; 116499a2dd95SBruce Richardson } 116599a2dd95SBruce Richardson 116699a2dd95SBruce Richardson if (lflags) { 116799a2dd95SBruce Richardson CPU_ZERO(&cpuset); 116899a2dd95SBruce Richardson CPU_SET(idx, &cpuset); 116999a2dd95SBruce Richardson } 117099a2dd95SBruce Richardson 117199a2dd95SBruce Richardson if (check_cpuset(&cpuset) < 0) 117299a2dd95SBruce Richardson goto err; 117399a2dd95SBruce Richardson rte_memcpy(&lcore_config[idx].cpuset, &cpuset, 117499a2dd95SBruce Richardson sizeof(rte_cpuset_t)); 117599a2dd95SBruce Richardson } 117699a2dd95SBruce Richardson 117799a2dd95SBruce Richardson /* some cores from the lcore_set can't be handled by EAL */ 117899a2dd95SBruce Richardson if (set_count != 0) 117999a2dd95SBruce Richardson goto err; 118099a2dd95SBruce Richardson 118199a2dd95SBruce Richardson lcores = end + 1; 118299a2dd95SBruce Richardson } while (*end != '\0'); 118399a2dd95SBruce Richardson 118499a2dd95SBruce Richardson if (count == 0) 118599a2dd95SBruce Richardson goto err; 118699a2dd95SBruce Richardson 118799a2dd95SBruce Richardson cfg->lcore_count = count; 118899a2dd95SBruce Richardson ret = 0; 118999a2dd95SBruce Richardson 119099a2dd95SBruce Richardson err: 119199a2dd95SBruce Richardson 119299a2dd95SBruce Richardson return ret; 119399a2dd95SBruce Richardson } 119499a2dd95SBruce Richardson 119599a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 119699a2dd95SBruce Richardson static int 119799a2dd95SBruce Richardson eal_parse_syslog(const char *facility, struct internal_config *conf) 119899a2dd95SBruce Richardson { 119999a2dd95SBruce Richardson int i; 120099a2dd95SBruce Richardson static const struct { 120199a2dd95SBruce Richardson const char *name; 120299a2dd95SBruce Richardson int value; 120399a2dd95SBruce Richardson } map[] = { 120499a2dd95SBruce Richardson { "auth", LOG_AUTH }, 120599a2dd95SBruce Richardson { "cron", LOG_CRON }, 120699a2dd95SBruce Richardson { "daemon", LOG_DAEMON }, 120799a2dd95SBruce Richardson { "ftp", LOG_FTP }, 120899a2dd95SBruce Richardson { "kern", LOG_KERN }, 120999a2dd95SBruce Richardson { "lpr", LOG_LPR }, 121099a2dd95SBruce Richardson { "mail", LOG_MAIL }, 121199a2dd95SBruce Richardson { "news", LOG_NEWS }, 121299a2dd95SBruce Richardson { "syslog", LOG_SYSLOG }, 121399a2dd95SBruce Richardson { "user", LOG_USER }, 121499a2dd95SBruce Richardson { "uucp", LOG_UUCP }, 121599a2dd95SBruce Richardson { "local0", LOG_LOCAL0 }, 121699a2dd95SBruce Richardson { "local1", LOG_LOCAL1 }, 121799a2dd95SBruce Richardson { "local2", LOG_LOCAL2 }, 121899a2dd95SBruce Richardson { "local3", LOG_LOCAL3 }, 121999a2dd95SBruce Richardson { "local4", LOG_LOCAL4 }, 122099a2dd95SBruce Richardson { "local5", LOG_LOCAL5 }, 122199a2dd95SBruce Richardson { "local6", LOG_LOCAL6 }, 122299a2dd95SBruce Richardson { "local7", LOG_LOCAL7 }, 122399a2dd95SBruce Richardson { NULL, 0 } 122499a2dd95SBruce Richardson }; 122599a2dd95SBruce Richardson 122699a2dd95SBruce Richardson for (i = 0; map[i].name; i++) { 122799a2dd95SBruce Richardson if (!strcmp(facility, map[i].name)) { 122899a2dd95SBruce Richardson conf->syslog_facility = map[i].value; 122999a2dd95SBruce Richardson return 0; 123099a2dd95SBruce Richardson } 123199a2dd95SBruce Richardson } 123299a2dd95SBruce Richardson return -1; 123399a2dd95SBruce Richardson } 123499a2dd95SBruce Richardson #endif 123599a2dd95SBruce Richardson 123699a2dd95SBruce Richardson static void 123799a2dd95SBruce Richardson eal_log_usage(void) 123899a2dd95SBruce Richardson { 123999a2dd95SBruce Richardson unsigned int level; 124099a2dd95SBruce Richardson 124199a2dd95SBruce Richardson printf("Log type is a pattern matching items of this list" 124299a2dd95SBruce Richardson " (plugins may be missing):\n"); 124399a2dd95SBruce Richardson rte_log_list_types(stdout, "\t"); 124499a2dd95SBruce Richardson printf("\n"); 124599a2dd95SBruce Richardson printf("Syntax using globbing pattern: "); 124699a2dd95SBruce Richardson printf("--"OPT_LOG_LEVEL" pattern:level\n"); 124799a2dd95SBruce Richardson printf("Syntax using regular expression: "); 124899a2dd95SBruce Richardson printf("--"OPT_LOG_LEVEL" regexp,level\n"); 124999a2dd95SBruce Richardson printf("Syntax for the global level: "); 125099a2dd95SBruce Richardson printf("--"OPT_LOG_LEVEL" level\n"); 125199a2dd95SBruce Richardson printf("Logs are emitted if allowed by both global and specific levels.\n"); 125299a2dd95SBruce Richardson printf("\n"); 125399a2dd95SBruce Richardson printf("Log level can be a number or the first letters of its name:\n"); 125499a2dd95SBruce Richardson for (level = 1; level <= RTE_LOG_MAX; level++) 125599a2dd95SBruce Richardson printf("\t%d %s\n", level, eal_log_level2str(level)); 125699a2dd95SBruce Richardson } 125799a2dd95SBruce Richardson 125899a2dd95SBruce Richardson static int 125999a2dd95SBruce Richardson eal_parse_log_priority(const char *level) 126099a2dd95SBruce Richardson { 126199a2dd95SBruce Richardson size_t len = strlen(level); 126299a2dd95SBruce Richardson unsigned long tmp; 126399a2dd95SBruce Richardson char *end; 126499a2dd95SBruce Richardson unsigned int i; 126599a2dd95SBruce Richardson 126699a2dd95SBruce Richardson if (len == 0) 126799a2dd95SBruce Richardson return -1; 126899a2dd95SBruce Richardson 126999a2dd95SBruce Richardson /* look for named values, skip 0 which is not a valid level */ 127099a2dd95SBruce Richardson for (i = 1; i <= RTE_LOG_MAX; i++) { 127199a2dd95SBruce Richardson if (strncmp(eal_log_level2str(i), level, len) == 0) 127299a2dd95SBruce Richardson return i; 127399a2dd95SBruce Richardson } 127499a2dd95SBruce Richardson 127599a2dd95SBruce Richardson /* not a string, maybe it is numeric */ 127699a2dd95SBruce Richardson errno = 0; 127799a2dd95SBruce Richardson tmp = strtoul(level, &end, 0); 127899a2dd95SBruce Richardson 127999a2dd95SBruce Richardson /* check for errors */ 128099a2dd95SBruce Richardson if (errno != 0 || end == NULL || *end != '\0' || 128199a2dd95SBruce Richardson tmp >= UINT32_MAX) 128299a2dd95SBruce Richardson return -1; 128399a2dd95SBruce Richardson 128499a2dd95SBruce Richardson return tmp; 128599a2dd95SBruce Richardson } 128699a2dd95SBruce Richardson 128799a2dd95SBruce Richardson static int 128899a2dd95SBruce Richardson eal_parse_log_level(const char *arg) 128999a2dd95SBruce Richardson { 129099a2dd95SBruce Richardson const char *pattern = NULL; 129199a2dd95SBruce Richardson const char *regex = NULL; 129299a2dd95SBruce Richardson char *str, *level; 129399a2dd95SBruce Richardson int priority; 129499a2dd95SBruce Richardson 129599a2dd95SBruce Richardson if (strcmp(arg, "help") == 0) { 129699a2dd95SBruce Richardson eal_log_usage(); 129799a2dd95SBruce Richardson exit(EXIT_SUCCESS); 129899a2dd95SBruce Richardson } 129999a2dd95SBruce Richardson 130099a2dd95SBruce Richardson str = strdup(arg); 130199a2dd95SBruce Richardson if (str == NULL) 130299a2dd95SBruce Richardson return -1; 130399a2dd95SBruce Richardson 130499a2dd95SBruce Richardson if ((level = strchr(str, ','))) { 130599a2dd95SBruce Richardson regex = str; 130699a2dd95SBruce Richardson *level++ = '\0'; 130799a2dd95SBruce Richardson } else if ((level = strchr(str, ':'))) { 130899a2dd95SBruce Richardson pattern = str; 130999a2dd95SBruce Richardson *level++ = '\0'; 131099a2dd95SBruce Richardson } else { 131199a2dd95SBruce Richardson level = str; 131299a2dd95SBruce Richardson } 131399a2dd95SBruce Richardson 131499a2dd95SBruce Richardson priority = eal_parse_log_priority(level); 131599a2dd95SBruce Richardson if (priority <= 0) { 131699a2dd95SBruce Richardson fprintf(stderr, "Invalid log level: %s\n", level); 131799a2dd95SBruce Richardson goto fail; 131899a2dd95SBruce Richardson } 131999a2dd95SBruce Richardson if (priority > (int)RTE_LOG_MAX) { 132099a2dd95SBruce Richardson fprintf(stderr, "Log level %d higher than maximum (%d)\n", 132199a2dd95SBruce Richardson priority, RTE_LOG_MAX); 132299a2dd95SBruce Richardson priority = RTE_LOG_MAX; 132399a2dd95SBruce Richardson } 132499a2dd95SBruce Richardson 132599a2dd95SBruce Richardson if (regex) { 132699a2dd95SBruce Richardson if (rte_log_set_level_regexp(regex, priority) < 0) { 132799a2dd95SBruce Richardson fprintf(stderr, "cannot set log level %s,%d\n", 132899a2dd95SBruce Richardson regex, priority); 132999a2dd95SBruce Richardson goto fail; 133099a2dd95SBruce Richardson } 133199a2dd95SBruce Richardson if (eal_log_save_regexp(regex, priority) < 0) 133299a2dd95SBruce Richardson goto fail; 133399a2dd95SBruce Richardson } else if (pattern) { 133499a2dd95SBruce Richardson if (rte_log_set_level_pattern(pattern, priority) < 0) { 133599a2dd95SBruce Richardson fprintf(stderr, "cannot set log level %s:%d\n", 133699a2dd95SBruce Richardson pattern, priority); 133799a2dd95SBruce Richardson goto fail; 133899a2dd95SBruce Richardson } 133999a2dd95SBruce Richardson if (eal_log_save_pattern(pattern, priority) < 0) 134099a2dd95SBruce Richardson goto fail; 134199a2dd95SBruce Richardson } else { 134299a2dd95SBruce Richardson rte_log_set_global_level(priority); 134399a2dd95SBruce Richardson } 134499a2dd95SBruce Richardson 134599a2dd95SBruce Richardson free(str); 134699a2dd95SBruce Richardson return 0; 134799a2dd95SBruce Richardson 134899a2dd95SBruce Richardson fail: 134999a2dd95SBruce Richardson free(str); 135099a2dd95SBruce Richardson return -1; 135199a2dd95SBruce Richardson } 135299a2dd95SBruce Richardson 135399a2dd95SBruce Richardson static enum rte_proc_type_t 135499a2dd95SBruce Richardson eal_parse_proc_type(const char *arg) 135599a2dd95SBruce Richardson { 135699a2dd95SBruce Richardson if (strncasecmp(arg, "primary", sizeof("primary")) == 0) 135799a2dd95SBruce Richardson return RTE_PROC_PRIMARY; 135899a2dd95SBruce Richardson if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0) 135999a2dd95SBruce Richardson return RTE_PROC_SECONDARY; 136099a2dd95SBruce Richardson if (strncasecmp(arg, "auto", sizeof("auto")) == 0) 136199a2dd95SBruce Richardson return RTE_PROC_AUTO; 136299a2dd95SBruce Richardson 136399a2dd95SBruce Richardson return RTE_PROC_INVALID; 136499a2dd95SBruce Richardson } 136599a2dd95SBruce Richardson 136699a2dd95SBruce Richardson static int 136799a2dd95SBruce Richardson eal_parse_iova_mode(const char *name) 136899a2dd95SBruce Richardson { 136999a2dd95SBruce Richardson int mode; 137099a2dd95SBruce Richardson struct internal_config *internal_conf = 137199a2dd95SBruce Richardson eal_get_internal_configuration(); 137299a2dd95SBruce Richardson 137399a2dd95SBruce Richardson if (name == NULL) 137499a2dd95SBruce Richardson return -1; 137599a2dd95SBruce Richardson 137699a2dd95SBruce Richardson if (!strcmp("pa", name)) 137799a2dd95SBruce Richardson mode = RTE_IOVA_PA; 137899a2dd95SBruce Richardson else if (!strcmp("va", name)) 137999a2dd95SBruce Richardson mode = RTE_IOVA_VA; 138099a2dd95SBruce Richardson else 138199a2dd95SBruce Richardson return -1; 138299a2dd95SBruce Richardson 138399a2dd95SBruce Richardson internal_conf->iova_mode = mode; 138499a2dd95SBruce Richardson return 0; 138599a2dd95SBruce Richardson } 138699a2dd95SBruce Richardson 138799a2dd95SBruce Richardson static int 138899a2dd95SBruce Richardson eal_parse_simd_bitwidth(const char *arg) 138999a2dd95SBruce Richardson { 139099a2dd95SBruce Richardson char *end; 139199a2dd95SBruce Richardson unsigned long bitwidth; 139299a2dd95SBruce Richardson int ret; 139399a2dd95SBruce Richardson struct internal_config *internal_conf = 139499a2dd95SBruce Richardson eal_get_internal_configuration(); 139599a2dd95SBruce Richardson 139699a2dd95SBruce Richardson if (arg == NULL || arg[0] == '\0') 139799a2dd95SBruce Richardson return -1; 139899a2dd95SBruce Richardson 139999a2dd95SBruce Richardson errno = 0; 140099a2dd95SBruce Richardson bitwidth = strtoul(arg, &end, 0); 140199a2dd95SBruce Richardson 140299a2dd95SBruce Richardson /* check for errors */ 140399a2dd95SBruce Richardson if (errno != 0 || end == NULL || *end != '\0' || bitwidth > RTE_VECT_SIMD_MAX) 140499a2dd95SBruce Richardson return -1; 140599a2dd95SBruce Richardson 140699a2dd95SBruce Richardson if (bitwidth == 0) 140799a2dd95SBruce Richardson bitwidth = (unsigned long) RTE_VECT_SIMD_MAX; 140899a2dd95SBruce Richardson ret = rte_vect_set_max_simd_bitwidth(bitwidth); 140999a2dd95SBruce Richardson if (ret < 0) 141099a2dd95SBruce Richardson return -1; 141199a2dd95SBruce Richardson internal_conf->max_simd_bitwidth.forced = 1; 141299a2dd95SBruce Richardson return 0; 141399a2dd95SBruce Richardson } 141499a2dd95SBruce Richardson 141599a2dd95SBruce Richardson static int 141699a2dd95SBruce Richardson eal_parse_base_virtaddr(const char *arg) 141799a2dd95SBruce Richardson { 141899a2dd95SBruce Richardson char *end; 141999a2dd95SBruce Richardson uint64_t addr; 142099a2dd95SBruce Richardson struct internal_config *internal_conf = 142199a2dd95SBruce Richardson eal_get_internal_configuration(); 142299a2dd95SBruce Richardson 142399a2dd95SBruce Richardson errno = 0; 142499a2dd95SBruce Richardson addr = strtoull(arg, &end, 16); 142599a2dd95SBruce Richardson 142699a2dd95SBruce Richardson /* check for errors */ 142799a2dd95SBruce Richardson if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0')) 142899a2dd95SBruce Richardson return -1; 142999a2dd95SBruce Richardson 143099a2dd95SBruce Richardson /* make sure we don't exceed 32-bit boundary on 32-bit target */ 143199a2dd95SBruce Richardson #ifndef RTE_ARCH_64 143299a2dd95SBruce Richardson if (addr >= UINTPTR_MAX) 143399a2dd95SBruce Richardson return -1; 143499a2dd95SBruce Richardson #endif 143599a2dd95SBruce Richardson 143699a2dd95SBruce Richardson /* align the addr on 16M boundary, 16MB is the minimum huge page 143799a2dd95SBruce Richardson * size on IBM Power architecture. If the addr is aligned to 16MB, 143899a2dd95SBruce Richardson * it can align to 2MB for x86. So this alignment can also be used 143999a2dd95SBruce Richardson * on x86 and other architectures. 144099a2dd95SBruce Richardson */ 144199a2dd95SBruce Richardson internal_conf->base_virtaddr = 144299a2dd95SBruce Richardson RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M); 144399a2dd95SBruce Richardson 144499a2dd95SBruce Richardson return 0; 144599a2dd95SBruce Richardson } 144699a2dd95SBruce Richardson 144799a2dd95SBruce Richardson /* caller is responsible for freeing the returned string */ 144899a2dd95SBruce Richardson static char * 144999a2dd95SBruce Richardson available_cores(void) 145099a2dd95SBruce Richardson { 145199a2dd95SBruce Richardson char *str = NULL; 145299a2dd95SBruce Richardson int previous; 145399a2dd95SBruce Richardson int sequence; 145499a2dd95SBruce Richardson char *tmp; 145599a2dd95SBruce Richardson int idx; 145699a2dd95SBruce Richardson 145799a2dd95SBruce Richardson /* find the first available cpu */ 145899a2dd95SBruce Richardson for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 145999a2dd95SBruce Richardson if (eal_cpu_detected(idx) == 0) 146099a2dd95SBruce Richardson continue; 146199a2dd95SBruce Richardson break; 146299a2dd95SBruce Richardson } 146399a2dd95SBruce Richardson if (idx >= RTE_MAX_LCORE) 146499a2dd95SBruce Richardson return NULL; 146599a2dd95SBruce Richardson 146699a2dd95SBruce Richardson /* first sequence */ 146799a2dd95SBruce Richardson if (asprintf(&str, "%d", idx) < 0) 146899a2dd95SBruce Richardson return NULL; 146999a2dd95SBruce Richardson previous = idx; 147099a2dd95SBruce Richardson sequence = 0; 147199a2dd95SBruce Richardson 147299a2dd95SBruce Richardson for (idx++ ; idx < RTE_MAX_LCORE; idx++) { 147399a2dd95SBruce Richardson if (eal_cpu_detected(idx) == 0) 147499a2dd95SBruce Richardson continue; 147599a2dd95SBruce Richardson 147699a2dd95SBruce Richardson if (idx == previous + 1) { 147799a2dd95SBruce Richardson previous = idx; 147899a2dd95SBruce Richardson sequence = 1; 147999a2dd95SBruce Richardson continue; 148099a2dd95SBruce Richardson } 148199a2dd95SBruce Richardson 148299a2dd95SBruce Richardson /* finish current sequence */ 148399a2dd95SBruce Richardson if (sequence) { 148499a2dd95SBruce Richardson if (asprintf(&tmp, "%s-%d", str, previous) < 0) { 148599a2dd95SBruce Richardson free(str); 148699a2dd95SBruce Richardson return NULL; 148799a2dd95SBruce Richardson } 148899a2dd95SBruce Richardson free(str); 148999a2dd95SBruce Richardson str = tmp; 149099a2dd95SBruce Richardson } 149199a2dd95SBruce Richardson 149299a2dd95SBruce Richardson /* new sequence */ 149399a2dd95SBruce Richardson if (asprintf(&tmp, "%s,%d", str, idx) < 0) { 149499a2dd95SBruce Richardson free(str); 149599a2dd95SBruce Richardson return NULL; 149699a2dd95SBruce Richardson } 149799a2dd95SBruce Richardson free(str); 149899a2dd95SBruce Richardson str = tmp; 149999a2dd95SBruce Richardson previous = idx; 150099a2dd95SBruce Richardson sequence = 0; 150199a2dd95SBruce Richardson } 150299a2dd95SBruce Richardson 150399a2dd95SBruce Richardson /* finish last sequence */ 150499a2dd95SBruce Richardson if (sequence) { 150599a2dd95SBruce Richardson if (asprintf(&tmp, "%s-%d", str, previous) < 0) { 150699a2dd95SBruce Richardson free(str); 150799a2dd95SBruce Richardson return NULL; 150899a2dd95SBruce Richardson } 150999a2dd95SBruce Richardson free(str); 151099a2dd95SBruce Richardson str = tmp; 151199a2dd95SBruce Richardson } 151299a2dd95SBruce Richardson 151399a2dd95SBruce Richardson return str; 151499a2dd95SBruce Richardson } 151599a2dd95SBruce Richardson 151699a2dd95SBruce Richardson int 151799a2dd95SBruce Richardson eal_parse_common_option(int opt, const char *optarg, 151899a2dd95SBruce Richardson struct internal_config *conf) 151999a2dd95SBruce Richardson { 152099a2dd95SBruce Richardson static int b_used; 152199a2dd95SBruce Richardson static int a_used; 152299a2dd95SBruce Richardson 152399a2dd95SBruce Richardson switch (opt) { 152499a2dd95SBruce Richardson case OPT_PCI_BLACKLIST_NUM: 152599a2dd95SBruce Richardson fprintf(stderr, 152699a2dd95SBruce Richardson "Option --pci-blacklist is deprecated, use -b, --block instead\n"); 152799a2dd95SBruce Richardson /* fallthrough */ 152899a2dd95SBruce Richardson case 'b': 152999a2dd95SBruce Richardson if (a_used) 153099a2dd95SBruce Richardson goto ba_conflict; 153199a2dd95SBruce Richardson if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0) 153299a2dd95SBruce Richardson return -1; 153399a2dd95SBruce Richardson b_used = 1; 153499a2dd95SBruce Richardson break; 153599a2dd95SBruce Richardson 153699a2dd95SBruce Richardson case 'w': 153799a2dd95SBruce Richardson fprintf(stderr, 153899a2dd95SBruce Richardson "Option -w, --pci-whitelist is deprecated, use -a, --allow option instead\n"); 153999a2dd95SBruce Richardson /* fallthrough */ 154099a2dd95SBruce Richardson case 'a': 154199a2dd95SBruce Richardson if (b_used) 154299a2dd95SBruce Richardson goto ba_conflict; 154399a2dd95SBruce Richardson if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0) 154499a2dd95SBruce Richardson return -1; 154599a2dd95SBruce Richardson a_used = 1; 154699a2dd95SBruce Richardson break; 154799a2dd95SBruce Richardson /* coremask */ 154899a2dd95SBruce Richardson case 'c': { 154999a2dd95SBruce Richardson int lcore_indexes[RTE_MAX_LCORE]; 155099a2dd95SBruce Richardson 155199a2dd95SBruce Richardson if (eal_service_cores_parsed()) 155299a2dd95SBruce Richardson RTE_LOG(WARNING, EAL, 155399a2dd95SBruce Richardson "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n"); 155499a2dd95SBruce Richardson if (eal_parse_coremask(optarg, lcore_indexes) < 0) { 155599a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid coremask syntax\n"); 155699a2dd95SBruce Richardson return -1; 155799a2dd95SBruce Richardson } 155899a2dd95SBruce Richardson if (update_lcore_config(lcore_indexes) < 0) { 155999a2dd95SBruce Richardson char *available = available_cores(); 156099a2dd95SBruce Richardson 156199a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 156299a2dd95SBruce Richardson "invalid coremask, please check specified cores are part of %s\n", 156399a2dd95SBruce Richardson available); 156499a2dd95SBruce Richardson free(available); 156599a2dd95SBruce Richardson return -1; 156699a2dd95SBruce Richardson } 156799a2dd95SBruce Richardson 156899a2dd95SBruce Richardson if (core_parsed) { 156999a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n", 157099a2dd95SBruce Richardson (core_parsed == LCORE_OPT_LST) ? "-l" : 157199a2dd95SBruce Richardson (core_parsed == LCORE_OPT_MAP) ? "--lcore" : 157299a2dd95SBruce Richardson "-c"); 157399a2dd95SBruce Richardson return -1; 157499a2dd95SBruce Richardson } 157599a2dd95SBruce Richardson 157699a2dd95SBruce Richardson core_parsed = LCORE_OPT_MSK; 157799a2dd95SBruce Richardson break; 157899a2dd95SBruce Richardson } 157999a2dd95SBruce Richardson /* corelist */ 158099a2dd95SBruce Richardson case 'l': { 158199a2dd95SBruce Richardson int lcore_indexes[RTE_MAX_LCORE]; 158299a2dd95SBruce Richardson 158399a2dd95SBruce Richardson if (eal_service_cores_parsed()) 158499a2dd95SBruce Richardson RTE_LOG(WARNING, EAL, 158599a2dd95SBruce Richardson "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n"); 158699a2dd95SBruce Richardson 158799a2dd95SBruce Richardson if (eal_parse_corelist(optarg, lcore_indexes) < 0) { 158899a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid core list syntax\n"); 158999a2dd95SBruce Richardson return -1; 159099a2dd95SBruce Richardson } 159199a2dd95SBruce Richardson if (update_lcore_config(lcore_indexes) < 0) { 159299a2dd95SBruce Richardson char *available = available_cores(); 159399a2dd95SBruce Richardson 159499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 159599a2dd95SBruce Richardson "invalid core list, please check specified cores are part of %s\n", 159699a2dd95SBruce Richardson available); 159799a2dd95SBruce Richardson free(available); 159899a2dd95SBruce Richardson return -1; 159999a2dd95SBruce Richardson } 160099a2dd95SBruce Richardson 160199a2dd95SBruce Richardson if (core_parsed) { 160299a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n", 160399a2dd95SBruce Richardson (core_parsed == LCORE_OPT_MSK) ? "-c" : 160499a2dd95SBruce Richardson (core_parsed == LCORE_OPT_MAP) ? "--lcore" : 160599a2dd95SBruce Richardson "-l"); 160699a2dd95SBruce Richardson return -1; 160799a2dd95SBruce Richardson } 160899a2dd95SBruce Richardson 160999a2dd95SBruce Richardson core_parsed = LCORE_OPT_LST; 161099a2dd95SBruce Richardson break; 161199a2dd95SBruce Richardson } 161299a2dd95SBruce Richardson /* service coremask */ 161399a2dd95SBruce Richardson case 's': 161499a2dd95SBruce Richardson if (eal_parse_service_coremask(optarg) < 0) { 161599a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid service coremask\n"); 161699a2dd95SBruce Richardson return -1; 161799a2dd95SBruce Richardson } 161899a2dd95SBruce Richardson break; 161999a2dd95SBruce Richardson /* service corelist */ 162099a2dd95SBruce Richardson case 'S': 162199a2dd95SBruce Richardson if (eal_parse_service_corelist(optarg) < 0) { 162299a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid service core list\n"); 162399a2dd95SBruce Richardson return -1; 162499a2dd95SBruce Richardson } 162599a2dd95SBruce Richardson break; 162699a2dd95SBruce Richardson /* size of memory */ 162799a2dd95SBruce Richardson case 'm': 162899a2dd95SBruce Richardson conf->memory = atoi(optarg); 162999a2dd95SBruce Richardson conf->memory *= 1024ULL; 163099a2dd95SBruce Richardson conf->memory *= 1024ULL; 163199a2dd95SBruce Richardson mem_parsed = 1; 163299a2dd95SBruce Richardson break; 163399a2dd95SBruce Richardson /* force number of channels */ 163499a2dd95SBruce Richardson case 'n': 163599a2dd95SBruce Richardson conf->force_nchannel = atoi(optarg); 163699a2dd95SBruce Richardson if (conf->force_nchannel == 0) { 163799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid channel number\n"); 163899a2dd95SBruce Richardson return -1; 163999a2dd95SBruce Richardson } 164099a2dd95SBruce Richardson break; 164199a2dd95SBruce Richardson /* force number of ranks */ 164299a2dd95SBruce Richardson case 'r': 164399a2dd95SBruce Richardson conf->force_nrank = atoi(optarg); 164499a2dd95SBruce Richardson if (conf->force_nrank == 0 || 164599a2dd95SBruce Richardson conf->force_nrank > 16) { 164699a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid rank number\n"); 164799a2dd95SBruce Richardson return -1; 164899a2dd95SBruce Richardson } 164999a2dd95SBruce Richardson break; 165099a2dd95SBruce Richardson /* force loading of external driver */ 165199a2dd95SBruce Richardson case 'd': 165299a2dd95SBruce Richardson if (eal_plugin_add(optarg) == -1) 165399a2dd95SBruce Richardson return -1; 165499a2dd95SBruce Richardson break; 165599a2dd95SBruce Richardson case 'v': 165699a2dd95SBruce Richardson /* since message is explicitly requested by user, we 165799a2dd95SBruce Richardson * write message at highest log level so it can always 165899a2dd95SBruce Richardson * be seen 165999a2dd95SBruce Richardson * even if info or warning messages are disabled */ 166099a2dd95SBruce Richardson RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version()); 166199a2dd95SBruce Richardson break; 166299a2dd95SBruce Richardson 166399a2dd95SBruce Richardson /* long options */ 166499a2dd95SBruce Richardson case OPT_HUGE_UNLINK_NUM: 166599a2dd95SBruce Richardson conf->hugepage_unlink = 1; 166699a2dd95SBruce Richardson break; 166799a2dd95SBruce Richardson 166899a2dd95SBruce Richardson case OPT_NO_HUGE_NUM: 166999a2dd95SBruce Richardson conf->no_hugetlbfs = 1; 167099a2dd95SBruce Richardson /* no-huge is legacy mem */ 167199a2dd95SBruce Richardson conf->legacy_mem = 1; 167299a2dd95SBruce Richardson break; 167399a2dd95SBruce Richardson 167499a2dd95SBruce Richardson case OPT_NO_PCI_NUM: 167599a2dd95SBruce Richardson conf->no_pci = 1; 167699a2dd95SBruce Richardson break; 167799a2dd95SBruce Richardson 167899a2dd95SBruce Richardson case OPT_NO_HPET_NUM: 167999a2dd95SBruce Richardson conf->no_hpet = 1; 168099a2dd95SBruce Richardson break; 168199a2dd95SBruce Richardson 168299a2dd95SBruce Richardson case OPT_VMWARE_TSC_MAP_NUM: 168399a2dd95SBruce Richardson conf->vmware_tsc_map = 1; 168499a2dd95SBruce Richardson break; 168599a2dd95SBruce Richardson 168699a2dd95SBruce Richardson case OPT_NO_SHCONF_NUM: 168799a2dd95SBruce Richardson conf->no_shconf = 1; 168899a2dd95SBruce Richardson break; 168999a2dd95SBruce Richardson 169099a2dd95SBruce Richardson case OPT_IN_MEMORY_NUM: 169199a2dd95SBruce Richardson conf->in_memory = 1; 169299a2dd95SBruce Richardson /* in-memory is a superset of noshconf and huge-unlink */ 169399a2dd95SBruce Richardson conf->no_shconf = 1; 169499a2dd95SBruce Richardson conf->hugepage_unlink = 1; 169599a2dd95SBruce Richardson break; 169699a2dd95SBruce Richardson 169799a2dd95SBruce Richardson case OPT_PROC_TYPE_NUM: 169899a2dd95SBruce Richardson conf->process_type = eal_parse_proc_type(optarg); 169999a2dd95SBruce Richardson break; 170099a2dd95SBruce Richardson 170199a2dd95SBruce Richardson case OPT_MASTER_LCORE_NUM: 170299a2dd95SBruce Richardson fprintf(stderr, 170399a2dd95SBruce Richardson "Option --" OPT_MASTER_LCORE 170499a2dd95SBruce Richardson " is deprecated use " OPT_MAIN_LCORE "\n"); 170599a2dd95SBruce Richardson /* fallthrough */ 170699a2dd95SBruce Richardson case OPT_MAIN_LCORE_NUM: 170799a2dd95SBruce Richardson if (eal_parse_main_lcore(optarg) < 0) { 170899a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameter for --" 170999a2dd95SBruce Richardson OPT_MAIN_LCORE "\n"); 171099a2dd95SBruce Richardson return -1; 171199a2dd95SBruce Richardson } 171299a2dd95SBruce Richardson break; 171399a2dd95SBruce Richardson 171499a2dd95SBruce Richardson case OPT_VDEV_NUM: 171599a2dd95SBruce Richardson if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL, 171699a2dd95SBruce Richardson optarg) < 0) { 171799a2dd95SBruce Richardson return -1; 171899a2dd95SBruce Richardson } 171999a2dd95SBruce Richardson break; 172099a2dd95SBruce Richardson 172199a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 172299a2dd95SBruce Richardson case OPT_SYSLOG_NUM: 172399a2dd95SBruce Richardson if (eal_parse_syslog(optarg, conf) < 0) { 172499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameters for --" 172599a2dd95SBruce Richardson OPT_SYSLOG "\n"); 172699a2dd95SBruce Richardson return -1; 172799a2dd95SBruce Richardson } 172899a2dd95SBruce Richardson break; 172999a2dd95SBruce Richardson #endif 173099a2dd95SBruce Richardson 173199a2dd95SBruce Richardson case OPT_LOG_LEVEL_NUM: { 173299a2dd95SBruce Richardson if (eal_parse_log_level(optarg) < 0) { 173399a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 173499a2dd95SBruce Richardson "invalid parameters for --" 173599a2dd95SBruce Richardson OPT_LOG_LEVEL "\n"); 173699a2dd95SBruce Richardson return -1; 173799a2dd95SBruce Richardson } 173899a2dd95SBruce Richardson break; 173999a2dd95SBruce Richardson } 174099a2dd95SBruce Richardson 174199a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 174299a2dd95SBruce Richardson case OPT_TRACE_NUM: { 174399a2dd95SBruce Richardson if (eal_trace_args_save(optarg) < 0) { 174499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameters for --" 174599a2dd95SBruce Richardson OPT_TRACE "\n"); 174699a2dd95SBruce Richardson return -1; 174799a2dd95SBruce Richardson } 174899a2dd95SBruce Richardson break; 174999a2dd95SBruce Richardson } 175099a2dd95SBruce Richardson 175199a2dd95SBruce Richardson case OPT_TRACE_DIR_NUM: { 175299a2dd95SBruce Richardson if (eal_trace_dir_args_save(optarg) < 0) { 175399a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameters for --" 175499a2dd95SBruce Richardson OPT_TRACE_DIR "\n"); 175599a2dd95SBruce Richardson return -1; 175699a2dd95SBruce Richardson } 175799a2dd95SBruce Richardson break; 175899a2dd95SBruce Richardson } 175999a2dd95SBruce Richardson 176099a2dd95SBruce Richardson case OPT_TRACE_BUF_SIZE_NUM: { 176199a2dd95SBruce Richardson if (eal_trace_bufsz_args_save(optarg) < 0) { 176299a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameters for --" 176399a2dd95SBruce Richardson OPT_TRACE_BUF_SIZE "\n"); 176499a2dd95SBruce Richardson return -1; 176599a2dd95SBruce Richardson } 176699a2dd95SBruce Richardson break; 176799a2dd95SBruce Richardson } 176899a2dd95SBruce Richardson 176999a2dd95SBruce Richardson case OPT_TRACE_MODE_NUM: { 177099a2dd95SBruce Richardson if (eal_trace_mode_args_save(optarg) < 0) { 177199a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameters for --" 177299a2dd95SBruce Richardson OPT_TRACE_MODE "\n"); 177399a2dd95SBruce Richardson return -1; 177499a2dd95SBruce Richardson } 177599a2dd95SBruce Richardson break; 177699a2dd95SBruce Richardson } 177799a2dd95SBruce Richardson #endif /* !RTE_EXEC_ENV_WINDOWS */ 177899a2dd95SBruce Richardson 177999a2dd95SBruce Richardson case OPT_LCORES_NUM: 178099a2dd95SBruce Richardson if (eal_parse_lcores(optarg) < 0) { 178199a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameter for --" 178299a2dd95SBruce Richardson OPT_LCORES "\n"); 178399a2dd95SBruce Richardson return -1; 178499a2dd95SBruce Richardson } 178599a2dd95SBruce Richardson 178699a2dd95SBruce Richardson if (core_parsed) { 178799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n", 178899a2dd95SBruce Richardson (core_parsed == LCORE_OPT_LST) ? "-l" : 178999a2dd95SBruce Richardson (core_parsed == LCORE_OPT_MSK) ? "-c" : 179099a2dd95SBruce Richardson "--lcore"); 179199a2dd95SBruce Richardson return -1; 179299a2dd95SBruce Richardson } 179399a2dd95SBruce Richardson 179499a2dd95SBruce Richardson core_parsed = LCORE_OPT_MAP; 179599a2dd95SBruce Richardson break; 179699a2dd95SBruce Richardson case OPT_LEGACY_MEM_NUM: 179799a2dd95SBruce Richardson conf->legacy_mem = 1; 179899a2dd95SBruce Richardson break; 179999a2dd95SBruce Richardson case OPT_SINGLE_FILE_SEGMENTS_NUM: 180099a2dd95SBruce Richardson conf->single_file_segments = 1; 180199a2dd95SBruce Richardson break; 180299a2dd95SBruce Richardson case OPT_IOVA_MODE_NUM: 180399a2dd95SBruce Richardson if (eal_parse_iova_mode(optarg) < 0) { 180499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameters for --" 180599a2dd95SBruce Richardson OPT_IOVA_MODE "\n"); 180699a2dd95SBruce Richardson return -1; 180799a2dd95SBruce Richardson } 180899a2dd95SBruce Richardson break; 180999a2dd95SBruce Richardson case OPT_BASE_VIRTADDR_NUM: 181099a2dd95SBruce Richardson if (eal_parse_base_virtaddr(optarg) < 0) { 181199a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameter for --" 181299a2dd95SBruce Richardson OPT_BASE_VIRTADDR "\n"); 181399a2dd95SBruce Richardson return -1; 181499a2dd95SBruce Richardson } 181599a2dd95SBruce Richardson break; 181699a2dd95SBruce Richardson case OPT_TELEMETRY_NUM: 181799a2dd95SBruce Richardson break; 181899a2dd95SBruce Richardson case OPT_NO_TELEMETRY_NUM: 181999a2dd95SBruce Richardson conf->no_telemetry = 1; 182099a2dd95SBruce Richardson break; 182199a2dd95SBruce Richardson case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM: 182299a2dd95SBruce Richardson if (eal_parse_simd_bitwidth(optarg) < 0) { 182399a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "invalid parameter for --" 182499a2dd95SBruce Richardson OPT_FORCE_MAX_SIMD_BITWIDTH "\n"); 182599a2dd95SBruce Richardson return -1; 182699a2dd95SBruce Richardson } 182799a2dd95SBruce Richardson break; 182899a2dd95SBruce Richardson 182999a2dd95SBruce Richardson /* don't know what to do, leave this to caller */ 183099a2dd95SBruce Richardson default: 183199a2dd95SBruce Richardson return 1; 183299a2dd95SBruce Richardson 183399a2dd95SBruce Richardson } 183499a2dd95SBruce Richardson 183599a2dd95SBruce Richardson return 0; 183699a2dd95SBruce Richardson 183799a2dd95SBruce Richardson ba_conflict: 183899a2dd95SBruce Richardson RTE_LOG(ERR, EAL, 183999a2dd95SBruce Richardson "Options allow (-a) and block (-b) can't be used at the same time\n"); 184099a2dd95SBruce Richardson return -1; 184199a2dd95SBruce Richardson } 184299a2dd95SBruce Richardson 184399a2dd95SBruce Richardson static void 184499a2dd95SBruce Richardson eal_auto_detect_cores(struct rte_config *cfg) 184599a2dd95SBruce Richardson { 184699a2dd95SBruce Richardson unsigned int lcore_id; 184799a2dd95SBruce Richardson unsigned int removed = 0; 184899a2dd95SBruce Richardson rte_cpuset_t affinity_set; 184999a2dd95SBruce Richardson 185099a2dd95SBruce Richardson if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t), 185199a2dd95SBruce Richardson &affinity_set)) 185299a2dd95SBruce Richardson CPU_ZERO(&affinity_set); 185399a2dd95SBruce Richardson 185499a2dd95SBruce Richardson for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 185599a2dd95SBruce Richardson if (cfg->lcore_role[lcore_id] == ROLE_RTE && 185699a2dd95SBruce Richardson !CPU_ISSET(lcore_id, &affinity_set)) { 185799a2dd95SBruce Richardson cfg->lcore_role[lcore_id] = ROLE_OFF; 185899a2dd95SBruce Richardson removed++; 185999a2dd95SBruce Richardson } 186099a2dd95SBruce Richardson } 186199a2dd95SBruce Richardson 186299a2dd95SBruce Richardson cfg->lcore_count -= removed; 186399a2dd95SBruce Richardson } 186499a2dd95SBruce Richardson 186599a2dd95SBruce Richardson static void 186699a2dd95SBruce Richardson compute_ctrl_threads_cpuset(struct internal_config *internal_cfg) 186799a2dd95SBruce Richardson { 186899a2dd95SBruce Richardson rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset; 186999a2dd95SBruce Richardson rte_cpuset_t default_set; 187099a2dd95SBruce Richardson unsigned int lcore_id; 187199a2dd95SBruce Richardson 187299a2dd95SBruce Richardson for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 187399a2dd95SBruce Richardson if (rte_lcore_has_role(lcore_id, ROLE_OFF)) 187499a2dd95SBruce Richardson continue; 187599a2dd95SBruce Richardson RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset); 187699a2dd95SBruce Richardson } 187799a2dd95SBruce Richardson RTE_CPU_NOT(cpuset, cpuset); 187899a2dd95SBruce Richardson 187999a2dd95SBruce Richardson if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t), 188099a2dd95SBruce Richardson &default_set)) 188199a2dd95SBruce Richardson CPU_ZERO(&default_set); 188299a2dd95SBruce Richardson 188399a2dd95SBruce Richardson RTE_CPU_AND(cpuset, cpuset, &default_set); 188499a2dd95SBruce Richardson 188599a2dd95SBruce Richardson /* if no remaining cpu, use main lcore cpu affinity */ 188699a2dd95SBruce Richardson if (!CPU_COUNT(cpuset)) { 188799a2dd95SBruce Richardson memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset, 188899a2dd95SBruce Richardson sizeof(*cpuset)); 188999a2dd95SBruce Richardson } 189099a2dd95SBruce Richardson } 189199a2dd95SBruce Richardson 189299a2dd95SBruce Richardson int 189399a2dd95SBruce Richardson eal_cleanup_config(struct internal_config *internal_cfg) 189499a2dd95SBruce Richardson { 189599a2dd95SBruce Richardson if (internal_cfg->hugefile_prefix != NULL) 189699a2dd95SBruce Richardson free(internal_cfg->hugefile_prefix); 189799a2dd95SBruce Richardson if (internal_cfg->hugepage_dir != NULL) 189899a2dd95SBruce Richardson free(internal_cfg->hugepage_dir); 189999a2dd95SBruce Richardson if (internal_cfg->user_mbuf_pool_ops_name != NULL) 190099a2dd95SBruce Richardson free(internal_cfg->user_mbuf_pool_ops_name); 190199a2dd95SBruce Richardson 190299a2dd95SBruce Richardson return 0; 190399a2dd95SBruce Richardson } 190499a2dd95SBruce Richardson 190599a2dd95SBruce Richardson int 190699a2dd95SBruce Richardson eal_adjust_config(struct internal_config *internal_cfg) 190799a2dd95SBruce Richardson { 190899a2dd95SBruce Richardson int i; 190999a2dd95SBruce Richardson struct rte_config *cfg = rte_eal_get_configuration(); 191099a2dd95SBruce Richardson struct internal_config *internal_conf = 191199a2dd95SBruce Richardson eal_get_internal_configuration(); 191299a2dd95SBruce Richardson 191399a2dd95SBruce Richardson if (!core_parsed) 191499a2dd95SBruce Richardson eal_auto_detect_cores(cfg); 191599a2dd95SBruce Richardson 191699a2dd95SBruce Richardson if (internal_conf->process_type == RTE_PROC_AUTO) 191799a2dd95SBruce Richardson internal_conf->process_type = eal_proc_type_detect(); 191899a2dd95SBruce Richardson 191999a2dd95SBruce Richardson /* default main lcore is the first one */ 192099a2dd95SBruce Richardson if (!main_lcore_parsed) { 192199a2dd95SBruce Richardson cfg->main_lcore = rte_get_next_lcore(-1, 0, 0); 192299a2dd95SBruce Richardson if (cfg->main_lcore >= RTE_MAX_LCORE) 192399a2dd95SBruce Richardson return -1; 192499a2dd95SBruce Richardson lcore_config[cfg->main_lcore].core_role = ROLE_RTE; 192599a2dd95SBruce Richardson } 192699a2dd95SBruce Richardson 192799a2dd95SBruce Richardson compute_ctrl_threads_cpuset(internal_cfg); 192899a2dd95SBruce Richardson 192999a2dd95SBruce Richardson /* if no memory amounts were requested, this will result in 0 and 193099a2dd95SBruce Richardson * will be overridden later, right after eal_hugepage_info_init() */ 193199a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_NUMA_NODES; i++) 193299a2dd95SBruce Richardson internal_cfg->memory += internal_cfg->socket_mem[i]; 193399a2dd95SBruce Richardson 193499a2dd95SBruce Richardson return 0; 193599a2dd95SBruce Richardson } 193699a2dd95SBruce Richardson 193799a2dd95SBruce Richardson int 193899a2dd95SBruce Richardson eal_check_common_options(struct internal_config *internal_cfg) 193999a2dd95SBruce Richardson { 194099a2dd95SBruce Richardson struct rte_config *cfg = rte_eal_get_configuration(); 194199a2dd95SBruce Richardson const struct internal_config *internal_conf = 194299a2dd95SBruce Richardson eal_get_internal_configuration(); 194399a2dd95SBruce Richardson 194499a2dd95SBruce Richardson if (cfg->lcore_role[cfg->main_lcore] != ROLE_RTE) { 194599a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Main lcore is not enabled for DPDK\n"); 194699a2dd95SBruce Richardson return -1; 194799a2dd95SBruce Richardson } 194899a2dd95SBruce Richardson 194999a2dd95SBruce Richardson if (internal_cfg->process_type == RTE_PROC_INVALID) { 195099a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Invalid process type specified\n"); 195199a2dd95SBruce Richardson return -1; 195299a2dd95SBruce Richardson } 195399a2dd95SBruce Richardson if (internal_cfg->hugefile_prefix != NULL && 195499a2dd95SBruce Richardson strlen(internal_cfg->hugefile_prefix) < 1) { 195599a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n"); 195699a2dd95SBruce Richardson return -1; 195799a2dd95SBruce Richardson } 195899a2dd95SBruce Richardson if (internal_cfg->hugepage_dir != NULL && 195999a2dd95SBruce Richardson strlen(internal_cfg->hugepage_dir) < 1) { 196099a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n"); 196199a2dd95SBruce Richardson return -1; 196299a2dd95SBruce Richardson } 196399a2dd95SBruce Richardson if (internal_cfg->user_mbuf_pool_ops_name != NULL && 196499a2dd95SBruce Richardson strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) { 196599a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n"); 196699a2dd95SBruce Richardson return -1; 196799a2dd95SBruce Richardson } 196899a2dd95SBruce Richardson if (strchr(eal_get_hugefile_prefix(), '%') != NULL) { 196999a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" " 197099a2dd95SBruce Richardson "option\n"); 197199a2dd95SBruce Richardson return -1; 197299a2dd95SBruce Richardson } 197399a2dd95SBruce Richardson if (mem_parsed && internal_cfg->force_sockets == 1) { 197499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot " 197599a2dd95SBruce Richardson "be specified at the same time\n"); 197699a2dd95SBruce Richardson return -1; 197799a2dd95SBruce Richardson } 197899a2dd95SBruce Richardson if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) { 197999a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot " 198099a2dd95SBruce Richardson "be specified together with --"OPT_NO_HUGE"\n"); 198199a2dd95SBruce Richardson return -1; 198299a2dd95SBruce Richardson } 198399a2dd95SBruce Richardson if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink && 198499a2dd95SBruce Richardson !internal_cfg->in_memory) { 198599a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot " 198699a2dd95SBruce Richardson "be specified together with --"OPT_NO_HUGE"\n"); 198799a2dd95SBruce Richardson return -1; 198899a2dd95SBruce Richardson } 198999a2dd95SBruce Richardson if (internal_conf->force_socket_limits && internal_conf->legacy_mem) { 199099a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT 199199a2dd95SBruce Richardson " is only supported in non-legacy memory mode\n"); 199299a2dd95SBruce Richardson } 199399a2dd95SBruce Richardson if (internal_cfg->single_file_segments && 199499a2dd95SBruce Richardson internal_cfg->hugepage_unlink && 199599a2dd95SBruce Richardson !internal_cfg->in_memory) { 199699a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is " 199799a2dd95SBruce Richardson "not compatible with --"OPT_HUGE_UNLINK"\n"); 199899a2dd95SBruce Richardson return -1; 199999a2dd95SBruce Richardson } 200099a2dd95SBruce Richardson if (internal_cfg->legacy_mem && 200199a2dd95SBruce Richardson internal_cfg->in_memory) { 200299a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible " 200399a2dd95SBruce Richardson "with --"OPT_IN_MEMORY"\n"); 200499a2dd95SBruce Richardson return -1; 200599a2dd95SBruce Richardson } 200699a2dd95SBruce Richardson if (internal_cfg->legacy_mem && internal_cfg->match_allocations) { 200799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible " 200899a2dd95SBruce Richardson "with --"OPT_MATCH_ALLOCATIONS"\n"); 200999a2dd95SBruce Richardson return -1; 201099a2dd95SBruce Richardson } 201199a2dd95SBruce Richardson if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) { 201299a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible " 201399a2dd95SBruce Richardson "with --"OPT_MATCH_ALLOCATIONS"\n"); 201499a2dd95SBruce Richardson return -1; 201599a2dd95SBruce Richardson } 201699a2dd95SBruce Richardson if (internal_cfg->legacy_mem && internal_cfg->memory == 0) { 201799a2dd95SBruce Richardson RTE_LOG(NOTICE, EAL, "Static memory layout is selected, " 201899a2dd95SBruce Richardson "amount of reserved memory can be adjusted with " 201999a2dd95SBruce Richardson "-m or --"OPT_SOCKET_MEM"\n"); 202099a2dd95SBruce Richardson } 202199a2dd95SBruce Richardson 202299a2dd95SBruce Richardson return 0; 202399a2dd95SBruce Richardson } 202499a2dd95SBruce Richardson 202599a2dd95SBruce Richardson uint16_t 202699a2dd95SBruce Richardson rte_vect_get_max_simd_bitwidth(void) 202799a2dd95SBruce Richardson { 202899a2dd95SBruce Richardson const struct internal_config *internal_conf = 202999a2dd95SBruce Richardson eal_get_internal_configuration(); 203099a2dd95SBruce Richardson return internal_conf->max_simd_bitwidth.bitwidth; 203199a2dd95SBruce Richardson } 203299a2dd95SBruce Richardson 203399a2dd95SBruce Richardson int 203499a2dd95SBruce Richardson rte_vect_set_max_simd_bitwidth(uint16_t bitwidth) 203599a2dd95SBruce Richardson { 203699a2dd95SBruce Richardson struct internal_config *internal_conf = 203799a2dd95SBruce Richardson eal_get_internal_configuration(); 203899a2dd95SBruce Richardson if (internal_conf->max_simd_bitwidth.forced) { 203999a2dd95SBruce Richardson RTE_LOG(NOTICE, EAL, "Cannot set max SIMD bitwidth - user runtime override enabled"); 204099a2dd95SBruce Richardson return -EPERM; 204199a2dd95SBruce Richardson } 204299a2dd95SBruce Richardson 204399a2dd95SBruce Richardson if (bitwidth < RTE_VECT_SIMD_DISABLED || !rte_is_power_of_2(bitwidth)) { 204499a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "Invalid bitwidth value!\n"); 204599a2dd95SBruce Richardson return -EINVAL; 204699a2dd95SBruce Richardson } 204799a2dd95SBruce Richardson internal_conf->max_simd_bitwidth.bitwidth = bitwidth; 204899a2dd95SBruce Richardson return 0; 204999a2dd95SBruce Richardson } 205099a2dd95SBruce Richardson 205199a2dd95SBruce Richardson void 205299a2dd95SBruce Richardson eal_common_usage(void) 205399a2dd95SBruce Richardson { 205499a2dd95SBruce Richardson printf("[options]\n\n" 205599a2dd95SBruce Richardson "EAL common options:\n" 205699a2dd95SBruce Richardson " -c COREMASK Hexadecimal bitmask of cores to run on\n" 205799a2dd95SBruce Richardson " -l CORELIST List of cores to run on\n" 205899a2dd95SBruce Richardson " The argument format is <c1>[-c2][,c3[-c4],...]\n" 205999a2dd95SBruce Richardson " where c1, c2, etc are core indexes between 0 and %d\n" 206099a2dd95SBruce Richardson " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n" 206199a2dd95SBruce Richardson " The argument format is\n" 206299a2dd95SBruce Richardson " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n" 206399a2dd95SBruce Richardson " lcores and cpus list are grouped by '(' and ')'\n" 206499a2dd95SBruce Richardson " Within the group, '-' is used for range separator,\n" 206599a2dd95SBruce Richardson " ',' is used for single number separator.\n" 206699a2dd95SBruce Richardson " '( )' can be omitted for single element group,\n" 206799a2dd95SBruce Richardson " '@' can be omitted if cpus and lcores have the same value\n" 206899a2dd95SBruce Richardson " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n" 206999a2dd95SBruce Richardson " --"OPT_MAIN_LCORE" ID Core ID that is used as main\n" 207099a2dd95SBruce Richardson " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n" 207199a2dd95SBruce Richardson " -n CHANNELS Number of memory channels\n" 207299a2dd95SBruce Richardson " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n" 207399a2dd95SBruce Richardson " -r RANKS Force number of memory ranks (don't detect)\n" 207499a2dd95SBruce Richardson " -b, --block Add a device to the blocked list.\n" 207599a2dd95SBruce Richardson " Prevent EAL from using this device. The argument\n" 207699a2dd95SBruce Richardson " format for PCI devices is <domain:bus:devid.func>.\n" 207799a2dd95SBruce Richardson " -a, --allow Add a device to the allow list.\n" 207899a2dd95SBruce Richardson " Only use the specified devices. The argument format\n" 207999a2dd95SBruce Richardson " for PCI devices is <[domain:]bus:devid.func>.\n" 208099a2dd95SBruce Richardson " This option can be present several times.\n" 208199a2dd95SBruce Richardson " [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n" 208299a2dd95SBruce Richardson " --"OPT_VDEV" Add a virtual device.\n" 208399a2dd95SBruce Richardson " The argument format is <driver><id>[,key=val,...]\n" 208499a2dd95SBruce Richardson " (ex: --vdev=net_pcap0,iface=eth2).\n" 208599a2dd95SBruce Richardson " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n" 208699a2dd95SBruce Richardson " 'va' for IOVA_VA\n" 208799a2dd95SBruce Richardson " -d LIB.so|DIR Add a driver or driver directory\n" 208899a2dd95SBruce Richardson " (can be used multiple times)\n" 208999a2dd95SBruce Richardson " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" 209099a2dd95SBruce Richardson " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" 209199a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 209299a2dd95SBruce Richardson " --"OPT_SYSLOG" Set syslog facility\n" 209399a2dd95SBruce Richardson #endif 209499a2dd95SBruce Richardson " --"OPT_LOG_LEVEL"=<level> Set global log level\n" 209599a2dd95SBruce Richardson " --"OPT_LOG_LEVEL"=<type-match>:<level>\n" 209699a2dd95SBruce Richardson " Set specific log level\n" 209799a2dd95SBruce Richardson " --"OPT_LOG_LEVEL"=help Show log types and levels\n" 209899a2dd95SBruce Richardson #ifndef RTE_EXEC_ENV_WINDOWS 209999a2dd95SBruce Richardson " --"OPT_TRACE"=<regex-match>\n" 210099a2dd95SBruce Richardson " Enable trace based on regular expression trace name.\n" 210199a2dd95SBruce Richardson " By default, the trace is disabled.\n" 210299a2dd95SBruce Richardson " User must specify this option to enable trace.\n" 210399a2dd95SBruce Richardson " --"OPT_TRACE_DIR"=<directory path>\n" 210499a2dd95SBruce Richardson " Specify trace directory for trace output.\n" 210599a2dd95SBruce Richardson " By default, trace output will created at\n" 210699a2dd95SBruce Richardson " $HOME directory and parameter must be\n" 210799a2dd95SBruce Richardson " specified once only.\n" 210899a2dd95SBruce Richardson " --"OPT_TRACE_BUF_SIZE"=<int>\n" 210999a2dd95SBruce Richardson " Specify maximum size of allocated memory\n" 211099a2dd95SBruce Richardson " for trace output for each thread. Valid\n" 211199a2dd95SBruce Richardson " unit can be either 'B|K|M' for 'Bytes',\n" 211299a2dd95SBruce Richardson " 'KBytes' and 'MBytes' respectively.\n" 211399a2dd95SBruce Richardson " Default is 1MB and parameter must be\n" 211499a2dd95SBruce Richardson " specified once only.\n" 211599a2dd95SBruce Richardson " --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n" 211699a2dd95SBruce Richardson " Specify the mode of update of trace\n" 211799a2dd95SBruce Richardson " output file. Either update on a file can\n" 211899a2dd95SBruce Richardson " be wrapped or discarded when file size\n" 211999a2dd95SBruce Richardson " reaches its maximum limit.\n" 212099a2dd95SBruce Richardson " Default mode is 'overwrite' and parameter\n" 212199a2dd95SBruce Richardson " must be specified once only.\n" 212299a2dd95SBruce Richardson #endif /* !RTE_EXEC_ENV_WINDOWS */ 212399a2dd95SBruce Richardson " -v Display version information on startup\n" 212499a2dd95SBruce Richardson " -h, --help This help\n" 212599a2dd95SBruce Richardson " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n" 212699a2dd95SBruce Richardson " disable secondary process support\n" 212799a2dd95SBruce Richardson " --"OPT_BASE_VIRTADDR" Base virtual address\n" 212899a2dd95SBruce Richardson " --"OPT_TELEMETRY" Enable telemetry support (on by default)\n" 212999a2dd95SBruce Richardson " --"OPT_NO_TELEMETRY" Disable telemetry support\n" 213099a2dd95SBruce Richardson " --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n" 213199a2dd95SBruce Richardson "\nEAL options for DEBUG use only:\n" 213299a2dd95SBruce Richardson " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n" 213399a2dd95SBruce Richardson " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n" 213499a2dd95SBruce Richardson " --"OPT_NO_PCI" Disable PCI\n" 213599a2dd95SBruce Richardson " --"OPT_NO_HPET" Disable HPET\n" 213699a2dd95SBruce Richardson " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n" 213799a2dd95SBruce Richardson "\n", RTE_MAX_LCORE); 213899a2dd95SBruce Richardson } 2139