log: move private functions
[dpdk.git] / lib / librte_eal / common / eal_common_options.c
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         "w:" /* pci-whitelist (deprecated) */
69         ;
70
71 const struct option
72 eal_long_options[] = {
73         {OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
74         {OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
75         {OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
76         {OPT_HELP,              0, NULL, OPT_HELP_NUM             },
77         {OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
78         {OPT_HUGE_UNLINK,       0, NULL, OPT_HUGE_UNLINK_NUM      },
79         {OPT_IOVA_MODE,         1, NULL, OPT_IOVA_MODE_NUM        },
80         {OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
81         {OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
82         {OPT_TRACE,             1, NULL, OPT_TRACE_NUM            },
83         {OPT_TRACE_DIR,         1, NULL, OPT_TRACE_DIR_NUM        },
84         {OPT_TRACE_BUF_SIZE,    1, NULL, OPT_TRACE_BUF_SIZE_NUM   },
85         {OPT_TRACE_MODE,        1, NULL, OPT_TRACE_MODE_NUM       },
86         {OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
87         {OPT_MAIN_LCORE,        1, NULL, OPT_MAIN_LCORE_NUM       },
88         {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
89         {OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
90         {OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
91         {OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
92         {OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
93         {OPT_IN_MEMORY,         0, NULL, OPT_IN_MEMORY_NUM        },
94         {OPT_DEV_BLOCK,         1, NULL, OPT_DEV_BLOCK_NUM        },
95         {OPT_DEV_ALLOW,         1, NULL, OPT_DEV_ALLOW_NUM        },
96         {OPT_PROC_TYPE,         1, NULL, OPT_PROC_TYPE_NUM        },
97         {OPT_SOCKET_MEM,        1, NULL, OPT_SOCKET_MEM_NUM       },
98         {OPT_SOCKET_LIMIT,      1, NULL, OPT_SOCKET_LIMIT_NUM     },
99         {OPT_SYSLOG,            1, NULL, OPT_SYSLOG_NUM           },
100         {OPT_VDEV,              1, NULL, OPT_VDEV_NUM             },
101         {OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
102         {OPT_VFIO_VF_TOKEN,     1, NULL, OPT_VFIO_VF_TOKEN_NUM    },
103         {OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
104         {OPT_LEGACY_MEM,        0, NULL, OPT_LEGACY_MEM_NUM       },
105         {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
106         {OPT_MATCH_ALLOCATIONS, 0, NULL, OPT_MATCH_ALLOCATIONS_NUM},
107         {OPT_TELEMETRY,         0, NULL, OPT_TELEMETRY_NUM        },
108         {OPT_NO_TELEMETRY,      0, NULL, OPT_NO_TELEMETRY_NUM     },
109         {OPT_FORCE_MAX_SIMD_BITWIDTH, 1, NULL, OPT_FORCE_MAX_SIMD_BITWIDTH_NUM},
110
111         /* legacy options that will be removed in future */
112         {OPT_PCI_BLACKLIST,     1, NULL, OPT_PCI_BLACKLIST_NUM    },
113         {OPT_PCI_WHITELIST,     1, NULL, OPT_PCI_WHITELIST_NUM    },
114
115         {0,                     0, NULL, 0                        }
116 };
117
118 TAILQ_HEAD(shared_driver_list, shared_driver);
119
120 /* Definition for shared object drivers. */
121 struct shared_driver {
122         TAILQ_ENTRY(shared_driver) next;
123
124         char    name[PATH_MAX];
125         void*   lib_handle;
126 };
127
128 /* List of external loadable drivers */
129 static struct shared_driver_list solib_list =
130 TAILQ_HEAD_INITIALIZER(solib_list);
131
132 #ifndef RTE_EXEC_ENV_WINDOWS
133 /* Default path of external loadable drivers */
134 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
135 #endif
136
137 /*
138  * Stringified version of solib path used by dpdk-pmdinfo.py
139  * Note: PLEASE DO NOT ALTER THIS without making a corresponding
140  * change to usertools/dpdk-pmdinfo.py
141  */
142 static const char dpdk_solib_path[] __rte_used =
143 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
144
145 TAILQ_HEAD(device_option_list, device_option);
146
147 struct device_option {
148         TAILQ_ENTRY(device_option) next;
149
150         enum rte_devtype type;
151         char arg[];
152 };
153
154 static struct device_option_list devopt_list =
155 TAILQ_HEAD_INITIALIZER(devopt_list);
156
157 static int main_lcore_parsed;
158 static int mem_parsed;
159 static int core_parsed;
160
161 /* Allow the application to print its usage message too if set */
162 static rte_usage_hook_t rte_application_usage_hook;
163
164 /* Returns rte_usage_hook_t */
165 rte_usage_hook_t
166 eal_get_application_usage_hook(void)
167 {
168         return rte_application_usage_hook;
169 }
170
171 /* Set a per-application usage message */
172 rte_usage_hook_t
173 rte_set_application_usage_hook(rte_usage_hook_t usage_func)
174 {
175         rte_usage_hook_t old_func;
176
177         /* Will be NULL on the first call to denote the last usage routine. */
178         old_func = rte_application_usage_hook;
179         rte_application_usage_hook = usage_func;
180
181         return old_func;
182 }
183
184 #ifndef RTE_EXEC_ENV_WINDOWS
185 static char **eal_args;
186 static char **eal_app_args;
187
188 #define EAL_PARAM_REQ "/eal/params"
189 #define EAL_APP_PARAM_REQ "/eal/app_params"
190
191 /* callback handler for telemetry library to report out EAL flags */
192 int
193 handle_eal_info_request(const char *cmd, const char *params __rte_unused,
194                 struct rte_tel_data *d)
195 {
196         char **args;
197         int used = 0;
198         int i = 0;
199
200         if (strcmp(cmd, EAL_PARAM_REQ) == 0)
201                 args = eal_args;
202         else
203                 args = eal_app_args;
204
205         rte_tel_data_start_array(d, RTE_TEL_STRING_VAL);
206         if (args == NULL || args[0] == NULL)
207                 return 0;
208
209         for ( ; args[i] != NULL; i++)
210                 used = rte_tel_data_add_array_string(d, args[i]);
211         return used;
212 }
213
214 int
215 eal_save_args(int argc, char **argv)
216 {
217         int i, j;
218
219         rte_telemetry_register_cmd(EAL_PARAM_REQ, handle_eal_info_request,
220                         "Returns EAL commandline parameters used. Takes no parameters");
221         rte_telemetry_register_cmd(EAL_APP_PARAM_REQ, handle_eal_info_request,
222                         "Returns app commandline parameters used. Takes no parameters");
223
224         /* clone argv to report out later. We overprovision, but
225          * this does not waste huge amounts of memory
226          */
227         eal_args = calloc(argc + 1, sizeof(*eal_args));
228         if (eal_args == NULL)
229                 return -1;
230
231         for (i = 0; i < argc; i++) {
232                 eal_args[i] = strdup(argv[i]);
233                 if (strcmp(argv[i], "--") == 0)
234                         break;
235         }
236         eal_args[i++] = NULL; /* always finish with NULL */
237
238         /* allow reporting of any app args we know about too */
239         if (i >= argc)
240                 return 0;
241
242         eal_app_args = calloc(argc - i + 1, sizeof(*eal_args));
243         if (eal_app_args == NULL)
244                 return -1;
245
246         for (j = 0; i < argc; j++, i++)
247                 eal_app_args[j] = strdup(argv[i]);
248         eal_app_args[j] = NULL;
249
250         return 0;
251 }
252 #endif
253
254 static int
255 eal_option_device_add(enum rte_devtype type, const char *optarg)
256 {
257         struct device_option *devopt;
258         size_t optlen;
259         int ret;
260
261         optlen = strlen(optarg) + 1;
262         devopt = calloc(1, sizeof(*devopt) + optlen);
263         if (devopt == NULL) {
264                 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
265                 return -ENOMEM;
266         }
267
268         devopt->type = type;
269         ret = strlcpy(devopt->arg, optarg, optlen);
270         if (ret < 0) {
271                 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
272                 free(devopt);
273                 return -EINVAL;
274         }
275         TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
276         return 0;
277 }
278
279 int
280 eal_option_device_parse(void)
281 {
282         struct device_option *devopt;
283         void *tmp;
284         int ret = 0;
285
286         TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
287                 if (ret == 0) {
288                         ret = rte_devargs_add(devopt->type, devopt->arg);
289                         if (ret)
290                                 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
291                                         devopt->arg);
292                 }
293                 TAILQ_REMOVE(&devopt_list, devopt, next);
294                 free(devopt);
295         }
296         return ret;
297 }
298
299 const char *
300 eal_get_hugefile_prefix(void)
301 {
302         const struct internal_config *internal_conf =
303                 eal_get_internal_configuration();
304
305         if (internal_conf->hugefile_prefix != NULL)
306                 return internal_conf->hugefile_prefix;
307         return HUGEFILE_PREFIX_DEFAULT;
308 }
309
310 void
311 eal_reset_internal_config(struct internal_config *internal_cfg)
312 {
313         int i;
314
315         internal_cfg->memory = 0;
316         internal_cfg->force_nrank = 0;
317         internal_cfg->force_nchannel = 0;
318         internal_cfg->hugefile_prefix = NULL;
319         internal_cfg->hugepage_dir = NULL;
320         internal_cfg->force_sockets = 0;
321         /* zero out the NUMA config */
322         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
323                 internal_cfg->socket_mem[i] = 0;
324         internal_cfg->force_socket_limits = 0;
325         /* zero out the NUMA limits config */
326         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
327                 internal_cfg->socket_limit[i] = 0;
328         /* zero out hugedir descriptors */
329         for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
330                 memset(&internal_cfg->hugepage_info[i], 0,
331                                 sizeof(internal_cfg->hugepage_info[0]));
332                 internal_cfg->hugepage_info[i].lock_descriptor = -1;
333         }
334         internal_cfg->base_virtaddr = 0;
335
336 #ifdef LOG_DAEMON
337         internal_cfg->syslog_facility = LOG_DAEMON;
338 #endif
339
340         /* if set to NONE, interrupt mode is determined automatically */
341         internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
342         memset(internal_cfg->vfio_vf_token, 0,
343                         sizeof(internal_cfg->vfio_vf_token));
344
345 #ifdef RTE_LIBEAL_USE_HPET
346         internal_cfg->no_hpet = 0;
347 #else
348         internal_cfg->no_hpet = 1;
349 #endif
350         internal_cfg->vmware_tsc_map = 0;
351         internal_cfg->create_uio_dev = 0;
352         internal_cfg->iova_mode = RTE_IOVA_DC;
353         internal_cfg->user_mbuf_pool_ops_name = NULL;
354         CPU_ZERO(&internal_cfg->ctrl_cpuset);
355         internal_cfg->init_complete = 0;
356         internal_cfg->max_simd_bitwidth.bitwidth = RTE_VECT_DEFAULT_SIMD_BITWIDTH;
357         internal_cfg->max_simd_bitwidth.forced = 0;
358 }
359
360 static int
361 eal_plugin_add(const char *path)
362 {
363         struct shared_driver *solib;
364
365         solib = malloc(sizeof(*solib));
366         if (solib == NULL) {
367                 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
368                 return -1;
369         }
370         memset(solib, 0, sizeof(*solib));
371         strlcpy(solib->name, path, PATH_MAX);
372         TAILQ_INSERT_TAIL(&solib_list, solib, next);
373
374         return 0;
375 }
376
377 #ifdef RTE_EXEC_ENV_WINDOWS
378 int
379 eal_plugins_init(void)
380 {
381         return 0;
382 }
383 #else
384
385 static int
386 eal_plugindir_init(const char *path)
387 {
388         DIR *d = NULL;
389         struct dirent *dent = NULL;
390         char sopath[PATH_MAX];
391
392         if (path == NULL || *path == '\0')
393                 return 0;
394
395         d = opendir(path);
396         if (d == NULL) {
397                 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
398                         path, strerror(errno));
399                 return -1;
400         }
401
402         while ((dent = readdir(d)) != NULL) {
403                 struct stat sb;
404                 int nlen = strnlen(dent->d_name, sizeof(dent->d_name));
405
406                 /* check if name ends in .so or .so.ABI_VERSION */
407                 if (strcmp(&dent->d_name[nlen - 3], ".so") != 0 &&
408                     strcmp(&dent->d_name[nlen - 4 - strlen(ABI_VERSION)],
409                            ".so."ABI_VERSION) != 0)
410                         continue;
411
412                 snprintf(sopath, sizeof(sopath), "%s/%s", path, dent->d_name);
413
414                 /* if a regular file, add to list to load */
415                 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
416                         continue;
417
418                 if (eal_plugin_add(sopath) == -1)
419                         break;
420         }
421
422         closedir(d);
423         /* XXX this ignores failures from readdir() itself */
424         return (dent == NULL) ? 0 : -1;
425 }
426
427 static int
428 verify_perms(const char *dirpath)
429 {
430         struct stat st;
431
432         /* if not root, check down one level first */
433         if (strcmp(dirpath, "/") != 0) {
434                 static __thread char last_dir_checked[PATH_MAX];
435                 char copy[PATH_MAX];
436                 const char *dir;
437
438                 strlcpy(copy, dirpath, PATH_MAX);
439                 dir = dirname(copy);
440                 if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) {
441                         if (verify_perms(dir) != 0)
442                                 return -1;
443                         strlcpy(last_dir_checked, dir, PATH_MAX);
444                 }
445         }
446
447         /* call stat to check for permissions and ensure not world writable */
448         if (stat(dirpath, &st) != 0) {
449                 RTE_LOG(ERR, EAL, "Error with stat on %s, %s\n",
450                                 dirpath, strerror(errno));
451                 return -1;
452         }
453         if (st.st_mode & S_IWOTH) {
454                 RTE_LOG(ERR, EAL,
455                                 "Error, directory path %s is world-writable and insecure\n",
456                                 dirpath);
457                 return -1;
458         }
459
460         return 0;
461 }
462
463 static void *
464 eal_dlopen(const char *pathname)
465 {
466         void *retval = NULL;
467         char *realp = realpath(pathname, NULL);
468
469         if (realp == NULL && errno == ENOENT) {
470                 /* not a full or relative path, try a load from system dirs */
471                 retval = dlopen(pathname, RTLD_NOW);
472                 if (retval == NULL)
473                         RTE_LOG(ERR, EAL, "%s\n", dlerror());
474                 return retval;
475         }
476         if (realp == NULL) {
477                 RTE_LOG(ERR, EAL, "Error with realpath for %s, %s\n",
478                                 pathname, strerror(errno));
479                 goto out;
480         }
481         if (strnlen(realp, PATH_MAX) == PATH_MAX) {
482                 RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n");
483                 goto out;
484         }
485
486         /* do permissions checks */
487         if (verify_perms(realp) != 0)
488                 goto out;
489
490         retval = dlopen(realp, RTLD_NOW);
491         if (retval == NULL)
492                 RTE_LOG(ERR, EAL, "%s\n", dlerror());
493 out:
494         free(realp);
495         return retval;
496 }
497
498 static int
499 is_shared_build(void)
500 {
501 #define EAL_SO "librte_eal.so"
502         char soname[32];
503         size_t len, minlen = strlen(EAL_SO);
504
505         len = strlcpy(soname, EAL_SO"."ABI_VERSION, sizeof(soname));
506         if (len > sizeof(soname)) {
507                 RTE_LOG(ERR, EAL, "Shared lib name too long in shared build check\n");
508                 len = sizeof(soname) - 1;
509         }
510
511         while (len >= minlen) {
512                 /* check if we have this .so loaded, if so - shared build */
513                 RTE_LOG(DEBUG, EAL, "Checking presence of .so '%s'\n", soname);
514                 if (dlopen(soname, RTLD_LAZY | RTLD_NOLOAD) != NULL) {
515                         RTE_LOG(INFO, EAL, "Detected shared linkage of DPDK\n");
516                         return 1;
517                 }
518
519                 /* remove any version numbers off the end to retry */
520                 while (len-- > 0)
521                         if (soname[len] == '.') {
522                                 soname[len] = '\0';
523                                 break;
524                         }
525         }
526
527         RTE_LOG(INFO, EAL, "Detected static linkage of DPDK\n");
528         return 0;
529 }
530
531 int
532 eal_plugins_init(void)
533 {
534         struct shared_driver *solib = NULL;
535         struct stat sb;
536
537         /* If we are not statically linked, add default driver loading
538          * path if it exists as a directory.
539          * (Using dlopen with NOLOAD flag on EAL, will return NULL if the EAL
540          * shared library is not already loaded i.e. it's statically linked.)
541          */
542         if (is_shared_build() &&
543                         *default_solib_dir != '\0' &&
544                         stat(default_solib_dir, &sb) == 0 &&
545                         S_ISDIR(sb.st_mode))
546                 eal_plugin_add(default_solib_dir);
547
548         TAILQ_FOREACH(solib, &solib_list, next) {
549
550                 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
551                         if (eal_plugindir_init(solib->name) == -1) {
552                                 RTE_LOG(ERR, EAL,
553                                         "Cannot init plugin directory %s\n",
554                                         solib->name);
555                                 return -1;
556                         }
557                 } else {
558                         RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
559                                 solib->name);
560                         solib->lib_handle = eal_dlopen(solib->name);
561                         if (solib->lib_handle == NULL)
562                                 return -1;
563                 }
564
565         }
566         return 0;
567 }
568 #endif
569
570 /*
571  * Parse the coremask given as argument (hexadecimal string) and fill
572  * the global configuration (core role and core count) with the parsed
573  * value.
574  */
575 static int xdigit2val(unsigned char c)
576 {
577         int val;
578
579         if (isdigit(c))
580                 val = c - '0';
581         else if (isupper(c))
582                 val = c - 'A' + 10;
583         else
584                 val = c - 'a' + 10;
585         return val;
586 }
587
588 static int
589 eal_parse_service_coremask(const char *coremask)
590 {
591         struct rte_config *cfg = rte_eal_get_configuration();
592         int i, j, idx = 0;
593         unsigned int count = 0;
594         char c;
595         int val;
596         uint32_t taken_lcore_count = 0;
597
598         if (coremask == NULL)
599                 return -1;
600         /* Remove all blank characters ahead and after .
601          * Remove 0x/0X if exists.
602          */
603         while (isblank(*coremask))
604                 coremask++;
605         if (coremask[0] == '0' && ((coremask[1] == 'x')
606                 || (coremask[1] == 'X')))
607                 coremask += 2;
608         i = strlen(coremask);
609         while ((i > 0) && isblank(coremask[i - 1]))
610                 i--;
611
612         if (i == 0)
613                 return -1;
614
615         for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
616                 c = coremask[i];
617                 if (isxdigit(c) == 0) {
618                         /* invalid characters */
619                         return -1;
620                 }
621                 val = xdigit2val(c);
622                 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
623                                 j++, idx++) {
624                         if ((1 << j) & val) {
625                                 /* handle main lcore already parsed */
626                                 uint32_t lcore = idx;
627                                 if (main_lcore_parsed &&
628                                                 cfg->main_lcore == lcore) {
629                                         RTE_LOG(ERR, EAL,
630                                                 "lcore %u is main lcore, cannot use as service core\n",
631                                                 idx);
632                                         return -1;
633                                 }
634
635                                 if (eal_cpu_detected(idx) == 0) {
636                                         RTE_LOG(ERR, EAL,
637                                                 "lcore %u unavailable\n", idx);
638                                         return -1;
639                                 }
640
641                                 if (cfg->lcore_role[idx] == ROLE_RTE)
642                                         taken_lcore_count++;
643
644                                 lcore_config[idx].core_role = ROLE_SERVICE;
645                                 count++;
646                         }
647                 }
648         }
649
650         for (; i >= 0; i--)
651                 if (coremask[i] != '0')
652                         return -1;
653
654         for (; idx < RTE_MAX_LCORE; idx++)
655                 lcore_config[idx].core_index = -1;
656
657         if (count == 0)
658                 return -1;
659
660         if (core_parsed && taken_lcore_count != count) {
661                 RTE_LOG(WARNING, EAL,
662                         "Not all service cores are in the coremask. "
663                         "Please ensure -c or -l includes service cores\n");
664         }
665
666         cfg->service_lcore_count = count;
667         return 0;
668 }
669
670 static int
671 eal_service_cores_parsed(void)
672 {
673         int idx;
674         for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
675                 if (lcore_config[idx].core_role == ROLE_SERVICE)
676                         return 1;
677         }
678         return 0;
679 }
680
681 static int
682 update_lcore_config(int *cores)
683 {
684         struct rte_config *cfg = rte_eal_get_configuration();
685         unsigned int count = 0;
686         unsigned int i;
687         int ret = 0;
688
689         for (i = 0; i < RTE_MAX_LCORE; i++) {
690                 if (cores[i] != -1) {
691                         if (eal_cpu_detected(i) == 0) {
692                                 RTE_LOG(ERR, EAL, "lcore %u unavailable\n", i);
693                                 ret = -1;
694                                 continue;
695                         }
696                         cfg->lcore_role[i] = ROLE_RTE;
697                         count++;
698                 } else {
699                         cfg->lcore_role[i] = ROLE_OFF;
700                 }
701                 lcore_config[i].core_index = cores[i];
702         }
703         if (!ret)
704                 cfg->lcore_count = count;
705         return ret;
706 }
707
708 static int
709 eal_parse_coremask(const char *coremask, int *cores)
710 {
711         unsigned count = 0;
712         int i, j, idx;
713         int val;
714         char c;
715
716         for (idx = 0; idx < RTE_MAX_LCORE; idx++)
717                 cores[idx] = -1;
718         idx = 0;
719
720         /* Remove all blank characters ahead and after .
721          * Remove 0x/0X if exists.
722          */
723         while (isblank(*coremask))
724                 coremask++;
725         if (coremask[0] == '0' && ((coremask[1] == 'x')
726                 || (coremask[1] == 'X')))
727                 coremask += 2;
728         i = strlen(coremask);
729         while ((i > 0) && isblank(coremask[i - 1]))
730                 i--;
731         if (i == 0)
732                 return -1;
733
734         for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
735                 c = coremask[i];
736                 if (isxdigit(c) == 0) {
737                         /* invalid characters */
738                         return -1;
739                 }
740                 val = xdigit2val(c);
741                 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
742                 {
743                         if ((1 << j) & val) {
744                                 cores[idx] = count;
745                                 count++;
746                         }
747                 }
748         }
749         for (; i >= 0; i--)
750                 if (coremask[i] != '0')
751                         return -1;
752         if (count == 0)
753                 return -1;
754         return 0;
755 }
756
757 static int
758 eal_parse_service_corelist(const char *corelist)
759 {
760         struct rte_config *cfg = rte_eal_get_configuration();
761         int i, idx = 0;
762         unsigned count = 0;
763         char *end = NULL;
764         int min, max;
765         uint32_t taken_lcore_count = 0;
766
767         if (corelist == NULL)
768                 return -1;
769
770         /* Remove all blank characters ahead and after */
771         while (isblank(*corelist))
772                 corelist++;
773         i = strlen(corelist);
774         while ((i > 0) && isblank(corelist[i - 1]))
775                 i--;
776
777         /* Get list of cores */
778         min = RTE_MAX_LCORE;
779         do {
780                 while (isblank(*corelist))
781                         corelist++;
782                 if (*corelist == '\0')
783                         return -1;
784                 errno = 0;
785                 idx = strtoul(corelist, &end, 10);
786                 if (errno || end == NULL)
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 int
1231 eal_parse_log_priority(const char *level)
1232 {
1233         static const char * const levels[] = {
1234                 [RTE_LOG_EMERG]   = "emergency",
1235                 [RTE_LOG_ALERT]   = "alert",
1236                 [RTE_LOG_CRIT]    = "critical",
1237                 [RTE_LOG_ERR]     = "error",
1238                 [RTE_LOG_WARNING] = "warning",
1239                 [RTE_LOG_NOTICE]  = "notice",
1240                 [RTE_LOG_INFO]    = "info",
1241                 [RTE_LOG_DEBUG]   = "debug",
1242         };
1243         size_t len = strlen(level);
1244         unsigned long tmp;
1245         char *end;
1246         unsigned int i;
1247
1248         if (len == 0)
1249                 return -1;
1250
1251         /* look for named values, skip 0 which is not a valid level */
1252         for (i = 1; i < RTE_DIM(levels); i++) {
1253                 if (strncmp(levels[i], level, len) == 0)
1254                         return i;
1255         }
1256
1257         /* not a string, maybe it is numeric */
1258         errno = 0;
1259         tmp = strtoul(level, &end, 0);
1260
1261         /* check for errors */
1262         if (errno != 0 || end == NULL || *end != '\0' ||
1263             tmp >= UINT32_MAX)
1264                 return -1;
1265
1266         return tmp;
1267 }
1268
1269 static int
1270 eal_parse_log_level(const char *arg)
1271 {
1272         const char *pattern = NULL;
1273         const char *regex = NULL;
1274         char *str, *level;
1275         int priority;
1276
1277         str = strdup(arg);
1278         if (str == NULL)
1279                 return -1;
1280
1281         if ((level = strchr(str, ','))) {
1282                 regex = str;
1283                 *level++ = '\0';
1284         } else if ((level = strchr(str, ':'))) {
1285                 pattern = str;
1286                 *level++ = '\0';
1287         } else {
1288                 level = str;
1289         }
1290
1291         priority = eal_parse_log_priority(level);
1292         if (priority < 0) {
1293                 fprintf(stderr, "invalid log priority: %s\n", level);
1294                 goto fail;
1295         }
1296
1297         if (regex) {
1298                 if (rte_log_set_level_regexp(regex, priority) < 0) {
1299                         fprintf(stderr, "cannot set log level %s,%d\n",
1300                                 regex, priority);
1301                         goto fail;
1302                 }
1303                 if (eal_log_save_regexp(regex, priority) < 0)
1304                         goto fail;
1305         } else if (pattern) {
1306                 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1307                         fprintf(stderr, "cannot set log level %s:%d\n",
1308                                 pattern, priority);
1309                         goto fail;
1310                 }
1311                 if (eal_log_save_pattern(pattern, priority) < 0)
1312                         goto fail;
1313         } else {
1314                 rte_log_set_global_level(priority);
1315         }
1316
1317         free(str);
1318         return 0;
1319
1320 fail:
1321         free(str);
1322         return -1;
1323 }
1324
1325 static enum rte_proc_type_t
1326 eal_parse_proc_type(const char *arg)
1327 {
1328         if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1329                 return RTE_PROC_PRIMARY;
1330         if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1331                 return RTE_PROC_SECONDARY;
1332         if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1333                 return RTE_PROC_AUTO;
1334
1335         return RTE_PROC_INVALID;
1336 }
1337
1338 static int
1339 eal_parse_iova_mode(const char *name)
1340 {
1341         int mode;
1342         struct internal_config *internal_conf =
1343                 eal_get_internal_configuration();
1344
1345         if (name == NULL)
1346                 return -1;
1347
1348         if (!strcmp("pa", name))
1349                 mode = RTE_IOVA_PA;
1350         else if (!strcmp("va", name))
1351                 mode = RTE_IOVA_VA;
1352         else
1353                 return -1;
1354
1355         internal_conf->iova_mode = mode;
1356         return 0;
1357 }
1358
1359 static int
1360 eal_parse_simd_bitwidth(const char *arg)
1361 {
1362         char *end;
1363         unsigned long bitwidth;
1364         int ret;
1365         struct internal_config *internal_conf =
1366                 eal_get_internal_configuration();
1367
1368         if (arg == NULL || arg[0] == '\0')
1369                 return -1;
1370
1371         errno = 0;
1372         bitwidth = strtoul(arg, &end, 0);
1373
1374         /* check for errors */
1375         if (errno != 0 || end == NULL || *end != '\0' || bitwidth > RTE_VECT_SIMD_MAX)
1376                 return -1;
1377
1378         if (bitwidth == 0)
1379                 bitwidth = (unsigned long) RTE_VECT_SIMD_MAX;
1380         ret = rte_vect_set_max_simd_bitwidth(bitwidth);
1381         if (ret < 0)
1382                 return -1;
1383         internal_conf->max_simd_bitwidth.forced = 1;
1384         return 0;
1385 }
1386
1387 static int
1388 eal_parse_base_virtaddr(const char *arg)
1389 {
1390         char *end;
1391         uint64_t addr;
1392         struct internal_config *internal_conf =
1393                 eal_get_internal_configuration();
1394
1395         errno = 0;
1396         addr = strtoull(arg, &end, 16);
1397
1398         /* check for errors */
1399         if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
1400                 return -1;
1401
1402         /* make sure we don't exceed 32-bit boundary on 32-bit target */
1403 #ifndef RTE_ARCH_64
1404         if (addr >= UINTPTR_MAX)
1405                 return -1;
1406 #endif
1407
1408         /* align the addr on 16M boundary, 16MB is the minimum huge page
1409          * size on IBM Power architecture. If the addr is aligned to 16MB,
1410          * it can align to 2MB for x86. So this alignment can also be used
1411          * on x86 and other architectures.
1412          */
1413         internal_conf->base_virtaddr =
1414                 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
1415
1416         return 0;
1417 }
1418
1419 /* caller is responsible for freeing the returned string */
1420 static char *
1421 available_cores(void)
1422 {
1423         char *str = NULL;
1424         int previous;
1425         int sequence;
1426         char *tmp;
1427         int idx;
1428
1429         /* find the first available cpu */
1430         for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
1431                 if (eal_cpu_detected(idx) == 0)
1432                         continue;
1433                 break;
1434         }
1435         if (idx >= RTE_MAX_LCORE)
1436                 return NULL;
1437
1438         /* first sequence */
1439         if (asprintf(&str, "%d", idx) < 0)
1440                 return NULL;
1441         previous = idx;
1442         sequence = 0;
1443
1444         for (idx++ ; idx < RTE_MAX_LCORE; idx++) {
1445                 if (eal_cpu_detected(idx) == 0)
1446                         continue;
1447
1448                 if (idx == previous + 1) {
1449                         previous = idx;
1450                         sequence = 1;
1451                         continue;
1452                 }
1453
1454                 /* finish current sequence */
1455                 if (sequence) {
1456                         if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1457                                 free(str);
1458                                 return NULL;
1459                         }
1460                         free(str);
1461                         str = tmp;
1462                 }
1463
1464                 /* new sequence */
1465                 if (asprintf(&tmp, "%s,%d", str, idx) < 0) {
1466                         free(str);
1467                         return NULL;
1468                 }
1469                 free(str);
1470                 str = tmp;
1471                 previous = idx;
1472                 sequence = 0;
1473         }
1474
1475         /* finish last sequence */
1476         if (sequence) {
1477                 if (asprintf(&tmp, "%s-%d", str, previous) < 0) {
1478                         free(str);
1479                         return NULL;
1480                 }
1481                 free(str);
1482                 str = tmp;
1483         }
1484
1485         return str;
1486 }
1487
1488 int
1489 eal_parse_common_option(int opt, const char *optarg,
1490                         struct internal_config *conf)
1491 {
1492         static int b_used;
1493         static int a_used;
1494
1495         switch (opt) {
1496         case OPT_PCI_BLACKLIST_NUM:
1497                 fprintf(stderr,
1498                         "Option --pci-blacklist is deprecated, use -b, --block instead\n");
1499                 /* fallthrough */
1500         case 'b':
1501                 if (a_used)
1502                         goto ba_conflict;
1503                 if (eal_option_device_add(RTE_DEVTYPE_BLOCKED, optarg) < 0)
1504                         return -1;
1505                 b_used = 1;
1506                 break;
1507
1508         case 'w':
1509                 fprintf(stderr,
1510                         "Option -w, --pci-whitelist is deprecated, use -a, --allow option instead\n");
1511                 /* fallthrough */
1512         case 'a':
1513                 if (b_used)
1514                         goto ba_conflict;
1515                 if (eal_option_device_add(RTE_DEVTYPE_ALLOWED, optarg) < 0)
1516                         return -1;
1517                 a_used = 1;
1518                 break;
1519         /* coremask */
1520         case 'c': {
1521                 int lcore_indexes[RTE_MAX_LCORE];
1522
1523                 if (eal_service_cores_parsed())
1524                         RTE_LOG(WARNING, EAL,
1525                                 "Service cores parsed before dataplane cores. Please ensure -c is before -s or -S\n");
1526                 if (eal_parse_coremask(optarg, lcore_indexes) < 0) {
1527                         RTE_LOG(ERR, EAL, "invalid coremask syntax\n");
1528                         return -1;
1529                 }
1530                 if (update_lcore_config(lcore_indexes) < 0) {
1531                         char *available = available_cores();
1532
1533                         RTE_LOG(ERR, EAL,
1534                                 "invalid coremask, please check specified cores are part of %s\n",
1535                                 available);
1536                         free(available);
1537                         return -1;
1538                 }
1539
1540                 if (core_parsed) {
1541                         RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1542                                 (core_parsed == LCORE_OPT_LST) ? "-l" :
1543                                 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1544                                 "-c");
1545                         return -1;
1546                 }
1547
1548                 core_parsed = LCORE_OPT_MSK;
1549                 break;
1550         }
1551         /* corelist */
1552         case 'l': {
1553                 int lcore_indexes[RTE_MAX_LCORE];
1554
1555                 if (eal_service_cores_parsed())
1556                         RTE_LOG(WARNING, EAL,
1557                                 "Service cores parsed before dataplane cores. Please ensure -l is before -s or -S\n");
1558
1559                 if (eal_parse_corelist(optarg, lcore_indexes) < 0) {
1560                         RTE_LOG(ERR, EAL, "invalid core list syntax\n");
1561                         return -1;
1562                 }
1563                 if (update_lcore_config(lcore_indexes) < 0) {
1564                         char *available = available_cores();
1565
1566                         RTE_LOG(ERR, EAL,
1567                                 "invalid core list, please check specified cores are part of %s\n",
1568                                 available);
1569                         free(available);
1570                         return -1;
1571                 }
1572
1573                 if (core_parsed) {
1574                         RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1575                                 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1576                                 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1577                                 "-l");
1578                         return -1;
1579                 }
1580
1581                 core_parsed = LCORE_OPT_LST;
1582                 break;
1583         }
1584         /* service coremask */
1585         case 's':
1586                 if (eal_parse_service_coremask(optarg) < 0) {
1587                         RTE_LOG(ERR, EAL, "invalid service coremask\n");
1588                         return -1;
1589                 }
1590                 break;
1591         /* service corelist */
1592         case 'S':
1593                 if (eal_parse_service_corelist(optarg) < 0) {
1594                         RTE_LOG(ERR, EAL, "invalid service core list\n");
1595                         return -1;
1596                 }
1597                 break;
1598         /* size of memory */
1599         case 'm':
1600                 conf->memory = atoi(optarg);
1601                 conf->memory *= 1024ULL;
1602                 conf->memory *= 1024ULL;
1603                 mem_parsed = 1;
1604                 break;
1605         /* force number of channels */
1606         case 'n':
1607                 conf->force_nchannel = atoi(optarg);
1608                 if (conf->force_nchannel == 0) {
1609                         RTE_LOG(ERR, EAL, "invalid channel number\n");
1610                         return -1;
1611                 }
1612                 break;
1613         /* force number of ranks */
1614         case 'r':
1615                 conf->force_nrank = atoi(optarg);
1616                 if (conf->force_nrank == 0 ||
1617                     conf->force_nrank > 16) {
1618                         RTE_LOG(ERR, EAL, "invalid rank number\n");
1619                         return -1;
1620                 }
1621                 break;
1622         /* force loading of external driver */
1623         case 'd':
1624                 if (eal_plugin_add(optarg) == -1)
1625                         return -1;
1626                 break;
1627         case 'v':
1628                 /* since message is explicitly requested by user, we
1629                  * write message at highest log level so it can always
1630                  * be seen
1631                  * even if info or warning messages are disabled */
1632                 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1633                 break;
1634
1635         /* long options */
1636         case OPT_HUGE_UNLINK_NUM:
1637                 conf->hugepage_unlink = 1;
1638                 break;
1639
1640         case OPT_NO_HUGE_NUM:
1641                 conf->no_hugetlbfs = 1;
1642                 /* no-huge is legacy mem */
1643                 conf->legacy_mem = 1;
1644                 break;
1645
1646         case OPT_NO_PCI_NUM:
1647                 conf->no_pci = 1;
1648                 break;
1649
1650         case OPT_NO_HPET_NUM:
1651                 conf->no_hpet = 1;
1652                 break;
1653
1654         case OPT_VMWARE_TSC_MAP_NUM:
1655                 conf->vmware_tsc_map = 1;
1656                 break;
1657
1658         case OPT_NO_SHCONF_NUM:
1659                 conf->no_shconf = 1;
1660                 break;
1661
1662         case OPT_IN_MEMORY_NUM:
1663                 conf->in_memory = 1;
1664                 /* in-memory is a superset of noshconf and huge-unlink */
1665                 conf->no_shconf = 1;
1666                 conf->hugepage_unlink = 1;
1667                 break;
1668
1669         case OPT_PROC_TYPE_NUM:
1670                 conf->process_type = eal_parse_proc_type(optarg);
1671                 break;
1672
1673         case OPT_MASTER_LCORE_NUM:
1674                 fprintf(stderr,
1675                         "Option --" OPT_MASTER_LCORE
1676                         " is deprecated use " OPT_MAIN_LCORE "\n");
1677                 /* fallthrough */
1678         case OPT_MAIN_LCORE_NUM:
1679                 if (eal_parse_main_lcore(optarg) < 0) {
1680                         RTE_LOG(ERR, EAL, "invalid parameter for --"
1681                                         OPT_MAIN_LCORE "\n");
1682                         return -1;
1683                 }
1684                 break;
1685
1686         case OPT_VDEV_NUM:
1687                 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1688                                 optarg) < 0) {
1689                         return -1;
1690                 }
1691                 break;
1692
1693 #ifndef RTE_EXEC_ENV_WINDOWS
1694         case OPT_SYSLOG_NUM:
1695                 if (eal_parse_syslog(optarg, conf) < 0) {
1696                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1697                                         OPT_SYSLOG "\n");
1698                         return -1;
1699                 }
1700                 break;
1701 #endif
1702
1703         case OPT_LOG_LEVEL_NUM: {
1704                 if (eal_parse_log_level(optarg) < 0) {
1705                         RTE_LOG(ERR, EAL,
1706                                 "invalid parameters for --"
1707                                 OPT_LOG_LEVEL "\n");
1708                         return -1;
1709                 }
1710                 break;
1711         }
1712
1713 #ifndef RTE_EXEC_ENV_WINDOWS
1714         case OPT_TRACE_NUM: {
1715                 if (eal_trace_args_save(optarg) < 0) {
1716                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1717                                 OPT_TRACE "\n");
1718                         return -1;
1719                 }
1720                 break;
1721         }
1722
1723         case OPT_TRACE_DIR_NUM: {
1724                 if (eal_trace_dir_args_save(optarg) < 0) {
1725                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1726                                 OPT_TRACE_DIR "\n");
1727                         return -1;
1728                 }
1729                 break;
1730         }
1731
1732         case OPT_TRACE_BUF_SIZE_NUM: {
1733                 if (eal_trace_bufsz_args_save(optarg) < 0) {
1734                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1735                                 OPT_TRACE_BUF_SIZE "\n");
1736                         return -1;
1737                 }
1738                 break;
1739         }
1740
1741         case OPT_TRACE_MODE_NUM: {
1742                 if (eal_trace_mode_args_save(optarg) < 0) {
1743                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1744                                 OPT_TRACE_MODE "\n");
1745                         return -1;
1746                 }
1747                 break;
1748         }
1749 #endif /* !RTE_EXEC_ENV_WINDOWS */
1750
1751         case OPT_LCORES_NUM:
1752                 if (eal_parse_lcores(optarg) < 0) {
1753                         RTE_LOG(ERR, EAL, "invalid parameter for --"
1754                                 OPT_LCORES "\n");
1755                         return -1;
1756                 }
1757
1758                 if (core_parsed) {
1759                         RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1760                                 (core_parsed == LCORE_OPT_LST) ? "-l" :
1761                                 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1762                                 "--lcore");
1763                         return -1;
1764                 }
1765
1766                 core_parsed = LCORE_OPT_MAP;
1767                 break;
1768         case OPT_LEGACY_MEM_NUM:
1769                 conf->legacy_mem = 1;
1770                 break;
1771         case OPT_SINGLE_FILE_SEGMENTS_NUM:
1772                 conf->single_file_segments = 1;
1773                 break;
1774         case OPT_IOVA_MODE_NUM:
1775                 if (eal_parse_iova_mode(optarg) < 0) {
1776                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1777                                 OPT_IOVA_MODE "\n");
1778                         return -1;
1779                 }
1780                 break;
1781         case OPT_BASE_VIRTADDR_NUM:
1782                 if (eal_parse_base_virtaddr(optarg) < 0) {
1783                         RTE_LOG(ERR, EAL, "invalid parameter for --"
1784                                         OPT_BASE_VIRTADDR "\n");
1785                         return -1;
1786                 }
1787                 break;
1788         case OPT_TELEMETRY_NUM:
1789                 break;
1790         case OPT_NO_TELEMETRY_NUM:
1791                 conf->no_telemetry = 1;
1792                 break;
1793         case OPT_FORCE_MAX_SIMD_BITWIDTH_NUM:
1794                 if (eal_parse_simd_bitwidth(optarg) < 0) {
1795                         RTE_LOG(ERR, EAL, "invalid parameter for --"
1796                                         OPT_FORCE_MAX_SIMD_BITWIDTH "\n");
1797                         return -1;
1798                 }
1799                 break;
1800
1801         /* don't know what to do, leave this to caller */
1802         default:
1803                 return 1;
1804
1805         }
1806
1807         return 0;
1808
1809 ba_conflict:
1810         RTE_LOG(ERR, EAL,
1811                 "Options allow (-a) and block (-b) can't be used at the same time\n");
1812         return -1;
1813 }
1814
1815 static void
1816 eal_auto_detect_cores(struct rte_config *cfg)
1817 {
1818         unsigned int lcore_id;
1819         unsigned int removed = 0;
1820         rte_cpuset_t affinity_set;
1821
1822         if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1823                                 &affinity_set))
1824                 CPU_ZERO(&affinity_set);
1825
1826         for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1827                 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1828                     !CPU_ISSET(lcore_id, &affinity_set)) {
1829                         cfg->lcore_role[lcore_id] = ROLE_OFF;
1830                         removed++;
1831                 }
1832         }
1833
1834         cfg->lcore_count -= removed;
1835 }
1836
1837 static void
1838 compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
1839 {
1840         rte_cpuset_t *cpuset = &internal_cfg->ctrl_cpuset;
1841         rte_cpuset_t default_set;
1842         unsigned int lcore_id;
1843
1844         for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1845                 if (rte_lcore_has_role(lcore_id, ROLE_OFF))
1846                         continue;
1847                 RTE_CPU_OR(cpuset, cpuset, &lcore_config[lcore_id].cpuset);
1848         }
1849         RTE_CPU_NOT(cpuset, cpuset);
1850
1851         if (pthread_getaffinity_np(pthread_self(), sizeof(rte_cpuset_t),
1852                                 &default_set))
1853                 CPU_ZERO(&default_set);
1854
1855         RTE_CPU_AND(cpuset, cpuset, &default_set);
1856
1857         /* if no remaining cpu, use main lcore cpu affinity */
1858         if (!CPU_COUNT(cpuset)) {
1859                 memcpy(cpuset, &lcore_config[rte_get_main_lcore()].cpuset,
1860                         sizeof(*cpuset));
1861         }
1862 }
1863
1864 int
1865 eal_cleanup_config(struct internal_config *internal_cfg)
1866 {
1867         if (internal_cfg->hugefile_prefix != NULL)
1868                 free(internal_cfg->hugefile_prefix);
1869         if (internal_cfg->hugepage_dir != NULL)
1870                 free(internal_cfg->hugepage_dir);
1871         if (internal_cfg->user_mbuf_pool_ops_name != NULL)
1872                 free(internal_cfg->user_mbuf_pool_ops_name);
1873
1874         return 0;
1875 }
1876
1877 int
1878 eal_adjust_config(struct internal_config *internal_cfg)
1879 {
1880         int i;
1881         struct rte_config *cfg = rte_eal_get_configuration();
1882         struct internal_config *internal_conf =
1883                 eal_get_internal_configuration();
1884
1885         if (!core_parsed)
1886                 eal_auto_detect_cores(cfg);
1887
1888         if (internal_conf->process_type == RTE_PROC_AUTO)
1889                 internal_conf->process_type = eal_proc_type_detect();
1890
1891         /* default main lcore is the first one */
1892         if (!main_lcore_parsed) {
1893                 cfg->main_lcore = rte_get_next_lcore(-1, 0, 0);
1894                 if (cfg->main_lcore >= RTE_MAX_LCORE)
1895                         return -1;
1896                 lcore_config[cfg->main_lcore].core_role = ROLE_RTE;
1897         }
1898
1899         compute_ctrl_threads_cpuset(internal_cfg);
1900
1901         /* if no memory amounts were requested, this will result in 0 and
1902          * will be overridden later, right after eal_hugepage_info_init() */
1903         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1904                 internal_cfg->memory += internal_cfg->socket_mem[i];
1905
1906         return 0;
1907 }
1908
1909 int
1910 eal_check_common_options(struct internal_config *internal_cfg)
1911 {
1912         struct rte_config *cfg = rte_eal_get_configuration();
1913         const struct internal_config *internal_conf =
1914                 eal_get_internal_configuration();
1915
1916         if (cfg->lcore_role[cfg->main_lcore] != ROLE_RTE) {
1917                 RTE_LOG(ERR, EAL, "Main lcore is not enabled for DPDK\n");
1918                 return -1;
1919         }
1920
1921         if (internal_cfg->process_type == RTE_PROC_INVALID) {
1922                 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1923                 return -1;
1924         }
1925         if (internal_cfg->hugefile_prefix != NULL &&
1926                         strlen(internal_cfg->hugefile_prefix) < 1) {
1927                 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_FILE_PREFIX " option\n");
1928                 return -1;
1929         }
1930         if (internal_cfg->hugepage_dir != NULL &&
1931                         strlen(internal_cfg->hugepage_dir) < 1) {
1932                 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_HUGE_DIR" option\n");
1933                 return -1;
1934         }
1935         if (internal_cfg->user_mbuf_pool_ops_name != NULL &&
1936                         strlen(internal_cfg->user_mbuf_pool_ops_name) < 1) {
1937                 RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
1938                 return -1;
1939         }
1940         if (index(eal_get_hugefile_prefix(), '%') != NULL) {
1941                 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1942                         "option\n");
1943                 return -1;
1944         }
1945         if (mem_parsed && internal_cfg->force_sockets == 1) {
1946                 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1947                         "be specified at the same time\n");
1948                 return -1;
1949         }
1950         if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1951                 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1952                         "be specified together with --"OPT_NO_HUGE"\n");
1953                 return -1;
1954         }
1955         if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1956                         !internal_cfg->in_memory) {
1957                 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1958                         "be specified together with --"OPT_NO_HUGE"\n");
1959                 return -1;
1960         }
1961         if (internal_conf->force_socket_limits && internal_conf->legacy_mem) {
1962                 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1963                         " is only supported in non-legacy memory mode\n");
1964         }
1965         if (internal_cfg->single_file_segments &&
1966                         internal_cfg->hugepage_unlink &&
1967                         !internal_cfg->in_memory) {
1968                 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1969                         "not compatible with --"OPT_HUGE_UNLINK"\n");
1970                 return -1;
1971         }
1972         if (internal_cfg->legacy_mem &&
1973                         internal_cfg->in_memory) {
1974                 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1975                                 "with --"OPT_IN_MEMORY"\n");
1976                 return -1;
1977         }
1978         if (internal_cfg->legacy_mem && internal_cfg->match_allocations) {
1979                 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1980                                 "with --"OPT_MATCH_ALLOCATIONS"\n");
1981                 return -1;
1982         }
1983         if (internal_cfg->no_hugetlbfs && internal_cfg->match_allocations) {
1984                 RTE_LOG(ERR, EAL, "Option --"OPT_NO_HUGE" is not compatible "
1985                                 "with --"OPT_MATCH_ALLOCATIONS"\n");
1986                 return -1;
1987         }
1988         if (internal_cfg->legacy_mem && internal_cfg->memory == 0) {
1989                 RTE_LOG(NOTICE, EAL, "Static memory layout is selected, "
1990                         "amount of reserved memory can be adjusted with "
1991                         "-m or --"OPT_SOCKET_MEM"\n");
1992         }
1993
1994         return 0;
1995 }
1996
1997 uint16_t
1998 rte_vect_get_max_simd_bitwidth(void)
1999 {
2000         const struct internal_config *internal_conf =
2001                 eal_get_internal_configuration();
2002         return internal_conf->max_simd_bitwidth.bitwidth;
2003 }
2004
2005 int
2006 rte_vect_set_max_simd_bitwidth(uint16_t bitwidth)
2007 {
2008         struct internal_config *internal_conf =
2009                 eal_get_internal_configuration();
2010         if (internal_conf->max_simd_bitwidth.forced) {
2011                 RTE_LOG(NOTICE, EAL, "Cannot set max SIMD bitwidth - user runtime override enabled");
2012                 return -EPERM;
2013         }
2014
2015         if (bitwidth < RTE_VECT_SIMD_DISABLED || !rte_is_power_of_2(bitwidth)) {
2016                 RTE_LOG(ERR, EAL, "Invalid bitwidth value!\n");
2017                 return -EINVAL;
2018         }
2019         internal_conf->max_simd_bitwidth.bitwidth = bitwidth;
2020         return 0;
2021 }
2022
2023 void
2024 eal_common_usage(void)
2025 {
2026         printf("[options]\n\n"
2027                "EAL common options:\n"
2028                "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
2029                "  -l CORELIST         List of cores to run on\n"
2030                "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
2031                "                      where c1, c2, etc are core indexes between 0 and %d\n"
2032                "  --"OPT_LCORES" COREMAP    Map lcore set to physical cpu set\n"
2033                "                      The argument format is\n"
2034                "                            '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
2035                "                      lcores and cpus list are grouped by '(' and ')'\n"
2036                "                      Within the group, '-' is used for range separator,\n"
2037                "                      ',' is used for single number separator.\n"
2038                "                      '( )' can be omitted for single element group,\n"
2039                "                      '@' can be omitted if cpus and lcores have the same value\n"
2040                "  -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
2041                "  --"OPT_MAIN_LCORE" ID     Core ID that is used as main\n"
2042                "  --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
2043                "  -n CHANNELS         Number of memory channels\n"
2044                "  -m MB               Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
2045                "  -r RANKS            Force number of memory ranks (don't detect)\n"
2046                "  -b, --block         Add a device to the blocked list.\n"
2047                "                      Prevent EAL from using this device. The argument\n"
2048                "                      format for PCI devices is <domain:bus:devid.func>.\n"
2049                "  -a, --allow         Add a device to the allow list.\n"
2050                "                      Only use the specified devices. The argument format\n"
2051                "                      for PCI devices is <[domain:]bus:devid.func>.\n"
2052                "                      This option can be present several times.\n"
2053                "                      [NOTE: " OPT_DEV_ALLOW " cannot be used with "OPT_DEV_BLOCK" option]\n"
2054                "  --"OPT_VDEV"              Add a virtual device.\n"
2055                "                      The argument format is <driver><id>[,key=val,...]\n"
2056                "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
2057                "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
2058                "                      'va' for IOVA_VA\n"
2059                "  -d LIB.so|DIR       Add a driver or driver directory\n"
2060                "                      (can be used multiple times)\n"
2061                "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
2062                "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
2063 #ifndef RTE_EXEC_ENV_WINDOWS
2064                "  --"OPT_SYSLOG"            Set syslog facility\n"
2065 #endif
2066                "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
2067                "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
2068                "                      Set specific log level\n"
2069 #ifndef RTE_EXEC_ENV_WINDOWS
2070                "  --"OPT_TRACE"=<regex-match>\n"
2071                "                      Enable trace based on regular expression trace name.\n"
2072                "                      By default, the trace is disabled.\n"
2073                "                      User must specify this option to enable trace.\n"
2074                "  --"OPT_TRACE_DIR"=<directory path>\n"
2075                "                      Specify trace directory for trace output.\n"
2076                "                      By default, trace output will created at\n"
2077                "                      $HOME directory and parameter must be\n"
2078                "                      specified once only.\n"
2079                "  --"OPT_TRACE_BUF_SIZE"=<int>\n"
2080                "                      Specify maximum size of allocated memory\n"
2081                "                      for trace output for each thread. Valid\n"
2082                "                      unit can be either 'B|K|M' for 'Bytes',\n"
2083                "                      'KBytes' and 'MBytes' respectively.\n"
2084                "                      Default is 1MB and parameter must be\n"
2085                "                      specified once only.\n"
2086                "  --"OPT_TRACE_MODE"=<o[verwrite] | d[iscard]>\n"
2087                "                      Specify the mode of update of trace\n"
2088                "                      output file. Either update on a file can\n"
2089                "                      be wrapped or discarded when file size\n"
2090                "                      reaches its maximum limit.\n"
2091                "                      Default mode is 'overwrite' and parameter\n"
2092                "                      must be specified once only.\n"
2093 #endif /* !RTE_EXEC_ENV_WINDOWS */
2094                "  -v                  Display version information on startup\n"
2095                "  -h, --help          This help\n"
2096                "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
2097                "                      disable secondary process support\n"
2098                "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
2099                "  --"OPT_TELEMETRY"   Enable telemetry support (on by default)\n"
2100                "  --"OPT_NO_TELEMETRY"   Disable telemetry support\n"
2101                "  --"OPT_FORCE_MAX_SIMD_BITWIDTH" Force the max SIMD bitwidth\n"
2102                "\nEAL options for DEBUG use only:\n"
2103                "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
2104                "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
2105                "  --"OPT_NO_PCI"            Disable PCI\n"
2106                "  --"OPT_NO_HPET"           Disable HPET\n"
2107                "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
2108                "\n", RTE_MAX_LCORE);
2109 }