1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
15 #include <sys/types.h>
19 #include <rte_string_fns.h>
22 #include <rte_lcore.h>
23 #include <rte_tailq.h>
24 #include <rte_version.h>
25 #include <rte_devargs.h>
26 #include <rte_memcpy.h>
28 #include "eal_internal_cfg.h"
29 #include "eal_options.h"
30 #include "eal_filesystem.h"
31 #include "eal_private.h"
33 #define BITS_PER_HEX 4
34 #define LCORE_OPT_LST 1
35 #define LCORE_OPT_MSK 2
36 #define LCORE_OPT_MAP 3
40 "b:" /* pci-blacklist */
42 "s:" /* service coremask */
46 "S:" /* service corelist */
47 "m:" /* memory size */
48 "n:" /* memory channels */
49 "r:" /* memory ranks */
51 "w:" /* pci-whitelist */
55 eal_long_options[] = {
56 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM },
57 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM },
58 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM },
59 {OPT_HELP, 0, NULL, OPT_HELP_NUM },
60 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM },
61 {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM },
62 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
63 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
64 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
65 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
66 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
67 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
68 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
69 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
70 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
71 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
72 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
73 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
74 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
75 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
76 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
77 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
78 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
79 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
80 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
81 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
82 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
83 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
87 TAILQ_HEAD(shared_driver_list, shared_driver);
89 /* Definition for shared object drivers. */
90 struct shared_driver {
91 TAILQ_ENTRY(shared_driver) next;
97 /* List of external loadable drivers */
98 static struct shared_driver_list solib_list =
99 TAILQ_HEAD_INITIALIZER(solib_list);
101 /* Default path of external loadable drivers */
102 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
105 * Stringified version of solib path used by dpdk-pmdinfo.py
106 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
107 * change to usertools/dpdk-pmdinfo.py
109 static const char dpdk_solib_path[] __attribute__((used)) =
110 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
112 TAILQ_HEAD(device_option_list, device_option);
114 struct device_option {
115 TAILQ_ENTRY(device_option) next;
117 enum rte_devtype type;
121 static struct device_option_list devopt_list =
122 TAILQ_HEAD_INITIALIZER(devopt_list);
124 static int master_lcore_parsed;
125 static int mem_parsed;
126 static int core_parsed;
129 eal_option_device_add(enum rte_devtype type, const char *optarg)
131 struct device_option *devopt;
135 optlen = strlen(optarg) + 1;
136 devopt = calloc(1, sizeof(*devopt) + optlen);
137 if (devopt == NULL) {
138 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
143 ret = strlcpy(devopt->arg, optarg, optlen);
145 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
149 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
154 eal_option_device_parse(void)
156 struct device_option *devopt;
160 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
162 ret = rte_devargs_add(devopt->type, devopt->arg);
164 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
167 TAILQ_REMOVE(&devopt_list, devopt, next);
174 eal_get_hugefile_prefix(void)
176 if (internal_config.hugefile_prefix != NULL)
177 return internal_config.hugefile_prefix;
178 return HUGEFILE_PREFIX_DEFAULT;
182 eal_reset_internal_config(struct internal_config *internal_cfg)
186 internal_cfg->memory = 0;
187 internal_cfg->force_nrank = 0;
188 internal_cfg->force_nchannel = 0;
189 internal_cfg->hugefile_prefix = NULL;
190 internal_cfg->hugepage_dir = NULL;
191 internal_cfg->force_sockets = 0;
192 /* zero out the NUMA config */
193 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
194 internal_cfg->socket_mem[i] = 0;
195 internal_cfg->force_socket_limits = 0;
196 /* zero out the NUMA limits config */
197 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
198 internal_cfg->socket_limit[i] = 0;
199 /* zero out hugedir descriptors */
200 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
201 memset(&internal_cfg->hugepage_info[i], 0,
202 sizeof(internal_cfg->hugepage_info[0]));
203 internal_cfg->hugepage_info[i].lock_descriptor = -1;
205 internal_cfg->base_virtaddr = 0;
207 internal_cfg->syslog_facility = LOG_DAEMON;
209 /* if set to NONE, interrupt mode is determined automatically */
210 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
212 #ifdef RTE_LIBEAL_USE_HPET
213 internal_cfg->no_hpet = 0;
215 internal_cfg->no_hpet = 1;
217 internal_cfg->vmware_tsc_map = 0;
218 internal_cfg->create_uio_dev = 0;
219 internal_cfg->iova_mode = RTE_IOVA_DC;
220 internal_cfg->user_mbuf_pool_ops_name = NULL;
221 CPU_ZERO(&internal_cfg->ctrl_cpuset);
222 internal_cfg->init_complete = 0;
226 eal_plugin_add(const char *path)
228 struct shared_driver *solib;
230 solib = malloc(sizeof(*solib));
232 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
235 memset(solib, 0, sizeof(*solib));
236 strlcpy(solib->name, path, PATH_MAX-1);
237 solib->name[PATH_MAX-1] = 0;
238 TAILQ_INSERT_TAIL(&solib_list, solib, next);
244 eal_plugindir_init(const char *path)
247 struct dirent *dent = NULL;
248 char sopath[PATH_MAX];
250 if (path == NULL || *path == '\0')
255 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
256 path, strerror(errno));
260 while ((dent = readdir(d)) != NULL) {
263 snprintf(sopath, PATH_MAX-1, "%s/%s", path, dent->d_name);
264 sopath[PATH_MAX-1] = 0;
266 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
269 if (eal_plugin_add(sopath) == -1)
274 /* XXX this ignores failures from readdir() itself */
275 return (dent == NULL) ? 0 : -1;
279 eal_plugins_init(void)
281 struct shared_driver *solib = NULL;
284 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
286 eal_plugin_add(default_solib_dir);
288 TAILQ_FOREACH(solib, &solib_list, next) {
290 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
291 if (eal_plugindir_init(solib->name) == -1) {
293 "Cannot init plugin directory %s\n",
298 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
300 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
301 if (solib->lib_handle == NULL) {
302 RTE_LOG(ERR, EAL, "%s\n", dlerror());
312 * Parse the coremask given as argument (hexadecimal string) and fill
313 * the global configuration (core role and core count) with the parsed
316 static int xdigit2val(unsigned char c)
330 eal_parse_service_coremask(const char *coremask)
332 struct rte_config *cfg = rte_eal_get_configuration();
334 unsigned int count = 0;
337 uint32_t taken_lcore_count = 0;
339 if (coremask == NULL)
341 /* Remove all blank characters ahead and after .
342 * Remove 0x/0X if exists.
344 while (isblank(*coremask))
346 if (coremask[0] == '0' && ((coremask[1] == 'x')
347 || (coremask[1] == 'X')))
349 i = strlen(coremask);
350 while ((i > 0) && isblank(coremask[i - 1]))
356 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
358 if (isxdigit(c) == 0) {
359 /* invalid characters */
363 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
365 if ((1 << j) & val) {
366 /* handle master lcore already parsed */
367 uint32_t lcore = idx;
368 if (master_lcore_parsed &&
369 cfg->master_lcore == lcore) {
371 "lcore %u is master lcore, cannot use as service core\n",
376 if (!lcore_config[idx].detected) {
378 "lcore %u unavailable\n", idx);
382 if (cfg->lcore_role[idx] == ROLE_RTE)
385 lcore_config[idx].core_role = ROLE_SERVICE;
392 if (coremask[i] != '0')
395 for (; idx < RTE_MAX_LCORE; idx++)
396 lcore_config[idx].core_index = -1;
401 if (core_parsed && taken_lcore_count != count) {
402 RTE_LOG(WARNING, EAL,
403 "Not all service cores are in the coremask. "
404 "Please ensure -c or -l includes service cores\n");
407 cfg->service_lcore_count = count;
412 eal_service_cores_parsed(void)
415 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
416 if (lcore_config[idx].core_role == ROLE_SERVICE)
423 update_lcore_config(int *cores)
425 struct rte_config *cfg = rte_eal_get_configuration();
426 unsigned int count = 0;
430 for (i = 0; i < RTE_MAX_LCORE; i++) {
431 if (cores[i] != -1) {
432 if (!lcore_config[i].detected) {
433 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
437 cfg->lcore_role[i] = ROLE_RTE;
440 cfg->lcore_role[i] = ROLE_OFF;
442 lcore_config[i].core_index = cores[i];
445 cfg->lcore_count = count;
450 eal_parse_coremask(const char *coremask, int *cores)
457 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
461 /* Remove all blank characters ahead and after .
462 * Remove 0x/0X if exists.
464 while (isblank(*coremask))
466 if (coremask[0] == '0' && ((coremask[1] == 'x')
467 || (coremask[1] == 'X')))
469 i = strlen(coremask);
470 while ((i > 0) && isblank(coremask[i - 1]))
475 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
477 if (isxdigit(c) == 0) {
478 /* invalid characters */
482 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
484 if ((1 << j) & val) {
491 if (coremask[i] != '0')
499 eal_parse_service_corelist(const char *corelist)
501 struct rte_config *cfg = rte_eal_get_configuration();
506 uint32_t taken_lcore_count = 0;
508 if (corelist == NULL)
511 /* Remove all blank characters ahead and after */
512 while (isblank(*corelist))
514 i = strlen(corelist);
515 while ((i > 0) && isblank(corelist[i - 1]))
518 /* Get list of cores */
521 while (isblank(*corelist))
523 if (*corelist == '\0')
526 idx = strtoul(corelist, &end, 10);
527 if (errno || end == NULL)
529 while (isblank(*end))
533 } else if ((*end == ',') || (*end == '\0')) {
535 if (min == RTE_MAX_LCORE)
537 for (idx = min; idx <= max; idx++) {
538 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
539 /* handle master lcore already parsed */
540 uint32_t lcore = idx;
541 if (cfg->master_lcore == lcore &&
542 master_lcore_parsed) {
544 "Error: lcore %u is master lcore, cannot use as service core\n",
548 if (cfg->lcore_role[idx] == ROLE_RTE)
551 lcore_config[idx].core_role =
560 } while (*end != '\0');
565 if (core_parsed && taken_lcore_count != count) {
566 RTE_LOG(WARNING, EAL,
567 "Not all service cores were in the coremask. "
568 "Please ensure -c or -l includes service cores\n");
575 eal_parse_corelist(const char *corelist, int *cores)
582 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
585 /* Remove all blank characters ahead */
586 while (isblank(*corelist))
589 /* Get list of cores */
592 while (isblank(*corelist))
594 if (*corelist == '\0')
597 idx = strtol(corelist, &end, 10);
598 if (errno || end == NULL)
600 if (idx < 0 || idx >= RTE_MAX_LCORE)
602 while (isblank(*end))
606 } else if ((*end == ',') || (*end == '\0')) {
608 if (min == RTE_MAX_LCORE)
610 for (idx = min; idx <= max; idx++) {
611 if (cores[idx] == -1) {
620 } while (*end != '\0');
627 /* Changes the lcore id of the master thread */
629 eal_parse_master_lcore(const char *arg)
632 struct rte_config *cfg = rte_eal_get_configuration();
635 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
636 if (errno || parsing_end[0] != 0)
638 if (cfg->master_lcore >= RTE_MAX_LCORE)
640 master_lcore_parsed = 1;
642 /* ensure master core is not used as service core */
643 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
645 "Error: Master lcore is used as a service core\n");
653 * Parse elem, the elem could be single number/range or '(' ')' group
654 * 1) A single number elem, it's just a simple digit. e.g. 9
655 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
656 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
657 * Within group elem, '-' used for a range separator;
658 * ',' used for a single number.
661 eal_parse_set(const char *input, uint16_t set[], unsigned num)
664 const char *str = input;
668 memset(set, 0, num * sizeof(uint16_t));
670 while (isblank(*str))
673 /* only digit or left bracket is qualify for start point */
674 if ((!isdigit(*str) && *str != '(') || *str == '\0')
677 /* process single number or single range of number */
680 idx = strtoul(str, &end, 10);
681 if (errno || end == NULL || idx >= num)
684 while (isblank(*end))
690 /* process single <number>-<number> */
692 while (isblank(*end))
698 idx = strtoul(end, &end, 10);
699 if (errno || end == NULL || idx >= num)
702 while (isblank(*end))
704 if (*end != ',' && *end != '\0')
708 if (*end != ',' && *end != '\0' &&
712 for (idx = RTE_MIN(min, max);
713 idx <= RTE_MAX(min, max); idx++)
720 /* process set within bracket */
722 while (isblank(*str))
730 /* go ahead to the first digit */
731 while (isblank(*str))
736 /* get the digit value */
738 idx = strtoul(str, &end, 10);
739 if (errno || end == NULL || idx >= num)
742 /* go ahead to separator '-',',' and ')' */
743 while (isblank(*end))
746 if (min == RTE_MAX_LCORE)
748 else /* avoid continuous '-' */
750 } else if ((*end == ',') || (*end == ')')) {
752 if (min == RTE_MAX_LCORE)
754 for (idx = RTE_MIN(min, max);
755 idx <= RTE_MAX(min, max); idx++)
763 } while (*end != '\0' && *end != ')');
766 * to avoid failure that tail blank makes end character check fail
767 * in eal_parse_lcores( )
769 while (isblank(*str))
775 /* convert from set array to cpuset bitmap */
777 convert_to_cpuset(rte_cpuset_t *cpusetp,
778 uint16_t *set, unsigned num)
784 for (idx = 0; idx < num; idx++) {
788 if (!lcore_config[idx].detected) {
789 RTE_LOG(ERR, EAL, "core %u "
790 "unavailable\n", idx);
794 CPU_SET(idx, cpusetp);
801 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
802 * lcores, cpus could be a single digit/range or a group.
803 * '(' and ')' are necessary if it's a group.
804 * If not supply '@cpus', the value of cpus uses the same as lcores.
805 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
806 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
807 * lcore 1 runs on cpuset 0x2 (cpu 1)
808 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
809 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
810 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
811 * lcore 7 runs on cpuset 0x80 (cpu 7)
812 * lcore 8 runs on cpuset 0x100 (cpu 8)
815 eal_parse_lcores(const char *lcores)
817 struct rte_config *cfg = rte_eal_get_configuration();
818 static uint16_t set[RTE_MAX_LCORE];
821 const char *lcore_start = NULL;
822 const char *end = NULL;
831 /* Remove all blank characters ahead and after */
832 while (isblank(*lcores))
837 /* Reset lcore config */
838 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
839 cfg->lcore_role[idx] = ROLE_OFF;
840 lcore_config[idx].core_index = -1;
841 CPU_ZERO(&lcore_config[idx].cpuset);
844 /* Get list of cores */
846 while (isblank(*lcores))
853 /* record lcore_set start point */
854 lcore_start = lcores;
856 /* go across a complete bracket */
857 if (*lcore_start == '(') {
858 lcores += strcspn(lcores, ")");
859 if (*lcores++ == '\0')
863 /* scan the separator '@', ','(next) or '\0'(finish) */
864 lcores += strcspn(lcores, "@,");
866 if (*lcores == '@') {
867 /* explicit assign cpu_set */
868 offset = eal_parse_set(lcores + 1, set, RTE_DIM(set));
872 /* prepare cpu_set and update the end cursor */
873 if (0 > convert_to_cpuset(&cpuset,
876 end = lcores + 1 + offset;
877 } else { /* ',' or '\0' */
878 /* haven't given cpu_set, current loop done */
881 /* go back to check <number>-<number> */
882 offset = strcspn(lcore_start, "(-");
883 if (offset < (end - lcore_start) &&
884 *(lcore_start + offset) != '(')
888 if (*end != ',' && *end != '\0')
891 /* parse lcore_set from start point */
892 if (0 > eal_parse_set(lcore_start, set, RTE_DIM(set)))
895 /* without '@', by default using lcore_set as cpu_set */
896 if (*lcores != '@' &&
897 0 > convert_to_cpuset(&cpuset, set, RTE_DIM(set)))
900 /* start to update lcore_set */
901 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
905 if (cfg->lcore_role[idx] != ROLE_RTE) {
906 lcore_config[idx].core_index = count;
907 cfg->lcore_role[idx] = ROLE_RTE;
913 CPU_SET(idx, &cpuset);
915 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
916 sizeof(rte_cpuset_t));
920 } while (*end != '\0');
925 cfg->lcore_count = count;
934 eal_parse_syslog(const char *facility, struct internal_config *conf)
937 static const struct {
941 { "auth", LOG_AUTH },
942 { "cron", LOG_CRON },
943 { "daemon", LOG_DAEMON },
945 { "kern", LOG_KERN },
947 { "mail", LOG_MAIL },
948 { "news", LOG_NEWS },
949 { "syslog", LOG_SYSLOG },
950 { "user", LOG_USER },
951 { "uucp", LOG_UUCP },
952 { "local0", LOG_LOCAL0 },
953 { "local1", LOG_LOCAL1 },
954 { "local2", LOG_LOCAL2 },
955 { "local3", LOG_LOCAL3 },
956 { "local4", LOG_LOCAL4 },
957 { "local5", LOG_LOCAL5 },
958 { "local6", LOG_LOCAL6 },
959 { "local7", LOG_LOCAL7 },
963 for (i = 0; map[i].name; i++) {
964 if (!strcmp(facility, map[i].name)) {
965 conf->syslog_facility = map[i].value;
973 eal_parse_log_priority(const char *level)
975 static const char * const levels[] = {
976 [RTE_LOG_EMERG] = "emergency",
977 [RTE_LOG_ALERT] = "alert",
978 [RTE_LOG_CRIT] = "critical",
979 [RTE_LOG_ERR] = "error",
980 [RTE_LOG_WARNING] = "warning",
981 [RTE_LOG_NOTICE] = "notice",
982 [RTE_LOG_INFO] = "info",
983 [RTE_LOG_DEBUG] = "debug",
985 size_t len = strlen(level);
993 /* look for named values, skip 0 which is not a valid level */
994 for (i = 1; i < RTE_DIM(levels); i++) {
995 if (strncmp(levels[i], level, len) == 0)
999 /* not a string, maybe it is numeric */
1001 tmp = strtoul(level, &end, 0);
1003 /* check for errors */
1004 if (errno != 0 || end == NULL || *end != '\0' ||
1012 eal_parse_log_level(const char *arg)
1014 const char *pattern = NULL;
1015 const char *regex = NULL;
1023 if ((level = strchr(str, ','))) {
1026 } else if ((level = strchr(str, ':'))) {
1033 priority = eal_parse_log_priority(level);
1035 fprintf(stderr, "invalid log priority: %s\n", level);
1040 if (rte_log_set_level_regexp(regex, priority) < 0) {
1041 fprintf(stderr, "cannot set log level %s,%d\n",
1045 if (rte_log_save_regexp(regex, priority) < 0)
1047 } else if (pattern) {
1048 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1049 fprintf(stderr, "cannot set log level %s:%d\n",
1053 if (rte_log_save_pattern(pattern, priority) < 0)
1056 rte_log_set_global_level(priority);
1067 static enum rte_proc_type_t
1068 eal_parse_proc_type(const char *arg)
1070 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1071 return RTE_PROC_PRIMARY;
1072 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1073 return RTE_PROC_SECONDARY;
1074 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1075 return RTE_PROC_AUTO;
1077 return RTE_PROC_INVALID;
1081 eal_parse_iova_mode(const char *name)
1088 if (!strcmp("pa", name))
1090 else if (!strcmp("va", name))
1095 internal_config.iova_mode = mode;
1099 /* caller is responsible for freeing the returned string */
1101 available_cores(void)
1109 /* find the first available cpu */
1110 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1111 if (!lcore_config[idx].detected)
1115 if (idx >= RTE_MAX_LCORE)
1118 /* first sequence */
1119 if (asprintf(&str, "%d", idx) < 0)
1124 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1125 if (!lcore_config[idx].detected)
1128 if (idx == previous + 1) {
1134 /* finish current sequence */
1136 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1145 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1155 /* finish last sequence */
1157 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1169 eal_parse_common_option(int opt, const char *optarg,
1170 struct internal_config *conf)
1180 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1190 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1198 int lcore_indexes[RTE_MAX_LCORE];
1200 if (eal_service_cores_parsed())
1201 RTE_LOG(WARNING, EAL,
1202 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1203 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1204 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1207 if (update_lcore_config(lcore_indexes) < 0) {
1208 char *available = available_cores();
1211 "invalid coremask, please check specified cores are part of %s\n",
1218 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1219 (core_parsed == LCORE_OPT_LST) ? "-l" :
1220 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1225 core_parsed = LCORE_OPT_MSK;
1230 int lcore_indexes[RTE_MAX_LCORE];
1232 if (eal_service_cores_parsed())
1233 RTE_LOG(WARNING, EAL,
1234 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1236 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1237 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1240 if (update_lcore_config(lcore_indexes) < 0) {
1241 char *available = available_cores();
1244 "invalid core list, please check specified cores are part of %s\n",
1251 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1252 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1253 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1258 core_parsed = LCORE_OPT_LST;
1261 /* service coremask */
1263 if (eal_parse_service_coremask(optarg) < 0) {
1264 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1268 /* service corelist */
1270 if (eal_parse_service_corelist(optarg) < 0) {
1271 RTE_LOG(ERR, EAL, "invalid service core list\n");
1275 /* size of memory */
1277 conf->memory = atoi(optarg);
1278 conf->memory *= 1024ULL;
1279 conf->memory *= 1024ULL;
1282 /* force number of channels */
1284 conf->force_nchannel = atoi(optarg);
1285 if (conf->force_nchannel == 0) {
1286 RTE_LOG(ERR, EAL, "invalid channel number\n");
1290 /* force number of ranks */
1292 conf->force_nrank = atoi(optarg);
1293 if (conf->force_nrank == 0 ||
1294 conf->force_nrank > 16) {
1295 RTE_LOG(ERR, EAL, "invalid rank number\n");
1299 /* force loading of external driver */
1301 if (eal_plugin_add(optarg) == -1)
1305 /* since message is explicitly requested by user, we
1306 * write message at highest log level so it can always
1308 * even if info or warning messages are disabled */
1309 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1313 case OPT_HUGE_UNLINK_NUM:
1314 conf->hugepage_unlink = 1;
1317 case OPT_NO_HUGE_NUM:
1318 conf->no_hugetlbfs = 1;
1319 /* no-huge is legacy mem */
1320 conf->legacy_mem = 1;
1323 case OPT_NO_PCI_NUM:
1327 case OPT_NO_HPET_NUM:
1331 case OPT_VMWARE_TSC_MAP_NUM:
1332 conf->vmware_tsc_map = 1;
1335 case OPT_NO_SHCONF_NUM:
1336 conf->no_shconf = 1;
1339 case OPT_IN_MEMORY_NUM:
1340 conf->in_memory = 1;
1341 /* in-memory is a superset of noshconf and huge-unlink */
1342 conf->no_shconf = 1;
1343 conf->hugepage_unlink = 1;
1346 case OPT_PROC_TYPE_NUM:
1347 conf->process_type = eal_parse_proc_type(optarg);
1350 case OPT_MASTER_LCORE_NUM:
1351 if (eal_parse_master_lcore(optarg) < 0) {
1352 RTE_LOG(ERR, EAL, "invalid parameter for --"
1353 OPT_MASTER_LCORE "\n");
1359 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1365 case OPT_SYSLOG_NUM:
1366 if (eal_parse_syslog(optarg, conf) < 0) {
1367 RTE_LOG(ERR, EAL, "invalid parameters for --"
1373 case OPT_LOG_LEVEL_NUM: {
1374 if (eal_parse_log_level(optarg) < 0) {
1376 "invalid parameters for --"
1377 OPT_LOG_LEVEL "\n");
1382 case OPT_LCORES_NUM:
1383 if (eal_parse_lcores(optarg) < 0) {
1384 RTE_LOG(ERR, EAL, "invalid parameter for --"
1390 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1391 (core_parsed == LCORE_OPT_LST) ? "-l" :
1392 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1397 core_parsed = LCORE_OPT_MAP;
1399 case OPT_LEGACY_MEM_NUM:
1400 conf->legacy_mem = 1;
1402 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1403 conf->single_file_segments = 1;
1405 case OPT_IOVA_MODE_NUM:
1406 if (eal_parse_iova_mode(optarg) < 0) {
1407 RTE_LOG(ERR, EAL, "invalid parameters for --"
1408 OPT_IOVA_MODE "\n");
1413 /* don't know what to do, leave this to caller */
1421 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1422 "cannot be used at the same time\n");
1427 eal_auto_detect_cores(struct rte_config *cfg)
1429 unsigned int lcore_id;
1430 unsigned int removed = 0;
1431 rte_cpuset_t affinity_set;
1433 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1435 CPU_ZERO(&affinity_set);
1437 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1438 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1439 !CPU_ISSET(lcore_id, &affinity_set)) {
1440 cfg->lcore_role[lcore_id] = ROLE_OFF;
1445 cfg->lcore_count -= removed;
1449 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1451 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1452 rte_cpuset_t default_set;
1453 unsigned int lcore_id;
1455 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1456 if (eal_cpu_detected(lcore_id) &&
1457 rte_lcore_has_role(lcore_id, ROLE_OFF)) {
1458 CPU_SET(lcore_id, cpuset);
1462 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1464 CPU_ZERO(&default_set);
1466 RTE_CPU_AND(cpuset, cpuset, &default_set);
1468 /* if no detected CPU is off, use master core */
1469 if (!CPU_COUNT(cpuset))
1470 CPU_SET(rte_get_master_lcore(), cpuset);
1474 eal_cleanup_config(struct internal_config *internal_cfg)
1476 if (internal_cfg->hugefile_prefix != NULL)
1477 free(internal_cfg->hugefile_prefix);
1478 if (internal_cfg->hugepage_dir != NULL)
1479 free(internal_cfg->hugepage_dir);
1480 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1481 free(internal_cfg->user_mbuf_pool_ops_name);
1487 eal_adjust_config(struct internal_config *internal_cfg)
1490 struct rte_config *cfg = rte_eal_get_configuration();
1493 eal_auto_detect_cores(cfg);
1495 if (internal_config.process_type == RTE_PROC_AUTO)
1496 internal_config.process_type = eal_proc_type_detect();
1498 /* default master lcore is the first one */
1499 if (!master_lcore_parsed) {
1500 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1501 if (cfg->master_lcore >= RTE_MAX_LCORE)
1503 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1506 compute_ctrl_threads_cpuset(internal_cfg);
1508 /* if no memory amounts were requested, this will result in 0 and
1509 * will be overridden later, right after eal_hugepage_info_init() */
1510 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1511 internal_cfg->memory += internal_cfg->socket_mem[i];
1517 eal_check_common_options(struct internal_config *internal_cfg)
1519 struct rte_config *cfg = rte_eal_get_configuration();
1521 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1522 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1526 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1527 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1530 if (internal_cfg->hugefile_prefix != NULL &&
1531 strlen(internal_cfg->hugefile_prefix) < 1) {
1532 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1535 if (internal_cfg->hugepage_dir != NULL &&
1536 strlen(internal_cfg->hugepage_dir) < 1) {
1537 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1540 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1541 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1542 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1545 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1546 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1550 if (mem_parsed && internal_cfg->force_sockets == 1) {
1551 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1552 "be specified at the same time\n");
1555 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1556 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1557 "be specified together with --"OPT_NO_HUGE"\n");
1560 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1561 !internal_cfg->in_memory) {
1562 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1563 "be specified together with --"OPT_NO_HUGE"\n");
1566 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1567 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1568 " is only supported in non-legacy memory mode\n");
1570 if (internal_cfg->single_file_segments &&
1571 internal_cfg->hugepage_unlink &&
1572 !internal_cfg->in_memory) {
1573 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1574 "not compatible with --"OPT_HUGE_UNLINK"\n");
1577 if (internal_cfg->legacy_mem &&
1578 internal_cfg->in_memory) {
1579 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1580 "with --"OPT_IN_MEMORY"\n");
1583 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1584 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1585 "with --"OPT_MATCH_ALLOCATIONS"\n");
1588 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1589 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1590 "with --"OPT_MATCH_ALLOCATIONS"\n");
1598 eal_common_usage(void)
1600 printf("[options]\n\n"
1601 "EAL common options:\n"
1602 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1603 " -l CORELIST List of cores to run on\n"
1604 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1605 " where c1, c2, etc are core indexes between 0 and %d\n"
1606 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1607 " The argument format is\n"
1608 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1609 " lcores and cpus list are grouped by '(' and ')'\n"
1610 " Within the group, '-' is used for range separator,\n"
1611 " ',' is used for single number separator.\n"
1612 " '( )' can be omitted for single element group,\n"
1613 " '@' can be omitted if cpus and lcores have the same value\n"
1614 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1615 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1616 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1617 " -n CHANNELS Number of memory channels\n"
1618 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1619 " -r RANKS Force number of memory ranks (don't detect)\n"
1620 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1621 " Prevent EAL from using this PCI device. The argument\n"
1622 " format is <domain:bus:devid.func>.\n"
1623 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1624 " Only use the specified PCI devices. The argument format\n"
1625 " is <[domain:]bus:devid.func>. This option can be present\n"
1626 " several times (once per device).\n"
1627 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1628 " --"OPT_VDEV" Add a virtual device.\n"
1629 " The argument format is <driver><id>[,key=val,...]\n"
1630 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1631 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1632 " 'va' for IOVA_VA\n"
1633 " -d LIB.so|DIR Add a driver or driver directory\n"
1634 " (can be used multiple times)\n"
1635 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1636 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1637 " --"OPT_SYSLOG" Set syslog facility\n"
1638 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1639 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1640 " Set specific log level\n"
1641 " -v Display version information on startup\n"
1642 " -h, --help This help\n"
1643 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1644 " disable secondary process support\n"
1645 "\nEAL options for DEBUG use only:\n"
1646 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1647 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1648 " --"OPT_NO_PCI" Disable PCI\n"
1649 " --"OPT_NO_HPET" Disable HPET\n"
1650 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1651 "\n", RTE_MAX_LCORE);