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