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_trace_point.h>
22 #include "eal_windows.h"
24 /* Allow the application to print its usage message too if set */
25 static rte_usage_hook_t rte_application_usage_hook;
27 /* define fd variable here, because file needs to be kept open for the
28 * duration of the program, as we hold a write lock on it in the primary proc
30 static int mem_cfg_fd = -1;
32 /* early configuration structure, when memory config is not mmapped */
33 static struct rte_mem_config early_mem_config;
35 /* Address of global and public configuration */
36 static struct rte_config rte_config = {
37 .mem_config = &early_mem_config,
40 /* internal configuration (per-core) */
41 struct lcore_config lcore_config[RTE_MAX_LCORE];
43 /* internal configuration */
44 struct internal_config internal_config;
46 /* platform-specific runtime dir */
47 static char runtime_dir[PATH_MAX];
50 rte_eal_get_runtime_dir(void)
55 /* Return a pointer to the configuration structure */
57 rte_eal_get_configuration(void)
62 /* Detect if we are a primary or a secondary process */
64 eal_proc_type_detect(void)
66 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
67 const char *pathname = eal_runtime_config_path();
69 /* if we can open the file but not get a write-lock we are a secondary
70 * process. NOTE: if we get a file handle back, we keep that open
71 * and don't close it to prevent a race condition between multiple opens
73 errno_t err = _sopen_s(&mem_cfg_fd, pathname,
74 _O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
76 OVERLAPPED soverlapped = { 0 };
77 soverlapped.Offset = sizeof(*rte_config.mem_config);
78 soverlapped.OffsetHigh = 0;
80 HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
82 if (!LockFileEx(hwinfilehandle,
83 LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
84 sizeof(*rte_config.mem_config), 0, &soverlapped))
85 ptype = RTE_PROC_SECONDARY;
88 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
89 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
96 eal_usage(const char *prgname)
98 printf("\nUsage: %s ", prgname);
100 /* Allow the application to print its usage message too
103 if (rte_application_usage_hook) {
104 printf("===== Application Usage =====\n\n");
105 rte_application_usage_hook(prgname);
109 /* Parse the arguments for --log-level only */
111 eal_log_level_parse(int argc, char **argv)
119 eal_reset_internal_config(&internal_config);
121 while ((opt = getopt_long(argc, argvopt, eal_short_options,
122 eal_long_options, &option_index)) != EOF) {
126 /* getopt is not happy, stop right now */
130 ret = (opt == OPT_LOG_LEVEL_NUM) ?
131 eal_parse_common_option(opt, optarg,
132 &internal_config) : 0;
134 /* common parser is not happy */
139 optind = 0; /* reset getopt lib */
142 /* Parse the argument given in the command line of the application */
144 eal_parse_args(int argc, char **argv)
149 char *prgname = argv[0];
153 while ((opt = getopt_long(argc, argvopt, eal_short_options,
154 eal_long_options, &option_index)) != EOF) {
158 /* getopt is not happy, stop right now */
164 ret = eal_parse_common_option(opt, optarg, &internal_config);
165 /* common parser is not happy */
170 /* common parser handled this option */
179 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
180 RTE_LOG(ERR, EAL, "Option %c is not supported "
181 "on Windows\n", opt);
182 } else if (opt >= OPT_LONG_MIN_NUM &&
183 opt < OPT_LONG_MAX_NUM) {
184 RTE_LOG(ERR, EAL, "Option %s is not supported "
186 eal_long_options[option_index].name);
188 RTE_LOG(ERR, EAL, "Option %d is not supported "
189 "on Windows\n", opt);
196 if (eal_adjust_config(&internal_config) != 0)
200 if (eal_check_common_options(&internal_config) != 0) {
206 argv[optind - 1] = prgname;
208 optind = 0; /* reset getopt lib */
213 sync_func(void *arg __rte_unused)
219 rte_eal_init_alert(const char *msg)
221 fprintf(stderr, "EAL: FATAL: %s\n", msg);
222 RTE_LOG(ERR, EAL, "%s\n", msg);
225 /* Stubs to enable EAL trace point compilation
226 * until eal_common_trace.c can be compiled.
229 RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
230 RTE_DEFINE_PER_LCORE(void *, trace_mem);
233 __rte_trace_mem_per_thread_alloc(void)
238 __rte_trace_point_emit_field(size_t sz, const char *field,
247 __rte_trace_point_register(rte_trace_point_t *trace, const char *name,
248 void (*register_fn)(void))
252 RTE_SET_USED(register_fn);
256 /* Launch threads, called at application init(). */
258 rte_eal_init(int argc, char **argv)
262 rte_eal_log_init(NULL, 0);
264 eal_log_level_parse(argc, argv);
266 if (eal_create_cpu_map() < 0) {
267 rte_eal_init_alert("Cannot discover CPU and NUMA.");
268 /* rte_errno is set */
272 if (rte_eal_cpu_init() < 0) {
273 rte_eal_init_alert("Cannot detect lcores.");
278 fctret = eal_parse_args(argc, argv);
282 eal_thread_init_master(rte_config.master_lcore);
284 RTE_LCORE_FOREACH_SLAVE(i) {
287 * create communication pipes between master thread
290 if (_pipe(lcore_config[i].pipe_master2slave,
291 sizeof(char), _O_BINARY) < 0)
292 rte_panic("Cannot create pipe\n");
293 if (_pipe(lcore_config[i].pipe_slave2master,
294 sizeof(char), _O_BINARY) < 0)
295 rte_panic("Cannot create pipe\n");
297 lcore_config[i].state = WAIT;
299 /* create a thread for each lcore */
300 if (eal_thread_create(&lcore_config[i].thread_id) != 0)
301 rte_panic("Cannot create thread\n");
305 * Launch a dummy function on all slave lcores, so that master lcore
306 * knows they are all ready when this function returns.
308 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
309 rte_eal_mp_wait_lcore();