eal: add option to delete hugepage backing files
[dpdk.git] / lib / librte_eal / common / eal_common_options.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <string.h>
37 #include <syslog.h>
38 #include <ctype.h>
39 #include <limits.h>
40 #include <errno.h>
41 #include <getopt.h>
42
43 #include <rte_eal.h>
44 #include <rte_log.h>
45 #include <rte_lcore.h>
46 #include <rte_version.h>
47 #include <rte_devargs.h>
48 #include <rte_memcpy.h>
49
50 #include "eal_internal_cfg.h"
51 #include "eal_options.h"
52 #include "eal_filesystem.h"
53
54 #define BITS_PER_HEX 4
55
56 const char
57 eal_short_options[] =
58         "b:" /* pci-blacklist */
59         "c:" /* coremask */
60         "d:" /* driver */
61         "h"  /* help */
62         "l:" /* corelist */
63         "m:" /* memory size */
64         "n:" /* memory channels */
65         "r:" /* memory ranks */
66         "v"  /* version */
67         "w:" /* pci-whitelist */
68         ;
69
70 const struct option
71 eal_long_options[] = {
72         {OPT_BASE_VIRTADDR,     1, NULL, OPT_BASE_VIRTADDR_NUM    },
73         {OPT_CREATE_UIO_DEV,    0, NULL, OPT_CREATE_UIO_DEV_NUM   },
74         {OPT_FILE_PREFIX,       1, NULL, OPT_FILE_PREFIX_NUM      },
75         {OPT_HELP,              0, NULL, OPT_HELP_NUM             },
76         {OPT_HUGE_DIR,          1, NULL, OPT_HUGE_DIR_NUM         },
77         {OPT_HUGE_UNLINK,       0, NULL, OPT_HUGE_UNLINK_NUM      },
78         {OPT_LCORES,            1, NULL, OPT_LCORES_NUM           },
79         {OPT_LOG_LEVEL,         1, NULL, OPT_LOG_LEVEL_NUM        },
80         {OPT_MASTER_LCORE,      1, NULL, OPT_MASTER_LCORE_NUM     },
81         {OPT_NO_HPET,           0, NULL, OPT_NO_HPET_NUM          },
82         {OPT_NO_HUGE,           0, NULL, OPT_NO_HUGE_NUM          },
83         {OPT_NO_PCI,            0, NULL, OPT_NO_PCI_NUM           },
84         {OPT_NO_SHCONF,         0, NULL, OPT_NO_SHCONF_NUM        },
85         {OPT_PCI_BLACKLIST,     1, NULL, OPT_PCI_BLACKLIST_NUM    },
86         {OPT_PCI_WHITELIST,     1, NULL, OPT_PCI_WHITELIST_NUM    },
87         {OPT_PROC_TYPE,         1, NULL, OPT_PROC_TYPE_NUM        },
88         {OPT_SOCKET_MEM,        1, NULL, OPT_SOCKET_MEM_NUM       },
89         {OPT_SYSLOG,            1, NULL, OPT_SYSLOG_NUM           },
90         {OPT_VDEV,              1, NULL, OPT_VDEV_NUM             },
91         {OPT_VFIO_INTR,         1, NULL, OPT_VFIO_INTR_NUM        },
92         {OPT_VMWARE_TSC_MAP,    0, NULL, OPT_VMWARE_TSC_MAP_NUM   },
93         {OPT_XEN_DOM0,          0, NULL, OPT_XEN_DOM0_NUM         },
94         {0,                     0, NULL, 0                        }
95 };
96
97 static int master_lcore_parsed;
98 static int mem_parsed;
99
100 void
101 eal_reset_internal_config(struct internal_config *internal_cfg)
102 {
103         int i;
104
105         internal_cfg->memory = 0;
106         internal_cfg->force_nrank = 0;
107         internal_cfg->force_nchannel = 0;
108         internal_cfg->hugefile_prefix = HUGEFILE_PREFIX_DEFAULT;
109         internal_cfg->hugepage_dir = NULL;
110         internal_cfg->force_sockets = 0;
111         /* zero out the NUMA config */
112         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
113                 internal_cfg->socket_mem[i] = 0;
114         /* zero out hugedir descriptors */
115         for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
116                 internal_cfg->hugepage_info[i].lock_descriptor = -1;
117         internal_cfg->base_virtaddr = 0;
118
119         internal_cfg->syslog_facility = LOG_DAEMON;
120         /* default value from build option */
121         internal_cfg->log_level = RTE_LOG_LEVEL;
122
123         internal_cfg->xen_dom0_support = 0;
124
125         /* if set to NONE, interrupt mode is determined automatically */
126         internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
127
128 #ifdef RTE_LIBEAL_USE_HPET
129         internal_cfg->no_hpet = 0;
130 #else
131         internal_cfg->no_hpet = 1;
132 #endif
133         internal_cfg->vmware_tsc_map = 0;
134         internal_cfg->create_uio_dev = 0;
135 }
136
137 /*
138  * Parse the coremask given as argument (hexadecimal string) and fill
139  * the global configuration (core role and core count) with the parsed
140  * value.
141  */
142 static int xdigit2val(unsigned char c)
143 {
144         int val;
145
146         if (isdigit(c))
147                 val = c - '0';
148         else if (isupper(c))
149                 val = c - 'A' + 10;
150         else
151                 val = c - 'a' + 10;
152         return val;
153 }
154
155 static int
156 eal_parse_coremask(const char *coremask)
157 {
158         struct rte_config *cfg = rte_eal_get_configuration();
159         int i, j, idx = 0;
160         unsigned count = 0;
161         char c;
162         int val;
163
164         if (coremask == NULL)
165                 return -1;
166         /* Remove all blank characters ahead and after .
167          * Remove 0x/0X if exists.
168          */
169         while (isblank(*coremask))
170                 coremask++;
171         if (coremask[0] == '0' && ((coremask[1] == 'x')
172                 || (coremask[1] == 'X')))
173                 coremask += 2;
174         i = strlen(coremask);
175         while ((i > 0) && isblank(coremask[i - 1]))
176                 i--;
177         if (i == 0)
178                 return -1;
179
180         for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
181                 c = coremask[i];
182                 if (isxdigit(c) == 0) {
183                         /* invalid characters */
184                         return -1;
185                 }
186                 val = xdigit2val(c);
187                 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
188                 {
189                         if ((1 << j) & val) {
190                                 if (!lcore_config[idx].detected) {
191                                         RTE_LOG(ERR, EAL, "lcore %u "
192                                                 "unavailable\n", idx);
193                                         return -1;
194                                 }
195                                 cfg->lcore_role[idx] = ROLE_RTE;
196                                 lcore_config[idx].core_index = count;
197                                 count++;
198                         } else {
199                                 cfg->lcore_role[idx] = ROLE_OFF;
200                                 lcore_config[idx].core_index = -1;
201                         }
202                 }
203         }
204         for (; i >= 0; i--)
205                 if (coremask[i] != '0')
206                         return -1;
207         for (; idx < RTE_MAX_LCORE; idx++) {
208                 cfg->lcore_role[idx] = ROLE_OFF;
209                 lcore_config[idx].core_index = -1;
210         }
211         if (count == 0)
212                 return -1;
213         /* Update the count of enabled logical cores of the EAL configuration */
214         cfg->lcore_count = count;
215         return 0;
216 }
217
218 static int
219 eal_parse_corelist(const char *corelist)
220 {
221         struct rte_config *cfg = rte_eal_get_configuration();
222         int i, idx = 0;
223         unsigned count = 0;
224         char *end = NULL;
225         int min, max;
226
227         if (corelist == NULL)
228                 return -1;
229
230         /* Remove all blank characters ahead and after */
231         while (isblank(*corelist))
232                 corelist++;
233         i = strlen(corelist);
234         while ((i > 0) && isblank(corelist[i - 1]))
235                 i--;
236
237         /* Reset config */
238         for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
239                 cfg->lcore_role[idx] = ROLE_OFF;
240                 lcore_config[idx].core_index = -1;
241         }
242
243         /* Get list of cores */
244         min = RTE_MAX_LCORE;
245         do {
246                 while (isblank(*corelist))
247                         corelist++;
248                 if (*corelist == '\0')
249                         return -1;
250                 errno = 0;
251                 idx = strtoul(corelist, &end, 10);
252                 if (errno || end == NULL)
253                         return -1;
254                 while (isblank(*end))
255                         end++;
256                 if (*end == '-') {
257                         min = idx;
258                 } else if ((*end == ',') || (*end == '\0')) {
259                         max = idx;
260                         if (min == RTE_MAX_LCORE)
261                                 min = idx;
262                         for (idx = min; idx <= max; idx++) {
263                                 if (cfg->lcore_role[idx] != ROLE_RTE) {
264                                         cfg->lcore_role[idx] = ROLE_RTE;
265                                         lcore_config[idx].core_index = count;
266                                         count++;
267                                 }
268                         }
269                         min = RTE_MAX_LCORE;
270                 } else
271                         return -1;
272                 corelist = end + 1;
273         } while (*end != '\0');
274
275         if (count == 0)
276                 return -1;
277
278         /* Update the count of enabled logical cores of the EAL configuration */
279         cfg->lcore_count = count;
280
281         return 0;
282 }
283
284 /* Changes the lcore id of the master thread */
285 static int
286 eal_parse_master_lcore(const char *arg)
287 {
288         char *parsing_end;
289         struct rte_config *cfg = rte_eal_get_configuration();
290
291         errno = 0;
292         cfg->master_lcore = (uint32_t) strtol(arg, &parsing_end, 0);
293         if (errno || parsing_end[0] != 0)
294                 return -1;
295         if (cfg->master_lcore >= RTE_MAX_LCORE)
296                 return -1;
297         master_lcore_parsed = 1;
298         return 0;
299 }
300
301 /*
302  * Parse elem, the elem could be single number/range or '(' ')' group
303  * 1) A single number elem, it's just a simple digit. e.g. 9
304  * 2) A single range elem, two digits with a '-' between. e.g. 2-6
305  * 3) A group elem, combines multiple 1) or 2) with '( )'. e.g (0,2-4,6)
306  *    Within group elem, '-' used for a range separator;
307  *                       ',' used for a single number.
308  */
309 static int
310 eal_parse_set(const char *input, uint16_t set[], unsigned num)
311 {
312         unsigned idx;
313         const char *str = input;
314         char *end = NULL;
315         unsigned min, max;
316
317         memset(set, 0, num * sizeof(uint16_t));
318
319         while (isblank(*str))
320                 str++;
321
322         /* only digit or left bracket is qualify for start point */
323         if ((!isdigit(*str) && *str != '(') || *str == '\0')
324                 return -1;
325
326         /* process single number or single range of number */
327         if (*str != '(') {
328                 errno = 0;
329                 idx = strtoul(str, &end, 10);
330                 if (errno || end == NULL || idx >= num)
331                         return -1;
332                 else {
333                         while (isblank(*end))
334                                 end++;
335
336                         min = idx;
337                         max = idx;
338                         if (*end == '-') {
339                                 /* process single <number>-<number> */
340                                 end++;
341                                 while (isblank(*end))
342                                         end++;
343                                 if (!isdigit(*end))
344                                         return -1;
345
346                                 errno = 0;
347                                 idx = strtoul(end, &end, 10);
348                                 if (errno || end == NULL || idx >= num)
349                                         return -1;
350                                 max = idx;
351                                 while (isblank(*end))
352                                         end++;
353                                 if (*end != ',' && *end != '\0')
354                                         return -1;
355                         }
356
357                         if (*end != ',' && *end != '\0' &&
358                             *end != '@')
359                                 return -1;
360
361                         for (idx = RTE_MIN(min, max);
362                              idx <= RTE_MAX(min, max); idx++)
363                                 set[idx] = 1;
364
365                         return end - input;
366                 }
367         }
368
369         /* process set within bracket */
370         str++;
371         while (isblank(*str))
372                 str++;
373         if (*str == '\0')
374                 return -1;
375
376         min = RTE_MAX_LCORE;
377         do {
378
379                 /* go ahead to the first digit */
380                 while (isblank(*str))
381                         str++;
382                 if (!isdigit(*str))
383                         return -1;
384
385                 /* get the digit value */
386                 errno = 0;
387                 idx = strtoul(str, &end, 10);
388                 if (errno || end == NULL || idx >= num)
389                         return -1;
390
391                 /* go ahead to separator '-',',' and ')' */
392                 while (isblank(*end))
393                         end++;
394                 if (*end == '-') {
395                         if (min == RTE_MAX_LCORE)
396                                 min = idx;
397                         else /* avoid continuous '-' */
398                                 return -1;
399                 } else if ((*end == ',') || (*end == ')')) {
400                         max = idx;
401                         if (min == RTE_MAX_LCORE)
402                                 min = idx;
403                         for (idx = RTE_MIN(min, max);
404                              idx <= RTE_MAX(min, max); idx++)
405                                 set[idx] = 1;
406
407                         min = RTE_MAX_LCORE;
408                 } else
409                         return -1;
410
411                 str = end + 1;
412         } while (*end != '\0' && *end != ')');
413
414         return str - input;
415 }
416
417 /* convert from set array to cpuset bitmap */
418 static int
419 convert_to_cpuset(rte_cpuset_t *cpusetp,
420               uint16_t *set, unsigned num)
421 {
422         unsigned idx;
423
424         CPU_ZERO(cpusetp);
425
426         for (idx = 0; idx < num; idx++) {
427                 if (!set[idx])
428                         continue;
429
430                 if (!lcore_config[idx].detected) {
431                         RTE_LOG(ERR, EAL, "core %u "
432                                 "unavailable\n", idx);
433                         return -1;
434                 }
435
436                 CPU_SET(idx, cpusetp);
437         }
438
439         return 0;
440 }
441
442 /*
443  * The format pattern: --lcores='<lcores[@cpus]>[<,lcores[@cpus]>...]'
444  * lcores, cpus could be a single digit/range or a group.
445  * '(' and ')' are necessary if it's a group.
446  * If not supply '@cpus', the value of cpus uses the same as lcores.
447  * e.g. '1,2@(5-7),(3-5)@(0,2),(0,6),7-8' means start 9 EAL thread as below
448  *   lcore 0 runs on cpuset 0x41 (cpu 0,6)
449  *   lcore 1 runs on cpuset 0x2 (cpu 1)
450  *   lcore 2 runs on cpuset 0xe0 (cpu 5,6,7)
451  *   lcore 3,4,5 runs on cpuset 0x5 (cpu 0,2)
452  *   lcore 6 runs on cpuset 0x41 (cpu 0,6)
453  *   lcore 7 runs on cpuset 0x80 (cpu 7)
454  *   lcore 8 runs on cpuset 0x100 (cpu 8)
455  */
456 static int
457 eal_parse_lcores(const char *lcores)
458 {
459         struct rte_config *cfg = rte_eal_get_configuration();
460         static uint16_t set[RTE_MAX_LCORE];
461         unsigned idx = 0;
462         int i;
463         unsigned count = 0;
464         const char *lcore_start = NULL;
465         const char *end = NULL;
466         int offset;
467         rte_cpuset_t cpuset;
468         int lflags = 0;
469         int ret = -1;
470
471         if (lcores == NULL)
472                 return -1;
473
474         /* Remove all blank characters ahead and after */
475         while (isblank(*lcores))
476                 lcores++;
477         i = strlen(lcores);
478         while ((i > 0) && isblank(lcores[i - 1]))
479                 i--;
480
481         CPU_ZERO(&cpuset);
482
483         /* Reset lcore config */
484         for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
485                 cfg->lcore_role[idx] = ROLE_OFF;
486                 lcore_config[idx].core_index = -1;
487                 CPU_ZERO(&lcore_config[idx].cpuset);
488         }
489
490         /* Get list of cores */
491         do {
492                 while (isblank(*lcores))
493                         lcores++;
494                 if (*lcores == '\0')
495                         goto err;
496
497                 /* record lcore_set start point */
498                 lcore_start = lcores;
499
500                 /* go across a complete bracket */
501                 if (*lcore_start == '(') {
502                         lcores += strcspn(lcores, ")");
503                         if (*lcores++ == '\0')
504                                 goto err;
505                 }
506
507                 /* scan the separator '@', ','(next) or '\0'(finish) */
508                 lcores += strcspn(lcores, "@,");
509
510                 if (*lcores == '@') {
511                         /* explicit assign cpu_set */
512                         offset = eal_parse_set(lcores + 1, set, RTE_DIM(set));
513                         if (offset < 0)
514                                 goto err;
515
516                         /* prepare cpu_set and update the end cursor */
517                         if (0 > convert_to_cpuset(&cpuset,
518                                                   set, RTE_DIM(set)))
519                                 goto err;
520                         end = lcores + 1 + offset;
521                 } else { /* ',' or '\0' */
522                         /* haven't given cpu_set, current loop done */
523                         end = lcores;
524
525                         /* go back to check <number>-<number> */
526                         offset = strcspn(lcore_start, "(-");
527                         if (offset < (end - lcore_start) &&
528                             *(lcore_start + offset) != '(')
529                                 lflags = 1;
530                 }
531
532                 if (*end != ',' && *end != '\0')
533                         goto err;
534
535                 /* parse lcore_set from start point */
536                 if (0 > eal_parse_set(lcore_start, set, RTE_DIM(set)))
537                         goto err;
538
539                 /* without '@', by default using lcore_set as cpu_set */
540                 if (*lcores != '@' &&
541                     0 > convert_to_cpuset(&cpuset, set, RTE_DIM(set)))
542                         goto err;
543
544                 /* start to update lcore_set */
545                 for (idx = 0; idx < RTE_MAX_LCORE; idx++) {
546                         if (!set[idx])
547                                 continue;
548
549                         if (cfg->lcore_role[idx] != ROLE_RTE) {
550                                 lcore_config[idx].core_index = count;
551                                 cfg->lcore_role[idx] = ROLE_RTE;
552                                 count++;
553                         }
554
555                         if (lflags) {
556                                 CPU_ZERO(&cpuset);
557                                 CPU_SET(idx, &cpuset);
558                         }
559                         rte_memcpy(&lcore_config[idx].cpuset, &cpuset,
560                                    sizeof(rte_cpuset_t));
561                 }
562
563                 lcores = end + 1;
564         } while (*end != '\0');
565
566         if (count == 0)
567                 goto err;
568
569         cfg->lcore_count = count;
570         ret = 0;
571
572 err:
573
574         return ret;
575 }
576
577 static int
578 eal_parse_syslog(const char *facility, struct internal_config *conf)
579 {
580         int i;
581         static struct {
582                 const char *name;
583                 int value;
584         } map[] = {
585                 { "auth", LOG_AUTH },
586                 { "cron", LOG_CRON },
587                 { "daemon", LOG_DAEMON },
588                 { "ftp", LOG_FTP },
589                 { "kern", LOG_KERN },
590                 { "lpr", LOG_LPR },
591                 { "mail", LOG_MAIL },
592                 { "news", LOG_NEWS },
593                 { "syslog", LOG_SYSLOG },
594                 { "user", LOG_USER },
595                 { "uucp", LOG_UUCP },
596                 { "local0", LOG_LOCAL0 },
597                 { "local1", LOG_LOCAL1 },
598                 { "local2", LOG_LOCAL2 },
599                 { "local3", LOG_LOCAL3 },
600                 { "local4", LOG_LOCAL4 },
601                 { "local5", LOG_LOCAL5 },
602                 { "local6", LOG_LOCAL6 },
603                 { "local7", LOG_LOCAL7 },
604                 { NULL, 0 }
605         };
606
607         for (i = 0; map[i].name; i++) {
608                 if (!strcmp(facility, map[i].name)) {
609                         conf->syslog_facility = map[i].value;
610                         return 0;
611                 }
612         }
613         return -1;
614 }
615
616 static int
617 eal_parse_log_level(const char *level, uint32_t *log_level)
618 {
619         char *end;
620         unsigned long tmp;
621
622         errno = 0;
623         tmp = strtoul(level, &end, 0);
624
625         /* check for errors */
626         if ((errno != 0) || (level[0] == '\0') ||
627             end == NULL || (*end != '\0'))
628                 return -1;
629
630         /* log_level is a uint32_t */
631         if (tmp >= UINT32_MAX)
632                 return -1;
633
634         *log_level = tmp;
635         return 0;
636 }
637
638 static enum rte_proc_type_t
639 eal_parse_proc_type(const char *arg)
640 {
641         if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
642                 return RTE_PROC_PRIMARY;
643         if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
644                 return RTE_PROC_SECONDARY;
645         if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
646                 return RTE_PROC_AUTO;
647
648         return RTE_PROC_INVALID;
649 }
650
651 int
652 eal_parse_common_option(int opt, const char *optarg,
653                         struct internal_config *conf)
654 {
655         switch (opt) {
656         /* blacklist */
657         case 'b':
658                 if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI,
659                                 optarg) < 0) {
660                         return -1;
661                 }
662                 break;
663         /* whitelist */
664         case 'w':
665                 if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI,
666                                 optarg) < 0) {
667                         return -1;
668                 }
669                 break;
670         /* coremask */
671         case 'c':
672                 if (eal_parse_coremask(optarg) < 0) {
673                         RTE_LOG(ERR, EAL, "invalid coremask\n");
674                         return -1;
675                 }
676                 break;
677         /* corelist */
678         case 'l':
679                 if (eal_parse_corelist(optarg) < 0) {
680                         RTE_LOG(ERR, EAL, "invalid core list\n");
681                         return -1;
682                 }
683                 break;
684         /* size of memory */
685         case 'm':
686                 conf->memory = atoi(optarg);
687                 conf->memory *= 1024ULL;
688                 conf->memory *= 1024ULL;
689                 mem_parsed = 1;
690                 break;
691         /* force number of channels */
692         case 'n':
693                 conf->force_nchannel = atoi(optarg);
694                 if (conf->force_nchannel == 0 ||
695                     conf->force_nchannel > 4) {
696                         RTE_LOG(ERR, EAL, "invalid channel number\n");
697                         return -1;
698                 }
699                 break;
700         /* force number of ranks */
701         case 'r':
702                 conf->force_nrank = atoi(optarg);
703                 if (conf->force_nrank == 0 ||
704                     conf->force_nrank > 16) {
705                         RTE_LOG(ERR, EAL, "invalid rank number\n");
706                         return -1;
707                 }
708                 break;
709         case 'v':
710                 /* since message is explicitly requested by user, we
711                  * write message at highest log level so it can always
712                  * be seen
713                  * even if info or warning messages are disabled */
714                 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
715                 break;
716
717         /* long options */
718         case OPT_HUGE_UNLINK_NUM:
719                 conf->hugepage_unlink = 1;
720                 break;
721
722         case OPT_NO_HUGE_NUM:
723                 conf->no_hugetlbfs = 1;
724                 break;
725
726         case OPT_NO_PCI_NUM:
727                 conf->no_pci = 1;
728                 break;
729
730         case OPT_NO_HPET_NUM:
731                 conf->no_hpet = 1;
732                 break;
733
734         case OPT_VMWARE_TSC_MAP_NUM:
735                 conf->vmware_tsc_map = 1;
736                 break;
737
738         case OPT_NO_SHCONF_NUM:
739                 conf->no_shconf = 1;
740                 break;
741
742         case OPT_PROC_TYPE_NUM:
743                 conf->process_type = eal_parse_proc_type(optarg);
744                 break;
745
746         case OPT_MASTER_LCORE_NUM:
747                 if (eal_parse_master_lcore(optarg) < 0) {
748                         RTE_LOG(ERR, EAL, "invalid parameter for --"
749                                         OPT_MASTER_LCORE "\n");
750                         return -1;
751                 }
752                 break;
753
754         case OPT_VDEV_NUM:
755                 if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL,
756                                 optarg) < 0) {
757                         return -1;
758                 }
759                 break;
760
761         case OPT_SYSLOG_NUM:
762                 if (eal_parse_syslog(optarg, conf) < 0) {
763                         RTE_LOG(ERR, EAL, "invalid parameters for --"
764                                         OPT_SYSLOG "\n");
765                         return -1;
766                 }
767                 break;
768
769         case OPT_LOG_LEVEL_NUM: {
770                 uint32_t log;
771
772                 if (eal_parse_log_level(optarg, &log) < 0) {
773                         RTE_LOG(ERR, EAL,
774                                 "invalid parameters for --"
775                                 OPT_LOG_LEVEL "\n");
776                         return -1;
777                 }
778                 conf->log_level = log;
779                 break;
780         }
781         case OPT_LCORES_NUM:
782                 if (eal_parse_lcores(optarg) < 0) {
783                         RTE_LOG(ERR, EAL, "invalid parameter for --"
784                                 OPT_LCORES "\n");
785                         return -1;
786                 }
787                 break;
788
789         /* don't know what to do, leave this to caller */
790         default:
791                 return 1;
792
793         }
794
795         return 0;
796 }
797
798 int
799 eal_adjust_config(struct internal_config *internal_cfg)
800 {
801         int i;
802         struct rte_config *cfg = rte_eal_get_configuration();
803
804         if (internal_config.process_type == RTE_PROC_AUTO)
805                 internal_config.process_type = eal_proc_type_detect();
806
807         /* default master lcore is the first one */
808         if (!master_lcore_parsed)
809                 cfg->master_lcore = rte_get_next_lcore(-1, 0, 0);
810
811         /* if no memory amounts were requested, this will result in 0 and
812          * will be overridden later, right after eal_hugepage_info_init() */
813         for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
814                 internal_cfg->memory += internal_cfg->socket_mem[i];
815
816         return 0;
817 }
818
819 int
820 eal_check_common_options(struct internal_config *internal_cfg)
821 {
822         struct rte_config *cfg = rte_eal_get_configuration();
823
824         if (cfg->lcore_role[cfg->master_lcore] != ROLE_RTE) {
825                 RTE_LOG(ERR, EAL, "Master lcore is not enabled for DPDK\n");
826                 return -1;
827         }
828
829         if (internal_cfg->process_type == RTE_PROC_INVALID) {
830                 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
831                 return -1;
832         }
833         if (index(internal_cfg->hugefile_prefix, '%') != NULL) {
834                 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
835                         "option\n");
836                 return -1;
837         }
838         if (mem_parsed && internal_cfg->force_sockets == 1) {
839                 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
840                         "be specified at the same time\n");
841                 return -1;
842         }
843         if (internal_cfg->no_hugetlbfs && internal_cfg->force_sockets == 1) {
844                 RTE_LOG(ERR, EAL, "Option --"OPT_SOCKET_MEM" cannot "
845                         "be specified together with --"OPT_NO_HUGE"\n");
846                 return -1;
847         }
848
849         if (internal_cfg->no_hugetlbfs && internal_cfg->hugepage_unlink) {
850                 RTE_LOG(ERR, EAL, "Option --"OPT_HUGE_UNLINK" cannot "
851                         "be specified together with --"OPT_NO_HUGE"\n");
852                 return -1;
853         }
854
855         if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 &&
856                 rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) {
857                 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
858                         "cannot be used at the same time\n");
859                 return -1;
860         }
861
862         return 0;
863 }
864
865 void
866 eal_common_usage(void)
867 {
868         printf("[options]\n\n"
869                "EAL common options:\n"
870                "  -c COREMASK         Hexadecimal bitmask of cores to run on\n"
871                "  -l CORELIST         List of cores to run on\n"
872                "                      The argument format is <c1>[-c2][,c3[-c4],...]\n"
873                "                      where c1, c2, etc are core indexes between 0 and %d\n"
874                "  --"OPT_LCORES" COREMAP    Map lcore set to physical cpu set\n"
875                "                      The argument format is\n"
876                "                            '<lcores[@cpus]>[<,lcores[@cpus]>...]'\n"
877                "                      lcores and cpus list are grouped by '(' and ')'\n"
878                "                      Within the group, '-' is used for range separator,\n"
879                "                      ',' is used for single number separator.\n"
880                "                      '( )' can be omitted for single element group,\n"
881                "                      '@' can be omitted if cpus and lcores have the same value\n"
882                "  --"OPT_MASTER_LCORE" ID   Core ID that is used as master\n"
883                "  -n CHANNELS         Number of memory channels\n"
884                "  -m MB               Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
885                "  -r RANKS            Force number of memory ranks (don't detect)\n"
886                "  -b, --"OPT_PCI_BLACKLIST" Add a PCI device in black list.\n"
887                "                      Prevent EAL from using this PCI device. The argument\n"
888                "                      format is <domain:bus:devid.func>.\n"
889                "  -w, --"OPT_PCI_WHITELIST" Add a PCI device in white list.\n"
890                "                      Only use the specified PCI devices. The argument format\n"
891                "                      is <[domain:]bus:devid.func>. This option can be present\n"
892                "                      several times (once per device).\n"
893                "                      [NOTE: PCI whitelist cannot be used with -b option]\n"
894                "  --"OPT_VDEV"              Add a virtual device.\n"
895                "                      The argument format is <driver><id>[,key=val,...]\n"
896                "                      (ex: --vdev=eth_pcap0,iface=eth2).\n"
897                "  --"OPT_VMWARE_TSC_MAP"    Use VMware TSC map instead of native RDTSC\n"
898                "  --"OPT_PROC_TYPE"         Type of this process (primary|secondary|auto)\n"
899                "  --"OPT_SYSLOG"            Set syslog facility\n"
900                "  --"OPT_LOG_LEVEL"         Set default log level\n"
901                "  -v                  Display version information on startup\n"
902                "  -h, --help          This help\n"
903                "\nEAL options for DEBUG use only:\n"
904                "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
905                "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"
906                "  --"OPT_NO_PCI"            Disable PCI\n"
907                "  --"OPT_NO_HPET"           Disable HPET\n"
908                "  --"OPT_NO_SHCONF"         No shared config (mmap'd files)\n"
909                "\n", RTE_MAX_LCORE);
910 }