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