1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
9 #ifndef RTE_EXEC_ENV_WINDOWS
16 #ifndef RTE_EXEC_ENV_WINDOWS
20 #include <sys/types.h>
22 #ifndef RTE_EXEC_ENV_WINDOWS
26 #include <rte_string_fns.h>
29 #include <rte_lcore.h>
30 #include <rte_memory.h>
31 #include <rte_tailq.h>
32 #include <rte_version.h>
33 #include <rte_devargs.h>
34 #include <rte_memcpy.h>
35 #ifndef RTE_EXEC_ENV_WINDOWS
36 #include <rte_telemetry.h>
40 #include "eal_internal_cfg.h"
41 #include "eal_options.h"
42 #include "eal_filesystem.h"
43 #include "eal_private.h"
45 #ifndef RTE_EXEC_ENV_WINDOWS
46 #include "eal_trace.h"
49 #define BITS_PER_HEX 4
50 #define LCORE_OPT_LST 1
51 #define LCORE_OPT_MSK 2
52 #define LCORE_OPT_MAP 3
59 "s:" /* service coremask */
63 "S:" /* service corelist */
64 "m:" /* memory size */
65 "n:" /* memory channels */
66 "r:" /* memory ranks */
71 eal_long_options[] = {
72 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM },
73 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM },
74 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM },
75 {OPT_HELP, 0, NULL, OPT_HELP_NUM },
76 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM },
77 {OPT_HUGE_UNLINK, 2, NULL, OPT_HUGE_UNLINK_NUM },
78 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
79 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
80 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
81 {OPT_TRACE, 1, NULL, OPT_TRACE_NUM },
82 {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM },
83 {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM },
84 {OPT_TRACE_MODE, 1, NULL, OPT_TRACE_MODE_NUM },
85 {OPT_MAIN_LCORE, 1, NULL, OPT_MAIN_LCORE_NUM },
86 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
87 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
88 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
89 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
90 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
91 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
92 {OPT_DEV_BLOCK, 1, NULL, OPT_DEV_BLOCK_NUM },
93 {OPT_DEV_ALLOW, 1, NULL, OPT_DEV_ALLOW_NUM },
94 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
95 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
96 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
97 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
98 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
99 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
100 {OPT_VFIO_VF_TOKEN, 1, NULL, OPT_VFIO_VF_TOKEN_NUM },
101 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
102 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
103 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
104 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
105 {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM },
106 {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM },
107 {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM},
112 TAILQ_HEAD(shared_driver_list, shared_driver);
114 /* Definition for shared object drivers. */
115 struct shared_driver {
116 TAILQ_ENTRY(shared_driver) next;
122 /* List of external loadable drivers */
123 static struct shared_driver_list solib_list =
124 TAILQ_HEAD_INITIALIZER(solib_list);
126 #ifndef RTE_EXEC_ENV_WINDOWS
127 /* Default path of external loadable drivers */
128 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
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
136 static const char dpdk_solib_path[] __rte_used =
137 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
139 TAILQ_HEAD(device_option_list, device_option);
141 struct device_option {
142 TAILQ_ENTRY(device_option) next;
144 enum rte_devtype type;
148 static struct device_option_list devopt_list =
149 TAILQ_HEAD_INITIALIZER(devopt_list);
151 static int main_lcore_parsed;
152 static int mem_parsed;
153 static int core_parsed;
155 /* Allow the application to print its usage message too if set */
156 static rte_usage_hook_t rte_application_usage_hook;
158 /* Returns rte_usage_hook_t */
160 eal_get_application_usage_hook(void)
162 return rte_application_usage_hook;
165 /* Set a per-application usage message */
167 rte_set_application_usage_hook(rte_usage_hook_t usage_func)
169 rte_usage_hook_t old_func;
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;
178 #ifndef RTE_EXEC_ENV_WINDOWS
179 static char **eal_args;
180 static char **eal_app_args;
182 #define EAL_PARAM_REQ "/eal/params"
183 #define EAL_APP_PARAM_REQ "/eal/app_params"
185 /* callback handler for telemetry library to report out EAL flags */
187 handle_eal_info_request(const char *cmd, const char *params __rte_unused,
188 struct rte_tel_data *d)
194 if (strcmp(cmd, EAL_PARAM_REQ) == 0)
199 rte_tel_data_start_array(d, RTE_TEL_STRING_VAL);
200 if (args == NULL || args[0] == NULL)
203 for ( ; args[i] != NULL; i++)
204 used = rte_tel_data_add_array_string(d, args[i]);
209 eal_save_args(int argc, char **argv)
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");
218 /* clone argv to report out later. We overprovision, but
219 * this does not waste huge amounts of memory
221 eal_args = calloc(argc + 1, sizeof(*eal_args));
222 if (eal_args == NULL)
225 for (i = 0; i < argc; i++) {
226 if (strcmp(argv[i], "--") == 0)
228 eal_args[i] = strdup(argv[i]);
230 eal_args[i++] = NULL; /* always finish with NULL */
232 /* allow reporting of any app args we know about too */
236 eal_app_args = calloc(argc - i + 1, sizeof(*eal_args));
237 if (eal_app_args == NULL)
240 for (j = 0; i < argc; j++, i++)
241 eal_app_args[j] = strdup(argv[i]);
242 eal_app_args[j] = NULL;
249 eal_option_device_add(enum rte_devtype type, const char *optarg)
251 struct device_option *devopt;
255 optlen = strlen(optarg) + 1;
256 devopt = calloc(1, sizeof(*devopt) + optlen);
257 if (devopt == NULL) {
258 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
263 ret = strlcpy(devopt->arg, optarg, optlen);
265 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
269 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
274 eal_option_device_parse(void)
276 struct device_option *devopt;
280 RTE_TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
282 ret = rte_devargs_add(devopt->type, devopt->arg);
284 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
287 TAILQ_REMOVE(&devopt_list, devopt, next);
294 eal_get_hugefile_prefix(void)
296 const struct internal_config *internal_conf =
297 eal_get_internal_configuration();
299 if (internal_conf->hugefile_prefix != NULL)
300 return internal_conf->hugefile_prefix;
301 return HUGEFILE_PREFIX_DEFAULT;
305 eal_reset_internal_config(struct internal_config *internal_cfg)
309 internal_cfg->memory = 0;
310 internal_cfg->force_nrank = 0;
311 internal_cfg->force_nchannel = 0;
312 internal_cfg->hugefile_prefix = NULL;
313 internal_cfg->hugepage_dir = NULL;
314 internal_cfg->hugepage_file.unlink_before_mapping = false;
315 internal_cfg->hugepage_file.unlink_existing = true;
316 internal_cfg->force_sockets = 0;
317 /* zero out the NUMA config */
318 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
319 internal_cfg->socket_mem[i] = 0;
320 internal_cfg->force_socket_limits = 0;
321 /* zero out the NUMA limits config */
322 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
323 internal_cfg->socket_limit[i] = 0;
324 /* zero out hugedir descriptors */
325 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
326 memset(&internal_cfg->hugepage_info[i], 0,
327 sizeof(internal_cfg->hugepage_info[0]));
328 internal_cfg->hugepage_info[i].lock_descriptor = -1;
330 internal_cfg->base_virtaddr = 0;
333 internal_cfg->syslog_facility = LOG_DAEMON;
336 /* if set to NONE, interrupt mode is determined automatically */
337 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
338 memset(internal_cfg->vfio_vf_token, 0,
339 sizeof(internal_cfg->vfio_vf_token));
341 #ifdef RTE_LIBEAL_USE_HPET
342 internal_cfg->no_hpet = 0;
344 internal_cfg->no_hpet = 1;
346 internal_cfg->vmware_tsc_map = 0;
347 internal_cfg->create_uio_dev = 0;
348 internal_cfg->iova_mode = RTE_IOVA_DC;
349 internal_cfg->user_mbuf_pool_ops_name = NULL;
350 CPU_ZERO(&internal_cfg->ctrl_cpuset);
351 internal_cfg->init_complete = 0;
352 internal_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH;
353 internal_cfg->max_simd_bitwidth.forced = 0;
357 eal_plugin_add(const char *path)
359 struct shared_driver *solib;
361 solib = malloc(sizeof(*solib));
363 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
366 memset(solib, 0, sizeof(*solib));
367 strlcpy(solib->name, path, PATH_MAX);
368 TAILQ_INSERT_TAIL(&solib_list, solib, next);
373 #ifdef RTE_EXEC_ENV_WINDOWS
375 eal_plugins_init(void)
382 eal_plugindir_init(const char *path)
385 struct dirent *dent = NULL;
386 char sopath[PATH_MAX];
388 if (path == NULL || *path == '\0')
393 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
394 path, strerror(errno));
398 while ((dent = readdir(d)) != NULL) {
400 int nlen = strnlen(dent->d_name, sizeof(dent->d_name));
402 /* check if name ends in .so or .so.ABI_VERSION */
403 if (strcmp(&dent->d_name[nlen - 3], ".so") != 0 &&
404 strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)],
405 ".so."ABI_VERSION) != 0)
408 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
410 /* if a regular file, add to list to load */
411 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
414 if (eal_plugin_add(sopath) == -1)
419 /* XXX this ignores failures from readdir() itself */
420 return (dent == NULL) ? 0 : -1;
424 verify_perms(const char *dirpath)
428 /* if not root, check down one level first */
429 if (strcmp(dirpath, "/") != 0) {
430 static __thread char last_dir_checked[PATH_MAX];
434 strlcpy(copy, dirpath, PATH_MAX);
436 if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
437 if (verify_perms(dir) != 0)
439 strlcpy(last_dir_checked, dir, PATH_MAX);
443 /* call stat to check for permissions and ensure not world writable */
444 if (stat(dirpath, &st) != 0) {
445 RTE_LOG(ERR, EAL, "Error with stat on %s, %s\n",
446 dirpath, strerror(errno));
449 if (st.st_mode & S_IWOTH) {
451 "Error, directory path %s is world-writable and insecure\n",
460 eal_dlopen(const char *pathname)
463 char *realp = realpath(pathname, NULL);
465 if (realp == NULL && errno == ENOENT) {
466 /* not a full or relative path, try a load from system dirs */
467 retval = dlopen(pathname, RTLD_NOW);
469 RTE_LOG(ERR, EAL, "%s\n", dlerror());
473 RTE_LOG(ERR, EAL, "Error with realpath for %s, %s\n",
474 pathname, strerror(errno));
477 if (strnlen(realp, PATH_MAX) == PATH_MAX) {
478 RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n");
482 /* do permissions checks */
483 if (verify_perms(realp) != 0)
486 retval = dlopen(realp, RTLD_NOW);
488 RTE_LOG(ERR, EAL, "%s\n", dlerror());
495 is_shared_build(void)
497 #define EAL_SO "librte_eal.so"
499 size_t len, minlen = strlen(EAL_SO);
501 len = strlcpy(soname, EAL_SO"."ABI_VERSION, sizeof(soname));
502 if (len > sizeof(soname)) {
503 RTE_LOG(ERR, EAL, "Shared lib name too long in shared build check\n");
504 len = sizeof(soname) - 1;
507 while (len >= minlen) {
510 /* check if we have this .so loaded, if so - shared build */
511 RTE_LOG(DEBUG, EAL, "Checking presence of .so '%s'\n", soname);
512 handle = dlopen(soname, RTLD_LAZY | RTLD_NOLOAD);
513 if (handle != NULL) {
514 RTE_LOG(INFO, EAL, "Detected shared linkage of DPDK\n");
519 /* remove any version numbers off the end to retry */
521 if (soname[len] == '.') {
527 RTE_LOG(INFO, EAL, "Detected static linkage of DPDK\n");
532 eal_plugins_init(void)
534 struct shared_driver *solib = NULL;
537 /* If we are not statically linked, add default driver loading
538 * path if it exists as a directory.
539 * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL
540 * shared library is not already loaded i.e. it's statically linked.)
542 if (is_shared_build() &&
543 *default_solib_dir != '\0' &&
544 stat(default_solib_dir, &sb) == 0 &&
546 eal_plugin_add(default_solib_dir);
548 TAILQ_FOREACH(solib, &solib_list, next) {
550 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
551 if (eal_plugindir_init(solib->name) == -1) {
553 "Cannot init plugin directory %s\n",
558 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
560 solib->lib_handle = eal_dlopen(solib->name);
561 if (solib->lib_handle == NULL)
571 * Parse the coremask given as argument (hexadecimal string) and fill
572 * the global configuration (core role and core count) with the parsed
575 static int xdigit2val(unsigned char c)
589 eal_parse_service_coremask(const char *coremask)
591 struct rte_config *cfg = rte_eal_get_configuration();
593 unsigned int count = 0;
596 uint32_t taken_lcore_count = 0;
598 if (coremask == NULL)
600 /* Remove all blank characters ahead and after .
601 * Remove 0x/0X if exists.
603 while (isblank(*coremask))
605 if (coremask[0] == '0' && ((coremask[1] == 'x')
606 || (coremask[1] == 'X')))
608 i = strlen(coremask);
609 while ((i > 0) && isblank(coremask[i - 1]))
615 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
617 if (isxdigit(c) == 0) {
618 /* invalid characters */
622 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
624 if ((1 << j) & val) {
625 /* handle main lcore already parsed */
626 uint32_t lcore = idx;
627 if (main_lcore_parsed &&
628 cfg->main_lcore == lcore) {
630 "lcore %u is main lcore, cannot use as service core\n",
635 if (eal_cpu_detected(idx) == 0) {
637 "lcore %u unavailable\n", idx);
641 if (cfg->lcore_role[idx] == ROLE_RTE)
644 lcore_config[idx].core_role = ROLE_SERVICE;
651 if (coremask[i] != '0')
654 for (; idx < RTE_MAX_LCORE; idx++)
655 lcore_config[idx].core_index = -1;
660 if (core_parsed && taken_lcore_count != count) {
661 RTE_LOG(WARNING, EAL,
662 "Not all service cores are in the coremask. "
663 "Please ensure -c or -l includes service cores\n");
666 cfg->service_lcore_count = count;
671 eal_service_cores_parsed(void)
674 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
675 if (lcore_config[idx].core_role == ROLE_SERVICE)
682 update_lcore_config(int *cores)
684 struct rte_config *cfg = rte_eal_get_configuration();
685 unsigned int count = 0;
689 for (i = 0; i < RTE_MAX_LCORE; i++) {
690 if (cores[i] != -1) {
691 if (eal_cpu_detected(i) == 0) {
692 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
696 cfg->lcore_role[i] = ROLE_RTE;
699 cfg->lcore_role[i] = ROLE_OFF;
701 lcore_config[i].core_index = cores[i];
704 cfg->lcore_count = count;
709 check_core_list(int *lcores, unsigned int count)
711 char lcorestr[RTE_MAX_LCORE * 10];
712 bool overflow = false;
716 for (i = 0; i < count; i++) {
717 if (lcores[i] < RTE_MAX_LCORE)
720 RTE_LOG(ERR, EAL, "lcore %d >= RTE_MAX_LCORE (%d)\n",
721 lcores[i], RTE_MAX_LCORE);
728 * We've encountered a core that's greater than RTE_MAX_LCORE,
729 * suggest using --lcores option to map lcores onto physical cores
730 * greater than RTE_MAX_LCORE.
732 for (i = 0; i < count; i++) {
733 ret = snprintf(&lcorestr[len], sizeof(lcorestr) - len,
734 "%d@%d,", i, lcores[i]);
739 lcorestr[len - 1] = 0;
740 RTE_LOG(ERR, EAL, "To use high physical core ids, "
741 "please use --lcores to map them to lcore ids below RTE_MAX_LCORE, "
742 "e.g. --lcores %s\n", lcorestr);
747 eal_parse_coremask(const char *coremask, int *cores)
749 const char *coremask_orig = coremask;
750 int lcores[RTE_MAX_LCORE];
751 unsigned int count = 0;
756 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
760 /* Remove all blank characters ahead and after .
761 * Remove 0x/0X if exists.
763 while (isblank(*coremask))
765 if (coremask[0] == '0' && ((coremask[1] == 'x')
766 || (coremask[1] == 'X')))
768 i = strlen(coremask);
769 while ((i > 0) && isblank(coremask[i - 1]))
772 RTE_LOG(ERR, EAL, "No lcores in coremask: [%s]\n",
777 for (i = i - 1; i >= 0; i--) {
779 if (isxdigit(c) == 0) {
780 /* invalid characters */
781 RTE_LOG(ERR, EAL, "invalid characters in coremask: [%s]\n",
786 for (j = 0; j < BITS_PER_HEX; j++, idx++)
788 if ((1 << j) & val) {
789 if (count >= RTE_MAX_LCORE) {
790 RTE_LOG(ERR, EAL, "Too many lcores provided. Cannot exceed RTE_MAX_LCORE (%d)\n",
794 lcores[count++] = idx;
799 RTE_LOG(ERR, EAL, "No lcores in coremask: [%s]\n",
804 if (check_core_list(lcores, count))
808 * Now that we've got a list of cores no longer than RTE_MAX_LCORE,
809 * and no lcore in that list is greater than RTE_MAX_LCORE, populate
814 cores[lcores[count]] = count;
815 } while (count != 0);
821 eal_parse_service_corelist(const char *corelist)
823 struct rte_config *cfg = rte_eal_get_configuration();
827 uint32_t min, max, idx;
828 uint32_t taken_lcore_count = 0;
830 if (corelist == NULL)
833 /* Remove all blank characters ahead and after */
834 while (isblank(*corelist))
836 i = strlen(corelist);
837 while ((i > 0) && isblank(corelist[i - 1]))
840 /* Get list of cores */
843 while (isblank(*corelist))
845 if (*corelist == '\0')
848 idx = strtoul(corelist, &end, 10);
849 if (errno || end == NULL)
851 if (idx >= RTE_MAX_LCORE)
853 while (isblank(*end))
857 } else if ((*end == ',') || (*end == '\0')) {
859 if (min == RTE_MAX_LCORE)
861 for (idx = min; idx <= max; idx++) {
862 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
863 /* handle main lcore already parsed */
864 uint32_t lcore = idx;
865 if (cfg->main_lcore == lcore &&
868 "Error: lcore %u is main lcore, cannot use as service core\n",
872 if (cfg->lcore_role[idx] == ROLE_RTE)
875 lcore_config[idx].core_role =
884 } while (*end != '\0');
889 if (core_parsed && taken_lcore_count != count) {
890 RTE_LOG(WARNING, EAL,
891 "Not all service cores were in the coremask. "
892 "Please ensure -c or -l includes service cores\n");
899 eal_parse_corelist(const char *corelist, int *cores)
901 unsigned int count = 0, i;
902 int lcores[RTE_MAX_LCORE];
907 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
910 /* Remove all blank characters ahead */
911 while (isblank(*corelist))
914 /* Get list of cores */
917 while (isblank(*corelist))
919 if (*corelist == '\0')
922 idx = strtol(corelist, &end, 10);
923 if (errno || end == NULL)
927 while (isblank(*end))
931 } else if ((*end == ',') || (*end == '\0')) {
935 for (idx = min; idx <= max; idx++) {
938 /* Check if this idx is already present */
939 for (i = 0; i < count; i++) {
940 if (lcores[i] == idx)
945 if (count >= RTE_MAX_LCORE) {
946 RTE_LOG(ERR, EAL, "Too many lcores provided. Cannot exceed RTE_MAX_LCORE (%d)\n",
950 lcores[count++] = idx;
956 } while (*end != '\0');
961 if (check_core_list(lcores, count))
965 * Now that we've got a list of cores no longer than RTE_MAX_LCORE,
966 * and no lcore in that list is greater than RTE_MAX_LCORE, populate
971 cores[lcores[count]] = count;
972 } while (count != 0);
977 /* Changes the lcore id of the main thread */
979 eal_parse_main_lcore(const char *arg)
982 struct rte_config *cfg = rte_eal_get_configuration();
985 cfg->main_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
986 if (errno || parsing_end[0] != 0)
988 if (cfg->main_lcore >= RTE_MAX_LCORE)
990 main_lcore_parsed = 1;
992 /* ensure main core is not used as service core */
993 if (lcore_config[cfg->main_lcore].core_role == ROLE_SERVICE) {
995 "Error: Main lcore is used as a service core\n");
1003 * Parse elem, the elem could be single number/range or '(' ')' group
1004 * 1) A single number elem, it's just a simple digit. e.g. 9
1005 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
1006 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
1007 * Within group elem, '-' used for a range separator;
1008 * ',' used for a single number.
1011 eal_parse_set(const char *input, rte_cpuset_t *set)
1014 const char *str = input;
1020 while (isblank(*str))
1023 /* only digit or left bracket is qualify for start point */
1024 if ((!isdigit(*str) && *str != '(') || *str == '\0')
1027 /* process single number or single range of number */
1030 idx = strtoul(str, &end, 10);
1031 if (errno || end == NULL || idx >= CPU_SETSIZE)
1034 while (isblank(*end))
1040 /* process single <number>-<number> */
1042 while (isblank(*end))
1048 idx = strtoul(end, &end, 10);
1049 if (errno || end == NULL || idx >= CPU_SETSIZE)
1052 while (isblank(*end))
1054 if (*end != ',' && *end != '\0')
1058 if (*end != ',' && *end != '\0' &&
1062 for (idx = RTE_MIN(min, max);
1063 idx <= RTE_MAX(min, max); idx++)
1070 /* process set within bracket */
1072 while (isblank(*str))
1077 min = RTE_MAX_LCORE;
1080 /* go ahead to the first digit */
1081 while (isblank(*str))
1086 /* get the digit value */
1088 idx = strtoul(str, &end, 10);
1089 if (errno || end == NULL || idx >= CPU_SETSIZE)
1092 /* go ahead to separator '-',',' and ')' */
1093 while (isblank(*end))
1096 if (min == RTE_MAX_LCORE)
1098 else /* avoid continuous '-' */
1100 } else if ((*end == ',') || (*end == ')')) {
1102 if (min == RTE_MAX_LCORE)
1104 for (idx = RTE_MIN(min, max);
1105 idx <= RTE_MAX(min, max); idx++)
1108 min = RTE_MAX_LCORE;
1113 } while (*end != '\0' && *end != ')');
1116 * to avoid failure that tail blank makes end character check fail
1117 * in eal_parse_lcores( )
1119 while (isblank(*str))
1126 check_cpuset(rte_cpuset_t *set)
1130 for (idx = 0; idx < CPU_SETSIZE; idx++) {
1131 if (!CPU_ISSET(idx, set))
1134 if (eal_cpu_detected(idx) == 0) {
1135 RTE_LOG(ERR, EAL, "core %u "
1136 "unavailable\n", idx);
1144 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
1145 * lcores, cpus could be a single digit/range or a group.
1146 * '(' and ')' are necessary if it's a group.
1147 * If not supply '@cpus', the value of cpus uses the same as lcores.
1148 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
1149 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
1150 * lcore 1 runs on cpuset 0x2 (cpu 1)
1151 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
1152 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
1153 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
1154 * lcore 7 runs on cpuset 0x80 (cpu 7)
1155 * lcore 8 runs on cpuset 0x100 (cpu 8)
1158 eal_parse_lcores(const char *lcores)
1160 struct rte_config *cfg = rte_eal_get_configuration();
1161 rte_cpuset_t lcore_set;
1162 unsigned int set_count;
1165 const char *lcore_start = NULL;
1166 const char *end = NULL;
1168 rte_cpuset_t cpuset;
1175 /* Remove all blank characters ahead and after */
1176 while (isblank(*lcores))
1181 /* Reset lcore config */
1182 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1183 cfg->lcore_role[idx] = ROLE_OFF;
1184 lcore_config[idx].core_index = -1;
1185 CPU_ZERO(&lcore_config[idx].cpuset);
1188 /* Get list of cores */
1190 while (isblank(*lcores))
1192 if (*lcores == '\0')
1197 /* record lcore_set start point */
1198 lcore_start = lcores;
1200 /* go across a complete bracket */
1201 if (*lcore_start == '(') {
1202 lcores += strcspn(lcores, ")");
1203 if (*lcores++ == '\0')
1207 /* scan the separator '@', ','(next) or '\0'(finish) */
1208 lcores += strcspn(lcores, "@,");
1210 if (*lcores == '@') {
1211 /* explicit assign cpuset and update the end cursor */
1212 offset = eal_parse_set(lcores + 1, &cpuset);
1215 end = lcores + 1 + offset;
1216 } else { /* ',' or '\0' */
1217 /* haven't given cpuset, current loop done */
1220 /* go back to check <number>-<number> */
1221 offset = strcspn(lcore_start, "(-");
1222 if (offset < (end - lcore_start) &&
1223 *(lcore_start + offset) != '(')
1227 if (*end != ',' && *end != '\0')
1230 /* parse lcore_set from start point */
1231 if (eal_parse_set(lcore_start, &lcore_set) < 0)
1234 /* without '@', by default using lcore_set as cpuset */
1236 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
1238 set_count = CPU_COUNT(&lcore_set);
1239 /* start to update lcore_set */
1240 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1241 if (!CPU_ISSET(idx, &lcore_set))
1245 if (cfg->lcore_role[idx] != ROLE_RTE) {
1246 lcore_config[idx].core_index = count;
1247 cfg->lcore_role[idx] = ROLE_RTE;
1253 CPU_SET(idx, &cpuset);
1256 if (check_cpuset(&cpuset) < 0)
1258 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
1259 sizeof(rte_cpuset_t));
1262 /* some cores from the lcore_set can't be handled by EAL */
1267 } while (*end != '\0');
1272 cfg->lcore_count = count;
1280 #ifndef RTE_EXEC_ENV_WINDOWS
1282 eal_parse_syslog(const char *facility, struct internal_config *conf)
1285 static const struct {
1289 { "auth", LOG_AUTH },
1290 { "cron", LOG_CRON },
1291 { "daemon", LOG_DAEMON },
1293 { "kern", LOG_KERN },
1295 { "mail", LOG_MAIL },
1296 { "news", LOG_NEWS },
1297 { "syslog", LOG_SYSLOG },
1298 { "user", LOG_USER },
1299 { "uucp", LOG_UUCP },
1300 { "local0", LOG_LOCAL0 },
1301 { "local1", LOG_LOCAL1 },
1302 { "local2", LOG_LOCAL2 },
1303 { "local3", LOG_LOCAL3 },
1304 { "local4", LOG_LOCAL4 },
1305 { "local5", LOG_LOCAL5 },
1306 { "local6", LOG_LOCAL6 },
1307 { "local7", LOG_LOCAL7 },
1311 for (i = 0; map[i].name; i++) {
1312 if (!strcmp(facility, map[i].name)) {
1313 conf->syslog_facility = map[i].value;
1326 printf("Log type is a pattern matching items of this list"
1327 " (plugins may be missing):\n");
1328 rte_log_list_types(stdout, "\t");
1330 printf("Syntax using globbing pattern: ");
1331 printf("--"OPT_LOG_LEVEL" pattern:level\n");
1332 printf("Syntax using regular expression: ");
1333 printf("--"OPT_LOG_LEVEL" regexp,level\n");
1334 printf("Syntax for the global level: ");
1335 printf("--"OPT_LOG_LEVEL" level\n");
1336 printf("Logs are emitted if allowed by both global and specific levels.\n");
1338 printf("Log level can be a number or the first letters of its name:\n");
1339 for (level = 1; level <= RTE_LOG_MAX; level++)
1340 printf("\t%d %s\n", level, eal_log_level2str(level));
1344 eal_parse_log_priority(const char *level)
1346 size_t len = strlen(level);
1354 /* look for named values, skip 0 which is not a valid level */
1355 for (i = 1; i <= RTE_LOG_MAX; i++) {
1356 if (strncmp(eal_log_level2str(i), level, len) == 0)
1360 /* not a string, maybe it is numeric */
1362 tmp = strtoul(level, &end, 0);
1364 /* check for errors */
1365 if (errno != 0 || end == NULL || *end != '\0' ||
1373 eal_parse_log_level(const char *arg)
1375 const char *pattern = NULL;
1376 const char *regex = NULL;
1380 if (strcmp(arg, "help") == 0) {
1389 if ((level = strchr(str, ','))) {
1392 } else if ((level = strchr(str, ':'))) {
1399 priority = eal_parse_log_priority(level);
1400 if (priority <= 0) {
1401 fprintf(stderr, "Invalid log level: %s\n", level);
1404 if (priority > (int)RTE_LOG_MAX) {
1405 fprintf(stderr, "Log level %d higher than maximum (%d)\n",
1406 priority, RTE_LOG_MAX);
1407 priority = RTE_LOG_MAX;
1411 if (rte_log_set_level_regexp(regex, priority) < 0) {
1412 fprintf(stderr, "cannot set log level %s,%d\n",
1416 if (eal_log_save_regexp(regex, priority) < 0)
1418 } else if (pattern) {
1419 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1420 fprintf(stderr, "cannot set log level %s:%d\n",
1424 if (eal_log_save_pattern(pattern, priority) < 0)
1427 rte_log_set_global_level(priority);
1438 static enum rte_proc_type_t
1439 eal_parse_proc_type(const char *arg)
1441 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1442 return RTE_PROC_PRIMARY;
1443 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1444 return RTE_PROC_SECONDARY;
1445 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1446 return RTE_PROC_AUTO;
1448 return RTE_PROC_INVALID;
1452 eal_parse_iova_mode(const char *name)
1455 struct internal_config *internal_conf =
1456 eal_get_internal_configuration();
1461 if (!strcmp("pa", name))
1463 else if (!strcmp("va", name))
1468 internal_conf->iova_mode = mode;
1473 eal_parse_simd_bitwidth(const char *arg)
1476 unsigned long bitwidth;
1478 struct internal_config *internal_conf =
1479 eal_get_internal_configuration();
1481 if (arg == NULL || arg[0] == '\0')
1485 bitwidth = strtoul(arg, &end, 0);
1487 /* check for errors */
1488 if (errno != 0 || end == NULL || *end != '\0' || bitwidth > RTE_VECT_SIMD_MAX)
1492 bitwidth = (unsigned long) RTE_VECT_SIMD_MAX;
1493 ret = rte_vect_set_max_simd_bitwidth(bitwidth);
1496 internal_conf->max_simd_bitwidth.forced = 1;
1501 eal_parse_base_virtaddr(const char *arg)
1505 struct internal_config *internal_conf =
1506 eal_get_internal_configuration();
1509 addr = strtoull(arg, &end, 16);
1511 /* check for errors */
1512 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1515 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1517 if (addr >= UINTPTR_MAX)
1521 /* align the addr on 16M boundary, 16MB is the minimum huge page
1522 * size on IBM Power architecture. If the addr is aligned to 16MB,
1523 * it can align to 2MB for x86. So this alignment can also be used
1524 * on x86 and other architectures.
1526 internal_conf->base_virtaddr =
1527 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1532 /* caller is responsible for freeing the returned string */
1534 available_cores(void)
1542 /* find the first available cpu */
1543 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1544 if (eal_cpu_detected(idx) == 0)
1548 if (idx >= RTE_MAX_LCORE)
1551 /* first sequence */
1552 if (asprintf(&str, "%d", idx) < 0)
1557 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1558 if (eal_cpu_detected(idx) == 0)
1561 if (idx == previous + 1) {
1567 /* finish current sequence */
1569 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1578 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1588 /* finish last sequence */
1590 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1601 #define HUGE_UNLINK_NEVER "never"
1604 eal_parse_huge_unlink(const char *arg, struct hugepage_file_discipline *out)
1606 if (arg == NULL || strcmp(arg, "always") == 0) {
1607 out->unlink_before_mapping = true;
1610 if (strcmp(arg, "existing") == 0) {
1611 /* same as not specifying the option */
1614 if (strcmp(arg, HUGE_UNLINK_NEVER) == 0) {
1615 RTE_LOG(WARNING, EAL, "Using --"OPT_HUGE_UNLINK"="
1616 HUGE_UNLINK_NEVER" may create data leaks.\n");
1617 out->unlink_existing = false;
1624 eal_parse_common_option(int opt, const char *optarg,
1625 struct internal_config *conf)
1634 if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0)
1642 if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0)
1648 int lcore_indexes[RTE_MAX_LCORE];
1650 if (eal_service_cores_parsed())
1651 RTE_LOG(WARNING, EAL,
1652 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1653 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1654 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1657 if (update_lcore_config(lcore_indexes) < 0) {
1658 char *available = available_cores();
1661 "invalid coremask, please check specified cores are part of %s\n",
1668 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1669 (core_parsed == LCORE_OPT_LST) ? "-l" :
1670 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1675 core_parsed = LCORE_OPT_MSK;
1680 int lcore_indexes[RTE_MAX_LCORE];
1682 if (eal_service_cores_parsed())
1683 RTE_LOG(WARNING, EAL,
1684 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1686 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1687 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1690 if (update_lcore_config(lcore_indexes) < 0) {
1691 char *available = available_cores();
1694 "invalid core list, please check specified cores are part of %s\n",
1701 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1702 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1703 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1708 core_parsed = LCORE_OPT_LST;
1711 /* service coremask */
1713 if (eal_parse_service_coremask(optarg) < 0) {
1714 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1718 /* service corelist */
1720 if (eal_parse_service_corelist(optarg) < 0) {
1721 RTE_LOG(ERR, EAL, "invalid service core list\n");
1725 /* size of memory */
1727 conf->memory = atoi(optarg);
1728 conf->memory *= 1024ULL;
1729 conf->memory *= 1024ULL;
1732 /* force number of channels */
1734 conf->force_nchannel = atoi(optarg);
1735 if (conf->force_nchannel == 0) {
1736 RTE_LOG(ERR, EAL, "invalid channel number\n");
1740 /* force number of ranks */
1742 conf->force_nrank = atoi(optarg);
1743 if (conf->force_nrank == 0 ||
1744 conf->force_nrank > 16) {
1745 RTE_LOG(ERR, EAL, "invalid rank number\n");
1749 /* force loading of external driver */
1751 if (eal_plugin_add(optarg) == -1)
1755 /* since message is explicitly requested by user, we
1756 * write message at highest log level so it can always
1758 * even if info or warning messages are disabled */
1759 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1763 case OPT_HUGE_UNLINK_NUM:
1764 if (eal_parse_huge_unlink(optarg, &conf->hugepage_file) < 0) {
1765 RTE_LOG(ERR, EAL, "invalid --"OPT_HUGE_UNLINK" option\n");
1770 case OPT_NO_HUGE_NUM:
1771 conf->no_hugetlbfs = 1;
1772 /* no-huge is legacy mem */
1773 conf->legacy_mem = 1;
1776 case OPT_NO_PCI_NUM:
1780 case OPT_NO_HPET_NUM:
1784 case OPT_VMWARE_TSC_MAP_NUM:
1785 conf->vmware_tsc_map = 1;
1788 case OPT_NO_SHCONF_NUM:
1789 conf->no_shconf = 1;
1792 case OPT_IN_MEMORY_NUM:
1793 conf->in_memory = 1;
1794 /* in-memory is a superset of noshconf and huge-unlink */
1795 conf->no_shconf = 1;
1796 conf->hugepage_file.unlink_before_mapping = true;
1799 case OPT_PROC_TYPE_NUM:
1800 conf->process_type = eal_parse_proc_type(optarg);
1803 case OPT_MAIN_LCORE_NUM:
1804 if (eal_parse_main_lcore(optarg) < 0) {
1805 RTE_LOG(ERR, EAL, "invalid parameter for --"
1806 OPT_MAIN_LCORE "\n");
1812 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1818 #ifndef RTE_EXEC_ENV_WINDOWS
1819 case OPT_SYSLOG_NUM:
1820 if (eal_parse_syslog(optarg, conf) < 0) {
1821 RTE_LOG(ERR, EAL, "invalid parameters for --"
1828 case OPT_LOG_LEVEL_NUM: {
1829 if (eal_parse_log_level(optarg) < 0) {
1831 "invalid parameters for --"
1832 OPT_LOG_LEVEL "\n");
1838 #ifndef RTE_EXEC_ENV_WINDOWS
1839 case OPT_TRACE_NUM: {
1840 if (eal_trace_args_save(optarg) < 0) {
1841 RTE_LOG(ERR, EAL, "invalid parameters for --"
1848 case OPT_TRACE_DIR_NUM: {
1849 if (eal_trace_dir_args_save(optarg) < 0) {
1850 RTE_LOG(ERR, EAL, "invalid parameters for --"
1851 OPT_TRACE_DIR "\n");
1857 case OPT_TRACE_BUF_SIZE_NUM: {
1858 if (eal_trace_bufsz_args_save(optarg) < 0) {
1859 RTE_LOG(ERR, EAL, "invalid parameters for --"
1860 OPT_TRACE_BUF_SIZE "\n");
1866 case OPT_TRACE_MODE_NUM: {
1867 if (eal_trace_mode_args_save(optarg) < 0) {
1868 RTE_LOG(ERR, EAL, "invalid parameters for --"
1869 OPT_TRACE_MODE "\n");
1874 #endif /* !RTE_EXEC_ENV_WINDOWS */
1876 case OPT_LCORES_NUM:
1877 if (eal_parse_lcores(optarg) < 0) {
1878 RTE_LOG(ERR, EAL, "invalid parameter for --"
1884 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1885 (core_parsed == LCORE_OPT_LST) ? "-l" :
1886 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1891 core_parsed = LCORE_OPT_MAP;
1893 case OPT_LEGACY_MEM_NUM:
1894 conf->legacy_mem = 1;
1896 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1897 conf->single_file_segments = 1;
1899 case OPT_IOVA_MODE_NUM:
1900 if (eal_parse_iova_mode(optarg) < 0) {
1901 RTE_LOG(ERR, EAL, "invalid parameters for --"
1902 OPT_IOVA_MODE "\n");
1906 case OPT_BASE_VIRTADDR_NUM:
1907 if (eal_parse_base_virtaddr(optarg) < 0) {
1908 RTE_LOG(ERR, EAL, "invalid parameter for --"
1909 OPT_BASE_VIRTADDR "\n");
1913 case OPT_TELEMETRY_NUM:
1915 case OPT_NO_TELEMETRY_NUM:
1916 conf->no_telemetry = 1;
1918 case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM:
1919 if (eal_parse_simd_bitwidth(optarg) < 0) {
1920 RTE_LOG(ERR, EAL, "invalid parameter for --"
1921 OPT_FORCE_MAX_SIMD_BITWIDTH "\n");
1926 /* don't know what to do, leave this to caller */
1936 "Options allow (-a) and block (-b) can't be used at the same time\n");
1941 eal_auto_detect_cores(struct rte_config *cfg)
1943 unsigned int lcore_id;
1944 unsigned int removed = 0;
1945 rte_cpuset_t affinity_set;
1947 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1949 CPU_ZERO(&affinity_set);
1951 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1952 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1953 !CPU_ISSET(lcore_id, &affinity_set)) {
1954 cfg->lcore_role[lcore_id] = ROLE_OFF;
1959 cfg->lcore_count -= removed;
1963 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1965 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1966 rte_cpuset_t default_set;
1967 unsigned int lcore_id;
1969 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1970 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1972 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1974 RTE_CPU_NOT(cpuset, cpuset);
1976 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1978 CPU_ZERO(&default_set);
1980 RTE_CPU_AND(cpuset, cpuset, &default_set);
1982 /* if no remaining cpu, use main lcore cpu affinity */
1983 if (!CPU_COUNT(cpuset)) {
1984 memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset,
1990 eal_cleanup_config(struct internal_config *internal_cfg)
1992 free(internal_cfg->hugefile_prefix);
1993 free(internal_cfg->hugepage_dir);
1994 free(internal_cfg->user_mbuf_pool_ops_name);
2000 eal_adjust_config(struct internal_config *internal_cfg)
2003 struct rte_config *cfg = rte_eal_get_configuration();
2004 struct internal_config *internal_conf =
2005 eal_get_internal_configuration();
2008 eal_auto_detect_cores(cfg);
2010 if (internal_conf->process_type == RTE_PROC_AUTO)
2011 internal_conf->process_type = eal_proc_type_detect();
2013 /* default main lcore is the first one */
2014 if (!main_lcore_parsed) {
2015 cfg->main_lcore = rte_get_next_lcore(-1, 0, 0);
2016 if (cfg->main_lcore >= RTE_MAX_LCORE)
2018 lcore_config[cfg->main_lcore].core_role = ROLE_RTE;
2021 compute_ctrl_threads_cpuset(internal_cfg);
2023 /* if no memory amounts were requested, this will result in 0 and
2024 * will be overridden later, right after eal_hugepage_info_init() */
2025 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
2026 internal_cfg->memory += internal_cfg->socket_mem[i];
2032 eal_check_common_options(struct internal_config *internal_cfg)
2034 struct rte_config *cfg = rte_eal_get_configuration();
2035 const struct internal_config *internal_conf =
2036 eal_get_internal_configuration();
2038 if (cfg->lcore_role[cfg->main_lcore] != ROLE_RTE) {
2039 RTE_LOG(ERR, EAL, "Main lcore is not enabled for DPDK\n");
2043 if (internal_cfg->process_type == RTE_PROC_INVALID) {
2044 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
2047 if (internal_cfg->hugefile_prefix != NULL &&
2048 strlen(internal_cfg->hugefile_prefix) < 1) {
2049 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
2052 if (internal_cfg->hugepage_dir != NULL &&
2053 strlen(internal_cfg->hugepage_dir) < 1) {
2054 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
2057 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
2058 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
2059 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
2062 if (strchr(eal_get_hugefile_prefix(), '%') != NULL) {
2063 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
2067 if (mem_parsed && internal_cfg->force_sockets == 1) {
2068 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
2069 "be specified at the same time\n");
2072 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
2073 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
2074 "be specified together with --"OPT_NO_HUGE"\n");
2077 if (internal_cfg->no_hugetlbfs &&
2078 internal_cfg->hugepage_file.unlink_before_mapping &&
2079 !internal_cfg->in_memory) {
2080 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
2081 "be specified together with --"OPT_NO_HUGE"\n");
2084 if (internal_conf->force_socket_limits && internal_conf->legacy_mem) {
2085 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
2086 " is only supported in non-legacy memory mode\n");
2088 if (internal_cfg->single_file_segments &&
2089 internal_cfg->hugepage_file.unlink_before_mapping &&
2090 !internal_cfg->in_memory) {
2091 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
2092 "not compatible with --"OPT_HUGE_UNLINK"\n");
2095 if (!internal_cfg->hugepage_file.unlink_existing &&
2096 internal_cfg->in_memory) {
2097 RTE_LOG(ERR, EAL, "Option --"OPT_IN_MEMORY" is not compatible "
2098 "with --"OPT_HUGE_UNLINK"="HUGE_UNLINK_NEVER"\n");
2101 if (internal_cfg->legacy_mem &&
2102 internal_cfg->in_memory) {
2103 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
2104 "with --"OPT_IN_MEMORY"\n");
2107 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
2108 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
2109 "with --"OPT_MATCH_ALLOCATIONS"\n");
2112 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
2113 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
2114 "with --"OPT_MATCH_ALLOCATIONS"\n");
2117 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
2118 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
2119 "amount of reserved memory can be adjusted with "
2120 "-m or --"OPT_SOCKET_MEM"\n");
2127 rte_vect_get_max_simd_bitwidth(void)
2129 const struct internal_config *internal_conf =
2130 eal_get_internal_configuration();
2131 return internal_conf->max_simd_bitwidth.bitwidth;
2135 rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
2137 struct internal_config *internal_conf =
2138 eal_get_internal_configuration();
2139 if (internal_conf->max_simd_bitwidth.forced) {
2140 RTE_LOG(NOTICE, EAL, "Cannot set max SIMD bitwidth - user runtime override enabled");
2144 if (bitwidth < RTE_VECT_SIMD_DISABLED || !rte_is_power_of_2(bitwidth)) {
2145 RTE_LOG(ERR, EAL, "Invalid bitwidth value!\n");
2148 internal_conf->max_simd_bitwidth.bitwidth = bitwidth;
2153 eal_common_usage(void)
2155 printf("[options]\n\n"
2156 "EAL common options:\n"
2157 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
2158 " -l CORELIST List of cores to run on\n"
2159 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
2160 " where c1, c2, etc are core indexes between 0 and %d\n"
2161 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
2162 " The argument format is\n"
2163 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
2164 " lcores and cpus list are grouped by '(' and ')'\n"
2165 " Within the group, '-' is used for range separator,\n"
2166 " ',' is used for single number separator.\n"
2167 " '( )' can be omitted for single element group,\n"
2168 " '@' can be omitted if cpus and lcores have the same value\n"
2169 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
2170 " --"OPT_MAIN_LCORE" ID Core ID that is used as main\n"
2171 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
2172 " -n CHANNELS Number of memory channels\n"
2173 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
2174 " -r RANKS Force number of memory ranks (don't detect)\n"
2175 " -b, --block Add a device to the blocked list.\n"
2176 " Prevent EAL from using this device. The argument\n"
2177 " format for PCI devices is <domain:bus:devid.func>.\n"
2178 " -a, --allow Add a device to the allow list.\n"
2179 " Only use the specified devices. The argument format\n"
2180 " for PCI devices is <[domain:]bus:devid.func>.\n"
2181 " This option can be present several times.\n"
2182 " [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n"
2183 " --"OPT_VDEV" Add a virtual device.\n"
2184 " The argument format is <driver><id>[,key=val,...]\n"
2185 " (ex: --vdev=net_pcap0,iface=eth2).\n"
2186 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
2187 " 'va' for IOVA_VA\n"
2188 " -d LIB.so|DIR Add a driver or driver directory\n"
2189 " (can be used multiple times)\n"
2190 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
2191 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
2192 #ifndef RTE_EXEC_ENV_WINDOWS
2193 " --"OPT_SYSLOG" Set syslog facility\n"
2195 " --"OPT_LOG_LEVEL"=<level> Set global log level\n"
2196 " --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
2197 " Set specific log level\n"
2198 " --"OPT_LOG_LEVEL"=help Show log types and levels\n"
2199 #ifndef RTE_EXEC_ENV_WINDOWS
2200 " --"OPT_TRACE"=<regex-match>\n"
2201 " Enable trace based on regular expression trace name.\n"
2202 " By default, the trace is disabled.\n"
2203 " User must specify this option to enable trace.\n"
2204 " --"OPT_TRACE_DIR"=<directory path>\n"
2205 " Specify trace directory for trace output.\n"
2206 " By default, trace output will created at\n"
2207 " $HOME directory and parameter must be\n"
2208 " specified once only.\n"
2209 " --"OPT_TRACE_BUF_SIZE"=<int>\n"
2210 " Specify maximum size of allocated memory\n"
2211 " for trace output for each thread. Valid\n"
2212 " unit can be either 'B|K|M' for 'Bytes',\n"
2213 " 'KBytes' and 'MBytes' respectively.\n"
2214 " Default is 1MB and parameter must be\n"
2215 " specified once only.\n"
2216 " --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
2217 " Specify the mode of update of trace\n"
2218 " output file. Either update on a file can\n"
2219 " be wrapped or discarded when file size\n"
2220 " reaches its maximum limit.\n"
2221 " Default mode is 'overwrite' and parameter\n"
2222 " must be specified once only.\n"
2223 #endif /* !RTE_EXEC_ENV_WINDOWS */
2224 " -v Display version information on startup\n"
2225 " -h, --help This help\n"
2226 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
2227 " disable secondary process support\n"
2228 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
2229 " --"OPT_TELEMETRY" Enable telemetry support (on by default)\n"
2230 " --"OPT_NO_TELEMETRY" Disable telemetry support\n"
2231 " --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
2232 "\nEAL options for DEBUG use only:\n"
2233 " --"OPT_HUGE_UNLINK"[=existing|always|never]\n"
2234 " When to unlink files in hugetlbfs\n"
2235 " ('existing' by default, no value means 'always')\n"
2236 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
2237 " --"OPT_NO_PCI" Disable PCI\n"
2238 " --"OPT_NO_HPET" Disable HPET\n"
2239 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
2240 "\n", RTE_MAX_LCORE);