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 size_t page_sz = sysconf(_SC_PAGE_SIZE);
310 size_t cfg_len = sizeof(*rte_config.mem_config);
311 size_t cfg_len_aligned = RTE_ALIGN(cfg_len, page_sz);
312 void *rte_mem_cfg_addr, *mapped_mem_cfg_addr;
315 const char *pathname = eal_runtime_config_path();
317 if (internal_config.no_shconf)
320 /* map the config before hugepage address so that we don't waste a page */
321 if (internal_config.base_virtaddr != 0)
322 rte_mem_cfg_addr = (void *)
323 RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
324 sizeof(struct rte_mem_config), page_sz);
326 rte_mem_cfg_addr = NULL;
329 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
330 if (mem_cfg_fd < 0) {
331 RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
337 retval = ftruncate(mem_cfg_fd, cfg_len);
341 RTE_LOG(ERR, EAL, "Cannot resize '%s' for rte_mem_config\n",
346 retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
350 RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary "
351 "process running?\n", pathname);
355 /* reserve space for config */
356 rte_mem_cfg_addr = eal_get_virtual_area(rte_mem_cfg_addr,
357 &cfg_len_aligned, page_sz, 0, 0);
358 if (rte_mem_cfg_addr == NULL) {
359 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config\n");
365 /* remap the actual file into the space we've just reserved */
366 mapped_mem_cfg_addr = mmap(rte_mem_cfg_addr,
367 cfg_len_aligned, PROT_READ | PROT_WRITE,
368 MAP_SHARED | MAP_FIXED, mem_cfg_fd, 0);
369 if (mapped_mem_cfg_addr == MAP_FAILED) {
370 munmap(rte_mem_cfg_addr, cfg_len);
373 RTE_LOG(ERR, EAL, "Cannot remap memory for rte_config\n");
377 memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
378 rte_config.mem_config = rte_mem_cfg_addr;
380 /* store address of the config in the config itself so that secondary
381 * processes could later map the config into this exact location */
382 rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
384 rte_config.mem_config->dma_maskbits = 0;
389 /* attach to an existing shared memory config */
391 rte_eal_config_attach(void)
393 struct rte_mem_config *mem_config;
395 const char *pathname = eal_runtime_config_path();
397 if (internal_config.no_shconf)
401 mem_cfg_fd = open(pathname, O_RDWR);
402 if (mem_cfg_fd < 0) {
403 RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
409 /* map it as read-only first */
410 mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
411 PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
412 if (mem_config == MAP_FAILED) {
415 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
416 errno, strerror(errno));
420 rte_config.mem_config = mem_config;
425 /* reattach the shared config at exact memory location primary process has it */
427 rte_eal_config_reattach(void)
429 struct rte_mem_config *mem_config;
430 void *rte_mem_cfg_addr;
432 if (internal_config.no_shconf)
435 /* save the address primary process has mapped shared config to */
436 rte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr;
438 /* unmap original config */
439 munmap(rte_config.mem_config, sizeof(struct rte_mem_config));
441 /* remap the config at proper address */
442 mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
443 sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
449 if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
450 if (mem_config != MAP_FAILED) {
451 /* errno is stale, don't use */
452 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config at [%p], got [%p]"
453 " - please use '--" OPT_BASE_VIRTADDR
454 "' option\n", rte_mem_cfg_addr, mem_config);
455 munmap(mem_config, sizeof(struct rte_mem_config));
458 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
459 errno, strerror(errno));
463 rte_config.mem_config = mem_config;
468 /* Detect if we are a primary or a secondary process */
470 eal_proc_type_detect(void)
472 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
473 const char *pathname = eal_runtime_config_path();
475 /* if there no shared config, there can be no secondary processes */
476 if (!internal_config.no_shconf) {
477 /* if we can open the file but not get a write-lock we are a
478 * secondary process. NOTE: if we get a file handle back, we
479 * keep that open and don't close it to prevent a race condition
480 * between multiple opens.
482 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
483 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
484 ptype = RTE_PROC_SECONDARY;
487 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
488 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
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_mcfg_update_from_internal();
505 case RTE_PROC_SECONDARY:
506 if (rte_eal_config_attach() < 0)
508 eal_mcfg_wait_complete();
509 if (eal_mcfg_check_version() < 0) {
510 RTE_LOG(ERR, EAL, "Primary and secondary process DPDK version mismatch\n");
513 if (rte_eal_config_reattach() < 0)
515 eal_mcfg_update_internal();
518 case RTE_PROC_INVALID:
519 RTE_LOG(ERR, EAL, "Invalid process type %d\n",
520 rte_config.process_type);
527 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
529 eal_hugedirs_unlock(void)
533 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
535 /* skip uninitialized */
536 if (internal_config.hugepage_info[i].lock_descriptor < 0)
538 /* unlock hugepage file */
539 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
540 close(internal_config.hugepage_info[i].lock_descriptor);
541 /* reset the field */
542 internal_config.hugepage_info[i].lock_descriptor = -1;
548 eal_usage(const char *prgname)
550 printf("\nUsage: %s ", prgname);
552 printf("EAL Linux options:\n"
553 " --"OPT_SOCKET_MEM" Memory to allocate on sockets (comma separated values)\n"
554 " --"OPT_SOCKET_LIMIT" Limit memory allocation on sockets (comma separated values)\n"
555 " --"OPT_HUGE_DIR" Directory where hugetlbfs is mounted\n"
556 " --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n"
557 " --"OPT_CREATE_UIO_DEV" Create /dev/uioX (usually done by hotplug)\n"
558 " --"OPT_VFIO_INTR" Interrupt mode for VFIO (legacy|msi|msix)\n"
559 " --"OPT_LEGACY_MEM" Legacy memory mode (no dynamic allocation, contiguous segments)\n"
560 " --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
561 " --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
563 /* Allow the application to print its usage message too if hook is set */
564 if ( rte_application_usage_hook ) {
565 printf("===== Application Usage =====\n\n");
566 rte_application_usage_hook(prgname);
570 /* Set a per-application usage message */
572 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
574 rte_usage_hook_t old_func;
576 /* Will be NULL on the first call to denote the last usage routine. */
577 old_func = rte_application_usage_hook;
578 rte_application_usage_hook = usage_func;
584 eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
586 char * arg[RTE_MAX_NUMA_NODES];
589 uint64_t total_mem = 0;
591 len = strnlen(strval, SOCKET_MEM_STRLEN);
592 if (len == SOCKET_MEM_STRLEN) {
593 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
597 /* all other error cases will be caught later */
598 if (!isdigit(strval[len-1]))
601 /* split the optarg into separate socket values */
602 arg_num = rte_strsplit(strval, len,
603 arg, RTE_MAX_NUMA_NODES, ',');
605 /* if split failed, or 0 arguments */
609 /* parse each defined socket option */
611 for (i = 0; i < arg_num; i++) {
614 val = strtoull(arg[i], &end, 10);
616 /* check for invalid input */
618 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
629 eal_parse_vfio_intr(const char *mode)
634 enum rte_intr_mode value;
636 { "legacy", RTE_INTR_MODE_LEGACY },
637 { "msi", RTE_INTR_MODE_MSI },
638 { "msix", RTE_INTR_MODE_MSIX },
641 for (i = 0; i < RTE_DIM(map); i++) {
642 if (!strcmp(mode, map[i].name)) {
643 internal_config.vfio_intr_mode = map[i].value;
650 /* Parse the arguments for --log-level only */
652 eal_log_level_parse(int argc, char **argv)
657 const int old_optind = optind;
658 const int old_optopt = optopt;
659 char * const old_optarg = optarg;
664 while ((opt = getopt_long(argc, argvopt, eal_short_options,
665 eal_long_options, &option_index)) != EOF) {
669 /* getopt is not happy, stop right now */
673 ret = (opt == OPT_LOG_LEVEL_NUM) ?
674 eal_parse_common_option(opt, optarg, &internal_config) : 0;
676 /* common parser is not happy */
681 /* restore getopt lib */
687 /* Parse the argument given in the command line of the application */
689 eal_parse_args(int argc, char **argv)
694 char *prgname = argv[0];
695 const int old_optind = optind;
696 const int old_optopt = optopt;
697 char * const old_optarg = optarg;
703 while ((opt = getopt_long(argc, argvopt, eal_short_options,
704 eal_long_options, &option_index)) != EOF) {
707 * getopt didn't recognise the option, lets parse the
708 * registered options to see if the flag is valid
711 ret = rte_option_parse(argv[optind-1]);
720 ret = eal_parse_common_option(opt, optarg, &internal_config);
721 /* common parser is not happy */
727 /* common parser handled this option */
736 case OPT_HUGE_DIR_NUM:
738 char *hdir = strdup(optarg);
740 RTE_LOG(ERR, EAL, "Could not store hugepage directory\n");
742 /* free old hugepage dir */
743 if (internal_config.hugepage_dir != NULL)
744 free(internal_config.hugepage_dir);
745 internal_config.hugepage_dir = hdir;
749 case OPT_FILE_PREFIX_NUM:
751 char *prefix = strdup(optarg);
753 RTE_LOG(ERR, EAL, "Could not store file prefix\n");
755 /* free old prefix */
756 if (internal_config.hugefile_prefix != NULL)
757 free(internal_config.hugefile_prefix);
758 internal_config.hugefile_prefix = prefix;
762 case OPT_SOCKET_MEM_NUM:
763 if (eal_parse_socket_arg(optarg,
764 internal_config.socket_mem) < 0) {
765 RTE_LOG(ERR, EAL, "invalid parameters for --"
766 OPT_SOCKET_MEM "\n");
771 internal_config.force_sockets = 1;
774 case OPT_SOCKET_LIMIT_NUM:
775 if (eal_parse_socket_arg(optarg,
776 internal_config.socket_limit) < 0) {
777 RTE_LOG(ERR, EAL, "invalid parameters for --"
778 OPT_SOCKET_LIMIT "\n");
783 internal_config.force_socket_limits = 1;
786 case OPT_VFIO_INTR_NUM:
787 if (eal_parse_vfio_intr(optarg) < 0) {
788 RTE_LOG(ERR, EAL, "invalid parameters for --"
796 case OPT_CREATE_UIO_DEV_NUM:
797 internal_config.create_uio_dev = 1;
800 case OPT_MBUF_POOL_OPS_NAME_NUM:
802 char *ops_name = strdup(optarg);
803 if (ops_name == NULL)
804 RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n");
806 /* free old ops name */
807 if (internal_config.user_mbuf_pool_ops_name !=
809 free(internal_config.user_mbuf_pool_ops_name);
811 internal_config.user_mbuf_pool_ops_name =
816 case OPT_MATCH_ALLOCATIONS_NUM:
817 internal_config.match_allocations = 1;
821 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
822 RTE_LOG(ERR, EAL, "Option %c is not supported "
824 } else if (opt >= OPT_LONG_MIN_NUM &&
825 opt < OPT_LONG_MAX_NUM) {
826 RTE_LOG(ERR, EAL, "Option %s is not supported "
828 eal_long_options[option_index].name);
830 RTE_LOG(ERR, EAL, "Option %d is not supported "
839 /* create runtime data directory */
840 if (internal_config.no_shconf == 0 &&
841 eal_create_runtime_dir() < 0) {
842 RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
847 if (eal_adjust_config(&internal_config) != 0) {
853 if (eal_check_common_options(&internal_config) != 0) {
860 argv[optind-1] = prgname;
864 /* restore getopt lib */
873 check_socket(const struct rte_memseg_list *msl, void *arg)
875 int *socket_id = arg;
880 return *socket_id == msl->socket_id;
884 eal_check_mem_on_local_socket(void)
888 socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
890 if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
891 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
895 sync_func(__attribute__((unused)) void *arg)
901 * Request iopl privilege for all RPL, returns 0 on success
902 * iopl() call is mostly for the i386 architecture. For other architectures,
903 * return -1 to indicate IO privilege can't be changed in this way.
906 rte_eal_iopl_init(void)
908 #if defined(RTE_ARCH_X86)
916 static int rte_eal_vfio_setup(void)
918 if (rte_vfio_enable("vfio"))
925 static void rte_eal_init_alert(const char *msg)
927 fprintf(stderr, "EAL: FATAL: %s\n", msg);
928 RTE_LOG(ERR, EAL, "%s\n", msg);
932 * On Linux 3.6+, even if VFIO is not loaded, whenever IOMMU is enabled in the
933 * BIOS and in the kernel, /sys/kernel/iommu_groups path will contain kernel
934 * IOMMU groups. If IOMMU is not enabled, that path would be empty.
935 * Therefore, checking if the path is empty will tell us if IOMMU is enabled.
938 is_iommu_enabled(void)
940 DIR *dir = opendir(KERNEL_IOMMU_GROUPS_PATH);
944 /* if directory doesn't exist, assume IOMMU is not enabled */
948 while ((d = readdir(dir)) != NULL) {
949 /* skip dot and dot-dot */
958 /* Launch threads, called at application init(). */
960 rte_eal_init(int argc, char **argv)
964 static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
966 static char logid[PATH_MAX];
967 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
968 char thread_name[RTE_MAX_THREAD_NAME_LEN];
971 /* checks if the machine is adequate */
972 if (!rte_cpu_is_supported()) {
973 rte_eal_init_alert("unsupported cpu type.");
978 if (!rte_atomic32_test_and_set(&run_once)) {
979 rte_eal_init_alert("already called initialization.");
980 rte_errno = EALREADY;
984 p = strrchr(argv[0], '/');
985 strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
986 thread_id = pthread_self();
988 eal_reset_internal_config(&internal_config);
990 /* set log level as early as possible */
991 eal_log_level_parse(argc, argv);
993 if (rte_eal_cpu_init() < 0) {
994 rte_eal_init_alert("Cannot detect lcores.");
999 fctret = eal_parse_args(argc, argv);
1001 rte_eal_init_alert("Invalid 'command line' arguments.");
1003 rte_atomic32_clear(&run_once);
1007 if (eal_plugins_init() < 0) {
1008 rte_eal_init_alert("Cannot init plugins");
1010 rte_atomic32_clear(&run_once);
1014 if (eal_option_device_parse()) {
1016 rte_atomic32_clear(&run_once);
1020 if (rte_config_init() < 0) {
1021 rte_eal_init_alert("Cannot init config");
1025 if (rte_eal_intr_init() < 0) {
1026 rte_eal_init_alert("Cannot init interrupt-handling thread");
1030 if (rte_eal_alarm_init() < 0) {
1031 rte_eal_init_alert("Cannot init alarm");
1032 /* rte_eal_alarm_init sets rte_errno on failure. */
1036 /* Put mp channel init before bus scan so that we can init the vdev
1037 * bus through mp channel in the secondary process before the bus scan.
1039 if (rte_mp_channel_init() < 0 && rte_errno != ENOTSUP) {
1040 rte_eal_init_alert("failed to init mp channel");
1041 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1047 /* register multi-process action callbacks for hotplug */
1048 if (eal_mp_dev_hotplug_init() < 0) {
1049 rte_eal_init_alert("failed to register mp callback for hotplug");
1053 if (rte_bus_scan()) {
1054 rte_eal_init_alert("Cannot scan the buses for devices");
1056 rte_atomic32_clear(&run_once);
1060 phys_addrs = rte_eal_using_phys_addrs() != 0;
1062 /* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */
1063 if (internal_config.iova_mode == RTE_IOVA_DC) {
1064 /* autodetect the IOVA mapping mode */
1065 enum rte_iova_mode iova_mode = rte_bus_get_iommu_class();
1067 if (iova_mode == RTE_IOVA_DC) {
1068 RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
1071 /* if we have no access to physical addresses,
1072 * pick IOVA as VA mode.
1074 iova_mode = RTE_IOVA_VA;
1075 RTE_LOG(DEBUG, EAL, "Physical addresses are unavailable, selecting IOVA as VA mode.\n");
1076 #if defined(RTE_LIBRTE_KNI) && LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
1077 } else if (rte_eal_check_module("rte_kni") == 1) {
1078 iova_mode = RTE_IOVA_PA;
1079 RTE_LOG(DEBUG, EAL, "KNI is loaded, selecting IOVA as PA mode for better KNI perfomance.\n");
1081 } else if (is_iommu_enabled()) {
1082 /* we have an IOMMU, pick IOVA as VA mode */
1083 iova_mode = RTE_IOVA_VA;
1084 RTE_LOG(DEBUG, EAL, "IOMMU is available, selecting IOVA as VA mode.\n");
1086 /* physical addresses available, and no IOMMU
1087 * found, so pick IOVA as PA.
1089 iova_mode = RTE_IOVA_PA;
1090 RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n");
1093 #if defined(RTE_LIBRTE_KNI) && LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
1094 /* Workaround for KNI which requires physical address to work
1097 if (iova_mode == RTE_IOVA_VA &&
1098 rte_eal_check_module("rte_kni") == 1) {
1100 iova_mode = RTE_IOVA_PA;
1101 RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
1103 RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
1107 rte_eal_get_configuration()->iova_mode = iova_mode;
1109 rte_eal_get_configuration()->iova_mode =
1110 internal_config.iova_mode;
1113 if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
1114 rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
1119 RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n",
1120 rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
1122 if (internal_config.no_hugetlbfs == 0) {
1123 /* rte_config isn't initialized yet */
1124 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
1125 eal_hugepage_info_init() :
1126 eal_hugepage_info_read();
1128 rte_eal_init_alert("Cannot get hugepage information.");
1130 rte_atomic32_clear(&run_once);
1135 if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
1136 if (internal_config.no_hugetlbfs)
1137 internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
1140 if (internal_config.vmware_tsc_map == 1) {
1141 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
1142 rte_cycles_vmware_tsc_map = 1;
1143 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
1144 "you must have monitor_control.pseudo_perfctr = TRUE\n");
1146 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
1147 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
1151 if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) {
1152 rte_eal_init_alert("Cannot init logging.");
1154 rte_atomic32_clear(&run_once);
1159 if (rte_eal_vfio_setup() < 0) {
1160 rte_eal_init_alert("Cannot init VFIO");
1162 rte_atomic32_clear(&run_once);
1166 /* in secondary processes, memory init may allocate additional fbarrays
1167 * not present in primary processes, so to avoid any potential issues,
1168 * initialize memzones first.
1170 if (rte_eal_memzone_init() < 0) {
1171 rte_eal_init_alert("Cannot init memzone");
1176 if (rte_eal_memory_init() < 0) {
1177 rte_eal_init_alert("Cannot init memory");
1182 /* the directories are locked during eal_hugepage_info_init */
1183 eal_hugedirs_unlock();
1185 if (rte_eal_malloc_heap_init() < 0) {
1186 rte_eal_init_alert("Cannot init malloc heap");
1191 if (rte_eal_tailqs_init() < 0) {
1192 rte_eal_init_alert("Cannot init tail queues for objects");
1197 if (rte_eal_timer_init() < 0) {
1198 rte_eal_init_alert("Cannot init HPET or TSC timers");
1199 rte_errno = ENOTSUP;
1203 eal_check_mem_on_local_socket();
1205 eal_thread_init_master(rte_config.master_lcore);
1207 ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
1209 RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
1210 rte_config.master_lcore, (uintptr_t)thread_id, cpuset,
1211 ret == 0 ? "" : "...");
1213 RTE_LCORE_FOREACH_SLAVE(i) {
1216 * create communication pipes between master thread
1219 if (pipe(lcore_config[i].pipe_master2slave) < 0)
1220 rte_panic("Cannot create pipe\n");
1221 if (pipe(lcore_config[i].pipe_slave2master) < 0)
1222 rte_panic("Cannot create pipe\n");
1224 lcore_config[i].state = WAIT;
1226 /* create a thread for each lcore */
1227 ret = pthread_create(&lcore_config[i].thread_id, NULL,
1228 eal_thread_loop, NULL);
1230 rte_panic("Cannot create thread\n");
1232 /* Set thread_name for aid in debugging. */
1233 snprintf(thread_name, sizeof(thread_name),
1234 "lcore-slave-%d", i);
1235 ret = rte_thread_setname(lcore_config[i].thread_id,
1239 "Cannot set name for lcore thread\n");
1243 * Launch a dummy function on all slave lcores, so that master lcore
1244 * knows they are all ready when this function returns.
1246 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
1247 rte_eal_mp_wait_lcore();
1249 /* initialize services so vdevs register service during bus_probe. */
1250 ret = rte_service_init();
1252 rte_eal_init_alert("rte_service_init() failed");
1253 rte_errno = ENOEXEC;
1257 /* Probe all the buses and devices/drivers on them */
1258 if (rte_bus_probe()) {
1259 rte_eal_init_alert("Cannot probe devices");
1260 rte_errno = ENOTSUP;
1265 /* Register mp action after probe() so that we got enough info */
1266 if (rte_vfio_is_enabled("vfio") && vfio_mp_sync_setup() < 0)
1270 /* initialize default service/lcore mappings and start running. Ignore
1271 * -ENOTSUP, as it indicates no service coremask passed to EAL.
1273 ret = rte_service_start_with_defaults();
1274 if (ret < 0 && ret != -ENOTSUP) {
1275 rte_errno = ENOEXEC;
1280 * Clean up unused files in runtime directory. We do this at the end of
1281 * init and not at the beginning because we want to clean stuff up
1282 * whether we are primary or secondary process, but we cannot remove
1283 * primary process' files because secondary should be able to run even
1284 * if primary process is dead.
1286 * In no_shconf mode, no runtime directory is created in the first
1287 * place, so no cleanup needed.
1289 if (!internal_config.no_shconf && eal_clean_runtime_dir() < 0) {
1290 rte_eal_init_alert("Cannot clear runtime directory\n");
1294 eal_mcfg_complete();
1296 /* Call each registered callback, if enabled */
1303 mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
1304 void *arg __rte_unused)
1306 /* ms is const, so find this memseg */
1307 struct rte_memseg *found;
1312 found = rte_mem_virt2memseg(ms->addr, msl);
1314 found->flags &= ~RTE_MEMSEG_FLAG_DO_NOT_FREE;
1320 rte_eal_cleanup(void)
1322 /* if we're in a primary process, we need to mark hugepages as freeable
1323 * so that finalization can release them back to the system.
1325 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1326 rte_memseg_walk(mark_freeable, NULL);
1327 rte_service_finalize();
1328 rte_mp_channel_cleanup();
1329 eal_cleanup_config(&internal_config);
1333 enum rte_proc_type_t
1334 rte_eal_process_type(void)
1336 return rte_config.process_type;
1339 int rte_eal_has_hugepages(void)
1341 return ! internal_config.no_hugetlbfs;
1344 int rte_eal_has_pci(void)
1346 return !internal_config.no_pci;
1349 int rte_eal_create_uio_dev(void)
1351 return internal_config.create_uio_dev;
1355 rte_eal_vfio_intr_mode(void)
1357 return internal_config.vfio_intr_mode;
1361 rte_eal_check_module(const char *module_name)
1363 char sysfs_mod_name[PATH_MAX];
1367 if (NULL == module_name)
1370 /* Check if there is sysfs mounted */
1371 if (stat("/sys/module", &st) != 0) {
1372 RTE_LOG(DEBUG, EAL, "sysfs is not mounted! error %i (%s)\n",
1373 errno, strerror(errno));
1377 /* A module might be built-in, therefore try sysfs */
1378 n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
1379 if (n < 0 || n > PATH_MAX) {
1380 RTE_LOG(DEBUG, EAL, "Could not format module path\n");
1384 if (stat(sysfs_mod_name, &st) != 0) {
1385 RTE_LOG(DEBUG, EAL, "Module %s not found! error %i (%s)\n",
1386 sysfs_mod_name, errno, strerror(errno));
1390 /* Module has been found */