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, sizeof(sopath), "%s/%s", path, dent->d_name);
265 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
268 if (eal_plugin_add(sopath) == -1)
273 /* XXX this ignores failures from readdir() itself */
274 return (dent == NULL) ? 0 : -1;
278 eal_plugins_init(void)
280 struct shared_driver *solib = NULL;
283 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
285 eal_plugin_add(default_solib_dir);
287 TAILQ_FOREACH(solib, &solib_list, next) {
289 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
290 if (eal_plugindir_init(solib->name) == -1) {
292 "Cannot init plugin directory %s\n",
297 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
299 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
300 if (solib->lib_handle == NULL) {
301 RTE_LOG(ERR, EAL, "%s\n", dlerror());
311 * Parse the coremask given as argument (hexadecimal string) and fill
312 * the global configuration (core role and core count) with the parsed
315 static int xdigit2val(unsigned char c)
329 eal_parse_service_coremask(const char *coremask)
331 struct rte_config *cfg = rte_eal_get_configuration();
333 unsigned int count = 0;
336 uint32_t taken_lcore_count = 0;
338 if (coremask == NULL)
340 /* Remove all blank characters ahead and after .
341 * Remove 0x/0X if exists.
343 while (isblank(*coremask))
345 if (coremask[0] == '0' && ((coremask[1] == 'x')
346 || (coremask[1] == 'X')))
348 i = strlen(coremask);
349 while ((i > 0) && isblank(coremask[i - 1]))
355 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
357 if (isxdigit(c) == 0) {
358 /* invalid characters */
362 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
364 if ((1 << j) & val) {
365 /* handle master lcore already parsed */
366 uint32_t lcore = idx;
367 if (master_lcore_parsed &&
368 cfg->master_lcore == lcore) {
370 "lcore %u is master lcore, cannot use as service core\n",
375 if (!lcore_config[idx].detected) {
377 "lcore %u unavailable\n", idx);
381 if (cfg->lcore_role[idx] == ROLE_RTE)
384 lcore_config[idx].core_role = ROLE_SERVICE;
391 if (coremask[i] != '0')
394 for (; idx < RTE_MAX_LCORE; idx++)
395 lcore_config[idx].core_index = -1;
400 if (core_parsed && taken_lcore_count != count) {
401 RTE_LOG(WARNING, EAL,
402 "Not all service cores are in the coremask. "
403 "Please ensure -c or -l includes service cores\n");
406 cfg->service_lcore_count = count;
411 eal_service_cores_parsed(void)
414 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
415 if (lcore_config[idx].core_role == ROLE_SERVICE)
422 update_lcore_config(int *cores)
424 struct rte_config *cfg = rte_eal_get_configuration();
425 unsigned int count = 0;
429 for (i = 0; i < RTE_MAX_LCORE; i++) {
430 if (cores[i] != -1) {
431 if (!lcore_config[i].detected) {
432 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
436 cfg->lcore_role[i] = ROLE_RTE;
439 cfg->lcore_role[i] = ROLE_OFF;
441 lcore_config[i].core_index = cores[i];
444 cfg->lcore_count = count;
449 eal_parse_coremask(const char *coremask, int *cores)
456 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
460 /* Remove all blank characters ahead and after .
461 * Remove 0x/0X if exists.
463 while (isblank(*coremask))
465 if (coremask[0] == '0' && ((coremask[1] == 'x')
466 || (coremask[1] == 'X')))
468 i = strlen(coremask);
469 while ((i > 0) && isblank(coremask[i - 1]))
474 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
476 if (isxdigit(c) == 0) {
477 /* invalid characters */
481 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
483 if ((1 << j) & val) {
490 if (coremask[i] != '0')
498 eal_parse_service_corelist(const char *corelist)
500 struct rte_config *cfg = rte_eal_get_configuration();
505 uint32_t taken_lcore_count = 0;
507 if (corelist == NULL)
510 /* Remove all blank characters ahead and after */
511 while (isblank(*corelist))
513 i = strlen(corelist);
514 while ((i > 0) && isblank(corelist[i - 1]))
517 /* Get list of cores */
520 while (isblank(*corelist))
522 if (*corelist == '\0')
525 idx = strtoul(corelist, &end, 10);
526 if (errno || end == NULL)
528 while (isblank(*end))
532 } else if ((*end == ',') || (*end == '\0')) {
534 if (min == RTE_MAX_LCORE)
536 for (idx = min; idx <= max; idx++) {
537 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
538 /* handle master lcore already parsed */
539 uint32_t lcore = idx;
540 if (cfg->master_lcore == lcore &&
541 master_lcore_parsed) {
543 "Error: lcore %u is master lcore, cannot use as service core\n",
547 if (cfg->lcore_role[idx] == ROLE_RTE)
550 lcore_config[idx].core_role =
559 } while (*end != '\0');
564 if (core_parsed && taken_lcore_count != count) {
565 RTE_LOG(WARNING, EAL,
566 "Not all service cores were in the coremask. "
567 "Please ensure -c or -l includes service cores\n");
574 eal_parse_corelist(const char *corelist, int *cores)
581 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
584 /* Remove all blank characters ahead */
585 while (isblank(*corelist))
588 /* Get list of cores */
591 while (isblank(*corelist))
593 if (*corelist == '\0')
596 idx = strtol(corelist, &end, 10);
597 if (errno || end == NULL)
599 if (idx < 0 || idx >= RTE_MAX_LCORE)
601 while (isblank(*end))
605 } else if ((*end == ',') || (*end == '\0')) {
607 if (min == RTE_MAX_LCORE)
609 for (idx = min; idx <= max; idx++) {
610 if (cores[idx] == -1) {
619 } while (*end != '\0');
626 /* Changes the lcore id of the master thread */
628 eal_parse_master_lcore(const char *arg)
631 struct rte_config *cfg = rte_eal_get_configuration();
634 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
635 if (errno || parsing_end[0] != 0)
637 if (cfg->master_lcore >= RTE_MAX_LCORE)
639 master_lcore_parsed = 1;
641 /* ensure master core is not used as service core */
642 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
644 "Error: Master lcore is used as a service core\n");
652 * Parse elem, the elem could be single number/range or '(' ')' group
653 * 1) A single number elem, it's just a simple digit. e.g. 9
654 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
655 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
656 * Within group elem, '-' used for a range separator;
657 * ',' used for a single number.
660 eal_parse_set(const char *input, uint16_t set[], unsigned num)
663 const char *str = input;
667 memset(set, 0, num * sizeof(uint16_t));
669 while (isblank(*str))
672 /* only digit or left bracket is qualify for start point */
673 if ((!isdigit(*str) && *str != '(') || *str == '\0')
676 /* process single number or single range of number */
679 idx = strtoul(str, &end, 10);
680 if (errno || end == NULL || idx >= num)
683 while (isblank(*end))
689 /* process single <number>-<number> */
691 while (isblank(*end))
697 idx = strtoul(end, &end, 10);
698 if (errno || end == NULL || idx >= num)
701 while (isblank(*end))
703 if (*end != ',' && *end != '\0')
707 if (*end != ',' && *end != '\0' &&
711 for (idx = RTE_MIN(min, max);
712 idx <= RTE_MAX(min, max); idx++)
719 /* process set within bracket */
721 while (isblank(*str))
729 /* go ahead to the first digit */
730 while (isblank(*str))
735 /* get the digit value */
737 idx = strtoul(str, &end, 10);
738 if (errno || end == NULL || idx >= num)
741 /* go ahead to separator '-',',' and ')' */
742 while (isblank(*end))
745 if (min == RTE_MAX_LCORE)
747 else /* avoid continuous '-' */
749 } else if ((*end == ',') || (*end == ')')) {
751 if (min == RTE_MAX_LCORE)
753 for (idx = RTE_MIN(min, max);
754 idx <= RTE_MAX(min, max); idx++)
762 } while (*end != '\0' && *end != ')');
765 * to avoid failure that tail blank makes end character check fail
766 * in eal_parse_lcores( )
768 while (isblank(*str))
774 /* convert from set array to cpuset bitmap */
776 convert_to_cpuset(rte_cpuset_t *cpusetp,
777 uint16_t *set, unsigned num)
783 for (idx = 0; idx < num; idx++) {
787 if (!lcore_config[idx].detected) {
788 RTE_LOG(ERR, EAL, "core %u "
789 "unavailable\n", idx);
793 CPU_SET(idx, cpusetp);
800 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
801 * lcores, cpus could be a single digit/range or a group.
802 * '(' and ')' are necessary if it's a group.
803 * If not supply '@cpus', the value of cpus uses the same as lcores.
804 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
805 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
806 * lcore 1 runs on cpuset 0x2 (cpu 1)
807 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
808 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
809 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
810 * lcore 7 runs on cpuset 0x80 (cpu 7)
811 * lcore 8 runs on cpuset 0x100 (cpu 8)
814 eal_parse_lcores(const char *lcores)
816 struct rte_config *cfg = rte_eal_get_configuration();
817 static uint16_t set[RTE_MAX_LCORE];
820 const char *lcore_start = NULL;
821 const char *end = NULL;
830 /* Remove all blank characters ahead and after */
831 while (isblank(*lcores))
836 /* Reset lcore config */
837 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
838 cfg->lcore_role[idx] = ROLE_OFF;
839 lcore_config[idx].core_index = -1;
840 CPU_ZERO(&lcore_config[idx].cpuset);
843 /* Get list of cores */
845 while (isblank(*lcores))
852 /* record lcore_set start point */
853 lcore_start = lcores;
855 /* go across a complete bracket */
856 if (*lcore_start == '(') {
857 lcores += strcspn(lcores, ")");
858 if (*lcores++ == '\0')
862 /* scan the separator '@', ','(next) or '\0'(finish) */
863 lcores += strcspn(lcores, "@,");
865 if (*lcores == '@') {
866 /* explicit assign cpu_set */
867 offset = eal_parse_set(lcores + 1, set, RTE_DIM(set));
871 /* prepare cpu_set and update the end cursor */
872 if (0 > convert_to_cpuset(&cpuset,
875 end = lcores + 1 + offset;
876 } else { /* ',' or '\0' */
877 /* haven't given cpu_set, current loop done */
880 /* go back to check <number>-<number> */
881 offset = strcspn(lcore_start, "(-");
882 if (offset < (end - lcore_start) &&
883 *(lcore_start + offset) != '(')
887 if (*end != ',' && *end != '\0')
890 /* parse lcore_set from start point */
891 if (0 > eal_parse_set(lcore_start, set, RTE_DIM(set)))
894 /* without '@', by default using lcore_set as cpu_set */
895 if (*lcores != '@' &&
896 0 > convert_to_cpuset(&cpuset, set, RTE_DIM(set)))
899 /* start to update lcore_set */
900 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
904 if (cfg->lcore_role[idx] != ROLE_RTE) {
905 lcore_config[idx].core_index = count;
906 cfg->lcore_role[idx] = ROLE_RTE;
912 CPU_SET(idx, &cpuset);
914 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
915 sizeof(rte_cpuset_t));
919 } while (*end != '\0');
924 cfg->lcore_count = count;
933 eal_parse_syslog(const char *facility, struct internal_config *conf)
936 static const struct {
940 { "auth", LOG_AUTH },
941 { "cron", LOG_CRON },
942 { "daemon", LOG_DAEMON },
944 { "kern", LOG_KERN },
946 { "mail", LOG_MAIL },
947 { "news", LOG_NEWS },
948 { "syslog", LOG_SYSLOG },
949 { "user", LOG_USER },
950 { "uucp", LOG_UUCP },
951 { "local0", LOG_LOCAL0 },
952 { "local1", LOG_LOCAL1 },
953 { "local2", LOG_LOCAL2 },
954 { "local3", LOG_LOCAL3 },
955 { "local4", LOG_LOCAL4 },
956 { "local5", LOG_LOCAL5 },
957 { "local6", LOG_LOCAL6 },
958 { "local7", LOG_LOCAL7 },
962 for (i = 0; map[i].name; i++) {
963 if (!strcmp(facility, map[i].name)) {
964 conf->syslog_facility = map[i].value;
972 eal_parse_log_priority(const char *level)
974 static const char * const levels[] = {
975 [RTE_LOG_EMERG] = "emergency",
976 [RTE_LOG_ALERT] = "alert",
977 [RTE_LOG_CRIT] = "critical",
978 [RTE_LOG_ERR] = "error",
979 [RTE_LOG_WARNING] = "warning",
980 [RTE_LOG_NOTICE] = "notice",
981 [RTE_LOG_INFO] = "info",
982 [RTE_LOG_DEBUG] = "debug",
984 size_t len = strlen(level);
992 /* look for named values, skip 0 which is not a valid level */
993 for (i = 1; i < RTE_DIM(levels); i++) {
994 if (strncmp(levels[i], level, len) == 0)
998 /* not a string, maybe it is numeric */
1000 tmp = strtoul(level, &end, 0);
1002 /* check for errors */
1003 if (errno != 0 || end == NULL || *end != '\0' ||
1011 eal_parse_log_level(const char *arg)
1013 const char *pattern = NULL;
1014 const char *regex = NULL;
1022 if ((level = strchr(str, ','))) {
1025 } else if ((level = strchr(str, ':'))) {
1032 priority = eal_parse_log_priority(level);
1034 fprintf(stderr, "invalid log priority: %s\n", level);
1039 if (rte_log_set_level_regexp(regex, priority) < 0) {
1040 fprintf(stderr, "cannot set log level %s,%d\n",
1044 if (rte_log_save_regexp(regex, priority) < 0)
1046 } else if (pattern) {
1047 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1048 fprintf(stderr, "cannot set log level %s:%d\n",
1052 if (rte_log_save_pattern(pattern, priority) < 0)
1055 rte_log_set_global_level(priority);
1066 static enum rte_proc_type_t
1067 eal_parse_proc_type(const char *arg)
1069 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1070 return RTE_PROC_PRIMARY;
1071 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1072 return RTE_PROC_SECONDARY;
1073 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1074 return RTE_PROC_AUTO;
1076 return RTE_PROC_INVALID;
1080 eal_parse_iova_mode(const char *name)
1087 if (!strcmp("pa", name))
1089 else if (!strcmp("va", name))
1094 internal_config.iova_mode = mode;
1098 /* caller is responsible for freeing the returned string */
1100 available_cores(void)
1108 /* find the first available cpu */
1109 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1110 if (!lcore_config[idx].detected)
1114 if (idx >= RTE_MAX_LCORE)
1117 /* first sequence */
1118 if (asprintf(&str, "%d", idx) < 0)
1123 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1124 if (!lcore_config[idx].detected)
1127 if (idx == previous + 1) {
1133 /* finish current sequence */
1135 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1144 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1154 /* finish last sequence */
1156 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1168 eal_parse_common_option(int opt, const char *optarg,
1169 struct internal_config *conf)
1179 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1189 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1197 int lcore_indexes[RTE_MAX_LCORE];
1199 if (eal_service_cores_parsed())
1200 RTE_LOG(WARNING, EAL,
1201 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1202 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1203 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1206 if (update_lcore_config(lcore_indexes) < 0) {
1207 char *available = available_cores();
1210 "invalid coremask, please check specified cores are part of %s\n",
1217 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1218 (core_parsed == LCORE_OPT_LST) ? "-l" :
1219 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1224 core_parsed = LCORE_OPT_MSK;
1229 int lcore_indexes[RTE_MAX_LCORE];
1231 if (eal_service_cores_parsed())
1232 RTE_LOG(WARNING, EAL,
1233 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1235 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1236 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1239 if (update_lcore_config(lcore_indexes) < 0) {
1240 char *available = available_cores();
1243 "invalid core list, please check specified cores are part of %s\n",
1250 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1251 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1252 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1257 core_parsed = LCORE_OPT_LST;
1260 /* service coremask */
1262 if (eal_parse_service_coremask(optarg) < 0) {
1263 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1267 /* service corelist */
1269 if (eal_parse_service_corelist(optarg) < 0) {
1270 RTE_LOG(ERR, EAL, "invalid service core list\n");
1274 /* size of memory */
1276 conf->memory = atoi(optarg);
1277 conf->memory *= 1024ULL;
1278 conf->memory *= 1024ULL;
1281 /* force number of channels */
1283 conf->force_nchannel = atoi(optarg);
1284 if (conf->force_nchannel == 0) {
1285 RTE_LOG(ERR, EAL, "invalid channel number\n");
1289 /* force number of ranks */
1291 conf->force_nrank = atoi(optarg);
1292 if (conf->force_nrank == 0 ||
1293 conf->force_nrank > 16) {
1294 RTE_LOG(ERR, EAL, "invalid rank number\n");
1298 /* force loading of external driver */
1300 if (eal_plugin_add(optarg) == -1)
1304 /* since message is explicitly requested by user, we
1305 * write message at highest log level so it can always
1307 * even if info or warning messages are disabled */
1308 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1312 case OPT_HUGE_UNLINK_NUM:
1313 conf->hugepage_unlink = 1;
1316 case OPT_NO_HUGE_NUM:
1317 conf->no_hugetlbfs = 1;
1318 /* no-huge is legacy mem */
1319 conf->legacy_mem = 1;
1322 case OPT_NO_PCI_NUM:
1326 case OPT_NO_HPET_NUM:
1330 case OPT_VMWARE_TSC_MAP_NUM:
1331 conf->vmware_tsc_map = 1;
1334 case OPT_NO_SHCONF_NUM:
1335 conf->no_shconf = 1;
1338 case OPT_IN_MEMORY_NUM:
1339 conf->in_memory = 1;
1340 /* in-memory is a superset of noshconf and huge-unlink */
1341 conf->no_shconf = 1;
1342 conf->hugepage_unlink = 1;
1345 case OPT_PROC_TYPE_NUM:
1346 conf->process_type = eal_parse_proc_type(optarg);
1349 case OPT_MASTER_LCORE_NUM:
1350 if (eal_parse_master_lcore(optarg) < 0) {
1351 RTE_LOG(ERR, EAL, "invalid parameter for --"
1352 OPT_MASTER_LCORE "\n");
1358 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1364 case OPT_SYSLOG_NUM:
1365 if (eal_parse_syslog(optarg, conf) < 0) {
1366 RTE_LOG(ERR, EAL, "invalid parameters for --"
1372 case OPT_LOG_LEVEL_NUM: {
1373 if (eal_parse_log_level(optarg) < 0) {
1375 "invalid parameters for --"
1376 OPT_LOG_LEVEL "\n");
1381 case OPT_LCORES_NUM:
1382 if (eal_parse_lcores(optarg) < 0) {
1383 RTE_LOG(ERR, EAL, "invalid parameter for --"
1389 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1390 (core_parsed == LCORE_OPT_LST) ? "-l" :
1391 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1396 core_parsed = LCORE_OPT_MAP;
1398 case OPT_LEGACY_MEM_NUM:
1399 conf->legacy_mem = 1;
1401 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1402 conf->single_file_segments = 1;
1404 case OPT_IOVA_MODE_NUM:
1405 if (eal_parse_iova_mode(optarg) < 0) {
1406 RTE_LOG(ERR, EAL, "invalid parameters for --"
1407 OPT_IOVA_MODE "\n");
1412 /* don't know what to do, leave this to caller */
1420 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1421 "cannot be used at the same time\n");
1426 eal_auto_detect_cores(struct rte_config *cfg)
1428 unsigned int lcore_id;
1429 unsigned int removed = 0;
1430 rte_cpuset_t affinity_set;
1432 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1434 CPU_ZERO(&affinity_set);
1436 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1437 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1438 !CPU_ISSET(lcore_id, &affinity_set)) {
1439 cfg->lcore_role[lcore_id] = ROLE_OFF;
1444 cfg->lcore_count -= removed;
1448 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1450 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1451 rte_cpuset_t default_set;
1452 unsigned int lcore_id;
1454 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1455 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1457 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1459 RTE_CPU_NOT(cpuset, cpuset);
1461 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1463 CPU_ZERO(&default_set);
1465 RTE_CPU_AND(cpuset, cpuset, &default_set);
1467 /* if no remaining cpu, use master lcore cpu affinity */
1468 if (!CPU_COUNT(cpuset)) {
1469 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1475 eal_cleanup_config(struct internal_config *internal_cfg)
1477 if (internal_cfg->hugefile_prefix != NULL)
1478 free(internal_cfg->hugefile_prefix);
1479 if (internal_cfg->hugepage_dir != NULL)
1480 free(internal_cfg->hugepage_dir);
1481 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1482 free(internal_cfg->user_mbuf_pool_ops_name);
1488 eal_adjust_config(struct internal_config *internal_cfg)
1491 struct rte_config *cfg = rte_eal_get_configuration();
1494 eal_auto_detect_cores(cfg);
1496 if (internal_config.process_type == RTE_PROC_AUTO)
1497 internal_config.process_type = eal_proc_type_detect();
1499 /* default master lcore is the first one */
1500 if (!master_lcore_parsed) {
1501 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1502 if (cfg->master_lcore >= RTE_MAX_LCORE)
1504 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1507 compute_ctrl_threads_cpuset(internal_cfg);
1509 /* if no memory amounts were requested, this will result in 0 and
1510 * will be overridden later, right after eal_hugepage_info_init() */
1511 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1512 internal_cfg->memory += internal_cfg->socket_mem[i];
1518 eal_check_common_options(struct internal_config *internal_cfg)
1520 struct rte_config *cfg = rte_eal_get_configuration();
1522 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1523 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1527 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1528 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1531 if (internal_cfg->hugefile_prefix != NULL &&
1532 strlen(internal_cfg->hugefile_prefix) < 1) {
1533 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1536 if (internal_cfg->hugepage_dir != NULL &&
1537 strlen(internal_cfg->hugepage_dir) < 1) {
1538 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1541 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1542 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1543 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1546 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1547 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1551 if (mem_parsed && internal_cfg->force_sockets == 1) {
1552 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1553 "be specified at the same time\n");
1556 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1557 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1558 "be specified together with --"OPT_NO_HUGE"\n");
1561 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1562 !internal_cfg->in_memory) {
1563 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1564 "be specified together with --"OPT_NO_HUGE"\n");
1567 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1568 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1569 " is only supported in non-legacy memory mode\n");
1571 if (internal_cfg->single_file_segments &&
1572 internal_cfg->hugepage_unlink &&
1573 !internal_cfg->in_memory) {
1574 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1575 "not compatible with --"OPT_HUGE_UNLINK"\n");
1578 if (internal_cfg->legacy_mem &&
1579 internal_cfg->in_memory) {
1580 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1581 "with --"OPT_IN_MEMORY"\n");
1584 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1585 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1586 "with --"OPT_MATCH_ALLOCATIONS"\n");
1589 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1590 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1591 "with --"OPT_MATCH_ALLOCATIONS"\n");
1594 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1595 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1596 "amount of reserved memory can be adjusted with "
1597 "-m or --"OPT_SOCKET_MEM"\n");
1604 eal_common_usage(void)
1606 printf("[options]\n\n"
1607 "EAL common options:\n"
1608 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1609 " -l CORELIST List of cores to run on\n"
1610 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1611 " where c1, c2, etc are core indexes between 0 and %d\n"
1612 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1613 " The argument format is\n"
1614 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1615 " lcores and cpus list are grouped by '(' and ')'\n"
1616 " Within the group, '-' is used for range separator,\n"
1617 " ',' is used for single number separator.\n"
1618 " '( )' can be omitted for single element group,\n"
1619 " '@' can be omitted if cpus and lcores have the same value\n"
1620 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1621 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1622 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1623 " -n CHANNELS Number of memory channels\n"
1624 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1625 " -r RANKS Force number of memory ranks (don't detect)\n"
1626 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1627 " Prevent EAL from using this PCI device. The argument\n"
1628 " format is <domain:bus:devid.func>.\n"
1629 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1630 " Only use the specified PCI devices. The argument format\n"
1631 " is <[domain:]bus:devid.func>. This option can be present\n"
1632 " several times (once per device).\n"
1633 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1634 " --"OPT_VDEV" Add a virtual device.\n"
1635 " The argument format is <driver><id>[,key=val,...]\n"
1636 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1637 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1638 " 'va' for IOVA_VA\n"
1639 " -d LIB.so|DIR Add a driver or driver directory\n"
1640 " (can be used multiple times)\n"
1641 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1642 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1643 " --"OPT_SYSLOG" Set syslog facility\n"
1644 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1645 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1646 " Set specific log level\n"
1647 " -v Display version information on startup\n"
1648 " -h, --help This help\n"
1649 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1650 " disable secondary process support\n"
1651 "\nEAL options for DEBUG use only:\n"
1652 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1653 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1654 " --"OPT_NO_PCI" Disable PCI\n"
1655 " --"OPT_NO_HPET" Disable HPET\n"
1656 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1657 "\n", RTE_MAX_LCORE);