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