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