1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2010-2014 Intel Corporation. 3 * Copyright(c) 2014 6WIND S.A. 4 */ 5 6 #include <stdlib.h> 7 #include <string.h> 8 #include <pthread.h> 9 #ifndef RTE_EXEC_ENV_WINDOWS 10 #include <syslog.h> 11 #endif 12 #include <ctype.h> 13 #include <limits.h> 14 #include <errno.h> 15 #include <getopt.h> 16 #ifndef RTE_EXEC_ENV_WINDOWS 17 #include <dlfcn.h> 18 #include <libgen.h> 19 #endif 20 #include <sys/stat.h> 21 #ifndef RTE_EXEC_ENV_WINDOWS 22 #include <dirent.h> 23 #endif 24 25 #include <rte_string_fns.h> 26 #include <rte_eal.h> 27 #include <rte_log.h> 28 #include <rte_lcore.h> 29 #include <rte_memory.h> 30 #include <rte_tailq.h> 31 #include <rte_version.h> 32 #include <rte_devargs.h> 33 #include <rte_memcpy.h> 34 #ifndef RTE_EXEC_ENV_WINDOWS 35 #include <rte_telemetry.h> 36 #endif 37 #include <rte_vect.h> 38 39 #include "eal_internal_cfg.h" 40 #include "eal_options.h" 41 #include "eal_filesystem.h" 42 #include "eal_private.h" 43 #include "log_internal.h" 44 #ifndef RTE_EXEC_ENV_WINDOWS 45 #include "eal_trace.h" 46 #endif 47 48 #define BITS_PER_HEX 4 49 #define LCORE_OPT_LST 1 50 #define LCORE_OPT_MSK 2 51 #define LCORE_OPT_MAP 3 52 53 const char 54 eal_short_options[] = 55 "a:" /* allow */ 56 "b:" /* block */ 57 "c:" /* coremask */ 58 "s:" /* service coremask */ 59 "d:" /* driver */ 60 "h" /* help */ 61 "l:" /* corelist */ 62 "S:" /* service corelist */ 63 "m:" /* memory size */ 64 "n:" /* memory channels */ 65 "r:" /* memory ranks */ 66 "v" /* version */ 67 ; 68 69 const struct option 70 eal_long_options[] = { 71 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM }, 72 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM }, 73 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM }, 74 {OPT_HELP, 0, NULL, OPT_HELP_NUM }, 75 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM }, 76 {OPT_HUGE_UNLINK, 2, NULL, OPT_HUGE_UNLINK_NUM }, 77 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM }, 78 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM }, 79 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM }, 80 {OPT_TRACE, 1, NULL, OPT_TRACE_NUM }, 81 {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM }, 82 {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM }, 83 {OPT_TRACE_MODE, 1, NULL, OPT_TRACE_MODE_NUM }, 84 {OPT_MAIN_LCORE, 1, NULL, OPT_MAIN_LCORE_NUM }, 85 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM}, 86 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM }, 87 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM }, 88 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM }, 89 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM }, 90 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM }, 91 {OPT_DEV_BLOCK, 1, NULL, OPT_DEV_BLOCK_NUM }, 92 {OPT_DEV_ALLOW, 1, NULL, OPT_DEV_ALLOW_NUM }, 93 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM }, 94 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM }, 95 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM }, 96 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM }, 97 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM }, 98 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM }, 99 {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM }, 100 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM }, 101 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM }, 102 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM}, 103 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM}, 104 {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM }, 105 {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM }, 106 {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM}, 107 {OPT_HUGE_WORKER_STACK, 2, NULL, OPT_HUGE_WORKER_STACK_NUM }, 108 109 {0, 0, NULL, 0 } 110 }; 111 112 TAILQ_HEAD(shared_driver_list, shared_driver); 113 114 /* Definition for shared object drivers. */ 115 struct shared_driver { 116 TAILQ_ENTRY(shared_driver) next; 117 118 char name[PATH_MAX]; 119 void* lib_handle; 120 }; 121 122 /* List of external loadable drivers */ 123 static struct shared_driver_list solib_list = 124 TAILQ_HEAD_INITIALIZER(solib_list); 125 126 #ifndef RTE_EXEC_ENV_WINDOWS 127 /* Default path of external loadable drivers */ 128 static const char *default_solib_dir = RTE_EAL_PMD_PATH; 129 #endif 130 131 /* 132 * Stringified version of solib path used by dpdk-pmdinfo.py 133 * Note: PLEASE DO NOT ALTER THIS without making a corresponding 134 * change to usertools/dpdk-pmdinfo.py 135 */ 136 static const char dpdk_solib_path[] __rte_used = 137 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH; 138 139 TAILQ_HEAD(device_option_list, device_option); 140 141 struct device_option { 142 TAILQ_ENTRY(device_option) next; 143 144 enum rte_devtype type; 145 char arg[]; 146 }; 147 148 static struct device_option_list devopt_list = 149 TAILQ_HEAD_INITIALIZER(devopt_list); 150 151 static int main_lcore_parsed; 152 static int mem_parsed; 153 static int core_parsed; 154 155 /* Allow the application to print its usage message too if set */ 156 static rte_usage_hook_t rte_application_usage_hook; 157 158 /* Returns rte_usage_hook_t */ 159 rte_usage_hook_t 160 eal_get_application_usage_hook(void) 161 { 162 return rte_application_usage_hook; 163 } 164 165 /* Set a per-application usage message */ 166 rte_usage_hook_t 167 rte_set_application_usage_hook(rte_usage_hook_t usage_func) 168 { 169 rte_usage_hook_t old_func; 170 171 /* Will be NULL on the first call to denote the last usage routine. */ 172 old_func = rte_application_usage_hook; 173 rte_application_usage_hook = usage_func; 174 175 return old_func; 176 } 177 178 #ifndef RTE_EXEC_ENV_WINDOWS 179 static char **eal_args; 180 static char **eal_app_args; 181 182 #define EAL_PARAM_REQ "/eal/params" 183 #define EAL_APP_PARAM_REQ "/eal/app_params" 184 185 /* callback handler for telemetry library to report out EAL flags */ 186 int 187 handle_eal_info_request(const char *cmd, const char *params __rte_unused, 188 struct rte_tel_data *d) 189 { 190 char **args; 191 int used = 0; 192 int i = 0; 193 194 if (strcmp(cmd, EAL_PARAM_REQ) == 0) 195 args = eal_args; 196 else 197 args = eal_app_args; 198 199 rte_tel_data_start_array(d, RTE_TEL_STRING_VAL); 200 if (args == NULL || args[0] == NULL) 201 return 0; 202 203 for ( ; args[i] != NULL; i++) 204 used = rte_tel_data_add_array_string(d, args[i]); 205 return used; 206 } 207 208 int 209 eal_save_args(int argc, char **argv) 210 { 211 int i, j; 212 213 rte_telemetry_register_cmd(EAL_PARAM_REQ, handle_eal_info_request, 214 "Returns EAL commandline parameters used. Takes no parameters"); 215 rte_telemetry_register_cmd(EAL_APP_PARAM_REQ, handle_eal_info_request, 216 "Returns app commandline parameters used. Takes no parameters"); 217 218 /* clone argv to report out later. We overprovision, but 219 * this does not waste huge amounts of memory 220 */ 221 eal_args = calloc(argc + 1, sizeof(*eal_args)); 222 if (eal_args == NULL) 223 return -1; 224 225 for (i = 0; i < argc; i++) { 226 if (strcmp(argv[i], "--") == 0) 227 break; 228 eal_args[i] = strdup(argv[i]); 229 if (eal_args[i] == NULL) 230 goto error; 231 } 232 eal_args[i++] = NULL; /* always finish with NULL */ 233 234 /* allow reporting of any app args we know about too */ 235 if (i >= argc) 236 return 0; 237 238 eal_app_args = calloc(argc - i + 1, sizeof(*eal_args)); 239 if (eal_app_args == NULL) 240 goto error; 241 242 for (j = 0; i < argc; j++, i++) { 243 eal_app_args[j] = strdup(argv[i]); 244 if (eal_app_args[j] == NULL) 245 goto error; 246 } 247 eal_app_args[j] = NULL; 248 249 return 0; 250 251 error: 252 if (eal_app_args != NULL) { 253 i = 0; 254 while (eal_app_args[i] != NULL) 255 free(eal_app_args[i++]); 256 free(eal_app_args); 257 eal_app_args = NULL; 258 } 259 i = 0; 260 while (eal_args[i] != NULL) 261 free(eal_args[i++]); 262 free(eal_args); 263 eal_args = NULL; 264 return -1; 265 } 266 #endif 267 268 static int 269 eal_option_device_add(enum rte_devtype type, const char *optarg) 270 { 271 struct device_option *devopt; 272 size_t optlen; 273 int ret; 274 275 optlen = strlen(optarg) + 1; 276 devopt = calloc(1, sizeof(*devopt) + optlen); 277 if (devopt == NULL) { 278 EAL_LOG(ERR, "Unable to allocate device option"); 279 return -ENOMEM; 280 } 281 282 devopt->type = type; 283 ret = strlcpy(devopt->arg, optarg, optlen); 284 if (ret < 0) { 285 EAL_LOG(ERR, "Unable to copy device option"); 286 free(devopt); 287 return -EINVAL; 288 } 289 TAILQ_INSERT_TAIL(&devopt_list, devopt, next); 290 return 0; 291 } 292 293 int 294 eal_option_device_parse(void) 295 { 296 struct device_option *devopt; 297 void *tmp; 298 int ret = 0; 299 300 RTE_TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) { 301 if (ret == 0) { 302 ret = rte_devargs_add(devopt->type, devopt->arg); 303 if (ret) 304 EAL_LOG(ERR, "Unable to parse device '%s'", 305 devopt->arg); 306 } 307 TAILQ_REMOVE(&devopt_list, devopt, next); 308 free(devopt); 309 } 310 return ret; 311 } 312 313 const char * 314 eal_get_hugefile_prefix(void) 315 { 316 const struct internal_config *internal_conf = 317 eal_get_internal_configuration(); 318 319 if (internal_conf->hugefile_prefix != NULL) 320 return internal_conf->hugefile_prefix; 321 return HUGEFILE_PREFIX_DEFAULT; 322 } 323 324 void 325 eal_reset_internal_config(struct internal_config *internal_cfg) 326 { 327 int i; 328 329 internal_cfg->memory = 0; 330 internal_cfg->force_nrank = 0; 331 internal_cfg->force_nchannel = 0; 332 internal_cfg->hugefile_prefix = NULL; 333 internal_cfg->hugepage_dir = NULL; 334 internal_cfg->hugepage_file.unlink_before_mapping = false; 335 internal_cfg->hugepage_file.unlink_existing = true; 336 internal_cfg->force_sockets = 0; 337 /* zero out the NUMA config */ 338 for (i = 0; i < RTE_MAX_NUMA_NODES; i++) 339 internal_cfg->socket_mem[i] = 0; 340 internal_cfg->force_socket_limits = 0; 341 /* zero out the NUMA limits config */ 342 for (i = 0; i < RTE_MAX_NUMA_NODES; i++) 343 internal_cfg->socket_limit[i] = 0; 344 /* zero out hugedir descriptors */ 345 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) { 346 memset(&internal_cfg->hugepage_info[i], 0, 347 sizeof(internal_cfg->hugepage_info[0])); 348 internal_cfg->hugepage_info[i].lock_descriptor = -1; 349 } 350 internal_cfg->base_virtaddr = 0; 351 352 #ifdef LOG_DAEMON 353 internal_cfg->syslog_facility = LOG_DAEMON; 354 #endif 355 356 /* if set to NONE, interrupt mode is determined automatically */ 357 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE; 358 memset(internal_cfg->vfio_vf_token, 0, 359 sizeof(internal_cfg->vfio_vf_token)); 360 361 #ifdef RTE_LIBEAL_USE_HPET 362 internal_cfg->no_hpet = 0; 363 #else 364 internal_cfg->no_hpet = 1; 365 #endif 366 internal_cfg->vmware_tsc_map = 0; 367 internal_cfg->create_uio_dev = 0; 368 internal_cfg->iova_mode = RTE_IOVA_DC; 369 internal_cfg->user_mbuf_pool_ops_name = NULL; 370 CPU_ZERO(&internal_cfg->ctrl_cpuset); 371 internal_cfg->init_complete = 0; 372 internal_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH; 373 internal_cfg->max_simd_bitwidth.forced = 0; 374 } 375 376 static int 377 eal_plugin_add(const char *path) 378 { 379 struct shared_driver *solib; 380 381 solib = malloc(sizeof(*solib)); 382 if (solib == NULL) { 383 EAL_LOG(ERR, "malloc(solib) failed"); 384 return -1; 385 } 386 memset(solib, 0, sizeof(*solib)); 387 strlcpy(solib->name, path, PATH_MAX); 388 TAILQ_INSERT_TAIL(&solib_list, solib, next); 389 390 return 0; 391 } 392 393 #ifdef RTE_EXEC_ENV_WINDOWS 394 int 395 eal_plugins_init(void) 396 { 397 return 0; 398 } 399 #else 400 401 static int 402 eal_plugindir_init(const char *path) 403 { 404 DIR *d = NULL; 405 struct dirent *dent = NULL; 406 char sopath[PATH_MAX]; 407 408 if (path == NULL || *path == '\0') 409 return 0; 410 411 d = opendir(path); 412 if (d == NULL) { 413 EAL_LOG(ERR, "failed to open directory %s: %s", 414 path, strerror(errno)); 415 return -1; 416 } 417 418 while ((dent = readdir(d)) != NULL) { 419 struct stat sb; 420 int nlen = strnlen(dent->d_name, sizeof(dent->d_name)); 421 422 /* check if name ends in .so or .so.ABI_VERSION */ 423 if (strcmp(&dent->d_name[nlen - 3], ".so") != 0 && 424 strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)], 425 ".so."ABI_VERSION) != 0) 426 continue; 427 428 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name); 429 430 /* if a regular file, add to list to load */ 431 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode))) 432 continue; 433 434 if (eal_plugin_add(sopath) == -1) 435 break; 436 } 437 438 closedir(d); 439 /* XXX this ignores failures from readdir() itself */ 440 return (dent == NULL) ? 0 : -1; 441 } 442 443 static int 444 verify_perms(const char *dirpath) 445 { 446 struct stat st; 447 448 /* if not root, check down one level first */ 449 if (strcmp(dirpath, "/") != 0) { 450 static __thread char last_dir_checked[PATH_MAX]; 451 char copy[PATH_MAX]; 452 const char *dir; 453 454 strlcpy(copy, dirpath, PATH_MAX); 455 dir = dirname(copy); 456 if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) { 457 if (verify_perms(dir) != 0) 458 return -1; 459 strlcpy(last_dir_checked, dir, PATH_MAX); 460 } 461 } 462 463 /* call stat to check for permissions and ensure not world writable */ 464 if (stat(dirpath, &st) != 0) { 465 EAL_LOG(ERR, "Error with stat on %s, %s", 466 dirpath, strerror(errno)); 467 return -1; 468 } 469 if (st.st_mode & S_IWOTH) { 470 EAL_LOG(ERR, 471 "Error, directory path %s is world-writable and insecure", 472 dirpath); 473 return -1; 474 } 475 476 return 0; 477 } 478 479 static void * 480 eal_dlopen(const char *pathname) 481 { 482 void *retval = NULL; 483 char *realp = realpath(pathname, NULL); 484 485 if (realp == NULL && errno == ENOENT) { 486 /* not a full or relative path, try a load from system dirs */ 487 retval = dlopen(pathname, RTLD_NOW); 488 if (retval == NULL) 489 EAL_LOG(ERR, "%s", dlerror()); 490 return retval; 491 } 492 if (realp == NULL) { 493 EAL_LOG(ERR, "Error with realpath for %s, %s", 494 pathname, strerror(errno)); 495 goto out; 496 } 497 if (strnlen(realp, PATH_MAX) == PATH_MAX) { 498 EAL_LOG(ERR, "Error, driver path greater than PATH_MAX"); 499 goto out; 500 } 501 502 /* do permissions checks */ 503 if (verify_perms(realp) != 0) 504 goto out; 505 506 retval = dlopen(realp, RTLD_NOW); 507 if (retval == NULL) 508 EAL_LOG(ERR, "%s", dlerror()); 509 out: 510 free(realp); 511 return retval; 512 } 513 514 static int 515 is_shared_build(void) 516 { 517 #define EAL_SO "librte_eal.so" 518 char soname[32]; 519 size_t len, minlen = strlen(EAL_SO); 520 521 len = strlcpy(soname, EAL_SO"."ABI_VERSION, sizeof(soname)); 522 if (len > sizeof(soname)) { 523 EAL_LOG(ERR, "Shared lib name too long in shared build check"); 524 len = sizeof(soname) - 1; 525 } 526 527 while (len >= minlen) { 528 void *handle; 529 530 /* check if we have this .so loaded, if so - shared build */ 531 EAL_LOG(DEBUG, "Checking presence of .so '%s'", soname); 532 handle = dlopen(soname, RTLD_LAZY | RTLD_NOLOAD); 533 if (handle != NULL) { 534 EAL_LOG(INFO, "Detected shared linkage of DPDK"); 535 dlclose(handle); 536 return 1; 537 } 538 539 /* remove any version numbers off the end to retry */ 540 while (len-- > 0) 541 if (soname[len] == '.') { 542 soname[len] = '\0'; 543 break; 544 } 545 } 546 547 EAL_LOG(INFO, "Detected static linkage of DPDK"); 548 return 0; 549 } 550 551 int 552 eal_plugins_init(void) 553 { 554 struct shared_driver *solib = NULL; 555 struct stat sb; 556 557 /* If we are not statically linked, add default driver loading 558 * path if it exists as a directory. 559 * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL 560 * shared library is not already loaded i.e. it's statically linked.) 561 */ 562 if (is_shared_build() && 563 *default_solib_dir != '\0' && 564 stat(default_solib_dir, &sb) == 0 && 565 S_ISDIR(sb.st_mode)) 566 eal_plugin_add(default_solib_dir); 567 568 TAILQ_FOREACH(solib, &solib_list, next) { 569 570 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) { 571 if (eal_plugindir_init(solib->name) == -1) { 572 EAL_LOG(ERR, 573 "Cannot init plugin directory %s", 574 solib->name); 575 return -1; 576 } 577 } else { 578 EAL_LOG(DEBUG, "open shared lib %s", 579 solib->name); 580 solib->lib_handle = eal_dlopen(solib->name); 581 if (solib->lib_handle == NULL) 582 return -1; 583 } 584 585 } 586 return 0; 587 } 588 #endif 589 590 /* 591 * Parse the coremask given as argument (hexadecimal string) and fill 592 * the global configuration (core role and core count) with the parsed 593 * value. 594 */ 595 static int xdigit2val(unsigned char c) 596 { 597 int val; 598 599 if (isdigit(c)) 600 val = c - '0'; 601 else if (isupper(c)) 602 val = c - 'A' + 10; 603 else 604 val = c - 'a' + 10; 605 return val; 606 } 607 608 static int 609 eal_parse_service_coremask(const char *coremask) 610 { 611 struct rte_config *cfg = rte_eal_get_configuration(); 612 int i, j, idx = 0; 613 unsigned int count = 0; 614 char c; 615 int val; 616 uint32_t taken_lcore_count = 0; 617 618 if (coremask == NULL) 619 return -1; 620 /* Remove all blank characters ahead and after . 621 * Remove 0x/0X if exists. 622 */ 623 while (isblank(*coremask)) 624 coremask++; 625 if (coremask[0] == '0' && ((coremask[1] == 'x') 626 || (coremask[1] == 'X'))) 627 coremask += 2; 628 i = strlen(coremask); 629 while ((i > 0) && isblank(coremask[i - 1])) 630 i--; 631 632 if (i == 0) 633 return -1; 634 635 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) { 636 c = coremask[i]; 637 if (isxdigit(c) == 0) { 638 /* invalid characters */ 639 return -1; 640 } 641 val = xdigit2val(c); 642 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; 643 j++, idx++) { 644 if ((1 << j) & val) { 645 /* handle main lcore already parsed */ 646 uint32_t lcore = idx; 647 if (main_lcore_parsed && 648 cfg->main_lcore == lcore) { 649 EAL_LOG(ERR, 650 "lcore %u is main lcore, cannot use as service core", 651 idx); 652 return -1; 653 } 654 655 if (eal_cpu_detected(idx) == 0) { 656 EAL_LOG(ERR, 657 "lcore %u unavailable", idx); 658 return -1; 659 } 660 661 if (cfg->lcore_role[idx] == ROLE_RTE) 662 taken_lcore_count++; 663 664 lcore_config[idx].core_role = ROLE_SERVICE; 665 count++; 666 } 667 } 668 } 669 670 for (; i >= 0; i--) 671 if (coremask[i] != '0') 672 return -1; 673 674 for (; idx < RTE_MAX_LCORE; idx++) 675 lcore_config[idx].core_index = -1; 676 677 if (count == 0) 678 return -1; 679 680 if (core_parsed && taken_lcore_count != count) { 681 EAL_LOG(WARNING, 682 "Not all service cores are in the coremask. " 683 "Please ensure -c or -l includes service cores"); 684 } 685 686 cfg->service_lcore_count = count; 687 return 0; 688 } 689 690 static int 691 eal_service_cores_parsed(void) 692 { 693 int idx; 694 for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 695 if (lcore_config[idx].core_role == ROLE_SERVICE) 696 return 1; 697 } 698 return 0; 699 } 700 701 static int 702 update_lcore_config(int *cores) 703 { 704 struct rte_config *cfg = rte_eal_get_configuration(); 705 unsigned int count = 0; 706 unsigned int i; 707 int ret = 0; 708 709 for (i = 0; i < RTE_MAX_LCORE; i++) { 710 if (cores[i] != -1) { 711 if (eal_cpu_detected(i) == 0) { 712 EAL_LOG(ERR, "lcore %u unavailable", i); 713 ret = -1; 714 continue; 715 } 716 cfg->lcore_role[i] = ROLE_RTE; 717 count++; 718 } else { 719 cfg->lcore_role[i] = ROLE_OFF; 720 } 721 lcore_config[i].core_index = cores[i]; 722 } 723 if (!ret) 724 cfg->lcore_count = count; 725 return ret; 726 } 727 728 static int 729 check_core_list(int *lcores, unsigned int count) 730 { 731 char lcorestr[RTE_MAX_LCORE * 10]; 732 bool overflow = false; 733 int len = 0, ret; 734 unsigned int i; 735 736 for (i = 0; i < count; i++) { 737 if (lcores[i] < RTE_MAX_LCORE) 738 continue; 739 740 EAL_LOG(ERR, "lcore %d >= RTE_MAX_LCORE (%d)", 741 lcores[i], RTE_MAX_LCORE); 742 overflow = true; 743 } 744 if (!overflow) 745 return 0; 746 747 /* 748 * We've encountered a core that's greater than RTE_MAX_LCORE, 749 * suggest using --lcores option to map lcores onto physical cores 750 * greater than RTE_MAX_LCORE. 751 */ 752 for (i = 0; i < count; i++) { 753 ret = snprintf(&lcorestr[len], sizeof(lcorestr) - len, 754 "%d@%d,", i, lcores[i]); 755 if (ret > 0) 756 len = len + ret; 757 } 758 if (len > 0) 759 lcorestr[len - 1] = 0; 760 EAL_LOG(ERR, "To use high physical core ids, " 761 "please use --lcores to map them to lcore ids below RTE_MAX_LCORE, " 762 "e.g. --lcores %s", lcorestr); 763 return -1; 764 } 765 766 int 767 rte_eal_parse_coremask(const char *coremask, int *cores) 768 { 769 const char *coremask_orig = coremask; 770 int lcores[RTE_MAX_LCORE]; 771 unsigned int count = 0; 772 int i, j, idx; 773 int val; 774 char c; 775 776 for (idx = 0; idx < RTE_MAX_LCORE; idx++) 777 cores[idx] = -1; 778 idx = 0; 779 780 /* Remove all blank characters ahead and after . 781 * Remove 0x/0X if exists. 782 */ 783 while (isblank(*coremask)) 784 coremask++; 785 if (coremask[0] == '0' && ((coremask[1] == 'x') 786 || (coremask[1] == 'X'))) 787 coremask += 2; 788 i = strlen(coremask); 789 while ((i > 0) && isblank(coremask[i - 1])) 790 i--; 791 if (i == 0) { 792 EAL_LOG(ERR, "No lcores in coremask: [%s]", 793 coremask_orig); 794 return -1; 795 } 796 797 for (i = i - 1; i >= 0; i--) { 798 c = coremask[i]; 799 if (isxdigit(c) == 0) { 800 /* invalid characters */ 801 EAL_LOG(ERR, "invalid characters in coremask: [%s]", 802 coremask_orig); 803 return -1; 804 } 805 val = xdigit2val(c); 806 for (j = 0; j < BITS_PER_HEX; j++, idx++) 807 { 808 if ((1 << j) & val) { 809 if (count >= RTE_MAX_LCORE) { 810 EAL_LOG(ERR, "Too many lcores provided. Cannot exceed RTE_MAX_LCORE (%d)", 811 RTE_MAX_LCORE); 812 return -1; 813 } 814 lcores[count++] = idx; 815 } 816 } 817 } 818 if (count == 0) { 819 EAL_LOG(ERR, "No lcores in coremask: [%s]", 820 coremask_orig); 821 return -1; 822 } 823 824 if (check_core_list(lcores, count)) 825 return -1; 826 827 /* 828 * Now that we've got a list of cores no longer than RTE_MAX_LCORE, 829 * and no lcore in that list is greater than RTE_MAX_LCORE, populate 830 * the cores array. 831 */ 832 do { 833 count--; 834 cores[lcores[count]] = count; 835 } while (count != 0); 836 837 return 0; 838 } 839 840 static int 841 eal_parse_service_corelist(const char *corelist) 842 { 843 struct rte_config *cfg = rte_eal_get_configuration(); 844 int i; 845 unsigned count = 0; 846 char *end = NULL; 847 uint32_t min, max, idx; 848 uint32_t taken_lcore_count = 0; 849 850 if (corelist == NULL) 851 return -1; 852 853 /* Remove all blank characters ahead and after */ 854 while (isblank(*corelist)) 855 corelist++; 856 i = strlen(corelist); 857 while ((i > 0) && isblank(corelist[i - 1])) 858 i--; 859 860 /* Get list of cores */ 861 min = RTE_MAX_LCORE; 862 do { 863 while (isblank(*corelist)) 864 corelist++; 865 if (*corelist == '\0') 866 return -1; 867 errno = 0; 868 idx = strtoul(corelist, &end, 10); 869 if (errno || end == NULL) 870 return -1; 871 if (idx >= RTE_MAX_LCORE) 872 return -1; 873 while (isblank(*end)) 874 end++; 875 if (*end == '-') { 876 min = idx; 877 } else if ((*end == ',') || (*end == '\0')) { 878 max = idx; 879 if (min == RTE_MAX_LCORE) 880 min = idx; 881 for (idx = min; idx <= max; idx++) { 882 if (cfg->lcore_role[idx] != ROLE_SERVICE) { 883 /* handle main lcore already parsed */ 884 uint32_t lcore = idx; 885 if (cfg->main_lcore == lcore && 886 main_lcore_parsed) { 887 EAL_LOG(ERR, 888 "Error: lcore %u is main lcore, cannot use as service core", 889 idx); 890 return -1; 891 } 892 if (cfg->lcore_role[idx] == ROLE_RTE) 893 taken_lcore_count++; 894 895 lcore_config[idx].core_role = 896 ROLE_SERVICE; 897 count++; 898 } 899 } 900 min = RTE_MAX_LCORE; 901 } else 902 return -1; 903 corelist = end + 1; 904 } while (*end != '\0'); 905 906 if (count == 0) 907 return -1; 908 909 if (core_parsed && taken_lcore_count != count) { 910 EAL_LOG(WARNING, 911 "Not all service cores were in the coremask. " 912 "Please ensure -c or -l includes service cores"); 913 } 914 915 return 0; 916 } 917 918 static int 919 eal_parse_corelist(const char *corelist, int *cores) 920 { 921 unsigned int count = 0, i; 922 int lcores[RTE_MAX_LCORE]; 923 char *end = NULL; 924 int min, max; 925 int idx; 926 927 for (idx = 0; idx < RTE_MAX_LCORE; idx++) 928 cores[idx] = -1; 929 930 /* Remove all blank characters ahead */ 931 while (isblank(*corelist)) 932 corelist++; 933 934 /* Get list of cores */ 935 min = -1; 936 do { 937 while (isblank(*corelist)) 938 corelist++; 939 if (*corelist == '\0') 940 return -1; 941 errno = 0; 942 idx = strtol(corelist, &end, 10); 943 if (errno || end == NULL) 944 return -1; 945 if (idx < 0) 946 return -1; 947 while (isblank(*end)) 948 end++; 949 if (*end == '-') { 950 min = idx; 951 } else if ((*end == ',') || (*end == '\0')) { 952 max = idx; 953 if (min == -1) 954 min = idx; 955 for (idx = min; idx <= max; idx++) { 956 bool dup = false; 957 958 /* Check if this idx is already present */ 959 for (i = 0; i < count; i++) { 960 if (lcores[i] == idx) 961 dup = true; 962 } 963 if (dup) 964 continue; 965 if (count >= RTE_MAX_LCORE) { 966 EAL_LOG(ERR, "Too many lcores provided. Cannot exceed RTE_MAX_LCORE (%d)", 967 RTE_MAX_LCORE); 968 return -1; 969 } 970 lcores[count++] = idx; 971 } 972 min = -1; 973 } else 974 return -1; 975 corelist = end + 1; 976 } while (*end != '\0'); 977 978 if (count == 0) 979 return -1; 980 981 if (check_core_list(lcores, count)) 982 return -1; 983 984 /* 985 * Now that we've got a list of cores no longer than RTE_MAX_LCORE, 986 * and no lcore in that list is greater than RTE_MAX_LCORE, populate 987 * the cores array. 988 */ 989 do { 990 count--; 991 cores[lcores[count]] = count; 992 } while (count != 0); 993 994 return 0; 995 } 996 997 /* Changes the lcore id of the main thread */ 998 static int 999 eal_parse_main_lcore(const char *arg) 1000 { 1001 char *parsing_end; 1002 struct rte_config *cfg = rte_eal_get_configuration(); 1003 1004 errno = 0; 1005 cfg->main_lcore = (uint32_t) strtol(arg, &parsing_end, 0); 1006 if (errno || parsing_end[0] != 0) 1007 return -1; 1008 if (cfg->main_lcore >= RTE_MAX_LCORE) 1009 return -1; 1010 main_lcore_parsed = 1; 1011 1012 /* ensure main core is not used as service core */ 1013 if (lcore_config[cfg->main_lcore].core_role == ROLE_SERVICE) { 1014 EAL_LOG(ERR, 1015 "Error: Main lcore is used as a service core"); 1016 return -1; 1017 } 1018 1019 return 0; 1020 } 1021 1022 /* 1023 * Parse elem, the elem could be single number/range or '(' ')' group 1024 * 1) A single number elem, it's just a simple digit. e.g. 9 1025 * 2) A single range elem, two digits with a '-' between. e.g. 2-6 1026 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6) 1027 * Within group elem, '-' used for a range separator; 1028 * ',' used for a single number. 1029 */ 1030 static int 1031 eal_parse_set(const char *input, rte_cpuset_t *set) 1032 { 1033 unsigned idx; 1034 const char *str = input; 1035 char *end = NULL; 1036 unsigned min, max; 1037 1038 CPU_ZERO(set); 1039 1040 while (isblank(*str)) 1041 str++; 1042 1043 /* only digit or left bracket is qualify for start point */ 1044 if ((!isdigit(*str) && *str != '(') || *str == '\0') 1045 return -1; 1046 1047 /* process single number or single range of number */ 1048 if (*str != '(') { 1049 errno = 0; 1050 idx = strtoul(str, &end, 10); 1051 if (errno || end == NULL || idx >= CPU_SETSIZE) 1052 return -1; 1053 else { 1054 while (isblank(*end)) 1055 end++; 1056 1057 min = idx; 1058 max = idx; 1059 if (*end == '-') { 1060 /* process single <number>-<number> */ 1061 end++; 1062 while (isblank(*end)) 1063 end++; 1064 if (!isdigit(*end)) 1065 return -1; 1066 1067 errno = 0; 1068 idx = strtoul(end, &end, 10); 1069 if (errno || end == NULL || idx >= CPU_SETSIZE) 1070 return -1; 1071 max = idx; 1072 while (isblank(*end)) 1073 end++; 1074 if (*end != ',' && *end != '\0') 1075 return -1; 1076 } 1077 1078 if (*end != ',' && *end != '\0' && 1079 *end != '@') 1080 return -1; 1081 1082 for (idx = RTE_MIN(min, max); 1083 idx <= RTE_MAX(min, max); idx++) 1084 CPU_SET(idx, set); 1085 1086 return end - input; 1087 } 1088 } 1089 1090 /* process set within bracket */ 1091 str++; 1092 while (isblank(*str)) 1093 str++; 1094 if (*str == '\0') 1095 return -1; 1096 1097 min = RTE_MAX_LCORE; 1098 do { 1099 1100 /* go ahead to the first digit */ 1101 while (isblank(*str)) 1102 str++; 1103 if (!isdigit(*str)) 1104 return -1; 1105 1106 /* get the digit value */ 1107 errno = 0; 1108 idx = strtoul(str, &end, 10); 1109 if (errno || end == NULL || idx >= CPU_SETSIZE) 1110 return -1; 1111 1112 /* go ahead to separator '-',',' and ')' */ 1113 while (isblank(*end)) 1114 end++; 1115 if (*end == '-') { 1116 if (min == RTE_MAX_LCORE) 1117 min = idx; 1118 else /* avoid continuous '-' */ 1119 return -1; 1120 } else if ((*end == ',') || (*end == ')')) { 1121 max = idx; 1122 if (min == RTE_MAX_LCORE) 1123 min = idx; 1124 for (idx = RTE_MIN(min, max); 1125 idx <= RTE_MAX(min, max); idx++) 1126 CPU_SET(idx, set); 1127 1128 min = RTE_MAX_LCORE; 1129 } else 1130 return -1; 1131 1132 str = end + 1; 1133 } while (*end != '\0' && *end != ')'); 1134 1135 /* 1136 * to avoid failure that tail blank makes end character check fail 1137 * in eal_parse_lcores( ) 1138 */ 1139 while (isblank(*str)) 1140 str++; 1141 1142 return str - input; 1143 } 1144 1145 static int 1146 check_cpuset(rte_cpuset_t *set) 1147 { 1148 unsigned int idx; 1149 1150 for (idx = 0; idx < CPU_SETSIZE; idx++) { 1151 if (!CPU_ISSET(idx, set)) 1152 continue; 1153 1154 if (eal_cpu_detected(idx) == 0) { 1155 EAL_LOG(ERR, "core %u " 1156 "unavailable", idx); 1157 return -1; 1158 } 1159 } 1160 return 0; 1161 } 1162 1163 /* 1164 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]' 1165 * lcores, cpus could be a single digit/range or a group. 1166 * '(' and ')' are necessary if it's a group. 1167 * If not supply '@cpus', the value of cpus uses the same as lcores. 1168 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below 1169 * lcore 0 runs on cpuset 0x41 (cpu 0,6) 1170 * lcore 1 runs on cpuset 0x2 (cpu 1) 1171 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7) 1172 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2) 1173 * lcore 6 runs on cpuset 0x41 (cpu 0,6) 1174 * lcore 7 runs on cpuset 0x80 (cpu 7) 1175 * lcore 8 runs on cpuset 0x100 (cpu 8) 1176 */ 1177 static int 1178 eal_parse_lcores(const char *lcores) 1179 { 1180 struct rte_config *cfg = rte_eal_get_configuration(); 1181 rte_cpuset_t lcore_set; 1182 unsigned int set_count; 1183 unsigned idx = 0; 1184 unsigned count = 0; 1185 const char *lcore_start = NULL; 1186 const char *end = NULL; 1187 int offset; 1188 rte_cpuset_t cpuset; 1189 int lflags; 1190 int ret = -1; 1191 1192 if (lcores == NULL) 1193 return -1; 1194 1195 /* Remove all blank characters ahead and after */ 1196 while (isblank(*lcores)) 1197 lcores++; 1198 1199 CPU_ZERO(&cpuset); 1200 1201 /* Reset lcore config */ 1202 for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 1203 cfg->lcore_role[idx] = ROLE_OFF; 1204 lcore_config[idx].core_index = -1; 1205 CPU_ZERO(&lcore_config[idx].cpuset); 1206 } 1207 1208 /* Get list of cores */ 1209 do { 1210 while (isblank(*lcores)) 1211 lcores++; 1212 if (*lcores == '\0') 1213 goto err; 1214 1215 lflags = 0; 1216 1217 /* record lcore_set start point */ 1218 lcore_start = lcores; 1219 1220 /* go across a complete bracket */ 1221 if (*lcore_start == '(') { 1222 lcores += strcspn(lcores, ")"); 1223 if (*lcores++ == '\0') 1224 goto err; 1225 } 1226 1227 /* scan the separator '@', ','(next) or '\0'(finish) */ 1228 lcores += strcspn(lcores, "@,"); 1229 1230 if (*lcores == '@') { 1231 /* explicit assign cpuset and update the end cursor */ 1232 offset = eal_parse_set(lcores + 1, &cpuset); 1233 if (offset < 0) 1234 goto err; 1235 end = lcores + 1 + offset; 1236 } else { /* ',' or '\0' */ 1237 /* haven't given cpuset, current loop done */ 1238 end = lcores; 1239 1240 /* go back to check <number>-<number> */ 1241 offset = strcspn(lcore_start, "(-"); 1242 if (offset < (end - lcore_start) && 1243 *(lcore_start + offset) != '(') 1244 lflags = 1; 1245 } 1246 1247 if (*end != ',' && *end != '\0') 1248 goto err; 1249 1250 /* parse lcore_set from start point */ 1251 if (eal_parse_set(lcore_start, &lcore_set) < 0) 1252 goto err; 1253 1254 /* without '@', by default using lcore_set as cpuset */ 1255 if (*lcores != '@') 1256 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset)); 1257 1258 set_count = CPU_COUNT(&lcore_set); 1259 /* start to update lcore_set */ 1260 for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 1261 if (!CPU_ISSET(idx, &lcore_set)) 1262 continue; 1263 set_count--; 1264 1265 if (cfg->lcore_role[idx] != ROLE_RTE) { 1266 lcore_config[idx].core_index = count; 1267 cfg->lcore_role[idx] = ROLE_RTE; 1268 count++; 1269 } 1270 1271 if (lflags) { 1272 CPU_ZERO(&cpuset); 1273 CPU_SET(idx, &cpuset); 1274 } 1275 1276 if (check_cpuset(&cpuset) < 0) 1277 goto err; 1278 rte_memcpy(&lcore_config[idx].cpuset, &cpuset, 1279 sizeof(rte_cpuset_t)); 1280 } 1281 1282 /* some cores from the lcore_set can't be handled by EAL */ 1283 if (set_count != 0) 1284 goto err; 1285 1286 lcores = end + 1; 1287 } while (*end != '\0'); 1288 1289 if (count == 0) 1290 goto err; 1291 1292 cfg->lcore_count = count; 1293 ret = 0; 1294 1295 err: 1296 1297 return ret; 1298 } 1299 1300 #ifndef RTE_EXEC_ENV_WINDOWS 1301 static int 1302 eal_parse_syslog(const char *facility, struct internal_config *conf) 1303 { 1304 int i; 1305 static const struct { 1306 const char *name; 1307 int value; 1308 } map[] = { 1309 { "auth", LOG_AUTH }, 1310 { "cron", LOG_CRON }, 1311 { "daemon", LOG_DAEMON }, 1312 { "ftp", LOG_FTP }, 1313 { "kern", LOG_KERN }, 1314 { "lpr", LOG_LPR }, 1315 { "mail", LOG_MAIL }, 1316 { "news", LOG_NEWS }, 1317 { "syslog", LOG_SYSLOG }, 1318 { "user", LOG_USER }, 1319 { "uucp", LOG_UUCP }, 1320 { "local0", LOG_LOCAL0 }, 1321 { "local1", LOG_LOCAL1 }, 1322 { "local2", LOG_LOCAL2 }, 1323 { "local3", LOG_LOCAL3 }, 1324 { "local4", LOG_LOCAL4 }, 1325 { "local5", LOG_LOCAL5 }, 1326 { "local6", LOG_LOCAL6 }, 1327 { "local7", LOG_LOCAL7 }, 1328 { NULL, 0 } 1329 }; 1330 1331 for (i = 0; map[i].name; i++) { 1332 if (!strcmp(facility, map[i].name)) { 1333 conf->syslog_facility = map[i].value; 1334 return 0; 1335 } 1336 } 1337 return -1; 1338 } 1339 #endif 1340 1341 static void 1342 eal_log_usage(void) 1343 { 1344 unsigned int level; 1345 1346 printf("Log type is a pattern matching items of this list" 1347 " (plugins may be missing):\n"); 1348 rte_log_list_types(stdout, "\t"); 1349 printf("\n"); 1350 printf("Syntax using globbing pattern: "); 1351 printf("--"OPT_LOG_LEVEL" pattern:level\n"); 1352 printf("Syntax using regular expression: "); 1353 printf("--"OPT_LOG_LEVEL" regexp,level\n"); 1354 printf("Syntax for the global level: "); 1355 printf("--"OPT_LOG_LEVEL" level\n"); 1356 printf("Logs are emitted if allowed by both global and specific levels.\n"); 1357 printf("\n"); 1358 printf("Log level can be a number or the first letters of its name:\n"); 1359 for (level = 1; level <= RTE_LOG_MAX; level++) 1360 printf("\t%d %s\n", level, eal_log_level2str(level)); 1361 } 1362 1363 static int 1364 eal_parse_log_priority(const char *level) 1365 { 1366 size_t len = strlen(level); 1367 unsigned long tmp; 1368 char *end; 1369 unsigned int i; 1370 1371 if (len == 0) 1372 return -1; 1373 1374 /* look for named values, skip 0 which is not a valid level */ 1375 for (i = 1; i <= RTE_LOG_MAX; i++) { 1376 if (strncmp(eal_log_level2str(i), level, len) == 0) 1377 return i; 1378 } 1379 1380 /* not a string, maybe it is numeric */ 1381 errno = 0; 1382 tmp = strtoul(level, &end, 0); 1383 1384 /* check for errors */ 1385 if (errno != 0 || end == NULL || *end != '\0' || 1386 tmp >= UINT32_MAX) 1387 return -1; 1388 1389 return tmp; 1390 } 1391 1392 static int 1393 eal_parse_log_level(const char *arg) 1394 { 1395 const char *pattern = NULL; 1396 const char *regex = NULL; 1397 char *str, *level; 1398 int priority; 1399 1400 if (strcmp(arg, "help") == 0) { 1401 eal_log_usage(); 1402 exit(EXIT_SUCCESS); 1403 } 1404 1405 str = strdup(arg); 1406 if (str == NULL) 1407 return -1; 1408 1409 if ((level = strchr(str, ','))) { 1410 regex = str; 1411 *level++ = '\0'; 1412 } else if ((level = strchr(str, ':'))) { 1413 pattern = str; 1414 *level++ = '\0'; 1415 } else { 1416 level = str; 1417 } 1418 1419 priority = eal_parse_log_priority(level); 1420 if (priority <= 0) { 1421 fprintf(stderr, "Invalid log level: %s\n", level); 1422 goto fail; 1423 } 1424 if (priority > (int)RTE_LOG_MAX) { 1425 fprintf(stderr, "Log level %d higher than maximum (%d)\n", 1426 priority, RTE_LOG_MAX); 1427 priority = RTE_LOG_MAX; 1428 } 1429 1430 if (regex) { 1431 if (rte_log_set_level_regexp(regex, priority) < 0) { 1432 fprintf(stderr, "cannot set log level %s,%d\n", 1433 regex, priority); 1434 goto fail; 1435 } 1436 if (eal_log_save_regexp(regex, priority) < 0) 1437 goto fail; 1438 } else if (pattern) { 1439 if (rte_log_set_level_pattern(pattern, priority) < 0) { 1440 fprintf(stderr, "cannot set log level %s:%d\n", 1441 pattern, priority); 1442 goto fail; 1443 } 1444 if (eal_log_save_pattern(pattern, priority) < 0) 1445 goto fail; 1446 } else { 1447 rte_log_set_global_level(priority); 1448 } 1449 1450 free(str); 1451 return 0; 1452 1453 fail: 1454 free(str); 1455 return -1; 1456 } 1457 1458 static enum rte_proc_type_t 1459 eal_parse_proc_type(const char *arg) 1460 { 1461 if (strncasecmp(arg, "primary", sizeof("primary")) == 0) 1462 return RTE_PROC_PRIMARY; 1463 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0) 1464 return RTE_PROC_SECONDARY; 1465 if (strncasecmp(arg, "auto", sizeof("auto")) == 0) 1466 return RTE_PROC_AUTO; 1467 1468 return RTE_PROC_INVALID; 1469 } 1470 1471 static int 1472 eal_parse_iova_mode(const char *name) 1473 { 1474 int mode; 1475 struct internal_config *internal_conf = 1476 eal_get_internal_configuration(); 1477 1478 if (name == NULL) 1479 return -1; 1480 1481 if (!strcmp("pa", name)) 1482 mode = RTE_IOVA_PA; 1483 else if (!strcmp("va", name)) 1484 mode = RTE_IOVA_VA; 1485 else 1486 return -1; 1487 1488 internal_conf->iova_mode = mode; 1489 return 0; 1490 } 1491 1492 static int 1493 eal_parse_simd_bitwidth(const char *arg) 1494 { 1495 char *end; 1496 unsigned long bitwidth; 1497 int ret; 1498 struct internal_config *internal_conf = 1499 eal_get_internal_configuration(); 1500 1501 if (arg == NULL || arg[0] == '\0') 1502 return -1; 1503 1504 errno = 0; 1505 bitwidth = strtoul(arg, &end, 0); 1506 1507 /* check for errors */ 1508 if (errno != 0 || end == NULL || *end != '\0' || bitwidth > RTE_VECT_SIMD_MAX) 1509 return -1; 1510 1511 if (bitwidth == 0) 1512 bitwidth = (unsigned long) RTE_VECT_SIMD_MAX; 1513 ret = rte_vect_set_max_simd_bitwidth(bitwidth); 1514 if (ret < 0) 1515 return -1; 1516 internal_conf->max_simd_bitwidth.forced = 1; 1517 return 0; 1518 } 1519 1520 static int 1521 eal_parse_base_virtaddr(const char *arg) 1522 { 1523 char *end; 1524 uint64_t addr; 1525 struct internal_config *internal_conf = 1526 eal_get_internal_configuration(); 1527 1528 errno = 0; 1529 addr = strtoull(arg, &end, 16); 1530 1531 /* check for errors */ 1532 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0')) 1533 return -1; 1534 1535 /* make sure we don't exceed 32-bit boundary on 32-bit target */ 1536 #ifndef RTE_ARCH_64 1537 if (addr >= UINTPTR_MAX) 1538 return -1; 1539 #endif 1540 1541 /* align the addr on 16M boundary, 16MB is the minimum huge page 1542 * size on IBM Power architecture. If the addr is aligned to 16MB, 1543 * it can align to 2MB for x86. So this alignment can also be used 1544 * on x86 and other architectures. 1545 */ 1546 internal_conf->base_virtaddr = 1547 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M); 1548 1549 return 0; 1550 } 1551 1552 /* caller is responsible for freeing the returned string */ 1553 static char * 1554 available_cores(void) 1555 { 1556 char *str = NULL; 1557 int previous; 1558 int sequence; 1559 char *tmp; 1560 int idx; 1561 1562 /* find the first available cpu */ 1563 for (idx = 0; idx < RTE_MAX_LCORE; idx++) { 1564 if (eal_cpu_detected(idx) == 0) 1565 continue; 1566 break; 1567 } 1568 if (idx >= RTE_MAX_LCORE) 1569 return NULL; 1570 1571 /* first sequence */ 1572 if (asprintf(&str, "%d", idx) < 0) 1573 return NULL; 1574 previous = idx; 1575 sequence = 0; 1576 1577 for (idx++ ; idx < RTE_MAX_LCORE; idx++) { 1578 if (eal_cpu_detected(idx) == 0) 1579 continue; 1580 1581 if (idx == previous + 1) { 1582 previous = idx; 1583 sequence = 1; 1584 continue; 1585 } 1586 1587 /* finish current sequence */ 1588 if (sequence) { 1589 if (asprintf(&tmp, "%s-%d", str, previous) < 0) { 1590 free(str); 1591 return NULL; 1592 } 1593 free(str); 1594 str = tmp; 1595 } 1596 1597 /* new sequence */ 1598 if (asprintf(&tmp, "%s,%d", str, idx) < 0) { 1599 free(str); 1600 return NULL; 1601 } 1602 free(str); 1603 str = tmp; 1604 previous = idx; 1605 sequence = 0; 1606 } 1607 1608 /* finish last sequence */ 1609 if (sequence) { 1610 if (asprintf(&tmp, "%s-%d", str, previous) < 0) { 1611 free(str); 1612 return NULL; 1613 } 1614 free(str); 1615 str = tmp; 1616 } 1617 1618 return str; 1619 } 1620 1621 #define HUGE_UNLINK_NEVER "never" 1622 1623 static int 1624 eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out) 1625 { 1626 if (arg == NULL || strcmp(arg, "always") == 0) { 1627 out->unlink_before_mapping = true; 1628 return 0; 1629 } 1630 if (strcmp(arg, "existing") == 0) { 1631 /* same as not specifying the option */ 1632 return 0; 1633 } 1634 if (strcmp(arg, HUGE_UNLINK_NEVER) == 0) { 1635 EAL_LOG(WARNING, "Using --"OPT_HUGE_UNLINK"=" 1636 HUGE_UNLINK_NEVER" may create data leaks."); 1637 out->unlink_existing = false; 1638 return 0; 1639 } 1640 return -1; 1641 } 1642 1643 int 1644 eal_parse_common_option(int opt, const char *optarg, 1645 struct internal_config *conf) 1646 { 1647 static int b_used; 1648 static int a_used; 1649 1650 switch (opt) { 1651 case 'b': 1652 if (a_used) 1653 goto ba_conflict; 1654 if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0) 1655 return -1; 1656 b_used = 1; 1657 break; 1658 1659 case 'a': 1660 if (b_used) 1661 goto ba_conflict; 1662 if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0) 1663 return -1; 1664 a_used = 1; 1665 break; 1666 /* coremask */ 1667 case 'c': { 1668 int lcore_indexes[RTE_MAX_LCORE]; 1669 1670 if (eal_service_cores_parsed()) 1671 EAL_LOG(WARNING, 1672 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S"); 1673 if (rte_eal_parse_coremask(optarg, lcore_indexes) < 0) { 1674 EAL_LOG(ERR, "invalid coremask syntax"); 1675 return -1; 1676 } 1677 if (update_lcore_config(lcore_indexes) < 0) { 1678 char *available = available_cores(); 1679 1680 EAL_LOG(ERR, 1681 "invalid coremask, please check specified cores are part of %s", 1682 available); 1683 free(available); 1684 return -1; 1685 } 1686 1687 if (core_parsed) { 1688 EAL_LOG(ERR, "Option -c is ignored, because (%s) is set!", 1689 (core_parsed == LCORE_OPT_LST) ? "-l" : 1690 (core_parsed == LCORE_OPT_MAP) ? "--lcore" : 1691 "-c"); 1692 return -1; 1693 } 1694 1695 core_parsed = LCORE_OPT_MSK; 1696 break; 1697 } 1698 /* corelist */ 1699 case 'l': { 1700 int lcore_indexes[RTE_MAX_LCORE]; 1701 1702 if (eal_service_cores_parsed()) 1703 EAL_LOG(WARNING, 1704 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S"); 1705 1706 if (eal_parse_corelist(optarg, lcore_indexes) < 0) { 1707 EAL_LOG(ERR, "invalid core list syntax"); 1708 return -1; 1709 } 1710 if (update_lcore_config(lcore_indexes) < 0) { 1711 char *available = available_cores(); 1712 1713 EAL_LOG(ERR, 1714 "invalid core list, please check specified cores are part of %s", 1715 available); 1716 free(available); 1717 return -1; 1718 } 1719 1720 if (core_parsed) { 1721 EAL_LOG(ERR, "Option -l is ignored, because (%s) is set!", 1722 (core_parsed == LCORE_OPT_MSK) ? "-c" : 1723 (core_parsed == LCORE_OPT_MAP) ? "--lcore" : 1724 "-l"); 1725 return -1; 1726 } 1727 1728 core_parsed = LCORE_OPT_LST; 1729 break; 1730 } 1731 /* service coremask */ 1732 case 's': 1733 if (eal_parse_service_coremask(optarg) < 0) { 1734 EAL_LOG(ERR, "invalid service coremask"); 1735 return -1; 1736 } 1737 break; 1738 /* service corelist */ 1739 case 'S': 1740 if (eal_parse_service_corelist(optarg) < 0) { 1741 EAL_LOG(ERR, "invalid service core list"); 1742 return -1; 1743 } 1744 break; 1745 /* size of memory */ 1746 case 'm': 1747 conf->memory = atoi(optarg); 1748 conf->memory *= 1024ULL; 1749 conf->memory *= 1024ULL; 1750 mem_parsed = 1; 1751 break; 1752 /* force number of channels */ 1753 case 'n': 1754 conf->force_nchannel = atoi(optarg); 1755 if (conf->force_nchannel == 0) { 1756 EAL_LOG(ERR, "invalid channel number"); 1757 return -1; 1758 } 1759 break; 1760 /* force number of ranks */ 1761 case 'r': 1762 conf->force_nrank = atoi(optarg); 1763 if (conf->force_nrank == 0 || 1764 conf->force_nrank > 16) { 1765 EAL_LOG(ERR, "invalid rank number"); 1766 return -1; 1767 } 1768 break; 1769 /* force loading of external driver */ 1770 case 'd': 1771 if (eal_plugin_add(optarg) == -1) 1772 return -1; 1773 break; 1774 case 'v': 1775 /* since message is explicitly requested by user, we 1776 * write message at highest log level so it can always 1777 * be seen 1778 * even if info or warning messages are disabled */ 1779 EAL_LOG(CRIT, "RTE Version: '%s'", rte_version()); 1780 break; 1781 1782 /* long options */ 1783 case OPT_HUGE_UNLINK_NUM: 1784 if (eal_parse_huge_unlink(optarg, &conf->hugepage_file) < 0) { 1785 EAL_LOG(ERR, "invalid --"OPT_HUGE_UNLINK" option"); 1786 return -1; 1787 } 1788 break; 1789 1790 case OPT_NO_HUGE_NUM: 1791 conf->no_hugetlbfs = 1; 1792 /* no-huge is legacy mem */ 1793 conf->legacy_mem = 1; 1794 break; 1795 1796 case OPT_NO_PCI_NUM: 1797 conf->no_pci = 1; 1798 break; 1799 1800 case OPT_NO_HPET_NUM: 1801 conf->no_hpet = 1; 1802 break; 1803 1804 case OPT_VMWARE_TSC_MAP_NUM: 1805 conf->vmware_tsc_map = 1; 1806 break; 1807 1808 case OPT_NO_SHCONF_NUM: 1809 conf->no_shconf = 1; 1810 break; 1811 1812 case OPT_IN_MEMORY_NUM: 1813 conf->in_memory = 1; 1814 /* in-memory is a superset of noshconf and huge-unlink */ 1815 conf->no_shconf = 1; 1816 conf->hugepage_file.unlink_before_mapping = true; 1817 break; 1818 1819 case OPT_PROC_TYPE_NUM: 1820 conf->process_type = eal_parse_proc_type(optarg); 1821 break; 1822 1823 case OPT_MAIN_LCORE_NUM: 1824 if (eal_parse_main_lcore(optarg) < 0) { 1825 EAL_LOG(ERR, "invalid parameter for --" 1826 OPT_MAIN_LCORE); 1827 return -1; 1828 } 1829 break; 1830 1831 case OPT_VDEV_NUM: 1832 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL, 1833 optarg) < 0) { 1834 return -1; 1835 } 1836 break; 1837 1838 #ifndef RTE_EXEC_ENV_WINDOWS 1839 case OPT_SYSLOG_NUM: 1840 if (eal_parse_syslog(optarg, conf) < 0) { 1841 EAL_LOG(ERR, "invalid parameters for --" 1842 OPT_SYSLOG); 1843 return -1; 1844 } 1845 break; 1846 #endif 1847 1848 case OPT_LOG_LEVEL_NUM: { 1849 if (eal_parse_log_level(optarg) < 0) { 1850 EAL_LOG(ERR, 1851 "invalid parameters for --" 1852 OPT_LOG_LEVEL); 1853 return -1; 1854 } 1855 break; 1856 } 1857 1858 #ifndef RTE_EXEC_ENV_WINDOWS 1859 case OPT_TRACE_NUM: { 1860 if (eal_trace_args_save(optarg) < 0) { 1861 EAL_LOG(ERR, "invalid parameters for --" 1862 OPT_TRACE); 1863 return -1; 1864 } 1865 break; 1866 } 1867 1868 case OPT_TRACE_DIR_NUM: { 1869 if (eal_trace_dir_args_save(optarg) < 0) { 1870 EAL_LOG(ERR, "invalid parameters for --" 1871 OPT_TRACE_DIR); 1872 return -1; 1873 } 1874 break; 1875 } 1876 1877 case OPT_TRACE_BUF_SIZE_NUM: { 1878 if (eal_trace_bufsz_args_save(optarg) < 0) { 1879 EAL_LOG(ERR, "invalid parameters for --" 1880 OPT_TRACE_BUF_SIZE); 1881 return -1; 1882 } 1883 break; 1884 } 1885 1886 case OPT_TRACE_MODE_NUM: { 1887 if (eal_trace_mode_args_save(optarg) < 0) { 1888 EAL_LOG(ERR, "invalid parameters for --" 1889 OPT_TRACE_MODE); 1890 return -1; 1891 } 1892 break; 1893 } 1894 #endif /* !RTE_EXEC_ENV_WINDOWS */ 1895 1896 case OPT_LCORES_NUM: 1897 if (eal_parse_lcores(optarg) < 0) { 1898 EAL_LOG(ERR, "invalid parameter for --" 1899 OPT_LCORES); 1900 return -1; 1901 } 1902 1903 if (core_parsed) { 1904 EAL_LOG(ERR, "Option --lcore is ignored, because (%s) is set!", 1905 (core_parsed == LCORE_OPT_LST) ? "-l" : 1906 (core_parsed == LCORE_OPT_MSK) ? "-c" : 1907 "--lcore"); 1908 return -1; 1909 } 1910 1911 core_parsed = LCORE_OPT_MAP; 1912 break; 1913 case OPT_LEGACY_MEM_NUM: 1914 conf->legacy_mem = 1; 1915 break; 1916 case OPT_SINGLE_FILE_SEGMENTS_NUM: 1917 conf->single_file_segments = 1; 1918 break; 1919 case OPT_IOVA_MODE_NUM: 1920 if (eal_parse_iova_mode(optarg) < 0) { 1921 EAL_LOG(ERR, "invalid parameters for --" 1922 OPT_IOVA_MODE); 1923 return -1; 1924 } 1925 break; 1926 case OPT_BASE_VIRTADDR_NUM: 1927 if (eal_parse_base_virtaddr(optarg) < 0) { 1928 EAL_LOG(ERR, "invalid parameter for --" 1929 OPT_BASE_VIRTADDR); 1930 return -1; 1931 } 1932 break; 1933 case OPT_TELEMETRY_NUM: 1934 break; 1935 case OPT_NO_TELEMETRY_NUM: 1936 conf->no_telemetry = 1; 1937 break; 1938 case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM: 1939 if (eal_parse_simd_bitwidth(optarg) < 0) { 1940 EAL_LOG(ERR, "invalid parameter for --" 1941 OPT_FORCE_MAX_SIMD_BITWIDTH); 1942 return -1; 1943 } 1944 break; 1945 1946 /* don't know what to do, leave this to caller */ 1947 default: 1948 return 1; 1949 1950 } 1951 1952 return 0; 1953 1954 ba_conflict: 1955 EAL_LOG(ERR, 1956 "Options allow (-a) and block (-b) can't be used at the same time"); 1957 return -1; 1958 } 1959 1960 static void 1961 eal_auto_detect_cores(struct rte_config *cfg) 1962 { 1963 unsigned int lcore_id; 1964 unsigned int removed = 0; 1965 rte_cpuset_t affinity_set; 1966 1967 if (rte_thread_get_affinity_by_id(rte_thread_self(), &affinity_set) != 0) 1968 CPU_ZERO(&affinity_set); 1969 1970 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 1971 if (cfg->lcore_role[lcore_id] == ROLE_RTE && 1972 !CPU_ISSET(lcore_id, &affinity_set)) { 1973 cfg->lcore_role[lcore_id] = ROLE_OFF; 1974 removed++; 1975 } 1976 } 1977 1978 cfg->lcore_count -= removed; 1979 } 1980 1981 static void 1982 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg) 1983 { 1984 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset; 1985 rte_cpuset_t default_set; 1986 unsigned int lcore_id; 1987 1988 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { 1989 if (rte_lcore_has_role(lcore_id, ROLE_OFF)) 1990 continue; 1991 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset); 1992 } 1993 RTE_CPU_NOT(cpuset, cpuset); 1994 1995 if (rte_thread_get_affinity_by_id(rte_thread_self(), &default_set) != 0) 1996 CPU_ZERO(&default_set); 1997 1998 RTE_CPU_AND(cpuset, cpuset, &default_set); 1999 2000 /* if no remaining cpu, use main lcore cpu affinity */ 2001 if (!CPU_COUNT(cpuset)) { 2002 memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset, 2003 sizeof(*cpuset)); 2004 } 2005 } 2006 2007 int 2008 eal_cleanup_config(struct internal_config *internal_cfg) 2009 { 2010 free(internal_cfg->hugefile_prefix); 2011 free(internal_cfg->hugepage_dir); 2012 free(internal_cfg->user_mbuf_pool_ops_name); 2013 2014 return 0; 2015 } 2016 2017 int 2018 eal_adjust_config(struct internal_config *internal_cfg) 2019 { 2020 int i; 2021 struct rte_config *cfg = rte_eal_get_configuration(); 2022 struct internal_config *internal_conf = 2023 eal_get_internal_configuration(); 2024 2025 if (!core_parsed) 2026 eal_auto_detect_cores(cfg); 2027 2028 if (internal_conf->process_type == RTE_PROC_AUTO) 2029 internal_conf->process_type = eal_proc_type_detect(); 2030 2031 /* default main lcore is the first one */ 2032 if (!main_lcore_parsed) { 2033 cfg->main_lcore = rte_get_next_lcore(-1, 0, 0); 2034 if (cfg->main_lcore >= RTE_MAX_LCORE) 2035 return -1; 2036 lcore_config[cfg->main_lcore].core_role = ROLE_RTE; 2037 } 2038 2039 compute_ctrl_threads_cpuset(internal_cfg); 2040 2041 /* if no memory amounts were requested, this will result in 0 and 2042 * will be overridden later, right after eal_hugepage_info_init() */ 2043 for (i = 0; i < RTE_MAX_NUMA_NODES; i++) 2044 internal_cfg->memory += internal_cfg->socket_mem[i]; 2045 2046 return 0; 2047 } 2048 2049 int 2050 eal_check_common_options(struct internal_config *internal_cfg) 2051 { 2052 struct rte_config *cfg = rte_eal_get_configuration(); 2053 const struct internal_config *internal_conf = 2054 eal_get_internal_configuration(); 2055 2056 if (cfg->lcore_role[cfg->main_lcore] != ROLE_RTE) { 2057 EAL_LOG(ERR, "Main lcore is not enabled for DPDK"); 2058 return -1; 2059 } 2060 2061 if (internal_cfg->process_type == RTE_PROC_INVALID) { 2062 EAL_LOG(ERR, "Invalid process type specified"); 2063 return -1; 2064 } 2065 if (internal_cfg->hugefile_prefix != NULL && 2066 strlen(internal_cfg->hugefile_prefix) < 1) { 2067 EAL_LOG(ERR, "Invalid length of --" OPT_FILE_PREFIX " option"); 2068 return -1; 2069 } 2070 if (internal_cfg->hugepage_dir != NULL && 2071 strlen(internal_cfg->hugepage_dir) < 1) { 2072 EAL_LOG(ERR, "Invalid length of --" OPT_HUGE_DIR" option"); 2073 return -1; 2074 } 2075 if (internal_cfg->user_mbuf_pool_ops_name != NULL && 2076 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) { 2077 EAL_LOG(ERR, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option"); 2078 return -1; 2079 } 2080 if (strchr(eal_get_hugefile_prefix(), '%') != NULL) { 2081 EAL_LOG(ERR, "Invalid char, '%%', in --"OPT_FILE_PREFIX" " 2082 "option"); 2083 return -1; 2084 } 2085 if (mem_parsed && internal_cfg->force_sockets == 1) { 2086 EAL_LOG(ERR, "Options -m and --"OPT_SOCKET_MEM" cannot " 2087 "be specified at the same time"); 2088 return -1; 2089 } 2090 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) { 2091 EAL_LOG(ERR, "Option --"OPT_SOCKET_MEM" cannot " 2092 "be specified together with --"OPT_NO_HUGE); 2093 return -1; 2094 } 2095 if (internal_cfg->no_hugetlbfs && 2096 internal_cfg->hugepage_file.unlink_before_mapping && 2097 !internal_cfg->in_memory) { 2098 EAL_LOG(ERR, "Option --"OPT_HUGE_UNLINK" cannot " 2099 "be specified together with --"OPT_NO_HUGE); 2100 return -1; 2101 } 2102 if (internal_cfg->no_hugetlbfs && 2103 internal_cfg->huge_worker_stack_size != 0) { 2104 EAL_LOG(ERR, "Option --"OPT_HUGE_WORKER_STACK" cannot " 2105 "be specified together with --"OPT_NO_HUGE); 2106 return -1; 2107 } 2108 if (internal_conf->force_socket_limits && internal_conf->legacy_mem) { 2109 EAL_LOG(ERR, "Option --"OPT_SOCKET_LIMIT 2110 " is only supported in non-legacy memory mode"); 2111 } 2112 if (internal_cfg->single_file_segments && 2113 internal_cfg->hugepage_file.unlink_before_mapping && 2114 !internal_cfg->in_memory) { 2115 EAL_LOG(ERR, "Option --"OPT_SINGLE_FILE_SEGMENTS" is " 2116 "not compatible with --"OPT_HUGE_UNLINK); 2117 return -1; 2118 } 2119 if (!internal_cfg->hugepage_file.unlink_existing && 2120 internal_cfg->in_memory) { 2121 EAL_LOG(ERR, "Option --"OPT_IN_MEMORY" is not compatible " 2122 "with --"OPT_HUGE_UNLINK"="HUGE_UNLINK_NEVER); 2123 return -1; 2124 } 2125 if (internal_cfg->legacy_mem && 2126 internal_cfg->in_memory) { 2127 EAL_LOG(ERR, "Option --"OPT_LEGACY_MEM" is not compatible " 2128 "with --"OPT_IN_MEMORY); 2129 return -1; 2130 } 2131 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) { 2132 EAL_LOG(ERR, "Option --"OPT_LEGACY_MEM" is not compatible " 2133 "with --"OPT_MATCH_ALLOCATIONS); 2134 return -1; 2135 } 2136 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) { 2137 EAL_LOG(ERR, "Option --"OPT_NO_HUGE" is not compatible " 2138 "with --"OPT_MATCH_ALLOCATIONS); 2139 return -1; 2140 } 2141 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) { 2142 EAL_LOG(NOTICE, "Static memory layout is selected, " 2143 "amount of reserved memory can be adjusted with " 2144 "-m or --"OPT_SOCKET_MEM); 2145 } 2146 2147 return 0; 2148 } 2149 2150 uint16_t 2151 rte_vect_get_max_simd_bitwidth(void) 2152 { 2153 const struct internal_config *internal_conf = 2154 eal_get_internal_configuration(); 2155 return internal_conf->max_simd_bitwidth.bitwidth; 2156 } 2157 2158 int 2159 rte_vect_set_max_simd_bitwidth(uint16_t bitwidth) 2160 { 2161 struct internal_config *internal_conf = 2162 eal_get_internal_configuration(); 2163 if (internal_conf->max_simd_bitwidth.forced) { 2164 EAL_LOG(NOTICE, "Cannot set max SIMD bitwidth - user runtime override enabled"); 2165 return -EPERM; 2166 } 2167 2168 if (bitwidth < RTE_VECT_SIMD_DISABLED || !rte_is_power_of_2(bitwidth)) { 2169 EAL_LOG(ERR, "Invalid bitwidth value!"); 2170 return -EINVAL; 2171 } 2172 internal_conf->max_simd_bitwidth.bitwidth = bitwidth; 2173 return 0; 2174 } 2175 2176 void 2177 eal_common_usage(void) 2178 { 2179 printf("[options]\n\n" 2180 "EAL common options:\n" 2181 " -c COREMASK Hexadecimal bitmask of cores to run on\n" 2182 " -l CORELIST List of cores to run on\n" 2183 " The argument format is <c1>[-c2][,c3[-c4],...]\n" 2184 " where c1, c2, etc are core indexes between 0 and %d\n" 2185 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n" 2186 " The argument format is\n" 2187 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n" 2188 " lcores and cpus list are grouped by '(' and ')'\n" 2189 " Within the group, '-' is used for range separator,\n" 2190 " ',' is used for single number separator.\n" 2191 " '( )' can be omitted for single element group,\n" 2192 " '@' can be omitted if cpus and lcores have the same value\n" 2193 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n" 2194 " --"OPT_MAIN_LCORE" ID Core ID that is used as main\n" 2195 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n" 2196 " -n CHANNELS Number of memory channels\n" 2197 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n" 2198 " -r RANKS Force number of memory ranks (don't detect)\n" 2199 " -b, --block Add a device to the blocked list.\n" 2200 " Prevent EAL from using this device. The argument\n" 2201 " format for PCI devices is <domain:bus:devid.func>.\n" 2202 " -a, --allow Add a device to the allow list.\n" 2203 " Only use the specified devices. The argument format\n" 2204 " for PCI devices is <[domain:]bus:devid.func>.\n" 2205 " This option can be present several times.\n" 2206 " [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n" 2207 " --"OPT_VDEV" Add a virtual device.\n" 2208 " The argument format is <driver><id>[,key=val,...]\n" 2209 " (ex: --vdev=net_pcap0,iface=eth2).\n" 2210 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n" 2211 " 'va' for IOVA_VA\n" 2212 " -d LIB.so|DIR Add a driver or driver directory\n" 2213 " (can be used multiple times)\n" 2214 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n" 2215 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n" 2216 #ifndef RTE_EXEC_ENV_WINDOWS 2217 " --"OPT_SYSLOG" Set syslog facility\n" 2218 #endif 2219 " --"OPT_LOG_LEVEL"=<level> Set global log level\n" 2220 " --"OPT_LOG_LEVEL"=<type-match>:<level>\n" 2221 " Set specific log level\n" 2222 " --"OPT_LOG_LEVEL"=help Show log types and levels\n" 2223 #ifndef RTE_EXEC_ENV_WINDOWS 2224 " --"OPT_TRACE"=<regex-match>\n" 2225 " Enable trace based on regular expression trace name.\n" 2226 " By default, the trace is disabled.\n" 2227 " User must specify this option to enable trace.\n" 2228 " --"OPT_TRACE_DIR"=<directory path>\n" 2229 " Specify trace directory for trace output.\n" 2230 " By default, trace output will created at\n" 2231 " $HOME directory and parameter must be\n" 2232 " specified once only.\n" 2233 " --"OPT_TRACE_BUF_SIZE"=<int>\n" 2234 " Specify maximum size of allocated memory\n" 2235 " for trace output for each thread. Valid\n" 2236 " unit can be either 'B|K|M' for 'Bytes',\n" 2237 " 'KBytes' and 'MBytes' respectively.\n" 2238 " Default is 1MB and parameter must be\n" 2239 " specified once only.\n" 2240 " --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n" 2241 " Specify the mode of update of trace\n" 2242 " output file. Either update on a file can\n" 2243 " be wrapped or discarded when file size\n" 2244 " reaches its maximum limit.\n" 2245 " Default mode is 'overwrite' and parameter\n" 2246 " must be specified once only.\n" 2247 #endif /* !RTE_EXEC_ENV_WINDOWS */ 2248 " -v Display version information on startup\n" 2249 " -h, --"OPT_HELP" This help\n" 2250 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n" 2251 " disable secondary process support\n" 2252 " --"OPT_BASE_VIRTADDR" Base virtual address\n" 2253 " --"OPT_TELEMETRY" Enable telemetry support (on by default)\n" 2254 " --"OPT_NO_TELEMETRY" Disable telemetry support\n" 2255 " --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n" 2256 "\nEAL options for DEBUG use only:\n" 2257 " --"OPT_HUGE_UNLINK"[=existing|always|never]\n" 2258 " When to unlink files in hugetlbfs\n" 2259 " ('existing' by default, no value means 'always')\n" 2260 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n" 2261 " --"OPT_NO_PCI" Disable PCI\n" 2262 " --"OPT_NO_HPET" Disable HPET\n" 2263 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n" 2264 "\n", RTE_MAX_LCORE); 2265 } 2266