4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2014 6WIND S.A.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
45 #include <rte_lcore.h>
46 #include <rte_version.h>
47 #include <rte_devargs.h>
49 #include "eal_internal_cfg.h"
50 #include "eal_options.h"
51 #include "eal_filesystem.h"
53 #define BITS_PER_HEX 4
57 "b:" /* pci-blacklist */
58 "w:" /* pci-whitelist */
68 eal_long_options[] = {
69 {OPT_HUGE_DIR, 1, 0, OPT_HUGE_DIR_NUM},
70 {OPT_PROC_TYPE, 1, 0, OPT_PROC_TYPE_NUM},
71 {OPT_NO_SHCONF, 0, 0, OPT_NO_SHCONF_NUM},
72 {OPT_NO_HPET, 0, 0, OPT_NO_HPET_NUM},
73 {OPT_VMWARE_TSC_MAP, 0, 0, OPT_VMWARE_TSC_MAP_NUM},
74 {OPT_NO_PCI, 0, 0, OPT_NO_PCI_NUM},
75 {OPT_NO_HUGE, 0, 0, OPT_NO_HUGE_NUM},
76 {OPT_FILE_PREFIX, 1, 0, OPT_FILE_PREFIX_NUM},
77 {OPT_SOCKET_MEM, 1, 0, OPT_SOCKET_MEM_NUM},
78 {OPT_PCI_WHITELIST, 1, 0, OPT_PCI_WHITELIST_NUM},
79 {OPT_PCI_BLACKLIST, 1, 0, OPT_PCI_BLACKLIST_NUM},
80 {OPT_VDEV, 1, 0, OPT_VDEV_NUM},
81 {OPT_SYSLOG, 1, NULL, OPT_SYSLOG_NUM},
82 {OPT_LOG_LEVEL, 1, NULL, OPT_LOG_LEVEL_NUM},
83 {OPT_BASE_VIRTADDR, 1, 0, OPT_BASE_VIRTADDR_NUM},
84 {OPT_XEN_DOM0, 0, 0, OPT_XEN_DOM0_NUM},
85 {OPT_CREATE_UIO_DEV, 1, NULL, OPT_CREATE_UIO_DEV_NUM},
86 {OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM},
90 static int lcores_parsed;
91 static int mem_parsed;
94 eal_reset_internal_config(struct internal_config *internal_cfg)
98 internal_cfg->memory = 0;
99 internal_cfg->force_nrank = 0;
100 internal_cfg->force_nchannel = 0;
101 internal_cfg->hugefile_prefix = HUGEFILE_PREFIX_DEFAULT;
102 internal_cfg->hugepage_dir = NULL;
103 internal_cfg->force_sockets = 0;
104 /* zero out the NUMA config */
105 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
106 internal_cfg->socket_mem[i] = 0;
107 /* zero out hugedir descriptors */
108 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
109 internal_cfg->hugepage_info[i].lock_descriptor = -1;
110 internal_cfg->base_virtaddr = 0;
112 internal_cfg->syslog_facility = LOG_DAEMON;
113 /* default value from build option */
114 internal_cfg->log_level = RTE_LOG_LEVEL;
116 internal_cfg->xen_dom0_support = 0;
118 /* if set to NONE, interrupt mode is determined automatically */
119 internal_cfg->vfio_intr_mode = RTE_INTR_MODE_NONE;
121 #ifdef RTE_LIBEAL_USE_HPET
122 internal_cfg->no_hpet = 0;
124 internal_cfg->no_hpet = 1;
126 internal_cfg->vmware_tsc_map = 0;
130 * Parse the coremask given as argument (hexadecimal string) and fill
131 * the global configuration (core role and core count) with the parsed
134 static int xdigit2val(unsigned char c)
148 eal_parse_coremask(const char *coremask)
150 struct rte_config *cfg = rte_eal_get_configuration();
156 if (coremask == NULL)
158 /* Remove all blank characters ahead and after .
159 * Remove 0x/0X if exists.
161 while (isblank(*coremask))
163 if (coremask[0] == '0' && ((coremask[1] == 'x')
164 || (coremask[1] == 'X')))
166 i = strnlen(coremask, PATH_MAX);
167 while ((i > 0) && isblank(coremask[i - 1]))
172 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
174 if (isxdigit(c) == 0) {
175 /* invalid characters */
179 for (j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++)
181 if ((1 << j) & val) {
182 if (!lcore_config[idx].detected) {
183 RTE_LOG(ERR, EAL, "lcore %u "
184 "unavailable\n", idx);
187 cfg->lcore_role[idx] = ROLE_RTE;
189 cfg->master_lcore = idx;
192 cfg->lcore_role[idx] = ROLE_OFF;
197 if (coremask[i] != '0')
199 for (; idx < RTE_MAX_LCORE; idx++)
200 cfg->lcore_role[idx] = ROLE_OFF;
203 /* Update the count of enabled logical cores of the EAL configuration */
204 cfg->lcore_count = count;
210 eal_parse_corelist(const char *corelist)
212 struct rte_config *cfg = rte_eal_get_configuration();
218 if (corelist == NULL)
221 /* Remove all blank characters ahead and after */
222 while (isblank(*corelist))
224 i = strnlen(corelist, sysconf(_SC_ARG_MAX));
225 while ((i > 0) && isblank(corelist[i - 1]))
228 /* Reset core roles */
229 for (idx = 0; idx < RTE_MAX_LCORE; idx++)
230 cfg->lcore_role[idx] = ROLE_OFF;
232 /* Get list of cores */
235 while (isblank(*corelist))
237 if (*corelist == '\0')
240 idx = strtoul(corelist, &end, 10);
241 if (errno || end == NULL)
243 while (isblank(*end))
247 } else if ((*end == ',') || (*end == '\0')) {
249 if (min == RTE_MAX_LCORE)
251 for (idx = min; idx <= max; idx++) {
252 cfg->lcore_role[idx] = ROLE_RTE;
254 cfg->master_lcore = idx;
261 } while (*end != '\0');
271 eal_parse_syslog(const char *facility, struct internal_config *conf)
278 { "auth", LOG_AUTH },
279 { "cron", LOG_CRON },
280 { "daemon", LOG_DAEMON },
282 { "kern", LOG_KERN },
284 { "mail", LOG_MAIL },
285 { "news", LOG_NEWS },
286 { "syslog", LOG_SYSLOG },
287 { "user", LOG_USER },
288 { "uucp", LOG_UUCP },
289 { "local0", LOG_LOCAL0 },
290 { "local1", LOG_LOCAL1 },
291 { "local2", LOG_LOCAL2 },
292 { "local3", LOG_LOCAL3 },
293 { "local4", LOG_LOCAL4 },
294 { "local5", LOG_LOCAL5 },
295 { "local6", LOG_LOCAL6 },
296 { "local7", LOG_LOCAL7 },
300 for (i = 0; map[i].name; i++) {
301 if (!strcmp(facility, map[i].name)) {
302 conf->syslog_facility = map[i].value;
310 eal_parse_log_level(const char *level, uint32_t *log_level)
316 tmp = strtoul(level, &end, 0);
318 /* check for errors */
319 if ((errno != 0) || (level[0] == '\0') ||
320 end == NULL || (*end != '\0'))
323 /* log_level is a uint32_t */
324 if (tmp >= UINT32_MAX)
331 static enum rte_proc_type_t
332 eal_parse_proc_type(const char *arg)
334 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
335 return RTE_PROC_PRIMARY;
336 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
337 return RTE_PROC_SECONDARY;
338 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
339 return RTE_PROC_AUTO;
341 return RTE_PROC_INVALID;
345 eal_parse_common_option(int opt, const char *optarg,
346 struct internal_config *conf)
351 if (rte_eal_devargs_add(RTE_DEVTYPE_BLACKLISTED_PCI,
358 if (rte_eal_devargs_add(RTE_DEVTYPE_WHITELISTED_PCI,
365 if (eal_parse_coremask(optarg) < 0) {
366 RTE_LOG(ERR, EAL, "invalid coremask\n");
372 if (eal_parse_corelist(optarg) < 0) {
373 RTE_LOG(ERR, EAL, "invalid core list\n");
379 conf->memory = atoi(optarg);
380 conf->memory *= 1024ULL;
381 conf->memory *= 1024ULL;
384 /* force number of channels */
386 conf->force_nchannel = atoi(optarg);
387 if (conf->force_nchannel == 0 ||
388 conf->force_nchannel > 4) {
389 RTE_LOG(ERR, EAL, "invalid channel number\n");
393 /* force number of ranks */
395 conf->force_nrank = atoi(optarg);
396 if (conf->force_nrank == 0 ||
397 conf->force_nrank > 16) {
398 RTE_LOG(ERR, EAL, "invalid rank number\n");
403 /* since message is explicitly requested by user, we
404 * write message at highest log level so it can always
406 * even if info or warning messages are disabled */
407 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
411 case OPT_NO_HUGE_NUM:
412 conf->no_hugetlbfs = 1;
419 case OPT_NO_HPET_NUM:
423 case OPT_VMWARE_TSC_MAP_NUM:
424 conf->vmware_tsc_map = 1;
427 case OPT_NO_SHCONF_NUM:
431 case OPT_PROC_TYPE_NUM:
432 conf->process_type = eal_parse_proc_type(optarg);
436 if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL,
443 if (eal_parse_syslog(optarg, conf) < 0) {
444 RTE_LOG(ERR, EAL, "invalid parameters for --"
450 case OPT_LOG_LEVEL_NUM: {
453 if (eal_parse_log_level(optarg, &log) < 0) {
455 "invalid parameters for --"
459 conf->log_level = log;
463 /* don't know what to do, leave this to caller */
473 eal_adjust_config(struct internal_config *internal_cfg)
477 if (internal_config.process_type == RTE_PROC_AUTO)
478 internal_config.process_type = eal_proc_type_detect();
480 /* if no memory amounts were requested, this will result in 0 and
481 * will be overridden later, right after eal_hugepage_info_init() */
482 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
483 internal_cfg->memory += internal_cfg->socket_mem[i];
489 eal_check_common_options(struct internal_config *internal_cfg)
491 struct rte_config *cfg = rte_eal_get_configuration();
493 if (!lcores_parsed) {
494 RTE_LOG(ERR, EAL, "CPU cores must be enabled with options "
499 if (internal_cfg->process_type == RTE_PROC_INVALID) {
500 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
503 if (internal_cfg->process_type == RTE_PROC_PRIMARY &&
504 internal_cfg->force_nchannel == 0) {
505 RTE_LOG(ERR, EAL, "Number of memory channels (-n) not "
509 if (index(internal_cfg->hugefile_prefix, '%') != NULL) {
510 RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
514 if (mem_parsed && internal_cfg->force_sockets == 1) {
515 RTE_LOG(ERR, EAL, "Options -m and --"OPT_SOCKET_MEM" cannot "
516 "be specified at the same time\n");
519 if (internal_cfg->no_hugetlbfs &&
520 (mem_parsed || internal_cfg->force_sockets == 1)) {
521 RTE_LOG(ERR, EAL, "Options -m or --"OPT_SOCKET_MEM" cannot "
522 "be specified together with --"OPT_NO_HUGE"\n");
526 if (rte_eal_devargs_type_count(RTE_DEVTYPE_WHITELISTED_PCI) != 0 &&
527 rte_eal_devargs_type_count(RTE_DEVTYPE_BLACKLISTED_PCI) != 0) {
528 RTE_LOG(ERR, EAL, "Options blacklist (-b) and whitelist (-w) "
529 "cannot be used at the same time\n");
537 eal_common_usage(void)
539 printf("-c COREMASK -n NUM [-m NB] [-r NUM] [-b <domain:bus:devid.func>]"
540 "[--proc-type primary|secondary|auto]\n\n"
541 "EAL common options:\n"
542 " -c COREMASK : A hexadecimal bitmask of cores to run on\n"
543 " -l CORELIST : List of cores to run on\n"
544 " The argument format is <c1>[-c2][,c3[-c4],...]\n"
545 " where c1, c2, etc are core indexes between 0 and %d\n"
546 " -n NUM : Number of memory channels\n"
547 " -v : Display version information on startup\n"
548 " -m MB : memory to allocate (see also --"OPT_SOCKET_MEM")\n"
549 " -r NUM : force number of memory ranks (don't detect)\n"
550 " --"OPT_SYSLOG" : set syslog facility\n"
551 " --"OPT_LOG_LEVEL" : set default log level\n"
552 " --"OPT_PROC_TYPE" : type of this process\n"
553 " --"OPT_PCI_BLACKLIST", -b: add a PCI device in black list.\n"
554 " Prevent EAL from using this PCI device. The argument\n"
555 " format is <domain:bus:devid.func>.\n"
556 " --"OPT_PCI_WHITELIST", -w: add a PCI device in white list.\n"
557 " Only use the specified PCI devices. The argument format\n"
558 " is <[domain:]bus:devid.func>. This option can be present\n"
559 " several times (once per device).\n"
560 " [NOTE: PCI whitelist cannot be used with -b option]\n"
561 " --"OPT_VDEV": add a virtual device.\n"
562 " The argument format is <driver><id>[,key=val,...]\n"
563 " (ex: --vdev=eth_pcap0,iface=eth2).\n"
564 " --"OPT_VMWARE_TSC_MAP": use VMware TSC map instead of native RDTSC\n"
565 "\nEAL options for DEBUG use only:\n"
566 " --"OPT_NO_HUGE" : use malloc instead of hugetlbfs\n"
567 " --"OPT_NO_PCI" : disable pci\n"
568 " --"OPT_NO_HPET" : disable hpet\n"
569 " --"OPT_NO_SHCONF": no shared config (mmap'd files)\n"
570 "\n", RTE_MAX_LCORE);