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>
21 #include <rte_lcore.h>
22 #include <rte_tailq.h>
23 #include <rte_version.h>
24 #include <rte_devargs.h>
25 #include <rte_memcpy.h>
27 #include "eal_internal_cfg.h"
28 #include "eal_options.h"
29 #include "eal_filesystem.h"
30 #include "eal_private.h"
32 #define BITS_PER_HEX 4
33 #define LCORE_OPT_LST 1
34 #define LCORE_OPT_MSK 2
35 #define LCORE_OPT_MAP 3
39 "b:" /* pci-blacklist */
41 "s:" /* service coremask */
45 "S:" /* service corelist */
46 "m:" /* memory size */
47 "n:" /* memory channels */
48 "r:" /* memory ranks */
50 "w:" /* pci-whitelist */
54 eal_long_options[] = {
55 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM },
56 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM },
57 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM },
58 {OPT_HELP, 0, NULL, OPT_HELP_NUM },
59 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM },
60 {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM },
61 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
62 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
63 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
64 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
65 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
66 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
67 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
68 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
69 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
70 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
71 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
72 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
73 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
74 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
75 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
76 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
77 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
78 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
79 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
80 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
81 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
82 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
86 TAILQ_HEAD(shared_driver_list, shared_driver);
88 /* Definition for shared object drivers. */
89 struct shared_driver {
90 TAILQ_ENTRY(shared_driver) next;
96 /* List of external loadable drivers */
97 static struct shared_driver_list solib_list =
98 TAILQ_HEAD_INITIALIZER(solib_list);
100 /* Default path of external loadable drivers */
101 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
104 * Stringified version of solib path used by dpdk-pmdinfo.py
105 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
106 * change to usertools/dpdk-pmdinfo.py
108 static const char dpdk_solib_path[] __attribute__((used)) =
109 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
111 TAILQ_HEAD(device_option_list, device_option);
113 struct device_option {
114 TAILQ_ENTRY(device_option) next;
116 enum rte_devtype type;
120 static struct device_option_list devopt_list =
121 TAILQ_HEAD_INITIALIZER(devopt_list);
123 static int master_lcore_parsed;
124 static int mem_parsed;
125 static int core_parsed;
128 eal_option_device_add(enum rte_devtype type, const char *optarg)
130 struct device_option *devopt;
134 optlen = strlen(optarg) + 1;
135 devopt = calloc(1, sizeof(*devopt) + optlen);
136 if (devopt == NULL) {
137 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
142 ret = snprintf(devopt->arg, optlen, "%s", optarg);
144 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
148 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
153 eal_option_device_parse(void)
155 struct device_option *devopt;
159 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
161 ret = rte_devargs_add(devopt->type, devopt->arg);
163 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
166 TAILQ_REMOVE(&devopt_list, devopt, next);
173 eal_get_hugefile_prefix(void)
175 if (internal_config.hugefile_prefix != NULL)
176 return internal_config.hugefile_prefix;
177 return HUGEFILE_PREFIX_DEFAULT;
181 eal_reset_internal_config(struct internal_config *internal_cfg)
185 internal_cfg->memory = 0;
186 internal_cfg->force_nrank = 0;
187 internal_cfg->force_nchannel = 0;
188 internal_cfg->hugefile_prefix = NULL;
189 internal_cfg->hugepage_dir = NULL;
190 internal_cfg->force_sockets = 0;
191 /* zero out the NUMA config */
192 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
193 internal_cfg->socket_mem[i] = 0;
194 internal_cfg->force_socket_limits = 0;
195 /* zero out the NUMA limits config */
196 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
197 internal_cfg->socket_limit[i] = 0;
198 /* zero out hugedir descriptors */
199 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
200 memset(&internal_cfg->hugepage_info[i], 0,
201 sizeof(internal_cfg->hugepage_info[0]));
202 internal_cfg->hugepage_info[i].lock_descriptor = -1;
204 internal_cfg->base_virtaddr = 0;
206 internal_cfg->syslog_facility = LOG_DAEMON;
208 /* if set to NONE, interrupt mode is determined automatically */
209 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
211 #ifdef RTE_LIBEAL_USE_HPET
212 internal_cfg->no_hpet = 0;
214 internal_cfg->no_hpet = 1;
216 internal_cfg->vmware_tsc_map = 0;
217 internal_cfg->create_uio_dev = 0;
218 internal_cfg->iova_mode = RTE_IOVA_DC;
219 internal_cfg->user_mbuf_pool_ops_name = NULL;
220 CPU_ZERO(&internal_cfg->ctrl_cpuset);
221 internal_cfg->init_complete = 0;
225 eal_plugin_add(const char *path)
227 struct shared_driver *solib;
229 solib = malloc(sizeof(*solib));
231 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
234 memset(solib, 0, sizeof(*solib));
235 strlcpy(solib->name, path, PATH_MAX-1);
236 solib->name[PATH_MAX-1] = 0;
237 TAILQ_INSERT_TAIL(&solib_list, solib, next);
243 eal_plugindir_init(const char *path)
246 struct dirent *dent = NULL;
247 char sopath[PATH_MAX];
249 if (path == NULL || *path == '\0')
254 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
255 path, strerror(errno));
259 while ((dent = readdir(d)) != NULL) {
262 snprintf(sopath, PATH_MAX-1, "%s/%s", path, dent->d_name);
263 sopath[PATH_MAX-1] = 0;
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 eal_parse_coremask(const char *coremask)
424 struct rte_config *cfg = rte_eal_get_configuration();
430 if (eal_service_cores_parsed())
431 RTE_LOG(WARNING, EAL,
432 "Service cores parsed before dataplane cores. "
433 "Please ensure -c is before -s or -S\n");
435 if (coremask == NULL)
437 /* Remove all blank characters ahead and after .
438 * Remove 0x/0X if exists.
440 while (isblank(*coremask))
442 if (coremask[0] == '0' && ((coremask[1] == 'x')
443 || (coremask[1] == 'X')))
445 i = strlen(coremask);
446 while ((i > 0) && isblank(coremask[i - 1]))
451 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
453 if (isxdigit(c) == 0) {
454 /* invalid characters */
458 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
460 if ((1 << j) & val) {
461 if (!lcore_config[idx].detected) {
462 RTE_LOG(ERR, EAL, "lcore %u "
463 "unavailable\n", idx);
467 cfg->lcore_role[idx] = ROLE_RTE;
468 lcore_config[idx].core_index = count;
471 cfg->lcore_role[idx] = ROLE_OFF;
472 lcore_config[idx].core_index = -1;
477 if (coremask[i] != '0')
479 for (; idx < RTE_MAX_LCORE; idx++) {
480 cfg->lcore_role[idx] = ROLE_OFF;
481 lcore_config[idx].core_index = -1;
485 /* Update the count of enabled logical cores of the EAL configuration */
486 cfg->lcore_count = count;
491 eal_parse_service_corelist(const char *corelist)
493 struct rte_config *cfg = rte_eal_get_configuration();
498 uint32_t taken_lcore_count = 0;
500 if (corelist == NULL)
503 /* Remove all blank characters ahead and after */
504 while (isblank(*corelist))
506 i = strlen(corelist);
507 while ((i > 0) && isblank(corelist[i - 1]))
510 /* Get list of cores */
513 while (isblank(*corelist))
515 if (*corelist == '\0')
518 idx = strtoul(corelist, &end, 10);
519 if (errno || end == NULL)
521 while (isblank(*end))
525 } else if ((*end == ',') || (*end == '\0')) {
527 if (min == RTE_MAX_LCORE)
529 for (idx = min; idx <= max; idx++) {
530 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
531 /* handle master lcore already parsed */
532 uint32_t lcore = idx;
533 if (cfg->master_lcore == lcore &&
534 master_lcore_parsed) {
536 "Error: lcore %u is master lcore, cannot use as service core\n",
540 if (cfg->lcore_role[idx] == ROLE_RTE)
543 lcore_config[idx].core_role =
552 } while (*end != '\0');
557 if (core_parsed && taken_lcore_count != count) {
558 RTE_LOG(WARNING, EAL,
559 "Not all service cores were in the coremask. "
560 "Please ensure -c or -l includes service cores\n");
567 eal_parse_corelist(const char *corelist)
569 struct rte_config *cfg = rte_eal_get_configuration();
575 if (eal_service_cores_parsed())
576 RTE_LOG(WARNING, EAL,
577 "Service cores parsed before dataplane cores. "
578 "Please ensure -l is before -s or -S\n");
580 if (corelist == NULL)
583 /* Remove all blank characters ahead */
584 while (isblank(*corelist))
588 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
589 cfg->lcore_role[idx] = ROLE_OFF;
590 lcore_config[idx].core_index = -1;
593 /* Get list of cores */
596 while (isblank(*corelist))
598 if (*corelist == '\0')
601 idx = strtol(corelist, &end, 10);
602 if (idx < 0 || idx >= (int)cfg->lcore_count)
604 if (errno || end == NULL)
606 while (isblank(*end))
610 } else if ((*end == ',') || (*end == '\0')) {
612 if (min == RTE_MAX_LCORE)
614 for (idx = min; idx <= max; idx++) {
615 if (cfg->lcore_role[idx] != ROLE_RTE) {
616 cfg->lcore_role[idx] = ROLE_RTE;
617 lcore_config[idx].core_index = count;
625 } while (*end != '\0');
630 /* Update the count of enabled logical cores of the EAL configuration */
631 cfg->lcore_count = count;
636 /* Changes the lcore id of the master thread */
638 eal_parse_master_lcore(const char *arg)
641 struct rte_config *cfg = rte_eal_get_configuration();
644 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
645 if (errno || parsing_end[0] != 0)
647 if (cfg->master_lcore >= RTE_MAX_LCORE)
649 master_lcore_parsed = 1;
651 /* ensure master core is not used as service core */
652 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
654 "Error: Master lcore is used as a service core\n");
662 * Parse elem, the elem could be single number/range or '(' ')' group
663 * 1) A single number elem, it's just a simple digit. e.g. 9
664 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
665 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
666 * Within group elem, '-' used for a range separator;
667 * ',' used for a single number.
670 eal_parse_set(const char *input, uint16_t set[], unsigned num)
673 const char *str = input;
677 memset(set, 0, num * sizeof(uint16_t));
679 while (isblank(*str))
682 /* only digit or left bracket is qualify for start point */
683 if ((!isdigit(*str) && *str != '(') || *str == '\0')
686 /* process single number or single range of number */
689 idx = strtoul(str, &end, 10);
690 if (errno || end == NULL || idx >= num)
693 while (isblank(*end))
699 /* process single <number>-<number> */
701 while (isblank(*end))
707 idx = strtoul(end, &end, 10);
708 if (errno || end == NULL || idx >= num)
711 while (isblank(*end))
713 if (*end != ',' && *end != '\0')
717 if (*end != ',' && *end != '\0' &&
721 for (idx = RTE_MIN(min, max);
722 idx <= RTE_MAX(min, max); idx++)
729 /* process set within bracket */
731 while (isblank(*str))
739 /* go ahead to the first digit */
740 while (isblank(*str))
745 /* get the digit value */
747 idx = strtoul(str, &end, 10);
748 if (errno || end == NULL || idx >= num)
751 /* go ahead to separator '-',',' and ')' */
752 while (isblank(*end))
755 if (min == RTE_MAX_LCORE)
757 else /* avoid continuous '-' */
759 } else if ((*end == ',') || (*end == ')')) {
761 if (min == RTE_MAX_LCORE)
763 for (idx = RTE_MIN(min, max);
764 idx <= RTE_MAX(min, max); idx++)
772 } while (*end != '\0' && *end != ')');
775 * to avoid failure that tail blank makes end character check fail
776 * in eal_parse_lcores( )
778 while (isblank(*str))
784 /* convert from set array to cpuset bitmap */
786 convert_to_cpuset(rte_cpuset_t *cpusetp,
787 uint16_t *set, unsigned num)
793 for (idx = 0; idx < num; idx++) {
797 if (!lcore_config[idx].detected) {
798 RTE_LOG(ERR, EAL, "core %u "
799 "unavailable\n", idx);
803 CPU_SET(idx, cpusetp);
810 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
811 * lcores, cpus could be a single digit/range or a group.
812 * '(' and ')' are necessary if it's a group.
813 * If not supply '@cpus', the value of cpus uses the same as lcores.
814 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
815 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
816 * lcore 1 runs on cpuset 0x2 (cpu 1)
817 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
818 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
819 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
820 * lcore 7 runs on cpuset 0x80 (cpu 7)
821 * lcore 8 runs on cpuset 0x100 (cpu 8)
824 eal_parse_lcores(const char *lcores)
826 struct rte_config *cfg = rte_eal_get_configuration();
827 static uint16_t set[RTE_MAX_LCORE];
830 const char *lcore_start = NULL;
831 const char *end = NULL;
840 /* Remove all blank characters ahead and after */
841 while (isblank(*lcores))
846 /* Reset lcore config */
847 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
848 cfg->lcore_role[idx] = ROLE_OFF;
849 lcore_config[idx].core_index = -1;
850 CPU_ZERO(&lcore_config[idx].cpuset);
853 /* Get list of cores */
855 while (isblank(*lcores))
862 /* record lcore_set start point */
863 lcore_start = lcores;
865 /* go across a complete bracket */
866 if (*lcore_start == '(') {
867 lcores += strcspn(lcores, ")");
868 if (*lcores++ == '\0')
872 /* scan the separator '@', ','(next) or '\0'(finish) */
873 lcores += strcspn(lcores, "@,");
875 if (*lcores == '@') {
876 /* explicit assign cpu_set */
877 offset = eal_parse_set(lcores + 1, set, RTE_DIM(set));
881 /* prepare cpu_set and update the end cursor */
882 if (0 > convert_to_cpuset(&cpuset,
885 end = lcores + 1 + offset;
886 } else { /* ',' or '\0' */
887 /* haven't given cpu_set, current loop done */
890 /* go back to check <number>-<number> */
891 offset = strcspn(lcore_start, "(-");
892 if (offset < (end - lcore_start) &&
893 *(lcore_start + offset) != '(')
897 if (*end != ',' && *end != '\0')
900 /* parse lcore_set from start point */
901 if (0 > eal_parse_set(lcore_start, set, RTE_DIM(set)))
904 /* without '@', by default using lcore_set as cpu_set */
905 if (*lcores != '@' &&
906 0 > convert_to_cpuset(&cpuset, set, RTE_DIM(set)))
909 /* start to update lcore_set */
910 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
914 if (cfg->lcore_role[idx] != ROLE_RTE) {
915 lcore_config[idx].core_index = count;
916 cfg->lcore_role[idx] = ROLE_RTE;
922 CPU_SET(idx, &cpuset);
924 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
925 sizeof(rte_cpuset_t));
929 } while (*end != '\0');
934 cfg->lcore_count = count;
943 eal_parse_syslog(const char *facility, struct internal_config *conf)
946 static const struct {
950 { "auth", LOG_AUTH },
951 { "cron", LOG_CRON },
952 { "daemon", LOG_DAEMON },
954 { "kern", LOG_KERN },
956 { "mail", LOG_MAIL },
957 { "news", LOG_NEWS },
958 { "syslog", LOG_SYSLOG },
959 { "user", LOG_USER },
960 { "uucp", LOG_UUCP },
961 { "local0", LOG_LOCAL0 },
962 { "local1", LOG_LOCAL1 },
963 { "local2", LOG_LOCAL2 },
964 { "local3", LOG_LOCAL3 },
965 { "local4", LOG_LOCAL4 },
966 { "local5", LOG_LOCAL5 },
967 { "local6", LOG_LOCAL6 },
968 { "local7", LOG_LOCAL7 },
972 for (i = 0; map[i].name; i++) {
973 if (!strcmp(facility, map[i].name)) {
974 conf->syslog_facility = map[i].value;
982 eal_parse_log_priority(const char *level)
984 static const char * const levels[] = {
985 [RTE_LOG_EMERG] = "emergency",
986 [RTE_LOG_ALERT] = "alert",
987 [RTE_LOG_CRIT] = "critical",
988 [RTE_LOG_ERR] = "error",
989 [RTE_LOG_WARNING] = "warning",
990 [RTE_LOG_NOTICE] = "notice",
991 [RTE_LOG_INFO] = "info",
992 [RTE_LOG_DEBUG] = "debug",
994 size_t len = strlen(level);
1002 /* look for named values, skip 0 which is not a valid level */
1003 for (i = 1; i < RTE_DIM(levels); i++) {
1004 if (strncmp(levels[i], level, len) == 0)
1008 /* not a string, maybe it is numeric */
1010 tmp = strtoul(level, &end, 0);
1012 /* check for errors */
1013 if (errno != 0 || end == NULL || *end != '\0' ||
1021 eal_parse_log_level(const char *arg)
1023 const char *pattern = NULL;
1024 const char *regex = NULL;
1032 if ((level = strchr(str, ','))) {
1035 } else if ((level = strchr(str, ':'))) {
1042 priority = eal_parse_log_priority(level);
1044 fprintf(stderr, "invalid log priority: %s\n", level);
1049 if (rte_log_set_level_regexp(regex, priority) < 0) {
1050 fprintf(stderr, "cannot set log level %s,%d\n",
1054 if (rte_log_save_regexp(regex, priority) < 0)
1056 } else if (pattern) {
1057 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1058 fprintf(stderr, "cannot set log level %s:%d\n",
1062 if (rte_log_save_pattern(pattern, priority) < 0)
1065 rte_log_set_global_level(priority);
1076 static enum rte_proc_type_t
1077 eal_parse_proc_type(const char *arg)
1079 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1080 return RTE_PROC_PRIMARY;
1081 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1082 return RTE_PROC_SECONDARY;
1083 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1084 return RTE_PROC_AUTO;
1086 return RTE_PROC_INVALID;
1090 eal_parse_iova_mode(const char *name)
1097 if (!strcmp("pa", name))
1099 else if (!strcmp("va", name))
1104 internal_config.iova_mode = mode;
1109 eal_parse_common_option(int opt, const char *optarg,
1110 struct internal_config *conf)
1114 struct rte_config *cfg = rte_eal_get_configuration();
1121 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1131 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1139 if (eal_parse_coremask(optarg) < 0) {
1140 RTE_LOG(ERR, EAL, "invalid coremask\n");
1145 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1146 (core_parsed == LCORE_OPT_LST) ? "-l" :
1147 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1152 core_parsed = LCORE_OPT_MSK;
1156 if (eal_parse_corelist(optarg) < 0) {
1158 "invalid core list, please check core numbers are in [0, %u] range\n",
1159 cfg->lcore_count-1);
1164 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1165 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1166 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1171 core_parsed = LCORE_OPT_LST;
1173 /* service coremask */
1175 if (eal_parse_service_coremask(optarg) < 0) {
1176 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1180 /* service corelist */
1182 if (eal_parse_service_corelist(optarg) < 0) {
1183 RTE_LOG(ERR, EAL, "invalid service core list\n");
1187 /* size of memory */
1189 conf->memory = atoi(optarg);
1190 conf->memory *= 1024ULL;
1191 conf->memory *= 1024ULL;
1194 /* force number of channels */
1196 conf->force_nchannel = atoi(optarg);
1197 if (conf->force_nchannel == 0) {
1198 RTE_LOG(ERR, EAL, "invalid channel number\n");
1202 /* force number of ranks */
1204 conf->force_nrank = atoi(optarg);
1205 if (conf->force_nrank == 0 ||
1206 conf->force_nrank > 16) {
1207 RTE_LOG(ERR, EAL, "invalid rank number\n");
1211 /* force loading of external driver */
1213 if (eal_plugin_add(optarg) == -1)
1217 /* since message is explicitly requested by user, we
1218 * write message at highest log level so it can always
1220 * even if info or warning messages are disabled */
1221 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1225 case OPT_HUGE_UNLINK_NUM:
1226 conf->hugepage_unlink = 1;
1229 case OPT_NO_HUGE_NUM:
1230 conf->no_hugetlbfs = 1;
1231 /* no-huge is legacy mem */
1232 conf->legacy_mem = 1;
1235 case OPT_NO_PCI_NUM:
1239 case OPT_NO_HPET_NUM:
1243 case OPT_VMWARE_TSC_MAP_NUM:
1244 conf->vmware_tsc_map = 1;
1247 case OPT_NO_SHCONF_NUM:
1248 conf->no_shconf = 1;
1251 case OPT_IN_MEMORY_NUM:
1252 conf->in_memory = 1;
1253 /* in-memory is a superset of noshconf and huge-unlink */
1254 conf->no_shconf = 1;
1255 conf->hugepage_unlink = 1;
1258 case OPT_PROC_TYPE_NUM:
1259 conf->process_type = eal_parse_proc_type(optarg);
1262 case OPT_MASTER_LCORE_NUM:
1263 if (eal_parse_master_lcore(optarg) < 0) {
1264 RTE_LOG(ERR, EAL, "invalid parameter for --"
1265 OPT_MASTER_LCORE "\n");
1271 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1277 case OPT_SYSLOG_NUM:
1278 if (eal_parse_syslog(optarg, conf) < 0) {
1279 RTE_LOG(ERR, EAL, "invalid parameters for --"
1285 case OPT_LOG_LEVEL_NUM: {
1286 if (eal_parse_log_level(optarg) < 0) {
1288 "invalid parameters for --"
1289 OPT_LOG_LEVEL "\n");
1294 case OPT_LCORES_NUM:
1295 if (eal_parse_lcores(optarg) < 0) {
1296 RTE_LOG(ERR, EAL, "invalid parameter for --"
1302 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1303 (core_parsed == LCORE_OPT_LST) ? "-l" :
1304 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1309 core_parsed = LCORE_OPT_MAP;
1311 case OPT_LEGACY_MEM_NUM:
1312 conf->legacy_mem = 1;
1314 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1315 conf->single_file_segments = 1;
1317 case OPT_IOVA_MODE_NUM:
1318 if (eal_parse_iova_mode(optarg) < 0) {
1319 RTE_LOG(ERR, EAL, "invalid parameters for --"
1320 OPT_IOVA_MODE "\n");
1325 /* don't know what to do, leave this to caller */
1333 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1334 "cannot be used at the same time\n");
1339 eal_auto_detect_cores(struct rte_config *cfg)
1341 unsigned int lcore_id;
1342 unsigned int removed = 0;
1343 rte_cpuset_t affinity_set;
1345 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1347 CPU_ZERO(&affinity_set);
1349 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1350 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1351 !CPU_ISSET(lcore_id, &affinity_set)) {
1352 cfg->lcore_role[lcore_id] = ROLE_OFF;
1357 cfg->lcore_count -= removed;
1361 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1363 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1364 rte_cpuset_t default_set;
1365 unsigned int lcore_id;
1367 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1368 if (eal_cpu_detected(lcore_id) &&
1369 rte_lcore_has_role(lcore_id, ROLE_OFF)) {
1370 CPU_SET(lcore_id, cpuset);
1374 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1376 CPU_ZERO(&default_set);
1378 RTE_CPU_AND(cpuset, cpuset, &default_set);
1380 /* if no detected CPU is off, use master core */
1381 if (!CPU_COUNT(cpuset))
1382 CPU_SET(rte_get_master_lcore(), cpuset);
1386 eal_cleanup_config(struct internal_config *internal_cfg)
1388 if (internal_cfg->hugefile_prefix != NULL)
1389 free(internal_cfg->hugefile_prefix);
1390 if (internal_cfg->hugepage_dir != NULL)
1391 free(internal_cfg->hugepage_dir);
1392 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1393 free(internal_cfg->user_mbuf_pool_ops_name);
1399 eal_adjust_config(struct internal_config *internal_cfg)
1402 struct rte_config *cfg = rte_eal_get_configuration();
1405 eal_auto_detect_cores(cfg);
1407 if (internal_config.process_type == RTE_PROC_AUTO)
1408 internal_config.process_type = eal_proc_type_detect();
1410 /* default master lcore is the first one */
1411 if (!master_lcore_parsed) {
1412 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1413 if (cfg->master_lcore >= RTE_MAX_LCORE)
1415 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1418 compute_ctrl_threads_cpuset(internal_cfg);
1420 /* if no memory amounts were requested, this will result in 0 and
1421 * will be overridden later, right after eal_hugepage_info_init() */
1422 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1423 internal_cfg->memory += internal_cfg->socket_mem[i];
1429 eal_check_common_options(struct internal_config *internal_cfg)
1431 struct rte_config *cfg = rte_eal_get_configuration();
1433 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1434 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1438 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1439 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1442 if (internal_cfg->hugefile_prefix != NULL &&
1443 strlen(internal_cfg->hugefile_prefix) < 1) {
1444 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1447 if (internal_cfg->hugepage_dir != NULL &&
1448 strlen(internal_cfg->hugepage_dir) < 1) {
1449 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1452 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1453 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1454 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1457 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1458 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1462 if (mem_parsed && internal_cfg->force_sockets == 1) {
1463 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1464 "be specified at the same time\n");
1467 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1468 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1469 "be specified together with --"OPT_NO_HUGE"\n");
1472 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1473 !internal_cfg->in_memory) {
1474 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1475 "be specified together with --"OPT_NO_HUGE"\n");
1478 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1479 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1480 " is only supported in non-legacy memory mode\n");
1482 if (internal_cfg->single_file_segments &&
1483 internal_cfg->hugepage_unlink &&
1484 !internal_cfg->in_memory) {
1485 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1486 "not compatible with --"OPT_HUGE_UNLINK"\n");
1489 if (internal_cfg->legacy_mem &&
1490 internal_cfg->in_memory) {
1491 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1492 "with --"OPT_IN_MEMORY"\n");
1495 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1496 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1497 "with --"OPT_MATCH_ALLOCATIONS"\n");
1500 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1501 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1502 "with --"OPT_MATCH_ALLOCATIONS"\n");
1510 eal_common_usage(void)
1512 printf("[options]\n\n"
1513 "EAL common options:\n"
1514 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1515 " -l CORELIST List of cores to run on\n"
1516 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1517 " where c1, c2, etc are core indexes between 0 and %d\n"
1518 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1519 " The argument format is\n"
1520 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1521 " lcores and cpus list are grouped by '(' and ')'\n"
1522 " Within the group, '-' is used for range separator,\n"
1523 " ',' is used for single number separator.\n"
1524 " '( )' can be omitted for single element group,\n"
1525 " '@' can be omitted if cpus and lcores have the same value\n"
1526 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1527 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1528 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1529 " -n CHANNELS Number of memory channels\n"
1530 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1531 " -r RANKS Force number of memory ranks (don't detect)\n"
1532 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1533 " Prevent EAL from using this PCI device. The argument\n"
1534 " format is <domain:bus:devid.func>.\n"
1535 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1536 " Only use the specified PCI devices. The argument format\n"
1537 " is <[domain:]bus:devid.func>. This option can be present\n"
1538 " several times (once per device).\n"
1539 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1540 " --"OPT_VDEV" Add a virtual device.\n"
1541 " The argument format is <driver><id>[,key=val,...]\n"
1542 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1543 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1544 " 'va' for IOVA_VA\n"
1545 " -d LIB.so|DIR Add a driver or driver directory\n"
1546 " (can be used multiple times)\n"
1547 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1548 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1549 " --"OPT_SYSLOG" Set syslog facility\n"
1550 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1551 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1552 " Set specific log level\n"
1553 " -v Display version information on startup\n"
1554 " -h, --help This help\n"
1555 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1556 " disable secondary process support\n"
1557 "\nEAL options for DEBUG use only:\n"
1558 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1559 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1560 " --"OPT_NO_PCI" Disable PCI\n"
1561 " --"OPT_NO_HPET" Disable HPET\n"
1562 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1563 "\n", RTE_MAX_LCORE);