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},
96 {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM },
97 {OPT_NO_TELEMETRY, 0, NULL, OPT_NO_TELEMETRY_NUM },
101 TAILQ_HEAD(shared_driver_list, shared_driver);
103 /* Definition for shared object drivers. */
104 struct shared_driver {
105 TAILQ_ENTRY(shared_driver) next;
111 /* List of external loadable drivers */
112 static struct shared_driver_list solib_list =
113 TAILQ_HEAD_INITIALIZER(solib_list);
115 /* Default path of external loadable drivers */
116 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
119 * Stringified version of solib path used by dpdk-pmdinfo.py
120 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
121 * change to usertools/dpdk-pmdinfo.py
123 static const char dpdk_solib_path[] __rte_used =
124 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
126 TAILQ_HEAD(device_option_list, device_option);
128 struct device_option {
129 TAILQ_ENTRY(device_option) next;
131 enum rte_devtype type;
135 static struct device_option_list devopt_list =
136 TAILQ_HEAD_INITIALIZER(devopt_list);
138 static int master_lcore_parsed;
139 static int mem_parsed;
140 static int core_parsed;
143 eal_option_device_add(enum rte_devtype type, const char *optarg)
145 struct device_option *devopt;
149 optlen = strlen(optarg) + 1;
150 devopt = calloc(1, sizeof(*devopt) + optlen);
151 if (devopt == NULL) {
152 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
157 ret = strlcpy(devopt->arg, optarg, optlen);
159 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
163 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
168 eal_option_device_parse(void)
170 struct device_option *devopt;
174 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
176 ret = rte_devargs_add(devopt->type, devopt->arg);
178 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
181 TAILQ_REMOVE(&devopt_list, devopt, next);
188 eal_get_hugefile_prefix(void)
190 if (internal_config.hugefile_prefix != NULL)
191 return internal_config.hugefile_prefix;
192 return HUGEFILE_PREFIX_DEFAULT;
196 eal_reset_internal_config(struct internal_config *internal_cfg)
200 internal_cfg->memory = 0;
201 internal_cfg->force_nrank = 0;
202 internal_cfg->force_nchannel = 0;
203 internal_cfg->hugefile_prefix = NULL;
204 internal_cfg->hugepage_dir = NULL;
205 internal_cfg->force_sockets = 0;
206 /* zero out the NUMA config */
207 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
208 internal_cfg->socket_mem[i] = 0;
209 internal_cfg->force_socket_limits = 0;
210 /* zero out the NUMA limits config */
211 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
212 internal_cfg->socket_limit[i] = 0;
213 /* zero out hugedir descriptors */
214 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
215 memset(&internal_cfg->hugepage_info[i], 0,
216 sizeof(internal_cfg->hugepage_info[0]));
217 internal_cfg->hugepage_info[i].lock_descriptor = -1;
219 internal_cfg->base_virtaddr = 0;
222 internal_cfg->syslog_facility = LOG_DAEMON;
225 /* if set to NONE, interrupt mode is determined automatically */
226 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
228 #ifdef RTE_LIBEAL_USE_HPET
229 internal_cfg->no_hpet = 0;
231 internal_cfg->no_hpet = 1;
233 internal_cfg->vmware_tsc_map = 0;
234 internal_cfg->create_uio_dev = 0;
235 internal_cfg->iova_mode = RTE_IOVA_DC;
236 internal_cfg->user_mbuf_pool_ops_name = NULL;
237 CPU_ZERO(&internal_cfg->ctrl_cpuset);
238 internal_cfg->init_complete = 0;
242 eal_plugin_add(const char *path)
244 struct shared_driver *solib;
246 solib = malloc(sizeof(*solib));
248 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
251 memset(solib, 0, sizeof(*solib));
252 strlcpy(solib->name, path, PATH_MAX-1);
253 solib->name[PATH_MAX-1] = 0;
254 TAILQ_INSERT_TAIL(&solib_list, solib, next);
260 eal_plugindir_init(const char *path)
263 struct dirent *dent = NULL;
264 char sopath[PATH_MAX];
266 if (path == NULL || *path == '\0')
271 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
272 path, strerror(errno));
276 while ((dent = readdir(d)) != NULL) {
279 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
281 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
284 if (eal_plugin_add(sopath) == -1)
289 /* XXX this ignores failures from readdir() itself */
290 return (dent == NULL) ? 0 : -1;
294 eal_plugins_init(void)
296 #ifndef RTE_EXEC_ENV_WINDOWS
297 struct shared_driver *solib = NULL;
300 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
302 eal_plugin_add(default_solib_dir);
304 TAILQ_FOREACH(solib, &solib_list, next) {
306 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
307 if (eal_plugindir_init(solib->name) == -1) {
309 "Cannot init plugin directory %s\n",
314 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
316 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
317 if (solib->lib_handle == NULL) {
318 RTE_LOG(ERR, EAL, "%s\n", dlerror());
329 * Parse the coremask given as argument (hexadecimal string) and fill
330 * the global configuration (core role and core count) with the parsed
333 static int xdigit2val(unsigned char c)
347 eal_parse_service_coremask(const char *coremask)
349 struct rte_config *cfg = rte_eal_get_configuration();
351 unsigned int count = 0;
354 uint32_t taken_lcore_count = 0;
356 if (coremask == NULL)
358 /* Remove all blank characters ahead and after .
359 * Remove 0x/0X if exists.
361 while (isblank(*coremask))
363 if (coremask[0] == '0' && ((coremask[1] == 'x')
364 || (coremask[1] == 'X')))
366 i = strlen(coremask);
367 while ((i > 0) && isblank(coremask[i - 1]))
373 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
375 if (isxdigit(c) == 0) {
376 /* invalid characters */
380 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
382 if ((1 << j) & val) {
383 /* handle master lcore already parsed */
384 uint32_t lcore = idx;
385 if (master_lcore_parsed &&
386 cfg->master_lcore == lcore) {
388 "lcore %u is master lcore, cannot use as service core\n",
393 if (eal_cpu_detected(idx) == 0) {
395 "lcore %u unavailable\n", idx);
399 if (cfg->lcore_role[idx] == ROLE_RTE)
402 lcore_config[idx].core_role = ROLE_SERVICE;
409 if (coremask[i] != '0')
412 for (; idx < RTE_MAX_LCORE; idx++)
413 lcore_config[idx].core_index = -1;
418 if (core_parsed && taken_lcore_count != count) {
419 RTE_LOG(WARNING, EAL,
420 "Not all service cores are in the coremask. "
421 "Please ensure -c or -l includes service cores\n");
424 cfg->service_lcore_count = count;
429 eal_service_cores_parsed(void)
432 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
433 if (lcore_config[idx].core_role == ROLE_SERVICE)
440 update_lcore_config(int *cores)
442 struct rte_config *cfg = rte_eal_get_configuration();
443 unsigned int count = 0;
447 for (i = 0; i < RTE_MAX_LCORE; i++) {
448 if (cores[i] != -1) {
449 if (eal_cpu_detected(i) == 0) {
450 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
454 cfg->lcore_role[i] = ROLE_RTE;
457 cfg->lcore_role[i] = ROLE_OFF;
459 lcore_config[i].core_index = cores[i];
462 cfg->lcore_count = count;
467 eal_parse_coremask(const char *coremask, int *cores)
474 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
478 /* Remove all blank characters ahead and after .
479 * Remove 0x/0X if exists.
481 while (isblank(*coremask))
483 if (coremask[0] == '0' && ((coremask[1] == 'x')
484 || (coremask[1] == 'X')))
486 i = strlen(coremask);
487 while ((i > 0) && isblank(coremask[i - 1]))
492 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
494 if (isxdigit(c) == 0) {
495 /* invalid characters */
499 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
501 if ((1 << j) & val) {
508 if (coremask[i] != '0')
516 eal_parse_service_corelist(const char *corelist)
518 struct rte_config *cfg = rte_eal_get_configuration();
523 uint32_t taken_lcore_count = 0;
525 if (corelist == NULL)
528 /* Remove all blank characters ahead and after */
529 while (isblank(*corelist))
531 i = strlen(corelist);
532 while ((i > 0) && isblank(corelist[i - 1]))
535 /* Get list of cores */
538 while (isblank(*corelist))
540 if (*corelist == '\0')
543 idx = strtoul(corelist, &end, 10);
544 if (errno || end == NULL)
546 while (isblank(*end))
550 } else if ((*end == ',') || (*end == '\0')) {
552 if (min == RTE_MAX_LCORE)
554 for (idx = min; idx <= max; idx++) {
555 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
556 /* handle master lcore already parsed */
557 uint32_t lcore = idx;
558 if (cfg->master_lcore == lcore &&
559 master_lcore_parsed) {
561 "Error: lcore %u is master lcore, cannot use as service core\n",
565 if (cfg->lcore_role[idx] == ROLE_RTE)
568 lcore_config[idx].core_role =
577 } while (*end != '\0');
582 if (core_parsed && taken_lcore_count != count) {
583 RTE_LOG(WARNING, EAL,
584 "Not all service cores were in the coremask. "
585 "Please ensure -c or -l includes service cores\n");
592 eal_parse_corelist(const char *corelist, int *cores)
599 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
602 /* Remove all blank characters ahead */
603 while (isblank(*corelist))
606 /* Get list of cores */
609 while (isblank(*corelist))
611 if (*corelist == '\0')
614 idx = strtol(corelist, &end, 10);
615 if (errno || end == NULL)
617 if (idx < 0 || idx >= RTE_MAX_LCORE)
619 while (isblank(*end))
623 } else if ((*end == ',') || (*end == '\0')) {
625 if (min == RTE_MAX_LCORE)
627 for (idx = min; idx <= max; idx++) {
628 if (cores[idx] == -1) {
637 } while (*end != '\0');
644 /* Changes the lcore id of the master thread */
646 eal_parse_master_lcore(const char *arg)
649 struct rte_config *cfg = rte_eal_get_configuration();
652 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
653 if (errno || parsing_end[0] != 0)
655 if (cfg->master_lcore >= RTE_MAX_LCORE)
657 master_lcore_parsed = 1;
659 /* ensure master core is not used as service core */
660 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
662 "Error: Master lcore is used as a service core\n");
670 * Parse elem, the elem could be single number/range or '(' ')' group
671 * 1) A single number elem, it's just a simple digit. e.g. 9
672 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
673 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
674 * Within group elem, '-' used for a range separator;
675 * ',' used for a single number.
678 eal_parse_set(const char *input, rte_cpuset_t *set)
681 const char *str = input;
687 while (isblank(*str))
690 /* only digit or left bracket is qualify for start point */
691 if ((!isdigit(*str) && *str != '(') || *str == '\0')
694 /* process single number or single range of number */
697 idx = strtoul(str, &end, 10);
698 if (errno || end == NULL || idx >= CPU_SETSIZE)
701 while (isblank(*end))
707 /* process single <number>-<number> */
709 while (isblank(*end))
715 idx = strtoul(end, &end, 10);
716 if (errno || end == NULL || idx >= CPU_SETSIZE)
719 while (isblank(*end))
721 if (*end != ',' && *end != '\0')
725 if (*end != ',' && *end != '\0' &&
729 for (idx = RTE_MIN(min, max);
730 idx <= RTE_MAX(min, max); idx++)
737 /* process set within bracket */
739 while (isblank(*str))
747 /* go ahead to the first digit */
748 while (isblank(*str))
753 /* get the digit value */
755 idx = strtoul(str, &end, 10);
756 if (errno || end == NULL || idx >= CPU_SETSIZE)
759 /* go ahead to separator '-',',' and ')' */
760 while (isblank(*end))
763 if (min == RTE_MAX_LCORE)
765 else /* avoid continuous '-' */
767 } else if ((*end == ',') || (*end == ')')) {
769 if (min == RTE_MAX_LCORE)
771 for (idx = RTE_MIN(min, max);
772 idx <= RTE_MAX(min, max); idx++)
780 } while (*end != '\0' && *end != ')');
783 * to avoid failure that tail blank makes end character check fail
784 * in eal_parse_lcores( )
786 while (isblank(*str))
793 check_cpuset(rte_cpuset_t *set)
797 for (idx = 0; idx < CPU_SETSIZE; idx++) {
798 if (!CPU_ISSET(idx, set))
801 if (eal_cpu_detected(idx) == 0) {
802 RTE_LOG(ERR, EAL, "core %u "
803 "unavailable\n", idx);
811 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
812 * lcores, cpus could be a single digit/range or a group.
813 * '(' and ')' are necessary if it's a group.
814 * If not supply '@cpus', the value of cpus uses the same as lcores.
815 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
816 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
817 * lcore 1 runs on cpuset 0x2 (cpu 1)
818 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
819 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
820 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
821 * lcore 7 runs on cpuset 0x80 (cpu 7)
822 * lcore 8 runs on cpuset 0x100 (cpu 8)
825 eal_parse_lcores(const char *lcores)
827 struct rte_config *cfg = rte_eal_get_configuration();
828 rte_cpuset_t lcore_set;
829 unsigned int set_count;
832 const char *lcore_start = NULL;
833 const char *end = NULL;
842 /* Remove all blank characters ahead and after */
843 while (isblank(*lcores))
848 /* Reset lcore config */
849 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
850 cfg->lcore_role[idx] = ROLE_OFF;
851 lcore_config[idx].core_index = -1;
852 CPU_ZERO(&lcore_config[idx].cpuset);
855 /* Get list of cores */
857 while (isblank(*lcores))
864 /* record lcore_set start point */
865 lcore_start = lcores;
867 /* go across a complete bracket */
868 if (*lcore_start == '(') {
869 lcores += strcspn(lcores, ")");
870 if (*lcores++ == '\0')
874 /* scan the separator '@', ','(next) or '\0'(finish) */
875 lcores += strcspn(lcores, "@,");
877 if (*lcores == '@') {
878 /* explicit assign cpuset and update the end cursor */
879 offset = eal_parse_set(lcores + 1, &cpuset);
882 end = lcores + 1 + offset;
883 } else { /* ',' or '\0' */
884 /* haven't given cpuset, current loop done */
887 /* go back to check <number>-<number> */
888 offset = strcspn(lcore_start, "(-");
889 if (offset < (end - lcore_start) &&
890 *(lcore_start + offset) != '(')
894 if (*end != ',' && *end != '\0')
897 /* parse lcore_set from start point */
898 if (eal_parse_set(lcore_start, &lcore_set) < 0)
901 /* without '@', by default using lcore_set as cpuset */
903 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
905 set_count = CPU_COUNT(&lcore_set);
906 /* start to update lcore_set */
907 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
908 if (!CPU_ISSET(idx, &lcore_set))
912 if (cfg->lcore_role[idx] != ROLE_RTE) {
913 lcore_config[idx].core_index = count;
914 cfg->lcore_role[idx] = ROLE_RTE;
920 CPU_SET(idx, &cpuset);
923 if (check_cpuset(&cpuset) < 0)
925 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
926 sizeof(rte_cpuset_t));
929 /* some cores from the lcore_set can't be handled by EAL */
934 } while (*end != '\0');
939 cfg->lcore_count = count;
947 #ifndef RTE_EXEC_ENV_WINDOWS
949 eal_parse_syslog(const char *facility, struct internal_config *conf)
952 static const struct {
956 { "auth", LOG_AUTH },
957 { "cron", LOG_CRON },
958 { "daemon", LOG_DAEMON },
960 { "kern", LOG_KERN },
962 { "mail", LOG_MAIL },
963 { "news", LOG_NEWS },
964 { "syslog", LOG_SYSLOG },
965 { "user", LOG_USER },
966 { "uucp", LOG_UUCP },
967 { "local0", LOG_LOCAL0 },
968 { "local1", LOG_LOCAL1 },
969 { "local2", LOG_LOCAL2 },
970 { "local3", LOG_LOCAL3 },
971 { "local4", LOG_LOCAL4 },
972 { "local5", LOG_LOCAL5 },
973 { "local6", LOG_LOCAL6 },
974 { "local7", LOG_LOCAL7 },
978 for (i = 0; map[i].name; i++) {
979 if (!strcmp(facility, map[i].name)) {
980 conf->syslog_facility = map[i].value;
989 eal_parse_log_priority(const char *level)
991 static const char * const levels[] = {
992 [RTE_LOG_EMERG] = "emergency",
993 [RTE_LOG_ALERT] = "alert",
994 [RTE_LOG_CRIT] = "critical",
995 [RTE_LOG_ERR] = "error",
996 [RTE_LOG_WARNING] = "warning",
997 [RTE_LOG_NOTICE] = "notice",
998 [RTE_LOG_INFO] = "info",
999 [RTE_LOG_DEBUG] = "debug",
1001 size_t len = strlen(level);
1009 /* look for named values, skip 0 which is not a valid level */
1010 for (i = 1; i < RTE_DIM(levels); i++) {
1011 if (strncmp(levels[i], level, len) == 0)
1015 /* not a string, maybe it is numeric */
1017 tmp = strtoul(level, &end, 0);
1019 /* check for errors */
1020 if (errno != 0 || end == NULL || *end != '\0' ||
1028 eal_parse_log_level(const char *arg)
1030 const char *pattern = NULL;
1031 const char *regex = NULL;
1039 if ((level = strchr(str, ','))) {
1042 } else if ((level = strchr(str, ':'))) {
1049 priority = eal_parse_log_priority(level);
1051 fprintf(stderr, "invalid log priority: %s\n", level);
1056 if (rte_log_set_level_regexp(regex, priority) < 0) {
1057 fprintf(stderr, "cannot set log level %s,%d\n",
1061 if (rte_log_save_regexp(regex, priority) < 0)
1063 } else if (pattern) {
1064 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1065 fprintf(stderr, "cannot set log level %s:%d\n",
1069 if (rte_log_save_pattern(pattern, priority) < 0)
1072 rte_log_set_global_level(priority);
1083 static enum rte_proc_type_t
1084 eal_parse_proc_type(const char *arg)
1086 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1087 return RTE_PROC_PRIMARY;
1088 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1089 return RTE_PROC_SECONDARY;
1090 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1091 return RTE_PROC_AUTO;
1093 return RTE_PROC_INVALID;
1097 eal_parse_iova_mode(const char *name)
1104 if (!strcmp("pa", name))
1106 else if (!strcmp("va", name))
1111 internal_config.iova_mode = mode;
1116 eal_parse_base_virtaddr(const char *arg)
1122 addr = strtoull(arg, &end, 16);
1124 /* check for errors */
1125 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1128 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1130 if (addr >= UINTPTR_MAX)
1134 /* align the addr on 16M boundary, 16MB is the minimum huge page
1135 * size on IBM Power architecture. If the addr is aligned to 16MB,
1136 * it can align to 2MB for x86. So this alignment can also be used
1137 * on x86 and other architectures.
1139 internal_config.base_virtaddr =
1140 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1145 /* caller is responsible for freeing the returned string */
1147 available_cores(void)
1155 /* find the first available cpu */
1156 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1157 if (eal_cpu_detected(idx) == 0)
1161 if (idx >= RTE_MAX_LCORE)
1164 /* first sequence */
1165 if (asprintf(&str, "%d", idx) < 0)
1170 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1171 if (eal_cpu_detected(idx) == 0)
1174 if (idx == previous + 1) {
1180 /* finish current sequence */
1182 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1191 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1201 /* finish last sequence */
1203 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1215 eal_parse_common_option(int opt, const char *optarg,
1216 struct internal_config *conf)
1226 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1236 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1244 int lcore_indexes[RTE_MAX_LCORE];
1246 if (eal_service_cores_parsed())
1247 RTE_LOG(WARNING, EAL,
1248 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1249 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1250 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1253 if (update_lcore_config(lcore_indexes) < 0) {
1254 char *available = available_cores();
1257 "invalid coremask, please check specified cores are part of %s\n",
1264 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1265 (core_parsed == LCORE_OPT_LST) ? "-l" :
1266 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1271 core_parsed = LCORE_OPT_MSK;
1276 int lcore_indexes[RTE_MAX_LCORE];
1278 if (eal_service_cores_parsed())
1279 RTE_LOG(WARNING, EAL,
1280 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1282 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1283 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1286 if (update_lcore_config(lcore_indexes) < 0) {
1287 char *available = available_cores();
1290 "invalid core list, please check specified cores are part of %s\n",
1297 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1298 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1299 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1304 core_parsed = LCORE_OPT_LST;
1307 /* service coremask */
1309 if (eal_parse_service_coremask(optarg) < 0) {
1310 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1314 /* service corelist */
1316 if (eal_parse_service_corelist(optarg) < 0) {
1317 RTE_LOG(ERR, EAL, "invalid service core list\n");
1321 /* size of memory */
1323 conf->memory = atoi(optarg);
1324 conf->memory *= 1024ULL;
1325 conf->memory *= 1024ULL;
1328 /* force number of channels */
1330 conf->force_nchannel = atoi(optarg);
1331 if (conf->force_nchannel == 0) {
1332 RTE_LOG(ERR, EAL, "invalid channel number\n");
1336 /* force number of ranks */
1338 conf->force_nrank = atoi(optarg);
1339 if (conf->force_nrank == 0 ||
1340 conf->force_nrank > 16) {
1341 RTE_LOG(ERR, EAL, "invalid rank number\n");
1345 /* force loading of external driver */
1347 if (eal_plugin_add(optarg) == -1)
1351 /* since message is explicitly requested by user, we
1352 * write message at highest log level so it can always
1354 * even if info or warning messages are disabled */
1355 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1359 case OPT_HUGE_UNLINK_NUM:
1360 conf->hugepage_unlink = 1;
1363 case OPT_NO_HUGE_NUM:
1364 conf->no_hugetlbfs = 1;
1365 /* no-huge is legacy mem */
1366 conf->legacy_mem = 1;
1369 case OPT_NO_PCI_NUM:
1373 case OPT_NO_HPET_NUM:
1377 case OPT_VMWARE_TSC_MAP_NUM:
1378 conf->vmware_tsc_map = 1;
1381 case OPT_NO_SHCONF_NUM:
1382 conf->no_shconf = 1;
1385 case OPT_IN_MEMORY_NUM:
1386 conf->in_memory = 1;
1387 /* in-memory is a superset of noshconf and huge-unlink */
1388 conf->no_shconf = 1;
1389 conf->hugepage_unlink = 1;
1392 case OPT_PROC_TYPE_NUM:
1393 conf->process_type = eal_parse_proc_type(optarg);
1396 case OPT_MASTER_LCORE_NUM:
1397 if (eal_parse_master_lcore(optarg) < 0) {
1398 RTE_LOG(ERR, EAL, "invalid parameter for --"
1399 OPT_MASTER_LCORE "\n");
1405 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1411 #ifndef RTE_EXEC_ENV_WINDOWS
1412 case OPT_SYSLOG_NUM:
1413 if (eal_parse_syslog(optarg, conf) < 0) {
1414 RTE_LOG(ERR, EAL, "invalid parameters for --"
1421 case OPT_LOG_LEVEL_NUM: {
1422 if (eal_parse_log_level(optarg) < 0) {
1424 "invalid parameters for --"
1425 OPT_LOG_LEVEL "\n");
1431 #ifndef RTE_EXEC_ENV_WINDOWS
1432 case OPT_TRACE_NUM: {
1433 if (eal_trace_args_save(optarg) < 0) {
1434 RTE_LOG(ERR, EAL, "invalid parameters for --"
1441 case OPT_TRACE_DIR_NUM: {
1442 if (eal_trace_dir_args_save(optarg) < 0) {
1443 RTE_LOG(ERR, EAL, "invalid parameters for --"
1444 OPT_TRACE_DIR "\n");
1450 case OPT_TRACE_BUF_SIZE_NUM: {
1451 if (eal_trace_bufsz_args_save(optarg) < 0) {
1452 RTE_LOG(ERR, EAL, "invalid parameters for --"
1453 OPT_TRACE_BUF_SIZE "\n");
1459 case OPT_TRACE_MODE_NUM: {
1460 if (eal_trace_mode_args_save(optarg) < 0) {
1461 RTE_LOG(ERR, EAL, "invalid parameters for --"
1462 OPT_TRACE_MODE "\n");
1467 #endif /* !RTE_EXEC_ENV_WINDOWS */
1469 case OPT_LCORES_NUM:
1470 if (eal_parse_lcores(optarg) < 0) {
1471 RTE_LOG(ERR, EAL, "invalid parameter for --"
1477 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1478 (core_parsed == LCORE_OPT_LST) ? "-l" :
1479 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1484 core_parsed = LCORE_OPT_MAP;
1486 case OPT_LEGACY_MEM_NUM:
1487 conf->legacy_mem = 1;
1489 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1490 conf->single_file_segments = 1;
1492 case OPT_IOVA_MODE_NUM:
1493 if (eal_parse_iova_mode(optarg) < 0) {
1494 RTE_LOG(ERR, EAL, "invalid parameters for --"
1495 OPT_IOVA_MODE "\n");
1499 case OPT_BASE_VIRTADDR_NUM:
1500 if (eal_parse_base_virtaddr(optarg) < 0) {
1501 RTE_LOG(ERR, EAL, "invalid parameter for --"
1502 OPT_BASE_VIRTADDR "\n");
1506 case OPT_TELEMETRY_NUM:
1508 case OPT_NO_TELEMETRY_NUM:
1509 conf->no_telemetry = 1;
1512 /* don't know what to do, leave this to caller */
1520 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1521 "cannot be used at the same time\n");
1526 eal_auto_detect_cores(struct rte_config *cfg)
1528 unsigned int lcore_id;
1529 unsigned int removed = 0;
1530 rte_cpuset_t affinity_set;
1532 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1534 CPU_ZERO(&affinity_set);
1536 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1537 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1538 !CPU_ISSET(lcore_id, &affinity_set)) {
1539 cfg->lcore_role[lcore_id] = ROLE_OFF;
1544 cfg->lcore_count -= removed;
1548 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1550 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1551 rte_cpuset_t default_set;
1552 unsigned int lcore_id;
1554 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1555 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1557 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1559 RTE_CPU_NOT(cpuset, cpuset);
1561 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1563 CPU_ZERO(&default_set);
1565 RTE_CPU_AND(cpuset, cpuset, &default_set);
1567 /* if no remaining cpu, use master lcore cpu affinity */
1568 if (!CPU_COUNT(cpuset)) {
1569 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1575 eal_cleanup_config(struct internal_config *internal_cfg)
1577 if (internal_cfg->hugefile_prefix != NULL)
1578 free(internal_cfg->hugefile_prefix);
1579 if (internal_cfg->hugepage_dir != NULL)
1580 free(internal_cfg->hugepage_dir);
1581 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1582 free(internal_cfg->user_mbuf_pool_ops_name);
1588 eal_adjust_config(struct internal_config *internal_cfg)
1591 struct rte_config *cfg = rte_eal_get_configuration();
1594 eal_auto_detect_cores(cfg);
1596 if (internal_config.process_type == RTE_PROC_AUTO)
1597 internal_config.process_type = eal_proc_type_detect();
1599 /* default master lcore is the first one */
1600 if (!master_lcore_parsed) {
1601 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1602 if (cfg->master_lcore >= RTE_MAX_LCORE)
1604 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1607 compute_ctrl_threads_cpuset(internal_cfg);
1609 /* if no memory amounts were requested, this will result in 0 and
1610 * will be overridden later, right after eal_hugepage_info_init() */
1611 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1612 internal_cfg->memory += internal_cfg->socket_mem[i];
1618 eal_check_common_options(struct internal_config *internal_cfg)
1620 struct rte_config *cfg = rte_eal_get_configuration();
1622 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1623 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1627 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1628 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1631 if (internal_cfg->hugefile_prefix != NULL &&
1632 strlen(internal_cfg->hugefile_prefix) < 1) {
1633 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1636 if (internal_cfg->hugepage_dir != NULL &&
1637 strlen(internal_cfg->hugepage_dir) < 1) {
1638 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1641 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1642 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1643 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1646 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1647 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1651 if (mem_parsed && internal_cfg->force_sockets == 1) {
1652 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1653 "be specified at the same time\n");
1656 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1657 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1658 "be specified together with --"OPT_NO_HUGE"\n");
1661 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1662 !internal_cfg->in_memory) {
1663 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1664 "be specified together with --"OPT_NO_HUGE"\n");
1667 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1668 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1669 " is only supported in non-legacy memory mode\n");
1671 if (internal_cfg->single_file_segments &&
1672 internal_cfg->hugepage_unlink &&
1673 !internal_cfg->in_memory) {
1674 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1675 "not compatible with --"OPT_HUGE_UNLINK"\n");
1678 if (internal_cfg->legacy_mem &&
1679 internal_cfg->in_memory) {
1680 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1681 "with --"OPT_IN_MEMORY"\n");
1684 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1685 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1686 "with --"OPT_MATCH_ALLOCATIONS"\n");
1689 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1690 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1691 "with --"OPT_MATCH_ALLOCATIONS"\n");
1694 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1695 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1696 "amount of reserved memory can be adjusted with "
1697 "-m or --"OPT_SOCKET_MEM"\n");
1704 eal_common_usage(void)
1706 printf("[options]\n\n"
1707 "EAL common options:\n"
1708 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1709 " -l CORELIST List of cores to run on\n"
1710 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1711 " where c1, c2, etc are core indexes between 0 and %d\n"
1712 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1713 " The argument format is\n"
1714 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1715 " lcores and cpus list are grouped by '(' and ')'\n"
1716 " Within the group, '-' is used for range separator,\n"
1717 " ',' is used for single number separator.\n"
1718 " '( )' can be omitted for single element group,\n"
1719 " '@' can be omitted if cpus and lcores have the same value\n"
1720 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1721 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1722 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1723 " -n CHANNELS Number of memory channels\n"
1724 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1725 " -r RANKS Force number of memory ranks (don't detect)\n"
1726 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1727 " Prevent EAL from using this PCI device. The argument\n"
1728 " format is <domain:bus:devid.func>.\n"
1729 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1730 " Only use the specified PCI devices. The argument format\n"
1731 " is <[domain:]bus:devid.func>. This option can be present\n"
1732 " several times (once per device).\n"
1733 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1734 " --"OPT_VDEV" Add a virtual device.\n"
1735 " The argument format is <driver><id>[,key=val,...]\n"
1736 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1737 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1738 " 'va' for IOVA_VA\n"
1739 " -d LIB.so|DIR Add a driver or driver directory\n"
1740 " (can be used multiple times)\n"
1741 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1742 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1743 #ifndef RTE_EXEC_ENV_WINDOWS
1744 " --"OPT_SYSLOG" Set syslog facility\n"
1746 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1747 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1748 " Set specific log level\n"
1749 #ifndef RTE_EXEC_ENV_WINDOWS
1750 " --"OPT_TRACE"=<regex-match>\n"
1751 " Enable trace based on regular expression trace name.\n"
1752 " By default, the trace is disabled.\n"
1753 " User must specify this option to enable trace.\n"
1754 " --"OPT_TRACE_DIR"=<directory path>\n"
1755 " Specify trace directory for trace output.\n"
1756 " By default, trace output will created at\n"
1757 " $HOME directory and parameter must be\n"
1758 " specified once only.\n"
1759 " --"OPT_TRACE_BUF_SIZE"=<int>\n"
1760 " Specify maximum size of allocated memory\n"
1761 " for trace output for each thread. Valid\n"
1762 " unit can be either 'B|K|M' for 'Bytes',\n"
1763 " 'KBytes' and 'MBytes' respectively.\n"
1764 " Default is 1MB and parameter must be\n"
1765 " specified once only.\n"
1766 " --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
1767 " Specify the mode of update of trace\n"
1768 " output file. Either update on a file can\n"
1769 " be wrapped or discarded when file size\n"
1770 " reaches its maximum limit.\n"
1771 " Default mode is 'overwrite' and parameter\n"
1772 " must be specified once only.\n"
1773 #endif /* !RTE_EXEC_ENV_WINDOWS */
1774 " -v Display version information on startup\n"
1775 " -h, --help This help\n"
1776 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1777 " disable secondary process support\n"
1778 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
1779 " --"OPT_TELEMETRY" Enable telemetry support (on by default)\n"
1780 " --"OPT_NO_TELEMETRY" Disable telemetry support\n"
1781 "\nEAL options for DEBUG use only:\n"
1782 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1783 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1784 " --"OPT_NO_PCI" Disable PCI\n"
1785 " --"OPT_NO_HPET" Disable HPET\n"
1786 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1787 "\n", RTE_MAX_LCORE);