mem: allow memseg lists to be marked as external
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation.
3  * Copyright(c) 2014 6WIND S.A.
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <stdarg.h>
11 #include <unistd.h>
12 #include <pthread.h>
13 #include <syslog.h>
14 #include <getopt.h>
15 #include <sys/file.h>
16 #include <stddef.h>
17 #include <errno.h>
18 #include <limits.h>
19 #include <sys/mman.h>
20 #include <sys/queue.h>
21 #include <sys/stat.h>
22
23 #include <rte_compat.h>
24 #include <rte_common.h>
25 #include <rte_debug.h>
26 #include <rte_memory.h>
27 #include <rte_launch.h>
28 #include <rte_eal.h>
29 #include <rte_eal_memconfig.h>
30 #include <rte_errno.h>
31 #include <rte_per_lcore.h>
32 #include <rte_lcore.h>
33 #include <rte_service_component.h>
34 #include <rte_log.h>
35 #include <rte_random.h>
36 #include <rte_cycles.h>
37 #include <rte_string_fns.h>
38 #include <rte_cpuflags.h>
39 #include <rte_interrupts.h>
40 #include <rte_bus.h>
41 #include <rte_dev.h>
42 #include <rte_devargs.h>
43 #include <rte_version.h>
44 #include <rte_vfio.h>
45 #include <rte_atomic.h>
46 #include <malloc_heap.h>
47
48 #include "eal_private.h"
49 #include "eal_thread.h"
50 #include "eal_internal_cfg.h"
51 #include "eal_filesystem.h"
52 #include "eal_hugepages.h"
53 #include "eal_options.h"
54
55 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
56
57 /* Allow the application to print its usage message too if set */
58 static rte_usage_hook_t rte_application_usage_hook = NULL;
59 /* early configuration structure, when memory config is not mmapped */
60 static struct rte_mem_config early_mem_config;
61
62 /* define fd variable here, because file needs to be kept open for the
63  * duration of the program, as we hold a write lock on it in the primary proc */
64 static int mem_cfg_fd = -1;
65
66 static struct flock wr_lock = {
67                 .l_type = F_WRLCK,
68                 .l_whence = SEEK_SET,
69                 .l_start = offsetof(struct rte_mem_config, memsegs),
70                 .l_len = sizeof(early_mem_config.memsegs),
71 };
72
73 /* Address of global and public configuration */
74 static struct rte_config rte_config = {
75                 .mem_config = &early_mem_config,
76 };
77
78 /* internal configuration (per-core) */
79 struct lcore_config lcore_config[RTE_MAX_LCORE];
80
81 /* internal configuration */
82 struct internal_config internal_config;
83
84 /* used by rte_rdtsc() */
85 int rte_cycles_vmware_tsc_map;
86
87 /* platform-specific runtime dir */
88 static char runtime_dir[PATH_MAX];
89
90 static const char *default_runtime_dir = "/var/run";
91
92 int
93 eal_create_runtime_dir(void)
94 {
95         const char *directory = default_runtime_dir;
96         const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
97         const char *fallback = "/tmp";
98         char tmp[PATH_MAX];
99         int ret;
100
101         if (getuid() != 0) {
102                 /* try XDG path first, fall back to /tmp */
103                 if (xdg_runtime_dir != NULL)
104                         directory = xdg_runtime_dir;
105                 else
106                         directory = fallback;
107         }
108         /* create DPDK subdirectory under runtime dir */
109         ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
110         if (ret < 0 || ret == sizeof(tmp)) {
111                 RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
112                 return -1;
113         }
114
115         /* create prefix-specific subdirectory under DPDK runtime dir */
116         ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
117                         tmp, internal_config.hugefile_prefix);
118         if (ret < 0 || ret == sizeof(runtime_dir)) {
119                 RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
120                 return -1;
121         }
122
123         /* create the path if it doesn't exist. no "mkdir -p" here, so do it
124          * step by step.
125          */
126         ret = mkdir(tmp, 0700);
127         if (ret < 0 && errno != EEXIST) {
128                 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
129                         tmp, strerror(errno));
130                 return -1;
131         }
132
133         ret = mkdir(runtime_dir, 0700);
134         if (ret < 0 && errno != EEXIST) {
135                 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
136                         runtime_dir, strerror(errno));
137                 return -1;
138         }
139
140         return 0;
141 }
142
143 const char *
144 eal_get_runtime_dir(void)
145 {
146         return runtime_dir;
147 }
148
149 /* Return user provided mbuf pool ops name */
150 const char *
151 rte_eal_mbuf_user_pool_ops(void)
152 {
153         return internal_config.user_mbuf_pool_ops_name;
154 }
155
156 /* Return a pointer to the configuration structure */
157 struct rte_config *
158 rte_eal_get_configuration(void)
159 {
160         return &rte_config;
161 }
162
163 enum rte_iova_mode
164 rte_eal_iova_mode(void)
165 {
166         return rte_eal_get_configuration()->iova_mode;
167 }
168
169 /* parse a sysfs (or other) file containing one integer value */
170 int
171 eal_parse_sysfs_value(const char *filename, unsigned long *val)
172 {
173         FILE *f;
174         char buf[BUFSIZ];
175         char *end = NULL;
176
177         if ((f = fopen(filename, "r")) == NULL) {
178                 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
179                         __func__, filename);
180                 return -1;
181         }
182
183         if (fgets(buf, sizeof(buf), f) == NULL) {
184                 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
185                         __func__, filename);
186                 fclose(f);
187                 return -1;
188         }
189         *val = strtoul(buf, &end, 0);
190         if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
191                 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
192                                 __func__, filename);
193                 fclose(f);
194                 return -1;
195         }
196         fclose(f);
197         return 0;
198 }
199
200
201 /* create memory configuration in shared/mmap memory. Take out
202  * a write lock on the memsegs, so we can auto-detect primary/secondary.
203  * This means we never close the file while running (auto-close on exit).
204  * We also don't lock the whole file, so that in future we can use read-locks
205  * on other parts, e.g. memzones, to detect if there are running secondary
206  * processes. */
207 static void
208 rte_eal_config_create(void)
209 {
210         void *rte_mem_cfg_addr;
211         int retval;
212
213         const char *pathname = eal_runtime_config_path();
214
215         if (internal_config.no_shconf)
216                 return;
217
218         if (mem_cfg_fd < 0){
219                 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
220                 if (mem_cfg_fd < 0)
221                         rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
222         }
223
224         retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
225         if (retval < 0){
226                 close(mem_cfg_fd);
227                 rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
228         }
229
230         retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
231         if (retval < 0){
232                 close(mem_cfg_fd);
233                 rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
234                                 "process running?\n", pathname);
235         }
236
237         rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
238                                 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
239
240         if (rte_mem_cfg_addr == MAP_FAILED){
241                 rte_panic("Cannot mmap memory for rte_config\n");
242         }
243         memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
244         rte_config.mem_config = rte_mem_cfg_addr;
245 }
246
247 /* attach to an existing shared memory config */
248 static void
249 rte_eal_config_attach(void)
250 {
251         void *rte_mem_cfg_addr;
252         const char *pathname = eal_runtime_config_path();
253
254         if (internal_config.no_shconf)
255                 return;
256
257         if (mem_cfg_fd < 0){
258                 mem_cfg_fd = open(pathname, O_RDWR);
259                 if (mem_cfg_fd < 0)
260                         rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
261         }
262
263         rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
264                                 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
265         close(mem_cfg_fd);
266         if (rte_mem_cfg_addr == MAP_FAILED)
267                 rte_panic("Cannot mmap memory for rte_config\n");
268
269         rte_config.mem_config = rte_mem_cfg_addr;
270 }
271
272 /* Detect if we are a primary or a secondary process */
273 enum rte_proc_type_t
274 eal_proc_type_detect(void)
275 {
276         enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
277         const char *pathname = eal_runtime_config_path();
278
279         /* if there no shared config, there can be no secondary processes */
280         if (!internal_config.no_shconf) {
281                 /* if we can open the file but not get a write-lock we are a
282                  * secondary process. NOTE: if we get a file handle back, we
283                  * keep that open and don't close it to prevent a race condition
284                  * between multiple opens.
285                  */
286                 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
287                                 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
288                         ptype = RTE_PROC_SECONDARY;
289         }
290
291         RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
292                         ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
293
294         return ptype;
295 }
296
297 /* Sets up rte_config structure with the pointer to shared memory config.*/
298 static void
299 rte_config_init(void)
300 {
301         rte_config.process_type = internal_config.process_type;
302
303         switch (rte_config.process_type){
304         case RTE_PROC_PRIMARY:
305                 rte_eal_config_create();
306                 break;
307         case RTE_PROC_SECONDARY:
308                 rte_eal_config_attach();
309                 rte_eal_mcfg_wait_complete(rte_config.mem_config);
310                 break;
311         case RTE_PROC_AUTO:
312         case RTE_PROC_INVALID:
313                 rte_panic("Invalid process type\n");
314         }
315 }
316
317 /* display usage */
318 static void
319 eal_usage(const char *prgname)
320 {
321         printf("\nUsage: %s ", prgname);
322         eal_common_usage();
323         /* Allow the application to print its usage message too if hook is set */
324         if ( rte_application_usage_hook ) {
325                 printf("===== Application Usage =====\n\n");
326                 rte_application_usage_hook(prgname);
327         }
328 }
329
330 /* Set a per-application usage message */
331 rte_usage_hook_t
332 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
333 {
334         rte_usage_hook_t        old_func;
335
336         /* Will be NULL on the first call to denote the last usage routine. */
337         old_func                                        = rte_application_usage_hook;
338         rte_application_usage_hook      = usage_func;
339
340         return old_func;
341 }
342
343 static inline size_t
344 eal_get_hugepage_mem_size(void)
345 {
346         uint64_t size = 0;
347         unsigned i, j;
348
349         for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
350                 struct hugepage_info *hpi = &internal_config.hugepage_info[i];
351                 if (strnlen(hpi->hugedir, sizeof(hpi->hugedir)) != 0) {
352                         for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
353                                 size += hpi->hugepage_sz * hpi->num_pages[j];
354                         }
355                 }
356         }
357
358         return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
359 }
360
361 /* Parse the arguments for --log-level only */
362 static void
363 eal_log_level_parse(int argc, char **argv)
364 {
365         int opt;
366         char **argvopt;
367         int option_index;
368         const int old_optind = optind;
369         const int old_optopt = optopt;
370         const int old_optreset = optreset;
371         char * const old_optarg = optarg;
372
373         argvopt = argv;
374         optind = 1;
375         optreset = 1;
376
377         while ((opt = getopt_long(argc, argvopt, eal_short_options,
378                                   eal_long_options, &option_index)) != EOF) {
379
380                 int ret;
381
382                 /* getopt is not happy, stop right now */
383                 if (opt == '?')
384                         break;
385
386                 ret = (opt == OPT_LOG_LEVEL_NUM) ?
387                         eal_parse_common_option(opt, optarg, &internal_config) : 0;
388
389                 /* common parser is not happy */
390                 if (ret < 0)
391                         break;
392         }
393
394         /* restore getopt lib */
395         optind = old_optind;
396         optopt = old_optopt;
397         optreset = old_optreset;
398         optarg = old_optarg;
399 }
400
401 /* Parse the argument given in the command line of the application */
402 static int
403 eal_parse_args(int argc, char **argv)
404 {
405         int opt, ret;
406         char **argvopt;
407         int option_index;
408         char *prgname = argv[0];
409         const int old_optind = optind;
410         const int old_optopt = optopt;
411         const int old_optreset = optreset;
412         char * const old_optarg = optarg;
413
414         argvopt = argv;
415         optind = 1;
416         optreset = 1;
417
418         while ((opt = getopt_long(argc, argvopt, eal_short_options,
419                                   eal_long_options, &option_index)) != EOF) {
420
421                 /* getopt is not happy, stop right now */
422                 if (opt == '?') {
423                         eal_usage(prgname);
424                         ret = -1;
425                         goto out;
426                 }
427
428                 ret = eal_parse_common_option(opt, optarg, &internal_config);
429                 /* common parser is not happy */
430                 if (ret < 0) {
431                         eal_usage(prgname);
432                         ret = -1;
433                         goto out;
434                 }
435                 /* common parser handled this option */
436                 if (ret == 0)
437                         continue;
438
439                 switch (opt) {
440                 case OPT_MBUF_POOL_OPS_NAME_NUM:
441                         internal_config.user_mbuf_pool_ops_name =
442                             strdup(optarg);
443                         break;
444                 case 'h':
445                         eal_usage(prgname);
446                         exit(EXIT_SUCCESS);
447                 default:
448                         if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
449                                 RTE_LOG(ERR, EAL, "Option %c is not supported "
450                                         "on FreeBSD\n", opt);
451                         } else if (opt >= OPT_LONG_MIN_NUM &&
452                                    opt < OPT_LONG_MAX_NUM) {
453                                 RTE_LOG(ERR, EAL, "Option %s is not supported "
454                                         "on FreeBSD\n",
455                                         eal_long_options[option_index].name);
456                         } else {
457                                 RTE_LOG(ERR, EAL, "Option %d is not supported "
458                                         "on FreeBSD\n", opt);
459                         }
460                         eal_usage(prgname);
461                         ret = -1;
462                         goto out;
463                 }
464         }
465
466         /* create runtime data directory */
467         if (internal_config.no_shconf == 0 &&
468                         eal_create_runtime_dir() < 0) {
469                 RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
470                 ret = -1;
471                 goto out;
472         }
473
474         if (eal_adjust_config(&internal_config) != 0) {
475                 ret = -1;
476                 goto out;
477         }
478
479         /* sanity checks */
480         if (eal_check_common_options(&internal_config) != 0) {
481                 eal_usage(prgname);
482                 ret = -1;
483                 goto out;
484         }
485
486         if (optind >= 0)
487                 argv[optind-1] = prgname;
488         ret = optind-1;
489
490 out:
491         /* restore getopt lib */
492         optind = old_optind;
493         optopt = old_optopt;
494         optreset = old_optreset;
495         optarg = old_optarg;
496
497         return ret;
498 }
499
500 static int
501 check_socket(const struct rte_memseg_list *msl, void *arg)
502 {
503         int *socket_id = arg;
504
505         if (msl->external)
506                 return 0;
507
508         if (msl->socket_id == *socket_id && msl->memseg_arr.count != 0)
509                 return 1;
510
511         return 0;
512 }
513
514 static void
515 eal_check_mem_on_local_socket(void)
516 {
517         int socket_id;
518
519         socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
520
521         if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
522                 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
523 }
524
525
526 static int
527 sync_func(__attribute__((unused)) void *arg)
528 {
529         return 0;
530 }
531
532 inline static void
533 rte_eal_mcfg_complete(void)
534 {
535         /* ALL shared mem_config related INIT DONE */
536         if (rte_config.process_type == RTE_PROC_PRIMARY)
537                 rte_config.mem_config->magic = RTE_MAGIC;
538 }
539
540 /* return non-zero if hugepages are enabled. */
541 int rte_eal_has_hugepages(void)
542 {
543         return !internal_config.no_hugetlbfs;
544 }
545
546 /* Abstraction for port I/0 privilege */
547 int
548 rte_eal_iopl_init(void)
549 {
550         static int fd;
551
552         fd = open("/dev/io", O_RDWR);
553         if (fd < 0)
554                 return -1;
555         /* keep fd open for iopl */
556         return 0;
557 }
558
559 static void rte_eal_init_alert(const char *msg)
560 {
561         fprintf(stderr, "EAL: FATAL: %s\n", msg);
562         RTE_LOG(ERR, EAL, "%s\n", msg);
563 }
564
565 /* Launch threads, called at application init(). */
566 int
567 rte_eal_init(int argc, char **argv)
568 {
569         int i, fctret, ret;
570         pthread_t thread_id;
571         static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
572         char cpuset[RTE_CPU_AFFINITY_STR_LEN];
573         char thread_name[RTE_MAX_THREAD_NAME_LEN];
574
575         /* checks if the machine is adequate */
576         if (!rte_cpu_is_supported()) {
577                 rte_eal_init_alert("unsupported cpu type.");
578                 rte_errno = ENOTSUP;
579                 return -1;
580         }
581
582         if (!rte_atomic32_test_and_set(&run_once)) {
583                 rte_eal_init_alert("already called initialization.");
584                 rte_errno = EALREADY;
585                 return -1;
586         }
587
588         thread_id = pthread_self();
589
590         eal_reset_internal_config(&internal_config);
591
592         /* set log level as early as possible */
593         eal_log_level_parse(argc, argv);
594
595         if (rte_eal_cpu_init() < 0) {
596                 rte_eal_init_alert("Cannot detect lcores.");
597                 rte_errno = ENOTSUP;
598                 return -1;
599         }
600
601         fctret = eal_parse_args(argc, argv);
602         if (fctret < 0) {
603                 rte_eal_init_alert("Invalid 'command line' arguments.");
604                 rte_errno = EINVAL;
605                 rte_atomic32_clear(&run_once);
606                 return -1;
607         }
608
609         /* FreeBSD always uses legacy memory model */
610         internal_config.legacy_mem = true;
611
612         if (eal_plugins_init() < 0) {
613                 rte_eal_init_alert("Cannot init plugins\n");
614                 rte_errno = EINVAL;
615                 rte_atomic32_clear(&run_once);
616                 return -1;
617         }
618
619         if (eal_option_device_parse()) {
620                 rte_errno = ENODEV;
621                 rte_atomic32_clear(&run_once);
622                 return -1;
623         }
624
625         rte_config_init();
626
627         if (rte_eal_intr_init() < 0) {
628                 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
629                 return -1;
630         }
631
632         /* Put mp channel init before bus scan so that we can init the vdev
633          * bus through mp channel in the secondary process before the bus scan.
634          */
635         if (rte_mp_channel_init() < 0) {
636                 rte_eal_init_alert("failed to init mp channel\n");
637                 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
638                         rte_errno = EFAULT;
639                         return -1;
640                 }
641         }
642
643         if (rte_bus_scan()) {
644                 rte_eal_init_alert("Cannot scan the buses for devices\n");
645                 rte_errno = ENODEV;
646                 rte_atomic32_clear(&run_once);
647                 return -1;
648         }
649
650         /* autodetect the iova mapping mode (default is iova_pa) */
651         rte_eal_get_configuration()->iova_mode = rte_bus_get_iommu_class();
652
653         if (internal_config.no_hugetlbfs == 0) {
654                 /* rte_config isn't initialized yet */
655                 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
656                         eal_hugepage_info_init() :
657                         eal_hugepage_info_read();
658                 if (ret < 0) {
659                         rte_eal_init_alert("Cannot get hugepage information.");
660                         rte_errno = EACCES;
661                         rte_atomic32_clear(&run_once);
662                         return -1;
663                 }
664         }
665
666         if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
667                 if (internal_config.no_hugetlbfs)
668                         internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
669                 else
670                         internal_config.memory = eal_get_hugepage_mem_size();
671         }
672
673         if (internal_config.vmware_tsc_map == 1) {
674 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
675                 rte_cycles_vmware_tsc_map = 1;
676                 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
677                                 "you must have monitor_control.pseudo_perfctr = TRUE\n");
678 #else
679                 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
680                                 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
681 #endif
682         }
683
684         rte_srand(rte_rdtsc());
685
686         /* in secondary processes, memory init may allocate additional fbarrays
687          * not present in primary processes, so to avoid any potential issues,
688          * initialize memzones first.
689          */
690         if (rte_eal_memzone_init() < 0) {
691                 rte_eal_init_alert("Cannot init memzone\n");
692                 rte_errno = ENODEV;
693                 return -1;
694         }
695
696         if (rte_eal_memory_init() < 0) {
697                 rte_eal_init_alert("Cannot init memory\n");
698                 rte_errno = ENOMEM;
699                 return -1;
700         }
701
702         if (rte_eal_malloc_heap_init() < 0) {
703                 rte_eal_init_alert("Cannot init malloc heap\n");
704                 rte_errno = ENODEV;
705                 return -1;
706         }
707
708         if (rte_eal_tailqs_init() < 0) {
709                 rte_eal_init_alert("Cannot init tail queues for objects\n");
710                 rte_errno = EFAULT;
711                 return -1;
712         }
713
714         if (rte_eal_alarm_init() < 0) {
715                 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
716                 /* rte_eal_alarm_init sets rte_errno on failure. */
717                 return -1;
718         }
719
720         if (rte_eal_timer_init() < 0) {
721                 rte_eal_init_alert("Cannot init HPET or TSC timers\n");
722                 rte_errno = ENOTSUP;
723                 return -1;
724         }
725
726         eal_check_mem_on_local_socket();
727
728         eal_thread_init_master(rte_config.master_lcore);
729
730         ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
731
732         RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
733                 rte_config.master_lcore, thread_id, cpuset,
734                 ret == 0 ? "" : "...");
735
736         RTE_LCORE_FOREACH_SLAVE(i) {
737
738                 /*
739                  * create communication pipes between master thread
740                  * and children
741                  */
742                 if (pipe(lcore_config[i].pipe_master2slave) < 0)
743                         rte_panic("Cannot create pipe\n");
744                 if (pipe(lcore_config[i].pipe_slave2master) < 0)
745                         rte_panic("Cannot create pipe\n");
746
747                 lcore_config[i].state = WAIT;
748
749                 /* create a thread for each lcore */
750                 ret = pthread_create(&lcore_config[i].thread_id, NULL,
751                                      eal_thread_loop, NULL);
752                 if (ret != 0)
753                         rte_panic("Cannot create thread\n");
754
755                 /* Set thread_name for aid in debugging. */
756                 snprintf(thread_name, sizeof(thread_name),
757                                 "lcore-slave-%d", i);
758                 rte_thread_setname(lcore_config[i].thread_id, thread_name);
759         }
760
761         /*
762          * Launch a dummy function on all slave lcores, so that master lcore
763          * knows they are all ready when this function returns.
764          */
765         rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
766         rte_eal_mp_wait_lcore();
767
768         /* initialize services so vdevs register service during bus_probe. */
769         ret = rte_service_init();
770         if (ret) {
771                 rte_eal_init_alert("rte_service_init() failed\n");
772                 rte_errno = ENOEXEC;
773                 return -1;
774         }
775
776         /* Probe all the buses and devices/drivers on them */
777         if (rte_bus_probe()) {
778                 rte_eal_init_alert("Cannot probe devices\n");
779                 rte_errno = ENOTSUP;
780                 return -1;
781         }
782
783         /* initialize default service/lcore mappings and start running. Ignore
784          * -ENOTSUP, as it indicates no service coremask passed to EAL.
785          */
786         ret = rte_service_start_with_defaults();
787         if (ret < 0 && ret != -ENOTSUP) {
788                 rte_errno = ENOEXEC;
789                 return -1;
790         }
791
792         rte_eal_mcfg_complete();
793
794         return fctret;
795 }
796
797 int __rte_experimental
798 rte_eal_cleanup(void)
799 {
800         rte_service_finalize();
801         return 0;
802 }
803
804 /* get core role */
805 enum rte_lcore_role_t
806 rte_eal_lcore_role(unsigned lcore_id)
807 {
808         return rte_config.lcore_role[lcore_id];
809 }
810
811 enum rte_proc_type_t
812 rte_eal_process_type(void)
813 {
814         return rte_config.process_type;
815 }
816
817 int rte_eal_has_pci(void)
818 {
819         return !internal_config.no_pci;
820 }
821
822 int rte_eal_create_uio_dev(void)
823 {
824         return internal_config.create_uio_dev;
825 }
826
827 enum rte_intr_mode
828 rte_eal_vfio_intr_mode(void)
829 {
830         return RTE_INTR_MODE_NONE;
831 }
832
833 int rte_vfio_setup_device(__rte_unused const char *sysfs_base,
834                       __rte_unused const char *dev_addr,
835                       __rte_unused int *vfio_dev_fd,
836                       __rte_unused struct vfio_device_info *device_info)
837 {
838         return -1;
839 }
840
841 int rte_vfio_release_device(__rte_unused const char *sysfs_base,
842                         __rte_unused const char *dev_addr,
843                         __rte_unused int fd)
844 {
845         return -1;
846 }
847
848 int rte_vfio_enable(__rte_unused const char *modname)
849 {
850         return -1;
851 }
852
853 int rte_vfio_is_enabled(__rte_unused const char *modname)
854 {
855         return 0;
856 }
857
858 int rte_vfio_noiommu_is_enabled(void)
859 {
860         return 0;
861 }
862
863 int rte_vfio_clear_group(__rte_unused int vfio_group_fd)
864 {
865         return 0;
866 }
867
868 int
869 rte_vfio_dma_map(uint64_t __rte_unused vaddr, __rte_unused uint64_t iova,
870                   __rte_unused uint64_t len)
871 {
872         return -1;
873 }
874
875 int
876 rte_vfio_dma_unmap(uint64_t __rte_unused vaddr, uint64_t __rte_unused iova,
877                     __rte_unused uint64_t len)
878 {
879         return -1;
880 }
881
882 int
883 rte_vfio_get_group_num(__rte_unused const char *sysfs_base,
884                        __rte_unused const char *dev_addr,
885                        __rte_unused int *iommu_group_num)
886 {
887         return -1;
888 }
889
890 int
891 rte_vfio_get_container_fd(void)
892 {
893         return -1;
894 }
895
896 int
897 rte_vfio_get_group_fd(__rte_unused int iommu_group_num)
898 {
899         return -1;
900 }
901
902 int
903 rte_vfio_container_create(void)
904 {
905         return -1;
906 }
907
908 int
909 rte_vfio_container_destroy(__rte_unused int container_fd)
910 {
911         return -1;
912 }
913
914 int
915 rte_vfio_container_group_bind(__rte_unused int container_fd,
916                 __rte_unused int iommu_group_num)
917 {
918         return -1;
919 }
920
921 int
922 rte_vfio_container_group_unbind(__rte_unused int container_fd,
923                 __rte_unused int iommu_group_num)
924 {
925         return -1;
926 }
927
928 int
929 rte_vfio_container_dma_map(__rte_unused int container_fd,
930                         __rte_unused uint64_t vaddr,
931                         __rte_unused uint64_t iova,
932                         __rte_unused uint64_t len)
933 {
934         return -1;
935 }
936
937 int
938 rte_vfio_container_dma_unmap(__rte_unused int container_fd,
939                         __rte_unused uint64_t vaddr,
940                         __rte_unused uint64_t iova,
941                         __rte_unused uint64_t len)
942 {
943         return -1;
944 }