xref: /dpdk/lib/eal/common/eal_common_options.c (revision c9902a15bd005b6d4fe072cf7b60fe4ee679155f)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5 
6 #include <stdlib.h>
7 #include <unistd.h>
8 #include <string.h>
9 #ifndef RTE_EXEC_ENV_WINDOWS
10 #include <syslog.h>
11 #endif
12 #include <ctype.h>
13 #include <limits.h>
14 #include <errno.h>
15 #include <getopt.h>
16 #ifndef RTE_EXEC_ENV_WINDOWS
17 #include <dlfcn.h>
18 #include <libgen.h>
19 #endif
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #ifndef RTE_EXEC_ENV_WINDOWS
23 #include <dirent.h>
24 #endif
25 
26 #include <rte_string_fns.h>
27 #include <rte_eal.h>
28 #include <rte_log.h>
29 #include <rte_lcore.h>
30 #include <rte_memory.h>
31 #include <rte_tailq.h>
32 #include <rte_version.h>
33 #include <rte_devargs.h>
34 #include <rte_memcpy.h>
35 #ifndef RTE_EXEC_ENV_WINDOWS
36 #include <rte_telemetry.h>
37 #endif
38 #include <rte_vect.h>
39 
40 #include "eal_internal_cfg.h"
41 #include "eal_options.h"
42 #include "eal_filesystem.h"
43 #include "eal_private.h"
44 #include "eal_log.h"
45 #ifndef RTE_EXEC_ENV_WINDOWS
46 #include "eal_trace.h"
47 #endif
48 
49 #define BITS_PER_HEX 4
50 #define LCORE_OPT_LST 1
51 #define LCORE_OPT_MSK 2
52 #define LCORE_OPT_MAP 3
53 
54 const char
55 eal_short_options[] =
56 	"a:" /* allow */
57 	"b:" /* block */
58 	"c:" /* coremask */
59 	"s:" /* service coremask */
60 	"d:" /* driver */
61 	"h"  /* help */
62 	"l:" /* corelist */
63 	"S:" /* service corelist */
64 	"m:" /* memory size */
65 	"n:" /* memory channels */
66 	"r:" /* memory ranks */
67 	"v"  /* version */
68 	;
69 
70 const struct option
71 eal_long_options[] = {
72 	{OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
73 	{OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
74 	{OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
75 	{OPT_HELP,              0, NULL, OPT_HELP_NUM             },
76 	{OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
77 	{OPT_HUGE_UNLINK,       0, NULL, OPT_HUGE_UNLINK_NUM      },
78 	{OPT_IOVA_MODE,	        1, NULL, OPT_IOVA_MODE_NUM        },
79 	{OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
80 	{OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
81 	{OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
82 	{OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
83 	{OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
84 	{OPT_TRACE_MODE,        1, NULL, OPT_TRACE_MODE_NUM       },
85 	{OPT_MAIN_LCORE,        1, NULL, OPT_MAIN_LCORE_NUM       },
86 	{OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
87 	{OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
88 	{OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
89 	{OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
90 	{OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
91 	{OPT_IN_MEMORY,         0, NULL, OPT_IN_MEMORY_NUM        },
92 	{OPT_DEV_BLOCK,         1, NULL, OPT_DEV_BLOCK_NUM        },
93 	{OPT_DEV_ALLOW,		1, NULL, OPT_DEV_ALLOW_NUM	  },
94 	{OPT_PROC_TYPE,         1, NULL, OPT_PROC_TYPE_NUM        },
95 	{OPT_SOCKET_MEM,        1, NULL, OPT_SOCKET_MEM_NUM       },
96 	{OPT_SOCKET_LIMIT,      1, NULL, OPT_SOCKET_LIMIT_NUM     },
97 	{OPT_SYSLOG,            1, NULL, OPT_SYSLOG_NUM           },
98 	{OPT_VDEV,              1, NULL, OPT_VDEV_NUM             },
99 	{OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
100 	{OPT_VFIO_VF_TOKEN,     1, NULL, OPT_VFIO_VF_TOKEN_NUM    },
101 	{OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
102 	{OPT_LEGACY_MEM,        0, NULL, OPT_LEGACY_MEM_NUM       },
103 	{OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
104 	{OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
105 	{OPT_TELEMETRY,         0, NULL, OPT_TELEMETRY_NUM        },
106 	{OPT_NO_TELEMETRY,      0, NULL, OPT_NO_TELEMETRY_NUM     },
107 	{OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM},
108 
109 	{0,                     0, NULL, 0                        }
110 };
111 
112 TAILQ_HEAD(shared_driver_list, shared_driver);
113 
114 /* Definition for shared object drivers. */
115 struct shared_driver {
116 	TAILQ_ENTRY(shared_driver) next;
117 
118 	char    name[PATH_MAX];
119 	void*   lib_handle;
120 };
121 
122 /* List of external loadable drivers */
123 static struct shared_driver_list solib_list =
124 TAILQ_HEAD_INITIALIZER(solib_list);
125 
126 #ifndef RTE_EXEC_ENV_WINDOWS
127 /* Default path of external loadable drivers */
128 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
129 #endif
130 
131 /*
132  * Stringified version of solib path used by dpdk-pmdinfo.py
133  * Note: PLEASE DO NOT ALTER THIS without making a corresponding
134  * change to usertools/dpdk-pmdinfo.py
135  */
136 static const char dpdk_solib_path[] __rte_used =
137 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
138 
139 TAILQ_HEAD(device_option_list, device_option);
140 
141 struct device_option {
142 	TAILQ_ENTRY(device_option) next;
143 
144 	enum rte_devtype type;
145 	char arg[];
146 };
147 
148 static struct device_option_list devopt_list =
149 TAILQ_HEAD_INITIALIZER(devopt_list);
150 
151 static int main_lcore_parsed;
152 static int mem_parsed;
153 static int core_parsed;
154 
155 /* Allow the application to print its usage message too if set */
156 static rte_usage_hook_t rte_application_usage_hook;
157 
158 /* Returns rte_usage_hook_t */
159 rte_usage_hook_t
160 eal_get_application_usage_hook(void)
161 {
162 	return rte_application_usage_hook;
163 }
164 
165 /* Set a per-application usage message */
166 rte_usage_hook_t
167 rte_set_application_usage_hook(rte_usage_hook_t usage_func)
168 {
169 	rte_usage_hook_t old_func;
170 
171 	/* Will be NULL on the first call to denote the last usage routine. */
172 	old_func = rte_application_usage_hook;
173 	rte_application_usage_hook = usage_func;
174 
175 	return old_func;
176 }
177 
178 #ifndef RTE_EXEC_ENV_WINDOWS
179 static char **eal_args;
180 static char **eal_app_args;
181 
182 #define EAL_PARAM_REQ "/eal/params"
183 #define EAL_APP_PARAM_REQ "/eal/app_params"
184 
185 /* callback handler for telemetry library to report out EAL flags */
186 int
187 handle_eal_info_request(const char *cmd, const char *params __rte_unused,
188 		struct rte_tel_data *d)
189 {
190 	char **args;
191 	int used = 0;
192 	int i = 0;
193 
194 	if (strcmp(cmd, EAL_PARAM_REQ) == 0)
195 		args = eal_args;
196 	else
197 		args = eal_app_args;
198 
199 	rte_tel_data_start_array(d, RTE_TEL_STRING_VAL);
200 	if (args == NULL || args[0] == NULL)
201 		return 0;
202 
203 	for ( ; args[i] != NULL; i++)
204 		used = rte_tel_data_add_array_string(d, args[i]);
205 	return used;
206 }
207 
208 int
209 eal_save_args(int argc, char **argv)
210 {
211 	int i, j;
212 
213 	rte_telemetry_register_cmd(EAL_PARAM_REQ, handle_eal_info_request,
214 			"Returns EAL commandline parameters used. Takes no parameters");
215 	rte_telemetry_register_cmd(EAL_APP_PARAM_REQ, handle_eal_info_request,
216 			"Returns app commandline parameters used. Takes no parameters");
217 
218 	/* clone argv to report out later. We overprovision, but
219 	 * this does not waste huge amounts of memory
220 	 */
221 	eal_args = calloc(argc + 1, sizeof(*eal_args));
222 	if (eal_args == NULL)
223 		return -1;
224 
225 	for (i = 0; i < argc; i++) {
226 		if (strcmp(argv[i], "--") == 0)
227 			break;
228 		eal_args[i] = strdup(argv[i]);
229 	}
230 	eal_args[i++] = NULL; /* always finish with NULL */
231 
232 	/* allow reporting of any app args we know about too */
233 	if (i >= argc)
234 		return 0;
235 
236 	eal_app_args = calloc(argc - i + 1, sizeof(*eal_args));
237 	if (eal_app_args == NULL)
238 		return -1;
239 
240 	for (j = 0; i < argc; j++, i++)
241 		eal_app_args[j] = strdup(argv[i]);
242 	eal_app_args[j] = NULL;
243 
244 	return 0;
245 }
246 #endif
247 
248 static int
249 eal_option_device_add(enum rte_devtype type, const char *optarg)
250 {
251 	struct device_option *devopt;
252 	size_t optlen;
253 	int ret;
254 
255 	optlen = strlen(optarg) + 1;
256 	devopt = calloc(1, sizeof(*devopt) + optlen);
257 	if (devopt == NULL) {
258 		RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
259 		return -ENOMEM;
260 	}
261 
262 	devopt->type = type;
263 	ret = strlcpy(devopt->arg, optarg, optlen);
264 	if (ret < 0) {
265 		RTE_LOG(ERR, EAL, "Unable to copy device option\n");
266 		free(devopt);
267 		return -EINVAL;
268 	}
269 	TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
270 	return 0;
271 }
272 
273 int
274 eal_option_device_parse(void)
275 {
276 	struct device_option *devopt;
277 	void *tmp;
278 	int ret = 0;
279 
280 	TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
281 		if (ret == 0) {
282 			ret = rte_devargs_add(devopt->type, devopt->arg);
283 			if (ret)
284 				RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
285 					devopt->arg);
286 		}
287 		TAILQ_REMOVE(&devopt_list, devopt, next);
288 		free(devopt);
289 	}
290 	return ret;
291 }
292 
293 const char *
294 eal_get_hugefile_prefix(void)
295 {
296 	const struct internal_config *internal_conf =
297 		eal_get_internal_configuration();
298 
299 	if (internal_conf->hugefile_prefix != NULL)
300 		return internal_conf->hugefile_prefix;
301 	return HUGEFILE_PREFIX_DEFAULT;
302 }
303 
304 void
305 eal_reset_internal_config(struct internal_config *internal_cfg)
306 {
307 	int i;
308 
309 	internal_cfg->memory = 0;
310 	internal_cfg->force_nrank = 0;
311 	internal_cfg->force_nchannel = 0;
312 	internal_cfg->hugefile_prefix = NULL;
313 	internal_cfg->hugepage_dir = NULL;
314 	internal_cfg->force_sockets = 0;
315 	/* zero out the NUMA config */
316 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
317 		internal_cfg->socket_mem[i] = 0;
318 	internal_cfg->force_socket_limits = 0;
319 	/* zero out the NUMA limits config */
320 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
321 		internal_cfg->socket_limit[i] = 0;
322 	/* zero out hugedir descriptors */
323 	for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
324 		memset(&internal_cfg->hugepage_info[i], 0,
325 				sizeof(internal_cfg->hugepage_info[0]));
326 		internal_cfg->hugepage_info[i].lock_descriptor = -1;
327 	}
328 	internal_cfg->base_virtaddr = 0;
329 
330 #ifdef LOG_DAEMON
331 	internal_cfg->syslog_facility = LOG_DAEMON;
332 #endif
333 
334 	/* if set to NONE, interrupt mode is determined automatically */
335 	internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
336 	memset(internal_cfg->vfio_vf_token, 0,
337 			sizeof(internal_cfg->vfio_vf_token));
338 
339 #ifdef RTE_LIBEAL_USE_HPET
340 	internal_cfg->no_hpet = 0;
341 #else
342 	internal_cfg->no_hpet = 1;
343 #endif
344 	internal_cfg->vmware_tsc_map = 0;
345 	internal_cfg->create_uio_dev = 0;
346 	internal_cfg->iova_mode = RTE_IOVA_DC;
347 	internal_cfg->user_mbuf_pool_ops_name = NULL;
348 	CPU_ZERO(&internal_cfg->ctrl_cpuset);
349 	internal_cfg->init_complete = 0;
350 	internal_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH;
351 	internal_cfg->max_simd_bitwidth.forced = 0;
352 }
353 
354 static int
355 eal_plugin_add(const char *path)
356 {
357 	struct shared_driver *solib;
358 
359 	solib = malloc(sizeof(*solib));
360 	if (solib == NULL) {
361 		RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
362 		return -1;
363 	}
364 	memset(solib, 0, sizeof(*solib));
365 	strlcpy(solib->name, path, PATH_MAX);
366 	TAILQ_INSERT_TAIL(&solib_list, solib, next);
367 
368 	return 0;
369 }
370 
371 #ifdef RTE_EXEC_ENV_WINDOWS
372 int
373 eal_plugins_init(void)
374 {
375 	return 0;
376 }
377 #else
378 
379 static int
380 eal_plugindir_init(const char *path)
381 {
382 	DIR *d = NULL;
383 	struct dirent *dent = NULL;
384 	char sopath[PATH_MAX];
385 
386 	if (path == NULL || *path == '\0')
387 		return 0;
388 
389 	d = opendir(path);
390 	if (d == NULL) {
391 		RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
392 			path, strerror(errno));
393 		return -1;
394 	}
395 
396 	while ((dent = readdir(d)) != NULL) {
397 		struct stat sb;
398 		int nlen = strnlen(dent->d_name, sizeof(dent->d_name));
399 
400 		/* check if name ends in .so or .so.ABI_VERSION */
401 		if (strcmp(&dent->d_name[nlen - 3], ".so") != 0 &&
402 		    strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)],
403 			   ".so."ABI_VERSION) != 0)
404 			continue;
405 
406 		snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
407 
408 		/* if a regular file, add to list to load */
409 		if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
410 			continue;
411 
412 		if (eal_plugin_add(sopath) == -1)
413 			break;
414 	}
415 
416 	closedir(d);
417 	/* XXX this ignores failures from readdir() itself */
418 	return (dent == NULL) ? 0 : -1;
419 }
420 
421 static int
422 verify_perms(const char *dirpath)
423 {
424 	struct stat st;
425 
426 	/* if not root, check down one level first */
427 	if (strcmp(dirpath, "/") != 0) {
428 		static __thread char last_dir_checked[PATH_MAX];
429 		char copy[PATH_MAX];
430 		const char *dir;
431 
432 		strlcpy(copy, dirpath, PATH_MAX);
433 		dir = dirname(copy);
434 		if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
435 			if (verify_perms(dir) != 0)
436 				return -1;
437 			strlcpy(last_dir_checked, dir, PATH_MAX);
438 		}
439 	}
440 
441 	/* call stat to check for permissions and ensure not world writable */
442 	if (stat(dirpath, &st) != 0) {
443 		RTE_LOG(ERR, EAL, "Error with stat on %s, %s\n",
444 				dirpath, strerror(errno));
445 		return -1;
446 	}
447 	if (st.st_mode & S_IWOTH) {
448 		RTE_LOG(ERR, EAL,
449 				"Error, directory path %s is world-writable and insecure\n",
450 				dirpath);
451 		return -1;
452 	}
453 
454 	return 0;
455 }
456 
457 static void *
458 eal_dlopen(const char *pathname)
459 {
460 	void *retval = NULL;
461 	char *realp = realpath(pathname, NULL);
462 
463 	if (realp == NULL && errno == ENOENT) {
464 		/* not a full or relative path, try a load from system dirs */
465 		retval = dlopen(pathname, RTLD_NOW);
466 		if (retval == NULL)
467 			RTE_LOG(ERR, EAL, "%s\n", dlerror());
468 		return retval;
469 	}
470 	if (realp == NULL) {
471 		RTE_LOG(ERR, EAL, "Error with realpath for %s, %s\n",
472 				pathname, strerror(errno));
473 		goto out;
474 	}
475 	if (strnlen(realp, PATH_MAX) == PATH_MAX) {
476 		RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n");
477 		goto out;
478 	}
479 
480 	/* do permissions checks */
481 	if (verify_perms(realp) != 0)
482 		goto out;
483 
484 	retval = dlopen(realp, RTLD_NOW);
485 	if (retval == NULL)
486 		RTE_LOG(ERR, EAL, "%s\n", dlerror());
487 out:
488 	free(realp);
489 	return retval;
490 }
491 
492 static int
493 is_shared_build(void)
494 {
495 #define EAL_SO "librte_eal.so"
496 	char soname[32];
497 	size_t len, minlen = strlen(EAL_SO);
498 
499 	len = strlcpy(soname, EAL_SO"."ABI_VERSION, sizeof(soname));
500 	if (len > sizeof(soname)) {
501 		RTE_LOG(ERR, EAL, "Shared lib name too long in shared build check\n");
502 		len = sizeof(soname) - 1;
503 	}
504 
505 	while (len >= minlen) {
506 		void *handle;
507 
508 		/* check if we have this .so loaded, if so - shared build */
509 		RTE_LOG(DEBUG, EAL, "Checking presence of .so '%s'\n", soname);
510 		handle = dlopen(soname, RTLD_LAZY | RTLD_NOLOAD);
511 		if (handle != NULL) {
512 			RTE_LOG(INFO, EAL, "Detected shared linkage of DPDK\n");
513 			dlclose(handle);
514 			return 1;
515 		}
516 
517 		/* remove any version numbers off the end to retry */
518 		while (len-- > 0)
519 			if (soname[len] == '.') {
520 				soname[len] = '\0';
521 				break;
522 			}
523 	}
524 
525 	RTE_LOG(INFO, EAL, "Detected static linkage of DPDK\n");
526 	return 0;
527 }
528 
529 int
530 eal_plugins_init(void)
531 {
532 	struct shared_driver *solib = NULL;
533 	struct stat sb;
534 
535 	/* If we are not statically linked, add default driver loading
536 	 * path if it exists as a directory.
537 	 * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL
538 	 * shared library is not already loaded i.e. it's statically linked.)
539 	 */
540 	if (is_shared_build() &&
541 			*default_solib_dir != '\0' &&
542 			stat(default_solib_dir, &sb) == 0 &&
543 			S_ISDIR(sb.st_mode))
544 		eal_plugin_add(default_solib_dir);
545 
546 	TAILQ_FOREACH(solib, &solib_list, next) {
547 
548 		if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
549 			if (eal_plugindir_init(solib->name) == -1) {
550 				RTE_LOG(ERR, EAL,
551 					"Cannot init plugin directory %s\n",
552 					solib->name);
553 				return -1;
554 			}
555 		} else {
556 			RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
557 				solib->name);
558 			solib->lib_handle = eal_dlopen(solib->name);
559 			if (solib->lib_handle == NULL)
560 				return -1;
561 		}
562 
563 	}
564 	return 0;
565 }
566 #endif
567 
568 /*
569  * Parse the coremask given as argument (hexadecimal string) and fill
570  * the global configuration (core role and core count) with the parsed
571  * value.
572  */
573 static int xdigit2val(unsigned char c)
574 {
575 	int val;
576 
577 	if (isdigit(c))
578 		val = c - '0';
579 	else if (isupper(c))
580 		val = c - 'A' + 10;
581 	else
582 		val = c - 'a' + 10;
583 	return val;
584 }
585 
586 static int
587 eal_parse_service_coremask(const char *coremask)
588 {
589 	struct rte_config *cfg = rte_eal_get_configuration();
590 	int i, j, idx = 0;
591 	unsigned int count = 0;
592 	char c;
593 	int val;
594 	uint32_t taken_lcore_count = 0;
595 
596 	if (coremask == NULL)
597 		return -1;
598 	/* Remove all blank characters ahead and after .
599 	 * Remove 0x/0X if exists.
600 	 */
601 	while (isblank(*coremask))
602 		coremask++;
603 	if (coremask[0] == '0' && ((coremask[1] == 'x')
604 		|| (coremask[1] == 'X')))
605 		coremask += 2;
606 	i = strlen(coremask);
607 	while ((i > 0) && isblank(coremask[i - 1]))
608 		i--;
609 
610 	if (i == 0)
611 		return -1;
612 
613 	for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
614 		c = coremask[i];
615 		if (isxdigit(c) == 0) {
616 			/* invalid characters */
617 			return -1;
618 		}
619 		val = xdigit2val(c);
620 		for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
621 				j++, idx++) {
622 			if ((1 << j) & val) {
623 				/* handle main lcore already parsed */
624 				uint32_t lcore = idx;
625 				if (main_lcore_parsed &&
626 						cfg->main_lcore == lcore) {
627 					RTE_LOG(ERR, EAL,
628 						"lcore %u is main lcore, cannot use as service core\n",
629 						idx);
630 					return -1;
631 				}
632 
633 				if (eal_cpu_detected(idx) == 0) {
634 					RTE_LOG(ERR, EAL,
635 						"lcore %u unavailable\n", idx);
636 					return -1;
637 				}
638 
639 				if (cfg->lcore_role[idx] == ROLE_RTE)
640 					taken_lcore_count++;
641 
642 				lcore_config[idx].core_role = ROLE_SERVICE;
643 				count++;
644 			}
645 		}
646 	}
647 
648 	for (; i >= 0; i--)
649 		if (coremask[i] != '0')
650 			return -1;
651 
652 	for (; idx < RTE_MAX_LCORE; idx++)
653 		lcore_config[idx].core_index = -1;
654 
655 	if (count == 0)
656 		return -1;
657 
658 	if (core_parsed && taken_lcore_count != count) {
659 		RTE_LOG(WARNING, EAL,
660 			"Not all service cores are in the coremask. "
661 			"Please ensure -c or -l includes service cores\n");
662 	}
663 
664 	cfg->service_lcore_count = count;
665 	return 0;
666 }
667 
668 static int
669 eal_service_cores_parsed(void)
670 {
671 	int idx;
672 	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
673 		if (lcore_config[idx].core_role == ROLE_SERVICE)
674 			return 1;
675 	}
676 	return 0;
677 }
678 
679 static int
680 update_lcore_config(int *cores)
681 {
682 	struct rte_config *cfg = rte_eal_get_configuration();
683 	unsigned int count = 0;
684 	unsigned int i;
685 	int ret = 0;
686 
687 	for (i = 0; i < RTE_MAX_LCORE; i++) {
688 		if (cores[i] != -1) {
689 			if (eal_cpu_detected(i) == 0) {
690 				RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
691 				ret = -1;
692 				continue;
693 			}
694 			cfg->lcore_role[i] = ROLE_RTE;
695 			count++;
696 		} else {
697 			cfg->lcore_role[i] = ROLE_OFF;
698 		}
699 		lcore_config[i].core_index = cores[i];
700 	}
701 	if (!ret)
702 		cfg->lcore_count = count;
703 	return ret;
704 }
705 
706 static int
707 eal_parse_coremask(const char *coremask, int *cores)
708 {
709 	unsigned count = 0;
710 	int i, j, idx;
711 	int val;
712 	char c;
713 
714 	for (idx = 0; idx < RTE_MAX_LCORE; idx++)
715 		cores[idx] = -1;
716 	idx = 0;
717 
718 	/* Remove all blank characters ahead and after .
719 	 * Remove 0x/0X if exists.
720 	 */
721 	while (isblank(*coremask))
722 		coremask++;
723 	if (coremask[0] == '0' && ((coremask[1] == 'x')
724 		|| (coremask[1] == 'X')))
725 		coremask += 2;
726 	i = strlen(coremask);
727 	while ((i > 0) && isblank(coremask[i - 1]))
728 		i--;
729 	if (i == 0)
730 		return -1;
731 
732 	for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
733 		c = coremask[i];
734 		if (isxdigit(c) == 0) {
735 			/* invalid characters */
736 			return -1;
737 		}
738 		val = xdigit2val(c);
739 		for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
740 		{
741 			if ((1 << j) & val) {
742 				cores[idx] = count;
743 				count++;
744 			}
745 		}
746 	}
747 	for (; i >= 0; i--)
748 		if (coremask[i] != '0')
749 			return -1;
750 	if (count == 0)
751 		return -1;
752 	return 0;
753 }
754 
755 static int
756 eal_parse_service_corelist(const char *corelist)
757 {
758 	struct rte_config *cfg = rte_eal_get_configuration();
759 	int i;
760 	unsigned count = 0;
761 	char *end = NULL;
762 	uint32_t min, max, idx;
763 	uint32_t taken_lcore_count = 0;
764 
765 	if (corelist == NULL)
766 		return -1;
767 
768 	/* Remove all blank characters ahead and after */
769 	while (isblank(*corelist))
770 		corelist++;
771 	i = strlen(corelist);
772 	while ((i > 0) && isblank(corelist[i - 1]))
773 		i--;
774 
775 	/* Get list of cores */
776 	min = RTE_MAX_LCORE;
777 	do {
778 		while (isblank(*corelist))
779 			corelist++;
780 		if (*corelist == '\0')
781 			return -1;
782 		errno = 0;
783 		idx = strtoul(corelist, &end, 10);
784 		if (errno || end == NULL)
785 			return -1;
786 		if (idx >= RTE_MAX_LCORE)
787 			return -1;
788 		while (isblank(*end))
789 			end++;
790 		if (*end == '-') {
791 			min = idx;
792 		} else if ((*end == ',') || (*end == '\0')) {
793 			max = idx;
794 			if (min == RTE_MAX_LCORE)
795 				min = idx;
796 			for (idx = min; idx <= max; idx++) {
797 				if (cfg->lcore_role[idx] != ROLE_SERVICE) {
798 					/* handle main lcore already parsed */
799 					uint32_t lcore = idx;
800 					if (cfg->main_lcore == lcore &&
801 							main_lcore_parsed) {
802 						RTE_LOG(ERR, EAL,
803 							"Error: lcore %u is main lcore, cannot use as service core\n",
804 							idx);
805 						return -1;
806 					}
807 					if (cfg->lcore_role[idx] == ROLE_RTE)
808 						taken_lcore_count++;
809 
810 					lcore_config[idx].core_role =
811 							ROLE_SERVICE;
812 					count++;
813 				}
814 			}
815 			min = RTE_MAX_LCORE;
816 		} else
817 			return -1;
818 		corelist = end + 1;
819 	} while (*end != '\0');
820 
821 	if (count == 0)
822 		return -1;
823 
824 	if (core_parsed && taken_lcore_count != count) {
825 		RTE_LOG(WARNING, EAL,
826 			"Not all service cores were in the coremask. "
827 			"Please ensure -c or -l includes service cores\n");
828 	}
829 
830 	return 0;
831 }
832 
833 static int
834 eal_parse_corelist(const char *corelist, int *cores)
835 {
836 	unsigned count = 0;
837 	char *end = NULL;
838 	int min, max;
839 	int idx;
840 
841 	for (idx = 0; idx < RTE_MAX_LCORE; idx++)
842 		cores[idx] = -1;
843 
844 	/* Remove all blank characters ahead */
845 	while (isblank(*corelist))
846 		corelist++;
847 
848 	/* Get list of cores */
849 	min = RTE_MAX_LCORE;
850 	do {
851 		while (isblank(*corelist))
852 			corelist++;
853 		if (*corelist == '\0')
854 			return -1;
855 		errno = 0;
856 		idx = strtol(corelist, &end, 10);
857 		if (errno || end == NULL)
858 			return -1;
859 		if (idx < 0 || idx >= RTE_MAX_LCORE)
860 			return -1;
861 		while (isblank(*end))
862 			end++;
863 		if (*end == '-') {
864 			min = idx;
865 		} else if ((*end == ',') || (*end == '\0')) {
866 			max = idx;
867 			if (min == RTE_MAX_LCORE)
868 				min = idx;
869 			for (idx = min; idx <= max; idx++) {
870 				if (cores[idx] == -1) {
871 					cores[idx] = count;
872 					count++;
873 				}
874 			}
875 			min = RTE_MAX_LCORE;
876 		} else
877 			return -1;
878 		corelist = end + 1;
879 	} while (*end != '\0');
880 
881 	if (count == 0)
882 		return -1;
883 	return 0;
884 }
885 
886 /* Changes the lcore id of the main thread */
887 static int
888 eal_parse_main_lcore(const char *arg)
889 {
890 	char *parsing_end;
891 	struct rte_config *cfg = rte_eal_get_configuration();
892 
893 	errno = 0;
894 	cfg->main_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
895 	if (errno || parsing_end[0] != 0)
896 		return -1;
897 	if (cfg->main_lcore >= RTE_MAX_LCORE)
898 		return -1;
899 	main_lcore_parsed = 1;
900 
901 	/* ensure main core is not used as service core */
902 	if (lcore_config[cfg->main_lcore].core_role == ROLE_SERVICE) {
903 		RTE_LOG(ERR, EAL,
904 			"Error: Main lcore is used as a service core\n");
905 		return -1;
906 	}
907 
908 	return 0;
909 }
910 
911 /*
912  * Parse elem, the elem could be single number/range or '(' ')' group
913  * 1) A single number elem, it's just a simple digit. e.g. 9
914  * 2) A single range elem, two digits with a '-' between. e.g. 2-6
915  * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
916  *    Within group elem, '-' used for a range separator;
917  *                       ',' used for a single number.
918  */
919 static int
920 eal_parse_set(const char *input, rte_cpuset_t *set)
921 {
922 	unsigned idx;
923 	const char *str = input;
924 	char *end = NULL;
925 	unsigned min, max;
926 
927 	CPU_ZERO(set);
928 
929 	while (isblank(*str))
930 		str++;
931 
932 	/* only digit or left bracket is qualify for start point */
933 	if ((!isdigit(*str) && *str != '(') || *str == '\0')
934 		return -1;
935 
936 	/* process single number or single range of number */
937 	if (*str != '(') {
938 		errno = 0;
939 		idx = strtoul(str, &end, 10);
940 		if (errno || end == NULL || idx >= CPU_SETSIZE)
941 			return -1;
942 		else {
943 			while (isblank(*end))
944 				end++;
945 
946 			min = idx;
947 			max = idx;
948 			if (*end == '-') {
949 				/* process single <number>-<number> */
950 				end++;
951 				while (isblank(*end))
952 					end++;
953 				if (!isdigit(*end))
954 					return -1;
955 
956 				errno = 0;
957 				idx = strtoul(end, &end, 10);
958 				if (errno || end == NULL || idx >= CPU_SETSIZE)
959 					return -1;
960 				max = idx;
961 				while (isblank(*end))
962 					end++;
963 				if (*end != ',' && *end != '\0')
964 					return -1;
965 			}
966 
967 			if (*end != ',' && *end != '\0' &&
968 			    *end != '@')
969 				return -1;
970 
971 			for (idx = RTE_MIN(min, max);
972 			     idx <= RTE_MAX(min, max); idx++)
973 				CPU_SET(idx, set);
974 
975 			return end - input;
976 		}
977 	}
978 
979 	/* process set within bracket */
980 	str++;
981 	while (isblank(*str))
982 		str++;
983 	if (*str == '\0')
984 		return -1;
985 
986 	min = RTE_MAX_LCORE;
987 	do {
988 
989 		/* go ahead to the first digit */
990 		while (isblank(*str))
991 			str++;
992 		if (!isdigit(*str))
993 			return -1;
994 
995 		/* get the digit value */
996 		errno = 0;
997 		idx = strtoul(str, &end, 10);
998 		if (errno || end == NULL || idx >= CPU_SETSIZE)
999 			return -1;
1000 
1001 		/* go ahead to separator '-',',' and ')' */
1002 		while (isblank(*end))
1003 			end++;
1004 		if (*end == '-') {
1005 			if (min == RTE_MAX_LCORE)
1006 				min = idx;
1007 			else /* avoid continuous '-' */
1008 				return -1;
1009 		} else if ((*end == ',') || (*end == ')')) {
1010 			max = idx;
1011 			if (min == RTE_MAX_LCORE)
1012 				min = idx;
1013 			for (idx = RTE_MIN(min, max);
1014 			     idx <= RTE_MAX(min, max); idx++)
1015 				CPU_SET(idx, set);
1016 
1017 			min = RTE_MAX_LCORE;
1018 		} else
1019 			return -1;
1020 
1021 		str = end + 1;
1022 	} while (*end != '\0' && *end != ')');
1023 
1024 	/*
1025 	 * to avoid failure that tail blank makes end character check fail
1026 	 * in eal_parse_lcores( )
1027 	 */
1028 	while (isblank(*str))
1029 		str++;
1030 
1031 	return str - input;
1032 }
1033 
1034 static int
1035 check_cpuset(rte_cpuset_t *set)
1036 {
1037 	unsigned int idx;
1038 
1039 	for (idx = 0; idx < CPU_SETSIZE; idx++) {
1040 		if (!CPU_ISSET(idx, set))
1041 			continue;
1042 
1043 		if (eal_cpu_detected(idx) == 0) {
1044 			RTE_LOG(ERR, EAL, "core %u "
1045 				"unavailable\n", idx);
1046 			return -1;
1047 		}
1048 	}
1049 	return 0;
1050 }
1051 
1052 /*
1053  * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
1054  * lcores, cpus could be a single digit/range or a group.
1055  * '(' and ')' are necessary if it's a group.
1056  * If not supply '@cpus', the value of cpus uses the same as lcores.
1057  * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
1058  *   lcore 0 runs on cpuset 0x41 (cpu 0,6)
1059  *   lcore 1 runs on cpuset 0x2 (cpu 1)
1060  *   lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
1061  *   lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
1062  *   lcore 6 runs on cpuset 0x41 (cpu 0,6)
1063  *   lcore 7 runs on cpuset 0x80 (cpu 7)
1064  *   lcore 8 runs on cpuset 0x100 (cpu 8)
1065  */
1066 static int
1067 eal_parse_lcores(const char *lcores)
1068 {
1069 	struct rte_config *cfg = rte_eal_get_configuration();
1070 	rte_cpuset_t lcore_set;
1071 	unsigned int set_count;
1072 	unsigned idx = 0;
1073 	unsigned count = 0;
1074 	const char *lcore_start = NULL;
1075 	const char *end = NULL;
1076 	int offset;
1077 	rte_cpuset_t cpuset;
1078 	int lflags;
1079 	int ret = -1;
1080 
1081 	if (lcores == NULL)
1082 		return -1;
1083 
1084 	/* Remove all blank characters ahead and after */
1085 	while (isblank(*lcores))
1086 		lcores++;
1087 
1088 	CPU_ZERO(&cpuset);
1089 
1090 	/* Reset lcore config */
1091 	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1092 		cfg->lcore_role[idx] = ROLE_OFF;
1093 		lcore_config[idx].core_index = -1;
1094 		CPU_ZERO(&lcore_config[idx].cpuset);
1095 	}
1096 
1097 	/* Get list of cores */
1098 	do {
1099 		while (isblank(*lcores))
1100 			lcores++;
1101 		if (*lcores == '\0')
1102 			goto err;
1103 
1104 		lflags = 0;
1105 
1106 		/* record lcore_set start point */
1107 		lcore_start = lcores;
1108 
1109 		/* go across a complete bracket */
1110 		if (*lcore_start == '(') {
1111 			lcores += strcspn(lcores, ")");
1112 			if (*lcores++ == '\0')
1113 				goto err;
1114 		}
1115 
1116 		/* scan the separator '@', ','(next) or '\0'(finish) */
1117 		lcores += strcspn(lcores, "@,");
1118 
1119 		if (*lcores == '@') {
1120 			/* explicit assign cpuset and update the end cursor */
1121 			offset = eal_parse_set(lcores + 1, &cpuset);
1122 			if (offset < 0)
1123 				goto err;
1124 			end = lcores + 1 + offset;
1125 		} else { /* ',' or '\0' */
1126 			/* haven't given cpuset, current loop done */
1127 			end = lcores;
1128 
1129 			/* go back to check <number>-<number> */
1130 			offset = strcspn(lcore_start, "(-");
1131 			if (offset < (end - lcore_start) &&
1132 			    *(lcore_start + offset) != '(')
1133 				lflags = 1;
1134 		}
1135 
1136 		if (*end != ',' && *end != '\0')
1137 			goto err;
1138 
1139 		/* parse lcore_set from start point */
1140 		if (eal_parse_set(lcore_start, &lcore_set) < 0)
1141 			goto err;
1142 
1143 		/* without '@', by default using lcore_set as cpuset */
1144 		if (*lcores != '@')
1145 			rte_memcpy(&cpuset, &lcore_set, sizeof(cpuset));
1146 
1147 		set_count = CPU_COUNT(&lcore_set);
1148 		/* start to update lcore_set */
1149 		for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1150 			if (!CPU_ISSET(idx, &lcore_set))
1151 				continue;
1152 			set_count--;
1153 
1154 			if (cfg->lcore_role[idx] != ROLE_RTE) {
1155 				lcore_config[idx].core_index = count;
1156 				cfg->lcore_role[idx] = ROLE_RTE;
1157 				count++;
1158 			}
1159 
1160 			if (lflags) {
1161 				CPU_ZERO(&cpuset);
1162 				CPU_SET(idx, &cpuset);
1163 			}
1164 
1165 			if (check_cpuset(&cpuset) < 0)
1166 				goto err;
1167 			rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
1168 				   sizeof(rte_cpuset_t));
1169 		}
1170 
1171 		/* some cores from the lcore_set can't be handled by EAL */
1172 		if (set_count != 0)
1173 			goto err;
1174 
1175 		lcores = end + 1;
1176 	} while (*end != '\0');
1177 
1178 	if (count == 0)
1179 		goto err;
1180 
1181 	cfg->lcore_count = count;
1182 	ret = 0;
1183 
1184 err:
1185 
1186 	return ret;
1187 }
1188 
1189 #ifndef RTE_EXEC_ENV_WINDOWS
1190 static int
1191 eal_parse_syslog(const char *facility, struct internal_config *conf)
1192 {
1193 	int i;
1194 	static const struct {
1195 		const char *name;
1196 		int value;
1197 	} map[] = {
1198 		{ "auth", LOG_AUTH },
1199 		{ "cron", LOG_CRON },
1200 		{ "daemon", LOG_DAEMON },
1201 		{ "ftp", LOG_FTP },
1202 		{ "kern", LOG_KERN },
1203 		{ "lpr", LOG_LPR },
1204 		{ "mail", LOG_MAIL },
1205 		{ "news", LOG_NEWS },
1206 		{ "syslog", LOG_SYSLOG },
1207 		{ "user", LOG_USER },
1208 		{ "uucp", LOG_UUCP },
1209 		{ "local0", LOG_LOCAL0 },
1210 		{ "local1", LOG_LOCAL1 },
1211 		{ "local2", LOG_LOCAL2 },
1212 		{ "local3", LOG_LOCAL3 },
1213 		{ "local4", LOG_LOCAL4 },
1214 		{ "local5", LOG_LOCAL5 },
1215 		{ "local6", LOG_LOCAL6 },
1216 		{ "local7", LOG_LOCAL7 },
1217 		{ NULL, 0 }
1218 	};
1219 
1220 	for (i = 0; map[i].name; i++) {
1221 		if (!strcmp(facility, map[i].name)) {
1222 			conf->syslog_facility = map[i].value;
1223 			return 0;
1224 		}
1225 	}
1226 	return -1;
1227 }
1228 #endif
1229 
1230 static void
1231 eal_log_usage(void)
1232 {
1233 	unsigned int level;
1234 
1235 	printf("Log type is a pattern matching items of this list"
1236 			" (plugins may be missing):\n");
1237 	rte_log_list_types(stdout, "\t");
1238 	printf("\n");
1239 	printf("Syntax using globbing pattern:     ");
1240 	printf("--"OPT_LOG_LEVEL" pattern:level\n");
1241 	printf("Syntax using regular expression:   ");
1242 	printf("--"OPT_LOG_LEVEL" regexp,level\n");
1243 	printf("Syntax for the global level:       ");
1244 	printf("--"OPT_LOG_LEVEL" level\n");
1245 	printf("Logs are emitted if allowed by both global and specific levels.\n");
1246 	printf("\n");
1247 	printf("Log level can be a number or the first letters of its name:\n");
1248 	for (level = 1; level <= RTE_LOG_MAX; level++)
1249 		printf("\t%d   %s\n", level, eal_log_level2str(level));
1250 }
1251 
1252 static int
1253 eal_parse_log_priority(const char *level)
1254 {
1255 	size_t len = strlen(level);
1256 	unsigned long tmp;
1257 	char *end;
1258 	unsigned int i;
1259 
1260 	if (len == 0)
1261 		return -1;
1262 
1263 	/* look for named values, skip 0 which is not a valid level */
1264 	for (i = 1; i <= RTE_LOG_MAX; i++) {
1265 		if (strncmp(eal_log_level2str(i), level, len) == 0)
1266 			return i;
1267 	}
1268 
1269 	/* not a string, maybe it is numeric */
1270 	errno = 0;
1271 	tmp = strtoul(level, &end, 0);
1272 
1273 	/* check for errors */
1274 	if (errno != 0 || end == NULL || *end != '\0' ||
1275 	    tmp >= UINT32_MAX)
1276 		return -1;
1277 
1278 	return tmp;
1279 }
1280 
1281 static int
1282 eal_parse_log_level(const char *arg)
1283 {
1284 	const char *pattern = NULL;
1285 	const char *regex = NULL;
1286 	char *str, *level;
1287 	int priority;
1288 
1289 	if (strcmp(arg, "help") == 0) {
1290 		eal_log_usage();
1291 		exit(EXIT_SUCCESS);
1292 	}
1293 
1294 	str = strdup(arg);
1295 	if (str == NULL)
1296 		return -1;
1297 
1298 	if ((level = strchr(str, ','))) {
1299 		regex = str;
1300 		*level++ = '\0';
1301 	} else if ((level = strchr(str, ':'))) {
1302 		pattern = str;
1303 		*level++ = '\0';
1304 	} else {
1305 		level = str;
1306 	}
1307 
1308 	priority = eal_parse_log_priority(level);
1309 	if (priority <= 0) {
1310 		fprintf(stderr, "Invalid log level: %s\n", level);
1311 		goto fail;
1312 	}
1313 	if (priority > (int)RTE_LOG_MAX) {
1314 		fprintf(stderr, "Log level %d higher than maximum (%d)\n",
1315 				priority, RTE_LOG_MAX);
1316 		priority = RTE_LOG_MAX;
1317 	}
1318 
1319 	if (regex) {
1320 		if (rte_log_set_level_regexp(regex, priority) < 0) {
1321 			fprintf(stderr, "cannot set log level %s,%d\n",
1322 				regex, priority);
1323 			goto fail;
1324 		}
1325 		if (eal_log_save_regexp(regex, priority) < 0)
1326 			goto fail;
1327 	} else if (pattern) {
1328 		if (rte_log_set_level_pattern(pattern, priority) < 0) {
1329 			fprintf(stderr, "cannot set log level %s:%d\n",
1330 				pattern, priority);
1331 			goto fail;
1332 		}
1333 		if (eal_log_save_pattern(pattern, priority) < 0)
1334 			goto fail;
1335 	} else {
1336 		rte_log_set_global_level(priority);
1337 	}
1338 
1339 	free(str);
1340 	return 0;
1341 
1342 fail:
1343 	free(str);
1344 	return -1;
1345 }
1346 
1347 static enum rte_proc_type_t
1348 eal_parse_proc_type(const char *arg)
1349 {
1350 	if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1351 		return RTE_PROC_PRIMARY;
1352 	if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1353 		return RTE_PROC_SECONDARY;
1354 	if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1355 		return RTE_PROC_AUTO;
1356 
1357 	return RTE_PROC_INVALID;
1358 }
1359 
1360 static int
1361 eal_parse_iova_mode(const char *name)
1362 {
1363 	int mode;
1364 	struct internal_config *internal_conf =
1365 		eal_get_internal_configuration();
1366 
1367 	if (name == NULL)
1368 		return -1;
1369 
1370 	if (!strcmp("pa", name))
1371 		mode = RTE_IOVA_PA;
1372 	else if (!strcmp("va", name))
1373 		mode = RTE_IOVA_VA;
1374 	else
1375 		return -1;
1376 
1377 	internal_conf->iova_mode = mode;
1378 	return 0;
1379 }
1380 
1381 static int
1382 eal_parse_simd_bitwidth(const char *arg)
1383 {
1384 	char *end;
1385 	unsigned long bitwidth;
1386 	int ret;
1387 	struct internal_config *internal_conf =
1388 		eal_get_internal_configuration();
1389 
1390 	if (arg == NULL || arg[0] == '\0')
1391 		return -1;
1392 
1393 	errno = 0;
1394 	bitwidth = strtoul(arg, &end, 0);
1395 
1396 	/* check for errors */
1397 	if (errno != 0 || end == NULL || *end != '\0' || bitwidth > RTE_VECT_SIMD_MAX)
1398 		return -1;
1399 
1400 	if (bitwidth == 0)
1401 		bitwidth = (unsigned long) RTE_VECT_SIMD_MAX;
1402 	ret = rte_vect_set_max_simd_bitwidth(bitwidth);
1403 	if (ret < 0)
1404 		return -1;
1405 	internal_conf->max_simd_bitwidth.forced = 1;
1406 	return 0;
1407 }
1408 
1409 static int
1410 eal_parse_base_virtaddr(const char *arg)
1411 {
1412 	char *end;
1413 	uint64_t addr;
1414 	struct internal_config *internal_conf =
1415 		eal_get_internal_configuration();
1416 
1417 	errno = 0;
1418 	addr = strtoull(arg, &end, 16);
1419 
1420 	/* check for errors */
1421 	if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1422 		return -1;
1423 
1424 	/* make sure we don't exceed 32-bit boundary on 32-bit target */
1425 #ifndef RTE_ARCH_64
1426 	if (addr >= UINTPTR_MAX)
1427 		return -1;
1428 #endif
1429 
1430 	/* align the addr on 16M boundary, 16MB is the minimum huge page
1431 	 * size on IBM Power architecture. If the addr is aligned to 16MB,
1432 	 * it can align to 2MB for x86. So this alignment can also be used
1433 	 * on x86 and other architectures.
1434 	 */
1435 	internal_conf->base_virtaddr =
1436 		RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1437 
1438 	return 0;
1439 }
1440 
1441 /* caller is responsible for freeing the returned string */
1442 static char *
1443 available_cores(void)
1444 {
1445 	char *str = NULL;
1446 	int previous;
1447 	int sequence;
1448 	char *tmp;
1449 	int idx;
1450 
1451 	/* find the first available cpu */
1452 	for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1453 		if (eal_cpu_detected(idx) == 0)
1454 			continue;
1455 		break;
1456 	}
1457 	if (idx >= RTE_MAX_LCORE)
1458 		return NULL;
1459 
1460 	/* first sequence */
1461 	if (asprintf(&str, "%d", idx) < 0)
1462 		return NULL;
1463 	previous = idx;
1464 	sequence = 0;
1465 
1466 	for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1467 		if (eal_cpu_detected(idx) == 0)
1468 			continue;
1469 
1470 		if (idx == previous + 1) {
1471 			previous = idx;
1472 			sequence = 1;
1473 			continue;
1474 		}
1475 
1476 		/* finish current sequence */
1477 		if (sequence) {
1478 			if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1479 				free(str);
1480 				return NULL;
1481 			}
1482 			free(str);
1483 			str = tmp;
1484 		}
1485 
1486 		/* new sequence */
1487 		if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1488 			free(str);
1489 			return NULL;
1490 		}
1491 		free(str);
1492 		str = tmp;
1493 		previous = idx;
1494 		sequence = 0;
1495 	}
1496 
1497 	/* finish last sequence */
1498 	if (sequence) {
1499 		if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1500 			free(str);
1501 			return NULL;
1502 		}
1503 		free(str);
1504 		str = tmp;
1505 	}
1506 
1507 	return str;
1508 }
1509 
1510 int
1511 eal_parse_common_option(int opt, const char *optarg,
1512 			struct internal_config *conf)
1513 {
1514 	static int b_used;
1515 	static int a_used;
1516 
1517 	switch (opt) {
1518 	case 'b':
1519 		if (a_used)
1520 			goto ba_conflict;
1521 		if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0)
1522 			return -1;
1523 		b_used = 1;
1524 		break;
1525 
1526 	case 'a':
1527 		if (b_used)
1528 			goto ba_conflict;
1529 		if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0)
1530 			return -1;
1531 		a_used = 1;
1532 		break;
1533 	/* coremask */
1534 	case 'c': {
1535 		int lcore_indexes[RTE_MAX_LCORE];
1536 
1537 		if (eal_service_cores_parsed())
1538 			RTE_LOG(WARNING, EAL,
1539 				"Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1540 		if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1541 			RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1542 			return -1;
1543 		}
1544 		if (update_lcore_config(lcore_indexes) < 0) {
1545 			char *available = available_cores();
1546 
1547 			RTE_LOG(ERR, EAL,
1548 				"invalid coremask, please check specified cores are part of %s\n",
1549 				available);
1550 			free(available);
1551 			return -1;
1552 		}
1553 
1554 		if (core_parsed) {
1555 			RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1556 				(core_parsed == LCORE_OPT_LST) ? "-l" :
1557 				(core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1558 				"-c");
1559 			return -1;
1560 		}
1561 
1562 		core_parsed = LCORE_OPT_MSK;
1563 		break;
1564 	}
1565 	/* corelist */
1566 	case 'l': {
1567 		int lcore_indexes[RTE_MAX_LCORE];
1568 
1569 		if (eal_service_cores_parsed())
1570 			RTE_LOG(WARNING, EAL,
1571 				"Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1572 
1573 		if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1574 			RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1575 			return -1;
1576 		}
1577 		if (update_lcore_config(lcore_indexes) < 0) {
1578 			char *available = available_cores();
1579 
1580 			RTE_LOG(ERR, EAL,
1581 				"invalid core list, please check specified cores are part of %s\n",
1582 				available);
1583 			free(available);
1584 			return -1;
1585 		}
1586 
1587 		if (core_parsed) {
1588 			RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1589 				(core_parsed == LCORE_OPT_MSK) ? "-c" :
1590 				(core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1591 				"-l");
1592 			return -1;
1593 		}
1594 
1595 		core_parsed = LCORE_OPT_LST;
1596 		break;
1597 	}
1598 	/* service coremask */
1599 	case 's':
1600 		if (eal_parse_service_coremask(optarg) < 0) {
1601 			RTE_LOG(ERR, EAL, "invalid service coremask\n");
1602 			return -1;
1603 		}
1604 		break;
1605 	/* service corelist */
1606 	case 'S':
1607 		if (eal_parse_service_corelist(optarg) < 0) {
1608 			RTE_LOG(ERR, EAL, "invalid service core list\n");
1609 			return -1;
1610 		}
1611 		break;
1612 	/* size of memory */
1613 	case 'm':
1614 		conf->memory = atoi(optarg);
1615 		conf->memory *= 1024ULL;
1616 		conf->memory *= 1024ULL;
1617 		mem_parsed = 1;
1618 		break;
1619 	/* force number of channels */
1620 	case 'n':
1621 		conf->force_nchannel = atoi(optarg);
1622 		if (conf->force_nchannel == 0) {
1623 			RTE_LOG(ERR, EAL, "invalid channel number\n");
1624 			return -1;
1625 		}
1626 		break;
1627 	/* force number of ranks */
1628 	case 'r':
1629 		conf->force_nrank = atoi(optarg);
1630 		if (conf->force_nrank == 0 ||
1631 		    conf->force_nrank > 16) {
1632 			RTE_LOG(ERR, EAL, "invalid rank number\n");
1633 			return -1;
1634 		}
1635 		break;
1636 	/* force loading of external driver */
1637 	case 'd':
1638 		if (eal_plugin_add(optarg) == -1)
1639 			return -1;
1640 		break;
1641 	case 'v':
1642 		/* since message is explicitly requested by user, we
1643 		 * write message at highest log level so it can always
1644 		 * be seen
1645 		 * even if info or warning messages are disabled */
1646 		RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1647 		break;
1648 
1649 	/* long options */
1650 	case OPT_HUGE_UNLINK_NUM:
1651 		conf->hugepage_unlink = 1;
1652 		break;
1653 
1654 	case OPT_NO_HUGE_NUM:
1655 		conf->no_hugetlbfs = 1;
1656 		/* no-huge is legacy mem */
1657 		conf->legacy_mem = 1;
1658 		break;
1659 
1660 	case OPT_NO_PCI_NUM:
1661 		conf->no_pci = 1;
1662 		break;
1663 
1664 	case OPT_NO_HPET_NUM:
1665 		conf->no_hpet = 1;
1666 		break;
1667 
1668 	case OPT_VMWARE_TSC_MAP_NUM:
1669 		conf->vmware_tsc_map = 1;
1670 		break;
1671 
1672 	case OPT_NO_SHCONF_NUM:
1673 		conf->no_shconf = 1;
1674 		break;
1675 
1676 	case OPT_IN_MEMORY_NUM:
1677 		conf->in_memory = 1;
1678 		/* in-memory is a superset of noshconf and huge-unlink */
1679 		conf->no_shconf = 1;
1680 		conf->hugepage_unlink = 1;
1681 		break;
1682 
1683 	case OPT_PROC_TYPE_NUM:
1684 		conf->process_type = eal_parse_proc_type(optarg);
1685 		break;
1686 
1687 	case OPT_MAIN_LCORE_NUM:
1688 		if (eal_parse_main_lcore(optarg) < 0) {
1689 			RTE_LOG(ERR, EAL, "invalid parameter for --"
1690 					OPT_MAIN_LCORE "\n");
1691 			return -1;
1692 		}
1693 		break;
1694 
1695 	case OPT_VDEV_NUM:
1696 		if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1697 				optarg) < 0) {
1698 			return -1;
1699 		}
1700 		break;
1701 
1702 #ifndef RTE_EXEC_ENV_WINDOWS
1703 	case OPT_SYSLOG_NUM:
1704 		if (eal_parse_syslog(optarg, conf) < 0) {
1705 			RTE_LOG(ERR, EAL, "invalid parameters for --"
1706 					OPT_SYSLOG "\n");
1707 			return -1;
1708 		}
1709 		break;
1710 #endif
1711 
1712 	case OPT_LOG_LEVEL_NUM: {
1713 		if (eal_parse_log_level(optarg) < 0) {
1714 			RTE_LOG(ERR, EAL,
1715 				"invalid parameters for --"
1716 				OPT_LOG_LEVEL "\n");
1717 			return -1;
1718 		}
1719 		break;
1720 	}
1721 
1722 #ifndef RTE_EXEC_ENV_WINDOWS
1723 	case OPT_TRACE_NUM: {
1724 		if (eal_trace_args_save(optarg) < 0) {
1725 			RTE_LOG(ERR, EAL, "invalid parameters for --"
1726 				OPT_TRACE "\n");
1727 			return -1;
1728 		}
1729 		break;
1730 	}
1731 
1732 	case OPT_TRACE_DIR_NUM: {
1733 		if (eal_trace_dir_args_save(optarg) < 0) {
1734 			RTE_LOG(ERR, EAL, "invalid parameters for --"
1735 				OPT_TRACE_DIR "\n");
1736 			return -1;
1737 		}
1738 		break;
1739 	}
1740 
1741 	case OPT_TRACE_BUF_SIZE_NUM: {
1742 		if (eal_trace_bufsz_args_save(optarg) < 0) {
1743 			RTE_LOG(ERR, EAL, "invalid parameters for --"
1744 				OPT_TRACE_BUF_SIZE "\n");
1745 			return -1;
1746 		}
1747 		break;
1748 	}
1749 
1750 	case OPT_TRACE_MODE_NUM: {
1751 		if (eal_trace_mode_args_save(optarg) < 0) {
1752 			RTE_LOG(ERR, EAL, "invalid parameters for --"
1753 				OPT_TRACE_MODE "\n");
1754 			return -1;
1755 		}
1756 		break;
1757 	}
1758 #endif /* !RTE_EXEC_ENV_WINDOWS */
1759 
1760 	case OPT_LCORES_NUM:
1761 		if (eal_parse_lcores(optarg) < 0) {
1762 			RTE_LOG(ERR, EAL, "invalid parameter for --"
1763 				OPT_LCORES "\n");
1764 			return -1;
1765 		}
1766 
1767 		if (core_parsed) {
1768 			RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1769 				(core_parsed == LCORE_OPT_LST) ? "-l" :
1770 				(core_parsed == LCORE_OPT_MSK) ? "-c" :
1771 				"--lcore");
1772 			return -1;
1773 		}
1774 
1775 		core_parsed = LCORE_OPT_MAP;
1776 		break;
1777 	case OPT_LEGACY_MEM_NUM:
1778 		conf->legacy_mem = 1;
1779 		break;
1780 	case OPT_SINGLE_FILE_SEGMENTS_NUM:
1781 		conf->single_file_segments = 1;
1782 		break;
1783 	case OPT_IOVA_MODE_NUM:
1784 		if (eal_parse_iova_mode(optarg) < 0) {
1785 			RTE_LOG(ERR, EAL, "invalid parameters for --"
1786 				OPT_IOVA_MODE "\n");
1787 			return -1;
1788 		}
1789 		break;
1790 	case OPT_BASE_VIRTADDR_NUM:
1791 		if (eal_parse_base_virtaddr(optarg) < 0) {
1792 			RTE_LOG(ERR, EAL, "invalid parameter for --"
1793 					OPT_BASE_VIRTADDR "\n");
1794 			return -1;
1795 		}
1796 		break;
1797 	case OPT_TELEMETRY_NUM:
1798 		break;
1799 	case OPT_NO_TELEMETRY_NUM:
1800 		conf->no_telemetry = 1;
1801 		break;
1802 	case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM:
1803 		if (eal_parse_simd_bitwidth(optarg) < 0) {
1804 			RTE_LOG(ERR, EAL, "invalid parameter for --"
1805 					OPT_FORCE_MAX_SIMD_BITWIDTH "\n");
1806 			return -1;
1807 		}
1808 		break;
1809 
1810 	/* don't know what to do, leave this to caller */
1811 	default:
1812 		return 1;
1813 
1814 	}
1815 
1816 	return 0;
1817 
1818 ba_conflict:
1819 	RTE_LOG(ERR, EAL,
1820 		"Options allow (-a) and block (-b) can't be used at the same time\n");
1821 	return -1;
1822 }
1823 
1824 static void
1825 eal_auto_detect_cores(struct rte_config *cfg)
1826 {
1827 	unsigned int lcore_id;
1828 	unsigned int removed = 0;
1829 	rte_cpuset_t affinity_set;
1830 
1831 	if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1832 				&affinity_set))
1833 		CPU_ZERO(&affinity_set);
1834 
1835 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1836 		if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1837 		    !CPU_ISSET(lcore_id, &affinity_set)) {
1838 			cfg->lcore_role[lcore_id] = ROLE_OFF;
1839 			removed++;
1840 		}
1841 	}
1842 
1843 	cfg->lcore_count -= removed;
1844 }
1845 
1846 static void
1847 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1848 {
1849 	rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1850 	rte_cpuset_t default_set;
1851 	unsigned int lcore_id;
1852 
1853 	for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1854 		if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1855 			continue;
1856 		RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1857 	}
1858 	RTE_CPU_NOT(cpuset, cpuset);
1859 
1860 	if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1861 				&default_set))
1862 		CPU_ZERO(&default_set);
1863 
1864 	RTE_CPU_AND(cpuset, cpuset, &default_set);
1865 
1866 	/* if no remaining cpu, use main lcore cpu affinity */
1867 	if (!CPU_COUNT(cpuset)) {
1868 		memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset,
1869 			sizeof(*cpuset));
1870 	}
1871 }
1872 
1873 int
1874 eal_cleanup_config(struct internal_config *internal_cfg)
1875 {
1876 	if (internal_cfg->hugefile_prefix != NULL)
1877 		free(internal_cfg->hugefile_prefix);
1878 	if (internal_cfg->hugepage_dir != NULL)
1879 		free(internal_cfg->hugepage_dir);
1880 	if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1881 		free(internal_cfg->user_mbuf_pool_ops_name);
1882 
1883 	return 0;
1884 }
1885 
1886 int
1887 eal_adjust_config(struct internal_config *internal_cfg)
1888 {
1889 	int i;
1890 	struct rte_config *cfg = rte_eal_get_configuration();
1891 	struct internal_config *internal_conf =
1892 		eal_get_internal_configuration();
1893 
1894 	if (!core_parsed)
1895 		eal_auto_detect_cores(cfg);
1896 
1897 	if (internal_conf->process_type == RTE_PROC_AUTO)
1898 		internal_conf->process_type = eal_proc_type_detect();
1899 
1900 	/* default main lcore is the first one */
1901 	if (!main_lcore_parsed) {
1902 		cfg->main_lcore = rte_get_next_lcore(-1, 0, 0);
1903 		if (cfg->main_lcore >= RTE_MAX_LCORE)
1904 			return -1;
1905 		lcore_config[cfg->main_lcore].core_role = ROLE_RTE;
1906 	}
1907 
1908 	compute_ctrl_threads_cpuset(internal_cfg);
1909 
1910 	/* if no memory amounts were requested, this will result in 0 and
1911 	 * will be overridden later, right after eal_hugepage_info_init() */
1912 	for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1913 		internal_cfg->memory += internal_cfg->socket_mem[i];
1914 
1915 	return 0;
1916 }
1917 
1918 int
1919 eal_check_common_options(struct internal_config *internal_cfg)
1920 {
1921 	struct rte_config *cfg = rte_eal_get_configuration();
1922 	const struct internal_config *internal_conf =
1923 		eal_get_internal_configuration();
1924 
1925 	if (cfg->lcore_role[cfg->main_lcore] != ROLE_RTE) {
1926 		RTE_LOG(ERR, EAL, "Main lcore is not enabled for DPDK\n");
1927 		return -1;
1928 	}
1929 
1930 	if (internal_cfg->process_type == RTE_PROC_INVALID) {
1931 		RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1932 		return -1;
1933 	}
1934 	if (internal_cfg->hugefile_prefix != NULL &&
1935 			strlen(internal_cfg->hugefile_prefix) < 1) {
1936 		RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1937 		return -1;
1938 	}
1939 	if (internal_cfg->hugepage_dir != NULL &&
1940 			strlen(internal_cfg->hugepage_dir) < 1) {
1941 		RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1942 		return -1;
1943 	}
1944 	if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1945 			strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1946 		RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1947 		return -1;
1948 	}
1949 	if (strchr(eal_get_hugefile_prefix(), '%') != NULL) {
1950 		RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1951 			"option\n");
1952 		return -1;
1953 	}
1954 	if (mem_parsed && internal_cfg->force_sockets == 1) {
1955 		RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1956 			"be specified at the same time\n");
1957 		return -1;
1958 	}
1959 	if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1960 		RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1961 			"be specified together with --"OPT_NO_HUGE"\n");
1962 		return -1;
1963 	}
1964 	if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1965 			!internal_cfg->in_memory) {
1966 		RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1967 			"be specified together with --"OPT_NO_HUGE"\n");
1968 		return -1;
1969 	}
1970 	if (internal_conf->force_socket_limits && internal_conf->legacy_mem) {
1971 		RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1972 			" is only supported in non-legacy memory mode\n");
1973 	}
1974 	if (internal_cfg->single_file_segments &&
1975 			internal_cfg->hugepage_unlink &&
1976 			!internal_cfg->in_memory) {
1977 		RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1978 			"not compatible with --"OPT_HUGE_UNLINK"\n");
1979 		return -1;
1980 	}
1981 	if (internal_cfg->legacy_mem &&
1982 			internal_cfg->in_memory) {
1983 		RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1984 				"with --"OPT_IN_MEMORY"\n");
1985 		return -1;
1986 	}
1987 	if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1988 		RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1989 				"with --"OPT_MATCH_ALLOCATIONS"\n");
1990 		return -1;
1991 	}
1992 	if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1993 		RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1994 				"with --"OPT_MATCH_ALLOCATIONS"\n");
1995 		return -1;
1996 	}
1997 	if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1998 		RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1999 			"amount of reserved memory can be adjusted with "
2000 			"-m or --"OPT_SOCKET_MEM"\n");
2001 	}
2002 
2003 	return 0;
2004 }
2005 
2006 uint16_t
2007 rte_vect_get_max_simd_bitwidth(void)
2008 {
2009 	const struct internal_config *internal_conf =
2010 		eal_get_internal_configuration();
2011 	return internal_conf->max_simd_bitwidth.bitwidth;
2012 }
2013 
2014 int
2015 rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
2016 {
2017 	struct internal_config *internal_conf =
2018 		eal_get_internal_configuration();
2019 	if (internal_conf->max_simd_bitwidth.forced) {
2020 		RTE_LOG(NOTICE, EAL, "Cannot set max SIMD bitwidth - user runtime override enabled");
2021 		return -EPERM;
2022 	}
2023 
2024 	if (bitwidth < RTE_VECT_SIMD_DISABLED || !rte_is_power_of_2(bitwidth)) {
2025 		RTE_LOG(ERR, EAL, "Invalid bitwidth value!\n");
2026 		return -EINVAL;
2027 	}
2028 	internal_conf->max_simd_bitwidth.bitwidth = bitwidth;
2029 	return 0;
2030 }
2031 
2032 void
2033 eal_common_usage(void)
2034 {
2035 	printf("[options]\n\n"
2036 	       "EAL common options:\n"
2037 	       "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
2038 	       "  -l CORELIST         List of cores to run on\n"
2039 	       "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
2040 	       "                      where c1, c2, etc are core indexes between 0 and %d\n"
2041 	       "  --"OPT_LCORES" COREMAP    Map lcore set to physical cpu set\n"
2042 	       "                      The argument format is\n"
2043 	       "                            '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
2044 	       "                      lcores and cpus list are grouped by '(' and ')'\n"
2045 	       "                      Within the group, '-' is used for range separator,\n"
2046 	       "                      ',' is used for single number separator.\n"
2047 	       "                      '( )' can be omitted for single element group,\n"
2048 	       "                      '@' can be omitted if cpus and lcores have the same value\n"
2049 	       "  -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
2050 	       "  --"OPT_MAIN_LCORE" ID     Core ID that is used as main\n"
2051 	       "  --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
2052 	       "  -n CHANNELS         Number of memory channels\n"
2053 	       "  -m MB               Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
2054 	       "  -r RANKS            Force number of memory ranks (don't detect)\n"
2055 	       "  -b, --block         Add a device to the blocked list.\n"
2056 	       "                      Prevent EAL from using this device. The argument\n"
2057 	       "                      format for PCI devices is <domain:bus:devid.func>.\n"
2058 	       "  -a, --allow         Add a device to the allow list.\n"
2059 	       "                      Only use the specified devices. The argument format\n"
2060 	       "                      for PCI devices is <[domain:]bus:devid.func>.\n"
2061 	       "                      This option can be present several times.\n"
2062 	       "                      [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n"
2063 	       "  --"OPT_VDEV"              Add a virtual device.\n"
2064 	       "                      The argument format is <driver><id>[,key=val,...]\n"
2065 	       "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
2066 	       "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
2067 	       "                      'va' for IOVA_VA\n"
2068 	       "  -d LIB.so|DIR       Add a driver or driver directory\n"
2069 	       "                      (can be used multiple times)\n"
2070 	       "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
2071 	       "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
2072 #ifndef RTE_EXEC_ENV_WINDOWS
2073 	       "  --"OPT_SYSLOG"            Set syslog facility\n"
2074 #endif
2075 	       "  --"OPT_LOG_LEVEL"=<level> Set global log level\n"
2076 	       "  --"OPT_LOG_LEVEL"=<type-match>:<level>\n"
2077 	       "                      Set specific log level\n"
2078 	       "  --"OPT_LOG_LEVEL"=help    Show log types and levels\n"
2079 #ifndef RTE_EXEC_ENV_WINDOWS
2080 	       "  --"OPT_TRACE"=<regex-match>\n"
2081 	       "                      Enable trace based on regular expression trace name.\n"
2082 	       "                      By default, the trace is disabled.\n"
2083 	       "		      User must specify this option to enable trace.\n"
2084 	       "  --"OPT_TRACE_DIR"=<directory path>\n"
2085 	       "                      Specify trace directory for trace output.\n"
2086 	       "                      By default, trace output will created at\n"
2087 	       "                      $HOME directory and parameter must be\n"
2088 	       "                      specified once only.\n"
2089 	       "  --"OPT_TRACE_BUF_SIZE"=<int>\n"
2090 	       "                      Specify maximum size of allocated memory\n"
2091 	       "                      for trace output for each thread. Valid\n"
2092 	       "                      unit can be either 'B|K|M' for 'Bytes',\n"
2093 	       "                      'KBytes' and 'MBytes' respectively.\n"
2094 	       "                      Default is 1MB and parameter must be\n"
2095 	       "                      specified once only.\n"
2096 	       "  --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
2097 	       "                      Specify the mode of update of trace\n"
2098 	       "                      output file. Either update on a file can\n"
2099 	       "                      be wrapped or discarded when file size\n"
2100 	       "                      reaches its maximum limit.\n"
2101 	       "                      Default mode is 'overwrite' and parameter\n"
2102 	       "                      must be specified once only.\n"
2103 #endif /* !RTE_EXEC_ENV_WINDOWS */
2104 	       "  -v                  Display version information on startup\n"
2105 	       "  -h, --help          This help\n"
2106 	       "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
2107 	       "                      disable secondary process support\n"
2108 	       "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
2109 	       "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
2110 	       "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
2111 	       "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
2112 	       "\nEAL options for DEBUG use only:\n"
2113 	       "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
2114 	       "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
2115 	       "  --"OPT_NO_PCI"            Disable PCI\n"
2116 	       "  --"OPT_NO_HPET"           Disable HPET\n"
2117 	       "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
2118 	       "\n", RTE_MAX_LCORE);
2119 }
2120