1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
15 #include <sys/types.h>
19 #include <rte_string_fns.h>
22 #include <rte_lcore.h>
23 #include <rte_tailq.h>
24 #include <rte_version.h>
25 #include <rte_devargs.h>
26 #include <rte_memcpy.h>
28 #include "eal_internal_cfg.h"
29 #include "eal_options.h"
30 #include "eal_filesystem.h"
31 #include "eal_private.h"
33 #define BITS_PER_HEX 4
34 #define LCORE_OPT_LST 1
35 #define LCORE_OPT_MSK 2
36 #define LCORE_OPT_MAP 3
40 "b:" /* pci-blacklist */
42 "s:" /* service coremask */
46 "S:" /* service corelist */
47 "m:" /* memory size */
48 "n:" /* memory channels */
49 "r:" /* memory ranks */
51 "w:" /* pci-whitelist */
55 eal_long_options[] = {
56 {OPT_BASE_VIRTADDR, 1, NULL, OPT_BASE_VIRTADDR_NUM },
57 {OPT_CREATE_UIO_DEV, 0, NULL, OPT_CREATE_UIO_DEV_NUM },
58 {OPT_FILE_PREFIX, 1, NULL, OPT_FILE_PREFIX_NUM },
59 {OPT_HELP, 0, NULL, OPT_HELP_NUM },
60 {OPT_HUGE_DIR, 1, NULL, OPT_HUGE_DIR_NUM },
61 {OPT_HUGE_UNLINK, 0, NULL, OPT_HUGE_UNLINK_NUM },
62 {OPT_IOVA_MODE, 1, NULL, OPT_IOVA_MODE_NUM },
63 {OPT_LCORES, 1, NULL, OPT_LCORES_NUM },
64 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM },
65 {OPT_MASTER_LCORE, 1, NULL, OPT_MASTER_LCORE_NUM },
66 {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
67 {OPT_NO_HPET, 0, NULL, OPT_NO_HPET_NUM },
68 {OPT_NO_HUGE, 0, NULL, OPT_NO_HUGE_NUM },
69 {OPT_NO_PCI, 0, NULL, OPT_NO_PCI_NUM },
70 {OPT_NO_SHCONF, 0, NULL, OPT_NO_SHCONF_NUM },
71 {OPT_IN_MEMORY, 0, NULL, OPT_IN_MEMORY_NUM },
72 {OPT_PCI_BLACKLIST, 1, NULL, OPT_PCI_BLACKLIST_NUM },
73 {OPT_PCI_WHITELIST, 1, NULL, OPT_PCI_WHITELIST_NUM },
74 {OPT_PROC_TYPE, 1, NULL, OPT_PROC_TYPE_NUM },
75 {OPT_SOCKET_MEM, 1, NULL, OPT_SOCKET_MEM_NUM },
76 {OPT_SOCKET_LIMIT, 1, NULL, OPT_SOCKET_LIMIT_NUM },
77 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM },
78 {OPT_VDEV, 1, NULL, OPT_VDEV_NUM },
79 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
80 {OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
81 {OPT_LEGACY_MEM, 0, NULL, OPT_LEGACY_MEM_NUM },
82 {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
83 {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
84 #ifdef RTE_LIBRTE_TELEMETRY
85 {OPT_TELEMETRY, 0, NULL, OPT_TELEMETRY_NUM },
90 TAILQ_HEAD(shared_driver_list, shared_driver);
92 /* Definition for shared object drivers. */
93 struct shared_driver {
94 TAILQ_ENTRY(shared_driver) next;
100 /* List of external loadable drivers */
101 static struct shared_driver_list solib_list =
102 TAILQ_HEAD_INITIALIZER(solib_list);
104 /* Default path of external loadable drivers */
105 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
108 * Stringified version of solib path used by dpdk-pmdinfo.py
109 * Note: PLEASE DO NOT ALTER THIS without making a corresponding
110 * change to usertools/dpdk-pmdinfo.py
112 static const char dpdk_solib_path[] __attribute__((used)) =
113 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
115 TAILQ_HEAD(device_option_list, device_option);
117 struct device_option {
118 TAILQ_ENTRY(device_option) next;
120 enum rte_devtype type;
124 static struct device_option_list devopt_list =
125 TAILQ_HEAD_INITIALIZER(devopt_list);
127 static int master_lcore_parsed;
128 static int mem_parsed;
129 static int core_parsed;
132 eal_option_device_add(enum rte_devtype type, const char *optarg)
134 struct device_option *devopt;
138 optlen = strlen(optarg) + 1;
139 devopt = calloc(1, sizeof(*devopt) + optlen);
140 if (devopt == NULL) {
141 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
146 ret = strlcpy(devopt->arg, optarg, optlen);
148 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
152 TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
157 eal_option_device_parse(void)
159 struct device_option *devopt;
163 TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
165 ret = rte_devargs_add(devopt->type, devopt->arg);
167 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
170 TAILQ_REMOVE(&devopt_list, devopt, next);
177 eal_get_hugefile_prefix(void)
179 if (internal_config.hugefile_prefix != NULL)
180 return internal_config.hugefile_prefix;
181 return HUGEFILE_PREFIX_DEFAULT;
185 eal_reset_internal_config(struct internal_config *internal_cfg)
189 internal_cfg->memory = 0;
190 internal_cfg->force_nrank = 0;
191 internal_cfg->force_nchannel = 0;
192 internal_cfg->hugefile_prefix = NULL;
193 internal_cfg->hugepage_dir = NULL;
194 internal_cfg->force_sockets = 0;
195 /* zero out the NUMA config */
196 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
197 internal_cfg->socket_mem[i] = 0;
198 internal_cfg->force_socket_limits = 0;
199 /* zero out the NUMA limits config */
200 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
201 internal_cfg->socket_limit[i] = 0;
202 /* zero out hugedir descriptors */
203 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
204 memset(&internal_cfg->hugepage_info[i], 0,
205 sizeof(internal_cfg->hugepage_info[0]));
206 internal_cfg->hugepage_info[i].lock_descriptor = -1;
208 internal_cfg->base_virtaddr = 0;
210 internal_cfg->syslog_facility = LOG_DAEMON;
212 /* if set to NONE, interrupt mode is determined automatically */
213 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
215 #ifdef RTE_LIBEAL_USE_HPET
216 internal_cfg->no_hpet = 0;
218 internal_cfg->no_hpet = 1;
220 internal_cfg->vmware_tsc_map = 0;
221 internal_cfg->create_uio_dev = 0;
222 internal_cfg->iova_mode = RTE_IOVA_DC;
223 internal_cfg->user_mbuf_pool_ops_name = NULL;
224 CPU_ZERO(&internal_cfg->ctrl_cpuset);
225 internal_cfg->init_complete = 0;
229 eal_plugin_add(const char *path)
231 struct shared_driver *solib;
233 solib = malloc(sizeof(*solib));
235 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
238 memset(solib, 0, sizeof(*solib));
239 strlcpy(solib->name, path, PATH_MAX-1);
240 solib->name[PATH_MAX-1] = 0;
241 TAILQ_INSERT_TAIL(&solib_list, solib, next);
247 eal_plugindir_init(const char *path)
250 struct dirent *dent = NULL;
251 char sopath[PATH_MAX];
253 if (path == NULL || *path == '\0')
258 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
259 path, strerror(errno));
263 while ((dent = readdir(d)) != NULL) {
266 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
268 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
271 if (eal_plugin_add(sopath) == -1)
276 /* XXX this ignores failures from readdir() itself */
277 return (dent == NULL) ? 0 : -1;
281 eal_plugins_init(void)
283 struct shared_driver *solib = NULL;
286 if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
288 eal_plugin_add(default_solib_dir);
290 TAILQ_FOREACH(solib, &solib_list, next) {
292 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
293 if (eal_plugindir_init(solib->name) == -1) {
295 "Cannot init plugin directory %s\n",
300 RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
302 solib->lib_handle = dlopen(solib->name, RTLD_NOW);
303 if (solib->lib_handle == NULL) {
304 RTE_LOG(ERR, EAL, "%s\n", dlerror());
314 * Parse the coremask given as argument (hexadecimal string) and fill
315 * the global configuration (core role and core count) with the parsed
318 static int xdigit2val(unsigned char c)
332 eal_parse_service_coremask(const char *coremask)
334 struct rte_config *cfg = rte_eal_get_configuration();
336 unsigned int count = 0;
339 uint32_t taken_lcore_count = 0;
341 if (coremask == NULL)
343 /* Remove all blank characters ahead and after .
344 * Remove 0x/0X if exists.
346 while (isblank(*coremask))
348 if (coremask[0] == '0' && ((coremask[1] == 'x')
349 || (coremask[1] == 'X')))
351 i = strlen(coremask);
352 while ((i > 0) && isblank(coremask[i - 1]))
358 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
360 if (isxdigit(c) == 0) {
361 /* invalid characters */
365 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
367 if ((1 << j) & val) {
368 /* handle master lcore already parsed */
369 uint32_t lcore = idx;
370 if (master_lcore_parsed &&
371 cfg->master_lcore == lcore) {
373 "lcore %u is master lcore, cannot use as service core\n",
378 if (!lcore_config[idx].detected) {
380 "lcore %u unavailable\n", idx);
384 if (cfg->lcore_role[idx] == ROLE_RTE)
387 lcore_config[idx].core_role = ROLE_SERVICE;
394 if (coremask[i] != '0')
397 for (; idx < RTE_MAX_LCORE; idx++)
398 lcore_config[idx].core_index = -1;
403 if (core_parsed && taken_lcore_count != count) {
404 RTE_LOG(WARNING, EAL,
405 "Not all service cores are in the coremask. "
406 "Please ensure -c or -l includes service cores\n");
409 cfg->service_lcore_count = count;
414 eal_service_cores_parsed(void)
417 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
418 if (lcore_config[idx].core_role == ROLE_SERVICE)
425 update_lcore_config(int *cores)
427 struct rte_config *cfg = rte_eal_get_configuration();
428 unsigned int count = 0;
432 for (i = 0; i < RTE_MAX_LCORE; i++) {
433 if (cores[i] != -1) {
434 if (!lcore_config[i].detected) {
435 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
439 cfg->lcore_role[i] = ROLE_RTE;
442 cfg->lcore_role[i] = ROLE_OFF;
444 lcore_config[i].core_index = cores[i];
447 cfg->lcore_count = count;
452 eal_parse_coremask(const char *coremask, int *cores)
459 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
463 /* Remove all blank characters ahead and after .
464 * Remove 0x/0X if exists.
466 while (isblank(*coremask))
468 if (coremask[0] == '0' && ((coremask[1] == 'x')
469 || (coremask[1] == 'X')))
471 i = strlen(coremask);
472 while ((i > 0) && isblank(coremask[i - 1]))
477 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
479 if (isxdigit(c) == 0) {
480 /* invalid characters */
484 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
486 if ((1 << j) & val) {
493 if (coremask[i] != '0')
501 eal_parse_service_corelist(const char *corelist)
503 struct rte_config *cfg = rte_eal_get_configuration();
508 uint32_t taken_lcore_count = 0;
510 if (corelist == NULL)
513 /* Remove all blank characters ahead and after */
514 while (isblank(*corelist))
516 i = strlen(corelist);
517 while ((i > 0) && isblank(corelist[i - 1]))
520 /* Get list of cores */
523 while (isblank(*corelist))
525 if (*corelist == '\0')
528 idx = strtoul(corelist, &end, 10);
529 if (errno || end == NULL)
531 while (isblank(*end))
535 } else if ((*end == ',') || (*end == '\0')) {
537 if (min == RTE_MAX_LCORE)
539 for (idx = min; idx <= max; idx++) {
540 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
541 /* handle master lcore already parsed */
542 uint32_t lcore = idx;
543 if (cfg->master_lcore == lcore &&
544 master_lcore_parsed) {
546 "Error: lcore %u is master lcore, cannot use as service core\n",
550 if (cfg->lcore_role[idx] == ROLE_RTE)
553 lcore_config[idx].core_role =
562 } while (*end != '\0');
567 if (core_parsed && taken_lcore_count != count) {
568 RTE_LOG(WARNING, EAL,
569 "Not all service cores were in the coremask. "
570 "Please ensure -c or -l includes service cores\n");
577 eal_parse_corelist(const char *corelist, int *cores)
584 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
587 /* Remove all blank characters ahead */
588 while (isblank(*corelist))
591 /* Get list of cores */
594 while (isblank(*corelist))
596 if (*corelist == '\0')
599 idx = strtol(corelist, &end, 10);
600 if (errno || end == NULL)
602 if (idx < 0 || idx >= RTE_MAX_LCORE)
604 while (isblank(*end))
608 } else if ((*end == ',') || (*end == '\0')) {
610 if (min == RTE_MAX_LCORE)
612 for (idx = min; idx <= max; idx++) {
613 if (cores[idx] == -1) {
622 } while (*end != '\0');
629 /* Changes the lcore id of the master thread */
631 eal_parse_master_lcore(const char *arg)
634 struct rte_config *cfg = rte_eal_get_configuration();
637 cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
638 if (errno || parsing_end[0] != 0)
640 if (cfg->master_lcore >= RTE_MAX_LCORE)
642 master_lcore_parsed = 1;
644 /* ensure master core is not used as service core */
645 if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
647 "Error: Master lcore is used as a service core\n");
655 * Parse elem, the elem could be single number/range or '(' ')' group
656 * 1) A single number elem, it's just a simple digit. e.g. 9
657 * 2) A single range elem, two digits with a '-' between. e.g. 2-6
658 * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
659 * Within group elem, '-' used for a range separator;
660 * ',' used for a single number.
663 eal_parse_set(const char *input, uint16_t set[], unsigned num)
666 const char *str = input;
670 memset(set, 0, num * sizeof(uint16_t));
672 while (isblank(*str))
675 /* only digit or left bracket is qualify for start point */
676 if ((!isdigit(*str) && *str != '(') || *str == '\0')
679 /* process single number or single range of number */
682 idx = strtoul(str, &end, 10);
683 if (errno || end == NULL || idx >= num)
686 while (isblank(*end))
692 /* process single <number>-<number> */
694 while (isblank(*end))
700 idx = strtoul(end, &end, 10);
701 if (errno || end == NULL || idx >= num)
704 while (isblank(*end))
706 if (*end != ',' && *end != '\0')
710 if (*end != ',' && *end != '\0' &&
714 for (idx = RTE_MIN(min, max);
715 idx <= RTE_MAX(min, max); idx++)
722 /* process set within bracket */
724 while (isblank(*str))
732 /* go ahead to the first digit */
733 while (isblank(*str))
738 /* get the digit value */
740 idx = strtoul(str, &end, 10);
741 if (errno || end == NULL || idx >= num)
744 /* go ahead to separator '-',',' and ')' */
745 while (isblank(*end))
748 if (min == RTE_MAX_LCORE)
750 else /* avoid continuous '-' */
752 } else if ((*end == ',') || (*end == ')')) {
754 if (min == RTE_MAX_LCORE)
756 for (idx = RTE_MIN(min, max);
757 idx <= RTE_MAX(min, max); idx++)
765 } while (*end != '\0' && *end != ')');
768 * to avoid failure that tail blank makes end character check fail
769 * in eal_parse_lcores( )
771 while (isblank(*str))
777 /* convert from set array to cpuset bitmap */
779 convert_to_cpuset(rte_cpuset_t *cpusetp,
780 uint16_t *set, unsigned num)
786 for (idx = 0; idx < num; idx++) {
790 if (!lcore_config[idx].detected) {
791 RTE_LOG(ERR, EAL, "core %u "
792 "unavailable\n", idx);
796 CPU_SET(idx, cpusetp);
803 * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
804 * lcores, cpus could be a single digit/range or a group.
805 * '(' and ')' are necessary if it's a group.
806 * If not supply '@cpus', the value of cpus uses the same as lcores.
807 * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
808 * lcore 0 runs on cpuset 0x41 (cpu 0,6)
809 * lcore 1 runs on cpuset 0x2 (cpu 1)
810 * lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
811 * lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
812 * lcore 6 runs on cpuset 0x41 (cpu 0,6)
813 * lcore 7 runs on cpuset 0x80 (cpu 7)
814 * lcore 8 runs on cpuset 0x100 (cpu 8)
817 eal_parse_lcores(const char *lcores)
819 struct rte_config *cfg = rte_eal_get_configuration();
820 static uint16_t set[RTE_MAX_LCORE];
823 const char *lcore_start = NULL;
824 const char *end = NULL;
833 /* Remove all blank characters ahead and after */
834 while (isblank(*lcores))
839 /* Reset lcore config */
840 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
841 cfg->lcore_role[idx] = ROLE_OFF;
842 lcore_config[idx].core_index = -1;
843 CPU_ZERO(&lcore_config[idx].cpuset);
846 /* Get list of cores */
848 while (isblank(*lcores))
855 /* record lcore_set start point */
856 lcore_start = lcores;
858 /* go across a complete bracket */
859 if (*lcore_start == '(') {
860 lcores += strcspn(lcores, ")");
861 if (*lcores++ == '\0')
865 /* scan the separator '@', ','(next) or '\0'(finish) */
866 lcores += strcspn(lcores, "@,");
868 if (*lcores == '@') {
869 /* explicit assign cpu_set */
870 offset = eal_parse_set(lcores + 1, set, RTE_DIM(set));
874 /* prepare cpu_set and update the end cursor */
875 if (0 > convert_to_cpuset(&cpuset,
878 end = lcores + 1 + offset;
879 } else { /* ',' or '\0' */
880 /* haven't given cpu_set, current loop done */
883 /* go back to check <number>-<number> */
884 offset = strcspn(lcore_start, "(-");
885 if (offset < (end - lcore_start) &&
886 *(lcore_start + offset) != '(')
890 if (*end != ',' && *end != '\0')
893 /* parse lcore_set from start point */
894 if (0 > eal_parse_set(lcore_start, set, RTE_DIM(set)))
897 /* without '@', by default using lcore_set as cpu_set */
898 if (*lcores != '@' &&
899 0 > convert_to_cpuset(&cpuset, set, RTE_DIM(set)))
902 /* start to update lcore_set */
903 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
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);
917 rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
918 sizeof(rte_cpuset_t));
922 } while (*end != '\0');
927 cfg->lcore_count = count;
936 eal_parse_syslog(const char *facility, struct internal_config *conf)
939 static const struct {
943 { "auth", LOG_AUTH },
944 { "cron", LOG_CRON },
945 { "daemon", LOG_DAEMON },
947 { "kern", LOG_KERN },
949 { "mail", LOG_MAIL },
950 { "news", LOG_NEWS },
951 { "syslog", LOG_SYSLOG },
952 { "user", LOG_USER },
953 { "uucp", LOG_UUCP },
954 { "local0", LOG_LOCAL0 },
955 { "local1", LOG_LOCAL1 },
956 { "local2", LOG_LOCAL2 },
957 { "local3", LOG_LOCAL3 },
958 { "local4", LOG_LOCAL4 },
959 { "local5", LOG_LOCAL5 },
960 { "local6", LOG_LOCAL6 },
961 { "local7", LOG_LOCAL7 },
965 for (i = 0; map[i].name; i++) {
966 if (!strcmp(facility, map[i].name)) {
967 conf->syslog_facility = map[i].value;
975 eal_parse_log_priority(const char *level)
977 static const char * const levels[] = {
978 [RTE_LOG_EMERG] = "emergency",
979 [RTE_LOG_ALERT] = "alert",
980 [RTE_LOG_CRIT] = "critical",
981 [RTE_LOG_ERR] = "error",
982 [RTE_LOG_WARNING] = "warning",
983 [RTE_LOG_NOTICE] = "notice",
984 [RTE_LOG_INFO] = "info",
985 [RTE_LOG_DEBUG] = "debug",
987 size_t len = strlen(level);
995 /* look for named values, skip 0 which is not a valid level */
996 for (i = 1; i < RTE_DIM(levels); i++) {
997 if (strncmp(levels[i], level, len) == 0)
1001 /* not a string, maybe it is numeric */
1003 tmp = strtoul(level, &end, 0);
1005 /* check for errors */
1006 if (errno != 0 || end == NULL || *end != '\0' ||
1014 eal_parse_log_level(const char *arg)
1016 const char *pattern = NULL;
1017 const char *regex = NULL;
1025 if ((level = strchr(str, ','))) {
1028 } else if ((level = strchr(str, ':'))) {
1035 priority = eal_parse_log_priority(level);
1037 fprintf(stderr, "invalid log priority: %s\n", level);
1042 if (rte_log_set_level_regexp(regex, priority) < 0) {
1043 fprintf(stderr, "cannot set log level %s,%d\n",
1047 if (rte_log_save_regexp(regex, priority) < 0)
1049 } else if (pattern) {
1050 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1051 fprintf(stderr, "cannot set log level %s:%d\n",
1055 if (rte_log_save_pattern(pattern, priority) < 0)
1058 rte_log_set_global_level(priority);
1069 static enum rte_proc_type_t
1070 eal_parse_proc_type(const char *arg)
1072 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1073 return RTE_PROC_PRIMARY;
1074 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1075 return RTE_PROC_SECONDARY;
1076 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1077 return RTE_PROC_AUTO;
1079 return RTE_PROC_INVALID;
1083 eal_parse_iova_mode(const char *name)
1090 if (!strcmp("pa", name))
1092 else if (!strcmp("va", name))
1097 internal_config.iova_mode = mode;
1101 /* caller is responsible for freeing the returned string */
1103 available_cores(void)
1111 /* find the first available cpu */
1112 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1113 if (!lcore_config[idx].detected)
1117 if (idx >= RTE_MAX_LCORE)
1120 /* first sequence */
1121 if (asprintf(&str, "%d", idx) < 0)
1126 for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1127 if (!lcore_config[idx].detected)
1130 if (idx == previous + 1) {
1136 /* finish current sequence */
1138 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1147 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1157 /* finish last sequence */
1159 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1171 eal_parse_common_option(int opt, const char *optarg,
1172 struct internal_config *conf)
1182 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1192 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1200 int lcore_indexes[RTE_MAX_LCORE];
1202 if (eal_service_cores_parsed())
1203 RTE_LOG(WARNING, EAL,
1204 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1205 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1206 RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1209 if (update_lcore_config(lcore_indexes) < 0) {
1210 char *available = available_cores();
1213 "invalid coremask, please check specified cores are part of %s\n",
1220 RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1221 (core_parsed == LCORE_OPT_LST) ? "-l" :
1222 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1227 core_parsed = LCORE_OPT_MSK;
1232 int lcore_indexes[RTE_MAX_LCORE];
1234 if (eal_service_cores_parsed())
1235 RTE_LOG(WARNING, EAL,
1236 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1238 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1239 RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1242 if (update_lcore_config(lcore_indexes) < 0) {
1243 char *available = available_cores();
1246 "invalid core list, please check specified cores are part of %s\n",
1253 RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1254 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1255 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1260 core_parsed = LCORE_OPT_LST;
1263 /* service coremask */
1265 if (eal_parse_service_coremask(optarg) < 0) {
1266 RTE_LOG(ERR, EAL, "invalid service coremask\n");
1270 /* service corelist */
1272 if (eal_parse_service_corelist(optarg) < 0) {
1273 RTE_LOG(ERR, EAL, "invalid service core list\n");
1277 /* size of memory */
1279 conf->memory = atoi(optarg);
1280 conf->memory *= 1024ULL;
1281 conf->memory *= 1024ULL;
1284 /* force number of channels */
1286 conf->force_nchannel = atoi(optarg);
1287 if (conf->force_nchannel == 0) {
1288 RTE_LOG(ERR, EAL, "invalid channel number\n");
1292 /* force number of ranks */
1294 conf->force_nrank = atoi(optarg);
1295 if (conf->force_nrank == 0 ||
1296 conf->force_nrank > 16) {
1297 RTE_LOG(ERR, EAL, "invalid rank number\n");
1301 /* force loading of external driver */
1303 if (eal_plugin_add(optarg) == -1)
1307 /* since message is explicitly requested by user, we
1308 * write message at highest log level so it can always
1310 * even if info or warning messages are disabled */
1311 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1315 case OPT_HUGE_UNLINK_NUM:
1316 conf->hugepage_unlink = 1;
1319 case OPT_NO_HUGE_NUM:
1320 conf->no_hugetlbfs = 1;
1321 /* no-huge is legacy mem */
1322 conf->legacy_mem = 1;
1325 case OPT_NO_PCI_NUM:
1329 case OPT_NO_HPET_NUM:
1333 case OPT_VMWARE_TSC_MAP_NUM:
1334 conf->vmware_tsc_map = 1;
1337 case OPT_NO_SHCONF_NUM:
1338 conf->no_shconf = 1;
1341 case OPT_IN_MEMORY_NUM:
1342 conf->in_memory = 1;
1343 /* in-memory is a superset of noshconf and huge-unlink */
1344 conf->no_shconf = 1;
1345 conf->hugepage_unlink = 1;
1348 case OPT_PROC_TYPE_NUM:
1349 conf->process_type = eal_parse_proc_type(optarg);
1352 case OPT_MASTER_LCORE_NUM:
1353 if (eal_parse_master_lcore(optarg) < 0) {
1354 RTE_LOG(ERR, EAL, "invalid parameter for --"
1355 OPT_MASTER_LCORE "\n");
1361 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1367 case OPT_SYSLOG_NUM:
1368 if (eal_parse_syslog(optarg, conf) < 0) {
1369 RTE_LOG(ERR, EAL, "invalid parameters for --"
1375 case OPT_LOG_LEVEL_NUM: {
1376 if (eal_parse_log_level(optarg) < 0) {
1378 "invalid parameters for --"
1379 OPT_LOG_LEVEL "\n");
1384 case OPT_LCORES_NUM:
1385 if (eal_parse_lcores(optarg) < 0) {
1386 RTE_LOG(ERR, EAL, "invalid parameter for --"
1392 RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1393 (core_parsed == LCORE_OPT_LST) ? "-l" :
1394 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1399 core_parsed = LCORE_OPT_MAP;
1401 case OPT_LEGACY_MEM_NUM:
1402 conf->legacy_mem = 1;
1404 case OPT_SINGLE_FILE_SEGMENTS_NUM:
1405 conf->single_file_segments = 1;
1407 case OPT_IOVA_MODE_NUM:
1408 if (eal_parse_iova_mode(optarg) < 0) {
1409 RTE_LOG(ERR, EAL, "invalid parameters for --"
1410 OPT_IOVA_MODE "\n");
1415 /* don't know what to do, leave this to caller */
1423 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1424 "cannot be used at the same time\n");
1429 eal_auto_detect_cores(struct rte_config *cfg)
1431 unsigned int lcore_id;
1432 unsigned int removed = 0;
1433 rte_cpuset_t affinity_set;
1435 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1437 CPU_ZERO(&affinity_set);
1439 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1440 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1441 !CPU_ISSET(lcore_id, &affinity_set)) {
1442 cfg->lcore_role[lcore_id] = ROLE_OFF;
1447 cfg->lcore_count -= removed;
1451 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1453 rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1454 rte_cpuset_t default_set;
1455 unsigned int lcore_id;
1457 for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1458 if (eal_cpu_detected(lcore_id) &&
1459 rte_lcore_has_role(lcore_id, ROLE_OFF)) {
1460 CPU_SET(lcore_id, cpuset);
1464 if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1466 CPU_ZERO(&default_set);
1468 RTE_CPU_AND(cpuset, cpuset, &default_set);
1470 /* if no detected CPU is off, use master core */
1471 if (!CPU_COUNT(cpuset))
1472 CPU_SET(rte_get_master_lcore(), cpuset);
1476 eal_cleanup_config(struct internal_config *internal_cfg)
1478 if (internal_cfg->hugefile_prefix != NULL)
1479 free(internal_cfg->hugefile_prefix);
1480 if (internal_cfg->hugepage_dir != NULL)
1481 free(internal_cfg->hugepage_dir);
1482 if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1483 free(internal_cfg->user_mbuf_pool_ops_name);
1489 eal_adjust_config(struct internal_config *internal_cfg)
1492 struct rte_config *cfg = rte_eal_get_configuration();
1495 eal_auto_detect_cores(cfg);
1497 if (internal_config.process_type == RTE_PROC_AUTO)
1498 internal_config.process_type = eal_proc_type_detect();
1500 /* default master lcore is the first one */
1501 if (!master_lcore_parsed) {
1502 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1503 if (cfg->master_lcore >= RTE_MAX_LCORE)
1505 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1508 compute_ctrl_threads_cpuset(internal_cfg);
1510 /* if no memory amounts were requested, this will result in 0 and
1511 * will be overridden later, right after eal_hugepage_info_init() */
1512 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1513 internal_cfg->memory += internal_cfg->socket_mem[i];
1519 eal_check_common_options(struct internal_config *internal_cfg)
1521 struct rte_config *cfg = rte_eal_get_configuration();
1523 if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1524 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1528 if (internal_cfg->process_type == RTE_PROC_INVALID) {
1529 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1532 if (internal_cfg->hugefile_prefix != NULL &&
1533 strlen(internal_cfg->hugefile_prefix) < 1) {
1534 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1537 if (internal_cfg->hugepage_dir != NULL &&
1538 strlen(internal_cfg->hugepage_dir) < 1) {
1539 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1542 if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1543 strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1544 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1547 if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1548 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1552 if (mem_parsed && internal_cfg->force_sockets == 1) {
1553 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1554 "be specified at the same time\n");
1557 if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1558 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1559 "be specified together with --"OPT_NO_HUGE"\n");
1562 if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1563 !internal_cfg->in_memory) {
1564 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1565 "be specified together with --"OPT_NO_HUGE"\n");
1568 if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1569 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1570 " is only supported in non-legacy memory mode\n");
1572 if (internal_cfg->single_file_segments &&
1573 internal_cfg->hugepage_unlink &&
1574 !internal_cfg->in_memory) {
1575 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1576 "not compatible with --"OPT_HUGE_UNLINK"\n");
1579 if (internal_cfg->legacy_mem &&
1580 internal_cfg->in_memory) {
1581 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1582 "with --"OPT_IN_MEMORY"\n");
1585 if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1586 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1587 "with --"OPT_MATCH_ALLOCATIONS"\n");
1590 if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1591 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1592 "with --"OPT_MATCH_ALLOCATIONS"\n");
1600 eal_common_usage(void)
1602 printf("[options]\n\n"
1603 "EAL common options:\n"
1604 " -c COREMASK Hexadecimal bitmask of cores to run on\n"
1605 " -l CORELIST List of cores to run on\n"
1606 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
1607 " where c1, c2, etc are core indexes between 0 and %d\n"
1608 " --"OPT_LCORES" COREMAP Map lcore set to physical cpu set\n"
1609 " The argument format is\n"
1610 " '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1611 " lcores and cpus list are grouped by '(' and ')'\n"
1612 " Within the group, '-' is used for range separator,\n"
1613 " ',' is used for single number separator.\n"
1614 " '( )' can be omitted for single element group,\n"
1615 " '@' can be omitted if cpus and lcores have the same value\n"
1616 " -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1617 " --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
1618 " --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1619 " -n CHANNELS Number of memory channels\n"
1620 " -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1621 " -r RANKS Force number of memory ranks (don't detect)\n"
1622 " -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1623 " Prevent EAL from using this PCI device. The argument\n"
1624 " format is <domain:bus:devid.func>.\n"
1625 " -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1626 " Only use the specified PCI devices. The argument format\n"
1627 " is <[domain:]bus:devid.func>. This option can be present\n"
1628 " several times (once per device).\n"
1629 " [NOTE: PCI whitelist cannot be used with -b option]\n"
1630 " --"OPT_VDEV" Add a virtual device.\n"
1631 " The argument format is <driver><id>[,key=val,...]\n"
1632 " (ex: --vdev=net_pcap0,iface=eth2).\n"
1633 " --"OPT_IOVA_MODE" Set IOVA mode. 'pa' for IOVA_PA\n"
1634 " 'va' for IOVA_VA\n"
1635 " -d LIB.so|DIR Add a driver or driver directory\n"
1636 " (can be used multiple times)\n"
1637 " --"OPT_VMWARE_TSC_MAP" Use VMware TSC map instead of native RDTSC\n"
1638 " --"OPT_PROC_TYPE" Type of this process (primary|secondary|auto)\n"
1639 " --"OPT_SYSLOG" Set syslog facility\n"
1640 " --"OPT_LOG_LEVEL"=<int> Set global log level\n"
1641 " --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1642 " Set specific log level\n"
1643 " -v Display version information on startup\n"
1644 " -h, --help This help\n"
1645 " --"OPT_IN_MEMORY" Operate entirely in memory. This will\n"
1646 " disable secondary process support\n"
1647 "\nEAL options for DEBUG use only:\n"
1648 " --"OPT_HUGE_UNLINK" Unlink hugepage files after init\n"
1649 " --"OPT_NO_HUGE" Use malloc instead of hugetlbfs\n"
1650 " --"OPT_NO_PCI" Disable PCI\n"
1651 " --"OPT_NO_HPET" Disable HPET\n"
1652 " --"OPT_NO_SHCONF" No shared config (mmap'd files)\n"
1653 "\n", RTE_MAX_LCORE);