1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation.
3 * Copyright(c) 2012-2014 6WIND S.A.
23 #include <sys/queue.h>
25 #if defined(RTE_ARCH_X86)
29 #include <rte_compat.h>
30 #include <rte_common.h>
31 #include <rte_debug.h>
32 #include <rte_memory.h>
33 #include <rte_launch.h>
35 #include <rte_eal_memconfig.h>
36 #include <rte_errno.h>
37 #include <rte_per_lcore.h>
38 #include <rte_lcore.h>
39 #include <rte_service_component.h>
41 #include <rte_random.h>
42 #include <rte_cycles.h>
43 #include <rte_string_fns.h>
44 #include <rte_cpuflags.h>
45 #include <rte_interrupts.h>
48 #include <rte_devargs.h>
49 #include <rte_version.h>
50 #include <rte_atomic.h>
51 #include <malloc_heap.h>
53 #include <rte_option.h>
55 #include "eal_private.h"
56 #include "eal_thread.h"
57 #include "eal_internal_cfg.h"
58 #include "eal_filesystem.h"
59 #include "eal_hugepages.h"
60 #include "eal_options.h"
62 #include "hotplug_mp.h"
64 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
66 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
68 /* Allow the application to print its usage message too if set */
69 static rte_usage_hook_t rte_application_usage_hook = NULL;
71 /* early configuration structure, when memory config is not mmapped */
72 static struct rte_mem_config early_mem_config;
74 /* define fd variable here, because file needs to be kept open for the
75 * duration of the program, as we hold a write lock on it in the primary proc */
76 static int mem_cfg_fd = -1;
78 static struct flock wr_lock = {
81 .l_start = offsetof(struct rte_mem_config, memsegs),
82 .l_len = sizeof(early_mem_config.memsegs),
85 /* Address of global and public configuration */
86 static struct rte_config rte_config = {
87 .mem_config = &early_mem_config,
90 /* internal configuration (per-core) */
91 struct lcore_config lcore_config[RTE_MAX_LCORE];
93 /* internal configuration */
94 struct internal_config internal_config;
96 /* used by rte_rdtsc() */
97 int rte_cycles_vmware_tsc_map;
99 /* platform-specific runtime dir */
100 static char runtime_dir[PATH_MAX];
102 static const char *default_runtime_dir = "/var/run";
105 eal_create_runtime_dir(void)
107 const char *directory = default_runtime_dir;
108 const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
109 const char *fallback = "/tmp";
114 /* try XDG path first, fall back to /tmp */
115 if (xdg_runtime_dir != NULL)
116 directory = xdg_runtime_dir;
118 directory = fallback;
120 /* create DPDK subdirectory under runtime dir */
121 ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
122 if (ret < 0 || ret == sizeof(tmp)) {
123 RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
127 /* create prefix-specific subdirectory under DPDK runtime dir */
128 ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
129 tmp, eal_get_hugefile_prefix());
130 if (ret < 0 || ret == sizeof(runtime_dir)) {
131 RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
135 /* create the path if it doesn't exist. no "mkdir -p" here, so do it
138 ret = mkdir(tmp, 0700);
139 if (ret < 0 && errno != EEXIST) {
140 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
141 tmp, strerror(errno));
145 ret = mkdir(runtime_dir, 0700);
146 if (ret < 0 && errno != EEXIST) {
147 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
148 runtime_dir, strerror(errno));
156 eal_clean_runtime_dir(void)
159 struct dirent *dirent;
160 int dir_fd, fd, lck_result;
161 static const char * const filters[] = {
167 dir = opendir(runtime_dir);
169 RTE_LOG(ERR, EAL, "Unable to open runtime directory %s\n",
175 /* lock the directory before doing anything, to avoid races */
176 if (flock(dir_fd, LOCK_EX) < 0) {
177 RTE_LOG(ERR, EAL, "Unable to lock runtime directory %s\n",
182 dirent = readdir(dir);
184 RTE_LOG(ERR, EAL, "Unable to read runtime directory %s\n",
189 while (dirent != NULL) {
193 /* skip files that don't match the patterns */
194 for (f_idx = 0; f_idx < RTE_DIM(filters); f_idx++) {
195 const char *filter = filters[f_idx];
197 if (fnmatch(filter, dirent->d_name, 0) == 0) {
203 dirent = readdir(dir);
207 /* try and lock the file */
208 fd = openat(dir_fd, dirent->d_name, O_RDONLY);
210 /* skip to next file */
212 dirent = readdir(dir);
216 /* non-blocking lock */
217 lck_result = flock(fd, LOCK_EX | LOCK_NB);
219 /* if lock succeeds, remove the file */
220 if (lck_result != -1)
221 unlinkat(dir_fd, dirent->d_name, 0);
223 dirent = readdir(dir);
226 /* closedir closes dir_fd and drops the lock */
234 RTE_LOG(ERR, EAL, "Error while clearing runtime dir: %s\n",
241 rte_eal_get_runtime_dir(void)
246 /* Return user provided mbuf pool ops name */
248 rte_eal_mbuf_user_pool_ops(void)
250 return internal_config.user_mbuf_pool_ops_name;
253 /* Return a pointer to the configuration structure */
255 rte_eal_get_configuration(void)
261 rte_eal_iova_mode(void)
263 return rte_eal_get_configuration()->iova_mode;
266 /* parse a sysfs (or other) file containing one integer value */
268 eal_parse_sysfs_value(const char *filename, unsigned long *val)
274 if ((f = fopen(filename, "r")) == NULL) {
275 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
280 if (fgets(buf, sizeof(buf), f) == NULL) {
281 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
286 *val = strtoul(buf, &end, 0);
287 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
288 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
298 /* create memory configuration in shared/mmap memory. Take out
299 * a write lock on the memsegs, so we can auto-detect primary/secondary.
300 * This means we never close the file while running (auto-close on exit).
301 * We also don't lock the whole file, so that in future we can use read-locks
302 * on other parts, e.g. memzones, to detect if there are running secondary
305 rte_eal_config_create(void)
307 void *rte_mem_cfg_addr;
310 const char *pathname = eal_runtime_config_path();
312 if (internal_config.no_shconf)
315 /* map the config before hugepage address so that we don't waste a page */
316 if (internal_config.base_virtaddr != 0)
317 rte_mem_cfg_addr = (void *)
318 RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
319 sizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));
321 rte_mem_cfg_addr = NULL;
324 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
325 if (mem_cfg_fd < 0) {
326 RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
332 retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
336 RTE_LOG(ERR, EAL, "Cannot resize '%s' for rte_mem_config\n",
341 retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
345 RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary "
346 "process running?\n", pathname);
350 rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),
351 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
353 if (rte_mem_cfg_addr == MAP_FAILED){
356 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config\n");
360 memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
361 rte_config.mem_config = rte_mem_cfg_addr;
363 /* store address of the config in the config itself so that secondary
364 * processes could later map the config into this exact location */
365 rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
367 rte_config.mem_config->dma_maskbits = 0;
372 /* attach to an existing shared memory config */
374 rte_eal_config_attach(void)
376 struct rte_mem_config *mem_config;
378 const char *pathname = eal_runtime_config_path();
380 if (internal_config.no_shconf)
384 mem_cfg_fd = open(pathname, O_RDWR);
385 if (mem_cfg_fd < 0) {
386 RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
392 /* map it as read-only first */
393 mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
394 PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
395 if (mem_config == MAP_FAILED) {
398 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
399 errno, strerror(errno));
403 rte_config.mem_config = mem_config;
408 /* reattach the shared config at exact memory location primary process has it */
410 rte_eal_config_reattach(void)
412 struct rte_mem_config *mem_config;
413 void *rte_mem_cfg_addr;
415 if (internal_config.no_shconf)
418 /* save the address primary process has mapped shared config to */
419 rte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr;
421 /* unmap original config */
422 munmap(rte_config.mem_config, sizeof(struct rte_mem_config));
424 /* remap the config at proper address */
425 mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
426 sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
432 if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
433 if (mem_config != MAP_FAILED) {
434 /* errno is stale, don't use */
435 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config at [%p], got [%p]"
436 " - please use '--base-virtaddr' option\n",
437 rte_mem_cfg_addr, mem_config);
440 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
441 errno, strerror(errno));
445 rte_config.mem_config = mem_config;
450 /* Detect if we are a primary or a secondary process */
452 eal_proc_type_detect(void)
454 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
455 const char *pathname = eal_runtime_config_path();
457 /* if there no shared config, there can be no secondary processes */
458 if (!internal_config.no_shconf) {
459 /* if we can open the file but not get a write-lock we are a
460 * secondary process. NOTE: if we get a file handle back, we
461 * keep that open and don't close it to prevent a race condition
462 * between multiple opens.
464 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
465 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
466 ptype = RTE_PROC_SECONDARY;
469 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
470 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
475 /* copies data from internal config to shared config */
477 eal_update_mem_config(void)
479 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
480 mcfg->legacy_mem = internal_config.legacy_mem;
481 mcfg->single_file_segments = internal_config.single_file_segments;
484 /* copies data from shared config to internal config */
486 eal_update_internal_config(void)
488 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
489 internal_config.legacy_mem = mcfg->legacy_mem;
490 internal_config.single_file_segments = mcfg->single_file_segments;
493 /* Sets up rte_config structure with the pointer to shared memory config.*/
495 rte_config_init(void)
497 rte_config.process_type = internal_config.process_type;
499 switch (rte_config.process_type){
500 case RTE_PROC_PRIMARY:
501 if (rte_eal_config_create() < 0)
503 eal_update_mem_config();
505 case RTE_PROC_SECONDARY:
506 if (rte_eal_config_attach() < 0)
508 rte_eal_mcfg_wait_complete(rte_config.mem_config);
509 if (rte_eal_config_reattach() < 0)
511 eal_update_internal_config();
514 case RTE_PROC_INVALID:
515 RTE_LOG(ERR, EAL, "Invalid process type %d\n",
516 rte_config.process_type);
523 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
525 eal_hugedirs_unlock(void)
529 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
531 /* skip uninitialized */
532 if (internal_config.hugepage_info[i].lock_descriptor < 0)
534 /* unlock hugepage file */
535 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
536 close(internal_config.hugepage_info[i].lock_descriptor);
537 /* reset the field */
538 internal_config.hugepage_info[i].lock_descriptor = -1;
544 eal_usage(const char *prgname)
546 printf("\nUsage: %s ", prgname);
548 printf("EAL Linux options:\n"
549 " --"OPT_SOCKET_MEM" Memory to allocate on sockets (comma separated values)\n"
550 " --"OPT_SOCKET_LIMIT" Limit memory allocation on sockets (comma separated values)\n"
551 " --"OPT_HUGE_DIR" Directory where hugetlbfs is mounted\n"
552 " --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n"
553 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
554 " --"OPT_CREATE_UIO_DEV" Create /dev/uioX (usually done by hotplug)\n"
555 " --"OPT_VFIO_INTR" Interrupt mode for VFIO (legacy|msi|msix)\n"
556 " --"OPT_LEGACY_MEM" Legacy memory mode (no dynamic allocation, contiguous segments)\n"
557 " --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
558 " --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
560 /* Allow the application to print its usage message too if hook is set */
561 if ( rte_application_usage_hook ) {
562 printf("===== Application Usage =====\n\n");
563 rte_application_usage_hook(prgname);
567 /* Set a per-application usage message */
569 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
571 rte_usage_hook_t old_func;
573 /* Will be NULL on the first call to denote the last usage routine. */
574 old_func = rte_application_usage_hook;
575 rte_application_usage_hook = usage_func;
581 eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
583 char * arg[RTE_MAX_NUMA_NODES];
586 uint64_t total_mem = 0;
588 len = strnlen(strval, SOCKET_MEM_STRLEN);
589 if (len == SOCKET_MEM_STRLEN) {
590 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
594 /* all other error cases will be caught later */
595 if (!isdigit(strval[len-1]))
598 /* split the optarg into separate socket values */
599 arg_num = rte_strsplit(strval, len,
600 arg, RTE_MAX_NUMA_NODES, ',');
602 /* if split failed, or 0 arguments */
606 /* parse each defined socket option */
608 for (i = 0; i < arg_num; i++) {
611 val = strtoull(arg[i], &end, 10);
613 /* check for invalid input */
615 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
626 eal_parse_base_virtaddr(const char *arg)
632 addr = strtoull(arg, &end, 16);
634 /* check for errors */
635 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
638 /* make sure we don't exceed 32-bit boundary on 32-bit target */
640 if (addr >= UINTPTR_MAX)
644 /* align the addr on 16M boundary, 16MB is the minimum huge page
645 * size on IBM Power architecture. If the addr is aligned to 16MB,
646 * it can align to 2MB for x86. So this alignment can also be used
648 internal_config.base_virtaddr =
649 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
655 eal_parse_vfio_intr(const char *mode)
660 enum rte_intr_mode value;
662 { "legacy", RTE_INTR_MODE_LEGACY },
663 { "msi", RTE_INTR_MODE_MSI },
664 { "msix", RTE_INTR_MODE_MSIX },
667 for (i = 0; i < RTE_DIM(map); i++) {
668 if (!strcmp(mode, map[i].name)) {
669 internal_config.vfio_intr_mode = map[i].value;
676 /* Parse the arguments for --log-level only */
678 eal_log_level_parse(int argc, char **argv)
683 const int old_optind = optind;
684 const int old_optopt = optopt;
685 char * const old_optarg = optarg;
690 while ((opt = getopt_long(argc, argvopt, eal_short_options,
691 eal_long_options, &option_index)) != EOF) {
695 /* getopt is not happy, stop right now */
699 ret = (opt == OPT_LOG_LEVEL_NUM) ?
700 eal_parse_common_option(opt, optarg, &internal_config) : 0;
702 /* common parser is not happy */
707 /* restore getopt lib */
713 /* Parse the argument given in the command line of the application */
715 eal_parse_args(int argc, char **argv)
720 char *prgname = argv[0];
721 const int old_optind = optind;
722 const int old_optopt = optopt;
723 char * const old_optarg = optarg;
729 while ((opt = getopt_long(argc, argvopt, eal_short_options,
730 eal_long_options, &option_index)) != EOF) {
733 * getopt didn't recognise the option, lets parse the
734 * registered options to see if the flag is valid
737 ret = rte_option_parse(argv[optind-1]);
746 ret = eal_parse_common_option(opt, optarg, &internal_config);
747 /* common parser is not happy */
753 /* common parser handled this option */
762 case OPT_HUGE_DIR_NUM:
764 char *hdir = strdup(optarg);
766 RTE_LOG(ERR, EAL, "Could not store hugepage directory\n");
768 /* free old hugepage dir */
769 if (internal_config.hugepage_dir != NULL)
770 free(internal_config.hugepage_dir);
771 internal_config.hugepage_dir = hdir;
775 case OPT_FILE_PREFIX_NUM:
777 char *prefix = strdup(optarg);
779 RTE_LOG(ERR, EAL, "Could not store file prefix\n");
781 /* free old prefix */
782 if (internal_config.hugefile_prefix != NULL)
783 free(internal_config.hugefile_prefix);
784 internal_config.hugefile_prefix = prefix;
788 case OPT_SOCKET_MEM_NUM:
789 if (eal_parse_socket_arg(optarg,
790 internal_config.socket_mem) < 0) {
791 RTE_LOG(ERR, EAL, "invalid parameters for --"
792 OPT_SOCKET_MEM "\n");
797 internal_config.force_sockets = 1;
800 case OPT_SOCKET_LIMIT_NUM:
801 if (eal_parse_socket_arg(optarg,
802 internal_config.socket_limit) < 0) {
803 RTE_LOG(ERR, EAL, "invalid parameters for --"
804 OPT_SOCKET_LIMIT "\n");
809 internal_config.force_socket_limits = 1;
812 case OPT_BASE_VIRTADDR_NUM:
813 if (eal_parse_base_virtaddr(optarg) < 0) {
814 RTE_LOG(ERR, EAL, "invalid parameter for --"
815 OPT_BASE_VIRTADDR "\n");
822 case OPT_VFIO_INTR_NUM:
823 if (eal_parse_vfio_intr(optarg) < 0) {
824 RTE_LOG(ERR, EAL, "invalid parameters for --"
832 case OPT_CREATE_UIO_DEV_NUM:
833 internal_config.create_uio_dev = 1;
836 case OPT_MBUF_POOL_OPS_NAME_NUM:
838 char *ops_name = strdup(optarg);
839 if (ops_name == NULL)
840 RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n");
842 /* free old ops name */
843 if (internal_config.user_mbuf_pool_ops_name !=
845 free(internal_config.user_mbuf_pool_ops_name);
847 internal_config.user_mbuf_pool_ops_name =
852 case OPT_MATCH_ALLOCATIONS_NUM:
853 internal_config.match_allocations = 1;
857 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
858 RTE_LOG(ERR, EAL, "Option %c is not supported "
860 } else if (opt >= OPT_LONG_MIN_NUM &&
861 opt < OPT_LONG_MAX_NUM) {
862 RTE_LOG(ERR, EAL, "Option %s is not supported "
864 eal_long_options[option_index].name);
866 RTE_LOG(ERR, EAL, "Option %d is not supported "
875 /* create runtime data directory */
876 if (internal_config.no_shconf == 0 &&
877 eal_create_runtime_dir() < 0) {
878 RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
883 if (eal_adjust_config(&internal_config) != 0) {
889 if (eal_check_common_options(&internal_config) != 0) {
896 argv[optind-1] = prgname;
900 /* restore getopt lib */
909 check_socket(const struct rte_memseg_list *msl, void *arg)
911 int *socket_id = arg;
916 return *socket_id == msl->socket_id;
920 eal_check_mem_on_local_socket(void)
924 socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
926 if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
927 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
931 sync_func(__attribute__((unused)) void *arg)
937 rte_eal_mcfg_complete(void)
939 /* ALL shared mem_config related INIT DONE */
940 if (rte_config.process_type == RTE_PROC_PRIMARY)
941 rte_config.mem_config->magic = RTE_MAGIC;
943 internal_config.init_complete = 1;
947 * Request iopl privilege for all RPL, returns 0 on success
948 * iopl() call is mostly for the i386 architecture. For other architectures,
949 * return -1 to indicate IO privilege can't be changed in this way.
952 rte_eal_iopl_init(void)
954 #if defined(RTE_ARCH_X86)
962 static int rte_eal_vfio_setup(void)
964 if (rte_vfio_enable("vfio"))
971 static void rte_eal_init_alert(const char *msg)
973 fprintf(stderr, "EAL: FATAL: %s\n", msg);
974 RTE_LOG(ERR, EAL, "%s\n", msg);
977 /* Launch threads, called at application init(). */
979 rte_eal_init(int argc, char **argv)
983 static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
985 static char logid[PATH_MAX];
986 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
987 char thread_name[RTE_MAX_THREAD_NAME_LEN];
989 /* checks if the machine is adequate */
990 if (!rte_cpu_is_supported()) {
991 rte_eal_init_alert("unsupported cpu type.");
996 if (!rte_atomic32_test_and_set(&run_once)) {
997 rte_eal_init_alert("already called initialization.");
998 rte_errno = EALREADY;
1002 p = strrchr(argv[0], '/');
1003 strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
1004 thread_id = pthread_self();
1006 eal_reset_internal_config(&internal_config);
1008 /* set log level as early as possible */
1009 eal_log_level_parse(argc, argv);
1011 if (rte_eal_cpu_init() < 0) {
1012 rte_eal_init_alert("Cannot detect lcores.");
1013 rte_errno = ENOTSUP;
1017 fctret = eal_parse_args(argc, argv);
1019 rte_eal_init_alert("Invalid 'command line' arguments.");
1021 rte_atomic32_clear(&run_once);
1025 if (eal_plugins_init() < 0) {
1026 rte_eal_init_alert("Cannot init plugins");
1028 rte_atomic32_clear(&run_once);
1032 if (eal_option_device_parse()) {
1034 rte_atomic32_clear(&run_once);
1038 if (rte_config_init() < 0) {
1039 rte_eal_init_alert("Cannot init config");
1043 if (rte_eal_intr_init() < 0) {
1044 rte_eal_init_alert("Cannot init interrupt-handling thread");
1048 if (rte_eal_alarm_init() < 0) {
1049 rte_eal_init_alert("Cannot init alarm");
1050 /* rte_eal_alarm_init sets rte_errno on failure. */
1054 /* Put mp channel init before bus scan so that we can init the vdev
1055 * bus through mp channel in the secondary process before the bus scan.
1057 if (rte_mp_channel_init() < 0 && rte_errno != ENOTSUP) {
1058 rte_eal_init_alert("failed to init mp channel");
1059 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1065 /* register multi-process action callbacks for hotplug */
1066 if (eal_mp_dev_hotplug_init() < 0) {
1067 rte_eal_init_alert("failed to register mp callback for hotplug");
1071 if (rte_bus_scan()) {
1072 rte_eal_init_alert("Cannot scan the buses for devices");
1074 rte_atomic32_clear(&run_once);
1078 /* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */
1079 if (internal_config.iova_mode == RTE_IOVA_DC) {
1080 /* autodetect the IOVA mapping mode (default is RTE_IOVA_PA) */
1081 rte_eal_get_configuration()->iova_mode =
1082 rte_bus_get_iommu_class();
1084 /* Workaround for KNI which requires physical address to work */
1085 if (rte_eal_get_configuration()->iova_mode == RTE_IOVA_VA &&
1086 rte_eal_check_module("rte_kni") == 1) {
1087 rte_eal_get_configuration()->iova_mode = RTE_IOVA_PA;
1088 RTE_LOG(WARNING, EAL,
1089 "Some devices want IOVA as VA but PA will be used because.. "
1090 "KNI module inserted\n");
1093 rte_eal_get_configuration()->iova_mode =
1094 internal_config.iova_mode;
1097 if (internal_config.no_hugetlbfs == 0) {
1098 /* rte_config isn't initialized yet */
1099 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
1100 eal_hugepage_info_init() :
1101 eal_hugepage_info_read();
1103 rte_eal_init_alert("Cannot get hugepage information.");
1105 rte_atomic32_clear(&run_once);
1110 if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
1111 if (internal_config.no_hugetlbfs)
1112 internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
1115 if (internal_config.vmware_tsc_map == 1) {
1116 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
1117 rte_cycles_vmware_tsc_map = 1;
1118 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
1119 "you must have monitor_control.pseudo_perfctr = TRUE\n");
1121 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
1122 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
1126 if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) {
1127 rte_eal_init_alert("Cannot init logging.");
1129 rte_atomic32_clear(&run_once);
1134 if (rte_eal_vfio_setup() < 0) {
1135 rte_eal_init_alert("Cannot init VFIO");
1137 rte_atomic32_clear(&run_once);
1141 /* in secondary processes, memory init may allocate additional fbarrays
1142 * not present in primary processes, so to avoid any potential issues,
1143 * initialize memzones first.
1145 if (rte_eal_memzone_init() < 0) {
1146 rte_eal_init_alert("Cannot init memzone");
1151 if (rte_eal_memory_init() < 0) {
1152 rte_eal_init_alert("Cannot init memory");
1157 /* the directories are locked during eal_hugepage_info_init */
1158 eal_hugedirs_unlock();
1160 if (rte_eal_malloc_heap_init() < 0) {
1161 rte_eal_init_alert("Cannot init malloc heap");
1166 if (rte_eal_tailqs_init() < 0) {
1167 rte_eal_init_alert("Cannot init tail queues for objects");
1172 if (rte_eal_timer_init() < 0) {
1173 rte_eal_init_alert("Cannot init HPET or TSC timers");
1174 rte_errno = ENOTSUP;
1178 eal_check_mem_on_local_socket();
1180 eal_thread_init_master(rte_config.master_lcore);
1182 ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
1184 RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
1185 rte_config.master_lcore, (uintptr_t)thread_id, cpuset,
1186 ret == 0 ? "" : "...");
1188 RTE_LCORE_FOREACH_SLAVE(i) {
1191 * create communication pipes between master thread
1194 if (pipe(lcore_config[i].pipe_master2slave) < 0)
1195 rte_panic("Cannot create pipe\n");
1196 if (pipe(lcore_config[i].pipe_slave2master) < 0)
1197 rte_panic("Cannot create pipe\n");
1199 lcore_config[i].state = WAIT;
1201 /* create a thread for each lcore */
1202 ret = pthread_create(&lcore_config[i].thread_id, NULL,
1203 eal_thread_loop, NULL);
1205 rte_panic("Cannot create thread\n");
1207 /* Set thread_name for aid in debugging. */
1208 snprintf(thread_name, sizeof(thread_name),
1209 "lcore-slave-%d", i);
1210 ret = rte_thread_setname(lcore_config[i].thread_id,
1214 "Cannot set name for lcore thread\n");
1218 * Launch a dummy function on all slave lcores, so that master lcore
1219 * knows they are all ready when this function returns.
1221 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
1222 rte_eal_mp_wait_lcore();
1224 /* initialize services so vdevs register service during bus_probe. */
1225 ret = rte_service_init();
1227 rte_eal_init_alert("rte_service_init() failed");
1228 rte_errno = ENOEXEC;
1232 /* Probe all the buses and devices/drivers on them */
1233 if (rte_bus_probe()) {
1234 rte_eal_init_alert("Cannot probe devices");
1235 rte_errno = ENOTSUP;
1240 /* Register mp action after probe() so that we got enough info */
1241 if (rte_vfio_is_enabled("vfio") && vfio_mp_sync_setup() < 0)
1245 /* initialize default service/lcore mappings and start running. Ignore
1246 * -ENOTSUP, as it indicates no service coremask passed to EAL.
1248 ret = rte_service_start_with_defaults();
1249 if (ret < 0 && ret != -ENOTSUP) {
1250 rte_errno = ENOEXEC;
1255 * Clean up unused files in runtime directory. We do this at the end of
1256 * init and not at the beginning because we want to clean stuff up
1257 * whether we are primary or secondary process, but we cannot remove
1258 * primary process' files because secondary should be able to run even
1259 * if primary process is dead.
1261 * In no_shconf mode, no runtime directory is created in the first
1262 * place, so no cleanup needed.
1264 if (!internal_config.no_shconf && eal_clean_runtime_dir() < 0) {
1265 rte_eal_init_alert("Cannot clear runtime directory\n");
1269 rte_eal_mcfg_complete();
1271 /* Call each registered callback, if enabled */
1278 mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
1279 void *arg __rte_unused)
1281 /* ms is const, so find this memseg */
1282 struct rte_memseg *found;
1287 found = rte_mem_virt2memseg(ms->addr, msl);
1289 found->flags &= ~RTE_MEMSEG_FLAG_DO_NOT_FREE;
1295 rte_eal_cleanup(void)
1297 /* if we're in a primary process, we need to mark hugepages as freeable
1298 * so that finalization can release them back to the system.
1300 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1301 rte_memseg_walk(mark_freeable, NULL);
1302 rte_service_finalize();
1303 rte_mp_channel_cleanup();
1304 eal_cleanup_config(&internal_config);
1309 enum rte_lcore_role_t
1310 rte_eal_lcore_role(unsigned lcore_id)
1312 return rte_config.lcore_role[lcore_id];
1315 enum rte_proc_type_t
1316 rte_eal_process_type(void)
1318 return rte_config.process_type;
1321 int rte_eal_has_hugepages(void)
1323 return ! internal_config.no_hugetlbfs;
1326 int rte_eal_has_pci(void)
1328 return !internal_config.no_pci;
1331 int rte_eal_create_uio_dev(void)
1333 return internal_config.create_uio_dev;
1337 rte_eal_vfio_intr_mode(void)
1339 return internal_config.vfio_intr_mode;
1343 rte_eal_check_module(const char *module_name)
1345 char sysfs_mod_name[PATH_MAX];
1349 if (NULL == module_name)
1352 /* Check if there is sysfs mounted */
1353 if (stat("/sys/module", &st) != 0) {
1354 RTE_LOG(DEBUG, EAL, "sysfs is not mounted! error %i (%s)\n",
1355 errno, strerror(errno));
1359 /* A module might be built-in, therefore try sysfs */
1360 n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
1361 if (n < 0 || n > PATH_MAX) {
1362 RTE_LOG(DEBUG, EAL, "Could not format module path\n");
1366 if (stat(sysfs_mod_name, &st) != 0) {
1367 RTE_LOG(DEBUG, EAL, "Module %s not found! error %i (%s)\n",
1368 sysfs_mod_name, errno, strerror(errno));
1372 /* Module has been found */