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