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>
51 #include <rte_option.h>
53 #include "eal_private.h"
54 #include "eal_thread.h"
55 #include "eal_internal_cfg.h"
56 #include "eal_filesystem.h"
57 #include "eal_hugepages.h"
58 #include "eal_options.h"
61 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
63 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
65 /* Allow the application to print its usage message too if set */
66 static rte_usage_hook_t rte_application_usage_hook = NULL;
68 /* early configuration structure, when memory config is not mmapped */
69 static struct rte_mem_config early_mem_config;
71 /* define fd variable here, because file needs to be kept open for the
72 * duration of the program, as we hold a write lock on it in the primary proc */
73 static int mem_cfg_fd = -1;
75 static struct flock wr_lock = {
78 .l_start = offsetof(struct rte_mem_config, memsegs),
79 .l_len = sizeof(early_mem_config.memsegs),
82 /* Address of global and public configuration */
83 static struct rte_config rte_config = {
84 .mem_config = &early_mem_config,
87 /* internal configuration (per-core) */
88 struct lcore_config lcore_config[RTE_MAX_LCORE];
90 /* internal configuration */
91 struct internal_config internal_config;
93 /* used by rte_rdtsc() */
94 int rte_cycles_vmware_tsc_map;
96 /* platform-specific runtime dir */
97 static char runtime_dir[PATH_MAX];
99 static const char *default_runtime_dir = "/var/run";
102 eal_create_runtime_dir(void)
104 const char *directory = default_runtime_dir;
105 const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
106 const char *fallback = "/tmp";
111 /* try XDG path first, fall back to /tmp */
112 if (xdg_runtime_dir != NULL)
113 directory = xdg_runtime_dir;
115 directory = fallback;
117 /* create DPDK subdirectory under runtime dir */
118 ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
119 if (ret < 0 || ret == sizeof(tmp)) {
120 RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
124 /* create prefix-specific subdirectory under DPDK runtime dir */
125 ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
126 tmp, internal_config.hugefile_prefix);
127 if (ret < 0 || ret == sizeof(runtime_dir)) {
128 RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
132 /* create the path if it doesn't exist. no "mkdir -p" here, so do it
135 ret = mkdir(tmp, 0700);
136 if (ret < 0 && errno != EEXIST) {
137 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
138 tmp, strerror(errno));
142 ret = mkdir(runtime_dir, 0700);
143 if (ret < 0 && errno != EEXIST) {
144 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
145 runtime_dir, strerror(errno));
153 rte_eal_get_runtime_dir(void)
158 /* Return user provided mbuf pool ops name */
160 rte_eal_mbuf_user_pool_ops(void)
162 return internal_config.user_mbuf_pool_ops_name;
165 /* Return a pointer to the configuration structure */
167 rte_eal_get_configuration(void)
173 rte_eal_iova_mode(void)
175 return rte_eal_get_configuration()->iova_mode;
178 /* parse a sysfs (or other) file containing one integer value */
180 eal_parse_sysfs_value(const char *filename, unsigned long *val)
186 if ((f = fopen(filename, "r")) == NULL) {
187 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
192 if (fgets(buf, sizeof(buf), f) == NULL) {
193 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
198 *val = strtoul(buf, &end, 0);
199 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
200 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
210 /* create memory configuration in shared/mmap memory. Take out
211 * a write lock on the memsegs, so we can auto-detect primary/secondary.
212 * This means we never close the file while running (auto-close on exit).
213 * We also don't lock the whole file, so that in future we can use read-locks
214 * on other parts, e.g. memzones, to detect if there are running secondary
217 rte_eal_config_create(void)
219 void *rte_mem_cfg_addr;
222 const char *pathname = eal_runtime_config_path();
224 if (internal_config.no_shconf)
227 /* map the config before hugepage address so that we don't waste a page */
228 if (internal_config.base_virtaddr != 0)
229 rte_mem_cfg_addr = (void *)
230 RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
231 sizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));
233 rte_mem_cfg_addr = NULL;
236 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
238 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
241 retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
244 rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
247 retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
250 rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
251 "process running?\n", pathname);
254 rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),
255 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
257 if (rte_mem_cfg_addr == MAP_FAILED){
258 rte_panic("Cannot mmap memory for rte_config\n");
260 memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
261 rte_config.mem_config = rte_mem_cfg_addr;
263 /* store address of the config in the config itself so that secondary
264 * processes could later map the config into this exact location */
265 rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
267 rte_config.mem_config->dma_maskbits = 0;
271 /* attach to an existing shared memory config */
273 rte_eal_config_attach(void)
275 struct rte_mem_config *mem_config;
277 const char *pathname = eal_runtime_config_path();
279 if (internal_config.no_shconf)
283 mem_cfg_fd = open(pathname, O_RDWR);
285 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
288 /* map it as read-only first */
289 mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
290 PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
291 if (mem_config == MAP_FAILED)
292 rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
293 errno, strerror(errno));
295 rte_config.mem_config = mem_config;
298 /* reattach the shared config at exact memory location primary process has it */
300 rte_eal_config_reattach(void)
302 struct rte_mem_config *mem_config;
303 void *rte_mem_cfg_addr;
305 if (internal_config.no_shconf)
308 /* save the address primary process has mapped shared config to */
309 rte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr;
311 /* unmap original config */
312 munmap(rte_config.mem_config, sizeof(struct rte_mem_config));
314 /* remap the config at proper address */
315 mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
316 sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
318 if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
319 if (mem_config != MAP_FAILED)
320 /* errno is stale, don't use */
321 rte_panic("Cannot mmap memory for rte_config at [%p], got [%p]"
322 " - please use '--base-virtaddr' option\n",
323 rte_mem_cfg_addr, mem_config);
325 rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
326 errno, strerror(errno));
330 rte_config.mem_config = mem_config;
333 /* Detect if we are a primary or a secondary process */
335 eal_proc_type_detect(void)
337 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
338 const char *pathname = eal_runtime_config_path();
340 /* if there no shared config, there can be no secondary processes */
341 if (!internal_config.no_shconf) {
342 /* if we can open the file but not get a write-lock we are a
343 * secondary process. NOTE: if we get a file handle back, we
344 * keep that open and don't close it to prevent a race condition
345 * between multiple opens.
347 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
348 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
349 ptype = RTE_PROC_SECONDARY;
352 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
353 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
358 /* copies data from internal config to shared config */
360 eal_update_mem_config(void)
362 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
363 mcfg->legacy_mem = internal_config.legacy_mem;
364 mcfg->single_file_segments = internal_config.single_file_segments;
367 /* copies data from shared config to internal config */
369 eal_update_internal_config(void)
371 struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
372 internal_config.legacy_mem = mcfg->legacy_mem;
373 internal_config.single_file_segments = mcfg->single_file_segments;
376 /* Sets up rte_config structure with the pointer to shared memory config.*/
378 rte_config_init(void)
380 rte_config.process_type = internal_config.process_type;
382 switch (rte_config.process_type){
383 case RTE_PROC_PRIMARY:
384 rte_eal_config_create();
385 eal_update_mem_config();
387 case RTE_PROC_SECONDARY:
388 rte_eal_config_attach();
389 rte_eal_mcfg_wait_complete(rte_config.mem_config);
390 rte_eal_config_reattach();
391 eal_update_internal_config();
394 case RTE_PROC_INVALID:
395 rte_panic("Invalid process type\n");
399 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
401 eal_hugedirs_unlock(void)
405 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
407 /* skip uninitialized */
408 if (internal_config.hugepage_info[i].lock_descriptor < 0)
410 /* unlock hugepage file */
411 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
412 close(internal_config.hugepage_info[i].lock_descriptor);
413 /* reset the field */
414 internal_config.hugepage_info[i].lock_descriptor = -1;
420 eal_usage(const char *prgname)
422 printf("\nUsage: %s ", prgname);
424 printf("EAL Linux options:\n"
425 " --"OPT_SOCKET_MEM" Memory to allocate on sockets (comma separated values)\n"
426 " --"OPT_SOCKET_LIMIT" Limit memory allocation on sockets (comma separated values)\n"
427 " --"OPT_HUGE_DIR" Directory where hugetlbfs is mounted\n"
428 " --"OPT_FILE_PREFIX" Prefix for hugepage filenames\n"
429 " --"OPT_BASE_VIRTADDR" Base virtual address\n"
430 " --"OPT_CREATE_UIO_DEV" Create /dev/uioX (usually done by hotplug)\n"
431 " --"OPT_VFIO_INTR" Interrupt mode for VFIO (legacy|msi|msix)\n"
432 " --"OPT_LEGACY_MEM" Legacy memory mode (no dynamic allocation, contiguous segments)\n"
433 " --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
435 /* Allow the application to print its usage message too if hook is set */
436 if ( rte_application_usage_hook ) {
437 printf("===== Application Usage =====\n\n");
438 rte_application_usage_hook(prgname);
442 /* Set a per-application usage message */
444 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
446 rte_usage_hook_t old_func;
448 /* Will be NULL on the first call to denote the last usage routine. */
449 old_func = rte_application_usage_hook;
450 rte_application_usage_hook = usage_func;
456 eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
458 char * arg[RTE_MAX_NUMA_NODES];
461 uint64_t total_mem = 0;
463 len = strnlen(strval, SOCKET_MEM_STRLEN);
464 if (len == SOCKET_MEM_STRLEN) {
465 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
469 /* all other error cases will be caught later */
470 if (!isdigit(strval[len-1]))
473 /* split the optarg into separate socket values */
474 arg_num = rte_strsplit(strval, len,
475 arg, RTE_MAX_NUMA_NODES, ',');
477 /* if split failed, or 0 arguments */
481 /* parse each defined socket option */
483 for (i = 0; i < arg_num; i++) {
486 val = strtoull(arg[i], &end, 10);
488 /* check for invalid input */
490 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
497 /* check if we have a positive amount of total memory */
505 eal_parse_base_virtaddr(const char *arg)
511 addr = strtoull(arg, &end, 16);
513 /* check for errors */
514 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
517 /* make sure we don't exceed 32-bit boundary on 32-bit target */
519 if (addr >= UINTPTR_MAX)
523 /* align the addr on 16M boundary, 16MB is the minimum huge page
524 * size on IBM Power architecture. If the addr is aligned to 16MB,
525 * it can align to 2MB for x86. So this alignment can also be used
527 internal_config.base_virtaddr =
528 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
534 eal_parse_vfio_intr(const char *mode)
539 enum rte_intr_mode value;
541 { "legacy", RTE_INTR_MODE_LEGACY },
542 { "msi", RTE_INTR_MODE_MSI },
543 { "msix", RTE_INTR_MODE_MSIX },
546 for (i = 0; i < RTE_DIM(map); i++) {
547 if (!strcmp(mode, map[i].name)) {
548 internal_config.vfio_intr_mode = map[i].value;
555 /* Parse the arguments for --log-level only */
557 eal_log_level_parse(int argc, char **argv)
562 const int old_optind = optind;
563 const int old_optopt = optopt;
564 char * const old_optarg = optarg;
569 while ((opt = getopt_long(argc, argvopt, eal_short_options,
570 eal_long_options, &option_index)) != EOF) {
574 /* getopt is not happy, stop right now */
578 ret = (opt == OPT_LOG_LEVEL_NUM) ?
579 eal_parse_common_option(opt, optarg, &internal_config) : 0;
581 /* common parser is not happy */
586 /* restore getopt lib */
592 /* Parse the argument given in the command line of the application */
594 eal_parse_args(int argc, char **argv)
599 char *prgname = argv[0];
600 const int old_optind = optind;
601 const int old_optopt = optopt;
602 char * const old_optarg = optarg;
608 while ((opt = getopt_long(argc, argvopt, eal_short_options,
609 eal_long_options, &option_index)) != EOF) {
612 * getopt didn't recognise the option, lets parse the
613 * registered options to see if the flag is valid
616 ret = rte_option_parse(argv[optind-1]);
625 ret = eal_parse_common_option(opt, optarg, &internal_config);
626 /* common parser is not happy */
632 /* common parser handled this option */
641 case OPT_HUGE_DIR_NUM:
642 internal_config.hugepage_dir = strdup(optarg);
645 case OPT_FILE_PREFIX_NUM:
646 internal_config.hugefile_prefix = strdup(optarg);
649 case OPT_SOCKET_MEM_NUM:
650 if (eal_parse_socket_arg(optarg,
651 internal_config.socket_mem) < 0) {
652 RTE_LOG(ERR, EAL, "invalid parameters for --"
653 OPT_SOCKET_MEM "\n");
658 internal_config.force_sockets = 1;
661 case OPT_SOCKET_LIMIT_NUM:
662 if (eal_parse_socket_arg(optarg,
663 internal_config.socket_limit) < 0) {
664 RTE_LOG(ERR, EAL, "invalid parameters for --"
665 OPT_SOCKET_LIMIT "\n");
670 internal_config.force_socket_limits = 1;
673 case OPT_BASE_VIRTADDR_NUM:
674 if (eal_parse_base_virtaddr(optarg) < 0) {
675 RTE_LOG(ERR, EAL, "invalid parameter for --"
676 OPT_BASE_VIRTADDR "\n");
683 case OPT_VFIO_INTR_NUM:
684 if (eal_parse_vfio_intr(optarg) < 0) {
685 RTE_LOG(ERR, EAL, "invalid parameters for --"
693 case OPT_CREATE_UIO_DEV_NUM:
694 internal_config.create_uio_dev = 1;
697 case OPT_MBUF_POOL_OPS_NAME_NUM:
698 internal_config.user_mbuf_pool_ops_name =
703 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
704 RTE_LOG(ERR, EAL, "Option %c is not supported "
706 } else if (opt >= OPT_LONG_MIN_NUM &&
707 opt < OPT_LONG_MAX_NUM) {
708 RTE_LOG(ERR, EAL, "Option %s is not supported "
710 eal_long_options[option_index].name);
712 RTE_LOG(ERR, EAL, "Option %d is not supported "
721 /* create runtime data directory */
722 if (internal_config.no_shconf == 0 &&
723 eal_create_runtime_dir() < 0) {
724 RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
729 if (eal_adjust_config(&internal_config) != 0) {
735 if (eal_check_common_options(&internal_config) != 0) {
742 argv[optind-1] = prgname;
746 /* restore getopt lib */
755 check_socket(const struct rte_memseg_list *msl, void *arg)
757 int *socket_id = arg;
762 return *socket_id == msl->socket_id;
766 eal_check_mem_on_local_socket(void)
770 socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
772 if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
773 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
777 sync_func(__attribute__((unused)) void *arg)
783 rte_eal_mcfg_complete(void)
785 /* ALL shared mem_config related INIT DONE */
786 if (rte_config.process_type == RTE_PROC_PRIMARY)
787 rte_config.mem_config->magic = RTE_MAGIC;
789 internal_config.init_complete = 1;
793 * Request iopl privilege for all RPL, returns 0 on success
794 * iopl() call is mostly for the i386 architecture. For other architectures,
795 * return -1 to indicate IO privilege can't be changed in this way.
798 rte_eal_iopl_init(void)
800 #if defined(RTE_ARCH_X86)
808 static int rte_eal_vfio_setup(void)
810 if (rte_vfio_enable("vfio"))
817 static void rte_eal_init_alert(const char *msg)
819 fprintf(stderr, "EAL: FATAL: %s\n", msg);
820 RTE_LOG(ERR, EAL, "%s\n", msg);
823 /* Launch threads, called at application init(). */
825 rte_eal_init(int argc, char **argv)
829 static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
831 static char logid[PATH_MAX];
832 char cpuset[RTE_CPU_AFFINITY_STR_LEN];
833 char thread_name[RTE_MAX_THREAD_NAME_LEN];
835 /* checks if the machine is adequate */
836 if (!rte_cpu_is_supported()) {
837 rte_eal_init_alert("unsupported cpu type.");
842 if (!rte_atomic32_test_and_set(&run_once)) {
843 rte_eal_init_alert("already called initialization.");
844 rte_errno = EALREADY;
848 p = strrchr(argv[0], '/');
849 strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
850 thread_id = pthread_self();
852 eal_reset_internal_config(&internal_config);
854 /* set log level as early as possible */
855 eal_log_level_parse(argc, argv);
857 if (rte_eal_cpu_init() < 0) {
858 rte_eal_init_alert("Cannot detect lcores.");
863 fctret = eal_parse_args(argc, argv);
865 rte_eal_init_alert("Invalid 'command line' arguments.");
867 rte_atomic32_clear(&run_once);
871 if (eal_plugins_init() < 0) {
872 rte_eal_init_alert("Cannot init plugins");
874 rte_atomic32_clear(&run_once);
878 if (eal_option_device_parse()) {
880 rte_atomic32_clear(&run_once);
886 if (rte_eal_intr_init() < 0) {
887 rte_eal_init_alert("Cannot init interrupt-handling thread");
891 /* Put mp channel init before bus scan so that we can init the vdev
892 * bus through mp channel in the secondary process before the bus scan.
894 if (rte_mp_channel_init() < 0) {
895 rte_eal_init_alert("failed to init mp channel");
896 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
902 /* register multi-process action callbacks for hotplug */
903 if (rte_mp_dev_hotplug_init() < 0) {
904 rte_eal_init_alert("failed to register mp callback for hotplug");
908 if (rte_bus_scan()) {
909 rte_eal_init_alert("Cannot scan the buses for devices");
911 rte_atomic32_clear(&run_once);
915 /* autodetect the iova mapping mode (default is iova_pa) */
916 rte_eal_get_configuration()->iova_mode = rte_bus_get_iommu_class();
918 /* Workaround for KNI which requires physical address to work */
919 if (rte_eal_get_configuration()->iova_mode == RTE_IOVA_VA &&
920 rte_eal_check_module("rte_kni") == 1) {
921 rte_eal_get_configuration()->iova_mode = RTE_IOVA_PA;
922 RTE_LOG(WARNING, EAL,
923 "Some devices want IOVA as VA but PA will be used because.. "
924 "KNI module inserted\n");
927 if (internal_config.no_hugetlbfs == 0) {
928 /* rte_config isn't initialized yet */
929 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
930 eal_hugepage_info_init() :
931 eal_hugepage_info_read();
933 rte_eal_init_alert("Cannot get hugepage information.");
935 rte_atomic32_clear(&run_once);
940 if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
941 if (internal_config.no_hugetlbfs)
942 internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
945 if (internal_config.vmware_tsc_map == 1) {
946 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
947 rte_cycles_vmware_tsc_map = 1;
948 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
949 "you must have monitor_control.pseudo_perfctr = TRUE\n");
951 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
952 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
956 rte_srand(rte_rdtsc());
958 if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) {
959 rte_eal_init_alert("Cannot init logging.");
961 rte_atomic32_clear(&run_once);
966 if (rte_eal_vfio_setup() < 0) {
967 rte_eal_init_alert("Cannot init VFIO");
969 rte_atomic32_clear(&run_once);
973 /* in secondary processes, memory init may allocate additional fbarrays
974 * not present in primary processes, so to avoid any potential issues,
975 * initialize memzones first.
977 if (rte_eal_memzone_init() < 0) {
978 rte_eal_init_alert("Cannot init memzone");
983 if (rte_eal_memory_init() < 0) {
984 rte_eal_init_alert("Cannot init memory");
989 /* the directories are locked during eal_hugepage_info_init */
990 eal_hugedirs_unlock();
992 if (rte_eal_malloc_heap_init() < 0) {
993 rte_eal_init_alert("Cannot init malloc heap");
998 if (rte_eal_tailqs_init() < 0) {
999 rte_eal_init_alert("Cannot init tail queues for objects");
1004 if (rte_eal_alarm_init() < 0) {
1005 rte_eal_init_alert("Cannot init interrupt-handling thread");
1006 /* rte_eal_alarm_init sets rte_errno on failure. */
1010 if (rte_eal_timer_init() < 0) {
1011 rte_eal_init_alert("Cannot init HPET or TSC timers");
1012 rte_errno = ENOTSUP;
1016 eal_check_mem_on_local_socket();
1018 eal_thread_init_master(rte_config.master_lcore);
1020 ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
1022 RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
1023 rte_config.master_lcore, (uintptr_t)thread_id, cpuset,
1024 ret == 0 ? "" : "...");
1026 RTE_LCORE_FOREACH_SLAVE(i) {
1029 * create communication pipes between master thread
1032 if (pipe(lcore_config[i].pipe_master2slave) < 0)
1033 rte_panic("Cannot create pipe\n");
1034 if (pipe(lcore_config[i].pipe_slave2master) < 0)
1035 rte_panic("Cannot create pipe\n");
1037 lcore_config[i].state = WAIT;
1039 /* create a thread for each lcore */
1040 ret = pthread_create(&lcore_config[i].thread_id, NULL,
1041 eal_thread_loop, NULL);
1043 rte_panic("Cannot create thread\n");
1045 /* Set thread_name for aid in debugging. */
1046 snprintf(thread_name, sizeof(thread_name),
1047 "lcore-slave-%d", i);
1048 ret = rte_thread_setname(lcore_config[i].thread_id,
1052 "Cannot set name for lcore thread\n");
1056 * Launch a dummy function on all slave lcores, so that master lcore
1057 * knows they are all ready when this function returns.
1059 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
1060 rte_eal_mp_wait_lcore();
1062 /* initialize services so vdevs register service during bus_probe. */
1063 ret = rte_service_init();
1065 rte_eal_init_alert("rte_service_init() failed");
1066 rte_errno = ENOEXEC;
1070 /* Probe all the buses and devices/drivers on them */
1071 if (rte_bus_probe()) {
1072 rte_eal_init_alert("Cannot probe devices");
1073 rte_errno = ENOTSUP;
1078 /* Register mp action after probe() so that we got enough info */
1079 if (rte_vfio_is_enabled("vfio") && vfio_mp_sync_setup() < 0)
1083 /* initialize default service/lcore mappings and start running. Ignore
1084 * -ENOTSUP, as it indicates no service coremask passed to EAL.
1086 ret = rte_service_start_with_defaults();
1087 if (ret < 0 && ret != -ENOTSUP) {
1088 rte_errno = ENOEXEC;
1092 rte_eal_mcfg_complete();
1094 /* Call each registered callback, if enabled */
1101 mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
1102 void *arg __rte_unused)
1104 /* ms is const, so find this memseg */
1105 struct rte_memseg *found;
1110 found = rte_mem_virt2memseg(ms->addr, msl);
1112 found->flags &= ~RTE_MEMSEG_FLAG_DO_NOT_FREE;
1117 int __rte_experimental
1118 rte_eal_cleanup(void)
1120 /* if we're in a primary process, we need to mark hugepages as freeable
1121 * so that finalization can release them back to the system.
1123 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1124 rte_memseg_walk(mark_freeable, NULL);
1125 rte_service_finalize();
1130 enum rte_lcore_role_t
1131 rte_eal_lcore_role(unsigned lcore_id)
1133 return rte_config.lcore_role[lcore_id];
1136 enum rte_proc_type_t
1137 rte_eal_process_type(void)
1139 return rte_config.process_type;
1142 int rte_eal_has_hugepages(void)
1144 return ! internal_config.no_hugetlbfs;
1147 int rte_eal_has_pci(void)
1149 return !internal_config.no_pci;
1152 int rte_eal_create_uio_dev(void)
1154 return internal_config.create_uio_dev;
1158 rte_eal_vfio_intr_mode(void)
1160 return internal_config.vfio_intr_mode;
1164 rte_eal_check_module(const char *module_name)
1166 char sysfs_mod_name[PATH_MAX];
1170 if (NULL == module_name)
1173 /* Check if there is sysfs mounted */
1174 if (stat("/sys/module", &st) != 0) {
1175 RTE_LOG(DEBUG, EAL, "sysfs is not mounted! error %i (%s)\n",
1176 errno, strerror(errno));
1180 /* A module might be built-in, therefore try sysfs */
1181 n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
1182 if (n < 0 || n > PATH_MAX) {
1183 RTE_LOG(DEBUG, EAL, "Could not format module path\n");
1187 if (stat(sysfs_mod_name, &st) != 0) {
1188 RTE_LOG(DEBUG, EAL, "Module %s not found! error %i (%s)\n",
1189 sysfs_mod_name, errno, strerror(errno));
1193 /* Module has been found */