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