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_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM },
74 {OPT_TRACE_MODE, 1, NULL, OPT_TRACE_MODE_NUM },
75 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
76 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
77 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
78 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
79 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
80 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
81 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
82 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
83 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
84 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
85 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
86 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
87 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
88 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
89 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
90 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
91 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
92 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
93 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
97 TAILQ_HEAD(shared_driver_list, shared_driver);
99 /* Definition for shared object drivers. */
100 struct shared_driver {
101 TAILQ_ENTRY(shared_driver) next;
107 /* List of external loadable drivers */
108 static struct shared_driver_list solib_list =
109 TAILQ_HEAD_INITIALIZER(solib_list);
111 /* Default path of external loadable drivers */
112 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
115 * Stringified version of solib path used by dpdk-pmdinfo.py
116 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
117 * change to usertools/dpdk-pmdinfo.py
119 static const char dpdk_solib_path[] __rte_used =
120 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
122 TAILQ_HEAD(device_option_list, device_option);
124 struct device_option {
125 TAILQ_ENTRY(device_option) next;
127 enum rte_devtype type;
131 static struct device_option_list devopt_list =
132 TAILQ_HEAD_INITIALIZER(devopt_list);
134 static int master_lcore_parsed;
135 static int mem_parsed;
136 static int core_parsed;
139 eal_option_device_add(enum rte_devtype type, const char *optarg)
141 struct device_option *devopt;
145 optlen = strlen(optarg) + 1;
146 devopt = calloc(1, sizeof(*devopt) + optlen);
147 if (devopt == NULL) {
148 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
153 ret = strlcpy(devopt->arg, optarg, optlen);
155 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
159 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
164 eal_option_device_parse(void)
166 struct device_option *devopt;
170 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
172 ret = rte_devargs_add(devopt->type, devopt->arg);
174 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
177 TAILQ_REMOVE(&devopt_list, devopt, next);
184 eal_get_hugefile_prefix(void)
186 if (internal_config.hugefile_prefix != NULL)
187 return internal_config.hugefile_prefix;
188 return HUGEFILE_PREFIX_DEFAULT;
192 eal_reset_internal_config(struct internal_config *internal_cfg)
196 internal_cfg->memory = 0;
197 internal_cfg->force_nrank = 0;
198 internal_cfg->force_nchannel = 0;
199 internal_cfg->hugefile_prefix = NULL;
200 internal_cfg->hugepage_dir = NULL;
201 internal_cfg->force_sockets = 0;
202 /* zero out the NUMA config */
203 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
204 internal_cfg->socket_mem[i] = 0;
205 internal_cfg->force_socket_limits = 0;
206 /* zero out the NUMA limits config */
207 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
208 internal_cfg->socket_limit[i] = 0;
209 /* zero out hugedir descriptors */
210 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
211 memset(&internal_cfg->hugepage_info[i], 0,
212 sizeof(internal_cfg->hugepage_info[0]));
213 internal_cfg->hugepage_info[i].lock_descriptor = -1;
215 internal_cfg->base_virtaddr = 0;
218 internal_cfg->syslog_facility = LOG_DAEMON;
221 /* if set to NONE, interrupt mode is determined automatically */
222 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
224 #ifdef RTE_LIBEAL_USE_HPET
225 internal_cfg->no_hpet = 0;
227 internal_cfg->no_hpet = 1;
229 internal_cfg->vmware_tsc_map = 0;
230 internal_cfg->create_uio_dev = 0;
231 internal_cfg->iova_mode = RTE_IOVA_DC;
232 internal_cfg->user_mbuf_pool_ops_name = NULL;
233 CPU_ZERO(&internal_cfg->ctrl_cpuset);
234 internal_cfg->init_complete = 0;
238 eal_plugin_add(const char *path)
240 struct shared_driver *solib;
242 solib = malloc(sizeof(*solib));
244 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
247 memset(solib, 0, sizeof(*solib));
248 strlcpy(solib->name, path, PATH_MAX-1);
249 solib->name[PATH_MAX-1] = 0;
250 TAILQ_INSERT_TAIL(&solib_list, solib, next);
256 eal_plugindir_init(const char *path)
259 struct dirent *dent = NULL;
260 char sopath[PATH_MAX];
262 if (path == NULL || *path == '\0')
267 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
268 path, strerror(errno));
272 while ((dent = readdir(d)) != NULL) {
275 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
277 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
280 if (eal_plugin_add(sopath) == -1)
285 /* XXX this ignores failures from readdir() itself */
286 return (dent == NULL) ? 0 : -1;
290 eal_plugins_init(void)
292 #ifndef RTE_EXEC_ENV_WINDOWS
293 struct shared_driver *solib = NULL;
296 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
298 eal_plugin_add(default_solib_dir);
300 TAILQ_FOREACH(solib, &solib_list, next) {
302 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
303 if (eal_plugindir_init(solib->name) == -1) {
305 "Cannot init plugin directory %s\n",
310 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
312 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
313 if (solib->lib_handle == NULL) {
314 RTE_LOG(ERR, EAL, "%s\n", dlerror());
325 * Parse the coremask given as argument (hexadecimal string) and fill
326 * the global configuration (core role and core count) with the parsed
329 static int xdigit2val(unsigned char c)
343 eal_parse_service_coremask(const char *coremask)
345 struct rte_config *cfg = rte_eal_get_configuration();
347 unsigned int count = 0;
350 uint32_t taken_lcore_count = 0;
352 if (coremask == NULL)
354 /* Remove all blank characters ahead and after .
355 * Remove 0x/0X if exists.
357 while (isblank(*coremask))
359 if (coremask[0] == '0' && ((coremask[1] == 'x')
360 || (coremask[1] == 'X')))
362 i = strlen(coremask);
363 while ((i > 0) && isblank(coremask[i - 1]))
369 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
371 if (isxdigit(c) == 0) {
372 /* invalid characters */
376 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
378 if ((1 << j) & val) {
379 /* handle master lcore already parsed */
380 uint32_t lcore = idx;
381 if (master_lcore_parsed &&
382 cfg->master_lcore == lcore) {
384 "lcore %u is master lcore, cannot use as service core\n",
389 if (eal_cpu_detected(idx) == 0) {
391 "lcore %u unavailable\n", idx);
395 if (cfg->lcore_role[idx] == ROLE_RTE)
398 lcore_config[idx].core_role = ROLE_SERVICE;
405 if (coremask[i] != '0')
408 for (; idx < RTE_MAX_LCORE; idx++)
409 lcore_config[idx].core_index = -1;
414 if (core_parsed && taken_lcore_count != count) {
415 RTE_LOG(WARNING, EAL,
416 "Not all service cores are in the coremask. "
417 "Please ensure -c or -l includes service cores\n");
420 cfg->service_lcore_count = count;
425 eal_service_cores_parsed(void)
428 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
429 if (lcore_config[idx].core_role == ROLE_SERVICE)
436 update_lcore_config(int *cores)
438 struct rte_config *cfg = rte_eal_get_configuration();
439 unsigned int count = 0;
443 for (i = 0; i < RTE_MAX_LCORE; i++) {
444 if (cores[i] != -1) {
445 if (eal_cpu_detected(i) == 0) {
446 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
450 cfg->lcore_role[i] = ROLE_RTE;
453 cfg->lcore_role[i] = ROLE_OFF;
455 lcore_config[i].core_index = cores[i];
458 cfg->lcore_count = count;
463 eal_parse_coremask(const char *coremask, int *cores)
470 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
474 /* Remove all blank characters ahead and after .
475 * Remove 0x/0X if exists.
477 while (isblank(*coremask))
479 if (coremask[0] == '0' && ((coremask[1] == 'x')
480 || (coremask[1] == 'X')))
482 i = strlen(coremask);
483 while ((i > 0) && isblank(coremask[i - 1]))
488 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
490 if (isxdigit(c) == 0) {
491 /* invalid characters */
495 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
497 if ((1 << j) & val) {
504 if (coremask[i] != '0')
512 eal_parse_service_corelist(const char *corelist)
514 struct rte_config *cfg = rte_eal_get_configuration();
519 uint32_t taken_lcore_count = 0;
521 if (corelist == NULL)
524 /* Remove all blank characters ahead and after */
525 while (isblank(*corelist))
527 i = strlen(corelist);
528 while ((i > 0) && isblank(corelist[i - 1]))
531 /* Get list of cores */
534 while (isblank(*corelist))
536 if (*corelist == '\0')
539 idx = strtoul(corelist, &end, 10);
540 if (errno || end == NULL)
542 while (isblank(*end))
546 } else if ((*end == ',') || (*end == '\0')) {
548 if (min == RTE_MAX_LCORE)
550 for (idx = min; idx <= max; idx++) {
551 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
552 /* handle master lcore already parsed */
553 uint32_t lcore = idx;
554 if (cfg->master_lcore == lcore &&
555 master_lcore_parsed) {
557 "Error: lcore %u is master lcore, cannot use as service core\n",
561 if (cfg->lcore_role[idx] == ROLE_RTE)
564 lcore_config[idx].core_role =
573 } while (*end != '\0');
578 if (core_parsed && taken_lcore_count != count) {
579 RTE_LOG(WARNING, EAL,
580 "Not all service cores were in the coremask. "
581 "Please ensure -c or -l includes service cores\n");
588 eal_parse_corelist(const char *corelist, int *cores)
595 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
598 /* Remove all blank characters ahead */
599 while (isblank(*corelist))
602 /* Get list of cores */
605 while (isblank(*corelist))
607 if (*corelist == '\0')
610 idx = strtol(corelist, &end, 10);
611 if (errno || end == NULL)
613 if (idx < 0 || idx >= RTE_MAX_LCORE)
615 while (isblank(*end))
619 } else if ((*end == ',') || (*end == '\0')) {
621 if (min == RTE_MAX_LCORE)
623 for (idx = min; idx <= max; idx++) {
624 if (cores[idx] == -1) {
633 } while (*end != '\0');
640 /* Changes the lcore id of the master thread */
642 eal_parse_master_lcore(const char *arg)
645 struct rte_config *cfg = rte_eal_get_configuration();
648 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
649 if (errno || parsing_end[0] != 0)
651 if (cfg->master_lcore >= RTE_MAX_LCORE)
653 master_lcore_parsed = 1;
655 /* ensure master core is not used as service core */
656 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
658 "Error: Master lcore is used as a service core\n");
666 * Parse elem, the elem could be single number/range or '(' ')' group
667 * 1) A single number elem, it's just a simple digit. e.g. 9
668 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
669 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
670 * Within group elem, '-' used for a range separator;
671 * ',' used for a single number.
674 eal_parse_set(const char *input, rte_cpuset_t *set)
677 const char *str = input;
683 while (isblank(*str))
686 /* only digit or left bracket is qualify for start point */
687 if ((!isdigit(*str) && *str != '(') || *str == '\0')
690 /* process single number or single range of number */
693 idx = strtoul(str, &end, 10);
694 if (errno || end == NULL || idx >= CPU_SETSIZE)
697 while (isblank(*end))
703 /* process single <number>-<number> */
705 while (isblank(*end))
711 idx = strtoul(end, &end, 10);
712 if (errno || end == NULL || idx >= CPU_SETSIZE)
715 while (isblank(*end))
717 if (*end != ',' && *end != '\0')
721 if (*end != ',' && *end != '\0' &&
725 for (idx = RTE_MIN(min, max);
726 idx <= RTE_MAX(min, max); idx++)
733 /* process set within bracket */
735 while (isblank(*str))
743 /* go ahead to the first digit */
744 while (isblank(*str))
749 /* get the digit value */
751 idx = strtoul(str, &end, 10);
752 if (errno || end == NULL || idx >= CPU_SETSIZE)
755 /* go ahead to separator '-',',' and ')' */
756 while (isblank(*end))
759 if (min == RTE_MAX_LCORE)
761 else /* avoid continuous '-' */
763 } else if ((*end == ',') || (*end == ')')) {
765 if (min == RTE_MAX_LCORE)
767 for (idx = RTE_MIN(min, max);
768 idx <= RTE_MAX(min, max); idx++)
776 } while (*end != '\0' && *end != ')');
779 * to avoid failure that tail blank makes end character check fail
780 * in eal_parse_lcores( )
782 while (isblank(*str))
789 check_cpuset(rte_cpuset_t *set)
793 for (idx = 0; idx < CPU_SETSIZE; idx++) {
794 if (!CPU_ISSET(idx, set))
797 if (eal_cpu_detected(idx) == 0) {
798 RTE_LOG(ERR, EAL, "core %u "
799 "unavailable\n", idx);
807 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
808 * lcores, cpus could be a single digit/range or a group.
809 * '(' and ')' are necessary if it's a group.
810 * If not supply '@cpus', the value of cpus uses the same as lcores.
811 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
812 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
813 * lcore 1 runs on cpuset 0x2 (cpu 1)
814 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
815 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
816 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
817 * lcore 7 runs on cpuset 0x80 (cpu 7)
818 * lcore 8 runs on cpuset 0x100 (cpu 8)
821 eal_parse_lcores(const char *lcores)
823 struct rte_config *cfg = rte_eal_get_configuration();
824 rte_cpuset_t lcore_set;
825 unsigned int set_count;
828 const char *lcore_start = NULL;
829 const char *end = NULL;
838 /* Remove all blank characters ahead and after */
839 while (isblank(*lcores))
844 /* Reset lcore config */
845 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
846 cfg->lcore_role[idx] = ROLE_OFF;
847 lcore_config[idx].core_index = -1;
848 CPU_ZERO(&lcore_config[idx].cpuset);
851 /* Get list of cores */
853 while (isblank(*lcores))
860 /* record lcore_set start point */
861 lcore_start = lcores;
863 /* go across a complete bracket */
864 if (*lcore_start == '(') {
865 lcores += strcspn(lcores, ")");
866 if (*lcores++ == '\0')
870 /* scan the separator '@', ','(next) or '\0'(finish) */
871 lcores += strcspn(lcores, "@,");
873 if (*lcores == '@') {
874 /* explicit assign cpuset and update the end cursor */
875 offset = eal_parse_set(lcores + 1, &cpuset);
878 end = lcores + 1 + offset;
879 } else { /* ',' or '\0' */
880 /* haven't given cpuset, current loop done */
883 /* go back to check <number>-<number> */
884 offset = strcspn(lcore_start, "(-");
885 if (offset < (end - lcore_start) &&
886 *(lcore_start + offset) != '(')
890 if (*end != ',' && *end != '\0')
893 /* parse lcore_set from start point */
894 if (eal_parse_set(lcore_start, &lcore_set) < 0)
897 /* without '@', by default using lcore_set as cpuset */
899 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
901 set_count = CPU_COUNT(&lcore_set);
902 /* start to update lcore_set */
903 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
904 if (!CPU_ISSET(idx, &lcore_set))
908 if (cfg->lcore_role[idx] != ROLE_RTE) {
909 lcore_config[idx].core_index = count;
910 cfg->lcore_role[idx] = ROLE_RTE;
916 CPU_SET(idx, &cpuset);
919 if (check_cpuset(&cpuset) < 0)
921 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
922 sizeof(rte_cpuset_t));
925 /* some cores from the lcore_set can't be handled by EAL */
930 } while (*end != '\0');
935 cfg->lcore_count = count;
943 #ifndef RTE_EXEC_ENV_WINDOWS
945 eal_parse_syslog(const char *facility, struct internal_config *conf)
948 static const struct {
952 { "auth", LOG_AUTH },
953 { "cron", LOG_CRON },
954 { "daemon", LOG_DAEMON },
956 { "kern", LOG_KERN },
958 { "mail", LOG_MAIL },
959 { "news", LOG_NEWS },
960 { "syslog", LOG_SYSLOG },
961 { "user", LOG_USER },
962 { "uucp", LOG_UUCP },
963 { "local0", LOG_LOCAL0 },
964 { "local1", LOG_LOCAL1 },
965 { "local2", LOG_LOCAL2 },
966 { "local3", LOG_LOCAL3 },
967 { "local4", LOG_LOCAL4 },
968 { "local5", LOG_LOCAL5 },
969 { "local6", LOG_LOCAL6 },
970 { "local7", LOG_LOCAL7 },
974 for (i = 0; map[i].name; i++) {
975 if (!strcmp(facility, map[i].name)) {
976 conf->syslog_facility = map[i].value;
985 eal_parse_log_priority(const char *level)
987 static const char * const levels[] = {
988 [RTE_LOG_EMERG] = "emergency",
989 [RTE_LOG_ALERT] = "alert",
990 [RTE_LOG_CRIT] = "critical",
991 [RTE_LOG_ERR] = "error",
992 [RTE_LOG_WARNING] = "warning",
993 [RTE_LOG_NOTICE] = "notice",
994 [RTE_LOG_INFO] = "info",
995 [RTE_LOG_DEBUG] = "debug",
997 size_t len = strlen(level);
1005 /* look for named values, skip 0 which is not a valid level */
1006 for (i = 1; i < RTE_DIM(levels); i++) {
1007 if (strncmp(levels[i], level, len) == 0)
1011 /* not a string, maybe it is numeric */
1013 tmp = strtoul(level, &end, 0);
1015 /* check for errors */
1016 if (errno != 0 || end == NULL || *end != '\0' ||
1024 eal_parse_log_level(const char *arg)
1026 const char *pattern = NULL;
1027 const char *regex = NULL;
1035 if ((level = strchr(str, ','))) {
1038 } else if ((level = strchr(str, ':'))) {
1045 priority = eal_parse_log_priority(level);
1047 fprintf(stderr, "invalid log priority: %s\n", level);
1052 if (rte_log_set_level_regexp(regex, priority) < 0) {
1053 fprintf(stderr, "cannot set log level %s,%d\n",
1057 if (rte_log_save_regexp(regex, priority) < 0)
1059 } else if (pattern) {
1060 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1061 fprintf(stderr, "cannot set log level %s:%d\n",
1065 if (rte_log_save_pattern(pattern, priority) < 0)
1068 rte_log_set_global_level(priority);
1079 static enum rte_proc_type_t
1080 eal_parse_proc_type(const char *arg)
1082 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1083 return RTE_PROC_PRIMARY;
1084 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1085 return RTE_PROC_SECONDARY;
1086 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1087 return RTE_PROC_AUTO;
1089 return RTE_PROC_INVALID;
1093 eal_parse_iova_mode(const char *name)
1100 if (!strcmp("pa", name))
1102 else if (!strcmp("va", name))
1107 internal_config.iova_mode = mode;
1112 eal_parse_base_virtaddr(const char *arg)
1118 addr = strtoull(arg, &end, 16);
1120 /* check for errors */
1121 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1124 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1126 if (addr >= UINTPTR_MAX)
1130 /* align the addr on 16M boundary, 16MB is the minimum huge page
1131 * size on IBM Power architecture. If the addr is aligned to 16MB,
1132 * it can align to 2MB for x86. So this alignment can also be used
1133 * on x86 and other architectures.
1135 internal_config.base_virtaddr =
1136 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1141 /* caller is responsible for freeing the returned string */
1143 available_cores(void)
1151 /* find the first available cpu */
1152 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1153 if (eal_cpu_detected(idx) == 0)
1157 if (idx >= RTE_MAX_LCORE)
1160 /* first sequence */
1161 if (asprintf(&str, "%d", idx) < 0)
1166 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1167 if (eal_cpu_detected(idx) == 0)
1170 if (idx == previous + 1) {
1176 /* finish current sequence */
1178 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1187 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1197 /* finish last sequence */
1199 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1211 eal_parse_common_option(int opt, const char *optarg,
1212 struct internal_config *conf)
1222 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1232 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1240 int lcore_indexes[RTE_MAX_LCORE];
1242 if (eal_service_cores_parsed())
1243 RTE_LOG(WARNING, EAL,
1244 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1245 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1246 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1249 if (update_lcore_config(lcore_indexes) < 0) {
1250 char *available = available_cores();
1253 "invalid coremask, please check specified cores are part of %s\n",
1260 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1261 (core_parsed == LCORE_OPT_LST) ? "-l" :
1262 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1267 core_parsed = LCORE_OPT_MSK;
1272 int lcore_indexes[RTE_MAX_LCORE];
1274 if (eal_service_cores_parsed())
1275 RTE_LOG(WARNING, EAL,
1276 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1278 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1279 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1282 if (update_lcore_config(lcore_indexes) < 0) {
1283 char *available = available_cores();
1286 "invalid core list, please check specified cores are part of %s\n",
1293 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1294 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1295 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1300 core_parsed = LCORE_OPT_LST;
1303 /* service coremask */
1305 if (eal_parse_service_coremask(optarg) < 0) {
1306 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1310 /* service corelist */
1312 if (eal_parse_service_corelist(optarg) < 0) {
1313 RTE_LOG(ERR, EAL, "invalid service core list\n");
1317 /* size of memory */
1319 conf->memory = atoi(optarg);
1320 conf->memory *= 1024ULL;
1321 conf->memory *= 1024ULL;
1324 /* force number of channels */
1326 conf->force_nchannel = atoi(optarg);
1327 if (conf->force_nchannel == 0) {
1328 RTE_LOG(ERR, EAL, "invalid channel number\n");
1332 /* force number of ranks */
1334 conf->force_nrank = atoi(optarg);
1335 if (conf->force_nrank == 0 ||
1336 conf->force_nrank > 16) {
1337 RTE_LOG(ERR, EAL, "invalid rank number\n");
1341 /* force loading of external driver */
1343 if (eal_plugin_add(optarg) == -1)
1347 /* since message is explicitly requested by user, we
1348 * write message at highest log level so it can always
1350 * even if info or warning messages are disabled */
1351 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1355 case OPT_HUGE_UNLINK_NUM:
1356 conf->hugepage_unlink = 1;
1359 case OPT_NO_HUGE_NUM:
1360 conf->no_hugetlbfs = 1;
1361 /* no-huge is legacy mem */
1362 conf->legacy_mem = 1;
1365 case OPT_NO_PCI_NUM:
1369 case OPT_NO_HPET_NUM:
1373 case OPT_VMWARE_TSC_MAP_NUM:
1374 conf->vmware_tsc_map = 1;
1377 case OPT_NO_SHCONF_NUM:
1378 conf->no_shconf = 1;
1381 case OPT_IN_MEMORY_NUM:
1382 conf->in_memory = 1;
1383 /* in-memory is a superset of noshconf and huge-unlink */
1384 conf->no_shconf = 1;
1385 conf->hugepage_unlink = 1;
1388 case OPT_PROC_TYPE_NUM:
1389 conf->process_type = eal_parse_proc_type(optarg);
1392 case OPT_MASTER_LCORE_NUM:
1393 if (eal_parse_master_lcore(optarg) < 0) {
1394 RTE_LOG(ERR, EAL, "invalid parameter for --"
1395 OPT_MASTER_LCORE "\n");
1401 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1407 #ifndef RTE_EXEC_ENV_WINDOWS
1408 case OPT_SYSLOG_NUM:
1409 if (eal_parse_syslog(optarg, conf) < 0) {
1410 RTE_LOG(ERR, EAL, "invalid parameters for --"
1417 case OPT_LOG_LEVEL_NUM: {
1418 if (eal_parse_log_level(optarg) < 0) {
1420 "invalid parameters for --"
1421 OPT_LOG_LEVEL "\n");
1427 case OPT_TRACE_NUM: {
1428 if (eal_trace_args_save(optarg) < 0) {
1429 RTE_LOG(ERR, EAL, "invalid parameters for --"
1436 case OPT_TRACE_DIR_NUM: {
1437 if (eal_trace_dir_args_save(optarg) < 0) {
1438 RTE_LOG(ERR, EAL, "invalid parameters for --"
1439 OPT_TRACE_DIR "\n");
1445 case OPT_TRACE_BUF_SIZE_NUM: {
1446 if (eal_trace_bufsz_args_save(optarg) < 0) {
1447 RTE_LOG(ERR, EAL, "invalid parameters for --"
1448 OPT_TRACE_BUF_SIZE "\n");
1454 case OPT_TRACE_MODE_NUM: {
1455 if (eal_trace_mode_args_save(optarg) < 0) {
1456 RTE_LOG(ERR, EAL, "invalid parameters for --"
1457 OPT_TRACE_MODE "\n");
1463 case OPT_LCORES_NUM:
1464 if (eal_parse_lcores(optarg) < 0) {
1465 RTE_LOG(ERR, EAL, "invalid parameter for --"
1471 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1472 (core_parsed == LCORE_OPT_LST) ? "-l" :
1473 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1478 core_parsed = LCORE_OPT_MAP;
1480 case OPT_LEGACY_MEM_NUM:
1481 conf->legacy_mem = 1;
1483 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1484 conf->single_file_segments = 1;
1486 case OPT_IOVA_MODE_NUM:
1487 if (eal_parse_iova_mode(optarg) < 0) {
1488 RTE_LOG(ERR, EAL, "invalid parameters for --"
1489 OPT_IOVA_MODE "\n");
1493 case OPT_BASE_VIRTADDR_NUM:
1494 if (eal_parse_base_virtaddr(optarg) < 0) {
1495 RTE_LOG(ERR, EAL, "invalid parameter for --"
1496 OPT_BASE_VIRTADDR "\n");
1501 /* don't know what to do, leave this to caller */
1509 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1510 "cannot be used at the same time\n");
1515 eal_auto_detect_cores(struct rte_config *cfg)
1517 unsigned int lcore_id;
1518 unsigned int removed = 0;
1519 rte_cpuset_t affinity_set;
1521 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1523 CPU_ZERO(&affinity_set);
1525 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1526 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1527 !CPU_ISSET(lcore_id, &affinity_set)) {
1528 cfg->lcore_role[lcore_id] = ROLE_OFF;
1533 cfg->lcore_count -= removed;
1537 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1539 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1540 rte_cpuset_t default_set;
1541 unsigned int lcore_id;
1543 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1544 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1546 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1548 RTE_CPU_NOT(cpuset, cpuset);
1550 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1552 CPU_ZERO(&default_set);
1554 RTE_CPU_AND(cpuset, cpuset, &default_set);
1556 /* if no remaining cpu, use master lcore cpu affinity */
1557 if (!CPU_COUNT(cpuset)) {
1558 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1564 eal_cleanup_config(struct internal_config *internal_cfg)
1566 if (internal_cfg->hugefile_prefix != NULL)
1567 free(internal_cfg->hugefile_prefix);
1568 if (internal_cfg->hugepage_dir != NULL)
1569 free(internal_cfg->hugepage_dir);
1570 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1571 free(internal_cfg->user_mbuf_pool_ops_name);
1577 eal_adjust_config(struct internal_config *internal_cfg)
1580 struct rte_config *cfg = rte_eal_get_configuration();
1583 eal_auto_detect_cores(cfg);
1585 if (internal_config.process_type == RTE_PROC_AUTO)
1586 internal_config.process_type = eal_proc_type_detect();
1588 /* default master lcore is the first one */
1589 if (!master_lcore_parsed) {
1590 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1591 if (cfg->master_lcore >= RTE_MAX_LCORE)
1593 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1596 compute_ctrl_threads_cpuset(internal_cfg);
1598 /* if no memory amounts were requested, this will result in 0 and
1599 * will be overridden later, right after eal_hugepage_info_init() */
1600 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1601 internal_cfg->memory += internal_cfg->socket_mem[i];
1607 eal_check_common_options(struct internal_config *internal_cfg)
1609 struct rte_config *cfg = rte_eal_get_configuration();
1611 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1612 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1616 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1617 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1620 if (internal_cfg->hugefile_prefix != NULL &&
1621 strlen(internal_cfg->hugefile_prefix) < 1) {
1622 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1625 if (internal_cfg->hugepage_dir != NULL &&
1626 strlen(internal_cfg->hugepage_dir) < 1) {
1627 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1630 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1631 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1632 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1635 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1636 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1640 if (mem_parsed && internal_cfg->force_sockets == 1) {
1641 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1642 "be specified at the same time\n");
1645 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1646 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1647 "be specified together with --"OPT_NO_HUGE"\n");
1650 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1651 !internal_cfg->in_memory) {
1652 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1653 "be specified together with --"OPT_NO_HUGE"\n");
1656 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1657 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1658 " is only supported in non-legacy memory mode\n");
1660 if (internal_cfg->single_file_segments &&
1661 internal_cfg->hugepage_unlink &&
1662 !internal_cfg->in_memory) {
1663 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1664 "not compatible with --"OPT_HUGE_UNLINK"\n");
1667 if (internal_cfg->legacy_mem &&
1668 internal_cfg->in_memory) {
1669 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1670 "with --"OPT_IN_MEMORY"\n");
1673 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1674 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1675 "with --"OPT_MATCH_ALLOCATIONS"\n");
1678 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1679 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1680 "with --"OPT_MATCH_ALLOCATIONS"\n");
1683 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1684 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1685 "amount of reserved memory can be adjusted with "
1686 "-m or --"OPT_SOCKET_MEM"\n");
1693 eal_common_usage(void)
1695 printf("[options]\n\n"
1696 "EAL common options:\n"
1697 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1698 " -l CORELIST List of cores to run on\n"
1699 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1700 " where c1, c2, etc are core indexes between 0 and %d\n"
1701 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1702 " The argument format is\n"
1703 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1704 " lcores and cpus list are grouped by '(' and ')'\n"
1705 " Within the group, '-' is used for range separator,\n"
1706 " ',' is used for single number separator.\n"
1707 " '( )' can be omitted for single element group,\n"
1708 " '@' can be omitted if cpus and lcores have the same value\n"
1709 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1710 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1711 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1712 " -n CHANNELS Number of memory channels\n"
1713 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1714 " -r RANKS Force number of memory ranks (don't detect)\n"
1715 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1716 " Prevent EAL from using this PCI device. The argument\n"
1717 " format is <domain:bus:devid.func>.\n"
1718 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1719 " Only use the specified PCI devices. The argument format\n"
1720 " is <[domain:]bus:devid.func>. This option can be present\n"
1721 " several times (once per device).\n"
1722 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1723 " --"OPT_VDEV" Add a virtual device.\n"
1724 " The argument format is <driver><id>[,key=val,...]\n"
1725 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1726 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1727 " 'va' for IOVA_VA\n"
1728 " -d LIB.so|DIR Add a driver or driver directory\n"
1729 " (can be used multiple times)\n"
1730 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1731 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1732 #ifndef RTE_EXEC_ENV_WINDOWS
1733 " --"OPT_SYSLOG" Set syslog facility\n"
1735 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1736 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1737 " Set specific log level\n"
1738 " --"OPT_TRACE"=<regex-match>\n"
1739 " Enable trace based on regular expression trace name.\n"
1740 " By default, the trace is disabled.\n"
1741 " User must specify this option to enable trace.\n"
1742 " --"OPT_TRACE_DIR"=<directory path>\n"
1743 " Specify trace directory for trace output.\n"
1744 " By default, trace output will created at\n"
1745 " $HOME directory and parameter must be\n"
1746 " specified once only.\n"
1747 " --"OPT_TRACE_BUF_SIZE"=<int>\n"
1748 " Specify maximum size of allocated memory\n"
1749 " for trace output for each thread. Valid\n"
1750 " unit can be either 'B|K|M' for 'Bytes',\n"
1751 " 'KBytes' and 'MBytes' respectively.\n"
1752 " Default is 1MB and parameter must be\n"
1753 " specified once only.\n"
1754 " --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
1755 " Specify the mode of update of trace\n"
1756 " output file. Either update on a file can\n"
1757 " be wrapped or discarded when file size\n"
1758 " reaches its maximum limit.\n"
1759 " Default mode is 'overwrite' and parameter\n"
1760 " must be specified once only.\n"
1761 " -v Display version information on startup\n"
1762 " -h, --help This help\n"
1763 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1764 " disable secondary process support\n"
1765 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
1766 "\nEAL options for DEBUG use only:\n"
1767 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1768 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1769 " --"OPT_NO_PCI" Disable PCI\n"
1770 " --"OPT_NO_HPET" Disable HPET\n"
1771 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1772 "\n", RTE_MAX_LCORE);