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