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
19 #include <sys/types.h>
23 #include <rte_string_fns.h>
26 #include <rte_lcore.h>
27 #include <rte_memory.h>
28 #include <rte_tailq.h>
29 #include <rte_version.h>
30 #include <rte_devargs.h>
31 #include <rte_memcpy.h>
33 #include "eal_internal_cfg.h"
34 #include "eal_options.h"
35 #include "eal_filesystem.h"
36 #include "eal_private.h"
38 #define BITS_PER_HEX 4
39 #define LCORE_OPT_LST 1
40 #define LCORE_OPT_MSK 2
41 #define LCORE_OPT_MAP 3
45 "b:" /* pci-blacklist */
47 "s:" /* service coremask */
51 "S:" /* service corelist */
52 "m:" /* memory size */
53 "n:" /* memory channels */
54 "r:" /* memory ranks */
56 "w:" /* pci-whitelist */
60 eal_long_options[] = {
61 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM },
62 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM },
63 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM },
64 {OPT_HELP, 0, NULL, OPT_HELP_NUM },
65 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM },
66 {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM },
67 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
68 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
69 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
70 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
71 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
72 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
73 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
74 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
75 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
76 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
77 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
78 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
79 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
80 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
81 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
82 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
83 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
84 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
85 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
86 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
87 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
88 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
92 TAILQ_HEAD(shared_driver_list, shared_driver);
94 /* Definition for shared object drivers. */
95 struct shared_driver {
96 TAILQ_ENTRY(shared_driver) next;
102 /* List of external loadable drivers */
103 static struct shared_driver_list solib_list =
104 TAILQ_HEAD_INITIALIZER(solib_list);
106 /* Default path of external loadable drivers */
107 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
110 * Stringified version of solib path used by dpdk-pmdinfo.py
111 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
112 * change to usertools/dpdk-pmdinfo.py
114 static const char dpdk_solib_path[] __attribute__((used)) =
115 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
117 TAILQ_HEAD(device_option_list, device_option);
119 struct device_option {
120 TAILQ_ENTRY(device_option) next;
122 enum rte_devtype type;
126 static struct device_option_list devopt_list =
127 TAILQ_HEAD_INITIALIZER(devopt_list);
129 static int master_lcore_parsed;
130 static int mem_parsed;
131 static int core_parsed;
134 eal_option_device_add(enum rte_devtype type, const char *optarg)
136 struct device_option *devopt;
140 optlen = strlen(optarg) + 1;
141 devopt = calloc(1, sizeof(*devopt) + optlen);
142 if (devopt == NULL) {
143 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
148 ret = strlcpy(devopt->arg, optarg, optlen);
150 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
154 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
159 eal_option_device_parse(void)
161 struct device_option *devopt;
165 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
167 ret = rte_devargs_add(devopt->type, devopt->arg);
169 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
172 TAILQ_REMOVE(&devopt_list, devopt, next);
179 eal_get_hugefile_prefix(void)
181 if (internal_config.hugefile_prefix != NULL)
182 return internal_config.hugefile_prefix;
183 return HUGEFILE_PREFIX_DEFAULT;
187 eal_reset_internal_config(struct internal_config *internal_cfg)
191 internal_cfg->memory = 0;
192 internal_cfg->force_nrank = 0;
193 internal_cfg->force_nchannel = 0;
194 internal_cfg->hugefile_prefix = NULL;
195 internal_cfg->hugepage_dir = NULL;
196 internal_cfg->force_sockets = 0;
197 /* zero out the NUMA config */
198 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
199 internal_cfg->socket_mem[i] = 0;
200 internal_cfg->force_socket_limits = 0;
201 /* zero out the NUMA limits config */
202 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
203 internal_cfg->socket_limit[i] = 0;
204 /* zero out hugedir descriptors */
205 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
206 memset(&internal_cfg->hugepage_info[i], 0,
207 sizeof(internal_cfg->hugepage_info[0]));
208 internal_cfg->hugepage_info[i].lock_descriptor = -1;
210 internal_cfg->base_virtaddr = 0;
213 internal_cfg->syslog_facility = LOG_DAEMON;
216 /* if set to NONE, interrupt mode is determined automatically */
217 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
219 #ifdef RTE_LIBEAL_USE_HPET
220 internal_cfg->no_hpet = 0;
222 internal_cfg->no_hpet = 1;
224 internal_cfg->vmware_tsc_map = 0;
225 internal_cfg->create_uio_dev = 0;
226 internal_cfg->iova_mode = RTE_IOVA_DC;
227 internal_cfg->user_mbuf_pool_ops_name = NULL;
228 CPU_ZERO(&internal_cfg->ctrl_cpuset);
229 internal_cfg->init_complete = 0;
233 eal_plugin_add(const char *path)
235 struct shared_driver *solib;
237 solib = malloc(sizeof(*solib));
239 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
242 memset(solib, 0, sizeof(*solib));
243 strlcpy(solib->name, path, PATH_MAX-1);
244 solib->name[PATH_MAX-1] = 0;
245 TAILQ_INSERT_TAIL(&solib_list, solib, next);
251 eal_plugindir_init(const char *path)
254 struct dirent *dent = NULL;
255 char sopath[PATH_MAX];
257 if (path == NULL || *path == '\0')
262 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
263 path, strerror(errno));
267 while ((dent = readdir(d)) != NULL) {
270 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
272 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
275 if (eal_plugin_add(sopath) == -1)
280 /* XXX this ignores failures from readdir() itself */
281 return (dent == NULL) ? 0 : -1;
285 eal_plugins_init(void)
287 #ifndef RTE_EXEC_ENV_WINDOWS
288 struct shared_driver *solib = NULL;
291 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
293 eal_plugin_add(default_solib_dir);
295 TAILQ_FOREACH(solib, &solib_list, next) {
297 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
298 if (eal_plugindir_init(solib->name) == -1) {
300 "Cannot init plugin directory %s\n",
305 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
307 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
308 if (solib->lib_handle == NULL) {
309 RTE_LOG(ERR, EAL, "%s\n", dlerror());
320 * Parse the coremask given as argument (hexadecimal string) and fill
321 * the global configuration (core role and core count) with the parsed
324 static int xdigit2val(unsigned char c)
338 eal_parse_service_coremask(const char *coremask)
340 struct rte_config *cfg = rte_eal_get_configuration();
342 unsigned int count = 0;
345 uint32_t taken_lcore_count = 0;
347 if (coremask == NULL)
349 /* Remove all blank characters ahead and after .
350 * Remove 0x/0X if exists.
352 while (isblank(*coremask))
354 if (coremask[0] == '0' && ((coremask[1] == 'x')
355 || (coremask[1] == 'X')))
357 i = strlen(coremask);
358 while ((i > 0) && isblank(coremask[i - 1]))
364 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
366 if (isxdigit(c) == 0) {
367 /* invalid characters */
371 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
373 if ((1 << j) & val) {
374 /* handle master lcore already parsed */
375 uint32_t lcore = idx;
376 if (master_lcore_parsed &&
377 cfg->master_lcore == lcore) {
379 "lcore %u is master lcore, cannot use as service core\n",
384 if (eal_cpu_detected(idx) == 0) {
386 "lcore %u unavailable\n", idx);
390 if (cfg->lcore_role[idx] == ROLE_RTE)
393 lcore_config[idx].core_role = ROLE_SERVICE;
400 if (coremask[i] != '0')
403 for (; idx < RTE_MAX_LCORE; idx++)
404 lcore_config[idx].core_index = -1;
409 if (core_parsed && taken_lcore_count != count) {
410 RTE_LOG(WARNING, EAL,
411 "Not all service cores are in the coremask. "
412 "Please ensure -c or -l includes service cores\n");
415 cfg->service_lcore_count = count;
420 eal_service_cores_parsed(void)
423 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
424 if (lcore_config[idx].core_role == ROLE_SERVICE)
431 update_lcore_config(int *cores)
433 struct rte_config *cfg = rte_eal_get_configuration();
434 unsigned int count = 0;
438 for (i = 0; i < RTE_MAX_LCORE; i++) {
439 if (cores[i] != -1) {
440 if (eal_cpu_detected(i) == 0) {
441 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
445 cfg->lcore_role[i] = ROLE_RTE;
448 cfg->lcore_role[i] = ROLE_OFF;
450 lcore_config[i].core_index = cores[i];
453 cfg->lcore_count = count;
458 eal_parse_coremask(const char *coremask, int *cores)
465 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
469 /* Remove all blank characters ahead and after .
470 * Remove 0x/0X if exists.
472 while (isblank(*coremask))
474 if (coremask[0] == '0' && ((coremask[1] == 'x')
475 || (coremask[1] == 'X')))
477 i = strlen(coremask);
478 while ((i > 0) && isblank(coremask[i - 1]))
483 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
485 if (isxdigit(c) == 0) {
486 /* invalid characters */
490 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
492 if ((1 << j) & val) {
499 if (coremask[i] != '0')
507 eal_parse_service_corelist(const char *corelist)
509 struct rte_config *cfg = rte_eal_get_configuration();
514 uint32_t taken_lcore_count = 0;
516 if (corelist == NULL)
519 /* Remove all blank characters ahead and after */
520 while (isblank(*corelist))
522 i = strlen(corelist);
523 while ((i > 0) && isblank(corelist[i - 1]))
526 /* Get list of cores */
529 while (isblank(*corelist))
531 if (*corelist == '\0')
534 idx = strtoul(corelist, &end, 10);
535 if (errno || end == NULL)
537 while (isblank(*end))
541 } else if ((*end == ',') || (*end == '\0')) {
543 if (min == RTE_MAX_LCORE)
545 for (idx = min; idx <= max; idx++) {
546 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
547 /* handle master lcore already parsed */
548 uint32_t lcore = idx;
549 if (cfg->master_lcore == lcore &&
550 master_lcore_parsed) {
552 "Error: lcore %u is master lcore, cannot use as service core\n",
556 if (cfg->lcore_role[idx] == ROLE_RTE)
559 lcore_config[idx].core_role =
568 } while (*end != '\0');
573 if (core_parsed && taken_lcore_count != count) {
574 RTE_LOG(WARNING, EAL,
575 "Not all service cores were in the coremask. "
576 "Please ensure -c or -l includes service cores\n");
583 eal_parse_corelist(const char *corelist, int *cores)
590 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
593 /* Remove all blank characters ahead */
594 while (isblank(*corelist))
597 /* Get list of cores */
600 while (isblank(*corelist))
602 if (*corelist == '\0')
605 idx = strtol(corelist, &end, 10);
606 if (errno || end == NULL)
608 if (idx < 0 || idx >= RTE_MAX_LCORE)
610 while (isblank(*end))
614 } else if ((*end == ',') || (*end == '\0')) {
616 if (min == RTE_MAX_LCORE)
618 for (idx = min; idx <= max; idx++) {
619 if (cores[idx] == -1) {
628 } while (*end != '\0');
635 /* Changes the lcore id of the master thread */
637 eal_parse_master_lcore(const char *arg)
640 struct rte_config *cfg = rte_eal_get_configuration();
643 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
644 if (errno || parsing_end[0] != 0)
646 if (cfg->master_lcore >= RTE_MAX_LCORE)
648 master_lcore_parsed = 1;
650 /* ensure master core is not used as service core */
651 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
653 "Error: Master lcore is used as a service core\n");
661 * Parse elem, the elem could be single number/range or '(' ')' group
662 * 1) A single number elem, it's just a simple digit. e.g. 9
663 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
664 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
665 * Within group elem, '-' used for a range separator;
666 * ',' used for a single number.
669 eal_parse_set(const char *input, rte_cpuset_t *set)
672 const char *str = input;
678 while (isblank(*str))
681 /* only digit or left bracket is qualify for start point */
682 if ((!isdigit(*str) && *str != '(') || *str == '\0')
685 /* process single number or single range of number */
688 idx = strtoul(str, &end, 10);
689 if (errno || end == NULL || idx >= CPU_SETSIZE)
692 while (isblank(*end))
698 /* process single <number>-<number> */
700 while (isblank(*end))
706 idx = strtoul(end, &end, 10);
707 if (errno || end == NULL || idx >= CPU_SETSIZE)
710 while (isblank(*end))
712 if (*end != ',' && *end != '\0')
716 if (*end != ',' && *end != '\0' &&
720 for (idx = RTE_MIN(min, max);
721 idx <= RTE_MAX(min, max); idx++)
728 /* process set within bracket */
730 while (isblank(*str))
738 /* go ahead to the first digit */
739 while (isblank(*str))
744 /* get the digit value */
746 idx = strtoul(str, &end, 10);
747 if (errno || end == NULL || idx >= CPU_SETSIZE)
750 /* go ahead to separator '-',',' and ')' */
751 while (isblank(*end))
754 if (min == RTE_MAX_LCORE)
756 else /* avoid continuous '-' */
758 } else if ((*end == ',') || (*end == ')')) {
760 if (min == RTE_MAX_LCORE)
762 for (idx = RTE_MIN(min, max);
763 idx <= RTE_MAX(min, max); idx++)
771 } while (*end != '\0' && *end != ')');
774 * to avoid failure that tail blank makes end character check fail
775 * in eal_parse_lcores( )
777 while (isblank(*str))
784 check_cpuset(rte_cpuset_t *set)
788 for (idx = 0; idx < CPU_SETSIZE; idx++) {
789 if (!CPU_ISSET(idx, set))
792 if (eal_cpu_detected(idx) == 0) {
793 RTE_LOG(ERR, EAL, "core %u "
794 "unavailable\n", idx);
802 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
803 * lcores, cpus could be a single digit/range or a group.
804 * '(' and ')' are necessary if it's a group.
805 * If not supply '@cpus', the value of cpus uses the same as lcores.
806 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
807 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
808 * lcore 1 runs on cpuset 0x2 (cpu 1)
809 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
810 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
811 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
812 * lcore 7 runs on cpuset 0x80 (cpu 7)
813 * lcore 8 runs on cpuset 0x100 (cpu 8)
816 eal_parse_lcores(const char *lcores)
818 struct rte_config *cfg = rte_eal_get_configuration();
819 rte_cpuset_t lcore_set;
820 unsigned int set_count;
823 const char *lcore_start = NULL;
824 const char *end = NULL;
833 /* Remove all blank characters ahead and after */
834 while (isblank(*lcores))
839 /* Reset lcore config */
840 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
841 cfg->lcore_role[idx] = ROLE_OFF;
842 lcore_config[idx].core_index = -1;
843 CPU_ZERO(&lcore_config[idx].cpuset);
846 /* Get list of cores */
848 while (isblank(*lcores))
855 /* record lcore_set start point */
856 lcore_start = lcores;
858 /* go across a complete bracket */
859 if (*lcore_start == '(') {
860 lcores += strcspn(lcores, ")");
861 if (*lcores++ == '\0')
865 /* scan the separator '@', ','(next) or '\0'(finish) */
866 lcores += strcspn(lcores, "@,");
868 if (*lcores == '@') {
869 /* explicit assign cpuset and update the end cursor */
870 offset = eal_parse_set(lcores + 1, &cpuset);
873 end = lcores + 1 + offset;
874 } else { /* ',' or '\0' */
875 /* haven't given cpuset, current loop done */
878 /* go back to check <number>-<number> */
879 offset = strcspn(lcore_start, "(-");
880 if (offset < (end - lcore_start) &&
881 *(lcore_start + offset) != '(')
885 if (*end != ',' && *end != '\0')
888 /* parse lcore_set from start point */
889 if (eal_parse_set(lcore_start, &lcore_set) < 0)
892 /* without '@', by default using lcore_set as cpuset */
894 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
896 set_count = CPU_COUNT(&lcore_set);
897 /* start to update lcore_set */
898 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
899 if (!CPU_ISSET(idx, &lcore_set))
903 if (cfg->lcore_role[idx] != ROLE_RTE) {
904 lcore_config[idx].core_index = count;
905 cfg->lcore_role[idx] = ROLE_RTE;
911 CPU_SET(idx, &cpuset);
914 if (check_cpuset(&cpuset) < 0)
916 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
917 sizeof(rte_cpuset_t));
920 /* some cores from the lcore_set can't be handled by EAL */
925 } while (*end != '\0');
930 cfg->lcore_count = count;
938 #ifndef RTE_EXEC_ENV_WINDOWS
940 eal_parse_syslog(const char *facility, struct internal_config *conf)
943 static const struct {
947 { "auth", LOG_AUTH },
948 { "cron", LOG_CRON },
949 { "daemon", LOG_DAEMON },
951 { "kern", LOG_KERN },
953 { "mail", LOG_MAIL },
954 { "news", LOG_NEWS },
955 { "syslog", LOG_SYSLOG },
956 { "user", LOG_USER },
957 { "uucp", LOG_UUCP },
958 { "local0", LOG_LOCAL0 },
959 { "local1", LOG_LOCAL1 },
960 { "local2", LOG_LOCAL2 },
961 { "local3", LOG_LOCAL3 },
962 { "local4", LOG_LOCAL4 },
963 { "local5", LOG_LOCAL5 },
964 { "local6", LOG_LOCAL6 },
965 { "local7", LOG_LOCAL7 },
969 for (i = 0; map[i].name; i++) {
970 if (!strcmp(facility, map[i].name)) {
971 conf->syslog_facility = map[i].value;
980 eal_parse_log_priority(const char *level)
982 static const char * const levels[] = {
983 [RTE_LOG_EMERG] = "emergency",
984 [RTE_LOG_ALERT] = "alert",
985 [RTE_LOG_CRIT] = "critical",
986 [RTE_LOG_ERR] = "error",
987 [RTE_LOG_WARNING] = "warning",
988 [RTE_LOG_NOTICE] = "notice",
989 [RTE_LOG_INFO] = "info",
990 [RTE_LOG_DEBUG] = "debug",
992 size_t len = strlen(level);
1000 /* look for named values, skip 0 which is not a valid level */
1001 for (i = 1; i < RTE_DIM(levels); i++) {
1002 if (strncmp(levels[i], level, len) == 0)
1006 /* not a string, maybe it is numeric */
1008 tmp = strtoul(level, &end, 0);
1010 /* check for errors */
1011 if (errno != 0 || end == NULL || *end != '\0' ||
1019 eal_parse_log_level(const char *arg)
1021 const char *pattern = NULL;
1022 const char *regex = NULL;
1030 if ((level = strchr(str, ','))) {
1033 } else if ((level = strchr(str, ':'))) {
1040 priority = eal_parse_log_priority(level);
1042 fprintf(stderr, "invalid log priority: %s\n", level);
1047 if (rte_log_set_level_regexp(regex, priority) < 0) {
1048 fprintf(stderr, "cannot set log level %s,%d\n",
1052 if (rte_log_save_regexp(regex, priority) < 0)
1054 } else if (pattern) {
1055 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1056 fprintf(stderr, "cannot set log level %s:%d\n",
1060 if (rte_log_save_pattern(pattern, priority) < 0)
1063 rte_log_set_global_level(priority);
1074 static enum rte_proc_type_t
1075 eal_parse_proc_type(const char *arg)
1077 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1078 return RTE_PROC_PRIMARY;
1079 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1080 return RTE_PROC_SECONDARY;
1081 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1082 return RTE_PROC_AUTO;
1084 return RTE_PROC_INVALID;
1088 eal_parse_iova_mode(const char *name)
1095 if (!strcmp("pa", name))
1097 else if (!strcmp("va", name))
1102 internal_config.iova_mode = mode;
1107 eal_parse_base_virtaddr(const char *arg)
1113 addr = strtoull(arg, &end, 16);
1115 /* check for errors */
1116 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1119 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1121 if (addr >= UINTPTR_MAX)
1125 /* align the addr on 16M boundary, 16MB is the minimum huge page
1126 * size on IBM Power architecture. If the addr is aligned to 16MB,
1127 * it can align to 2MB for x86. So this alignment can also be used
1128 * on x86 and other architectures.
1130 internal_config.base_virtaddr =
1131 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1136 /* caller is responsible for freeing the returned string */
1138 available_cores(void)
1146 /* find the first available cpu */
1147 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1148 if (eal_cpu_detected(idx) == 0)
1152 if (idx >= RTE_MAX_LCORE)
1155 /* first sequence */
1156 if (asprintf(&str, "%d", idx) < 0)
1161 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1162 if (eal_cpu_detected(idx) == 0)
1165 if (idx == previous + 1) {
1171 /* finish current sequence */
1173 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1182 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1192 /* finish last sequence */
1194 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1206 eal_parse_common_option(int opt, const char *optarg,
1207 struct internal_config *conf)
1217 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1227 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1235 int lcore_indexes[RTE_MAX_LCORE];
1237 if (eal_service_cores_parsed())
1238 RTE_LOG(WARNING, EAL,
1239 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1240 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1241 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1244 if (update_lcore_config(lcore_indexes) < 0) {
1245 char *available = available_cores();
1248 "invalid coremask, please check specified cores are part of %s\n",
1255 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1256 (core_parsed == LCORE_OPT_LST) ? "-l" :
1257 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1262 core_parsed = LCORE_OPT_MSK;
1267 int lcore_indexes[RTE_MAX_LCORE];
1269 if (eal_service_cores_parsed())
1270 RTE_LOG(WARNING, EAL,
1271 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1273 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1274 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1277 if (update_lcore_config(lcore_indexes) < 0) {
1278 char *available = available_cores();
1281 "invalid core list, please check specified cores are part of %s\n",
1288 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1289 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1290 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1295 core_parsed = LCORE_OPT_LST;
1298 /* service coremask */
1300 if (eal_parse_service_coremask(optarg) < 0) {
1301 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1305 /* service corelist */
1307 if (eal_parse_service_corelist(optarg) < 0) {
1308 RTE_LOG(ERR, EAL, "invalid service core list\n");
1312 /* size of memory */
1314 conf->memory = atoi(optarg);
1315 conf->memory *= 1024ULL;
1316 conf->memory *= 1024ULL;
1319 /* force number of channels */
1321 conf->force_nchannel = atoi(optarg);
1322 if (conf->force_nchannel == 0) {
1323 RTE_LOG(ERR, EAL, "invalid channel number\n");
1327 /* force number of ranks */
1329 conf->force_nrank = atoi(optarg);
1330 if (conf->force_nrank == 0 ||
1331 conf->force_nrank > 16) {
1332 RTE_LOG(ERR, EAL, "invalid rank number\n");
1336 /* force loading of external driver */
1338 if (eal_plugin_add(optarg) == -1)
1342 /* since message is explicitly requested by user, we
1343 * write message at highest log level so it can always
1345 * even if info or warning messages are disabled */
1346 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1350 case OPT_HUGE_UNLINK_NUM:
1351 conf->hugepage_unlink = 1;
1354 case OPT_NO_HUGE_NUM:
1355 conf->no_hugetlbfs = 1;
1356 /* no-huge is legacy mem */
1357 conf->legacy_mem = 1;
1360 case OPT_NO_PCI_NUM:
1364 case OPT_NO_HPET_NUM:
1368 case OPT_VMWARE_TSC_MAP_NUM:
1369 conf->vmware_tsc_map = 1;
1372 case OPT_NO_SHCONF_NUM:
1373 conf->no_shconf = 1;
1376 case OPT_IN_MEMORY_NUM:
1377 conf->in_memory = 1;
1378 /* in-memory is a superset of noshconf and huge-unlink */
1379 conf->no_shconf = 1;
1380 conf->hugepage_unlink = 1;
1383 case OPT_PROC_TYPE_NUM:
1384 conf->process_type = eal_parse_proc_type(optarg);
1387 case OPT_MASTER_LCORE_NUM:
1388 if (eal_parse_master_lcore(optarg) < 0) {
1389 RTE_LOG(ERR, EAL, "invalid parameter for --"
1390 OPT_MASTER_LCORE "\n");
1396 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1402 #ifndef RTE_EXEC_ENV_WINDOWS
1403 case OPT_SYSLOG_NUM:
1404 if (eal_parse_syslog(optarg, conf) < 0) {
1405 RTE_LOG(ERR, EAL, "invalid parameters for --"
1412 case OPT_LOG_LEVEL_NUM: {
1413 if (eal_parse_log_level(optarg) < 0) {
1415 "invalid parameters for --"
1416 OPT_LOG_LEVEL "\n");
1421 case OPT_LCORES_NUM:
1422 if (eal_parse_lcores(optarg) < 0) {
1423 RTE_LOG(ERR, EAL, "invalid parameter for --"
1429 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1430 (core_parsed == LCORE_OPT_LST) ? "-l" :
1431 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1436 core_parsed = LCORE_OPT_MAP;
1438 case OPT_LEGACY_MEM_NUM:
1439 conf->legacy_mem = 1;
1441 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1442 conf->single_file_segments = 1;
1444 case OPT_IOVA_MODE_NUM:
1445 if (eal_parse_iova_mode(optarg) < 0) {
1446 RTE_LOG(ERR, EAL, "invalid parameters for --"
1447 OPT_IOVA_MODE "\n");
1451 case OPT_BASE_VIRTADDR_NUM:
1452 if (eal_parse_base_virtaddr(optarg) < 0) {
1453 RTE_LOG(ERR, EAL, "invalid parameter for --"
1454 OPT_BASE_VIRTADDR "\n");
1459 /* don't know what to do, leave this to caller */
1467 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1468 "cannot be used at the same time\n");
1473 eal_auto_detect_cores(struct rte_config *cfg)
1475 unsigned int lcore_id;
1476 unsigned int removed = 0;
1477 rte_cpuset_t affinity_set;
1479 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1481 CPU_ZERO(&affinity_set);
1483 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1484 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1485 !CPU_ISSET(lcore_id, &affinity_set)) {
1486 cfg->lcore_role[lcore_id] = ROLE_OFF;
1491 cfg->lcore_count -= removed;
1495 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1497 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1498 rte_cpuset_t default_set;
1499 unsigned int lcore_id;
1501 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1502 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1504 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1506 RTE_CPU_NOT(cpuset, cpuset);
1508 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1510 CPU_ZERO(&default_set);
1512 RTE_CPU_AND(cpuset, cpuset, &default_set);
1514 /* if no remaining cpu, use master lcore cpu affinity */
1515 if (!CPU_COUNT(cpuset)) {
1516 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1522 eal_cleanup_config(struct internal_config *internal_cfg)
1524 if (internal_cfg->hugefile_prefix != NULL)
1525 free(internal_cfg->hugefile_prefix);
1526 if (internal_cfg->hugepage_dir != NULL)
1527 free(internal_cfg->hugepage_dir);
1528 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1529 free(internal_cfg->user_mbuf_pool_ops_name);
1535 eal_adjust_config(struct internal_config *internal_cfg)
1538 struct rte_config *cfg = rte_eal_get_configuration();
1541 eal_auto_detect_cores(cfg);
1543 if (internal_config.process_type == RTE_PROC_AUTO)
1544 internal_config.process_type = eal_proc_type_detect();
1546 /* default master lcore is the first one */
1547 if (!master_lcore_parsed) {
1548 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1549 if (cfg->master_lcore >= RTE_MAX_LCORE)
1551 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1554 compute_ctrl_threads_cpuset(internal_cfg);
1556 /* if no memory amounts were requested, this will result in 0 and
1557 * will be overridden later, right after eal_hugepage_info_init() */
1558 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1559 internal_cfg->memory += internal_cfg->socket_mem[i];
1565 eal_check_common_options(struct internal_config *internal_cfg)
1567 struct rte_config *cfg = rte_eal_get_configuration();
1569 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1570 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1574 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1575 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1578 if (internal_cfg->hugefile_prefix != NULL &&
1579 strlen(internal_cfg->hugefile_prefix) < 1) {
1580 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1583 if (internal_cfg->hugepage_dir != NULL &&
1584 strlen(internal_cfg->hugepage_dir) < 1) {
1585 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1588 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1589 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1590 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1593 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1594 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1598 if (mem_parsed && internal_cfg->force_sockets == 1) {
1599 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1600 "be specified at the same time\n");
1603 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1604 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1605 "be specified together with --"OPT_NO_HUGE"\n");
1608 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1609 !internal_cfg->in_memory) {
1610 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1611 "be specified together with --"OPT_NO_HUGE"\n");
1614 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1615 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1616 " is only supported in non-legacy memory mode\n");
1618 if (internal_cfg->single_file_segments &&
1619 internal_cfg->hugepage_unlink &&
1620 !internal_cfg->in_memory) {
1621 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1622 "not compatible with --"OPT_HUGE_UNLINK"\n");
1625 if (internal_cfg->legacy_mem &&
1626 internal_cfg->in_memory) {
1627 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1628 "with --"OPT_IN_MEMORY"\n");
1631 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1632 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1633 "with --"OPT_MATCH_ALLOCATIONS"\n");
1636 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1637 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1638 "with --"OPT_MATCH_ALLOCATIONS"\n");
1641 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1642 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1643 "amount of reserved memory can be adjusted with "
1644 "-m or --"OPT_SOCKET_MEM"\n");
1651 eal_common_usage(void)
1653 printf("[options]\n\n"
1654 "EAL common options:\n"
1655 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1656 " -l CORELIST List of cores to run on\n"
1657 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1658 " where c1, c2, etc are core indexes between 0 and %d\n"
1659 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1660 " The argument format is\n"
1661 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1662 " lcores and cpus list are grouped by '(' and ')'\n"
1663 " Within the group, '-' is used for range separator,\n"
1664 " ',' is used for single number separator.\n"
1665 " '( )' can be omitted for single element group,\n"
1666 " '@' can be omitted if cpus and lcores have the same value\n"
1667 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1668 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1669 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1670 " -n CHANNELS Number of memory channels\n"
1671 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1672 " -r RANKS Force number of memory ranks (don't detect)\n"
1673 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1674 " Prevent EAL from using this PCI device. The argument\n"
1675 " format is <domain:bus:devid.func>.\n"
1676 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1677 " Only use the specified PCI devices. The argument format\n"
1678 " is <[domain:]bus:devid.func>. This option can be present\n"
1679 " several times (once per device).\n"
1680 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1681 " --"OPT_VDEV" Add a virtual device.\n"
1682 " The argument format is <driver><id>[,key=val,...]\n"
1683 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1684 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1685 " 'va' for IOVA_VA\n"
1686 " -d LIB.so|DIR Add a driver or driver directory\n"
1687 " (can be used multiple times)\n"
1688 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1689 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1690 #ifndef RTE_EXEC_ENV_WINDOWS
1691 " --"OPT_SYSLOG" Set syslog facility\n"
1693 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1694 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1695 " Set specific log level\n"
1696 " -v Display version information on startup\n"
1697 " -h, --help This help\n"
1698 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1699 " disable secondary process support\n"
1700 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
1701 "\nEAL options for DEBUG use only:\n"
1702 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1703 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1704 " --"OPT_NO_PCI" Disable PCI\n"
1705 " --"OPT_NO_HPET" Disable HPET\n"
1706 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1707 "\n", RTE_MAX_LCORE);