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>
21 #include "eal_windows.h"
23 /* Allow the application to print its usage message too if set */
24 static rte_usage_hook_t rte_application_usage_hook;
26 /* define fd variable here, because file needs to be kept open for the
27 * duration of the program, as we hold a write lock on it in the primary proc
29 static int mem_cfg_fd = -1;
31 /* early configuration structure, when memory config is not mmapped */
32 static struct rte_mem_config early_mem_config;
34 /* Address of global and public configuration */
35 static struct rte_config rte_config = {
36 .mem_config = &early_mem_config,
39 /* internal configuration (per-core) */
40 struct lcore_config lcore_config[RTE_MAX_LCORE];
42 /* internal configuration */
43 struct internal_config internal_config;
45 /* platform-specific runtime dir */
46 static char runtime_dir[PATH_MAX];
49 rte_eal_get_runtime_dir(void)
54 /* Return a pointer to the configuration structure */
56 rte_eal_get_configuration(void)
61 /* Detect if we are a primary or a secondary process */
63 eal_proc_type_detect(void)
65 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
66 const char *pathname = eal_runtime_config_path();
68 /* if we can open the file but not get a write-lock we are a secondary
69 * process. NOTE: if we get a file handle back, we keep that open
70 * and don't close it to prevent a race condition between multiple opens
72 errno_t err = _sopen_s(&mem_cfg_fd, pathname,
73 _O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE);
75 OVERLAPPED soverlapped = { 0 };
76 soverlapped.Offset = sizeof(*rte_config.mem_config);
77 soverlapped.OffsetHigh = 0;
79 HANDLE hwinfilehandle = (HANDLE)_get_osfhandle(mem_cfg_fd);
81 if (!LockFileEx(hwinfilehandle,
82 LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0,
83 sizeof(*rte_config.mem_config), 0, &soverlapped))
84 ptype = RTE_PROC_SECONDARY;
87 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
88 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
95 eal_usage(const char *prgname)
97 printf("\nUsage: %s ", prgname);
99 /* Allow the application to print its usage message too
102 if (rte_application_usage_hook) {
103 printf("===== Application Usage =====\n\n");
104 rte_application_usage_hook(prgname);
108 /* Parse the arguments for --log-level only */
110 eal_log_level_parse(int argc, char **argv)
118 eal_reset_internal_config(&internal_config);
120 while ((opt = getopt_long(argc, argvopt, eal_short_options,
121 eal_long_options, &option_index)) != EOF) {
125 /* getopt is not happy, stop right now */
129 ret = (opt == OPT_LOG_LEVEL_NUM) ?
130 eal_parse_common_option(opt, optarg,
131 &internal_config) : 0;
133 /* common parser is not happy */
138 optind = 0; /* reset getopt lib */
141 /* Parse the argument given in the command line of the application */
143 eal_parse_args(int argc, char **argv)
148 char *prgname = argv[0];
152 while ((opt = getopt_long(argc, argvopt, eal_short_options,
153 eal_long_options, &option_index)) != EOF) {
157 /* getopt is not happy, stop right now */
163 ret = eal_parse_common_option(opt, optarg, &internal_config);
164 /* common parser is not happy */
169 /* common parser handled this option */
178 if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
179 RTE_LOG(ERR, EAL, "Option %c is not supported "
180 "on Windows\n", opt);
181 } else if (opt >= OPT_LONG_MIN_NUM &&
182 opt < OPT_LONG_MAX_NUM) {
183 RTE_LOG(ERR, EAL, "Option %s is not supported "
185 eal_long_options[option_index].name);
187 RTE_LOG(ERR, EAL, "Option %d is not supported "
188 "on Windows\n", opt);
195 if (eal_adjust_config(&internal_config) != 0)
199 if (eal_check_common_options(&internal_config) != 0) {
205 argv[optind - 1] = prgname;
207 optind = 0; /* reset getopt lib */
212 sync_func(void *arg __rte_unused)
218 rte_eal_init_alert(const char *msg)
220 fprintf(stderr, "EAL: FATAL: %s\n", msg);
221 RTE_LOG(ERR, EAL, "%s\n", msg);
224 /* Launch threads, called at application init(). */
226 rte_eal_init(int argc, char **argv)
230 rte_eal_log_init(NULL, 0);
232 eal_log_level_parse(argc, argv);
234 /* create a map of all processors in the system */
235 eal_create_cpu_map();
237 if (rte_eal_cpu_init() < 0) {
238 rte_eal_init_alert("Cannot detect lcores.");
243 fctret = eal_parse_args(argc, argv);
247 eal_thread_init_master(rte_config.master_lcore);
249 RTE_LCORE_FOREACH_SLAVE(i) {
252 * create communication pipes between master thread
255 if (_pipe(lcore_config[i].pipe_master2slave,
256 sizeof(char), _O_BINARY) < 0)
257 rte_panic("Cannot create pipe\n");
258 if (_pipe(lcore_config[i].pipe_slave2master,
259 sizeof(char), _O_BINARY) < 0)
260 rte_panic("Cannot create pipe\n");
262 lcore_config[i].state = WAIT;
264 /* create a thread for each lcore */
265 if (eal_thread_create(&lcore_config[i].thread_id) != 0)
266 rte_panic("Cannot create thread\n");
270 * Launch a dummy function on all slave lcores, so that master lcore
271 * knows they are all ready when this function returns.
273 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
274 rte_eal_mp_wait_lcore();