4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
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.
49 #include <sys/queue.h>
52 #include <linux/binfmts.h>
54 #include <rte_common.h>
55 #include <rte_debug.h>
56 #include <rte_memory.h>
57 #include <rte_memzone.h>
58 #include <rte_launch.h>
59 #include <rte_tailq.h>
61 #include <rte_eal_memconfig.h>
62 #include <rte_per_lcore.h>
63 #include <rte_lcore.h>
65 #include <rte_random.h>
66 #include <rte_cycles.h>
67 #include <rte_string_fns.h>
68 #include <rte_cpuflags.h>
69 #include <rte_interrupts.h>
71 #include <rte_common.h>
72 #include <rte_version.h>
73 #include <rte_atomic.h>
74 #include <malloc_heap.h>
75 #include <rte_eth_ring.h>
77 #include "eal_private.h"
78 #include "eal_thread.h"
79 #include "eal_internal_cfg.h"
80 #include "eal_filesystem.h"
81 #include "eal_hugepages.h"
83 #define OPT_HUGE_DIR "huge-dir"
84 #define OPT_PROC_TYPE "proc-type"
85 #define OPT_NO_SHCONF "no-shconf"
86 #define OPT_NO_HPET "no-hpet"
87 #define OPT_VMWARE_TSC_MAP "vmware-tsc-map"
88 #define OPT_NO_PCI "no-pci"
89 #define OPT_NO_HUGE "no-huge"
90 #define OPT_FILE_PREFIX "file-prefix"
91 #define OPT_SOCKET_MEM "socket-mem"
92 #define OPT_USE_DEVICE "use-device"
93 #define OPT_SYSLOG "syslog"
94 #define OPT_BASE_VIRTADDR "base-virtaddr"
96 #define RTE_EAL_BLACKLIST_SIZE 0x100
98 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
100 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
102 #define HIGHEST_RPL 3
104 #define BITS_PER_HEX 4
106 #define GET_BLACKLIST_FIELD(in, fd, lim, dlm) \
111 val = strtoul((in), &end, 16); \
112 if (errno != 0 || end[0] != (dlm) || val > (lim)) \
114 (fd) = (typeof (fd))val; \
118 /* Allow the application to print its usage message too if set */
119 static rte_usage_hook_t rte_application_usage_hook = NULL;
120 /* early configuration structure, when memory config is not mmapped */
121 static struct rte_mem_config early_mem_config;
123 /* define fd variable here, because file needs to be kept open for the
124 * duration of the program, as we hold a write lock on it in the primary proc */
125 static int mem_cfg_fd = -1;
127 static struct flock wr_lock = {
129 .l_whence = SEEK_SET,
130 .l_start = offsetof(struct rte_mem_config, memseg),
131 .l_len = sizeof(early_mem_config.memseg),
134 /* Address of global and public configuration */
135 static struct rte_config rte_config = {
136 .mem_config = &early_mem_config,
139 static struct rte_pci_addr eal_dev_blacklist[RTE_EAL_BLACKLIST_SIZE];
141 /* internal configuration (per-core) */
142 struct lcore_config lcore_config[RTE_MAX_LCORE];
144 /* internal configuration */
145 struct internal_config internal_config;
147 /* used by rte_rdtsc() */
148 int rte_cycles_vmware_tsc_map;
150 /* Return a pointer to the configuration structure */
152 rte_eal_get_configuration(void)
157 /* parse a sysfs (or other) file containing one integer value */
159 eal_parse_sysfs_value(const char *filename, unsigned long *val)
165 if ((f = fopen(filename, "r")) == NULL) {
166 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
171 if (fgets(buf, sizeof(buf), f) == NULL) {
172 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
177 *val = strtoul(buf, &end, 0);
178 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
179 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
189 /* create memory configuration in shared/mmap memory. Take out
190 * a write lock on the memsegs, so we can auto-detect primary/secondary.
191 * This means we never close the file while running (auto-close on exit).
192 * We also don't lock the whole file, so that in future we can use read-locks
193 * on other parts, e.g. memzones, to detect if there are running secondary
196 rte_eal_config_create(void)
198 void *rte_mem_cfg_addr;
201 const char *pathname = eal_runtime_config_path();
203 if (internal_config.no_shconf)
207 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
209 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
212 retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
215 rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
218 retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
221 rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
222 "process running?\n", pathname);
225 rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
226 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
228 if (rte_mem_cfg_addr == MAP_FAILED){
229 rte_panic("Cannot mmap memory for rte_config\n");
231 memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
232 rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
235 /* attach to an existing shared memory config */
237 rte_eal_config_attach(void)
239 void *rte_mem_cfg_addr;
240 const char *pathname = eal_runtime_config_path();
242 if (internal_config.no_shconf)
246 mem_cfg_fd = open(pathname, O_RDWR);
248 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
251 rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
252 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
254 if (rte_mem_cfg_addr == MAP_FAILED)
255 rte_panic("Cannot mmap memory for rte_config\n");
257 rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
260 /* Detect if we are a primary or a secondary process */
261 static enum rte_proc_type_t
262 eal_proc_type_detect(void)
264 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
265 const char *pathname = eal_runtime_config_path();
267 /* if we can open the file but not get a write-lock we are a secondary
268 * process. NOTE: if we get a file handle back, we keep that open
269 * and don't close it to prevent a race condition between multiple opens */
270 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
271 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
272 ptype = RTE_PROC_SECONDARY;
274 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
275 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
280 /* Sets up rte_config structure with the pointer to shared memory config.*/
282 rte_config_init(void)
284 /* set the magic in configuration structure */
285 rte_config.magic = RTE_MAGIC;
286 rte_config.process_type = (internal_config.process_type == RTE_PROC_AUTO) ?
287 eal_proc_type_detect() : /* for auto, detect the type */
288 internal_config.process_type; /* otherwise use what's already set */
290 switch (rte_config.process_type){
291 case RTE_PROC_PRIMARY:
292 rte_eal_config_create();
294 case RTE_PROC_SECONDARY:
295 rte_eal_config_attach();
296 rte_eal_mcfg_wait_complete(rte_config.mem_config);
299 case RTE_PROC_INVALID:
300 rte_panic("Invalid process type\n");
304 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
306 eal_hugedirs_unlock(void)
310 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
312 /* skip uninitialized */
313 if (internal_config.hugepage_info[i].lock_descriptor < 0)
315 /* unlock hugepage file */
316 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
317 close(internal_config.hugepage_info[i].lock_descriptor);
318 /* reset the field */
319 internal_config.hugepage_info[i].lock_descriptor = -1;
325 eal_usage(const char *prgname)
327 printf("\nUsage: %s -c COREMASK -n NUM [-m NB] [-r NUM] [-b <domain:bus:devid.func>]"
328 "[--proc-type primary|secondary|auto] \n\n"
330 " -c COREMASK : A hexadecimal bitmask of cores to run on\n"
331 " -n NUM : Number of memory channels\n"
332 " -v : Display version information on startup\n"
333 " -b <domain:bus:devid.func>: to prevent EAL from using specified "
335 " (multiple -b options are allowed)\n"
336 " -m MB : memory to allocate (see also --"OPT_SOCKET_MEM")\n"
337 " -r NUM : force number of memory ranks (don't detect)\n"
338 " --"OPT_SYSLOG" : set syslog facility\n"
339 " --"OPT_SOCKET_MEM" : memory to allocate on specific \n"
340 " sockets (use comma separated values)\n"
341 " --"OPT_HUGE_DIR" : directory where hugetlbfs is mounted\n"
342 " --"OPT_PROC_TYPE" : type of this process\n"
343 " --"OPT_FILE_PREFIX": prefix for hugepage filenames\n"
344 " --"OPT_USE_DEVICE": use the specified ethernet device(s) only. "
345 "Use comma-separate <[domain:]bus:devid.func> values.\n"
346 " [NOTE: Cannot be used with -b option]\n"
347 " --"OPT_VMWARE_TSC_MAP": use VMware TSC map instead of "
349 " --"OPT_BASE_VIRTADDR": specify base virtual address\n"
350 "\nEAL options for DEBUG use only:\n"
351 " --"OPT_NO_HUGE" : use malloc instead of hugetlbfs\n"
352 " --"OPT_NO_PCI" : disable pci\n"
353 " --"OPT_NO_HPET" : disable hpet\n"
354 " --"OPT_NO_SHCONF": no shared config (mmap'd files)\n"
357 /* Allow the application to print its usage message too if hook is set */
358 if ( rte_application_usage_hook ) {
359 printf("===== Application Usage =====\n\n");
360 rte_application_usage_hook(prgname);
364 /* Set a per-application usage message */
366 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
368 rte_usage_hook_t old_func;
370 /* Will be NULL on the first call to denote the last usage routine. */
371 old_func = rte_application_usage_hook;
372 rte_application_usage_hook = usage_func;
378 * Parse the coremask given as argument (hexadecimal string) and fill
379 * the global configuration (core role and core count) with the parsed
382 static int xdigit2val(unsigned char c)
394 eal_parse_coremask(const char *coremask)
396 struct rte_config *cfg = rte_eal_get_configuration();
402 if (coremask == NULL)
404 /* Remove all blank characters ahead and after .
405 * Remove 0x/0X if exists.
407 while (isblank(*coremask))
409 if (coremask[0] == '0' && ((coremask[1] == 'x')
410 || (coremask[1] == 'X')) )
412 i = strnlen(coremask, MAX_ARG_STRLEN);
413 while ((i > 0) && isblank(coremask[i - 1]))
418 for (i = i - 1; i >= 0 && idx < RTE_MAX_LCORE; i--) {
420 if (isxdigit(c) == 0) {
421 /* invalid characters */
425 for(j = 0; j < BITS_PER_HEX && idx < RTE_MAX_LCORE; j++, idx++) {
427 cfg->lcore_role[idx] = ROLE_RTE;
429 cfg->master_lcore = idx;
432 cfg->lcore_role[idx] = ROLE_OFF;
437 if(coremask[i] != '0')
439 for(; idx < RTE_MAX_LCORE; idx++)
440 cfg->lcore_role[idx] = ROLE_OFF;
447 eal_parse_syslog(const char *facility)
454 { "auth", LOG_AUTH },
455 { "cron", LOG_CRON },
456 { "daemon", LOG_DAEMON },
458 { "kern", LOG_KERN },
460 { "mail", LOG_MAIL },
461 { "news", LOG_NEWS },
462 { "syslog", LOG_SYSLOG },
463 { "user", LOG_USER },
464 { "uucp", LOG_UUCP },
465 { "local0", LOG_LOCAL0 },
466 { "local1", LOG_LOCAL1 },
467 { "local2", LOG_LOCAL2 },
468 { "local3", LOG_LOCAL3 },
469 { "local4", LOG_LOCAL4 },
470 { "local5", LOG_LOCAL5 },
471 { "local6", LOG_LOCAL6 },
472 { "local7", LOG_LOCAL7 },
476 for (i = 0; map[i].name; i++) {
477 if (!strcmp(facility, map[i].name)) {
478 internal_config.syslog_facility = map[i].value;
486 eal_parse_socket_mem(char *socket_mem)
488 char * arg[RTE_MAX_NUMA_NODES];
491 uint64_t total_mem = 0;
493 len = strnlen(socket_mem, SOCKET_MEM_STRLEN);
494 if (len == SOCKET_MEM_STRLEN) {
495 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
499 /* all other error cases will be caught later */
500 if (!isdigit(socket_mem[len-1]))
503 /* split the optarg into separate socket values */
504 arg_num = rte_strsplit(socket_mem, len,
505 arg, RTE_MAX_NUMA_NODES, ',');
507 /* if split failed, or 0 arguments */
511 internal_config.force_sockets = 1;
513 /* parse each defined socket option */
515 for (i = 0; i < arg_num; i++) {
517 internal_config.socket_mem[i] = strtoull(arg[i], &end, 10);
519 /* check for invalid input */
521 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
523 internal_config.socket_mem[i] *= 1024ULL;
524 internal_config.socket_mem[i] *= 1024ULL;
525 total_mem += internal_config.socket_mem[i];
528 /* check if we have a positive amount of total memory */
536 eal_parse_base_virtaddr(const char *arg)
541 addr = strtoull(arg, &end, 16);
543 /* check for errors */
544 if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
547 /* make sure we don't exceed 32-bit boundary on 32-bit target */
548 #ifndef RTE_ARCH_X86_64
549 if (addr >= UINTPTR_MAX)
553 /* align the addr on 2M boundary */
554 addr = RTE_PTR_ALIGN_CEIL(addr, RTE_PGSIZE_2M);
556 internal_config.base_virtaddr = (uintptr_t) addr;
561 eal_get_hugepage_mem_size(void)
566 for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
567 struct hugepage_info *hpi = &internal_config.hugepage_info[i];
568 if (hpi->hugedir != NULL) {
569 for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
570 size += hpi->hugepage_sz * hpi->num_pages[j];
575 return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
578 static enum rte_proc_type_t
579 eal_parse_proc_type(const char *arg)
581 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
582 return RTE_PROC_PRIMARY;
583 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
584 return RTE_PROC_SECONDARY;
585 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
586 return RTE_PROC_AUTO;
588 return RTE_PROC_INVALID;
592 eal_parse_blacklist_opt(const char *optarg, size_t idx)
594 if (idx >= sizeof (eal_dev_blacklist) / sizeof (eal_dev_blacklist[0])) {
595 RTE_LOG(ERR, EAL, "%s - too many devices to blacklist...\n", optarg);
597 } else if (eal_parse_pci_DomBDF(optarg, eal_dev_blacklist + idx) < 0 &&
598 eal_parse_pci_BDF(optarg, eal_dev_blacklist + idx) < 0) {
599 RTE_LOG(ERR, EAL, "%s - invalid device to blacklist...\n", optarg);
607 /* Parse the argument given in the command line of the application */
609 eal_parse_args(int argc, char **argv)
615 ssize_t blacklist_index = 0;
616 char *prgname = argv[0];
617 static struct option lgopts[] = {
618 {OPT_NO_HUGE, 0, 0, 0},
619 {OPT_NO_PCI, 0, 0, 0},
620 {OPT_NO_HPET, 0, 0, 0},
621 {OPT_VMWARE_TSC_MAP, 0, 0, 0},
622 {OPT_HUGE_DIR, 1, 0, 0},
623 {OPT_NO_SHCONF, 0, 0, 0},
624 {OPT_PROC_TYPE, 1, 0, 0},
625 {OPT_FILE_PREFIX, 1, 0, 0},
626 {OPT_SOCKET_MEM, 1, 0, 0},
627 {OPT_USE_DEVICE, 1, 0, 0},
628 {OPT_SYSLOG, 1, NULL, 0},
629 {OPT_BASE_VIRTADDR, 1, 0, 0},
635 internal_config.memory = 0;
636 internal_config.force_nrank = 0;
637 internal_config.force_nchannel = 0;
638 internal_config.hugefile_prefix = HUGEFILE_PREFIX_DEFAULT;
639 internal_config.hugepage_dir = NULL;
640 internal_config.force_sockets = 0;
641 internal_config.syslog_facility = LOG_DAEMON;
642 #ifdef RTE_LIBEAL_USE_HPET
643 internal_config.no_hpet = 0;
645 internal_config.no_hpet = 1;
647 /* zero out the NUMA config */
648 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
649 internal_config.socket_mem[i] = 0;
651 /* zero out hugedir descriptors */
652 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
653 internal_config.hugepage_info[i].lock_descriptor = -1;
655 internal_config.vmware_tsc_map = 0;
656 internal_config.base_virtaddr = 0;
658 while ((opt = getopt_long(argc, argvopt, "b:c:m:n:r:v",
659 lgopts, &option_index)) != EOF) {
664 if ((blacklist_index = eal_parse_blacklist_opt(optarg,
665 blacklist_index)) < 0) {
672 if (eal_parse_coremask(optarg) < 0) {
673 RTE_LOG(ERR, EAL, "invalid coremask\n");
681 internal_config.memory = atoi(optarg);
682 internal_config.memory *= 1024ULL;
683 internal_config.memory *= 1024ULL;
685 /* force number of channels */
687 internal_config.force_nchannel = atoi(optarg);
688 if (internal_config.force_nchannel == 0 ||
689 internal_config.force_nchannel > 4) {
690 RTE_LOG(ERR, EAL, "invalid channel number\n");
695 /* force number of ranks */
697 internal_config.force_nrank = atoi(optarg);
698 if (internal_config.force_nrank == 0 ||
699 internal_config.force_nrank > 16) {
700 RTE_LOG(ERR, EAL, "invalid rank number\n");
706 /* since message is explicitly requested by user, we
707 * write message at highest log level so it can always be seen
708 * even if info or warning messages are disabled */
709 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
714 if (!strcmp(lgopts[option_index].name, OPT_NO_HUGE)) {
715 internal_config.no_hugetlbfs = 1;
717 else if (!strcmp(lgopts[option_index].name, OPT_NO_PCI)) {
718 internal_config.no_pci = 1;
720 else if (!strcmp(lgopts[option_index].name, OPT_NO_HPET)) {
721 internal_config.no_hpet = 1;
723 else if (!strcmp(lgopts[option_index].name, OPT_VMWARE_TSC_MAP)) {
724 internal_config.vmware_tsc_map = 1;
726 else if (!strcmp(lgopts[option_index].name, OPT_NO_SHCONF)) {
727 internal_config.no_shconf = 1;
729 else if (!strcmp(lgopts[option_index].name, OPT_HUGE_DIR)) {
730 internal_config.hugepage_dir = optarg;
732 else if (!strcmp(lgopts[option_index].name, OPT_PROC_TYPE)) {
733 internal_config.process_type = eal_parse_proc_type(optarg);
735 else if (!strcmp(lgopts[option_index].name, OPT_FILE_PREFIX)) {
736 internal_config.hugefile_prefix = optarg;
738 else if (!strcmp(lgopts[option_index].name, OPT_SOCKET_MEM)) {
739 if (eal_parse_socket_mem(optarg) < 0) {
740 RTE_LOG(ERR, EAL, "invalid parameters for --"
741 OPT_SOCKET_MEM "\n");
746 else if (!strcmp(lgopts[option_index].name, OPT_USE_DEVICE)) {
747 eal_dev_whitelist_add_entry(optarg);
749 else if (!strcmp(lgopts[option_index].name, OPT_SYSLOG)) {
750 if (eal_parse_syslog(optarg) < 0) {
751 RTE_LOG(ERR, EAL, "invalid parameters for --"
757 else if (!strcmp(lgopts[option_index].name, OPT_BASE_VIRTADDR)) {
758 if (eal_parse_base_virtaddr(optarg) < 0) {
759 RTE_LOG(ERR, EAL, "invalid parameter for --"
760 OPT_BASE_VIRTADDR "\n");
775 RTE_LOG(ERR, EAL, "coremask not specified\n");
779 if (internal_config.process_type == RTE_PROC_AUTO){
780 internal_config.process_type = eal_proc_type_detect();
782 if (internal_config.process_type == RTE_PROC_INVALID){
783 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
787 if (internal_config.process_type == RTE_PROC_PRIMARY &&
788 internal_config.force_nchannel == 0) {
789 RTE_LOG(ERR, EAL, "Number of memory channels (-n) not specified\n");
793 if (index(internal_config.hugefile_prefix,'%') != NULL){
794 RTE_LOG(ERR, EAL, "Invalid char, '%%', in '"OPT_FILE_PREFIX"' option\n");
798 if (internal_config.memory > 0 && internal_config.force_sockets == 1) {
799 RTE_LOG(ERR, EAL, "Options -m and --socket-mem cannot be specified "
800 "at the same time\n");
804 /* --no-huge doesn't make sense with either -m or --socket-mem */
805 if (internal_config.no_hugetlbfs &&
806 (internal_config.memory > 0 ||
807 internal_config.force_sockets == 1)) {
808 RTE_LOG(ERR, EAL, "Options -m or --socket-mem cannot be specified "
809 "together with --no-huge!\n");
814 /* if no blacklist, parse a whitelist */
815 if (blacklist_index > 0) {
816 if (eal_dev_whitelist_exists()) {
817 RTE_LOG(ERR, EAL, "Error: blacklist [-b] and whitelist "
818 "[--use-device] options cannot be used at the same time\n");
822 rte_eal_pci_set_blacklist(eal_dev_blacklist, blacklist_index);
824 if (eal_dev_whitelist_exists() && eal_dev_whitelist_parse() < 0) {
825 RTE_LOG(ERR,EAL, "Error parsing whitelist[--use-device] options\n");
831 argv[optind-1] = prgname;
833 /* if no memory amounts were requested, this will result in 0 and
834 * will be overriden later, right after eal_hugepage_info_init() */
835 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
836 internal_config.memory += internal_config.socket_mem[i];
839 optind = 0; /* reset getopt lib */
844 eal_check_mem_on_local_socket(void)
846 const struct rte_memseg *ms;
849 socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
851 ms = rte_eal_get_physmem_layout();
853 for (i = 0; i < RTE_MAX_MEMSEG; i++)
854 if (ms[i].socket_id == socket_id &&
858 RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
859 "memory on local socket!\n");
863 sync_func(__attribute__((unused)) void *arg)
869 rte_eal_mcfg_complete(void)
871 /* ALL shared mem_config related INIT DONE */
872 if (rte_config.process_type == RTE_PROC_PRIMARY)
873 rte_config.mem_config->magic = RTE_MAGIC;
877 * Request iopl priviledge for all RPL, returns 0 on success
880 rte_eal_iopl_init(void)
882 return iopl(HIGHEST_RPL);
885 /* Launch threads, called at application init(). */
887 rte_eal_init(int argc, char **argv)
891 static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
893 if (!rte_atomic32_test_and_set(&run_once))
896 thread_id = pthread_self();
898 if (rte_eal_log_early_init() < 0)
899 rte_panic("Cannot init early logs\n");
901 fctret = eal_parse_args(argc, argv);
905 if (internal_config.no_hugetlbfs == 0 &&
906 internal_config.process_type != RTE_PROC_SECONDARY &&
907 eal_hugepage_info_init() < 0)
908 rte_panic("Cannot get hugepage information\n");
910 if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
911 if (internal_config.no_hugetlbfs)
912 internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
914 internal_config.memory = eal_get_hugepage_mem_size();
917 if (internal_config.vmware_tsc_map == 1) {
918 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
919 rte_cycles_vmware_tsc_map = 1;
920 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
921 "you must have monitor_control.pseudo_perfctr = TRUE\n");
923 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
924 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
928 rte_srand(rte_rdtsc());
932 if (rte_eal_iopl_init() == 0)
933 rte_config.flags |= EAL_FLG_HIGH_IOPL;
935 if (rte_eal_cpu_init() < 0)
936 rte_panic("Cannot detect lcores\n");
938 if (rte_eal_memory_init() < 0)
939 rte_panic("Cannot init memory\n");
941 /* the directories are locked during eal_hugepage_info_init */
942 eal_hugedirs_unlock();
944 if (rte_eal_memzone_init() < 0)
945 rte_panic("Cannot init memzone\n");
947 if (rte_eal_tailqs_init() < 0)
948 rte_panic("Cannot init tail queues for objects\n");
950 if (rte_eal_log_init(argv[0], internal_config.syslog_facility) < 0)
951 rte_panic("Cannot init logs\n");
953 if (rte_eal_alarm_init() < 0)
954 rte_panic("Cannot init interrupt-handling thread\n");
956 if (rte_eal_intr_init() < 0)
957 rte_panic("Cannot init interrupt-handling thread\n");
959 if (rte_eal_timer_init() < 0)
960 rte_panic("Cannot init HPET or TSC timers\n");
962 if (rte_eal_pci_init() < 0)
963 rte_panic("Cannot init PCI\n");
965 RTE_LOG(DEBUG, EAL, "Master core %u is ready (tid=%x)\n",
966 rte_config.master_lcore, (int)thread_id);
968 eal_check_mem_on_local_socket();
970 rte_eal_mcfg_complete();
972 if (rte_eal_non_pci_ethdev_init() < 0)
973 rte_panic("Cannot init non-PCI eth_devs\n");
975 RTE_LCORE_FOREACH_SLAVE(i) {
978 * create communication pipes between master thread
981 if (pipe(lcore_config[i].pipe_master2slave) < 0)
982 rte_panic("Cannot create pipe\n");
983 if (pipe(lcore_config[i].pipe_slave2master) < 0)
984 rte_panic("Cannot create pipe\n");
986 lcore_config[i].state = WAIT;
988 /* create a thread for each lcore */
989 ret = pthread_create(&lcore_config[i].thread_id, NULL,
990 eal_thread_loop, NULL);
992 rte_panic("Cannot create thread\n");
995 eal_thread_init_master(rte_config.master_lcore);
998 * Launch a dummy function on all slave lcores, so that master lcore
999 * knows they are all ready when this function returns.
1001 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
1002 rte_eal_mp_wait_lcore();
1008 enum rte_lcore_role_t
1009 rte_eal_lcore_role(unsigned lcore_id)
1011 return (rte_config.lcore_role[lcore_id]);
1014 enum rte_proc_type_t
1015 rte_eal_process_type(void)
1017 return (rte_config.process_type);