4 * Copyright(c) 2010-2013 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.
50 #include <sys/queue.h>
52 #include <rte_common.h>
53 #include <rte_debug.h>
54 #include <rte_memory.h>
55 #include <rte_memzone.h>
56 #include <rte_launch.h>
57 #include <rte_tailq.h>
59 #include <rte_eal_memconfig.h>
60 #include <rte_per_lcore.h>
61 #include <rte_lcore.h>
63 #include <rte_random.h>
64 #include <rte_cycles.h>
65 #include <rte_string_fns.h>
66 #include <rte_cpuflags.h>
67 #include <rte_interrupts.h>
69 #include <rte_common.h>
70 #include <rte_version.h>
71 #include <rte_atomic.h>
72 #include <malloc_heap.h>
74 #include "eal_private.h"
75 #include "eal_thread.h"
76 #include "eal_internal_cfg.h"
77 #include "eal_filesystem.h"
78 #include "eal_hugepages.h"
80 #define OPT_HUGE_DIR "huge-dir"
81 #define OPT_PROC_TYPE "proc-type"
82 #define OPT_NO_SHCONF "no-shconf"
83 #define OPT_NO_HPET "no-hpet"
84 #define OPT_VMWARE_TSC_MAP "vmware-tsc-map"
85 #define OPT_NO_PCI "no-pci"
86 #define OPT_NO_HUGE "no-huge"
87 #define OPT_FILE_PREFIX "file-prefix"
88 #define OPT_SOCKET_MEM "socket-mem"
89 #define OPT_SYSLOG "syslog"
91 #define RTE_EAL_BLACKLIST_SIZE 0x100
93 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
95 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
97 #define GET_BLACKLIST_FIELD(in, fd, lim, dlm) \
102 val = strtoul((in), &end, 16); \
103 if (errno != 0 || end[0] != (dlm) || val > (lim)) \
105 (fd) = (typeof (fd))val; \
109 /* Allow the application to print its usage message too if set */
110 static rte_usage_hook_t rte_application_usage_hook = NULL;
111 /* early configuration structure, when memory config is not mmapped */
112 static struct rte_mem_config early_mem_config;
114 /* define fd variable here, because file needs to be kept open for the
115 * duration of the program, as we hold a write lock on it in the primary proc */
116 static int mem_cfg_fd = -1;
118 static struct flock wr_lock = {
120 .l_whence = SEEK_SET,
121 .l_start = offsetof(struct rte_mem_config, memseg),
122 .l_len = sizeof(early_mem_config.memseg),
125 /* Address of global and public configuration */
126 static struct rte_config rte_config = {
127 .mem_config = &early_mem_config,
130 static struct rte_pci_addr eal_dev_blacklist[RTE_EAL_BLACKLIST_SIZE];
132 /* internal configuration (per-core) */
133 struct lcore_config lcore_config[RTE_MAX_LCORE];
135 /* internal configuration */
136 struct internal_config internal_config;
138 /* used by rte_rdtsc() */
139 int rte_cycles_vmware_tsc_map;
141 /* Return a pointer to the configuration structure */
143 rte_eal_get_configuration(void)
148 /* parse a sysfs (or other) file containing one integer value */
150 eal_parse_sysfs_value(const char *filename, unsigned long *val)
156 if ((f = fopen(filename, "r")) == NULL) {
157 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
162 if (fgets(buf, sizeof(buf), f) == NULL) {
163 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
168 *val = strtoul(buf, &end, 0);
169 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
170 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
180 /* create memory configuration in shared/mmap memory. Take out
181 * a write lock on the memsegs, so we can auto-detect primary/secondary.
182 * This means we never close the file while running (auto-close on exit).
183 * We also don't lock the whole file, so that in future we can use read-locks
184 * on other parts, e.g. memzones, to detect if there are running secondary
187 rte_eal_config_create(void)
189 void *rte_mem_cfg_addr;
192 const char *pathname = eal_runtime_config_path();
194 if (internal_config.no_shconf)
198 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
200 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
203 retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
206 rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
209 retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
212 rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
213 "process running?\n", pathname);
216 rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
217 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
219 if (rte_mem_cfg_addr == MAP_FAILED){
220 rte_panic("Cannot mmap memory for rte_config\n");
222 memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
223 rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
226 /* attach to an existing shared memory config */
228 rte_eal_config_attach(void)
230 void *rte_mem_cfg_addr;
231 const char *pathname = eal_runtime_config_path();
233 if (internal_config.no_shconf)
237 mem_cfg_fd = open(pathname, O_RDWR);
239 rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
242 rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
243 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
245 if (rte_mem_cfg_addr == MAP_FAILED)
246 rte_panic("Cannot mmap memory for rte_config\n");
248 rte_config.mem_config = (struct rte_mem_config *) rte_mem_cfg_addr;
251 /* Detect if we are a primary or a secondary process */
252 static enum rte_proc_type_t
253 eal_proc_type_detect(void)
255 enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
256 const char *pathname = eal_runtime_config_path();
258 /* if we can open the file but not get a write-lock we are a secondary
259 * process. NOTE: if we get a file handle back, we keep that open
260 * and don't close it to prevent a race condition between multiple opens */
261 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
262 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
263 ptype = RTE_PROC_SECONDARY;
265 RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
266 ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
271 /* Sets up rte_config structure with the pointer to shared memory config.*/
273 rte_config_init(void)
275 /* set the magic in configuration structure */
276 rte_config.magic = RTE_MAGIC;
277 rte_config.process_type = (internal_config.process_type == RTE_PROC_AUTO) ?
278 eal_proc_type_detect() : /* for auto, detect the type */
279 internal_config.process_type; /* otherwise use what's already set */
281 switch (rte_config.process_type){
282 case RTE_PROC_PRIMARY:
283 rte_eal_config_create();
285 case RTE_PROC_SECONDARY:
286 rte_eal_config_attach();
287 rte_eal_mcfg_wait_complete(rte_config.mem_config);
290 case RTE_PROC_INVALID:
291 rte_panic("Invalid process type\n");
295 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
297 eal_hugedirs_unlock(void)
301 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
303 /* skip uninitialized */
304 if (internal_config.hugepage_info[i].lock_descriptor == 0)
306 /* unlock hugepage file */
307 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
308 close(internal_config.hugepage_info[i].lock_descriptor);
309 /* reset the field */
310 internal_config.hugepage_info[i].lock_descriptor = 0;
316 eal_usage(const char *prgname)
318 printf("\nUsage: %s -c COREMASK -n NUM [-m NB] [-r NUM] [-b <domain:bus:devid.func>]"
319 "[--proc-type primary|secondary|auto] \n\n"
321 " -c COREMASK : A hexadecimal bitmask of cores to run on\n"
322 " -n NUM : Number of memory channels\n"
323 " -v : Display version information on startup\n"
324 " -b <domain:bus:devid.func>: to prevent EAL from using specified "
326 " (multiple -b options are allowed)\n"
327 " -m MB : memory to allocate (see also --"OPT_SOCKET_MEM")\n"
328 " -r NUM : force number of memory ranks (don't detect)\n"
329 " --"OPT_SYSLOG" : set syslog facility\n"
330 " --"OPT_SOCKET_MEM" : memory to allocate on specific \n"
331 " sockets (use comma separated values)\n"
332 " --"OPT_HUGE_DIR" : directory where hugetlbfs is mounted\n"
333 " --"OPT_PROC_TYPE" : type of this process\n"
334 " --"OPT_FILE_PREFIX": prefix for hugepage filenames\n"
335 " --"OPT_VMWARE_TSC_MAP": use VMware TSC map instead of "
337 "\nEAL options for DEBUG use only:\n"
338 " --"OPT_NO_HUGE" : use malloc instead of hugetlbfs\n"
339 " --"OPT_NO_PCI" : disable pci\n"
340 " --"OPT_NO_HPET" : disable hpet\n"
341 " --"OPT_NO_SHCONF": no shared config (mmap'd files)\n\n",
343 /* Allow the application to print its usage message too if hook is set */
344 if ( rte_application_usage_hook ) {
345 printf("===== Application Usage =====\n\n");
346 rte_application_usage_hook(prgname);
350 /* Set a per-application usage message */
352 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
354 rte_usage_hook_t old_func;
356 /* Will be NULL on the first call to denote the last usage routine. */
357 old_func = rte_application_usage_hook;
358 rte_application_usage_hook = usage_func;
364 * Parse the coremask given as argument (hexadecimal string) and fill
365 * the global configuration (core role and core count) with the parsed
369 eal_parse_coremask(const char *coremask)
371 struct rte_config *cfg = rte_eal_get_configuration();
374 unsigned long long cm;
377 /* parse hexadecimal string */
378 cm = strtoull(coremask, &end, 16);
379 if ((coremask[0] == '\0') || (end == NULL) || (*end != '\0') || (cm == 0))
382 RTE_LOG(DEBUG, EAL, "coremask set to %llx\n", cm);
383 /* set core role and core count */
384 for (i = 0; i < RTE_MAX_LCORE; i++) {
385 if ((1ULL << i) & cm) {
387 cfg->master_lcore = i;
388 cfg->lcore_role[i] = ROLE_RTE;
392 cfg->lcore_role[i] = ROLE_OFF;
399 eal_parse_syslog(const char *facility)
406 { "auth", LOG_AUTH },
407 { "cron", LOG_CRON },
408 { "daemon", LOG_DAEMON },
410 { "kern", LOG_KERN },
412 { "mail", LOG_MAIL },
413 { "news", LOG_NEWS },
414 { "syslog", LOG_SYSLOG },
415 { "user", LOG_USER },
416 { "uucp", LOG_UUCP },
417 { "local0", LOG_LOCAL0 },
418 { "local1", LOG_LOCAL1 },
419 { "local2", LOG_LOCAL2 },
420 { "local3", LOG_LOCAL3 },
421 { "local4", LOG_LOCAL4 },
422 { "local5", LOG_LOCAL5 },
423 { "local6", LOG_LOCAL6 },
424 { "local7", LOG_LOCAL7 },
428 for (i = 0; map[i].name; i++) {
429 if (!strcmp(facility, map[i].name)) {
430 internal_config.syslog_facility = map[i].value;
438 eal_parse_socket_mem(char *socket_mem)
440 char * arg[RTE_MAX_NUMA_NODES];
443 uint64_t total_mem = 0;
445 len = strnlen(socket_mem, SOCKET_MEM_STRLEN);
446 if (len == SOCKET_MEM_STRLEN) {
447 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
451 /* all other error cases will be caught later */
452 if (!isdigit(socket_mem[len-1]))
455 /* split the optarg into separate socket values */
456 arg_num = rte_strsplit(socket_mem, len,
457 arg, RTE_MAX_NUMA_NODES, ',');
459 /* if split failed, or 0 arguments */
463 internal_config.force_sockets = 1;
465 /* parse each defined socket option */
467 for (i = 0; i < arg_num; i++) {
469 internal_config.socket_mem[i] = strtoull(arg[i], &end, 10);
471 /* check for invalid input */
473 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
475 internal_config.socket_mem[i] *= 1024ULL;
476 internal_config.socket_mem[i] *= 1024ULL;
477 total_mem += internal_config.socket_mem[i];
480 /* check if we have a positive amount of total memory */
488 eal_get_hugepage_mem_size(void)
493 for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
494 struct hugepage_info *hpi = &internal_config.hugepage_info[i];
495 if (hpi->hugedir != NULL) {
496 for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
497 size += hpi->hugepage_sz * hpi->num_pages[j];
502 return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
505 static enum rte_proc_type_t
506 eal_parse_proc_type(const char *arg)
508 if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
509 return RTE_PROC_PRIMARY;
510 if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
511 return RTE_PROC_SECONDARY;
512 if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
513 return RTE_PROC_AUTO;
515 return RTE_PROC_INVALID;
519 eal_parse_blacklist(const char *input, struct rte_pci_addr *dev2bl)
521 GET_BLACKLIST_FIELD(input, dev2bl->domain, UINT16_MAX, ':');
522 GET_BLACKLIST_FIELD(input, dev2bl->bus, UINT8_MAX, ':');
523 GET_BLACKLIST_FIELD(input, dev2bl->devid, UINT8_MAX, '.');
524 GET_BLACKLIST_FIELD(input, dev2bl->function, UINT8_MAX, 0);
529 eal_parse_blacklist_opt(const char *optarg, size_t idx)
531 if (idx >= sizeof (eal_dev_blacklist) / sizeof (eal_dev_blacklist[0])) {
533 "%s - too many devices to blacklist...\n",
536 } else if (eal_parse_blacklist(optarg, eal_dev_blacklist + idx) != 0) {
538 "%s - invalid device to blacklist...\n",
548 /* Parse the argument given in the command line of the application */
550 eal_parse_args(int argc, char **argv)
556 ssize_t blacklist_index = 0;;
557 char *prgname = argv[0];
558 static struct option lgopts[] = {
559 {OPT_NO_HUGE, 0, 0, 0},
560 {OPT_NO_PCI, 0, 0, 0},
561 {OPT_NO_HPET, 0, 0, 0},
562 {OPT_VMWARE_TSC_MAP, 0, 0, 0},
563 {OPT_HUGE_DIR, 1, 0, 0},
564 {OPT_NO_SHCONF, 0, 0, 0},
565 {OPT_PROC_TYPE, 1, 0, 0},
566 {OPT_FILE_PREFIX, 1, 0, 0},
567 {OPT_SOCKET_MEM, 1, 0, 0},
568 {OPT_SYSLOG, 1, NULL, 0},
574 internal_config.memory = 0;
575 internal_config.force_nrank = 0;
576 internal_config.force_nchannel = 0;
577 internal_config.hugefile_prefix = HUGEFILE_PREFIX_DEFAULT;
578 internal_config.hugepage_dir = NULL;
579 internal_config.force_sockets = 0;
580 internal_config.syslog_facility = LOG_DAEMON;
581 #ifdef RTE_LIBEAL_USE_HPET
582 internal_config.no_hpet = 0;
584 internal_config.no_hpet = 1;
586 /* zero out the NUMA config */
587 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
588 internal_config.socket_mem[i] = 0;
590 /* zero out hugedir descriptors */
591 for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
592 internal_config.hugepage_info[i].lock_descriptor = 0;
594 internal_config.vmware_tsc_map = 0;
596 while ((opt = getopt_long(argc, argvopt, "b:c:m:n:r:v",
597 lgopts, &option_index)) != EOF) {
602 if ((blacklist_index = eal_parse_blacklist_opt(optarg,
603 blacklist_index)) < 0) {
610 if (eal_parse_coremask(optarg) < 0) {
611 RTE_LOG(ERR, EAL, "invalid coremask\n");
619 internal_config.memory = atoi(optarg);
620 internal_config.memory *= 1024ULL;
621 internal_config.memory *= 1024ULL;
623 /* force number of channels */
625 internal_config.force_nchannel = atoi(optarg);
626 if (internal_config.force_nchannel == 0 ||
627 internal_config.force_nchannel > 4) {
628 RTE_LOG(ERR, EAL, "invalid channel number\n");
633 /* force number of ranks */
635 internal_config.force_nrank = atoi(optarg);
636 if (internal_config.force_nrank == 0 ||
637 internal_config.force_nrank > 16) {
638 RTE_LOG(ERR, EAL, "invalid rank number\n");
644 /* since message is explicitly requested by user, we
645 * write message at highest log level so it can always be seen
646 * even if info or warning messages are disabled */
647 RTE_LOG(CRIT, EAL, "RTE Version: '%s'\n", rte_version());
652 if (!strcmp(lgopts[option_index].name, OPT_NO_HUGE)) {
653 internal_config.no_hugetlbfs = 1;
655 else if (!strcmp(lgopts[option_index].name, OPT_NO_PCI)) {
656 internal_config.no_pci = 1;
658 else if (!strcmp(lgopts[option_index].name, OPT_NO_HPET)) {
659 internal_config.no_hpet = 1;
661 else if (!strcmp(lgopts[option_index].name, OPT_VMWARE_TSC_MAP)) {
662 internal_config.vmware_tsc_map = 1;
664 else if (!strcmp(lgopts[option_index].name, OPT_NO_SHCONF)) {
665 internal_config.no_shconf = 1;
667 else if (!strcmp(lgopts[option_index].name, OPT_HUGE_DIR)) {
668 internal_config.hugepage_dir = optarg;
670 else if (!strcmp(lgopts[option_index].name, OPT_PROC_TYPE)) {
671 internal_config.process_type = eal_parse_proc_type(optarg);
673 else if (!strcmp(lgopts[option_index].name, OPT_FILE_PREFIX)) {
674 internal_config.hugefile_prefix = optarg;
676 else if (!strcmp(lgopts[option_index].name, OPT_SOCKET_MEM)) {
677 if (eal_parse_socket_mem(optarg) < 0) {
678 RTE_LOG(ERR, EAL, "invalid parameters for --"
679 OPT_SOCKET_MEM "\n");
684 else if (!strcmp(lgopts[option_index].name, OPT_SYSLOG)) {
685 if (eal_parse_syslog(optarg) < 0) {
686 RTE_LOG(ERR, EAL, "invalid parameters for --"
702 RTE_LOG(ERR, EAL, "coremask not specified\n");
706 if (internal_config.process_type == RTE_PROC_AUTO){
707 internal_config.process_type = eal_proc_type_detect();
709 if (internal_config.process_type == RTE_PROC_INVALID){
710 RTE_LOG(ERR, EAL, "Invalid process type specified\n");
714 if (internal_config.process_type == RTE_PROC_PRIMARY &&
715 internal_config.force_nchannel == 0) {
716 RTE_LOG(ERR, EAL, "Number of memory channels (-n) not specified\n");
720 if (index(internal_config.hugefile_prefix,'%') != NULL){
721 RTE_LOG(ERR, EAL, "Invalid char, '%%', in '"OPT_FILE_PREFIX"' option\n");
725 if (internal_config.memory > 0 && internal_config.force_sockets == 1) {
726 RTE_LOG(ERR, EAL, "Options -m and --socket-mem cannot be specified "
727 "at the same time\n");
731 /* --no-huge doesn't make sense with either -m or --socket-mem */
732 if (internal_config.no_hugetlbfs &&
733 (internal_config.memory > 0 ||
734 internal_config.force_sockets == 1)) {
735 RTE_LOG(ERR, EAL, "Options -m or --socket-mem cannot be specified "
736 "together with --no-huge!\n");
741 if (blacklist_index > 0)
742 rte_eal_pci_set_blacklist(eal_dev_blacklist, blacklist_index);
745 argv[optind-1] = prgname;
747 /* if no memory amounts were requested, this will result in 0 and
748 * will be overriden later, right after eal_hugepage_info_init() */
749 for (i = 0; i < RTE_MAX_NUMA_NODES; i++)
750 internal_config.memory += internal_config.socket_mem[i];
753 optind = 0; /* reset getopt lib */
758 eal_check_mem_on_local_socket(void)
760 const struct rte_memseg *ms;
763 socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
765 ms = rte_eal_get_physmem_layout();
767 for (i = 0; i < RTE_MAX_MEMSEG; i++)
768 if (ms[i].socket_id == socket_id &&
772 RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
773 "memory on local socket!\n");
777 sync_func(__attribute__((unused)) void *arg)
783 rte_eal_mcfg_complete(void)
785 /* ALL shared mem_config related INIT DONE */
786 if (rte_config.process_type == RTE_PROC_PRIMARY)
787 rte_config.mem_config->magic = RTE_MAGIC;
790 /* Launch threads, called at application init(). */
792 rte_eal_init(int argc, char **argv)
796 static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
798 if (!rte_atomic32_test_and_set(&run_once))
801 thread_id = pthread_self();
803 if (rte_eal_log_early_init() < 0)
804 rte_panic("Cannot init early logs\n");
806 fctret = eal_parse_args(argc, argv);
810 if (internal_config.no_hugetlbfs == 0 &&
811 internal_config.process_type != RTE_PROC_SECONDARY &&
812 eal_hugepage_info_init() < 0)
813 rte_panic("Cannot get hugepage information\n");
815 if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
816 if (internal_config.no_hugetlbfs)
817 internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
819 internal_config.memory = eal_get_hugepage_mem_size();
822 if (internal_config.vmware_tsc_map == 1) {
823 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
824 rte_cycles_vmware_tsc_map = 1;
825 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
826 "you must have monitor_control.pseudo_perfctr = TRUE\n");
828 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
829 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
833 rte_srand(rte_rdtsc());
837 if (rte_eal_cpu_init() < 0)
838 rte_panic("Cannot detect lcores\n");
840 if (rte_eal_memory_init() < 0)
841 rte_panic("Cannot init memory\n");
843 /* the directories are locked during eal_hugepage_info_init */
844 eal_hugedirs_unlock();
846 if (rte_eal_memzone_init() < 0)
847 rte_panic("Cannot init memzone\n");
849 if (rte_eal_tailqs_init() < 0)
850 rte_panic("Cannot init tail queues for objects\n");
852 if (rte_eal_log_init(argv[0], internal_config.syslog_facility) < 0)
853 rte_panic("Cannot init logs\n");
855 if (rte_eal_alarm_init() < 0)
856 rte_panic("Cannot init interrupt-handling thread\n");
858 if (rte_eal_intr_init() < 0)
859 rte_panic("Cannot init interrupt-handling thread\n");
861 if (rte_eal_timer_init() < 0)
862 rte_panic("Cannot init HPET or TSC timers\n");
864 if (rte_eal_pci_init() < 0)
865 rte_panic("Cannot init PCI\n");
867 RTE_LOG(DEBUG, EAL, "Master core %u is ready (tid=%x)\n",
868 rte_config.master_lcore, (int)thread_id);
870 eal_check_mem_on_local_socket();
872 rte_eal_mcfg_complete();
874 RTE_LCORE_FOREACH_SLAVE(i) {
877 * create communication pipes between master thread
880 if (pipe(lcore_config[i].pipe_master2slave) < 0)
881 rte_panic("Cannot create pipe\n");
882 if (pipe(lcore_config[i].pipe_slave2master) < 0)
883 rte_panic("Cannot create pipe\n");
885 lcore_config[i].state = WAIT;
887 /* create a thread for each lcore */
888 ret = pthread_create(&lcore_config[i].thread_id, NULL,
889 eal_thread_loop, NULL);
891 rte_panic("Cannot create thread\n");
894 eal_thread_init_master(rte_config.master_lcore);
897 * Launch a dummy function on all slave lcores, so that master lcore
898 * knows they are all ready when this function returns.
900 rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
901 rte_eal_mp_wait_lcore();
907 enum rte_lcore_role_t
908 rte_eal_lcore_role(unsigned lcore_id)
910 return (rte_config.lcore_role[lcore_id]);
914 rte_eal_process_type(void)
916 return (rte_config.process_type);