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