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_errno.h>
36 #include <rte_per_lcore.h>
37 #include <rte_lcore.h>
38 #include <rte_service_component.h>
40 #include <rte_random.h>
41 #include <rte_cycles.h>
42 #include <rte_string_fns.h>
43 #include <rte_cpuflags.h>
44 #include <rte_interrupts.h>
47 #include <rte_devargs.h>
48 #include <rte_version.h>
49 #include <rte_atomic.h>
50 #include <malloc_heap.h>
52 #include <rte_option.h>
54 #include "eal_private.h"
55 #include "eal_thread.h"
56 #include "eal_internal_cfg.h"
57 #include "eal_filesystem.h"
58 #include "eal_hugepages.h"
59 #include "eal_memcfg.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 #define KERNEL_IOMMU_GROUPS_PATH "/sys/kernel/iommu_groups"
70 /* Allow the application to print its usage message too if set */
71 static rte_usage_hook_t rte_application_usage_hook = NULL;
73 /* early configuration structure, when memory config is not mmapped */
74 static struct rte_mem_config early_mem_config;
76 /* define fd variable here, because file needs to be kept open for the
77 * duration of the program, as we hold a write lock on it in the primary proc */
78 static int mem_cfg_fd = -1;
80 static struct flock wr_lock = {
83 .l_start = offsetof(struct rte_mem_config, memsegs),
84 .l_len = sizeof(early_mem_config.memsegs),
87 /* Address of global and public configuration */
88 static struct rte_config rte_config = {
89 .mem_config = &early_mem_config,
92 /* internal configuration (per-core) */
93 struct lcore_config lcore_config[RTE_MAX_LCORE];
95 /* internal configuration */
96 struct internal_config internal_config;
98 /* used by rte_rdtsc() */
99 int rte_cycles_vmware_tsc_map;
101 /* platform-specific runtime dir */
102 static char runtime_dir[PATH_MAX];
104 static const char *default_runtime_dir = "/var/run";
107 eal_create_runtime_dir(void)
109 const char *directory = default_runtime_dir;
110 const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
111 const char *fallback = "/tmp";
116 /* try XDG path first, fall back to /tmp */
117 if (xdg_runtime_dir != NULL)
118 directory = xdg_runtime_dir;
120 directory = fallback;
122 /* create DPDK subdirectory under runtime dir */
123 ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
124 if (ret < 0 || ret == sizeof(tmp)) {
125 RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
129 /* create prefix-specific subdirectory under DPDK runtime dir */
130 ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
131 tmp, eal_get_hugefile_prefix());
132 if (ret < 0 || ret == sizeof(runtime_dir)) {
133 RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
137 /* create the path if it doesn't exist. no "mkdir -p" here, so do it
140 ret = mkdir(tmp, 0700);
141 if (ret < 0 && errno != EEXIST) {
142 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
143 tmp, strerror(errno));
147 ret = mkdir(runtime_dir, 0700);
148 if (ret < 0 && errno != EEXIST) {
149 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
150 runtime_dir, strerror(errno));
158 eal_clean_runtime_dir(void)
161 struct dirent *dirent;
162 int dir_fd, fd, lck_result;
163 static const char * const filters[] = {
169 dir = opendir(runtime_dir);
171 RTE_LOG(ERR, EAL, "Unable to open runtime directory %s\n",
177 /* lock the directory before doing anything, to avoid races */
178 if (flock(dir_fd, LOCK_EX) < 0) {
179 RTE_LOG(ERR, EAL, "Unable to lock runtime directory %s\n",
184 dirent = readdir(dir);
186 RTE_LOG(ERR, EAL, "Unable to read runtime directory %s\n",
191 while (dirent != NULL) {
195 /* skip files that don't match the patterns */
196 for (f_idx = 0; f_idx < RTE_DIM(filters); f_idx++) {
197 const char *filter = filters[f_idx];
199 if (fnmatch(filter, dirent->d_name, 0) == 0) {
205 dirent = readdir(dir);
209 /* try and lock the file */
210 fd = openat(dir_fd, dirent->d_name, O_RDONLY);
212 /* skip to next file */
214 dirent = readdir(dir);
218 /* non-blocking lock */
219 lck_result = flock(fd, LOCK_EX | LOCK_NB);
221 /* if lock succeeds, remove the file */
222 if (lck_result != -1)
223 unlinkat(dir_fd, dirent->d_name, 0);
225 dirent = readdir(dir);
228 /* closedir closes dir_fd and drops the lock */
236 RTE_LOG(ERR, EAL, "Error while clearing runtime dir: %s\n",
243 rte_eal_get_runtime_dir(void)
248 /* Return user provided mbuf pool ops name */
250 rte_eal_mbuf_user_pool_ops(void)
252 return internal_config.user_mbuf_pool_ops_name;
255 /* Return a pointer to the configuration structure */
257 rte_eal_get_configuration(void)
263 rte_eal_iova_mode(void)
265 return rte_eal_get_configuration()->iova_mode;
268 /* parse a sysfs (or other) file containing one integer value */
270 eal_parse_sysfs_value(const char *filename, unsigned long *val)
276 if ((f = fopen(filename, "r")) == NULL) {
277 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
282 if (fgets(buf, sizeof(buf), f) == NULL) {
283 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
288 *val = strtoul(buf, &end, 0);
289 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
290 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
300 /* create memory configuration in shared/mmap memory. Take out
301 * a write lock on the memsegs, so we can auto-detect primary/secondary.
302 * This means we never close the file while running (auto-close on exit).
303 * We also don't lock the whole file, so that in future we can use read-locks
304 * on other parts, e.g. memzones, to detect if there are running secondary
307 rte_eal_config_create(void)
309 void *rte_mem_cfg_addr;
312 const char *pathname = eal_runtime_config_path();
314 if (internal_config.no_shconf)
317 /* map the config before hugepage address so that we don't waste a page */
318 if (internal_config.base_virtaddr != 0)
319 rte_mem_cfg_addr = (void *)
320 RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
321 sizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));
323 rte_mem_cfg_addr = NULL;
326 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
327 if (mem_cfg_fd < 0) {
328 RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
334 retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
338 RTE_LOG(ERR, EAL, "Cannot resize '%s' for rte_mem_config\n",
343 retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
347 RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary "
348 "process running?\n", pathname);
352 rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),
353 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
355 if (rte_mem_cfg_addr == MAP_FAILED){
358 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config\n");
362 memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
363 rte_config.mem_config = rte_mem_cfg_addr;
365 /* store address of the config in the config itself so that secondary
366 * processes could later map the config into this exact location */
367 rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
369 rte_config.mem_config->dma_maskbits = 0;
374 /* attach to an existing shared memory config */
376 rte_eal_config_attach(void)
378 struct rte_mem_config *mem_config;
380 const char *pathname = eal_runtime_config_path();
382 if (internal_config.no_shconf)
386 mem_cfg_fd = open(pathname, O_RDWR);
387 if (mem_cfg_fd < 0) {
388 RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
394 /* map it as read-only first */
395 mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
396 PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
397 if (mem_config == MAP_FAILED) {
400 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
401 errno, strerror(errno));
405 rte_config.mem_config = mem_config;
410 /* reattach the shared config at exact memory location primary process has it */
412 rte_eal_config_reattach(void)
414 struct rte_mem_config *mem_config;
415 void *rte_mem_cfg_addr;
417 if (internal_config.no_shconf)
420 /* save the address primary process has mapped shared config to */
421 rte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr;
423 /* unmap original config */
424 munmap(rte_config.mem_config, sizeof(struct rte_mem_config));
426 /* remap the config at proper address */
427 mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
428 sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
434 if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
435 if (mem_config != MAP_FAILED) {
436 /* errno is stale, don't use */
437 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config at [%p], got [%p]"
438 " - please use '--base-virtaddr' option\n",
439 rte_mem_cfg_addr, mem_config);
442 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
443 errno, strerror(errno));
447 rte_config.mem_config = mem_config;
452 /* Detect if we are a primary or a secondary process */
454 eal_proc_type_detect(void)
456 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
457 const char *pathname = eal_runtime_config_path();
459 /* if there no shared config, there can be no secondary processes */
460 if (!internal_config.no_shconf) {
461 /* if we can open the file but not get a write-lock we are a
462 * secondary process. NOTE: if we get a file handle back, we
463 * keep that open and don't close it to prevent a race condition
464 * between multiple opens.
466 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
467 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
468 ptype = RTE_PROC_SECONDARY;
471 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
472 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
477 /* Sets up rte_config structure with the pointer to shared memory config.*/
479 rte_config_init(void)
481 rte_config.process_type = internal_config.process_type;
483 switch (rte_config.process_type){
484 case RTE_PROC_PRIMARY:
485 if (rte_eal_config_create() < 0)
487 eal_mcfg_update_from_internal();
489 case RTE_PROC_SECONDARY:
490 if (rte_eal_config_attach() < 0)
492 eal_mcfg_wait_complete();
493 if (eal_mcfg_check_version() < 0) {
494 RTE_LOG(ERR, EAL, "Primary and secondary process DPDK version mismatch\n");
497 if (rte_eal_config_reattach() < 0)
499 eal_mcfg_update_internal();
502 case RTE_PROC_INVALID:
503 RTE_LOG(ERR, EAL, "Invalid process type %d\n",
504 rte_config.process_type);
511 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
513 eal_hugedirs_unlock(void)
517 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
519 /* skip uninitialized */
520 if (internal_config.hugepage_info[i].lock_descriptor < 0)
522 /* unlock hugepage file */
523 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
524 close(internal_config.hugepage_info[i].lock_descriptor);
525 /* reset the field */
526 internal_config.hugepage_info[i].lock_descriptor = -1;
532 eal_usage(const char *prgname)
534 printf("\nUsage: %s ", prgname);
536 printf("EAL Linux options:\n"
537 " --"OPT_SOCKET_MEM" Memory to allocate on sockets (comma separated values)\n"
538 " --"OPT_SOCKET_LIMIT" Limit memory allocation on sockets (comma separated values)\n"
539 " --"OPT_HUGE_DIR" Directory where hugetlbfs is mounted\n"
540 " --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n"
541 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
542 " --"OPT_CREATE_UIO_DEV" Create /dev/uioX (usually done by hotplug)\n"
543 " --"OPT_VFIO_INTR" Interrupt mode for VFIO (legacy|msi|msix)\n"
544 " --"OPT_LEGACY_MEM" Legacy memory mode (no dynamic allocation, contiguous segments)\n"
545 " --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
546 " --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
548 /* Allow the application to print its usage message too if hook is set */
549 if ( rte_application_usage_hook ) {
550 printf("===== Application Usage =====\n\n");
551 rte_application_usage_hook(prgname);
555 /* Set a per-application usage message */
557 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
559 rte_usage_hook_t old_func;
561 /* Will be NULL on the first call to denote the last usage routine. */
562 old_func = rte_application_usage_hook;
563 rte_application_usage_hook = usage_func;
569 eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
571 char * arg[RTE_MAX_NUMA_NODES];
574 uint64_t total_mem = 0;
576 len = strnlen(strval, SOCKET_MEM_STRLEN);
577 if (len == SOCKET_MEM_STRLEN) {
578 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
582 /* all other error cases will be caught later */
583 if (!isdigit(strval[len-1]))
586 /* split the optarg into separate socket values */
587 arg_num = rte_strsplit(strval, len,
588 arg, RTE_MAX_NUMA_NODES, ',');
590 /* if split failed, or 0 arguments */
594 /* parse each defined socket option */
596 for (i = 0; i < arg_num; i++) {
599 val = strtoull(arg[i], &end, 10);
601 /* check for invalid input */
603 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
614 eal_parse_base_virtaddr(const char *arg)
620 addr = strtoull(arg, &end, 16);
622 /* check for errors */
623 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
626 /* make sure we don't exceed 32-bit boundary on 32-bit target */
628 if (addr >= UINTPTR_MAX)
632 /* align the addr on 16M boundary, 16MB is the minimum huge page
633 * size on IBM Power architecture. If the addr is aligned to 16MB,
634 * it can align to 2MB for x86. So this alignment can also be used
636 internal_config.base_virtaddr =
637 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
643 eal_parse_vfio_intr(const char *mode)
648 enum rte_intr_mode value;
650 { "legacy", RTE_INTR_MODE_LEGACY },
651 { "msi", RTE_INTR_MODE_MSI },
652 { "msix", RTE_INTR_MODE_MSIX },
655 for (i = 0; i < RTE_DIM(map); i++) {
656 if (!strcmp(mode, map[i].name)) {
657 internal_config.vfio_intr_mode = map[i].value;
664 /* Parse the arguments for --log-level only */
666 eal_log_level_parse(int argc, char **argv)
671 const int old_optind = optind;
672 const int old_optopt = optopt;
673 char * const old_optarg = optarg;
678 while ((opt = getopt_long(argc, argvopt, eal_short_options,
679 eal_long_options, &option_index)) != EOF) {
683 /* getopt is not happy, stop right now */
687 ret = (opt == OPT_LOG_LEVEL_NUM) ?
688 eal_parse_common_option(opt, optarg, &internal_config) : 0;
690 /* common parser is not happy */
695 /* restore getopt lib */
701 /* Parse the argument given in the command line of the application */
703 eal_parse_args(int argc, char **argv)
708 char *prgname = argv[0];
709 const int old_optind = optind;
710 const int old_optopt = optopt;
711 char * const old_optarg = optarg;
717 while ((opt = getopt_long(argc, argvopt, eal_short_options,
718 eal_long_options, &option_index)) != EOF) {
721 * getopt didn't recognise the option, lets parse the
722 * registered options to see if the flag is valid
725 ret = rte_option_parse(argv[optind-1]);
734 ret = eal_parse_common_option(opt, optarg, &internal_config);
735 /* common parser is not happy */
741 /* common parser handled this option */
750 case OPT_HUGE_DIR_NUM:
752 char *hdir = strdup(optarg);
754 RTE_LOG(ERR, EAL, "Could not store hugepage directory\n");
756 /* free old hugepage dir */
757 if (internal_config.hugepage_dir != NULL)
758 free(internal_config.hugepage_dir);
759 internal_config.hugepage_dir = hdir;
763 case OPT_FILE_PREFIX_NUM:
765 char *prefix = strdup(optarg);
767 RTE_LOG(ERR, EAL, "Could not store file prefix\n");
769 /* free old prefix */
770 if (internal_config.hugefile_prefix != NULL)
771 free(internal_config.hugefile_prefix);
772 internal_config.hugefile_prefix = prefix;
776 case OPT_SOCKET_MEM_NUM:
777 if (eal_parse_socket_arg(optarg,
778 internal_config.socket_mem) < 0) {
779 RTE_LOG(ERR, EAL, "invalid parameters for --"
780 OPT_SOCKET_MEM "\n");
785 internal_config.force_sockets = 1;
788 case OPT_SOCKET_LIMIT_NUM:
789 if (eal_parse_socket_arg(optarg,
790 internal_config.socket_limit) < 0) {
791 RTE_LOG(ERR, EAL, "invalid parameters for --"
792 OPT_SOCKET_LIMIT "\n");
797 internal_config.force_socket_limits = 1;
800 case OPT_BASE_VIRTADDR_NUM:
801 if (eal_parse_base_virtaddr(optarg) < 0) {
802 RTE_LOG(ERR, EAL, "invalid parameter for --"
803 OPT_BASE_VIRTADDR "\n");
810 case OPT_VFIO_INTR_NUM:
811 if (eal_parse_vfio_intr(optarg) < 0) {
812 RTE_LOG(ERR, EAL, "invalid parameters for --"
820 case OPT_CREATE_UIO_DEV_NUM:
821 internal_config.create_uio_dev = 1;
824 case OPT_MBUF_POOL_OPS_NAME_NUM:
826 char *ops_name = strdup(optarg);
827 if (ops_name == NULL)
828 RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n");
830 /* free old ops name */
831 if (internal_config.user_mbuf_pool_ops_name !=
833 free(internal_config.user_mbuf_pool_ops_name);
835 internal_config.user_mbuf_pool_ops_name =
840 case OPT_MATCH_ALLOCATIONS_NUM:
841 internal_config.match_allocations = 1;
845 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
846 RTE_LOG(ERR, EAL, "Option %c is not supported "
848 } else if (opt >= OPT_LONG_MIN_NUM &&
849 opt < OPT_LONG_MAX_NUM) {
850 RTE_LOG(ERR, EAL, "Option %s is not supported "
852 eal_long_options[option_index].name);
854 RTE_LOG(ERR, EAL, "Option %d is not supported "
863 /* create runtime data directory */
864 if (internal_config.no_shconf == 0 &&
865 eal_create_runtime_dir() < 0) {
866 RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
871 if (eal_adjust_config(&internal_config) != 0) {
877 if (eal_check_common_options(&internal_config) != 0) {
884 argv[optind-1] = prgname;
888 /* restore getopt lib */
897 check_socket(const struct rte_memseg_list *msl, void *arg)
899 int *socket_id = arg;
904 return *socket_id == msl->socket_id;
908 eal_check_mem_on_local_socket(void)
912 socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
914 if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
915 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
919 sync_func(__attribute__((unused)) void *arg)
925 * Request iopl privilege for all RPL, returns 0 on success
926 * iopl() call is mostly for the i386 architecture. For other architectures,
927 * return -1 to indicate IO privilege can't be changed in this way.
930 rte_eal_iopl_init(void)
932 #if defined(RTE_ARCH_X86)
940 static int rte_eal_vfio_setup(void)
942 if (rte_vfio_enable("vfio"))
949 static void rte_eal_init_alert(const char *msg)
951 fprintf(stderr, "EAL: FATAL: %s\n", msg);
952 RTE_LOG(ERR, EAL, "%s\n", msg);
956 * On Linux 3.6+, even if VFIO is not loaded, whenever IOMMU is enabled in the
957 * BIOS and in the kernel, /sys/kernel/iommu_groups path will contain kernel
958 * IOMMU groups. If IOMMU is not enabled, that path would be empty.
959 * Therefore, checking if the path is empty will tell us if IOMMU is enabled.
962 is_iommu_enabled(void)
964 DIR *dir = opendir(KERNEL_IOMMU_GROUPS_PATH);
968 /* if directory doesn't exist, assume IOMMU is not enabled */
972 while ((d = readdir(dir)) != NULL) {
973 /* skip dot and dot-dot */
982 /* Launch threads, called at application init(). */
984 rte_eal_init(int argc, char **argv)
988 static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
990 static char logid[PATH_MAX];
991 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
992 char thread_name[RTE_MAX_THREAD_NAME_LEN];
995 /* checks if the machine is adequate */
996 if (!rte_cpu_is_supported()) {
997 rte_eal_init_alert("unsupported cpu type.");
1002 if (!rte_atomic32_test_and_set(&run_once)) {
1003 rte_eal_init_alert("already called initialization.");
1004 rte_errno = EALREADY;
1008 p = strrchr(argv[0], '/');
1009 strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
1010 thread_id = pthread_self();
1012 eal_reset_internal_config(&internal_config);
1014 /* set log level as early as possible */
1015 eal_log_level_parse(argc, argv);
1017 if (rte_eal_cpu_init() < 0) {
1018 rte_eal_init_alert("Cannot detect lcores.");
1019 rte_errno = ENOTSUP;
1023 fctret = eal_parse_args(argc, argv);
1025 rte_eal_init_alert("Invalid 'command line' arguments.");
1027 rte_atomic32_clear(&run_once);
1031 if (eal_plugins_init() < 0) {
1032 rte_eal_init_alert("Cannot init plugins");
1034 rte_atomic32_clear(&run_once);
1038 if (eal_option_device_parse()) {
1040 rte_atomic32_clear(&run_once);
1044 if (rte_config_init() < 0) {
1045 rte_eal_init_alert("Cannot init config");
1049 if (rte_eal_intr_init() < 0) {
1050 rte_eal_init_alert("Cannot init interrupt-handling thread");
1054 if (rte_eal_alarm_init() < 0) {
1055 rte_eal_init_alert("Cannot init alarm");
1056 /* rte_eal_alarm_init sets rte_errno on failure. */
1060 /* Put mp channel init before bus scan so that we can init the vdev
1061 * bus through mp channel in the secondary process before the bus scan.
1063 if (rte_mp_channel_init() < 0 && rte_errno != ENOTSUP) {
1064 rte_eal_init_alert("failed to init mp channel");
1065 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1071 /* register multi-process action callbacks for hotplug */
1072 if (eal_mp_dev_hotplug_init() < 0) {
1073 rte_eal_init_alert("failed to register mp callback for hotplug");
1077 if (rte_bus_scan()) {
1078 rte_eal_init_alert("Cannot scan the buses for devices");
1080 rte_atomic32_clear(&run_once);
1084 phys_addrs = rte_eal_using_phys_addrs() != 0;
1086 /* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */
1087 if (internal_config.iova_mode == RTE_IOVA_DC) {
1088 /* autodetect the IOVA mapping mode */
1089 enum rte_iova_mode iova_mode = rte_bus_get_iommu_class();
1091 if (iova_mode == RTE_IOVA_DC) {
1092 RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
1095 /* if we have no access to physical addresses,
1096 * pick IOVA as VA mode.
1098 iova_mode = RTE_IOVA_VA;
1099 RTE_LOG(DEBUG, EAL, "Physical addresses are unavailable, selecting IOVA as VA mode.\n");
1100 } else if (is_iommu_enabled()) {
1101 /* we have an IOMMU, pick IOVA as VA mode */
1102 iova_mode = RTE_IOVA_VA;
1103 RTE_LOG(DEBUG, EAL, "IOMMU is available, selecting IOVA as VA mode.\n");
1105 /* physical addresses available, and no IOMMU
1106 * found, so pick IOVA as PA.
1108 iova_mode = RTE_IOVA_PA;
1109 RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n");
1112 #ifdef RTE_LIBRTE_KNI
1113 /* Workaround for KNI which requires physical address to work */
1114 if (iova_mode == RTE_IOVA_VA &&
1115 rte_eal_check_module("rte_kni") == 1) {
1117 iova_mode = RTE_IOVA_PA;
1118 RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
1120 RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
1124 rte_eal_get_configuration()->iova_mode = iova_mode;
1126 rte_eal_get_configuration()->iova_mode =
1127 internal_config.iova_mode;
1130 if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
1131 rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
1136 RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n",
1137 rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
1139 if (internal_config.no_hugetlbfs == 0) {
1140 /* rte_config isn't initialized yet */
1141 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
1142 eal_hugepage_info_init() :
1143 eal_hugepage_info_read();
1145 rte_eal_init_alert("Cannot get hugepage information.");
1147 rte_atomic32_clear(&run_once);
1152 if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
1153 if (internal_config.no_hugetlbfs)
1154 internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
1157 if (internal_config.vmware_tsc_map == 1) {
1158 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
1159 rte_cycles_vmware_tsc_map = 1;
1160 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
1161 "you must have monitor_control.pseudo_perfctr = TRUE\n");
1163 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
1164 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
1168 if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) {
1169 rte_eal_init_alert("Cannot init logging.");
1171 rte_atomic32_clear(&run_once);
1176 if (rte_eal_vfio_setup() < 0) {
1177 rte_eal_init_alert("Cannot init VFIO");
1179 rte_atomic32_clear(&run_once);
1183 /* in secondary processes, memory init may allocate additional fbarrays
1184 * not present in primary processes, so to avoid any potential issues,
1185 * initialize memzones first.
1187 if (rte_eal_memzone_init() < 0) {
1188 rte_eal_init_alert("Cannot init memzone");
1193 if (rte_eal_memory_init() < 0) {
1194 rte_eal_init_alert("Cannot init memory");
1199 /* the directories are locked during eal_hugepage_info_init */
1200 eal_hugedirs_unlock();
1202 if (rte_eal_malloc_heap_init() < 0) {
1203 rte_eal_init_alert("Cannot init malloc heap");
1208 if (rte_eal_tailqs_init() < 0) {
1209 rte_eal_init_alert("Cannot init tail queues for objects");
1214 if (rte_eal_timer_init() < 0) {
1215 rte_eal_init_alert("Cannot init HPET or TSC timers");
1216 rte_errno = ENOTSUP;
1220 eal_check_mem_on_local_socket();
1222 eal_thread_init_master(rte_config.master_lcore);
1224 ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
1226 RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
1227 rte_config.master_lcore, (uintptr_t)thread_id, cpuset,
1228 ret == 0 ? "" : "...");
1230 RTE_LCORE_FOREACH_SLAVE(i) {
1233 * create communication pipes between master thread
1236 if (pipe(lcore_config[i].pipe_master2slave) < 0)
1237 rte_panic("Cannot create pipe\n");
1238 if (pipe(lcore_config[i].pipe_slave2master) < 0)
1239 rte_panic("Cannot create pipe\n");
1241 lcore_config[i].state = WAIT;
1243 /* create a thread for each lcore */
1244 ret = pthread_create(&lcore_config[i].thread_id, NULL,
1245 eal_thread_loop, NULL);
1247 rte_panic("Cannot create thread\n");
1249 /* Set thread_name for aid in debugging. */
1250 snprintf(thread_name, sizeof(thread_name),
1251 "lcore-slave-%d", i);
1252 ret = rte_thread_setname(lcore_config[i].thread_id,
1256 "Cannot set name for lcore thread\n");
1260 * Launch a dummy function on all slave lcores, so that master lcore
1261 * knows they are all ready when this function returns.
1263 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
1264 rte_eal_mp_wait_lcore();
1266 /* initialize services so vdevs register service during bus_probe. */
1267 ret = rte_service_init();
1269 rte_eal_init_alert("rte_service_init() failed");
1270 rte_errno = ENOEXEC;
1274 /* Probe all the buses and devices/drivers on them */
1275 if (rte_bus_probe()) {
1276 rte_eal_init_alert("Cannot probe devices");
1277 rte_errno = ENOTSUP;
1282 /* Register mp action after probe() so that we got enough info */
1283 if (rte_vfio_is_enabled("vfio") && vfio_mp_sync_setup() < 0)
1287 /* initialize default service/lcore mappings and start running. Ignore
1288 * -ENOTSUP, as it indicates no service coremask passed to EAL.
1290 ret = rte_service_start_with_defaults();
1291 if (ret < 0 && ret != -ENOTSUP) {
1292 rte_errno = ENOEXEC;
1297 * Clean up unused files in runtime directory. We do this at the end of
1298 * init and not at the beginning because we want to clean stuff up
1299 * whether we are primary or secondary process, but we cannot remove
1300 * primary process' files because secondary should be able to run even
1301 * if primary process is dead.
1303 * In no_shconf mode, no runtime directory is created in the first
1304 * place, so no cleanup needed.
1306 if (!internal_config.no_shconf && eal_clean_runtime_dir() < 0) {
1307 rte_eal_init_alert("Cannot clear runtime directory\n");
1311 eal_mcfg_complete();
1313 /* Call each registered callback, if enabled */
1320 mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
1321 void *arg __rte_unused)
1323 /* ms is const, so find this memseg */
1324 struct rte_memseg *found;
1329 found = rte_mem_virt2memseg(ms->addr, msl);
1331 found->flags &= ~RTE_MEMSEG_FLAG_DO_NOT_FREE;
1337 rte_eal_cleanup(void)
1339 /* if we're in a primary process, we need to mark hugepages as freeable
1340 * so that finalization can release them back to the system.
1342 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1343 rte_memseg_walk(mark_freeable, NULL);
1344 rte_service_finalize();
1345 rte_mp_channel_cleanup();
1346 eal_cleanup_config(&internal_config);
1351 enum rte_lcore_role_t
1352 rte_eal_lcore_role(unsigned lcore_id)
1354 return rte_config.lcore_role[lcore_id];
1357 enum rte_proc_type_t
1358 rte_eal_process_type(void)
1360 return rte_config.process_type;
1363 int rte_eal_has_hugepages(void)
1365 return ! internal_config.no_hugetlbfs;
1368 int rte_eal_has_pci(void)
1370 return !internal_config.no_pci;
1373 int rte_eal_create_uio_dev(void)
1375 return internal_config.create_uio_dev;
1379 rte_eal_vfio_intr_mode(void)
1381 return internal_config.vfio_intr_mode;
1385 rte_eal_check_module(const char *module_name)
1387 char sysfs_mod_name[PATH_MAX];
1391 if (NULL == module_name)
1394 /* Check if there is sysfs mounted */
1395 if (stat("/sys/module", &st) != 0) {
1396 RTE_LOG(DEBUG, EAL, "sysfs is not mounted! error %i (%s)\n",
1397 errno, strerror(errno));
1401 /* A module might be built-in, therefore try sysfs */
1402 n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
1403 if (n < 0 || n > PATH_MAX) {
1404 RTE_LOG(DEBUG, EAL, "Could not format module path\n");
1408 if (stat(sysfs_mod_name, &st) != 0) {
1409 RTE_LOG(DEBUG, EAL, "Module %s not found! error %i (%s)\n",
1410 sysfs_mod_name, errno, strerror(errno));
1414 /* Module has been found */