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