1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation.
3 * Copyright(c) 2012-2014 6WIND S.A.
21 #include <sys/queue.h>
23 #if defined(RTE_ARCH_X86)
27 #include <rte_compat.h>
28 #include <rte_common.h>
29 #include <rte_debug.h>
30 #include <rte_memory.h>
31 #include <rte_launch.h>
33 #include <rte_eal_memconfig.h>
34 #include <rte_errno.h>
35 #include <rte_per_lcore.h>
36 #include <rte_lcore.h>
37 #include <rte_service_component.h>
39 #include <rte_random.h>
40 #include <rte_cycles.h>
41 #include <rte_string_fns.h>
42 #include <rte_cpuflags.h>
43 #include <rte_interrupts.h>
46 #include <rte_devargs.h>
47 #include <rte_version.h>
48 #include <rte_atomic.h>
49 #include <malloc_heap.h>
52 #include "eal_private.h"
53 #include "eal_thread.h"
54 #include "eal_internal_cfg.h"
55 #include "eal_filesystem.h"
56 #include "eal_hugepages.h"
57 #include "eal_options.h"
60 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
62 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
64 /* Allow the application to print its usage message too if set */
65 static rte_usage_hook_t rte_application_usage_hook = NULL;
67 /* early configuration structure, when memory config is not mmapped */
68 static struct rte_mem_config early_mem_config;
70 /* define fd variable here, because file needs to be kept open for the
71 * duration of the program, as we hold a write lock on it in the primary proc */
72 static int mem_cfg_fd = -1;
74 static struct flock wr_lock = {
77 .l_start = offsetof(struct rte_mem_config, memsegs),
78 .l_len = sizeof(early_mem_config.memsegs),
81 /* Address of global and public configuration */
82 static struct rte_config rte_config = {
83 .mem_config = &early_mem_config,
86 /* internal configuration (per-core) */
87 struct lcore_config lcore_config[RTE_MAX_LCORE];
89 /* internal configuration */
90 struct internal_config internal_config;
92 /* used by rte_rdtsc() */
93 int rte_cycles_vmware_tsc_map;
95 /* platform-specific runtime dir */
96 static char runtime_dir[PATH_MAX];
98 static const char *default_runtime_dir = "/var/run";
101 eal_create_runtime_dir(void)
103 const char *directory = default_runtime_dir;
104 const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
105 const char *fallback = "/tmp";
110 /* try XDG path first, fall back to /tmp */
111 if (xdg_runtime_dir != NULL)
112 directory = xdg_runtime_dir;
114 directory = fallback;
116 /* create DPDK subdirectory under runtime dir */
117 ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
118 if (ret < 0 || ret == sizeof(tmp)) {
119 RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
123 /* create prefix-specific subdirectory under DPDK runtime dir */
124 ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
125 tmp, internal_config.hugefile_prefix);
126 if (ret < 0 || ret == sizeof(runtime_dir)) {
127 RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
131 /* create the path if it doesn't exist. no "mkdir -p" here, so do it
134 ret = mkdir(tmp, 0700);
135 if (ret < 0 && errno != EEXIST) {
136 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
137 tmp, strerror(errno));
141 ret = mkdir(runtime_dir, 0700);
142 if (ret < 0 && errno != EEXIST) {
143 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
144 runtime_dir, strerror(errno));
152 eal_get_runtime_dir(void)
157 /* Return user provided mbuf pool ops name */
159 rte_eal_mbuf_user_pool_ops(void)
161 return internal_config.user_mbuf_pool_ops_name;
164 /* Return a pointer to the configuration structure */
166 rte_eal_get_configuration(void)
172 rte_eal_iova_mode(void)
174 return rte_eal_get_configuration()->iova_mode;
177 /* parse a sysfs (or other) file containing one integer value */
179 eal_parse_sysfs_value(const char *filename, unsigned long *val)
185 if ((f = fopen(filename, "r")) == NULL) {
186 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
191 if (fgets(buf, sizeof(buf), f) == NULL) {
192 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
197 *val = strtoul(buf, &end, 0);
198 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
199 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
209 /* create memory configuration in shared/mmap memory. Take out
210 * a write lock on the memsegs, so we can auto-detect primary/secondary.
211 * This means we never close the file while running (auto-close on exit).
212 * We also don't lock the whole file, so that in future we can use read-locks
213 * on other parts, e.g. memzones, to detect if there are running secondary
216 rte_eal_config_create(void)
218 void *rte_mem_cfg_addr;
221 const char *pathname = eal_runtime_config_path();
223 if (internal_config.no_shconf)
226 /* map the config before hugepage address so that we don't waste a page */
227 if (internal_config.base_virtaddr != 0)
228 rte_mem_cfg_addr = (void *)
229 RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
230 sizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));
232 rte_mem_cfg_addr = NULL;
235 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
237 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
240 retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
243 rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
246 retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
249 rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
250 "process running?\n", pathname);
253 rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),
254 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
256 if (rte_mem_cfg_addr == MAP_FAILED){
257 rte_panic("Cannot mmap memory for rte_config\n");
259 memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
260 rte_config.mem_config = rte_mem_cfg_addr;
262 /* store address of the config in the config itself so that secondary
263 * processes could later map the config into this exact location */
264 rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
268 /* attach to an existing shared memory config */
270 rte_eal_config_attach(void)
272 struct rte_mem_config *mem_config;
274 const char *pathname = eal_runtime_config_path();
276 if (internal_config.no_shconf)
280 mem_cfg_fd = open(pathname, O_RDWR);
282 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
285 /* map it as read-only first */
286 mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
287 PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
288 if (mem_config == MAP_FAILED)
289 rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
290 errno, strerror(errno));
292 rte_config.mem_config = mem_config;
295 /* reattach the shared config at exact memory location primary process has it */
297 rte_eal_config_reattach(void)
299 struct rte_mem_config *mem_config;
300 void *rte_mem_cfg_addr;
302 if (internal_config.no_shconf)
305 /* save the address primary process has mapped shared config to */
306 rte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr;
308 /* unmap original config */
309 munmap(rte_config.mem_config, sizeof(struct rte_mem_config));
311 /* remap the config at proper address */
312 mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
313 sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
315 if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
316 if (mem_config != MAP_FAILED)
317 /* errno is stale, don't use */
318 rte_panic("Cannot mmap memory for rte_config at [%p], got [%p]"
319 " - please use '--base-virtaddr' option\n",
320 rte_mem_cfg_addr, mem_config);
322 rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
323 errno, strerror(errno));
327 rte_config.mem_config = mem_config;
330 /* Detect if we are a primary or a secondary process */
332 eal_proc_type_detect(void)
334 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
335 const char *pathname = eal_runtime_config_path();
337 /* if there no shared config, there can be no secondary processes */
338 if (!internal_config.no_shconf) {
339 /* if we can open the file but not get a write-lock we are a
340 * secondary process. NOTE: if we get a file handle back, we
341 * keep that open and don't close it to prevent a race condition
342 * between multiple opens.
344 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
345 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
346 ptype = RTE_PROC_SECONDARY;
349 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
350 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
355 /* copies data from internal config to shared config */
357 eal_update_mem_config(void)
359 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
360 mcfg->legacy_mem = internal_config.legacy_mem;
361 mcfg->single_file_segments = internal_config.single_file_segments;
364 /* copies data from shared config to internal config */
366 eal_update_internal_config(void)
368 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
369 internal_config.legacy_mem = mcfg->legacy_mem;
370 internal_config.single_file_segments = mcfg->single_file_segments;
373 /* Sets up rte_config structure with the pointer to shared memory config.*/
375 rte_config_init(void)
377 rte_config.process_type = internal_config.process_type;
379 switch (rte_config.process_type){
380 case RTE_PROC_PRIMARY:
381 rte_eal_config_create();
382 eal_update_mem_config();
384 case RTE_PROC_SECONDARY:
385 rte_eal_config_attach();
386 rte_eal_mcfg_wait_complete(rte_config.mem_config);
387 rte_eal_config_reattach();
388 eal_update_internal_config();
391 case RTE_PROC_INVALID:
392 rte_panic("Invalid process type\n");
396 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
398 eal_hugedirs_unlock(void)
402 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
404 /* skip uninitialized */
405 if (internal_config.hugepage_info[i].lock_descriptor < 0)
407 /* unlock hugepage file */
408 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
409 close(internal_config.hugepage_info[i].lock_descriptor);
410 /* reset the field */
411 internal_config.hugepage_info[i].lock_descriptor = -1;
417 eal_usage(const char *prgname)
419 printf("\nUsage: %s ", prgname);
421 printf("EAL Linux options:\n"
422 " --"OPT_SOCKET_MEM" Memory to allocate on sockets (comma separated values)\n"
423 " --"OPT_SOCKET_LIMIT" Limit memory allocation on sockets (comma separated values)\n"
424 " --"OPT_HUGE_DIR" Directory where hugetlbfs is mounted\n"
425 " --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n"
426 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
427 " --"OPT_CREATE_UIO_DEV" Create /dev/uioX (usually done by hotplug)\n"
428 " --"OPT_VFIO_INTR" Interrupt mode for VFIO (legacy|msi|msix)\n"
429 " --"OPT_LEGACY_MEM" Legacy memory mode (no dynamic allocation, contiguous segments)\n"
430 " --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
432 /* Allow the application to print its usage message too if hook is set */
433 if ( rte_application_usage_hook ) {
434 printf("===== Application Usage =====\n\n");
435 rte_application_usage_hook(prgname);
439 /* Set a per-application usage message */
441 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
443 rte_usage_hook_t old_func;
445 /* Will be NULL on the first call to denote the last usage routine. */
446 old_func = rte_application_usage_hook;
447 rte_application_usage_hook = usage_func;
453 eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
455 char * arg[RTE_MAX_NUMA_NODES];
458 uint64_t total_mem = 0;
460 len = strnlen(strval, SOCKET_MEM_STRLEN);
461 if (len == SOCKET_MEM_STRLEN) {
462 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
466 /* all other error cases will be caught later */
467 if (!isdigit(strval[len-1]))
470 /* split the optarg into separate socket values */
471 arg_num = rte_strsplit(strval, len,
472 arg, RTE_MAX_NUMA_NODES, ',');
474 /* if split failed, or 0 arguments */
478 /* parse each defined socket option */
480 for (i = 0; i < arg_num; i++) {
483 val = strtoull(arg[i], &end, 10);
485 /* check for invalid input */
487 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
494 /* check if we have a positive amount of total memory */
502 eal_parse_base_virtaddr(const char *arg)
508 addr = strtoull(arg, &end, 16);
510 /* check for errors */
511 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
514 /* make sure we don't exceed 32-bit boundary on 32-bit target */
516 if (addr >= UINTPTR_MAX)
520 /* align the addr on 16M boundary, 16MB is the minimum huge page
521 * size on IBM Power architecture. If the addr is aligned to 16MB,
522 * it can align to 2MB for x86. So this alignment can also be used
524 internal_config.base_virtaddr =
525 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
531 eal_parse_vfio_intr(const char *mode)
536 enum rte_intr_mode value;
538 { "legacy", RTE_INTR_MODE_LEGACY },
539 { "msi", RTE_INTR_MODE_MSI },
540 { "msix", RTE_INTR_MODE_MSIX },
543 for (i = 0; i < RTE_DIM(map); i++) {
544 if (!strcmp(mode, map[i].name)) {
545 internal_config.vfio_intr_mode = map[i].value;
552 /* Parse the arguments for --log-level only */
554 eal_log_level_parse(int argc, char **argv)
559 const int old_optind = optind;
560 const int old_optopt = optopt;
561 char * const old_optarg = optarg;
566 while ((opt = getopt_long(argc, argvopt, eal_short_options,
567 eal_long_options, &option_index)) != EOF) {
571 /* getopt is not happy, stop right now */
575 ret = (opt == OPT_LOG_LEVEL_NUM) ?
576 eal_parse_common_option(opt, optarg, &internal_config) : 0;
578 /* common parser is not happy */
583 /* restore getopt lib */
589 /* Parse the argument given in the command line of the application */
591 eal_parse_args(int argc, char **argv)
596 char *prgname = argv[0];
597 const int old_optind = optind;
598 const int old_optopt = optopt;
599 char * const old_optarg = optarg;
604 while ((opt = getopt_long(argc, argvopt, eal_short_options,
605 eal_long_options, &option_index)) != EOF) {
607 /* getopt is not happy, stop right now */
614 ret = eal_parse_common_option(opt, optarg, &internal_config);
615 /* common parser is not happy */
621 /* common parser handled this option */
630 case OPT_HUGE_DIR_NUM:
631 internal_config.hugepage_dir = strdup(optarg);
634 case OPT_FILE_PREFIX_NUM:
635 internal_config.hugefile_prefix = strdup(optarg);
638 case OPT_SOCKET_MEM_NUM:
639 if (eal_parse_socket_arg(optarg,
640 internal_config.socket_mem) < 0) {
641 RTE_LOG(ERR, EAL, "invalid parameters for --"
642 OPT_SOCKET_MEM "\n");
647 internal_config.force_sockets = 1;
650 case OPT_SOCKET_LIMIT_NUM:
651 if (eal_parse_socket_arg(optarg,
652 internal_config.socket_limit) < 0) {
653 RTE_LOG(ERR, EAL, "invalid parameters for --"
654 OPT_SOCKET_LIMIT "\n");
659 internal_config.force_socket_limits = 1;
662 case OPT_BASE_VIRTADDR_NUM:
663 if (eal_parse_base_virtaddr(optarg) < 0) {
664 RTE_LOG(ERR, EAL, "invalid parameter for --"
665 OPT_BASE_VIRTADDR "\n");
672 case OPT_VFIO_INTR_NUM:
673 if (eal_parse_vfio_intr(optarg) < 0) {
674 RTE_LOG(ERR, EAL, "invalid parameters for --"
682 case OPT_CREATE_UIO_DEV_NUM:
683 internal_config.create_uio_dev = 1;
686 case OPT_MBUF_POOL_OPS_NAME_NUM:
687 internal_config.user_mbuf_pool_ops_name =
692 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
693 RTE_LOG(ERR, EAL, "Option %c is not supported "
695 } else if (opt >= OPT_LONG_MIN_NUM &&
696 opt < OPT_LONG_MAX_NUM) {
697 RTE_LOG(ERR, EAL, "Option %s is not supported "
699 eal_long_options[option_index].name);
701 RTE_LOG(ERR, EAL, "Option %d is not supported "
710 /* create runtime data directory */
711 if (internal_config.no_shconf == 0 &&
712 eal_create_runtime_dir() < 0) {
713 RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
718 if (eal_adjust_config(&internal_config) != 0) {
724 if (eal_check_common_options(&internal_config) != 0) {
731 argv[optind-1] = prgname;
735 /* restore getopt lib */
744 check_socket(const struct rte_memseg_list *msl, void *arg)
746 int *socket_id = arg;
748 return *socket_id == msl->socket_id;
752 eal_check_mem_on_local_socket(void)
756 socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
758 if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
759 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
763 sync_func(__attribute__((unused)) void *arg)
769 rte_eal_mcfg_complete(void)
771 /* ALL shared mem_config related INIT DONE */
772 if (rte_config.process_type == RTE_PROC_PRIMARY)
773 rte_config.mem_config->magic = RTE_MAGIC;
775 internal_config.init_complete = 1;
779 * Request iopl privilege for all RPL, returns 0 on success
780 * iopl() call is mostly for the i386 architecture. For other architectures,
781 * return -1 to indicate IO privilege can't be changed in this way.
784 rte_eal_iopl_init(void)
786 #if defined(RTE_ARCH_X86)
794 static int rte_eal_vfio_setup(void)
796 if (rte_vfio_enable("vfio"))
803 static void rte_eal_init_alert(const char *msg)
805 fprintf(stderr, "EAL: FATAL: %s\n", msg);
806 RTE_LOG(ERR, EAL, "%s\n", msg);
809 /* Launch threads, called at application init(). */
811 rte_eal_init(int argc, char **argv)
815 static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
817 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
818 char thread_name[RTE_MAX_THREAD_NAME_LEN];
820 /* checks if the machine is adequate */
821 if (!rte_cpu_is_supported()) {
822 rte_eal_init_alert("unsupported cpu type.");
827 if (!rte_atomic32_test_and_set(&run_once)) {
828 rte_eal_init_alert("already called initialization.");
829 rte_errno = EALREADY;
833 logid = strrchr(argv[0], '/');
834 logid = strdup(logid ? logid + 1: argv[0]);
836 thread_id = pthread_self();
838 eal_reset_internal_config(&internal_config);
840 /* set log level as early as possible */
841 eal_log_level_parse(argc, argv);
843 if (rte_eal_cpu_init() < 0) {
844 rte_eal_init_alert("Cannot detect lcores.");
849 fctret = eal_parse_args(argc, argv);
851 rte_eal_init_alert("Invalid 'command line' arguments.");
853 rte_atomic32_clear(&run_once);
857 if (eal_plugins_init() < 0) {
858 rte_eal_init_alert("Cannot init plugins\n");
860 rte_atomic32_clear(&run_once);
864 if (eal_option_device_parse()) {
866 rte_atomic32_clear(&run_once);
872 if (rte_eal_intr_init() < 0) {
873 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
877 /* Put mp channel init before bus scan so that we can init the vdev
878 * bus through mp channel in the secondary process before the bus scan.
880 if (rte_mp_channel_init() < 0) {
881 rte_eal_init_alert("failed to init mp channel\n");
882 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
888 if (rte_bus_scan()) {
889 rte_eal_init_alert("Cannot scan the buses for devices\n");
891 rte_atomic32_clear(&run_once);
895 /* autodetect the iova mapping mode (default is iova_pa) */
896 rte_eal_get_configuration()->iova_mode = rte_bus_get_iommu_class();
898 /* Workaround for KNI which requires physical address to work */
899 if (rte_eal_get_configuration()->iova_mode == RTE_IOVA_VA &&
900 rte_eal_check_module("rte_kni") == 1) {
901 rte_eal_get_configuration()->iova_mode = RTE_IOVA_PA;
902 RTE_LOG(WARNING, EAL,
903 "Some devices want IOVA as VA but PA will be used because.. "
904 "KNI module inserted\n");
907 if (internal_config.no_hugetlbfs == 0) {
908 /* rte_config isn't initialized yet */
909 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
910 eal_hugepage_info_init() :
911 eal_hugepage_info_read();
913 rte_eal_init_alert("Cannot get hugepage information.");
915 rte_atomic32_clear(&run_once);
920 if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
921 if (internal_config.no_hugetlbfs)
922 internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
925 if (internal_config.vmware_tsc_map == 1) {
926 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
927 rte_cycles_vmware_tsc_map = 1;
928 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
929 "you must have monitor_control.pseudo_perfctr = TRUE\n");
931 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
932 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
936 rte_srand(rte_rdtsc());
938 if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) {
939 rte_eal_init_alert("Cannot init logging.");
941 rte_atomic32_clear(&run_once);
946 if (rte_eal_vfio_setup() < 0) {
947 rte_eal_init_alert("Cannot init VFIO\n");
949 rte_atomic32_clear(&run_once);
953 /* in secondary processes, memory init may allocate additional fbarrays
954 * not present in primary processes, so to avoid any potential issues,
955 * initialize memzones first.
957 if (rte_eal_memzone_init() < 0) {
958 rte_eal_init_alert("Cannot init memzone\n");
963 if (rte_eal_memory_init() < 0) {
964 rte_eal_init_alert("Cannot init memory\n");
969 /* the directories are locked during eal_hugepage_info_init */
970 eal_hugedirs_unlock();
972 if (rte_eal_malloc_heap_init() < 0) {
973 rte_eal_init_alert("Cannot init malloc heap\n");
978 if (rte_eal_tailqs_init() < 0) {
979 rte_eal_init_alert("Cannot init tail queues for objects\n");
984 if (rte_eal_alarm_init() < 0) {
985 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
986 /* rte_eal_alarm_init sets rte_errno on failure. */
990 if (rte_eal_timer_init() < 0) {
991 rte_eal_init_alert("Cannot init HPET or TSC timers\n");
996 eal_check_mem_on_local_socket();
998 eal_thread_init_master(rte_config.master_lcore);
1000 ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
1002 RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%x;cpuset=[%s%s])\n",
1003 rte_config.master_lcore, (int)thread_id, cpuset,
1004 ret == 0 ? "" : "...");
1006 RTE_LCORE_FOREACH_SLAVE(i) {
1009 * create communication pipes between master thread
1012 if (pipe(lcore_config[i].pipe_master2slave) < 0)
1013 rte_panic("Cannot create pipe\n");
1014 if (pipe(lcore_config[i].pipe_slave2master) < 0)
1015 rte_panic("Cannot create pipe\n");
1017 lcore_config[i].state = WAIT;
1019 /* create a thread for each lcore */
1020 ret = pthread_create(&lcore_config[i].thread_id, NULL,
1021 eal_thread_loop, NULL);
1023 rte_panic("Cannot create thread\n");
1025 /* Set thread_name for aid in debugging. */
1026 snprintf(thread_name, sizeof(thread_name),
1027 "lcore-slave-%d", i);
1028 ret = rte_thread_setname(lcore_config[i].thread_id,
1032 "Cannot set name for lcore thread\n");
1036 * Launch a dummy function on all slave lcores, so that master lcore
1037 * knows they are all ready when this function returns.
1039 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
1040 rte_eal_mp_wait_lcore();
1042 /* initialize services so vdevs register service during bus_probe. */
1043 ret = rte_service_init();
1045 rte_eal_init_alert("rte_service_init() failed\n");
1046 rte_errno = ENOEXEC;
1050 /* Probe all the buses and devices/drivers on them */
1051 if (rte_bus_probe()) {
1052 rte_eal_init_alert("Cannot probe devices\n");
1053 rte_errno = ENOTSUP;
1058 /* Register mp action after probe() so that we got enough info */
1059 if (rte_vfio_is_enabled("vfio") && vfio_mp_sync_setup() < 0)
1063 /* initialize default service/lcore mappings and start running. Ignore
1064 * -ENOTSUP, as it indicates no service coremask passed to EAL.
1066 ret = rte_service_start_with_defaults();
1067 if (ret < 0 && ret != -ENOTSUP) {
1068 rte_errno = ENOEXEC;
1072 rte_eal_mcfg_complete();
1078 mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
1079 void *arg __rte_unused)
1081 /* ms is const, so find this memseg */
1082 struct rte_memseg *found = rte_mem_virt2memseg(ms->addr, msl);
1084 found->flags &= ~RTE_MEMSEG_FLAG_DO_NOT_FREE;
1089 int __rte_experimental
1090 rte_eal_cleanup(void)
1092 /* if we're in a primary process, we need to mark hugepages as freeable
1093 * so that finalization can release them back to the system.
1095 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1096 rte_memseg_walk(mark_freeable, NULL);
1097 rte_service_finalize();
1102 enum rte_lcore_role_t
1103 rte_eal_lcore_role(unsigned lcore_id)
1105 return rte_config.lcore_role[lcore_id];
1108 enum rte_proc_type_t
1109 rte_eal_process_type(void)
1111 return rte_config.process_type;
1114 int rte_eal_has_hugepages(void)
1116 return ! internal_config.no_hugetlbfs;
1119 int rte_eal_has_pci(void)
1121 return !internal_config.no_pci;
1124 int rte_eal_create_uio_dev(void)
1126 return internal_config.create_uio_dev;
1130 rte_eal_vfio_intr_mode(void)
1132 return internal_config.vfio_intr_mode;
1136 rte_eal_check_module(const char *module_name)
1138 char sysfs_mod_name[PATH_MAX];
1142 if (NULL == module_name)
1145 /* Check if there is sysfs mounted */
1146 if (stat("/sys/module", &st) != 0) {
1147 RTE_LOG(DEBUG, EAL, "sysfs is not mounted! error %i (%s)\n",
1148 errno, strerror(errno));
1152 /* A module might be built-in, therefore try sysfs */
1153 n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
1154 if (n < 0 || n > PATH_MAX) {
1155 RTE_LOG(DEBUG, EAL, "Could not format module path\n");
1159 if (stat(sysfs_mod_name, &st) != 0) {
1160 RTE_LOG(DEBUG, EAL, "Module %s not found! error %i (%s)\n",
1161 sysfs_mod_name, errno, strerror(errno));
1165 /* Module has been found */