1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
9 #ifndef RTE_EXEC_ENV_WINDOWS
16 #ifndef RTE_EXEC_ENV_WINDOWS
19 #include <sys/types.h>
23 #include <rte_string_fns.h>
26 #include <rte_lcore.h>
27 #include <rte_memory.h>
28 #include <rte_tailq.h>
29 #include <rte_version.h>
30 #include <rte_devargs.h>
31 #include <rte_memcpy.h>
33 #include "eal_internal_cfg.h"
34 #include "eal_options.h"
35 #include "eal_filesystem.h"
36 #include "eal_private.h"
37 #include "eal_trace.h"
39 #define BITS_PER_HEX 4
40 #define LCORE_OPT_LST 1
41 #define LCORE_OPT_MSK 2
42 #define LCORE_OPT_MAP 3
46 "b:" /* pci-blacklist */
48 "s:" /* service coremask */
52 "S:" /* service corelist */
53 "m:" /* memory size */
54 "n:" /* memory channels */
55 "r:" /* memory ranks */
57 "w:" /* pci-whitelist */
61 eal_long_options[] = {
62 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM },
63 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM },
64 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM },
65 {OPT_HELP, 0, NULL, OPT_HELP_NUM },
66 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM },
67 {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM },
68 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
69 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
70 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
71 {OPT_TRACE, 1, NULL, OPT_TRACE_NUM },
72 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
73 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
74 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
75 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
76 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
77 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
78 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
79 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
80 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
81 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
82 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
83 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
84 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
85 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
86 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
87 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
88 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
89 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
90 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
94 TAILQ_HEAD(shared_driver_list, shared_driver);
96 /* Definition for shared object drivers. */
97 struct shared_driver {
98 TAILQ_ENTRY(shared_driver) next;
104 /* List of external loadable drivers */
105 static struct shared_driver_list solib_list =
106 TAILQ_HEAD_INITIALIZER(solib_list);
108 /* Default path of external loadable drivers */
109 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
112 * Stringified version of solib path used by dpdk-pmdinfo.py
113 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
114 * change to usertools/dpdk-pmdinfo.py
116 static const char dpdk_solib_path[] __rte_used =
117 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
119 TAILQ_HEAD(device_option_list, device_option);
121 struct device_option {
122 TAILQ_ENTRY(device_option) next;
124 enum rte_devtype type;
128 static struct device_option_list devopt_list =
129 TAILQ_HEAD_INITIALIZER(devopt_list);
131 static int master_lcore_parsed;
132 static int mem_parsed;
133 static int core_parsed;
136 eal_option_device_add(enum rte_devtype type, const char *optarg)
138 struct device_option *devopt;
142 optlen = strlen(optarg) + 1;
143 devopt = calloc(1, sizeof(*devopt) + optlen);
144 if (devopt == NULL) {
145 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
150 ret = strlcpy(devopt->arg, optarg, optlen);
152 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
156 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
161 eal_option_device_parse(void)
163 struct device_option *devopt;
167 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
169 ret = rte_devargs_add(devopt->type, devopt->arg);
171 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
174 TAILQ_REMOVE(&devopt_list, devopt, next);
181 eal_get_hugefile_prefix(void)
183 if (internal_config.hugefile_prefix != NULL)
184 return internal_config.hugefile_prefix;
185 return HUGEFILE_PREFIX_DEFAULT;
189 eal_reset_internal_config(struct internal_config *internal_cfg)
193 internal_cfg->memory = 0;
194 internal_cfg->force_nrank = 0;
195 internal_cfg->force_nchannel = 0;
196 internal_cfg->hugefile_prefix = NULL;
197 internal_cfg->hugepage_dir = NULL;
198 internal_cfg->force_sockets = 0;
199 /* zero out the NUMA config */
200 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
201 internal_cfg->socket_mem[i] = 0;
202 internal_cfg->force_socket_limits = 0;
203 /* zero out the NUMA limits config */
204 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
205 internal_cfg->socket_limit[i] = 0;
206 /* zero out hugedir descriptors */
207 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
208 memset(&internal_cfg->hugepage_info[i], 0,
209 sizeof(internal_cfg->hugepage_info[0]));
210 internal_cfg->hugepage_info[i].lock_descriptor = -1;
212 internal_cfg->base_virtaddr = 0;
215 internal_cfg->syslog_facility = LOG_DAEMON;
218 /* if set to NONE, interrupt mode is determined automatically */
219 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
221 #ifdef RTE_LIBEAL_USE_HPET
222 internal_cfg->no_hpet = 0;
224 internal_cfg->no_hpet = 1;
226 internal_cfg->vmware_tsc_map = 0;
227 internal_cfg->create_uio_dev = 0;
228 internal_cfg->iova_mode = RTE_IOVA_DC;
229 internal_cfg->user_mbuf_pool_ops_name = NULL;
230 CPU_ZERO(&internal_cfg->ctrl_cpuset);
231 internal_cfg->init_complete = 0;
235 eal_plugin_add(const char *path)
237 struct shared_driver *solib;
239 solib = malloc(sizeof(*solib));
241 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
244 memset(solib, 0, sizeof(*solib));
245 strlcpy(solib->name, path, PATH_MAX-1);
246 solib->name[PATH_MAX-1] = 0;
247 TAILQ_INSERT_TAIL(&solib_list, solib, next);
253 eal_plugindir_init(const char *path)
256 struct dirent *dent = NULL;
257 char sopath[PATH_MAX];
259 if (path == NULL || *path == '\0')
264 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
265 path, strerror(errno));
269 while ((dent = readdir(d)) != NULL) {
272 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
274 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
277 if (eal_plugin_add(sopath) == -1)
282 /* XXX this ignores failures from readdir() itself */
283 return (dent == NULL) ? 0 : -1;
287 eal_plugins_init(void)
289 #ifndef RTE_EXEC_ENV_WINDOWS
290 struct shared_driver *solib = NULL;
293 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
295 eal_plugin_add(default_solib_dir);
297 TAILQ_FOREACH(solib, &solib_list, next) {
299 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
300 if (eal_plugindir_init(solib->name) == -1) {
302 "Cannot init plugin directory %s\n",
307 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
309 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
310 if (solib->lib_handle == NULL) {
311 RTE_LOG(ERR, EAL, "%s\n", dlerror());
322 * Parse the coremask given as argument (hexadecimal string) and fill
323 * the global configuration (core role and core count) with the parsed
326 static int xdigit2val(unsigned char c)
340 eal_parse_service_coremask(const char *coremask)
342 struct rte_config *cfg = rte_eal_get_configuration();
344 unsigned int count = 0;
347 uint32_t taken_lcore_count = 0;
349 if (coremask == NULL)
351 /* Remove all blank characters ahead and after .
352 * Remove 0x/0X if exists.
354 while (isblank(*coremask))
356 if (coremask[0] == '0' && ((coremask[1] == 'x')
357 || (coremask[1] == 'X')))
359 i = strlen(coremask);
360 while ((i > 0) && isblank(coremask[i - 1]))
366 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
368 if (isxdigit(c) == 0) {
369 /* invalid characters */
373 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
375 if ((1 << j) & val) {
376 /* handle master lcore already parsed */
377 uint32_t lcore = idx;
378 if (master_lcore_parsed &&
379 cfg->master_lcore == lcore) {
381 "lcore %u is master lcore, cannot use as service core\n",
386 if (eal_cpu_detected(idx) == 0) {
388 "lcore %u unavailable\n", idx);
392 if (cfg->lcore_role[idx] == ROLE_RTE)
395 lcore_config[idx].core_role = ROLE_SERVICE;
402 if (coremask[i] != '0')
405 for (; idx < RTE_MAX_LCORE; idx++)
406 lcore_config[idx].core_index = -1;
411 if (core_parsed && taken_lcore_count != count) {
412 RTE_LOG(WARNING, EAL,
413 "Not all service cores are in the coremask. "
414 "Please ensure -c or -l includes service cores\n");
417 cfg->service_lcore_count = count;
422 eal_service_cores_parsed(void)
425 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
426 if (lcore_config[idx].core_role == ROLE_SERVICE)
433 update_lcore_config(int *cores)
435 struct rte_config *cfg = rte_eal_get_configuration();
436 unsigned int count = 0;
440 for (i = 0; i < RTE_MAX_LCORE; i++) {
441 if (cores[i] != -1) {
442 if (eal_cpu_detected(i) == 0) {
443 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
447 cfg->lcore_role[i] = ROLE_RTE;
450 cfg->lcore_role[i] = ROLE_OFF;
452 lcore_config[i].core_index = cores[i];
455 cfg->lcore_count = count;
460 eal_parse_coremask(const char *coremask, int *cores)
467 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
471 /* Remove all blank characters ahead and after .
472 * Remove 0x/0X if exists.
474 while (isblank(*coremask))
476 if (coremask[0] == '0' && ((coremask[1] == 'x')
477 || (coremask[1] == 'X')))
479 i = strlen(coremask);
480 while ((i > 0) && isblank(coremask[i - 1]))
485 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
487 if (isxdigit(c) == 0) {
488 /* invalid characters */
492 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
494 if ((1 << j) & val) {
501 if (coremask[i] != '0')
509 eal_parse_service_corelist(const char *corelist)
511 struct rte_config *cfg = rte_eal_get_configuration();
516 uint32_t taken_lcore_count = 0;
518 if (corelist == NULL)
521 /* Remove all blank characters ahead and after */
522 while (isblank(*corelist))
524 i = strlen(corelist);
525 while ((i > 0) && isblank(corelist[i - 1]))
528 /* Get list of cores */
531 while (isblank(*corelist))
533 if (*corelist == '\0')
536 idx = strtoul(corelist, &end, 10);
537 if (errno || end == NULL)
539 while (isblank(*end))
543 } else if ((*end == ',') || (*end == '\0')) {
545 if (min == RTE_MAX_LCORE)
547 for (idx = min; idx <= max; idx++) {
548 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
549 /* handle master lcore already parsed */
550 uint32_t lcore = idx;
551 if (cfg->master_lcore == lcore &&
552 master_lcore_parsed) {
554 "Error: lcore %u is master lcore, cannot use as service core\n",
558 if (cfg->lcore_role[idx] == ROLE_RTE)
561 lcore_config[idx].core_role =
570 } while (*end != '\0');
575 if (core_parsed && taken_lcore_count != count) {
576 RTE_LOG(WARNING, EAL,
577 "Not all service cores were in the coremask. "
578 "Please ensure -c or -l includes service cores\n");
585 eal_parse_corelist(const char *corelist, int *cores)
592 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
595 /* Remove all blank characters ahead */
596 while (isblank(*corelist))
599 /* Get list of cores */
602 while (isblank(*corelist))
604 if (*corelist == '\0')
607 idx = strtol(corelist, &end, 10);
608 if (errno || end == NULL)
610 if (idx < 0 || idx >= RTE_MAX_LCORE)
612 while (isblank(*end))
616 } else if ((*end == ',') || (*end == '\0')) {
618 if (min == RTE_MAX_LCORE)
620 for (idx = min; idx <= max; idx++) {
621 if (cores[idx] == -1) {
630 } while (*end != '\0');
637 /* Changes the lcore id of the master thread */
639 eal_parse_master_lcore(const char *arg)
642 struct rte_config *cfg = rte_eal_get_configuration();
645 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
646 if (errno || parsing_end[0] != 0)
648 if (cfg->master_lcore >= RTE_MAX_LCORE)
650 master_lcore_parsed = 1;
652 /* ensure master core is not used as service core */
653 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
655 "Error: Master lcore is used as a service core\n");
663 * Parse elem, the elem could be single number/range or '(' ')' group
664 * 1) A single number elem, it's just a simple digit. e.g. 9
665 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
666 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
667 * Within group elem, '-' used for a range separator;
668 * ',' used for a single number.
671 eal_parse_set(const char *input, rte_cpuset_t *set)
674 const char *str = input;
680 while (isblank(*str))
683 /* only digit or left bracket is qualify for start point */
684 if ((!isdigit(*str) && *str != '(') || *str == '\0')
687 /* process single number or single range of number */
690 idx = strtoul(str, &end, 10);
691 if (errno || end == NULL || idx >= CPU_SETSIZE)
694 while (isblank(*end))
700 /* process single <number>-<number> */
702 while (isblank(*end))
708 idx = strtoul(end, &end, 10);
709 if (errno || end == NULL || idx >= CPU_SETSIZE)
712 while (isblank(*end))
714 if (*end != ',' && *end != '\0')
718 if (*end != ',' && *end != '\0' &&
722 for (idx = RTE_MIN(min, max);
723 idx <= RTE_MAX(min, max); idx++)
730 /* process set within bracket */
732 while (isblank(*str))
740 /* go ahead to the first digit */
741 while (isblank(*str))
746 /* get the digit value */
748 idx = strtoul(str, &end, 10);
749 if (errno || end == NULL || idx >= CPU_SETSIZE)
752 /* go ahead to separator '-',',' and ')' */
753 while (isblank(*end))
756 if (min == RTE_MAX_LCORE)
758 else /* avoid continuous '-' */
760 } else if ((*end == ',') || (*end == ')')) {
762 if (min == RTE_MAX_LCORE)
764 for (idx = RTE_MIN(min, max);
765 idx <= RTE_MAX(min, max); idx++)
773 } while (*end != '\0' && *end != ')');
776 * to avoid failure that tail blank makes end character check fail
777 * in eal_parse_lcores( )
779 while (isblank(*str))
786 check_cpuset(rte_cpuset_t *set)
790 for (idx = 0; idx < CPU_SETSIZE; idx++) {
791 if (!CPU_ISSET(idx, set))
794 if (eal_cpu_detected(idx) == 0) {
795 RTE_LOG(ERR, EAL, "core %u "
796 "unavailable\n", idx);
804 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
805 * lcores, cpus could be a single digit/range or a group.
806 * '(' and ')' are necessary if it's a group.
807 * If not supply '@cpus', the value of cpus uses the same as lcores.
808 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
809 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
810 * lcore 1 runs on cpuset 0x2 (cpu 1)
811 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
812 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
813 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
814 * lcore 7 runs on cpuset 0x80 (cpu 7)
815 * lcore 8 runs on cpuset 0x100 (cpu 8)
818 eal_parse_lcores(const char *lcores)
820 struct rte_config *cfg = rte_eal_get_configuration();
821 rte_cpuset_t lcore_set;
822 unsigned int set_count;
825 const char *lcore_start = NULL;
826 const char *end = NULL;
835 /* Remove all blank characters ahead and after */
836 while (isblank(*lcores))
841 /* Reset lcore config */
842 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
843 cfg->lcore_role[idx] = ROLE_OFF;
844 lcore_config[idx].core_index = -1;
845 CPU_ZERO(&lcore_config[idx].cpuset);
848 /* Get list of cores */
850 while (isblank(*lcores))
857 /* record lcore_set start point */
858 lcore_start = lcores;
860 /* go across a complete bracket */
861 if (*lcore_start == '(') {
862 lcores += strcspn(lcores, ")");
863 if (*lcores++ == '\0')
867 /* scan the separator '@', ','(next) or '\0'(finish) */
868 lcores += strcspn(lcores, "@,");
870 if (*lcores == '@') {
871 /* explicit assign cpuset and update the end cursor */
872 offset = eal_parse_set(lcores + 1, &cpuset);
875 end = lcores + 1 + offset;
876 } else { /* ',' or '\0' */
877 /* haven't given cpuset, 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 (eal_parse_set(lcore_start, &lcore_set) < 0)
894 /* without '@', by default using lcore_set as cpuset */
896 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
898 set_count = CPU_COUNT(&lcore_set);
899 /* start to update lcore_set */
900 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
901 if (!CPU_ISSET(idx, &lcore_set))
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);
916 if (check_cpuset(&cpuset) < 0)
918 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
919 sizeof(rte_cpuset_t));
922 /* some cores from the lcore_set can't be handled by EAL */
927 } while (*end != '\0');
932 cfg->lcore_count = count;
940 #ifndef RTE_EXEC_ENV_WINDOWS
942 eal_parse_syslog(const char *facility, struct internal_config *conf)
945 static const struct {
949 { "auth", LOG_AUTH },
950 { "cron", LOG_CRON },
951 { "daemon", LOG_DAEMON },
953 { "kern", LOG_KERN },
955 { "mail", LOG_MAIL },
956 { "news", LOG_NEWS },
957 { "syslog", LOG_SYSLOG },
958 { "user", LOG_USER },
959 { "uucp", LOG_UUCP },
960 { "local0", LOG_LOCAL0 },
961 { "local1", LOG_LOCAL1 },
962 { "local2", LOG_LOCAL2 },
963 { "local3", LOG_LOCAL3 },
964 { "local4", LOG_LOCAL4 },
965 { "local5", LOG_LOCAL5 },
966 { "local6", LOG_LOCAL6 },
967 { "local7", LOG_LOCAL7 },
971 for (i = 0; map[i].name; i++) {
972 if (!strcmp(facility, map[i].name)) {
973 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_base_virtaddr(const char *arg)
1115 addr = strtoull(arg, &end, 16);
1117 /* check for errors */
1118 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1121 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1123 if (addr >= UINTPTR_MAX)
1127 /* align the addr on 16M boundary, 16MB is the minimum huge page
1128 * size on IBM Power architecture. If the addr is aligned to 16MB,
1129 * it can align to 2MB for x86. So this alignment can also be used
1130 * on x86 and other architectures.
1132 internal_config.base_virtaddr =
1133 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1138 /* caller is responsible for freeing the returned string */
1140 available_cores(void)
1148 /* find the first available cpu */
1149 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1150 if (eal_cpu_detected(idx) == 0)
1154 if (idx >= RTE_MAX_LCORE)
1157 /* first sequence */
1158 if (asprintf(&str, "%d", idx) < 0)
1163 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1164 if (eal_cpu_detected(idx) == 0)
1167 if (idx == previous + 1) {
1173 /* finish current sequence */
1175 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1184 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1194 /* finish last sequence */
1196 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1208 eal_parse_common_option(int opt, const char *optarg,
1209 struct internal_config *conf)
1219 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1229 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1237 int lcore_indexes[RTE_MAX_LCORE];
1239 if (eal_service_cores_parsed())
1240 RTE_LOG(WARNING, EAL,
1241 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1242 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1243 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1246 if (update_lcore_config(lcore_indexes) < 0) {
1247 char *available = available_cores();
1250 "invalid coremask, please check specified cores are part of %s\n",
1257 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1258 (core_parsed == LCORE_OPT_LST) ? "-l" :
1259 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1264 core_parsed = LCORE_OPT_MSK;
1269 int lcore_indexes[RTE_MAX_LCORE];
1271 if (eal_service_cores_parsed())
1272 RTE_LOG(WARNING, EAL,
1273 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1275 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1276 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1279 if (update_lcore_config(lcore_indexes) < 0) {
1280 char *available = available_cores();
1283 "invalid core list, please check specified cores are part of %s\n",
1290 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1291 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1292 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1297 core_parsed = LCORE_OPT_LST;
1300 /* service coremask */
1302 if (eal_parse_service_coremask(optarg) < 0) {
1303 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1307 /* service corelist */
1309 if (eal_parse_service_corelist(optarg) < 0) {
1310 RTE_LOG(ERR, EAL, "invalid service core list\n");
1314 /* size of memory */
1316 conf->memory = atoi(optarg);
1317 conf->memory *= 1024ULL;
1318 conf->memory *= 1024ULL;
1321 /* force number of channels */
1323 conf->force_nchannel = atoi(optarg);
1324 if (conf->force_nchannel == 0) {
1325 RTE_LOG(ERR, EAL, "invalid channel number\n");
1329 /* force number of ranks */
1331 conf->force_nrank = atoi(optarg);
1332 if (conf->force_nrank == 0 ||
1333 conf->force_nrank > 16) {
1334 RTE_LOG(ERR, EAL, "invalid rank number\n");
1338 /* force loading of external driver */
1340 if (eal_plugin_add(optarg) == -1)
1344 /* since message is explicitly requested by user, we
1345 * write message at highest log level so it can always
1347 * even if info or warning messages are disabled */
1348 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1352 case OPT_HUGE_UNLINK_NUM:
1353 conf->hugepage_unlink = 1;
1356 case OPT_NO_HUGE_NUM:
1357 conf->no_hugetlbfs = 1;
1358 /* no-huge is legacy mem */
1359 conf->legacy_mem = 1;
1362 case OPT_NO_PCI_NUM:
1366 case OPT_NO_HPET_NUM:
1370 case OPT_VMWARE_TSC_MAP_NUM:
1371 conf->vmware_tsc_map = 1;
1374 case OPT_NO_SHCONF_NUM:
1375 conf->no_shconf = 1;
1378 case OPT_IN_MEMORY_NUM:
1379 conf->in_memory = 1;
1380 /* in-memory is a superset of noshconf and huge-unlink */
1381 conf->no_shconf = 1;
1382 conf->hugepage_unlink = 1;
1385 case OPT_PROC_TYPE_NUM:
1386 conf->process_type = eal_parse_proc_type(optarg);
1389 case OPT_MASTER_LCORE_NUM:
1390 if (eal_parse_master_lcore(optarg) < 0) {
1391 RTE_LOG(ERR, EAL, "invalid parameter for --"
1392 OPT_MASTER_LCORE "\n");
1398 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1404 #ifndef RTE_EXEC_ENV_WINDOWS
1405 case OPT_SYSLOG_NUM:
1406 if (eal_parse_syslog(optarg, conf) < 0) {
1407 RTE_LOG(ERR, EAL, "invalid parameters for --"
1414 case OPT_LOG_LEVEL_NUM: {
1415 if (eal_parse_log_level(optarg) < 0) {
1417 "invalid parameters for --"
1418 OPT_LOG_LEVEL "\n");
1424 case OPT_TRACE_NUM: {
1425 if (eal_trace_args_save(optarg) < 0) {
1426 RTE_LOG(ERR, EAL, "invalid parameters for --"
1433 case OPT_LCORES_NUM:
1434 if (eal_parse_lcores(optarg) < 0) {
1435 RTE_LOG(ERR, EAL, "invalid parameter for --"
1441 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1442 (core_parsed == LCORE_OPT_LST) ? "-l" :
1443 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1448 core_parsed = LCORE_OPT_MAP;
1450 case OPT_LEGACY_MEM_NUM:
1451 conf->legacy_mem = 1;
1453 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1454 conf->single_file_segments = 1;
1456 case OPT_IOVA_MODE_NUM:
1457 if (eal_parse_iova_mode(optarg) < 0) {
1458 RTE_LOG(ERR, EAL, "invalid parameters for --"
1459 OPT_IOVA_MODE "\n");
1463 case OPT_BASE_VIRTADDR_NUM:
1464 if (eal_parse_base_virtaddr(optarg) < 0) {
1465 RTE_LOG(ERR, EAL, "invalid parameter for --"
1466 OPT_BASE_VIRTADDR "\n");
1471 /* don't know what to do, leave this to caller */
1479 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1480 "cannot be used at the same time\n");
1485 eal_auto_detect_cores(struct rte_config *cfg)
1487 unsigned int lcore_id;
1488 unsigned int removed = 0;
1489 rte_cpuset_t affinity_set;
1491 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1493 CPU_ZERO(&affinity_set);
1495 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1496 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1497 !CPU_ISSET(lcore_id, &affinity_set)) {
1498 cfg->lcore_role[lcore_id] = ROLE_OFF;
1503 cfg->lcore_count -= removed;
1507 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1509 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1510 rte_cpuset_t default_set;
1511 unsigned int lcore_id;
1513 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1514 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1516 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1518 RTE_CPU_NOT(cpuset, cpuset);
1520 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1522 CPU_ZERO(&default_set);
1524 RTE_CPU_AND(cpuset, cpuset, &default_set);
1526 /* if no remaining cpu, use master lcore cpu affinity */
1527 if (!CPU_COUNT(cpuset)) {
1528 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1534 eal_cleanup_config(struct internal_config *internal_cfg)
1536 if (internal_cfg->hugefile_prefix != NULL)
1537 free(internal_cfg->hugefile_prefix);
1538 if (internal_cfg->hugepage_dir != NULL)
1539 free(internal_cfg->hugepage_dir);
1540 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1541 free(internal_cfg->user_mbuf_pool_ops_name);
1547 eal_adjust_config(struct internal_config *internal_cfg)
1550 struct rte_config *cfg = rte_eal_get_configuration();
1553 eal_auto_detect_cores(cfg);
1555 if (internal_config.process_type == RTE_PROC_AUTO)
1556 internal_config.process_type = eal_proc_type_detect();
1558 /* default master lcore is the first one */
1559 if (!master_lcore_parsed) {
1560 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1561 if (cfg->master_lcore >= RTE_MAX_LCORE)
1563 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1566 compute_ctrl_threads_cpuset(internal_cfg);
1568 /* if no memory amounts were requested, this will result in 0 and
1569 * will be overridden later, right after eal_hugepage_info_init() */
1570 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1571 internal_cfg->memory += internal_cfg->socket_mem[i];
1577 eal_check_common_options(struct internal_config *internal_cfg)
1579 struct rte_config *cfg = rte_eal_get_configuration();
1581 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1582 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1586 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1587 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1590 if (internal_cfg->hugefile_prefix != NULL &&
1591 strlen(internal_cfg->hugefile_prefix) < 1) {
1592 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1595 if (internal_cfg->hugepage_dir != NULL &&
1596 strlen(internal_cfg->hugepage_dir) < 1) {
1597 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1600 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1601 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1602 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1605 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1606 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1610 if (mem_parsed && internal_cfg->force_sockets == 1) {
1611 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1612 "be specified at the same time\n");
1615 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1616 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1617 "be specified together with --"OPT_NO_HUGE"\n");
1620 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1621 !internal_cfg->in_memory) {
1622 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1623 "be specified together with --"OPT_NO_HUGE"\n");
1626 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1627 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1628 " is only supported in non-legacy memory mode\n");
1630 if (internal_cfg->single_file_segments &&
1631 internal_cfg->hugepage_unlink &&
1632 !internal_cfg->in_memory) {
1633 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1634 "not compatible with --"OPT_HUGE_UNLINK"\n");
1637 if (internal_cfg->legacy_mem &&
1638 internal_cfg->in_memory) {
1639 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1640 "with --"OPT_IN_MEMORY"\n");
1643 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1644 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1645 "with --"OPT_MATCH_ALLOCATIONS"\n");
1648 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1649 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1650 "with --"OPT_MATCH_ALLOCATIONS"\n");
1653 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1654 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1655 "amount of reserved memory can be adjusted with "
1656 "-m or --"OPT_SOCKET_MEM"\n");
1663 eal_common_usage(void)
1665 printf("[options]\n\n"
1666 "EAL common options:\n"
1667 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1668 " -l CORELIST List of cores to run on\n"
1669 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1670 " where c1, c2, etc are core indexes between 0 and %d\n"
1671 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1672 " The argument format is\n"
1673 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1674 " lcores and cpus list are grouped by '(' and ')'\n"
1675 " Within the group, '-' is used for range separator,\n"
1676 " ',' is used for single number separator.\n"
1677 " '( )' can be omitted for single element group,\n"
1678 " '@' can be omitted if cpus and lcores have the same value\n"
1679 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1680 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1681 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1682 " -n CHANNELS Number of memory channels\n"
1683 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1684 " -r RANKS Force number of memory ranks (don't detect)\n"
1685 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1686 " Prevent EAL from using this PCI device. The argument\n"
1687 " format is <domain:bus:devid.func>.\n"
1688 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1689 " Only use the specified PCI devices. The argument format\n"
1690 " is <[domain:]bus:devid.func>. This option can be present\n"
1691 " several times (once per device).\n"
1692 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1693 " --"OPT_VDEV" Add a virtual device.\n"
1694 " The argument format is <driver><id>[,key=val,...]\n"
1695 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1696 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1697 " 'va' for IOVA_VA\n"
1698 " -d LIB.so|DIR Add a driver or driver directory\n"
1699 " (can be used multiple times)\n"
1700 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1701 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1702 #ifndef RTE_EXEC_ENV_WINDOWS
1703 " --"OPT_SYSLOG" Set syslog facility\n"
1705 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1706 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1707 " Set specific log level\n"
1708 " --"OPT_TRACE"=<regex-match>\n"
1709 " Enable trace based on regular expression trace name.\n"
1710 " By default, the trace is disabled.\n"
1711 " User must specify this option to enable trace.\n"
1712 " -v Display version information on startup\n"
1713 " -h, --help This help\n"
1714 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1715 " disable secondary process support\n"
1716 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
1717 "\nEAL options for DEBUG use only:\n"
1718 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1719 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1720 " --"OPT_NO_PCI" Disable PCI\n"
1721 " --"OPT_NO_HPET" Disable HPET\n"
1722 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1723 "\n", RTE_MAX_LCORE);