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_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM },
73 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
74 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
75 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
76 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
77 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
78 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
79 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
80 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
81 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
82 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
83 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
84 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
85 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
86 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
87 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
88 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
89 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
90 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
91 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
95 TAILQ_HEAD(shared_driver_list, shared_driver);
97 /* Definition for shared object drivers. */
98 struct shared_driver {
99 TAILQ_ENTRY(shared_driver) next;
105 /* List of external loadable drivers */
106 static struct shared_driver_list solib_list =
107 TAILQ_HEAD_INITIALIZER(solib_list);
109 /* Default path of external loadable drivers */
110 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
113 * Stringified version of solib path used by dpdk-pmdinfo.py
114 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
115 * change to usertools/dpdk-pmdinfo.py
117 static const char dpdk_solib_path[] __rte_used =
118 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
120 TAILQ_HEAD(device_option_list, device_option);
122 struct device_option {
123 TAILQ_ENTRY(device_option) next;
125 enum rte_devtype type;
129 static struct device_option_list devopt_list =
130 TAILQ_HEAD_INITIALIZER(devopt_list);
132 static int master_lcore_parsed;
133 static int mem_parsed;
134 static int core_parsed;
137 eal_option_device_add(enum rte_devtype type, const char *optarg)
139 struct device_option *devopt;
143 optlen = strlen(optarg) + 1;
144 devopt = calloc(1, sizeof(*devopt) + optlen);
145 if (devopt == NULL) {
146 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
151 ret = strlcpy(devopt->arg, optarg, optlen);
153 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
157 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
162 eal_option_device_parse(void)
164 struct device_option *devopt;
168 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
170 ret = rte_devargs_add(devopt->type, devopt->arg);
172 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
175 TAILQ_REMOVE(&devopt_list, devopt, next);
182 eal_get_hugefile_prefix(void)
184 if (internal_config.hugefile_prefix != NULL)
185 return internal_config.hugefile_prefix;
186 return HUGEFILE_PREFIX_DEFAULT;
190 eal_reset_internal_config(struct internal_config *internal_cfg)
194 internal_cfg->memory = 0;
195 internal_cfg->force_nrank = 0;
196 internal_cfg->force_nchannel = 0;
197 internal_cfg->hugefile_prefix = NULL;
198 internal_cfg->hugepage_dir = NULL;
199 internal_cfg->force_sockets = 0;
200 /* zero out the NUMA config */
201 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
202 internal_cfg->socket_mem[i] = 0;
203 internal_cfg->force_socket_limits = 0;
204 /* zero out the NUMA limits config */
205 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
206 internal_cfg->socket_limit[i] = 0;
207 /* zero out hugedir descriptors */
208 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
209 memset(&internal_cfg->hugepage_info[i], 0,
210 sizeof(internal_cfg->hugepage_info[0]));
211 internal_cfg->hugepage_info[i].lock_descriptor = -1;
213 internal_cfg->base_virtaddr = 0;
216 internal_cfg->syslog_facility = LOG_DAEMON;
219 /* if set to NONE, interrupt mode is determined automatically */
220 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
222 #ifdef RTE_LIBEAL_USE_HPET
223 internal_cfg->no_hpet = 0;
225 internal_cfg->no_hpet = 1;
227 internal_cfg->vmware_tsc_map = 0;
228 internal_cfg->create_uio_dev = 0;
229 internal_cfg->iova_mode = RTE_IOVA_DC;
230 internal_cfg->user_mbuf_pool_ops_name = NULL;
231 CPU_ZERO(&internal_cfg->ctrl_cpuset);
232 internal_cfg->init_complete = 0;
236 eal_plugin_add(const char *path)
238 struct shared_driver *solib;
240 solib = malloc(sizeof(*solib));
242 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
245 memset(solib, 0, sizeof(*solib));
246 strlcpy(solib->name, path, PATH_MAX-1);
247 solib->name[PATH_MAX-1] = 0;
248 TAILQ_INSERT_TAIL(&solib_list, solib, next);
254 eal_plugindir_init(const char *path)
257 struct dirent *dent = NULL;
258 char sopath[PATH_MAX];
260 if (path == NULL || *path == '\0')
265 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
266 path, strerror(errno));
270 while ((dent = readdir(d)) != NULL) {
273 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
275 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
278 if (eal_plugin_add(sopath) == -1)
283 /* XXX this ignores failures from readdir() itself */
284 return (dent == NULL) ? 0 : -1;
288 eal_plugins_init(void)
290 #ifndef RTE_EXEC_ENV_WINDOWS
291 struct shared_driver *solib = NULL;
294 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
296 eal_plugin_add(default_solib_dir);
298 TAILQ_FOREACH(solib, &solib_list, next) {
300 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
301 if (eal_plugindir_init(solib->name) == -1) {
303 "Cannot init plugin directory %s\n",
308 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
310 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
311 if (solib->lib_handle == NULL) {
312 RTE_LOG(ERR, EAL, "%s\n", dlerror());
323 * Parse the coremask given as argument (hexadecimal string) and fill
324 * the global configuration (core role and core count) with the parsed
327 static int xdigit2val(unsigned char c)
341 eal_parse_service_coremask(const char *coremask)
343 struct rte_config *cfg = rte_eal_get_configuration();
345 unsigned int count = 0;
348 uint32_t taken_lcore_count = 0;
350 if (coremask == NULL)
352 /* Remove all blank characters ahead and after .
353 * Remove 0x/0X if exists.
355 while (isblank(*coremask))
357 if (coremask[0] == '0' && ((coremask[1] == 'x')
358 || (coremask[1] == 'X')))
360 i = strlen(coremask);
361 while ((i > 0) && isblank(coremask[i - 1]))
367 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
369 if (isxdigit(c) == 0) {
370 /* invalid characters */
374 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
376 if ((1 << j) & val) {
377 /* handle master lcore already parsed */
378 uint32_t lcore = idx;
379 if (master_lcore_parsed &&
380 cfg->master_lcore == lcore) {
382 "lcore %u is master lcore, cannot use as service core\n",
387 if (eal_cpu_detected(idx) == 0) {
389 "lcore %u unavailable\n", idx);
393 if (cfg->lcore_role[idx] == ROLE_RTE)
396 lcore_config[idx].core_role = ROLE_SERVICE;
403 if (coremask[i] != '0')
406 for (; idx < RTE_MAX_LCORE; idx++)
407 lcore_config[idx].core_index = -1;
412 if (core_parsed && taken_lcore_count != count) {
413 RTE_LOG(WARNING, EAL,
414 "Not all service cores are in the coremask. "
415 "Please ensure -c or -l includes service cores\n");
418 cfg->service_lcore_count = count;
423 eal_service_cores_parsed(void)
426 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
427 if (lcore_config[idx].core_role == ROLE_SERVICE)
434 update_lcore_config(int *cores)
436 struct rte_config *cfg = rte_eal_get_configuration();
437 unsigned int count = 0;
441 for (i = 0; i < RTE_MAX_LCORE; i++) {
442 if (cores[i] != -1) {
443 if (eal_cpu_detected(i) == 0) {
444 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
448 cfg->lcore_role[i] = ROLE_RTE;
451 cfg->lcore_role[i] = ROLE_OFF;
453 lcore_config[i].core_index = cores[i];
456 cfg->lcore_count = count;
461 eal_parse_coremask(const char *coremask, int *cores)
468 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
472 /* Remove all blank characters ahead and after .
473 * Remove 0x/0X if exists.
475 while (isblank(*coremask))
477 if (coremask[0] == '0' && ((coremask[1] == 'x')
478 || (coremask[1] == 'X')))
480 i = strlen(coremask);
481 while ((i > 0) && isblank(coremask[i - 1]))
486 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
488 if (isxdigit(c) == 0) {
489 /* invalid characters */
493 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
495 if ((1 << j) & val) {
502 if (coremask[i] != '0')
510 eal_parse_service_corelist(const char *corelist)
512 struct rte_config *cfg = rte_eal_get_configuration();
517 uint32_t taken_lcore_count = 0;
519 if (corelist == NULL)
522 /* Remove all blank characters ahead and after */
523 while (isblank(*corelist))
525 i = strlen(corelist);
526 while ((i > 0) && isblank(corelist[i - 1]))
529 /* Get list of cores */
532 while (isblank(*corelist))
534 if (*corelist == '\0')
537 idx = strtoul(corelist, &end, 10);
538 if (errno || end == NULL)
540 while (isblank(*end))
544 } else if ((*end == ',') || (*end == '\0')) {
546 if (min == RTE_MAX_LCORE)
548 for (idx = min; idx <= max; idx++) {
549 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
550 /* handle master lcore already parsed */
551 uint32_t lcore = idx;
552 if (cfg->master_lcore == lcore &&
553 master_lcore_parsed) {
555 "Error: lcore %u is master lcore, cannot use as service core\n",
559 if (cfg->lcore_role[idx] == ROLE_RTE)
562 lcore_config[idx].core_role =
571 } while (*end != '\0');
576 if (core_parsed && taken_lcore_count != count) {
577 RTE_LOG(WARNING, EAL,
578 "Not all service cores were in the coremask. "
579 "Please ensure -c or -l includes service cores\n");
586 eal_parse_corelist(const char *corelist, int *cores)
593 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
596 /* Remove all blank characters ahead */
597 while (isblank(*corelist))
600 /* Get list of cores */
603 while (isblank(*corelist))
605 if (*corelist == '\0')
608 idx = strtol(corelist, &end, 10);
609 if (errno || end == NULL)
611 if (idx < 0 || idx >= RTE_MAX_LCORE)
613 while (isblank(*end))
617 } else if ((*end == ',') || (*end == '\0')) {
619 if (min == RTE_MAX_LCORE)
621 for (idx = min; idx <= max; idx++) {
622 if (cores[idx] == -1) {
631 } while (*end != '\0');
638 /* Changes the lcore id of the master thread */
640 eal_parse_master_lcore(const char *arg)
643 struct rte_config *cfg = rte_eal_get_configuration();
646 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
647 if (errno || parsing_end[0] != 0)
649 if (cfg->master_lcore >= RTE_MAX_LCORE)
651 master_lcore_parsed = 1;
653 /* ensure master core is not used as service core */
654 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
656 "Error: Master lcore is used as a service core\n");
664 * Parse elem, the elem could be single number/range or '(' ')' group
665 * 1) A single number elem, it's just a simple digit. e.g. 9
666 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
667 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
668 * Within group elem, '-' used for a range separator;
669 * ',' used for a single number.
672 eal_parse_set(const char *input, rte_cpuset_t *set)
675 const char *str = input;
681 while (isblank(*str))
684 /* only digit or left bracket is qualify for start point */
685 if ((!isdigit(*str) && *str != '(') || *str == '\0')
688 /* process single number or single range of number */
691 idx = strtoul(str, &end, 10);
692 if (errno || end == NULL || idx >= CPU_SETSIZE)
695 while (isblank(*end))
701 /* process single <number>-<number> */
703 while (isblank(*end))
709 idx = strtoul(end, &end, 10);
710 if (errno || end == NULL || idx >= CPU_SETSIZE)
713 while (isblank(*end))
715 if (*end != ',' && *end != '\0')
719 if (*end != ',' && *end != '\0' &&
723 for (idx = RTE_MIN(min, max);
724 idx <= RTE_MAX(min, max); idx++)
731 /* process set within bracket */
733 while (isblank(*str))
741 /* go ahead to the first digit */
742 while (isblank(*str))
747 /* get the digit value */
749 idx = strtoul(str, &end, 10);
750 if (errno || end == NULL || idx >= CPU_SETSIZE)
753 /* go ahead to separator '-',',' and ')' */
754 while (isblank(*end))
757 if (min == RTE_MAX_LCORE)
759 else /* avoid continuous '-' */
761 } else if ((*end == ',') || (*end == ')')) {
763 if (min == RTE_MAX_LCORE)
765 for (idx = RTE_MIN(min, max);
766 idx <= RTE_MAX(min, max); idx++)
774 } while (*end != '\0' && *end != ')');
777 * to avoid failure that tail blank makes end character check fail
778 * in eal_parse_lcores( )
780 while (isblank(*str))
787 check_cpuset(rte_cpuset_t *set)
791 for (idx = 0; idx < CPU_SETSIZE; idx++) {
792 if (!CPU_ISSET(idx, set))
795 if (eal_cpu_detected(idx) == 0) {
796 RTE_LOG(ERR, EAL, "core %u "
797 "unavailable\n", idx);
805 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
806 * lcores, cpus could be a single digit/range or a group.
807 * '(' and ')' are necessary if it's a group.
808 * If not supply '@cpus', the value of cpus uses the same as lcores.
809 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
810 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
811 * lcore 1 runs on cpuset 0x2 (cpu 1)
812 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
813 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
814 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
815 * lcore 7 runs on cpuset 0x80 (cpu 7)
816 * lcore 8 runs on cpuset 0x100 (cpu 8)
819 eal_parse_lcores(const char *lcores)
821 struct rte_config *cfg = rte_eal_get_configuration();
822 rte_cpuset_t lcore_set;
823 unsigned int set_count;
826 const char *lcore_start = NULL;
827 const char *end = NULL;
836 /* Remove all blank characters ahead and after */
837 while (isblank(*lcores))
842 /* Reset lcore config */
843 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
844 cfg->lcore_role[idx] = ROLE_OFF;
845 lcore_config[idx].core_index = -1;
846 CPU_ZERO(&lcore_config[idx].cpuset);
849 /* Get list of cores */
851 while (isblank(*lcores))
858 /* record lcore_set start point */
859 lcore_start = lcores;
861 /* go across a complete bracket */
862 if (*lcore_start == '(') {
863 lcores += strcspn(lcores, ")");
864 if (*lcores++ == '\0')
868 /* scan the separator '@', ','(next) or '\0'(finish) */
869 lcores += strcspn(lcores, "@,");
871 if (*lcores == '@') {
872 /* explicit assign cpuset and update the end cursor */
873 offset = eal_parse_set(lcores + 1, &cpuset);
876 end = lcores + 1 + offset;
877 } else { /* ',' or '\0' */
878 /* haven't given cpuset, current loop done */
881 /* go back to check <number>-<number> */
882 offset = strcspn(lcore_start, "(-");
883 if (offset < (end - lcore_start) &&
884 *(lcore_start + offset) != '(')
888 if (*end != ',' && *end != '\0')
891 /* parse lcore_set from start point */
892 if (eal_parse_set(lcore_start, &lcore_set) < 0)
895 /* without '@', by default using lcore_set as cpuset */
897 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
899 set_count = CPU_COUNT(&lcore_set);
900 /* start to update lcore_set */
901 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
902 if (!CPU_ISSET(idx, &lcore_set))
906 if (cfg->lcore_role[idx] != ROLE_RTE) {
907 lcore_config[idx].core_index = count;
908 cfg->lcore_role[idx] = ROLE_RTE;
914 CPU_SET(idx, &cpuset);
917 if (check_cpuset(&cpuset) < 0)
919 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
920 sizeof(rte_cpuset_t));
923 /* some cores from the lcore_set can't be handled by EAL */
928 } while (*end != '\0');
933 cfg->lcore_count = count;
941 #ifndef RTE_EXEC_ENV_WINDOWS
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;
983 eal_parse_log_priority(const char *level)
985 static const char * const levels[] = {
986 [RTE_LOG_EMERG] = "emergency",
987 [RTE_LOG_ALERT] = "alert",
988 [RTE_LOG_CRIT] = "critical",
989 [RTE_LOG_ERR] = "error",
990 [RTE_LOG_WARNING] = "warning",
991 [RTE_LOG_NOTICE] = "notice",
992 [RTE_LOG_INFO] = "info",
993 [RTE_LOG_DEBUG] = "debug",
995 size_t len = strlen(level);
1003 /* look for named values, skip 0 which is not a valid level */
1004 for (i = 1; i < RTE_DIM(levels); i++) {
1005 if (strncmp(levels[i], level, len) == 0)
1009 /* not a string, maybe it is numeric */
1011 tmp = strtoul(level, &end, 0);
1013 /* check for errors */
1014 if (errno != 0 || end == NULL || *end != '\0' ||
1022 eal_parse_log_level(const char *arg)
1024 const char *pattern = NULL;
1025 const char *regex = NULL;
1033 if ((level = strchr(str, ','))) {
1036 } else if ((level = strchr(str, ':'))) {
1043 priority = eal_parse_log_priority(level);
1045 fprintf(stderr, "invalid log priority: %s\n", level);
1050 if (rte_log_set_level_regexp(regex, priority) < 0) {
1051 fprintf(stderr, "cannot set log level %s,%d\n",
1055 if (rte_log_save_regexp(regex, priority) < 0)
1057 } else if (pattern) {
1058 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1059 fprintf(stderr, "cannot set log level %s:%d\n",
1063 if (rte_log_save_pattern(pattern, priority) < 0)
1066 rte_log_set_global_level(priority);
1077 static enum rte_proc_type_t
1078 eal_parse_proc_type(const char *arg)
1080 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1081 return RTE_PROC_PRIMARY;
1082 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1083 return RTE_PROC_SECONDARY;
1084 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1085 return RTE_PROC_AUTO;
1087 return RTE_PROC_INVALID;
1091 eal_parse_iova_mode(const char *name)
1098 if (!strcmp("pa", name))
1100 else if (!strcmp("va", name))
1105 internal_config.iova_mode = mode;
1110 eal_parse_base_virtaddr(const char *arg)
1116 addr = strtoull(arg, &end, 16);
1118 /* check for errors */
1119 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1122 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1124 if (addr >= UINTPTR_MAX)
1128 /* align the addr on 16M boundary, 16MB is the minimum huge page
1129 * size on IBM Power architecture. If the addr is aligned to 16MB,
1130 * it can align to 2MB for x86. So this alignment can also be used
1131 * on x86 and other architectures.
1133 internal_config.base_virtaddr =
1134 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1139 /* caller is responsible for freeing the returned string */
1141 available_cores(void)
1149 /* find the first available cpu */
1150 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1151 if (eal_cpu_detected(idx) == 0)
1155 if (idx >= RTE_MAX_LCORE)
1158 /* first sequence */
1159 if (asprintf(&str, "%d", idx) < 0)
1164 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1165 if (eal_cpu_detected(idx) == 0)
1168 if (idx == previous + 1) {
1174 /* finish current sequence */
1176 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1185 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1195 /* finish last sequence */
1197 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1209 eal_parse_common_option(int opt, const char *optarg,
1210 struct internal_config *conf)
1220 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1230 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1238 int lcore_indexes[RTE_MAX_LCORE];
1240 if (eal_service_cores_parsed())
1241 RTE_LOG(WARNING, EAL,
1242 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1243 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1244 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1247 if (update_lcore_config(lcore_indexes) < 0) {
1248 char *available = available_cores();
1251 "invalid coremask, please check specified cores are part of %s\n",
1258 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1259 (core_parsed == LCORE_OPT_LST) ? "-l" :
1260 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1265 core_parsed = LCORE_OPT_MSK;
1270 int lcore_indexes[RTE_MAX_LCORE];
1272 if (eal_service_cores_parsed())
1273 RTE_LOG(WARNING, EAL,
1274 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1276 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1277 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1280 if (update_lcore_config(lcore_indexes) < 0) {
1281 char *available = available_cores();
1284 "invalid core list, please check specified cores are part of %s\n",
1291 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1292 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1293 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1298 core_parsed = LCORE_OPT_LST;
1301 /* service coremask */
1303 if (eal_parse_service_coremask(optarg) < 0) {
1304 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1308 /* service corelist */
1310 if (eal_parse_service_corelist(optarg) < 0) {
1311 RTE_LOG(ERR, EAL, "invalid service core list\n");
1315 /* size of memory */
1317 conf->memory = atoi(optarg);
1318 conf->memory *= 1024ULL;
1319 conf->memory *= 1024ULL;
1322 /* force number of channels */
1324 conf->force_nchannel = atoi(optarg);
1325 if (conf->force_nchannel == 0) {
1326 RTE_LOG(ERR, EAL, "invalid channel number\n");
1330 /* force number of ranks */
1332 conf->force_nrank = atoi(optarg);
1333 if (conf->force_nrank == 0 ||
1334 conf->force_nrank > 16) {
1335 RTE_LOG(ERR, EAL, "invalid rank number\n");
1339 /* force loading of external driver */
1341 if (eal_plugin_add(optarg) == -1)
1345 /* since message is explicitly requested by user, we
1346 * write message at highest log level so it can always
1348 * even if info or warning messages are disabled */
1349 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1353 case OPT_HUGE_UNLINK_NUM:
1354 conf->hugepage_unlink = 1;
1357 case OPT_NO_HUGE_NUM:
1358 conf->no_hugetlbfs = 1;
1359 /* no-huge is legacy mem */
1360 conf->legacy_mem = 1;
1363 case OPT_NO_PCI_NUM:
1367 case OPT_NO_HPET_NUM:
1371 case OPT_VMWARE_TSC_MAP_NUM:
1372 conf->vmware_tsc_map = 1;
1375 case OPT_NO_SHCONF_NUM:
1376 conf->no_shconf = 1;
1379 case OPT_IN_MEMORY_NUM:
1380 conf->in_memory = 1;
1381 /* in-memory is a superset of noshconf and huge-unlink */
1382 conf->no_shconf = 1;
1383 conf->hugepage_unlink = 1;
1386 case OPT_PROC_TYPE_NUM:
1387 conf->process_type = eal_parse_proc_type(optarg);
1390 case OPT_MASTER_LCORE_NUM:
1391 if (eal_parse_master_lcore(optarg) < 0) {
1392 RTE_LOG(ERR, EAL, "invalid parameter for --"
1393 OPT_MASTER_LCORE "\n");
1399 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1405 #ifndef RTE_EXEC_ENV_WINDOWS
1406 case OPT_SYSLOG_NUM:
1407 if (eal_parse_syslog(optarg, conf) < 0) {
1408 RTE_LOG(ERR, EAL, "invalid parameters for --"
1415 case OPT_LOG_LEVEL_NUM: {
1416 if (eal_parse_log_level(optarg) < 0) {
1418 "invalid parameters for --"
1419 OPT_LOG_LEVEL "\n");
1425 case OPT_TRACE_NUM: {
1426 if (eal_trace_args_save(optarg) < 0) {
1427 RTE_LOG(ERR, EAL, "invalid parameters for --"
1434 case OPT_TRACE_DIR_NUM: {
1435 if (eal_trace_dir_args_save(optarg) < 0) {
1436 RTE_LOG(ERR, EAL, "invalid parameters for --"
1437 OPT_TRACE_DIR "\n");
1443 case OPT_LCORES_NUM:
1444 if (eal_parse_lcores(optarg) < 0) {
1445 RTE_LOG(ERR, EAL, "invalid parameter for --"
1451 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1452 (core_parsed == LCORE_OPT_LST) ? "-l" :
1453 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1458 core_parsed = LCORE_OPT_MAP;
1460 case OPT_LEGACY_MEM_NUM:
1461 conf->legacy_mem = 1;
1463 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1464 conf->single_file_segments = 1;
1466 case OPT_IOVA_MODE_NUM:
1467 if (eal_parse_iova_mode(optarg) < 0) {
1468 RTE_LOG(ERR, EAL, "invalid parameters for --"
1469 OPT_IOVA_MODE "\n");
1473 case OPT_BASE_VIRTADDR_NUM:
1474 if (eal_parse_base_virtaddr(optarg) < 0) {
1475 RTE_LOG(ERR, EAL, "invalid parameter for --"
1476 OPT_BASE_VIRTADDR "\n");
1481 /* don't know what to do, leave this to caller */
1489 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1490 "cannot be used at the same time\n");
1495 eal_auto_detect_cores(struct rte_config *cfg)
1497 unsigned int lcore_id;
1498 unsigned int removed = 0;
1499 rte_cpuset_t affinity_set;
1501 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1503 CPU_ZERO(&affinity_set);
1505 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1506 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1507 !CPU_ISSET(lcore_id, &affinity_set)) {
1508 cfg->lcore_role[lcore_id] = ROLE_OFF;
1513 cfg->lcore_count -= removed;
1517 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1519 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1520 rte_cpuset_t default_set;
1521 unsigned int lcore_id;
1523 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1524 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1526 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1528 RTE_CPU_NOT(cpuset, cpuset);
1530 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1532 CPU_ZERO(&default_set);
1534 RTE_CPU_AND(cpuset, cpuset, &default_set);
1536 /* if no remaining cpu, use master lcore cpu affinity */
1537 if (!CPU_COUNT(cpuset)) {
1538 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1544 eal_cleanup_config(struct internal_config *internal_cfg)
1546 if (internal_cfg->hugefile_prefix != NULL)
1547 free(internal_cfg->hugefile_prefix);
1548 if (internal_cfg->hugepage_dir != NULL)
1549 free(internal_cfg->hugepage_dir);
1550 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1551 free(internal_cfg->user_mbuf_pool_ops_name);
1557 eal_adjust_config(struct internal_config *internal_cfg)
1560 struct rte_config *cfg = rte_eal_get_configuration();
1563 eal_auto_detect_cores(cfg);
1565 if (internal_config.process_type == RTE_PROC_AUTO)
1566 internal_config.process_type = eal_proc_type_detect();
1568 /* default master lcore is the first one */
1569 if (!master_lcore_parsed) {
1570 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1571 if (cfg->master_lcore >= RTE_MAX_LCORE)
1573 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1576 compute_ctrl_threads_cpuset(internal_cfg);
1578 /* if no memory amounts were requested, this will result in 0 and
1579 * will be overridden later, right after eal_hugepage_info_init() */
1580 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1581 internal_cfg->memory += internal_cfg->socket_mem[i];
1587 eal_check_common_options(struct internal_config *internal_cfg)
1589 struct rte_config *cfg = rte_eal_get_configuration();
1591 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1592 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1596 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1597 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1600 if (internal_cfg->hugefile_prefix != NULL &&
1601 strlen(internal_cfg->hugefile_prefix) < 1) {
1602 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1605 if (internal_cfg->hugepage_dir != NULL &&
1606 strlen(internal_cfg->hugepage_dir) < 1) {
1607 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1610 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1611 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1612 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1615 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1616 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1620 if (mem_parsed && internal_cfg->force_sockets == 1) {
1621 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1622 "be specified at the same time\n");
1625 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1626 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1627 "be specified together with --"OPT_NO_HUGE"\n");
1630 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1631 !internal_cfg->in_memory) {
1632 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1633 "be specified together with --"OPT_NO_HUGE"\n");
1636 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1637 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1638 " is only supported in non-legacy memory mode\n");
1640 if (internal_cfg->single_file_segments &&
1641 internal_cfg->hugepage_unlink &&
1642 !internal_cfg->in_memory) {
1643 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1644 "not compatible with --"OPT_HUGE_UNLINK"\n");
1647 if (internal_cfg->legacy_mem &&
1648 internal_cfg->in_memory) {
1649 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1650 "with --"OPT_IN_MEMORY"\n");
1653 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1654 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1655 "with --"OPT_MATCH_ALLOCATIONS"\n");
1658 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1659 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1660 "with --"OPT_MATCH_ALLOCATIONS"\n");
1663 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1664 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1665 "amount of reserved memory can be adjusted with "
1666 "-m or --"OPT_SOCKET_MEM"\n");
1673 eal_common_usage(void)
1675 printf("[options]\n\n"
1676 "EAL common options:\n"
1677 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1678 " -l CORELIST List of cores to run on\n"
1679 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1680 " where c1, c2, etc are core indexes between 0 and %d\n"
1681 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1682 " The argument format is\n"
1683 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1684 " lcores and cpus list are grouped by '(' and ')'\n"
1685 " Within the group, '-' is used for range separator,\n"
1686 " ',' is used for single number separator.\n"
1687 " '( )' can be omitted for single element group,\n"
1688 " '@' can be omitted if cpus and lcores have the same value\n"
1689 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1690 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1691 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1692 " -n CHANNELS Number of memory channels\n"
1693 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1694 " -r RANKS Force number of memory ranks (don't detect)\n"
1695 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1696 " Prevent EAL from using this PCI device. The argument\n"
1697 " format is <domain:bus:devid.func>.\n"
1698 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1699 " Only use the specified PCI devices. The argument format\n"
1700 " is <[domain:]bus:devid.func>. This option can be present\n"
1701 " several times (once per device).\n"
1702 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1703 " --"OPT_VDEV" Add a virtual device.\n"
1704 " The argument format is <driver><id>[,key=val,...]\n"
1705 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1706 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1707 " 'va' for IOVA_VA\n"
1708 " -d LIB.so|DIR Add a driver or driver directory\n"
1709 " (can be used multiple times)\n"
1710 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1711 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1712 #ifndef RTE_EXEC_ENV_WINDOWS
1713 " --"OPT_SYSLOG" Set syslog facility\n"
1715 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1716 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1717 " Set specific log level\n"
1718 " --"OPT_TRACE"=<regex-match>\n"
1719 " Enable trace based on regular expression trace name.\n"
1720 " By default, the trace is disabled.\n"
1721 " User must specify this option to enable trace.\n"
1722 " --"OPT_TRACE_DIR"=<directory path>\n"
1723 " Specify trace directory for trace output.\n"
1724 " By default, trace output will created at\n"
1725 " $HOME directory and parameter must be\n"
1726 " specified once only.\n"
1727 " -v Display version information on startup\n"
1728 " -h, --help This help\n"
1729 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1730 " disable secondary process support\n"
1731 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
1732 "\nEAL options for DEBUG use only:\n"
1733 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1734 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1735 " --"OPT_NO_PCI" Disable PCI\n"
1736 " --"OPT_NO_HPET" Disable HPET\n"
1737 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1738 "\n", RTE_MAX_LCORE);