1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
10 #include <rte_debug.h>
12 #include <eal_memcfg.h>
13 #include <rte_errno.h>
14 #include <rte_lcore.h>
15 #include <eal_thread.h>
16 #include <eal_internal_cfg.h>
17 #include <eal_filesystem.h>
18 #include <eal_options.h>
19 #include <eal_private.h>
20 #include <rte_service_component.h>
23 #include "eal_hugepages.h"
24 #include "eal_trace.h"
26 #include "eal_windows.h"
28 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
30 /* define fd variable here, because file needs to be kept open for the
31 * duration of the program, as we hold a write lock on it in the primary proc
33 static int mem_cfg_fd = -1;
35 /* internal configuration (per-core) */
36 struct lcore_config lcore_config[RTE_MAX_LCORE];
38 /* Detect if we are a primary or a secondary process */
40 eal_proc_type_detect(void)
42 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
43 const char *pathname = eal_runtime_config_path();
44 const struct rte_config *config = rte_eal_get_configuration();
46 /* if we can open the file but not get a write-lock we are a secondary
47 * process. NOTE: if we get a file handle back, we keep that open
48 * and don't close it to prevent a race condition between multiple opens
50 errno_t err = _sopen_s(&mem_cfg_fd, pathname,
51 _O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
53 OVERLAPPED soverlapped = { 0 };
54 soverlapped.Offset = sizeof(*config->mem_config);
55 soverlapped.OffsetHigh = 0;
57 HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
59 if (!LockFileEx(hwinfilehandle,
60 LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
61 sizeof(*config->mem_config), 0, &soverlapped))
62 ptype = RTE_PROC_SECONDARY;
65 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
66 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
79 eal_usage(const char *prgname)
81 rte_usage_hook_t hook = eal_get_application_usage_hook();
83 printf("\nUsage: %s ", prgname);
85 /* Allow the application to print its usage message too
89 printf("===== Application Usage =====\n\n");
94 /* Parse the arguments for --log-level only */
96 eal_log_level_parse(int argc, char **argv)
101 struct internal_config *internal_conf =
102 eal_get_internal_configuration();
106 eal_reset_internal_config(internal_conf);
108 while ((opt = getopt_long(argc, argvopt, eal_short_options,
109 eal_long_options, &option_index)) != EOF) {
113 /* getopt is not happy, stop right now */
117 ret = (opt == OPT_LOG_LEVEL_NUM) ?
118 eal_parse_common_option(opt, optarg,
121 /* common parser is not happy */
126 optind = 0; /* reset getopt lib */
129 /* Parse the argument given in the command line of the application */
131 eal_parse_args(int argc, char **argv)
136 char *prgname = argv[0];
137 struct internal_config *internal_conf =
138 eal_get_internal_configuration();
142 while ((opt = getopt_long(argc, argvopt, eal_short_options,
143 eal_long_options, &option_index)) != EOF) {
147 /* getopt is not happy, stop right now */
153 ret = eal_parse_common_option(opt, optarg, internal_conf);
154 /* common parser is not happy */
159 /* common parser handled this option */
168 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
169 RTE_LOG(ERR, EAL, "Option %c is not supported "
170 "on Windows\n", opt);
171 } else if (opt >= OPT_LONG_MIN_NUM &&
172 opt < OPT_LONG_MAX_NUM) {
173 RTE_LOG(ERR, EAL, "Option %s is not supported "
175 eal_long_options[option_index].name);
177 RTE_LOG(ERR, EAL, "Option %d is not supported "
178 "on Windows\n", opt);
185 if (eal_adjust_config(internal_conf) != 0)
189 if (eal_check_common_options(internal_conf) != 0) {
195 argv[optind - 1] = prgname;
197 optind = 0; /* reset getopt lib */
202 sync_func(void *arg __rte_unused)
208 rte_eal_init_alert(const char *msg)
210 fprintf(stderr, "EAL: FATAL: %s\n", msg);
211 RTE_LOG(ERR, EAL, "%s\n", msg);
214 /* Stubs to enable EAL trace point compilation
215 * until eal_common_trace.c can be compiled.
218 RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
219 RTE_DEFINE_PER_LCORE(void *, trace_mem);
222 __rte_trace_mem_per_thread_alloc(void)
227 trace_mem_per_thread_free(void)
232 __rte_trace_point_emit_field(size_t sz, const char *field,
241 __rte_trace_point_register(rte_trace_point_t *trace, const char *name,
242 void (*register_fn)(void))
246 RTE_SET_USED(register_fn);
251 rte_eal_cleanup(void)
253 struct internal_config *internal_conf =
254 eal_get_internal_configuration();
255 /* after this point, any DPDK pointers will become dangling */
256 rte_eal_memory_detach();
257 eal_cleanup_config(internal_conf);
261 /* Launch threads, called at application init(). */
263 rte_eal_init(int argc, char **argv)
265 int i, fctret, bscan;
266 const struct rte_config *config = rte_eal_get_configuration();
267 struct internal_config *internal_conf =
268 eal_get_internal_configuration();
271 eal_log_init(NULL, 0);
273 eal_log_level_parse(argc, argv);
275 if (eal_create_cpu_map() < 0) {
276 rte_eal_init_alert("Cannot discover CPU and NUMA.");
277 /* rte_errno is set */
281 if (rte_eal_cpu_init() < 0) {
282 rte_eal_init_alert("Cannot detect lcores.");
287 fctret = eal_parse_args(argc, argv);
291 if (eal_option_device_parse()) {
296 /* Prevent creation of shared memory files. */
297 if (internal_conf->in_memory == 0) {
298 RTE_LOG(WARNING, EAL, "Multi-process support is requested, "
299 "but not available.\n");
300 internal_conf->in_memory = 1;
301 internal_conf->no_shconf = 1;
304 if (!internal_conf->no_hugetlbfs && (eal_hugepage_info_init() < 0)) {
305 rte_eal_init_alert("Cannot get hugepage information");
310 if (internal_conf->memory == 0 && !internal_conf->force_sockets) {
311 if (internal_conf->no_hugetlbfs)
312 internal_conf->memory = MEMSIZE_IF_NO_HUGE_PAGE;
315 if (eal_mem_win32api_init() < 0) {
316 rte_eal_init_alert("Cannot access Win32 memory management");
321 if (eal_mem_virt2iova_init() < 0) {
322 /* Non-fatal error if physical addresses are not required. */
323 RTE_LOG(WARNING, EAL, "Cannot access virt2phys driver, "
324 "PA will not be available\n");
327 if (rte_eal_memzone_init() < 0) {
328 rte_eal_init_alert("Cannot init memzone");
333 if (rte_eal_memory_init() < 0) {
334 rte_eal_init_alert("Cannot init memory");
339 if (rte_eal_malloc_heap_init() < 0) {
340 rte_eal_init_alert("Cannot init malloc heap");
345 if (rte_eal_tailqs_init() < 0) {
346 rte_eal_init_alert("Cannot init tail queues for objects");
351 if (rte_eal_intr_init() < 0) {
352 rte_eal_init_alert("Cannot init interrupt-handling thread");
356 if (rte_eal_timer_init() < 0) {
357 rte_eal_init_alert("Cannot init TSC timer");
362 __rte_thread_init(config->main_lcore,
363 &lcore_config[config->main_lcore].cpuset);
365 bscan = rte_bus_scan();
367 rte_eal_init_alert("Cannot init PCI");
372 RTE_LCORE_FOREACH_WORKER(i) {
375 * create communication pipes between main thread
378 if (_pipe(lcore_config[i].pipe_main2worker,
379 sizeof(char), _O_BINARY) < 0)
380 rte_panic("Cannot create pipe\n");
381 if (_pipe(lcore_config[i].pipe_worker2main,
382 sizeof(char), _O_BINARY) < 0)
383 rte_panic("Cannot create pipe\n");
385 lcore_config[i].state = WAIT;
387 /* create a thread for each lcore */
388 if (eal_thread_create(&lcore_config[i].thread_id) != 0)
389 rte_panic("Cannot create thread\n");
392 /* Initialize services so drivers can register services during probe. */
393 ret = rte_service_init();
395 rte_eal_init_alert("rte_service_init() failed");
400 if (rte_bus_probe()) {
401 rte_eal_init_alert("Cannot probe devices");
407 * Launch a dummy function on all worker lcores, so that main lcore
408 * knows they are all ready when this function returns.
410 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MAIN);
411 rte_eal_mp_wait_lcore();
416 rte_vfio_container_dma_map(__rte_unused int container_fd,
417 __rte_unused uint64_t vaddr,
418 __rte_unused uint64_t iova,
419 __rte_unused uint64_t len)
425 rte_vfio_container_dma_unmap(__rte_unused int container_fd,
426 __rte_unused uint64_t vaddr,
427 __rte_unused uint64_t iova,
428 __rte_unused uint64_t len)