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 #ifndef RTE_EXEC_ENV_WINDOWS
38 #include "eal_trace.h"
41 #define BITS_PER_HEX 4
42 #define LCORE_OPT_LST 1
43 #define LCORE_OPT_MSK 2
44 #define LCORE_OPT_MAP 3
48 "b:" /* pci-blacklist */
50 "s:" /* service coremask */
54 "S:" /* service corelist */
55 "m:" /* memory size */
56 "n:" /* memory channels */
57 "r:" /* memory ranks */
59 "w:" /* pci-whitelist */
63 eal_long_options[] = {
64 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM },
65 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM },
66 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM },
67 {OPT_HELP, 0, NULL, OPT_HELP_NUM },
68 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM },
69 {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM },
70 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
71 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
72 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
73 {OPT_TRACE, 1, NULL, OPT_TRACE_NUM },
74 {OPT_TRACE_DIR, 1, NULL, OPT_TRACE_DIR_NUM },
75 {OPT_TRACE_BUF_SIZE, 1, NULL, OPT_TRACE_BUF_SIZE_NUM },
76 {OPT_TRACE_MODE, 1, NULL, OPT_TRACE_MODE_NUM },
77 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
78 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
79 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
80 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
81 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
82 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
83 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
84 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
85 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
86 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
87 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
88 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
89 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
90 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
91 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
92 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
93 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
94 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
95 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
99 TAILQ_HEAD(shared_driver_list, shared_driver);
101 /* Definition for shared object drivers. */
102 struct shared_driver {
103 TAILQ_ENTRY(shared_driver) next;
109 /* List of external loadable drivers */
110 static struct shared_driver_list solib_list =
111 TAILQ_HEAD_INITIALIZER(solib_list);
113 /* Default path of external loadable drivers */
114 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
117 * Stringified version of solib path used by dpdk-pmdinfo.py
118 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
119 * change to usertools/dpdk-pmdinfo.py
121 static const char dpdk_solib_path[] __rte_used =
122 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
124 TAILQ_HEAD(device_option_list, device_option);
126 struct device_option {
127 TAILQ_ENTRY(device_option) next;
129 enum rte_devtype type;
133 static struct device_option_list devopt_list =
134 TAILQ_HEAD_INITIALIZER(devopt_list);
136 static int master_lcore_parsed;
137 static int mem_parsed;
138 static int core_parsed;
141 eal_option_device_add(enum rte_devtype type, const char *optarg)
143 struct device_option *devopt;
147 optlen = strlen(optarg) + 1;
148 devopt = calloc(1, sizeof(*devopt) + optlen);
149 if (devopt == NULL) {
150 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
155 ret = strlcpy(devopt->arg, optarg, optlen);
157 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
161 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
166 eal_option_device_parse(void)
168 struct device_option *devopt;
172 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
174 ret = rte_devargs_add(devopt->type, devopt->arg);
176 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
179 TAILQ_REMOVE(&devopt_list, devopt, next);
186 eal_get_hugefile_prefix(void)
188 if (internal_config.hugefile_prefix != NULL)
189 return internal_config.hugefile_prefix;
190 return HUGEFILE_PREFIX_DEFAULT;
194 eal_reset_internal_config(struct internal_config *internal_cfg)
198 internal_cfg->memory = 0;
199 internal_cfg->force_nrank = 0;
200 internal_cfg->force_nchannel = 0;
201 internal_cfg->hugefile_prefix = NULL;
202 internal_cfg->hugepage_dir = NULL;
203 internal_cfg->force_sockets = 0;
204 /* zero out the NUMA config */
205 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
206 internal_cfg->socket_mem[i] = 0;
207 internal_cfg->force_socket_limits = 0;
208 /* zero out the NUMA limits config */
209 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
210 internal_cfg->socket_limit[i] = 0;
211 /* zero out hugedir descriptors */
212 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
213 memset(&internal_cfg->hugepage_info[i], 0,
214 sizeof(internal_cfg->hugepage_info[0]));
215 internal_cfg->hugepage_info[i].lock_descriptor = -1;
217 internal_cfg->base_virtaddr = 0;
220 internal_cfg->syslog_facility = LOG_DAEMON;
223 /* if set to NONE, interrupt mode is determined automatically */
224 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
226 #ifdef RTE_LIBEAL_USE_HPET
227 internal_cfg->no_hpet = 0;
229 internal_cfg->no_hpet = 1;
231 internal_cfg->vmware_tsc_map = 0;
232 internal_cfg->create_uio_dev = 0;
233 internal_cfg->iova_mode = RTE_IOVA_DC;
234 internal_cfg->user_mbuf_pool_ops_name = NULL;
235 CPU_ZERO(&internal_cfg->ctrl_cpuset);
236 internal_cfg->init_complete = 0;
240 eal_plugin_add(const char *path)
242 struct shared_driver *solib;
244 solib = malloc(sizeof(*solib));
246 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
249 memset(solib, 0, sizeof(*solib));
250 strlcpy(solib->name, path, PATH_MAX-1);
251 solib->name[PATH_MAX-1] = 0;
252 TAILQ_INSERT_TAIL(&solib_list, solib, next);
258 eal_plugindir_init(const char *path)
261 struct dirent *dent = NULL;
262 char sopath[PATH_MAX];
264 if (path == NULL || *path == '\0')
269 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
270 path, strerror(errno));
274 while ((dent = readdir(d)) != NULL) {
277 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
279 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
282 if (eal_plugin_add(sopath) == -1)
287 /* XXX this ignores failures from readdir() itself */
288 return (dent == NULL) ? 0 : -1;
292 eal_plugins_init(void)
294 #ifndef RTE_EXEC_ENV_WINDOWS
295 struct shared_driver *solib = NULL;
298 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
300 eal_plugin_add(default_solib_dir);
302 TAILQ_FOREACH(solib, &solib_list, next) {
304 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
305 if (eal_plugindir_init(solib->name) == -1) {
307 "Cannot init plugin directory %s\n",
312 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
314 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
315 if (solib->lib_handle == NULL) {
316 RTE_LOG(ERR, EAL, "%s\n", dlerror());
327 * Parse the coremask given as argument (hexadecimal string) and fill
328 * the global configuration (core role and core count) with the parsed
331 static int xdigit2val(unsigned char c)
345 eal_parse_service_coremask(const char *coremask)
347 struct rte_config *cfg = rte_eal_get_configuration();
349 unsigned int count = 0;
352 uint32_t taken_lcore_count = 0;
354 if (coremask == NULL)
356 /* Remove all blank characters ahead and after .
357 * Remove 0x/0X if exists.
359 while (isblank(*coremask))
361 if (coremask[0] == '0' && ((coremask[1] == 'x')
362 || (coremask[1] == 'X')))
364 i = strlen(coremask);
365 while ((i > 0) && isblank(coremask[i - 1]))
371 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
373 if (isxdigit(c) == 0) {
374 /* invalid characters */
378 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
380 if ((1 << j) & val) {
381 /* handle master lcore already parsed */
382 uint32_t lcore = idx;
383 if (master_lcore_parsed &&
384 cfg->master_lcore == lcore) {
386 "lcore %u is master lcore, cannot use as service core\n",
391 if (eal_cpu_detected(idx) == 0) {
393 "lcore %u unavailable\n", idx);
397 if (cfg->lcore_role[idx] == ROLE_RTE)
400 lcore_config[idx].core_role = ROLE_SERVICE;
407 if (coremask[i] != '0')
410 for (; idx < RTE_MAX_LCORE; idx++)
411 lcore_config[idx].core_index = -1;
416 if (core_parsed && taken_lcore_count != count) {
417 RTE_LOG(WARNING, EAL,
418 "Not all service cores are in the coremask. "
419 "Please ensure -c or -l includes service cores\n");
422 cfg->service_lcore_count = count;
427 eal_service_cores_parsed(void)
430 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
431 if (lcore_config[idx].core_role == ROLE_SERVICE)
438 update_lcore_config(int *cores)
440 struct rte_config *cfg = rte_eal_get_configuration();
441 unsigned int count = 0;
445 for (i = 0; i < RTE_MAX_LCORE; i++) {
446 if (cores[i] != -1) {
447 if (eal_cpu_detected(i) == 0) {
448 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
452 cfg->lcore_role[i] = ROLE_RTE;
455 cfg->lcore_role[i] = ROLE_OFF;
457 lcore_config[i].core_index = cores[i];
460 cfg->lcore_count = count;
465 eal_parse_coremask(const char *coremask, int *cores)
472 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
476 /* Remove all blank characters ahead and after .
477 * Remove 0x/0X if exists.
479 while (isblank(*coremask))
481 if (coremask[0] == '0' && ((coremask[1] == 'x')
482 || (coremask[1] == 'X')))
484 i = strlen(coremask);
485 while ((i > 0) && isblank(coremask[i - 1]))
490 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
492 if (isxdigit(c) == 0) {
493 /* invalid characters */
497 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
499 if ((1 << j) & val) {
506 if (coremask[i] != '0')
514 eal_parse_service_corelist(const char *corelist)
516 struct rte_config *cfg = rte_eal_get_configuration();
521 uint32_t taken_lcore_count = 0;
523 if (corelist == NULL)
526 /* Remove all blank characters ahead and after */
527 while (isblank(*corelist))
529 i = strlen(corelist);
530 while ((i > 0) && isblank(corelist[i - 1]))
533 /* Get list of cores */
536 while (isblank(*corelist))
538 if (*corelist == '\0')
541 idx = strtoul(corelist, &end, 10);
542 if (errno || end == NULL)
544 while (isblank(*end))
548 } else if ((*end == ',') || (*end == '\0')) {
550 if (min == RTE_MAX_LCORE)
552 for (idx = min; idx <= max; idx++) {
553 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
554 /* handle master lcore already parsed */
555 uint32_t lcore = idx;
556 if (cfg->master_lcore == lcore &&
557 master_lcore_parsed) {
559 "Error: lcore %u is master lcore, cannot use as service core\n",
563 if (cfg->lcore_role[idx] == ROLE_RTE)
566 lcore_config[idx].core_role =
575 } while (*end != '\0');
580 if (core_parsed && taken_lcore_count != count) {
581 RTE_LOG(WARNING, EAL,
582 "Not all service cores were in the coremask. "
583 "Please ensure -c or -l includes service cores\n");
590 eal_parse_corelist(const char *corelist, int *cores)
597 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
600 /* Remove all blank characters ahead */
601 while (isblank(*corelist))
604 /* Get list of cores */
607 while (isblank(*corelist))
609 if (*corelist == '\0')
612 idx = strtol(corelist, &end, 10);
613 if (errno || end == NULL)
615 if (idx < 0 || idx >= RTE_MAX_LCORE)
617 while (isblank(*end))
621 } else if ((*end == ',') || (*end == '\0')) {
623 if (min == RTE_MAX_LCORE)
625 for (idx = min; idx <= max; idx++) {
626 if (cores[idx] == -1) {
635 } while (*end != '\0');
642 /* Changes the lcore id of the master thread */
644 eal_parse_master_lcore(const char *arg)
647 struct rte_config *cfg = rte_eal_get_configuration();
650 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
651 if (errno || parsing_end[0] != 0)
653 if (cfg->master_lcore >= RTE_MAX_LCORE)
655 master_lcore_parsed = 1;
657 /* ensure master core is not used as service core */
658 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
660 "Error: Master lcore is used as a service core\n");
668 * Parse elem, the elem could be single number/range or '(' ')' group
669 * 1) A single number elem, it's just a simple digit. e.g. 9
670 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
671 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
672 * Within group elem, '-' used for a range separator;
673 * ',' used for a single number.
676 eal_parse_set(const char *input, rte_cpuset_t *set)
679 const char *str = input;
685 while (isblank(*str))
688 /* only digit or left bracket is qualify for start point */
689 if ((!isdigit(*str) && *str != '(') || *str == '\0')
692 /* process single number or single range of number */
695 idx = strtoul(str, &end, 10);
696 if (errno || end == NULL || idx >= CPU_SETSIZE)
699 while (isblank(*end))
705 /* process single <number>-<number> */
707 while (isblank(*end))
713 idx = strtoul(end, &end, 10);
714 if (errno || end == NULL || idx >= CPU_SETSIZE)
717 while (isblank(*end))
719 if (*end != ',' && *end != '\0')
723 if (*end != ',' && *end != '\0' &&
727 for (idx = RTE_MIN(min, max);
728 idx <= RTE_MAX(min, max); idx++)
735 /* process set within bracket */
737 while (isblank(*str))
745 /* go ahead to the first digit */
746 while (isblank(*str))
751 /* get the digit value */
753 idx = strtoul(str, &end, 10);
754 if (errno || end == NULL || idx >= CPU_SETSIZE)
757 /* go ahead to separator '-',',' and ')' */
758 while (isblank(*end))
761 if (min == RTE_MAX_LCORE)
763 else /* avoid continuous '-' */
765 } else if ((*end == ',') || (*end == ')')) {
767 if (min == RTE_MAX_LCORE)
769 for (idx = RTE_MIN(min, max);
770 idx <= RTE_MAX(min, max); idx++)
778 } while (*end != '\0' && *end != ')');
781 * to avoid failure that tail blank makes end character check fail
782 * in eal_parse_lcores( )
784 while (isblank(*str))
791 check_cpuset(rte_cpuset_t *set)
795 for (idx = 0; idx < CPU_SETSIZE; idx++) {
796 if (!CPU_ISSET(idx, set))
799 if (eal_cpu_detected(idx) == 0) {
800 RTE_LOG(ERR, EAL, "core %u "
801 "unavailable\n", idx);
809 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
810 * lcores, cpus could be a single digit/range or a group.
811 * '(' and ')' are necessary if it's a group.
812 * If not supply '@cpus', the value of cpus uses the same as lcores.
813 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
814 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
815 * lcore 1 runs on cpuset 0x2 (cpu 1)
816 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
817 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
818 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
819 * lcore 7 runs on cpuset 0x80 (cpu 7)
820 * lcore 8 runs on cpuset 0x100 (cpu 8)
823 eal_parse_lcores(const char *lcores)
825 struct rte_config *cfg = rte_eal_get_configuration();
826 rte_cpuset_t lcore_set;
827 unsigned int set_count;
830 const char *lcore_start = NULL;
831 const char *end = NULL;
840 /* Remove all blank characters ahead and after */
841 while (isblank(*lcores))
846 /* Reset lcore config */
847 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
848 cfg->lcore_role[idx] = ROLE_OFF;
849 lcore_config[idx].core_index = -1;
850 CPU_ZERO(&lcore_config[idx].cpuset);
853 /* Get list of cores */
855 while (isblank(*lcores))
862 /* record lcore_set start point */
863 lcore_start = lcores;
865 /* go across a complete bracket */
866 if (*lcore_start == '(') {
867 lcores += strcspn(lcores, ")");
868 if (*lcores++ == '\0')
872 /* scan the separator '@', ','(next) or '\0'(finish) */
873 lcores += strcspn(lcores, "@,");
875 if (*lcores == '@') {
876 /* explicit assign cpuset and update the end cursor */
877 offset = eal_parse_set(lcores + 1, &cpuset);
880 end = lcores + 1 + offset;
881 } else { /* ',' or '\0' */
882 /* haven't given cpuset, current loop done */
885 /* go back to check <number>-<number> */
886 offset = strcspn(lcore_start, "(-");
887 if (offset < (end - lcore_start) &&
888 *(lcore_start + offset) != '(')
892 if (*end != ',' && *end != '\0')
895 /* parse lcore_set from start point */
896 if (eal_parse_set(lcore_start, &lcore_set) < 0)
899 /* without '@', by default using lcore_set as cpuset */
901 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
903 set_count = CPU_COUNT(&lcore_set);
904 /* start to update lcore_set */
905 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
906 if (!CPU_ISSET(idx, &lcore_set))
910 if (cfg->lcore_role[idx] != ROLE_RTE) {
911 lcore_config[idx].core_index = count;
912 cfg->lcore_role[idx] = ROLE_RTE;
918 CPU_SET(idx, &cpuset);
921 if (check_cpuset(&cpuset) < 0)
923 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
924 sizeof(rte_cpuset_t));
927 /* some cores from the lcore_set can't be handled by EAL */
932 } while (*end != '\0');
937 cfg->lcore_count = count;
945 #ifndef RTE_EXEC_ENV_WINDOWS
947 eal_parse_syslog(const char *facility, struct internal_config *conf)
950 static const struct {
954 { "auth", LOG_AUTH },
955 { "cron", LOG_CRON },
956 { "daemon", LOG_DAEMON },
958 { "kern", LOG_KERN },
960 { "mail", LOG_MAIL },
961 { "news", LOG_NEWS },
962 { "syslog", LOG_SYSLOG },
963 { "user", LOG_USER },
964 { "uucp", LOG_UUCP },
965 { "local0", LOG_LOCAL0 },
966 { "local1", LOG_LOCAL1 },
967 { "local2", LOG_LOCAL2 },
968 { "local3", LOG_LOCAL3 },
969 { "local4", LOG_LOCAL4 },
970 { "local5", LOG_LOCAL5 },
971 { "local6", LOG_LOCAL6 },
972 { "local7", LOG_LOCAL7 },
976 for (i = 0; map[i].name; i++) {
977 if (!strcmp(facility, map[i].name)) {
978 conf->syslog_facility = map[i].value;
987 eal_parse_log_priority(const char *level)
989 static const char * const levels[] = {
990 [RTE_LOG_EMERG] = "emergency",
991 [RTE_LOG_ALERT] = "alert",
992 [RTE_LOG_CRIT] = "critical",
993 [RTE_LOG_ERR] = "error",
994 [RTE_LOG_WARNING] = "warning",
995 [RTE_LOG_NOTICE] = "notice",
996 [RTE_LOG_INFO] = "info",
997 [RTE_LOG_DEBUG] = "debug",
999 size_t len = strlen(level);
1007 /* look for named values, skip 0 which is not a valid level */
1008 for (i = 1; i < RTE_DIM(levels); i++) {
1009 if (strncmp(levels[i], level, len) == 0)
1013 /* not a string, maybe it is numeric */
1015 tmp = strtoul(level, &end, 0);
1017 /* check for errors */
1018 if (errno != 0 || end == NULL || *end != '\0' ||
1026 eal_parse_log_level(const char *arg)
1028 const char *pattern = NULL;
1029 const char *regex = NULL;
1037 if ((level = strchr(str, ','))) {
1040 } else if ((level = strchr(str, ':'))) {
1047 priority = eal_parse_log_priority(level);
1049 fprintf(stderr, "invalid log priority: %s\n", level);
1054 if (rte_log_set_level_regexp(regex, priority) < 0) {
1055 fprintf(stderr, "cannot set log level %s,%d\n",
1059 if (rte_log_save_regexp(regex, priority) < 0)
1061 } else if (pattern) {
1062 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1063 fprintf(stderr, "cannot set log level %s:%d\n",
1067 if (rte_log_save_pattern(pattern, priority) < 0)
1070 rte_log_set_global_level(priority);
1081 static enum rte_proc_type_t
1082 eal_parse_proc_type(const char *arg)
1084 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1085 return RTE_PROC_PRIMARY;
1086 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1087 return RTE_PROC_SECONDARY;
1088 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1089 return RTE_PROC_AUTO;
1091 return RTE_PROC_INVALID;
1095 eal_parse_iova_mode(const char *name)
1102 if (!strcmp("pa", name))
1104 else if (!strcmp("va", name))
1109 internal_config.iova_mode = mode;
1114 eal_parse_base_virtaddr(const char *arg)
1120 addr = strtoull(arg, &end, 16);
1122 /* check for errors */
1123 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1126 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1128 if (addr >= UINTPTR_MAX)
1132 /* align the addr on 16M boundary, 16MB is the minimum huge page
1133 * size on IBM Power architecture. If the addr is aligned to 16MB,
1134 * it can align to 2MB for x86. So this alignment can also be used
1135 * on x86 and other architectures.
1137 internal_config.base_virtaddr =
1138 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1143 /* caller is responsible for freeing the returned string */
1145 available_cores(void)
1153 /* find the first available cpu */
1154 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1155 if (eal_cpu_detected(idx) == 0)
1159 if (idx >= RTE_MAX_LCORE)
1162 /* first sequence */
1163 if (asprintf(&str, "%d", idx) < 0)
1168 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1169 if (eal_cpu_detected(idx) == 0)
1172 if (idx == previous + 1) {
1178 /* finish current sequence */
1180 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1189 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1199 /* finish last sequence */
1201 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1213 eal_parse_common_option(int opt, const char *optarg,
1214 struct internal_config *conf)
1224 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1234 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1242 int lcore_indexes[RTE_MAX_LCORE];
1244 if (eal_service_cores_parsed())
1245 RTE_LOG(WARNING, EAL,
1246 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1247 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1248 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1251 if (update_lcore_config(lcore_indexes) < 0) {
1252 char *available = available_cores();
1255 "invalid coremask, please check specified cores are part of %s\n",
1262 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1263 (core_parsed == LCORE_OPT_LST) ? "-l" :
1264 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1269 core_parsed = LCORE_OPT_MSK;
1274 int lcore_indexes[RTE_MAX_LCORE];
1276 if (eal_service_cores_parsed())
1277 RTE_LOG(WARNING, EAL,
1278 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1280 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1281 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1284 if (update_lcore_config(lcore_indexes) < 0) {
1285 char *available = available_cores();
1288 "invalid core list, please check specified cores are part of %s\n",
1295 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1296 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1297 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1302 core_parsed = LCORE_OPT_LST;
1305 /* service coremask */
1307 if (eal_parse_service_coremask(optarg) < 0) {
1308 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1312 /* service corelist */
1314 if (eal_parse_service_corelist(optarg) < 0) {
1315 RTE_LOG(ERR, EAL, "invalid service core list\n");
1319 /* size of memory */
1321 conf->memory = atoi(optarg);
1322 conf->memory *= 1024ULL;
1323 conf->memory *= 1024ULL;
1326 /* force number of channels */
1328 conf->force_nchannel = atoi(optarg);
1329 if (conf->force_nchannel == 0) {
1330 RTE_LOG(ERR, EAL, "invalid channel number\n");
1334 /* force number of ranks */
1336 conf->force_nrank = atoi(optarg);
1337 if (conf->force_nrank == 0 ||
1338 conf->force_nrank > 16) {
1339 RTE_LOG(ERR, EAL, "invalid rank number\n");
1343 /* force loading of external driver */
1345 if (eal_plugin_add(optarg) == -1)
1349 /* since message is explicitly requested by user, we
1350 * write message at highest log level so it can always
1352 * even if info or warning messages are disabled */
1353 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1357 case OPT_HUGE_UNLINK_NUM:
1358 conf->hugepage_unlink = 1;
1361 case OPT_NO_HUGE_NUM:
1362 conf->no_hugetlbfs = 1;
1363 /* no-huge is legacy mem */
1364 conf->legacy_mem = 1;
1367 case OPT_NO_PCI_NUM:
1371 case OPT_NO_HPET_NUM:
1375 case OPT_VMWARE_TSC_MAP_NUM:
1376 conf->vmware_tsc_map = 1;
1379 case OPT_NO_SHCONF_NUM:
1380 conf->no_shconf = 1;
1383 case OPT_IN_MEMORY_NUM:
1384 conf->in_memory = 1;
1385 /* in-memory is a superset of noshconf and huge-unlink */
1386 conf->no_shconf = 1;
1387 conf->hugepage_unlink = 1;
1390 case OPT_PROC_TYPE_NUM:
1391 conf->process_type = eal_parse_proc_type(optarg);
1394 case OPT_MASTER_LCORE_NUM:
1395 if (eal_parse_master_lcore(optarg) < 0) {
1396 RTE_LOG(ERR, EAL, "invalid parameter for --"
1397 OPT_MASTER_LCORE "\n");
1403 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1409 #ifndef RTE_EXEC_ENV_WINDOWS
1410 case OPT_SYSLOG_NUM:
1411 if (eal_parse_syslog(optarg, conf) < 0) {
1412 RTE_LOG(ERR, EAL, "invalid parameters for --"
1419 case OPT_LOG_LEVEL_NUM: {
1420 if (eal_parse_log_level(optarg) < 0) {
1422 "invalid parameters for --"
1423 OPT_LOG_LEVEL "\n");
1429 #ifndef RTE_EXEC_ENV_WINDOWS
1430 case OPT_TRACE_NUM: {
1431 if (eal_trace_args_save(optarg) < 0) {
1432 RTE_LOG(ERR, EAL, "invalid parameters for --"
1439 case OPT_TRACE_DIR_NUM: {
1440 if (eal_trace_dir_args_save(optarg) < 0) {
1441 RTE_LOG(ERR, EAL, "invalid parameters for --"
1442 OPT_TRACE_DIR "\n");
1448 case OPT_TRACE_BUF_SIZE_NUM: {
1449 if (eal_trace_bufsz_args_save(optarg) < 0) {
1450 RTE_LOG(ERR, EAL, "invalid parameters for --"
1451 OPT_TRACE_BUF_SIZE "\n");
1457 case OPT_TRACE_MODE_NUM: {
1458 if (eal_trace_mode_args_save(optarg) < 0) {
1459 RTE_LOG(ERR, EAL, "invalid parameters for --"
1460 OPT_TRACE_MODE "\n");
1465 #endif /* !RTE_EXEC_ENV_WINDOWS */
1467 case OPT_LCORES_NUM:
1468 if (eal_parse_lcores(optarg) < 0) {
1469 RTE_LOG(ERR, EAL, "invalid parameter for --"
1475 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1476 (core_parsed == LCORE_OPT_LST) ? "-l" :
1477 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1482 core_parsed = LCORE_OPT_MAP;
1484 case OPT_LEGACY_MEM_NUM:
1485 conf->legacy_mem = 1;
1487 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1488 conf->single_file_segments = 1;
1490 case OPT_IOVA_MODE_NUM:
1491 if (eal_parse_iova_mode(optarg) < 0) {
1492 RTE_LOG(ERR, EAL, "invalid parameters for --"
1493 OPT_IOVA_MODE "\n");
1497 case OPT_BASE_VIRTADDR_NUM:
1498 if (eal_parse_base_virtaddr(optarg) < 0) {
1499 RTE_LOG(ERR, EAL, "invalid parameter for --"
1500 OPT_BASE_VIRTADDR "\n");
1505 /* don't know what to do, leave this to caller */
1513 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1514 "cannot be used at the same time\n");
1519 eal_auto_detect_cores(struct rte_config *cfg)
1521 unsigned int lcore_id;
1522 unsigned int removed = 0;
1523 rte_cpuset_t affinity_set;
1525 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1527 CPU_ZERO(&affinity_set);
1529 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1530 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1531 !CPU_ISSET(lcore_id, &affinity_set)) {
1532 cfg->lcore_role[lcore_id] = ROLE_OFF;
1537 cfg->lcore_count -= removed;
1541 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1543 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1544 rte_cpuset_t default_set;
1545 unsigned int lcore_id;
1547 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1548 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1550 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1552 RTE_CPU_NOT(cpuset, cpuset);
1554 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1556 CPU_ZERO(&default_set);
1558 RTE_CPU_AND(cpuset, cpuset, &default_set);
1560 /* if no remaining cpu, use master lcore cpu affinity */
1561 if (!CPU_COUNT(cpuset)) {
1562 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1568 eal_cleanup_config(struct internal_config *internal_cfg)
1570 if (internal_cfg->hugefile_prefix != NULL)
1571 free(internal_cfg->hugefile_prefix);
1572 if (internal_cfg->hugepage_dir != NULL)
1573 free(internal_cfg->hugepage_dir);
1574 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1575 free(internal_cfg->user_mbuf_pool_ops_name);
1581 eal_adjust_config(struct internal_config *internal_cfg)
1584 struct rte_config *cfg = rte_eal_get_configuration();
1587 eal_auto_detect_cores(cfg);
1589 if (internal_config.process_type == RTE_PROC_AUTO)
1590 internal_config.process_type = eal_proc_type_detect();
1592 /* default master lcore is the first one */
1593 if (!master_lcore_parsed) {
1594 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1595 if (cfg->master_lcore >= RTE_MAX_LCORE)
1597 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1600 compute_ctrl_threads_cpuset(internal_cfg);
1602 /* if no memory amounts were requested, this will result in 0 and
1603 * will be overridden later, right after eal_hugepage_info_init() */
1604 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1605 internal_cfg->memory += internal_cfg->socket_mem[i];
1611 eal_check_common_options(struct internal_config *internal_cfg)
1613 struct rte_config *cfg = rte_eal_get_configuration();
1615 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1616 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1620 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1621 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1624 if (internal_cfg->hugefile_prefix != NULL &&
1625 strlen(internal_cfg->hugefile_prefix) < 1) {
1626 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1629 if (internal_cfg->hugepage_dir != NULL &&
1630 strlen(internal_cfg->hugepage_dir) < 1) {
1631 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1634 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1635 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1636 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1639 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1640 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1644 if (mem_parsed && internal_cfg->force_sockets == 1) {
1645 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1646 "be specified at the same time\n");
1649 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1650 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1651 "be specified together with --"OPT_NO_HUGE"\n");
1654 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1655 !internal_cfg->in_memory) {
1656 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1657 "be specified together with --"OPT_NO_HUGE"\n");
1660 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1661 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1662 " is only supported in non-legacy memory mode\n");
1664 if (internal_cfg->single_file_segments &&
1665 internal_cfg->hugepage_unlink &&
1666 !internal_cfg->in_memory) {
1667 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1668 "not compatible with --"OPT_HUGE_UNLINK"\n");
1671 if (internal_cfg->legacy_mem &&
1672 internal_cfg->in_memory) {
1673 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1674 "with --"OPT_IN_MEMORY"\n");
1677 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1678 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1679 "with --"OPT_MATCH_ALLOCATIONS"\n");
1682 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1683 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1684 "with --"OPT_MATCH_ALLOCATIONS"\n");
1687 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1688 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1689 "amount of reserved memory can be adjusted with "
1690 "-m or --"OPT_SOCKET_MEM"\n");
1697 eal_common_usage(void)
1699 printf("[options]\n\n"
1700 "EAL common options:\n"
1701 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1702 " -l CORELIST List of cores to run on\n"
1703 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1704 " where c1, c2, etc are core indexes between 0 and %d\n"
1705 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1706 " The argument format is\n"
1707 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1708 " lcores and cpus list are grouped by '(' and ')'\n"
1709 " Within the group, '-' is used for range separator,\n"
1710 " ',' is used for single number separator.\n"
1711 " '( )' can be omitted for single element group,\n"
1712 " '@' can be omitted if cpus and lcores have the same value\n"
1713 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1714 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1715 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1716 " -n CHANNELS Number of memory channels\n"
1717 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1718 " -r RANKS Force number of memory ranks (don't detect)\n"
1719 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1720 " Prevent EAL from using this PCI device. The argument\n"
1721 " format is <domain:bus:devid.func>.\n"
1722 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1723 " Only use the specified PCI devices. The argument format\n"
1724 " is <[domain:]bus:devid.func>. This option can be present\n"
1725 " several times (once per device).\n"
1726 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1727 " --"OPT_VDEV" Add a virtual device.\n"
1728 " The argument format is <driver><id>[,key=val,...]\n"
1729 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1730 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1731 " 'va' for IOVA_VA\n"
1732 " -d LIB.so|DIR Add a driver or driver directory\n"
1733 " (can be used multiple times)\n"
1734 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1735 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1736 #ifndef RTE_EXEC_ENV_WINDOWS
1737 " --"OPT_SYSLOG" Set syslog facility\n"
1739 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1740 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1741 " Set specific log level\n"
1742 #ifndef RTE_EXEC_ENV_WINDOWS
1743 " --"OPT_TRACE"=<regex-match>\n"
1744 " Enable trace based on regular expression trace name.\n"
1745 " By default, the trace is disabled.\n"
1746 " User must specify this option to enable trace.\n"
1747 " --"OPT_TRACE_DIR"=<directory path>\n"
1748 " Specify trace directory for trace output.\n"
1749 " By default, trace output will created at\n"
1750 " $HOME directory and parameter must be\n"
1751 " specified once only.\n"
1752 " --"OPT_TRACE_BUF_SIZE"=<int>\n"
1753 " Specify maximum size of allocated memory\n"
1754 " for trace output for each thread. Valid\n"
1755 " unit can be either 'B|K|M' for 'Bytes',\n"
1756 " 'KBytes' and 'MBytes' respectively.\n"
1757 " Default is 1MB and parameter must be\n"
1758 " specified once only.\n"
1759 " --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
1760 " Specify the mode of update of trace\n"
1761 " output file. Either update on a file can\n"
1762 " be wrapped or discarded when file size\n"
1763 " reaches its maximum limit.\n"
1764 " Default mode is 'overwrite' and parameter\n"
1765 " must be specified once only.\n"
1766 #endif /* !RTE_EXEC_ENV_WINDOWS */
1767 " -v Display version information on startup\n"
1768 " -h, --help This help\n"
1769 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1770 " disable secondary process support\n"
1771 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
1772 "\nEAL options for DEBUG use only:\n"
1773 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1774 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1775 " --"OPT_NO_PCI" Disable PCI\n"
1776 " --"OPT_NO_HPET" Disable HPET\n"
1777 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1778 "\n", RTE_MAX_LCORE);