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_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
75 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
76 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
77 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
78 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
79 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
80 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
81 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
82 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
83 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
84 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
85 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
86 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
87 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
88 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
89 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
90 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
91 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
92 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
96 TAILQ_HEAD(shared_driver_list, shared_driver);
98 /* Definition for shared object drivers. */
99 struct shared_driver {
100 TAILQ_ENTRY(shared_driver) next;
106 /* List of external loadable drivers */
107 static struct shared_driver_list solib_list =
108 TAILQ_HEAD_INITIALIZER(solib_list);
110 /* Default path of external loadable drivers */
111 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
114 * Stringified version of solib path used by dpdk-pmdinfo.py
115 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
116 * change to usertools/dpdk-pmdinfo.py
118 static const char dpdk_solib_path[] __rte_used =
119 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
121 TAILQ_HEAD(device_option_list, device_option);
123 struct device_option {
124 TAILQ_ENTRY(device_option) next;
126 enum rte_devtype type;
130 static struct device_option_list devopt_list =
131 TAILQ_HEAD_INITIALIZER(devopt_list);
133 static int master_lcore_parsed;
134 static int mem_parsed;
135 static int core_parsed;
138 eal_option_device_add(enum rte_devtype type, const char *optarg)
140 struct device_option *devopt;
144 optlen = strlen(optarg) + 1;
145 devopt = calloc(1, sizeof(*devopt) + optlen);
146 if (devopt == NULL) {
147 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
152 ret = strlcpy(devopt->arg, optarg, optlen);
154 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
158 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
163 eal_option_device_parse(void)
165 struct device_option *devopt;
169 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
171 ret = rte_devargs_add(devopt->type, devopt->arg);
173 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
176 TAILQ_REMOVE(&devopt_list, devopt, next);
183 eal_get_hugefile_prefix(void)
185 if (internal_config.hugefile_prefix != NULL)
186 return internal_config.hugefile_prefix;
187 return HUGEFILE_PREFIX_DEFAULT;
191 eal_reset_internal_config(struct internal_config *internal_cfg)
195 internal_cfg->memory = 0;
196 internal_cfg->force_nrank = 0;
197 internal_cfg->force_nchannel = 0;
198 internal_cfg->hugefile_prefix = NULL;
199 internal_cfg->hugepage_dir = NULL;
200 internal_cfg->force_sockets = 0;
201 /* zero out the NUMA config */
202 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
203 internal_cfg->socket_mem[i] = 0;
204 internal_cfg->force_socket_limits = 0;
205 /* zero out the NUMA limits config */
206 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
207 internal_cfg->socket_limit[i] = 0;
208 /* zero out hugedir descriptors */
209 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
210 memset(&internal_cfg->hugepage_info[i], 0,
211 sizeof(internal_cfg->hugepage_info[0]));
212 internal_cfg->hugepage_info[i].lock_descriptor = -1;
214 internal_cfg->base_virtaddr = 0;
217 internal_cfg->syslog_facility = LOG_DAEMON;
220 /* if set to NONE, interrupt mode is determined automatically */
221 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
223 #ifdef RTE_LIBEAL_USE_HPET
224 internal_cfg->no_hpet = 0;
226 internal_cfg->no_hpet = 1;
228 internal_cfg->vmware_tsc_map = 0;
229 internal_cfg->create_uio_dev = 0;
230 internal_cfg->iova_mode = RTE_IOVA_DC;
231 internal_cfg->user_mbuf_pool_ops_name = NULL;
232 CPU_ZERO(&internal_cfg->ctrl_cpuset);
233 internal_cfg->init_complete = 0;
237 eal_plugin_add(const char *path)
239 struct shared_driver *solib;
241 solib = malloc(sizeof(*solib));
243 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
246 memset(solib, 0, sizeof(*solib));
247 strlcpy(solib->name, path, PATH_MAX-1);
248 solib->name[PATH_MAX-1] = 0;
249 TAILQ_INSERT_TAIL(&solib_list, solib, next);
255 eal_plugindir_init(const char *path)
258 struct dirent *dent = NULL;
259 char sopath[PATH_MAX];
261 if (path == NULL || *path == '\0')
266 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
267 path, strerror(errno));
271 while ((dent = readdir(d)) != NULL) {
274 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
276 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
279 if (eal_plugin_add(sopath) == -1)
284 /* XXX this ignores failures from readdir() itself */
285 return (dent == NULL) ? 0 : -1;
289 eal_plugins_init(void)
291 #ifndef RTE_EXEC_ENV_WINDOWS
292 struct shared_driver *solib = NULL;
295 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
297 eal_plugin_add(default_solib_dir);
299 TAILQ_FOREACH(solib, &solib_list, next) {
301 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
302 if (eal_plugindir_init(solib->name) == -1) {
304 "Cannot init plugin directory %s\n",
309 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
311 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
312 if (solib->lib_handle == NULL) {
313 RTE_LOG(ERR, EAL, "%s\n", dlerror());
324 * Parse the coremask given as argument (hexadecimal string) and fill
325 * the global configuration (core role and core count) with the parsed
328 static int xdigit2val(unsigned char c)
342 eal_parse_service_coremask(const char *coremask)
344 struct rte_config *cfg = rte_eal_get_configuration();
346 unsigned int count = 0;
349 uint32_t taken_lcore_count = 0;
351 if (coremask == NULL)
353 /* Remove all blank characters ahead and after .
354 * Remove 0x/0X if exists.
356 while (isblank(*coremask))
358 if (coremask[0] == '0' && ((coremask[1] == 'x')
359 || (coremask[1] == 'X')))
361 i = strlen(coremask);
362 while ((i > 0) && isblank(coremask[i - 1]))
368 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
370 if (isxdigit(c) == 0) {
371 /* invalid characters */
375 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
377 if ((1 << j) & val) {
378 /* handle master lcore already parsed */
379 uint32_t lcore = idx;
380 if (master_lcore_parsed &&
381 cfg->master_lcore == lcore) {
383 "lcore %u is master lcore, cannot use as service core\n",
388 if (eal_cpu_detected(idx) == 0) {
390 "lcore %u unavailable\n", idx);
394 if (cfg->lcore_role[idx] == ROLE_RTE)
397 lcore_config[idx].core_role = ROLE_SERVICE;
404 if (coremask[i] != '0')
407 for (; idx < RTE_MAX_LCORE; idx++)
408 lcore_config[idx].core_index = -1;
413 if (core_parsed && taken_lcore_count != count) {
414 RTE_LOG(WARNING, EAL,
415 "Not all service cores are in the coremask. "
416 "Please ensure -c or -l includes service cores\n");
419 cfg->service_lcore_count = count;
424 eal_service_cores_parsed(void)
427 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
428 if (lcore_config[idx].core_role == ROLE_SERVICE)
435 update_lcore_config(int *cores)
437 struct rte_config *cfg = rte_eal_get_configuration();
438 unsigned int count = 0;
442 for (i = 0; i < RTE_MAX_LCORE; i++) {
443 if (cores[i] != -1) {
444 if (eal_cpu_detected(i) == 0) {
445 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
449 cfg->lcore_role[i] = ROLE_RTE;
452 cfg->lcore_role[i] = ROLE_OFF;
454 lcore_config[i].core_index = cores[i];
457 cfg->lcore_count = count;
462 eal_parse_coremask(const char *coremask, int *cores)
469 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
473 /* Remove all blank characters ahead and after .
474 * Remove 0x/0X if exists.
476 while (isblank(*coremask))
478 if (coremask[0] == '0' && ((coremask[1] == 'x')
479 || (coremask[1] == 'X')))
481 i = strlen(coremask);
482 while ((i > 0) && isblank(coremask[i - 1]))
487 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
489 if (isxdigit(c) == 0) {
490 /* invalid characters */
494 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
496 if ((1 << j) & val) {
503 if (coremask[i] != '0')
511 eal_parse_service_corelist(const char *corelist)
513 struct rte_config *cfg = rte_eal_get_configuration();
518 uint32_t taken_lcore_count = 0;
520 if (corelist == NULL)
523 /* Remove all blank characters ahead and after */
524 while (isblank(*corelist))
526 i = strlen(corelist);
527 while ((i > 0) && isblank(corelist[i - 1]))
530 /* Get list of cores */
533 while (isblank(*corelist))
535 if (*corelist == '\0')
538 idx = strtoul(corelist, &end, 10);
539 if (errno || end == NULL)
541 while (isblank(*end))
545 } else if ((*end == ',') || (*end == '\0')) {
547 if (min == RTE_MAX_LCORE)
549 for (idx = min; idx <= max; idx++) {
550 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
551 /* handle master lcore already parsed */
552 uint32_t lcore = idx;
553 if (cfg->master_lcore == lcore &&
554 master_lcore_parsed) {
556 "Error: lcore %u is master lcore, cannot use as service core\n",
560 if (cfg->lcore_role[idx] == ROLE_RTE)
563 lcore_config[idx].core_role =
572 } while (*end != '\0');
577 if (core_parsed && taken_lcore_count != count) {
578 RTE_LOG(WARNING, EAL,
579 "Not all service cores were in the coremask. "
580 "Please ensure -c or -l includes service cores\n");
587 eal_parse_corelist(const char *corelist, int *cores)
594 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
597 /* Remove all blank characters ahead */
598 while (isblank(*corelist))
601 /* Get list of cores */
604 while (isblank(*corelist))
606 if (*corelist == '\0')
609 idx = strtol(corelist, &end, 10);
610 if (errno || end == NULL)
612 if (idx < 0 || idx >= RTE_MAX_LCORE)
614 while (isblank(*end))
618 } else if ((*end == ',') || (*end == '\0')) {
620 if (min == RTE_MAX_LCORE)
622 for (idx = min; idx <= max; idx++) {
623 if (cores[idx] == -1) {
632 } while (*end != '\0');
639 /* Changes the lcore id of the master thread */
641 eal_parse_master_lcore(const char *arg)
644 struct rte_config *cfg = rte_eal_get_configuration();
647 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
648 if (errno || parsing_end[0] != 0)
650 if (cfg->master_lcore >= RTE_MAX_LCORE)
652 master_lcore_parsed = 1;
654 /* ensure master core is not used as service core */
655 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
657 "Error: Master lcore is used as a service core\n");
665 * Parse elem, the elem could be single number/range or '(' ')' group
666 * 1) A single number elem, it's just a simple digit. e.g. 9
667 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
668 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
669 * Within group elem, '-' used for a range separator;
670 * ',' used for a single number.
673 eal_parse_set(const char *input, rte_cpuset_t *set)
676 const char *str = input;
682 while (isblank(*str))
685 /* only digit or left bracket is qualify for start point */
686 if ((!isdigit(*str) && *str != '(') || *str == '\0')
689 /* process single number or single range of number */
692 idx = strtoul(str, &end, 10);
693 if (errno || end == NULL || idx >= CPU_SETSIZE)
696 while (isblank(*end))
702 /* process single <number>-<number> */
704 while (isblank(*end))
710 idx = strtoul(end, &end, 10);
711 if (errno || end == NULL || idx >= CPU_SETSIZE)
714 while (isblank(*end))
716 if (*end != ',' && *end != '\0')
720 if (*end != ',' && *end != '\0' &&
724 for (idx = RTE_MIN(min, max);
725 idx <= RTE_MAX(min, max); idx++)
732 /* process set within bracket */
734 while (isblank(*str))
742 /* go ahead to the first digit */
743 while (isblank(*str))
748 /* get the digit value */
750 idx = strtoul(str, &end, 10);
751 if (errno || end == NULL || idx >= CPU_SETSIZE)
754 /* go ahead to separator '-',',' and ')' */
755 while (isblank(*end))
758 if (min == RTE_MAX_LCORE)
760 else /* avoid continuous '-' */
762 } else if ((*end == ',') || (*end == ')')) {
764 if (min == RTE_MAX_LCORE)
766 for (idx = RTE_MIN(min, max);
767 idx <= RTE_MAX(min, max); idx++)
775 } while (*end != '\0' && *end != ')');
778 * to avoid failure that tail blank makes end character check fail
779 * in eal_parse_lcores( )
781 while (isblank(*str))
788 check_cpuset(rte_cpuset_t *set)
792 for (idx = 0; idx < CPU_SETSIZE; idx++) {
793 if (!CPU_ISSET(idx, set))
796 if (eal_cpu_detected(idx) == 0) {
797 RTE_LOG(ERR, EAL, "core %u "
798 "unavailable\n", idx);
806 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
807 * lcores, cpus could be a single digit/range or a group.
808 * '(' and ')' are necessary if it's a group.
809 * If not supply '@cpus', the value of cpus uses the same as lcores.
810 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
811 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
812 * lcore 1 runs on cpuset 0x2 (cpu 1)
813 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
814 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
815 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
816 * lcore 7 runs on cpuset 0x80 (cpu 7)
817 * lcore 8 runs on cpuset 0x100 (cpu 8)
820 eal_parse_lcores(const char *lcores)
822 struct rte_config *cfg = rte_eal_get_configuration();
823 rte_cpuset_t lcore_set;
824 unsigned int set_count;
827 const char *lcore_start = NULL;
828 const char *end = NULL;
837 /* Remove all blank characters ahead and after */
838 while (isblank(*lcores))
843 /* Reset lcore config */
844 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
845 cfg->lcore_role[idx] = ROLE_OFF;
846 lcore_config[idx].core_index = -1;
847 CPU_ZERO(&lcore_config[idx].cpuset);
850 /* Get list of cores */
852 while (isblank(*lcores))
859 /* record lcore_set start point */
860 lcore_start = lcores;
862 /* go across a complete bracket */
863 if (*lcore_start == '(') {
864 lcores += strcspn(lcores, ")");
865 if (*lcores++ == '\0')
869 /* scan the separator '@', ','(next) or '\0'(finish) */
870 lcores += strcspn(lcores, "@,");
872 if (*lcores == '@') {
873 /* explicit assign cpuset and update the end cursor */
874 offset = eal_parse_set(lcores + 1, &cpuset);
877 end = lcores + 1 + offset;
878 } else { /* ',' or '\0' */
879 /* haven't given cpuset, current loop done */
882 /* go back to check <number>-<number> */
883 offset = strcspn(lcore_start, "(-");
884 if (offset < (end - lcore_start) &&
885 *(lcore_start + offset) != '(')
889 if (*end != ',' && *end != '\0')
892 /* parse lcore_set from start point */
893 if (eal_parse_set(lcore_start, &lcore_set) < 0)
896 /* without '@', by default using lcore_set as cpuset */
898 rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
900 set_count = CPU_COUNT(&lcore_set);
901 /* start to update lcore_set */
902 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
903 if (!CPU_ISSET(idx, &lcore_set))
907 if (cfg->lcore_role[idx] != ROLE_RTE) {
908 lcore_config[idx].core_index = count;
909 cfg->lcore_role[idx] = ROLE_RTE;
915 CPU_SET(idx, &cpuset);
918 if (check_cpuset(&cpuset) < 0)
920 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
921 sizeof(rte_cpuset_t));
924 /* some cores from the lcore_set can't be handled by EAL */
929 } while (*end != '\0');
934 cfg->lcore_count = count;
942 #ifndef RTE_EXEC_ENV_WINDOWS
944 eal_parse_syslog(const char *facility, struct internal_config *conf)
947 static const struct {
951 { "auth", LOG_AUTH },
952 { "cron", LOG_CRON },
953 { "daemon", LOG_DAEMON },
955 { "kern", LOG_KERN },
957 { "mail", LOG_MAIL },
958 { "news", LOG_NEWS },
959 { "syslog", LOG_SYSLOG },
960 { "user", LOG_USER },
961 { "uucp", LOG_UUCP },
962 { "local0", LOG_LOCAL0 },
963 { "local1", LOG_LOCAL1 },
964 { "local2", LOG_LOCAL2 },
965 { "local3", LOG_LOCAL3 },
966 { "local4", LOG_LOCAL4 },
967 { "local5", LOG_LOCAL5 },
968 { "local6", LOG_LOCAL6 },
969 { "local7", LOG_LOCAL7 },
973 for (i = 0; map[i].name; i++) {
974 if (!strcmp(facility, map[i].name)) {
975 conf->syslog_facility = map[i].value;
984 eal_parse_log_priority(const char *level)
986 static const char * const levels[] = {
987 [RTE_LOG_EMERG] = "emergency",
988 [RTE_LOG_ALERT] = "alert",
989 [RTE_LOG_CRIT] = "critical",
990 [RTE_LOG_ERR] = "error",
991 [RTE_LOG_WARNING] = "warning",
992 [RTE_LOG_NOTICE] = "notice",
993 [RTE_LOG_INFO] = "info",
994 [RTE_LOG_DEBUG] = "debug",
996 size_t len = strlen(level);
1004 /* look for named values, skip 0 which is not a valid level */
1005 for (i = 1; i < RTE_DIM(levels); i++) {
1006 if (strncmp(levels[i], level, len) == 0)
1010 /* not a string, maybe it is numeric */
1012 tmp = strtoul(level, &end, 0);
1014 /* check for errors */
1015 if (errno != 0 || end == NULL || *end != '\0' ||
1023 eal_parse_log_level(const char *arg)
1025 const char *pattern = NULL;
1026 const char *regex = NULL;
1034 if ((level = strchr(str, ','))) {
1037 } else if ((level = strchr(str, ':'))) {
1044 priority = eal_parse_log_priority(level);
1046 fprintf(stderr, "invalid log priority: %s\n", level);
1051 if (rte_log_set_level_regexp(regex, priority) < 0) {
1052 fprintf(stderr, "cannot set log level %s,%d\n",
1056 if (rte_log_save_regexp(regex, priority) < 0)
1058 } else if (pattern) {
1059 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1060 fprintf(stderr, "cannot set log level %s:%d\n",
1064 if (rte_log_save_pattern(pattern, priority) < 0)
1067 rte_log_set_global_level(priority);
1078 static enum rte_proc_type_t
1079 eal_parse_proc_type(const char *arg)
1081 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1082 return RTE_PROC_PRIMARY;
1083 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1084 return RTE_PROC_SECONDARY;
1085 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1086 return RTE_PROC_AUTO;
1088 return RTE_PROC_INVALID;
1092 eal_parse_iova_mode(const char *name)
1099 if (!strcmp("pa", name))
1101 else if (!strcmp("va", name))
1106 internal_config.iova_mode = mode;
1111 eal_parse_base_virtaddr(const char *arg)
1117 addr = strtoull(arg, &end, 16);
1119 /* check for errors */
1120 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1123 /* make sure we don't exceed 32-bit boundary on 32-bit target */
1125 if (addr >= UINTPTR_MAX)
1129 /* align the addr on 16M boundary, 16MB is the minimum huge page
1130 * size on IBM Power architecture. If the addr is aligned to 16MB,
1131 * it can align to 2MB for x86. So this alignment can also be used
1132 * on x86 and other architectures.
1134 internal_config.base_virtaddr =
1135 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1140 /* caller is responsible for freeing the returned string */
1142 available_cores(void)
1150 /* find the first available cpu */
1151 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1152 if (eal_cpu_detected(idx) == 0)
1156 if (idx >= RTE_MAX_LCORE)
1159 /* first sequence */
1160 if (asprintf(&str, "%d", idx) < 0)
1165 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1166 if (eal_cpu_detected(idx) == 0)
1169 if (idx == previous + 1) {
1175 /* finish current sequence */
1177 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1186 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1196 /* finish last sequence */
1198 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1210 eal_parse_common_option(int opt, const char *optarg,
1211 struct internal_config *conf)
1221 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1231 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1239 int lcore_indexes[RTE_MAX_LCORE];
1241 if (eal_service_cores_parsed())
1242 RTE_LOG(WARNING, EAL,
1243 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1244 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1245 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1248 if (update_lcore_config(lcore_indexes) < 0) {
1249 char *available = available_cores();
1252 "invalid coremask, please check specified cores are part of %s\n",
1259 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1260 (core_parsed == LCORE_OPT_LST) ? "-l" :
1261 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1266 core_parsed = LCORE_OPT_MSK;
1271 int lcore_indexes[RTE_MAX_LCORE];
1273 if (eal_service_cores_parsed())
1274 RTE_LOG(WARNING, EAL,
1275 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1277 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1278 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1281 if (update_lcore_config(lcore_indexes) < 0) {
1282 char *available = available_cores();
1285 "invalid core list, please check specified cores are part of %s\n",
1292 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1293 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1294 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1299 core_parsed = LCORE_OPT_LST;
1302 /* service coremask */
1304 if (eal_parse_service_coremask(optarg) < 0) {
1305 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1309 /* service corelist */
1311 if (eal_parse_service_corelist(optarg) < 0) {
1312 RTE_LOG(ERR, EAL, "invalid service core list\n");
1316 /* size of memory */
1318 conf->memory = atoi(optarg);
1319 conf->memory *= 1024ULL;
1320 conf->memory *= 1024ULL;
1323 /* force number of channels */
1325 conf->force_nchannel = atoi(optarg);
1326 if (conf->force_nchannel == 0) {
1327 RTE_LOG(ERR, EAL, "invalid channel number\n");
1331 /* force number of ranks */
1333 conf->force_nrank = atoi(optarg);
1334 if (conf->force_nrank == 0 ||
1335 conf->force_nrank > 16) {
1336 RTE_LOG(ERR, EAL, "invalid rank number\n");
1340 /* force loading of external driver */
1342 if (eal_plugin_add(optarg) == -1)
1346 /* since message is explicitly requested by user, we
1347 * write message at highest log level so it can always
1349 * even if info or warning messages are disabled */
1350 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1354 case OPT_HUGE_UNLINK_NUM:
1355 conf->hugepage_unlink = 1;
1358 case OPT_NO_HUGE_NUM:
1359 conf->no_hugetlbfs = 1;
1360 /* no-huge is legacy mem */
1361 conf->legacy_mem = 1;
1364 case OPT_NO_PCI_NUM:
1368 case OPT_NO_HPET_NUM:
1372 case OPT_VMWARE_TSC_MAP_NUM:
1373 conf->vmware_tsc_map = 1;
1376 case OPT_NO_SHCONF_NUM:
1377 conf->no_shconf = 1;
1380 case OPT_IN_MEMORY_NUM:
1381 conf->in_memory = 1;
1382 /* in-memory is a superset of noshconf and huge-unlink */
1383 conf->no_shconf = 1;
1384 conf->hugepage_unlink = 1;
1387 case OPT_PROC_TYPE_NUM:
1388 conf->process_type = eal_parse_proc_type(optarg);
1391 case OPT_MASTER_LCORE_NUM:
1392 if (eal_parse_master_lcore(optarg) < 0) {
1393 RTE_LOG(ERR, EAL, "invalid parameter for --"
1394 OPT_MASTER_LCORE "\n");
1400 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1406 #ifndef RTE_EXEC_ENV_WINDOWS
1407 case OPT_SYSLOG_NUM:
1408 if (eal_parse_syslog(optarg, conf) < 0) {
1409 RTE_LOG(ERR, EAL, "invalid parameters for --"
1416 case OPT_LOG_LEVEL_NUM: {
1417 if (eal_parse_log_level(optarg) < 0) {
1419 "invalid parameters for --"
1420 OPT_LOG_LEVEL "\n");
1426 case OPT_TRACE_NUM: {
1427 if (eal_trace_args_save(optarg) < 0) {
1428 RTE_LOG(ERR, EAL, "invalid parameters for --"
1435 case OPT_TRACE_DIR_NUM: {
1436 if (eal_trace_dir_args_save(optarg) < 0) {
1437 RTE_LOG(ERR, EAL, "invalid parameters for --"
1438 OPT_TRACE_DIR "\n");
1444 case OPT_TRACE_BUF_SIZE_NUM: {
1445 if (eal_trace_bufsz_args_save(optarg) < 0) {
1446 RTE_LOG(ERR, EAL, "invalid parameters for --"
1447 OPT_TRACE_BUF_SIZE "\n");
1453 case OPT_LCORES_NUM:
1454 if (eal_parse_lcores(optarg) < 0) {
1455 RTE_LOG(ERR, EAL, "invalid parameter for --"
1461 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1462 (core_parsed == LCORE_OPT_LST) ? "-l" :
1463 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1468 core_parsed = LCORE_OPT_MAP;
1470 case OPT_LEGACY_MEM_NUM:
1471 conf->legacy_mem = 1;
1473 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1474 conf->single_file_segments = 1;
1476 case OPT_IOVA_MODE_NUM:
1477 if (eal_parse_iova_mode(optarg) < 0) {
1478 RTE_LOG(ERR, EAL, "invalid parameters for --"
1479 OPT_IOVA_MODE "\n");
1483 case OPT_BASE_VIRTADDR_NUM:
1484 if (eal_parse_base_virtaddr(optarg) < 0) {
1485 RTE_LOG(ERR, EAL, "invalid parameter for --"
1486 OPT_BASE_VIRTADDR "\n");
1491 /* don't know what to do, leave this to caller */
1499 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1500 "cannot be used at the same time\n");
1505 eal_auto_detect_cores(struct rte_config *cfg)
1507 unsigned int lcore_id;
1508 unsigned int removed = 0;
1509 rte_cpuset_t affinity_set;
1511 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1513 CPU_ZERO(&affinity_set);
1515 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1516 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1517 !CPU_ISSET(lcore_id, &affinity_set)) {
1518 cfg->lcore_role[lcore_id] = ROLE_OFF;
1523 cfg->lcore_count -= removed;
1527 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1529 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1530 rte_cpuset_t default_set;
1531 unsigned int lcore_id;
1533 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1534 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1536 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1538 RTE_CPU_NOT(cpuset, cpuset);
1540 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1542 CPU_ZERO(&default_set);
1544 RTE_CPU_AND(cpuset, cpuset, &default_set);
1546 /* if no remaining cpu, use master lcore cpu affinity */
1547 if (!CPU_COUNT(cpuset)) {
1548 memcpy(cpuset, &lcore_config[rte_get_master_lcore()].cpuset,
1554 eal_cleanup_config(struct internal_config *internal_cfg)
1556 if (internal_cfg->hugefile_prefix != NULL)
1557 free(internal_cfg->hugefile_prefix);
1558 if (internal_cfg->hugepage_dir != NULL)
1559 free(internal_cfg->hugepage_dir);
1560 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1561 free(internal_cfg->user_mbuf_pool_ops_name);
1567 eal_adjust_config(struct internal_config *internal_cfg)
1570 struct rte_config *cfg = rte_eal_get_configuration();
1573 eal_auto_detect_cores(cfg);
1575 if (internal_config.process_type == RTE_PROC_AUTO)
1576 internal_config.process_type = eal_proc_type_detect();
1578 /* default master lcore is the first one */
1579 if (!master_lcore_parsed) {
1580 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1581 if (cfg->master_lcore >= RTE_MAX_LCORE)
1583 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1586 compute_ctrl_threads_cpuset(internal_cfg);
1588 /* if no memory amounts were requested, this will result in 0 and
1589 * will be overridden later, right after eal_hugepage_info_init() */
1590 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1591 internal_cfg->memory += internal_cfg->socket_mem[i];
1597 eal_check_common_options(struct internal_config *internal_cfg)
1599 struct rte_config *cfg = rte_eal_get_configuration();
1601 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1602 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1606 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1607 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1610 if (internal_cfg->hugefile_prefix != NULL &&
1611 strlen(internal_cfg->hugefile_prefix) < 1) {
1612 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1615 if (internal_cfg->hugepage_dir != NULL &&
1616 strlen(internal_cfg->hugepage_dir) < 1) {
1617 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1620 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1621 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1622 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1625 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1626 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1630 if (mem_parsed && internal_cfg->force_sockets == 1) {
1631 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1632 "be specified at the same time\n");
1635 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1636 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1637 "be specified together with --"OPT_NO_HUGE"\n");
1640 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1641 !internal_cfg->in_memory) {
1642 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1643 "be specified together with --"OPT_NO_HUGE"\n");
1646 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1647 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1648 " is only supported in non-legacy memory mode\n");
1650 if (internal_cfg->single_file_segments &&
1651 internal_cfg->hugepage_unlink &&
1652 !internal_cfg->in_memory) {
1653 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1654 "not compatible with --"OPT_HUGE_UNLINK"\n");
1657 if (internal_cfg->legacy_mem &&
1658 internal_cfg->in_memory) {
1659 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1660 "with --"OPT_IN_MEMORY"\n");
1663 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1664 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1665 "with --"OPT_MATCH_ALLOCATIONS"\n");
1668 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1669 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1670 "with --"OPT_MATCH_ALLOCATIONS"\n");
1673 if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1674 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1675 "amount of reserved memory can be adjusted with "
1676 "-m or --"OPT_SOCKET_MEM"\n");
1683 eal_common_usage(void)
1685 printf("[options]\n\n"
1686 "EAL common options:\n"
1687 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1688 " -l CORELIST List of cores to run on\n"
1689 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1690 " where c1, c2, etc are core indexes between 0 and %d\n"
1691 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1692 " The argument format is\n"
1693 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1694 " lcores and cpus list are grouped by '(' and ')'\n"
1695 " Within the group, '-' is used for range separator,\n"
1696 " ',' is used for single number separator.\n"
1697 " '( )' can be omitted for single element group,\n"
1698 " '@' can be omitted if cpus and lcores have the same value\n"
1699 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1700 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1701 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1702 " -n CHANNELS Number of memory channels\n"
1703 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1704 " -r RANKS Force number of memory ranks (don't detect)\n"
1705 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1706 " Prevent EAL from using this PCI device. The argument\n"
1707 " format is <domain:bus:devid.func>.\n"
1708 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1709 " Only use the specified PCI devices. The argument format\n"
1710 " is <[domain:]bus:devid.func>. This option can be present\n"
1711 " several times (once per device).\n"
1712 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1713 " --"OPT_VDEV" Add a virtual device.\n"
1714 " The argument format is <driver><id>[,key=val,...]\n"
1715 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1716 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1717 " 'va' for IOVA_VA\n"
1718 " -d LIB.so|DIR Add a driver or driver directory\n"
1719 " (can be used multiple times)\n"
1720 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1721 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1722 #ifndef RTE_EXEC_ENV_WINDOWS
1723 " --"OPT_SYSLOG" Set syslog facility\n"
1725 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1726 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1727 " Set specific log level\n"
1728 " --"OPT_TRACE"=<regex-match>\n"
1729 " Enable trace based on regular expression trace name.\n"
1730 " By default, the trace is disabled.\n"
1731 " User must specify this option to enable trace.\n"
1732 " --"OPT_TRACE_DIR"=<directory path>\n"
1733 " Specify trace directory for trace output.\n"
1734 " By default, trace output will created at\n"
1735 " $HOME directory and parameter must be\n"
1736 " specified once only.\n"
1737 " --"OPT_TRACE_BUF_SIZE"=<int>\n"
1738 " Specify maximum size of allocated memory\n"
1739 " for trace output for each thread. Valid\n"
1740 " unit can be either 'B|K|M' for 'Bytes',\n"
1741 " 'KBytes' and 'MBytes' respectively.\n"
1742 " Default is 1MB and parameter must be\n"
1743 " specified once only.\n"
1744 " -v Display version information on startup\n"
1745 " -h, --help This help\n"
1746 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1747 " disable secondary process support\n"
1748 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
1749 "\nEAL options for DEBUG use only:\n"
1750 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1751 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1752 " --"OPT_NO_PCI" Disable PCI\n"
1753 " --"OPT_NO_HPET" Disable HPET\n"
1754 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1755 "\n", RTE_MAX_LCORE);