New upstream version 18.11-rc1
[deb_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 #include <syslog.h>
10 #include <ctype.h>
11 #include <limits.h>
12 #include <errno.h>
13 #include <getopt.h>
14 #include <dlfcn.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <dirent.h>
18
19 #include <rte_eal.h>
20 #include <rte_log.h>
21 #include <rte_lcore.h>
22 #include <rte_tailq.h>
23 #include <rte_version.h>
24 #include <rte_devargs.h>
25 #include <rte_memcpy.h>
26
27 #include "eal_internal_cfg.h"
28 #include "eal_options.h"
29 #include "eal_filesystem.h"
30 #include "eal_private.h"
31
32 #define BITS_PER_HEX 4
33 #define LCORE_OPT_LST 1
34 #define LCORE_OPT_MSK 2
35 #define LCORE_OPT_MAP 3
36
37 const char
38 eal_short_options[] =
39         "b:" /* pci-blacklist */
40         "c:" /* coremask */
41         "s:" /* service coremask */
42         "d:" /* driver */
43         "h"  /* help */
44         "l:" /* corelist */
45         "S:" /* service corelist */
46         "m:" /* memory size */
47         "n:" /* memory channels */
48         "r:" /* memory ranks */
49         "v"  /* version */
50         "w:" /* pci-whitelist */
51         ;
52
53 const struct option
54 eal_long_options[] = {
55         {OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
56         {OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
57         {OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
58         {OPT_HELP,              0, NULL, OPT_HELP_NUM             },
59         {OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
60         {OPT_HUGE_UNLINK,       0, NULL, OPT_HUGE_UNLINK_NUM      },
61         {OPT_IOVA_MODE,         1, NULL, OPT_IOVA_MODE_NUM        },
62         {OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
63         {OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
64         {OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
65         {OPT_MBUF_POOL_OPS_NAME, 1, NULL, OPT_MBUF_POOL_OPS_NAME_NUM},
66         {OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
67         {OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
68         {OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
69         {OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
70         {OPT_IN_MEMORY,         0, NULL, OPT_IN_MEMORY_NUM        },
71         {OPT_PCI_BLACKLIST,     1, NULL, OPT_PCI_BLACKLIST_NUM    },
72         {OPT_PCI_WHITELIST,     1, NULL, OPT_PCI_WHITELIST_NUM    },
73         {OPT_PROC_TYPE,         1, NULL, OPT_PROC_TYPE_NUM        },
74         {OPT_SOCKET_MEM,        1, NULL, OPT_SOCKET_MEM_NUM       },
75         {OPT_SOCKET_LIMIT,      1, NULL, OPT_SOCKET_LIMIT_NUM     },
76         {OPT_SYSLOG,            1, NULL, OPT_SYSLOG_NUM           },
77         {OPT_VDEV,              1, NULL, OPT_VDEV_NUM             },
78         {OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
79         {OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
80         {OPT_LEGACY_MEM,        0, NULL, OPT_LEGACY_MEM_NUM       },
81         {OPT_SINGLE_FILE_SEGMENTS, 0, NULL, OPT_SINGLE_FILE_SEGMENTS_NUM},
82         {0,                     0, NULL, 0                        }
83 };
84
85 TAILQ_HEAD(shared_driver_list, shared_driver);
86
87 /* Definition for shared object drivers. */
88 struct shared_driver {
89         TAILQ_ENTRY(shared_driver) next;
90
91         char    name[PATH_MAX];
92         void*   lib_handle;
93 };
94
95 /* List of external loadable drivers */
96 static struct shared_driver_list solib_list =
97 TAILQ_HEAD_INITIALIZER(solib_list);
98
99 /* Default path of external loadable drivers */
100 static const char *default_solib_dir = RTE_EAL_PMD_PATH;
101
102 /*
103  * Stringified version of solib path used by dpdk-pmdinfo.py
104  * Note: PLEASE DO NOT ALTER THIS without making a corresponding
105  * change to usertools/dpdk-pmdinfo.py
106  */
107 static const char dpdk_solib_path[] __attribute__((used)) =
108 "DPDK_PLUGIN_PATH=" RTE_EAL_PMD_PATH;
109
110 TAILQ_HEAD(device_option_list, device_option);
111
112 struct device_option {
113         TAILQ_ENTRY(device_option) next;
114
115         enum rte_devtype type;
116         char arg[];
117 };
118
119 static struct device_option_list devopt_list =
120 TAILQ_HEAD_INITIALIZER(devopt_list);
121
122 static int master_lcore_parsed;
123 static int mem_parsed;
124 static int core_parsed;
125
126 static int
127 eal_option_device_add(enum rte_devtype type, const char *optarg)
128 {
129         struct device_option *devopt;
130         size_t optlen;
131         int ret;
132
133         optlen = strlen(optarg) + 1;
134         devopt = calloc(1, sizeof(*devopt) + optlen);
135         if (devopt == NULL) {
136                 RTE_LOG(ERR, EAL, "Unable to allocate device option\n");
137                 return -ENOMEM;
138         }
139
140         devopt->type = type;
141         ret = snprintf(devopt->arg, optlen, "%s", optarg);
142         if (ret < 0) {
143                 RTE_LOG(ERR, EAL, "Unable to copy device option\n");
144                 free(devopt);
145                 return -EINVAL;
146         }
147         TAILQ_INSERT_TAIL(&devopt_list, devopt, next);
148         return 0;
149 }
150
151 int
152 eal_option_device_parse(void)
153 {
154         struct device_option *devopt;
155         void *tmp;
156         int ret = 0;
157
158         TAILQ_FOREACH_SAFE(devopt, &devopt_list, next, tmp) {
159                 if (ret == 0) {
160                         ret = rte_devargs_add(devopt->type, devopt->arg);
161                         if (ret)
162                                 RTE_LOG(ERR, EAL, "Unable to parse device '%s'\n",
163                                         devopt->arg);
164                 }
165                 TAILQ_REMOVE(&devopt_list, devopt, next);
166                 free(devopt);
167         }
168         return ret;
169 }
170
171 void
172 eal_reset_internal_config(struct internal_config *internal_cfg)
173 {
174         int i;
175
176         internal_cfg->memory = 0;
177         internal_cfg->force_nrank = 0;
178         internal_cfg->force_nchannel = 0;
179         internal_cfg->hugefile_prefix = HUGEFILE_PREFIX_DEFAULT;
180         internal_cfg->hugepage_dir = NULL;
181         internal_cfg->force_sockets = 0;
182         /* zero out the NUMA config */
183         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
184                 internal_cfg->socket_mem[i] = 0;
185         internal_cfg->force_socket_limits = 0;
186         /* zero out the NUMA limits config */
187         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
188                 internal_cfg->socket_limit[i] = 0;
189         /* zero out hugedir descriptors */
190         for (i = 0; i < MAX_HUGEPAGE_SIZES; i++) {
191                 memset(&internal_cfg->hugepage_info[i], 0,
192                                 sizeof(internal_cfg->hugepage_info[0]));
193                 internal_cfg->hugepage_info[i].lock_descriptor = -1;
194         }
195         internal_cfg->base_virtaddr = 0;
196
197         internal_cfg->syslog_facility = LOG_DAEMON;
198
199         /* if set to NONE, interrupt mode is determined automatically */
200         internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
201
202 #ifdef RTE_LIBEAL_USE_HPET
203         internal_cfg->no_hpet = 0;
204 #else
205         internal_cfg->no_hpet = 1;
206 #endif
207         internal_cfg->vmware_tsc_map = 0;
208         internal_cfg->create_uio_dev = 0;
209         internal_cfg->iova_mode = RTE_IOVA_DC;
210         internal_cfg->user_mbuf_pool_ops_name = NULL;
211         internal_cfg->init_complete = 0;
212 }
213
214 static int
215 eal_plugin_add(const char *path)
216 {
217         struct shared_driver *solib;
218
219         solib = malloc(sizeof(*solib));
220         if (solib == NULL) {
221                 RTE_LOG(ERR, EAL, "malloc(solib) failed\n");
222                 return -1;
223         }
224         memset(solib, 0, sizeof(*solib));
225         strncpy(solib->name, path, PATH_MAX-1);
226         solib->name[PATH_MAX-1] = 0;
227         TAILQ_INSERT_TAIL(&solib_list, solib, next);
228
229         return 0;
230 }
231
232 static int
233 eal_plugindir_init(const char *path)
234 {
235         DIR *d = NULL;
236         struct dirent *dent = NULL;
237         char sopath[PATH_MAX];
238
239         if (path == NULL || *path == '\0')
240                 return 0;
241
242         d = opendir(path);
243         if (d == NULL) {
244                 RTE_LOG(ERR, EAL, "failed to open directory %s: %s\n",
245                         path, strerror(errno));
246                 return -1;
247         }
248
249         while ((dent = readdir(d)) != NULL) {
250                 struct stat sb;
251
252                 snprintf(sopath, PATH_MAX-1, "%s/%s", path, dent->d_name);
253                 sopath[PATH_MAX-1] = 0;
254
255                 if (!(stat(sopath, &sb) == 0 && S_ISREG(sb.st_mode)))
256                         continue;
257
258                 if (eal_plugin_add(sopath) == -1)
259                         break;
260         }
261
262         closedir(d);
263         /* XXX this ignores failures from readdir() itself */
264         return (dent == NULL) ? 0 : -1;
265 }
266
267 int
268 eal_plugins_init(void)
269 {
270         struct shared_driver *solib = NULL;
271         struct stat sb;
272
273         if (*default_solib_dir != '\0' && stat(default_solib_dir, &sb) == 0 &&
274                                 S_ISDIR(sb.st_mode))
275                 eal_plugin_add(default_solib_dir);
276
277         TAILQ_FOREACH(solib, &solib_list, next) {
278
279                 if (stat(solib->name, &sb) == 0 && S_ISDIR(sb.st_mode)) {
280                         if (eal_plugindir_init(solib->name) == -1) {
281                                 RTE_LOG(ERR, EAL,
282                                         "Cannot init plugin directory %s\n",
283                                         solib->name);
284                                 return -1;
285                         }
286                 } else {
287                         RTE_LOG(DEBUG, EAL, "open shared lib %s\n",
288                                 solib->name);
289                         solib->lib_handle = dlopen(solib->name, RTLD_NOW);
290                         if (solib->lib_handle == NULL) {
291                                 RTE_LOG(ERR, EAL, "%s\n", dlerror());
292                                 return -1;
293                         }
294                 }
295
296         }
297         return 0;
298 }
299
300 /*
301  * Parse the coremask given as argument (hexadecimal string) and fill
302  * the global configuration (core role and core count) with the parsed
303  * value.
304  */
305 static int xdigit2val(unsigned char c)
306 {
307         int val;
308
309         if (isdigit(c))
310                 val = c - '0';
311         else if (isupper(c))
312                 val = c - 'A' + 10;
313         else
314                 val = c - 'a' + 10;
315         return val;
316 }
317
318 static int
319 eal_parse_service_coremask(const char *coremask)
320 {
321         struct rte_config *cfg = rte_eal_get_configuration();
322         int i, j, idx = 0;
323         unsigned int count = 0;
324         char c;
325         int val;
326         uint32_t taken_lcore_count = 0;
327
328         if (coremask == NULL)
329                 return -1;
330         /* Remove all blank characters ahead and after .
331          * Remove 0x/0X if exists.
332          */
333         while (isblank(*coremask))
334                 coremask++;
335         if (coremask[0] == '0' && ((coremask[1] == 'x')
336                 || (coremask[1] == 'X')))
337                 coremask += 2;
338         i = strlen(coremask);
339         while ((i > 0) && isblank(coremask[i - 1]))
340                 i--;
341
342         if (i == 0)
343                 return -1;
344
345         for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
346                 c = coremask[i];
347                 if (isxdigit(c) == 0) {
348                         /* invalid characters */
349                         return -1;
350                 }
351                 val = xdigit2val(c);
352                 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE;
353                                 j++, idx++) {
354                         if ((1 << j) & val) {
355                                 /* handle master lcore already parsed */
356                                 uint32_t lcore = idx;
357                                 if (master_lcore_parsed &&
358                                                 cfg->master_lcore == lcore) {
359                                         RTE_LOG(ERR, EAL,
360                                                 "lcore %u is master lcore, cannot use as service core\n",
361                                                 idx);
362                                         return -1;
363                                 }
364
365                                 if (!lcore_config[idx].detected) {
366                                         RTE_LOG(ERR, EAL,
367                                                 "lcore %u unavailable\n", idx);
368                                         return -1;
369                                 }
370
371                                 if (cfg->lcore_role[idx] == ROLE_RTE)
372                                         taken_lcore_count++;
373
374                                 lcore_config[idx].core_role = ROLE_SERVICE;
375                                 count++;
376                         }
377                 }
378         }
379
380         for (; i >= 0; i--)
381                 if (coremask[i] != '0')
382                         return -1;
383
384         for (; idx < RTE_MAX_LCORE; idx++)
385                 lcore_config[idx].core_index = -1;
386
387         if (count == 0)
388                 return -1;
389
390         if (core_parsed && taken_lcore_count != count) {
391                 RTE_LOG(WARNING, EAL,
392                         "Not all service cores are in the coremask. "
393                         "Please ensure -c or -l includes service cores\n");
394         }
395
396         cfg->service_lcore_count = count;
397         return 0;
398 }
399
400 static int
401 eal_service_cores_parsed(void)
402 {
403         int idx;
404         for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
405                 if (lcore_config[idx].core_role == ROLE_SERVICE)
406                         return 1;
407         }
408         return 0;
409 }
410
411 static int
412 eal_parse_coremask(const char *coremask)
413 {
414         struct rte_config *cfg = rte_eal_get_configuration();
415         int i, j, idx = 0;
416         unsigned count = 0;
417         char c;
418         int val;
419
420         if (eal_service_cores_parsed())
421                 RTE_LOG(WARNING, EAL,
422                         "Service cores parsed before dataplane cores. "
423                         "Please ensure -c is before -s or -S\n");
424
425         if (coremask == NULL)
426                 return -1;
427         /* Remove all blank characters ahead and after .
428          * Remove 0x/0X if exists.
429          */
430         while (isblank(*coremask))
431                 coremask++;
432         if (coremask[0] == '0' && ((coremask[1] == 'x')
433                 || (coremask[1] == 'X')))
434                 coremask += 2;
435         i = strlen(coremask);
436         while ((i > 0) && isblank(coremask[i - 1]))
437                 i--;
438         if (i == 0)
439                 return -1;
440
441         for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
442                 c = coremask[i];
443                 if (isxdigit(c) == 0) {
444                         /* invalid characters */
445                         return -1;
446                 }
447                 val = xdigit2val(c);
448                 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
449                 {
450                         if ((1 << j) & val) {
451                                 if (!lcore_config[idx].detected) {
452                                         RTE_LOG(ERR, EAL, "lcore %u "
453                                                 "unavailable\n", idx);
454                                         return -1;
455                                 }
456
457                                 cfg->lcore_role[idx] = ROLE_RTE;
458                                 lcore_config[idx].core_index = count;
459                                 count++;
460                         } else {
461                                 cfg->lcore_role[idx] = ROLE_OFF;
462                                 lcore_config[idx].core_index = -1;
463                         }
464                 }
465         }
466         for (; i >= 0; i--)
467                 if (coremask[i] != '0')
468                         return -1;
469         for (; idx < RTE_MAX_LCORE; idx++) {
470                 cfg->lcore_role[idx] = ROLE_OFF;
471                 lcore_config[idx].core_index = -1;
472         }
473         if (count == 0)
474                 return -1;
475         /* Update the count of enabled logical cores of the EAL configuration */
476         cfg->lcore_count = count;
477         return 0;
478 }
479
480 static int
481 eal_parse_service_corelist(const char *corelist)
482 {
483         struct rte_config *cfg = rte_eal_get_configuration();
484         int i, idx = 0;
485         unsigned count = 0;
486         char *end = NULL;
487         int min, max;
488         uint32_t taken_lcore_count = 0;
489
490         if (corelist == NULL)
491                 return -1;
492
493         /* Remove all blank characters ahead and after */
494         while (isblank(*corelist))
495                 corelist++;
496         i = strlen(corelist);
497         while ((i > 0) && isblank(corelist[i - 1]))
498                 i--;
499
500         /* Get list of cores */
501         min = RTE_MAX_LCORE;
502         do {
503                 while (isblank(*corelist))
504                         corelist++;
505                 if (*corelist == '\0')
506                         return -1;
507                 errno = 0;
508                 idx = strtoul(corelist, &end, 10);
509                 if (errno || end == NULL)
510                         return -1;
511                 while (isblank(*end))
512                         end++;
513                 if (*end == '-') {
514                         min = idx;
515                 } else if ((*end == ',') || (*end == '\0')) {
516                         max = idx;
517                         if (min == RTE_MAX_LCORE)
518                                 min = idx;
519                         for (idx = min; idx <= max; idx++) {
520                                 if (cfg->lcore_role[idx] != ROLE_SERVICE) {
521                                         /* handle master lcore already parsed */
522                                         uint32_t lcore = idx;
523                                         if (cfg->master_lcore == lcore &&
524                                                         master_lcore_parsed) {
525                                                 RTE_LOG(ERR, EAL,
526                                                         "Error: lcore %u is master lcore, cannot use as service core\n",
527                                                         idx);
528                                                 return -1;
529                                         }
530                                         if (cfg->lcore_role[idx] == ROLE_RTE)
531                                                 taken_lcore_count++;
532
533                                         lcore_config[idx].core_role =
534                                                         ROLE_SERVICE;
535                                         count++;
536                                 }
537                         }
538                         min = RTE_MAX_LCORE;
539                 } else
540                         return -1;
541                 corelist = end + 1;
542         } while (*end != '\0');
543
544         if (count == 0)
545                 return -1;
546
547         if (core_parsed && taken_lcore_count != count) {
548                 RTE_LOG(WARNING, EAL,
549                         "Not all service cores were in the coremask. "
550                         "Please ensure -c or -l includes service cores\n");
551         }
552
553         return 0;
554 }
555
556 static int
557 eal_parse_corelist(const char *corelist)
558 {
559         struct rte_config *cfg = rte_eal_get_configuration();
560         int i, idx = 0;
561         unsigned count = 0;
562         char *end = NULL;
563         int min, max;
564
565         if (eal_service_cores_parsed())
566                 RTE_LOG(WARNING, EAL,
567                         "Service cores parsed before dataplane cores. "
568                         "Please ensure -l is before -s or -S\n");
569
570         if (corelist == NULL)
571                 return -1;
572
573         /* Remove all blank characters ahead and after */
574         while (isblank(*corelist))
575                 corelist++;
576         i = strlen(corelist);
577         while ((i > 0) && isblank(corelist[i - 1]))
578                 i--;
579
580         /* Reset config */
581         for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
582                 cfg->lcore_role[idx] = ROLE_OFF;
583                 lcore_config[idx].core_index = -1;
584         }
585
586         /* Get list of cores */
587         min = RTE_MAX_LCORE;
588         do {
589                 while (isblank(*corelist))
590                         corelist++;
591                 if (*corelist == '\0')
592                         return -1;
593                 errno = 0;
594                 idx = strtoul(corelist, &end, 10);
595                 if (errno || end == NULL)
596                         return -1;
597                 while (isblank(*end))
598                         end++;
599                 if (*end == '-') {
600                         min = idx;
601                 } else if ((*end == ',') || (*end == '\0')) {
602                         max = idx;
603                         if (min == RTE_MAX_LCORE)
604                                 min = idx;
605                         for (idx = min; idx <= max; idx++) {
606                                 if (cfg->lcore_role[idx] != ROLE_RTE) {
607                                         cfg->lcore_role[idx] = ROLE_RTE;
608                                         lcore_config[idx].core_index = count;
609                                         count++;
610                                 }
611                         }
612                         min = RTE_MAX_LCORE;
613                 } else
614                         return -1;
615                 corelist = end + 1;
616         } while (*end != '\0');
617
618         if (count == 0)
619                 return -1;
620
621         /* Update the count of enabled logical cores of the EAL configuration */
622         cfg->lcore_count = count;
623
624         return 0;
625 }
626
627 /* Changes the lcore id of the master thread */
628 static int
629 eal_parse_master_lcore(const char *arg)
630 {
631         char *parsing_end;
632         struct rte_config *cfg = rte_eal_get_configuration();
633
634         errno = 0;
635         cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
636         if (errno || parsing_end[0] != 0)
637                 return -1;
638         if (cfg->master_lcore >= RTE_MAX_LCORE)
639                 return -1;
640         master_lcore_parsed = 1;
641
642         /* ensure master core is not used as service core */
643         if (lcore_config[cfg->master_lcore].core_role == ROLE_SERVICE) {
644                 RTE_LOG(ERR, EAL,
645                         "Error: Master lcore is used as a service core\n");
646                 return -1;
647         }
648
649         return 0;
650 }
651
652 /*
653  * Parse elem, the elem could be single number/range or '(' ')' group
654  * 1) A single number elem, it's just a simple digit. e.g. 9
655  * 2) A single range elem, two digits with a '-' between. e.g. 2-6
656  * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
657  *    Within group elem, '-' used for a range separator;
658  *                       ',' used for a single number.
659  */
660 static int
661 eal_parse_set(const char *input, uint16_t set[], unsigned num)
662 {
663         unsigned idx;
664         const char *str = input;
665         char *end = NULL;
666         unsigned min, max;
667
668         memset(set, 0, num * sizeof(uint16_t));
669
670         while (isblank(*str))
671                 str++;
672
673         /* only digit or left bracket is qualify for start point */
674         if ((!isdigit(*str) && *str != '(') || *str == '\0')
675                 return -1;
676
677         /* process single number or single range of number */
678         if (*str != '(') {
679                 errno = 0;
680                 idx = strtoul(str, &end, 10);
681                 if (errno || end == NULL || idx >= num)
682                         return -1;
683                 else {
684                         while (isblank(*end))
685                                 end++;
686
687                         min = idx;
688                         max = idx;
689                         if (*end == '-') {
690                                 /* process single <number>-<number> */
691                                 end++;
692                                 while (isblank(*end))
693                                         end++;
694                                 if (!isdigit(*end))
695                                         return -1;
696
697                                 errno = 0;
698                                 idx = strtoul(end, &end, 10);
699                                 if (errno || end == NULL || idx >= num)
700                                         return -1;
701                                 max = idx;
702                                 while (isblank(*end))
703                                         end++;
704                                 if (*end != ',' && *end != '\0')
705                                         return -1;
706                         }
707
708                         if (*end != ',' && *end != '\0' &&
709                             *end != '@')
710                                 return -1;
711
712                         for (idx = RTE_MIN(min, max);
713                              idx <= RTE_MAX(min, max); idx++)
714                                 set[idx] = 1;
715
716                         return end - input;
717                 }
718         }
719
720         /* process set within bracket */
721         str++;
722         while (isblank(*str))
723                 str++;
724         if (*str == '\0')
725                 return -1;
726
727         min = RTE_MAX_LCORE;
728         do {
729
730                 /* go ahead to the first digit */
731                 while (isblank(*str))
732                         str++;
733                 if (!isdigit(*str))
734                         return -1;
735
736                 /* get the digit value */
737                 errno = 0;
738                 idx = strtoul(str, &end, 10);
739                 if (errno || end == NULL || idx >= num)
740                         return -1;
741
742                 /* go ahead to separator '-',',' and ')' */
743                 while (isblank(*end))
744                         end++;
745                 if (*end == '-') {
746                         if (min == RTE_MAX_LCORE)
747                                 min = idx;
748                         else /* avoid continuous '-' */
749                                 return -1;
750                 } else if ((*end == ',') || (*end == ')')) {
751                         max = idx;
752                         if (min == RTE_MAX_LCORE)
753                                 min = idx;
754                         for (idx = RTE_MIN(min, max);
755                              idx <= RTE_MAX(min, max); idx++)
756                                 set[idx] = 1;
757
758                         min = RTE_MAX_LCORE;
759                 } else
760                         return -1;
761
762                 str = end + 1;
763         } while (*end != '\0' && *end != ')');
764
765         /*
766          * to avoid failure that tail blank makes end character check fail
767          * in eal_parse_lcores( )
768          */
769         while (isblank(*str))
770                 str++;
771
772         return str - input;
773 }
774
775 /* convert from set array to cpuset bitmap */
776 static int
777 convert_to_cpuset(rte_cpuset_t *cpusetp,
778               uint16_t *set, unsigned num)
779 {
780         unsigned idx;
781
782         CPU_ZERO(cpusetp);
783
784         for (idx = 0; idx < num; idx++) {
785                 if (!set[idx])
786                         continue;
787
788                 if (!lcore_config[idx].detected) {
789                         RTE_LOG(ERR, EAL, "core %u "
790                                 "unavailable\n", idx);
791                         return -1;
792                 }
793
794                 CPU_SET(idx, cpusetp);
795         }
796
797         return 0;
798 }
799
800 /*
801  * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
802  * lcores, cpus could be a single digit/range or a group.
803  * '(' and ')' are necessary if it's a group.
804  * If not supply '@cpus', the value of cpus uses the same as lcores.
805  * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
806  *   lcore 0 runs on cpuset 0x41 (cpu 0,6)
807  *   lcore 1 runs on cpuset 0x2 (cpu 1)
808  *   lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
809  *   lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
810  *   lcore 6 runs on cpuset 0x41 (cpu 0,6)
811  *   lcore 7 runs on cpuset 0x80 (cpu 7)
812  *   lcore 8 runs on cpuset 0x100 (cpu 8)
813  */
814 static int
815 eal_parse_lcores(const char *lcores)
816 {
817         struct rte_config *cfg = rte_eal_get_configuration();
818         static uint16_t set[RTE_MAX_LCORE];
819         unsigned idx = 0;
820         unsigned count = 0;
821         const char *lcore_start = NULL;
822         const char *end = NULL;
823         int offset;
824         rte_cpuset_t cpuset;
825         int lflags;
826         int ret = -1;
827
828         if (lcores == NULL)
829                 return -1;
830
831         /* Remove all blank characters ahead and after */
832         while (isblank(*lcores))
833                 lcores++;
834
835         CPU_ZERO(&cpuset);
836
837         /* Reset lcore config */
838         for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
839                 cfg->lcore_role[idx] = ROLE_OFF;
840                 lcore_config[idx].core_index = -1;
841                 CPU_ZERO(&lcore_config[idx].cpuset);
842         }
843
844         /* Get list of cores */
845         do {
846                 while (isblank(*lcores))
847                         lcores++;
848                 if (*lcores == '\0')
849                         goto err;
850
851                 lflags = 0;
852
853                 /* record lcore_set start point */
854                 lcore_start = lcores;
855
856                 /* go across a complete bracket */
857                 if (*lcore_start == '(') {
858                         lcores += strcspn(lcores, ")");
859                         if (*lcores++ == '\0')
860                                 goto err;
861                 }
862
863                 /* scan the separator '@', ','(next) or '\0'(finish) */
864                 lcores += strcspn(lcores, "@,");
865
866                 if (*lcores == '@') {
867                         /* explicit assign cpu_set */
868                         offset = eal_parse_set(lcores + 1, set, RTE_DIM(set));
869                         if (offset < 0)
870                                 goto err;
871
872                         /* prepare cpu_set and update the end cursor */
873                         if (0 > convert_to_cpuset(&cpuset,
874                                                   set, RTE_DIM(set)))
875                                 goto err;
876                         end = lcores + 1 + offset;
877                 } else { /* ',' or '\0' */
878                         /* haven't given cpu_set, current loop done */
879                         end = lcores;
880
881                         /* go back to check <number>-<number> */
882                         offset = strcspn(lcore_start, "(-");
883                         if (offset < (end - lcore_start) &&
884                             *(lcore_start + offset) != '(')
885                                 lflags = 1;
886                 }
887
888                 if (*end != ',' && *end != '\0')
889                         goto err;
890
891                 /* parse lcore_set from start point */
892                 if (0 > eal_parse_set(lcore_start, set, RTE_DIM(set)))
893                         goto err;
894
895                 /* without '@', by default using lcore_set as cpu_set */
896                 if (*lcores != '@' &&
897                     0 > convert_to_cpuset(&cpuset, set, RTE_DIM(set)))
898                         goto err;
899
900                 /* start to update lcore_set */
901                 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
902                         if (!set[idx])
903                                 continue;
904
905                         if (cfg->lcore_role[idx] != ROLE_RTE) {
906                                 lcore_config[idx].core_index = count;
907                                 cfg->lcore_role[idx] = ROLE_RTE;
908                                 count++;
909                         }
910
911                         if (lflags) {
912                                 CPU_ZERO(&cpuset);
913                                 CPU_SET(idx, &cpuset);
914                         }
915                         rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
916                                    sizeof(rte_cpuset_t));
917                 }
918
919                 lcores = end + 1;
920         } while (*end != '\0');
921
922         if (count == 0)
923                 goto err;
924
925         cfg->lcore_count = count;
926         ret = 0;
927
928 err:
929
930         return ret;
931 }
932
933 static int
934 eal_parse_syslog(const char *facility, struct internal_config *conf)
935 {
936         int i;
937         static const struct {
938                 const char *name;
939                 int value;
940         } map[] = {
941                 { "auth", LOG_AUTH },
942                 { "cron", LOG_CRON },
943                 { "daemon", LOG_DAEMON },
944                 { "ftp", LOG_FTP },
945                 { "kern", LOG_KERN },
946                 { "lpr", LOG_LPR },
947                 { "mail", LOG_MAIL },
948                 { "news", LOG_NEWS },
949                 { "syslog", LOG_SYSLOG },
950                 { "user", LOG_USER },
951                 { "uucp", LOG_UUCP },
952                 { "local0", LOG_LOCAL0 },
953                 { "local1", LOG_LOCAL1 },
954                 { "local2", LOG_LOCAL2 },
955                 { "local3", LOG_LOCAL3 },
956                 { "local4", LOG_LOCAL4 },
957                 { "local5", LOG_LOCAL5 },
958                 { "local6", LOG_LOCAL6 },
959                 { "local7", LOG_LOCAL7 },
960                 { NULL, 0 }
961         };
962
963         for (i = 0; map[i].name; i++) {
964                 if (!strcmp(facility, map[i].name)) {
965                         conf->syslog_facility = map[i].value;
966                         return 0;
967                 }
968         }
969         return -1;
970 }
971
972 static int
973 eal_parse_log_priority(const char *level)
974 {
975         static const char * const levels[] = {
976                 [RTE_LOG_EMERG]   = "emergency",
977                 [RTE_LOG_ALERT]   = "alert",
978                 [RTE_LOG_CRIT]    = "critical",
979                 [RTE_LOG_ERR]     = "error",
980                 [RTE_LOG_WARNING] = "warning",
981                 [RTE_LOG_NOTICE]  = "notice",
982                 [RTE_LOG_INFO]    = "info",
983                 [RTE_LOG_DEBUG]   = "debug",
984         };
985         size_t len = strlen(level);
986         unsigned long tmp;
987         char *end;
988         unsigned int i;
989
990         if (len == 0)
991                 return -1;
992
993         /* look for named values, skip 0 which is not a valid level */
994         for (i = 1; i < RTE_DIM(levels); i++) {
995                 if (strncmp(levels[i], level, len) == 0)
996                         return i;
997         }
998
999         /* not a string, maybe it is numeric */
1000         errno = 0;
1001         tmp = strtoul(level, &end, 0);
1002
1003         /* check for errors */
1004         if (errno != 0 || end == NULL || *end != '\0' ||
1005             tmp >= UINT32_MAX)
1006                 return -1;
1007
1008         return tmp;
1009 }
1010
1011 static int
1012 eal_parse_log_level(const char *arg)
1013 {
1014         const char *pattern = NULL;
1015         const char *regex = NULL;
1016         char *str, *level;
1017         int priority;
1018
1019         str = strdup(arg);
1020         if (str == NULL)
1021                 return -1;
1022
1023         if ((level = strchr(str, ','))) {
1024                 regex = str;
1025                 *level++ = '\0';
1026         } else if ((level = strchr(str, ':'))) {
1027                 pattern = str;
1028                 *level++ = '\0';
1029         } else {
1030                 level = str;
1031         }
1032
1033         priority = eal_parse_log_priority(level);
1034         if (priority < 0) {
1035                 fprintf(stderr, "invalid log priority: %s\n", level);
1036                 goto fail;
1037         }
1038
1039         if (regex) {
1040                 if (rte_log_set_level_regexp(regex, priority) < 0) {
1041                         fprintf(stderr, "cannot set log level %s,%d\n",
1042                                 pattern, priority);
1043                         goto fail;
1044                 }
1045                 if (rte_log_save_regexp(regex, priority) < 0)
1046                         goto fail;
1047         } else if (pattern) {
1048                 if (rte_log_set_level_pattern(pattern, priority) < 0) {
1049                         fprintf(stderr, "cannot set log level %s:%d\n",
1050                                 pattern, priority);
1051                         goto fail;
1052                 }
1053                 if (rte_log_save_pattern(pattern, priority) < 0)
1054                         goto fail;
1055         } else {
1056                 rte_log_set_global_level(priority);
1057         }
1058
1059         free(str);
1060         return 0;
1061
1062 fail:
1063         free(str);
1064         return -1;
1065 }
1066
1067 static enum rte_proc_type_t
1068 eal_parse_proc_type(const char *arg)
1069 {
1070         if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
1071                 return RTE_PROC_PRIMARY;
1072         if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
1073                 return RTE_PROC_SECONDARY;
1074         if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
1075                 return RTE_PROC_AUTO;
1076
1077         return RTE_PROC_INVALID;
1078 }
1079
1080 static int
1081 eal_parse_iova_mode(const char *name)
1082 {
1083         int mode;
1084
1085         if (name == NULL)
1086                 return -1;
1087
1088         if (!strcmp("pa", name))
1089                 mode = RTE_IOVA_PA;
1090         else if (!strcmp("va", name))
1091                 mode = RTE_IOVA_VA;
1092         else
1093                 return -1;
1094
1095         internal_config.iova_mode = mode;
1096         return 0;
1097 }
1098
1099 int
1100 eal_parse_common_option(int opt, const char *optarg,
1101                         struct internal_config *conf)
1102 {
1103         static int b_used;
1104         static int w_used;
1105
1106         switch (opt) {
1107         /* blacklist */
1108         case 'b':
1109                 if (w_used)
1110                         goto bw_used;
1111                 if (eal_option_device_add(RTE_DEVTYPE_BLACKLISTED_PCI,
1112                                 optarg) < 0) {
1113                         return -1;
1114                 }
1115                 b_used = 1;
1116                 break;
1117         /* whitelist */
1118         case 'w':
1119                 if (b_used)
1120                         goto bw_used;
1121                 if (eal_option_device_add(RTE_DEVTYPE_WHITELISTED_PCI,
1122                                 optarg) < 0) {
1123                         return -1;
1124                 }
1125                 w_used = 1;
1126                 break;
1127         /* coremask */
1128         case 'c':
1129                 if (eal_parse_coremask(optarg) < 0) {
1130                         RTE_LOG(ERR, EAL, "invalid coremask\n");
1131                         return -1;
1132                 }
1133
1134                 if (core_parsed) {
1135                         RTE_LOG(ERR, EAL, "Option -c is ignored, because (%s) is set!\n",
1136                                 (core_parsed == LCORE_OPT_LST) ? "-l" :
1137                                 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1138                                 "-c");
1139                         return -1;
1140                 }
1141
1142                 core_parsed = LCORE_OPT_MSK;
1143                 break;
1144         /* corelist */
1145         case 'l':
1146                 if (eal_parse_corelist(optarg) < 0) {
1147                         RTE_LOG(ERR, EAL, "invalid core list\n");
1148                         return -1;
1149                 }
1150
1151                 if (core_parsed) {
1152                         RTE_LOG(ERR, EAL, "Option -l is ignored, because (%s) is set!\n",
1153                                 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1154                                 (core_parsed == LCORE_OPT_MAP) ? "--lcore" :
1155                                 "-l");
1156                         return -1;
1157                 }
1158
1159                 core_parsed = LCORE_OPT_LST;
1160                 break;
1161         /* service coremask */
1162         case 's':
1163                 if (eal_parse_service_coremask(optarg) < 0) {
1164                         RTE_LOG(ERR, EAL, "invalid service coremask\n");
1165                         return -1;
1166                 }
1167                 break;
1168         /* service corelist */
1169         case 'S':
1170                 if (eal_parse_service_corelist(optarg) < 0) {
1171                         RTE_LOG(ERR, EAL, "invalid service core list\n");
1172                         return -1;
1173                 }
1174                 break;
1175         /* size of memory */
1176         case 'm':
1177                 conf->memory = atoi(optarg);
1178                 conf->memory *= 1024ULL;
1179                 conf->memory *= 1024ULL;
1180                 mem_parsed = 1;
1181                 break;
1182         /* force number of channels */
1183         case 'n':
1184                 conf->force_nchannel = atoi(optarg);
1185                 if (conf->force_nchannel == 0) {
1186                         RTE_LOG(ERR, EAL, "invalid channel number\n");
1187                         return -1;
1188                 }
1189                 break;
1190         /* force number of ranks */
1191         case 'r':
1192                 conf->force_nrank = atoi(optarg);
1193                 if (conf->force_nrank == 0 ||
1194                     conf->force_nrank > 16) {
1195                         RTE_LOG(ERR, EAL, "invalid rank number\n");
1196                         return -1;
1197                 }
1198                 break;
1199         /* force loading of external driver */
1200         case 'd':
1201                 if (eal_plugin_add(optarg) == -1)
1202                         return -1;
1203                 break;
1204         case 'v':
1205                 /* since message is explicitly requested by user, we
1206                  * write message at highest log level so it can always
1207                  * be seen
1208                  * even if info or warning messages are disabled */
1209                 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
1210                 break;
1211
1212         /* long options */
1213         case OPT_HUGE_UNLINK_NUM:
1214                 conf->hugepage_unlink = 1;
1215                 break;
1216
1217         case OPT_NO_HUGE_NUM:
1218                 conf->no_hugetlbfs = 1;
1219                 /* no-huge is legacy mem */
1220                 conf->legacy_mem = 1;
1221                 break;
1222
1223         case OPT_NO_PCI_NUM:
1224                 conf->no_pci = 1;
1225                 break;
1226
1227         case OPT_NO_HPET_NUM:
1228                 conf->no_hpet = 1;
1229                 break;
1230
1231         case OPT_VMWARE_TSC_MAP_NUM:
1232                 conf->vmware_tsc_map = 1;
1233                 break;
1234
1235         case OPT_NO_SHCONF_NUM:
1236                 conf->no_shconf = 1;
1237                 break;
1238
1239         case OPT_IN_MEMORY_NUM:
1240                 conf->in_memory = 1;
1241                 /* in-memory is a superset of noshconf and huge-unlink */
1242                 conf->no_shconf = 1;
1243                 conf->hugepage_unlink = 1;
1244                 break;
1245
1246         case OPT_PROC_TYPE_NUM:
1247                 conf->process_type = eal_parse_proc_type(optarg);
1248                 break;
1249
1250         case OPT_MASTER_LCORE_NUM:
1251                 if (eal_parse_master_lcore(optarg) < 0) {
1252                         RTE_LOG(ERR, EAL, "invalid parameter for --"
1253                                         OPT_MASTER_LCORE "\n");
1254                         return -1;
1255                 }
1256                 break;
1257
1258         case OPT_VDEV_NUM:
1259                 if (eal_option_device_add(RTE_DEVTYPE_VIRTUAL,
1260                                 optarg) < 0) {
1261                         return -1;
1262                 }
1263                 break;
1264
1265         case OPT_SYSLOG_NUM:
1266                 if (eal_parse_syslog(optarg, conf) < 0) {
1267                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1268                                         OPT_SYSLOG "\n");
1269                         return -1;
1270                 }
1271                 break;
1272
1273         case OPT_LOG_LEVEL_NUM: {
1274                 if (eal_parse_log_level(optarg) < 0) {
1275                         RTE_LOG(ERR, EAL,
1276                                 "invalid parameters for --"
1277                                 OPT_LOG_LEVEL "\n");
1278                         return -1;
1279                 }
1280                 break;
1281         }
1282         case OPT_LCORES_NUM:
1283                 if (eal_parse_lcores(optarg) < 0) {
1284                         RTE_LOG(ERR, EAL, "invalid parameter for --"
1285                                 OPT_LCORES "\n");
1286                         return -1;
1287                 }
1288
1289                 if (core_parsed) {
1290                         RTE_LOG(ERR, EAL, "Option --lcore is ignored, because (%s) is set!\n",
1291                                 (core_parsed == LCORE_OPT_LST) ? "-l" :
1292                                 (core_parsed == LCORE_OPT_MSK) ? "-c" :
1293                                 "--lcore");
1294                         return -1;
1295                 }
1296
1297                 core_parsed = LCORE_OPT_MAP;
1298                 break;
1299         case OPT_LEGACY_MEM_NUM:
1300                 conf->legacy_mem = 1;
1301                 break;
1302         case OPT_SINGLE_FILE_SEGMENTS_NUM:
1303                 conf->single_file_segments = 1;
1304                 break;
1305         case OPT_IOVA_MODE_NUM:
1306                 if (eal_parse_iova_mode(optarg) < 0) {
1307                         RTE_LOG(ERR, EAL, "invalid parameters for --"
1308                                 OPT_IOVA_MODE "\n");
1309                         return -1;
1310                 }
1311                 break;
1312
1313         /* don't know what to do, leave this to caller */
1314         default:
1315                 return 1;
1316
1317         }
1318
1319         return 0;
1320 bw_used:
1321         RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
1322                 "cannot be used at the same time\n");
1323         return -1;
1324 }
1325
1326 static void
1327 eal_auto_detect_cores(struct rte_config *cfg)
1328 {
1329         unsigned int lcore_id;
1330         unsigned int removed = 0;
1331         rte_cpuset_t affinity_set;
1332         pthread_t tid = pthread_self();
1333
1334         if (pthread_getaffinity_np(tid, sizeof(rte_cpuset_t),
1335                                 &affinity_set) < 0)
1336                 CPU_ZERO(&affinity_set);
1337
1338         for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) {
1339                 if (cfg->lcore_role[lcore_id] == ROLE_RTE &&
1340                     !CPU_ISSET(lcore_id, &affinity_set)) {
1341                         cfg->lcore_role[lcore_id] = ROLE_OFF;
1342                         removed++;
1343                 }
1344         }
1345
1346         cfg->lcore_count -= removed;
1347 }
1348
1349 int
1350 eal_adjust_config(struct internal_config *internal_cfg)
1351 {
1352         int i;
1353         struct rte_config *cfg = rte_eal_get_configuration();
1354
1355         if (!core_parsed)
1356                 eal_auto_detect_cores(cfg);
1357
1358         if (internal_config.process_type == RTE_PROC_AUTO)
1359                 internal_config.process_type = eal_proc_type_detect();
1360
1361         /* default master lcore is the first one */
1362         if (!master_lcore_parsed) {
1363                 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
1364                 lcore_config[cfg->master_lcore].core_role = ROLE_RTE;
1365         }
1366
1367         /* if no memory amounts were requested, this will result in 0 and
1368          * will be overridden later, right after eal_hugepage_info_init() */
1369         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
1370                 internal_cfg->memory += internal_cfg->socket_mem[i];
1371
1372         return 0;
1373 }
1374
1375 int
1376 eal_check_common_options(struct internal_config *internal_cfg)
1377 {
1378         struct rte_config *cfg = rte_eal_get_configuration();
1379
1380         if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
1381                 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
1382                 return -1;
1383         }
1384
1385         if (internal_cfg->process_type == RTE_PROC_INVALID) {
1386                 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
1387                 return -1;
1388         }
1389         if (index(internal_cfg->hugefile_prefix, '%') != NULL) {
1390                 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
1391                         "option\n");
1392                 return -1;
1393         }
1394         if (mem_parsed && internal_cfg->force_sockets == 1) {
1395                 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
1396                         "be specified at the same time\n");
1397                 return -1;
1398         }
1399         if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
1400                 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
1401                         "be specified together with --"OPT_NO_HUGE"\n");
1402                 return -1;
1403         }
1404         if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink &&
1405                         !internal_cfg->in_memory) {
1406                 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
1407                         "be specified together with --"OPT_NO_HUGE"\n");
1408                 return -1;
1409         }
1410         if (internal_config.force_socket_limits && internal_config.legacy_mem) {
1411                 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_LIMIT
1412                         " is only supported in non-legacy memory mode\n");
1413         }
1414         if (internal_cfg->single_file_segments &&
1415                         internal_cfg->hugepage_unlink &&
1416                         !internal_cfg->in_memory) {
1417                 RTE_LOG(ERR, EAL, "Option --"OPT_SINGLE_FILE_SEGMENTS" is "
1418                         "not compatible with --"OPT_HUGE_UNLINK"\n");
1419                 return -1;
1420         }
1421         if (internal_cfg->legacy_mem &&
1422                         internal_cfg->in_memory) {
1423                 RTE_LOG(ERR, EAL, "Option --"OPT_LEGACY_MEM" is not compatible "
1424                                 "with --"OPT_IN_MEMORY"\n");
1425                 return -1;
1426         }
1427
1428         return 0;
1429 }
1430
1431 void
1432 eal_common_usage(void)
1433 {
1434         printf("[options]\n\n"
1435                "EAL common options:\n"
1436                "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
1437                "  -l CORELIST         List of cores to run on\n"
1438                "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
1439                "                      where c1, c2, etc are core indexes between 0 and %d\n"
1440                "  --"OPT_LCORES" COREMAP    Map lcore set to physical cpu set\n"
1441                "                      The argument format is\n"
1442                "                            '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
1443                "                      lcores and cpus list are grouped by '(' and ')'\n"
1444                "                      Within the group, '-' is used for range separator,\n"
1445                "                      ',' is used for single number separator.\n"
1446                "                      '( )' can be omitted for single element group,\n"
1447                "                      '@' can be omitted if cpus and lcores have the same value\n"
1448                "  -s SERVICE COREMASK Hexadecimal bitmask of cores to be used as service cores\n"
1449                "  --"OPT_MASTER_LCORE" ID   Core ID that is used as master\n"
1450                "  --"OPT_MBUF_POOL_OPS_NAME" Pool ops name for mbuf to use\n"
1451                "  -n CHANNELS         Number of memory channels\n"
1452                "  -m MB               Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
1453                "  -r RANKS            Force number of memory ranks (don't detect)\n"
1454                "  -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
1455                "                      Prevent EAL from using this PCI device. The argument\n"
1456                "                      format is <domain:bus:devid.func>.\n"
1457                "  -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
1458                "                      Only use the specified PCI devices. The argument format\n"
1459                "                      is <[domain:]bus:devid.func>. This option can be present\n"
1460                "                      several times (once per device).\n"
1461                "                      [NOTE: PCI whitelist cannot be used with -b option]\n"
1462                "  --"OPT_VDEV"              Add a virtual device.\n"
1463                "                      The argument format is <driver><id>[,key=val,...]\n"
1464                "                      (ex: --vdev=net_pcap0,iface=eth2).\n"
1465                "  --"OPT_IOVA_MODE"   Set IOVA mode. 'pa' for IOVA_PA\n"
1466                "                      'va' for IOVA_VA\n"
1467                "  -d LIB.so|DIR       Add a driver or driver directory\n"
1468                "                      (can be used multiple times)\n"
1469                "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
1470                "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
1471                "  --"OPT_SYSLOG"            Set syslog facility\n"
1472                "  --"OPT_LOG_LEVEL"=<int>   Set global log level\n"
1473                "  --"OPT_LOG_LEVEL"=<type-match>:<int>\n"
1474                "                      Set specific log level\n"
1475                "  -v                  Display version information on startup\n"
1476                "  -h, --help          This help\n"
1477                "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
1478                "                      disable secondary process support\n"
1479                "\nEAL options for DEBUG use only:\n"
1480                "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
1481                "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
1482                "  --"OPT_NO_PCI"            Disable PCI\n"
1483                "  --"OPT_NO_HPET"           Disable HPET\n"
1484                "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
1485                "\n", RTE_MAX_LCORE);
1486 }