eal: use sizeof to avoid a double use of a define
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
5  *   Copyright(c) 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdint.h>
38 #include <string.h>
39 #include <stdarg.h>
40 #include <unistd.h>
41 #include <pthread.h>
42 #include <syslog.h>
43 #include <getopt.h>
44 #include <sys/file.h>
45 #include <stddef.h>
46 #include <errno.h>
47 #include <limits.h>
48 #include <sys/mman.h>
49 #include <sys/queue.h>
50
51 #include <rte_common.h>
52 #include <rte_debug.h>
53 #include <rte_memory.h>
54 #include <rte_launch.h>
55 #include <rte_eal.h>
56 #include <rte_eal_memconfig.h>
57 #include <rte_errno.h>
58 #include <rte_per_lcore.h>
59 #include <rte_lcore.h>
60 #include <rte_service_component.h>
61 #include <rte_log.h>
62 #include <rte_random.h>
63 #include <rte_cycles.h>
64 #include <rte_string_fns.h>
65 #include <rte_cpuflags.h>
66 #include <rte_interrupts.h>
67 #include <rte_bus.h>
68 #include <rte_dev.h>
69 #include <rte_devargs.h>
70 #include <rte_version.h>
71 #include <rte_atomic.h>
72 #include <malloc_heap.h>
73
74 #include "eal_private.h"
75 #include "eal_thread.h"
76 #include "eal_internal_cfg.h"
77 #include "eal_filesystem.h"
78 #include "eal_hugepages.h"
79 #include "eal_options.h"
80
81 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
82
83 /* Allow the application to print its usage message too if set */
84 static rte_usage_hook_t rte_application_usage_hook = NULL;
85 /* early configuration structure, when memory config is not mmapped */
86 static struct rte_mem_config early_mem_config;
87
88 /* define fd variable here, because file needs to be kept open for the
89  * duration of the program, as we hold a write lock on it in the primary proc */
90 static int mem_cfg_fd = -1;
91
92 static struct flock wr_lock = {
93                 .l_type = F_WRLCK,
94                 .l_whence = SEEK_SET,
95                 .l_start = offsetof(struct rte_mem_config, memseg),
96                 .l_len = sizeof(early_mem_config.memseg),
97 };
98
99 /* Address of global and public configuration */
100 static struct rte_config rte_config = {
101                 .mem_config = &early_mem_config,
102 };
103
104 /* internal configuration (per-core) */
105 struct lcore_config lcore_config[RTE_MAX_LCORE];
106
107 /* internal configuration */
108 struct internal_config internal_config;
109
110 /* used by rte_rdtsc() */
111 int rte_cycles_vmware_tsc_map;
112
113 /* Return mbuf pool ops name */
114 const char *
115 rte_eal_mbuf_default_mempool_ops(void)
116 {
117         return internal_config.mbuf_pool_ops_name;
118 }
119
120 /* Return a pointer to the configuration structure */
121 struct rte_config *
122 rte_eal_get_configuration(void)
123 {
124         return &rte_config;
125 }
126
127 enum rte_iova_mode
128 rte_eal_iova_mode(void)
129 {
130         return rte_eal_get_configuration()->iova_mode;
131 }
132
133 /* parse a sysfs (or other) file containing one integer value */
134 int
135 eal_parse_sysfs_value(const char *filename, unsigned long *val)
136 {
137         FILE *f;
138         char buf[BUFSIZ];
139         char *end = NULL;
140
141         if ((f = fopen(filename, "r")) == NULL) {
142                 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
143                         __func__, filename);
144                 return -1;
145         }
146
147         if (fgets(buf, sizeof(buf), f) == NULL) {
148                 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
149                         __func__, filename);
150                 fclose(f);
151                 return -1;
152         }
153         *val = strtoul(buf, &end, 0);
154         if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
155                 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
156                                 __func__, filename);
157                 fclose(f);
158                 return -1;
159         }
160         fclose(f);
161         return 0;
162 }
163
164
165 /* create memory configuration in shared/mmap memory. Take out
166  * a write lock on the memsegs, so we can auto-detect primary/secondary.
167  * This means we never close the file while running (auto-close on exit).
168  * We also don't lock the whole file, so that in future we can use read-locks
169  * on other parts, e.g. memzones, to detect if there are running secondary
170  * processes. */
171 static void
172 rte_eal_config_create(void)
173 {
174         void *rte_mem_cfg_addr;
175         int retval;
176
177         const char *pathname = eal_runtime_config_path();
178
179         if (internal_config.no_shconf)
180                 return;
181
182         if (mem_cfg_fd < 0){
183                 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0660);
184                 if (mem_cfg_fd < 0)
185                         rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
186         }
187
188         retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
189         if (retval < 0){
190                 close(mem_cfg_fd);
191                 rte_panic("Cannot resize '%s' for rte_mem_config\n", pathname);
192         }
193
194         retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
195         if (retval < 0){
196                 close(mem_cfg_fd);
197                 rte_exit(EXIT_FAILURE, "Cannot create lock on '%s'. Is another primary "
198                                 "process running?\n", pathname);
199         }
200
201         rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
202                                 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
203
204         if (rte_mem_cfg_addr == MAP_FAILED){
205                 rte_panic("Cannot mmap memory for rte_config\n");
206         }
207         memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
208         rte_config.mem_config = rte_mem_cfg_addr;
209 }
210
211 /* attach to an existing shared memory config */
212 static void
213 rte_eal_config_attach(void)
214 {
215         void *rte_mem_cfg_addr;
216         const char *pathname = eal_runtime_config_path();
217
218         if (internal_config.no_shconf)
219                 return;
220
221         if (mem_cfg_fd < 0){
222                 mem_cfg_fd = open(pathname, O_RDWR);
223                 if (mem_cfg_fd < 0)
224                         rte_panic("Cannot open '%s' for rte_mem_config\n", pathname);
225         }
226
227         rte_mem_cfg_addr = mmap(NULL, sizeof(*rte_config.mem_config),
228                                 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
229         close(mem_cfg_fd);
230         if (rte_mem_cfg_addr == MAP_FAILED)
231                 rte_panic("Cannot mmap memory for rte_config\n");
232
233         rte_config.mem_config = rte_mem_cfg_addr;
234 }
235
236 /* Detect if we are a primary or a secondary process */
237 enum rte_proc_type_t
238 eal_proc_type_detect(void)
239 {
240         enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
241         const char *pathname = eal_runtime_config_path();
242
243         /* if we can open the file but not get a write-lock we are a secondary
244          * process. NOTE: if we get a file handle back, we keep that open
245          * and don't close it to prevent a race condition between multiple opens */
246         if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
247                         (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
248                 ptype = RTE_PROC_SECONDARY;
249
250         RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
251                         ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
252
253         return ptype;
254 }
255
256 /* Sets up rte_config structure with the pointer to shared memory config.*/
257 static void
258 rte_config_init(void)
259 {
260         rte_config.process_type = internal_config.process_type;
261
262         switch (rte_config.process_type){
263         case RTE_PROC_PRIMARY:
264                 rte_eal_config_create();
265                 break;
266         case RTE_PROC_SECONDARY:
267                 rte_eal_config_attach();
268                 rte_eal_mcfg_wait_complete(rte_config.mem_config);
269                 break;
270         case RTE_PROC_AUTO:
271         case RTE_PROC_INVALID:
272                 rte_panic("Invalid process type\n");
273         }
274 }
275
276 /* display usage */
277 static void
278 eal_usage(const char *prgname)
279 {
280         printf("\nUsage: %s ", prgname);
281         eal_common_usage();
282         /* Allow the application to print its usage message too if hook is set */
283         if ( rte_application_usage_hook ) {
284                 printf("===== Application Usage =====\n\n");
285                 rte_application_usage_hook(prgname);
286         }
287 }
288
289 /* Set a per-application usage message */
290 rte_usage_hook_t
291 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
292 {
293         rte_usage_hook_t        old_func;
294
295         /* Will be NULL on the first call to denote the last usage routine. */
296         old_func                                        = rte_application_usage_hook;
297         rte_application_usage_hook      = usage_func;
298
299         return old_func;
300 }
301
302 static inline size_t
303 eal_get_hugepage_mem_size(void)
304 {
305         uint64_t size = 0;
306         unsigned i, j;
307
308         for (i = 0; i < internal_config.num_hugepage_sizes; i++) {
309                 struct hugepage_info *hpi = &internal_config.hugepage_info[i];
310                 if (hpi->hugedir != NULL) {
311                         for (j = 0; j < RTE_MAX_NUMA_NODES; j++) {
312                                 size += hpi->hugepage_sz * hpi->num_pages[j];
313                         }
314                 }
315         }
316
317         return (size < SIZE_MAX) ? (size_t)(size) : SIZE_MAX;
318 }
319
320 /* Parse the arguments for --log-level only */
321 static void
322 eal_log_level_parse(int argc, char **argv)
323 {
324         int opt;
325         char **argvopt;
326         int option_index;
327         const int old_optind = optind;
328         const int old_optopt = optopt;
329         const int old_optreset = optreset;
330         char * const old_optarg = optarg;
331
332         argvopt = argv;
333         optind = 1;
334         optreset = 1;
335
336         while ((opt = getopt_long(argc, argvopt, eal_short_options,
337                                   eal_long_options, &option_index)) != EOF) {
338
339                 int ret;
340
341                 /* getopt is not happy, stop right now */
342                 if (opt == '?')
343                         break;
344
345                 ret = (opt == OPT_LOG_LEVEL_NUM) ?
346                         eal_parse_common_option(opt, optarg, &internal_config) : 0;
347
348                 /* common parser is not happy */
349                 if (ret < 0)
350                         break;
351         }
352
353         /* restore getopt lib */
354         optind = old_optind;
355         optopt = old_optopt;
356         optreset = old_optreset;
357         optarg = old_optarg;
358 }
359
360 /* Parse the argument given in the command line of the application */
361 static int
362 eal_parse_args(int argc, char **argv)
363 {
364         int opt, ret;
365         char **argvopt;
366         int option_index;
367         char *prgname = argv[0];
368         const int old_optind = optind;
369         const int old_optopt = optopt;
370         const int old_optreset = optreset;
371         char * const old_optarg = optarg;
372
373         argvopt = argv;
374         optind = 1;
375         optreset = 1;
376
377         while ((opt = getopt_long(argc, argvopt, eal_short_options,
378                                   eal_long_options, &option_index)) != EOF) {
379
380                 /* getopt is not happy, stop right now */
381                 if (opt == '?') {
382                         eal_usage(prgname);
383                         ret = -1;
384                         goto out;
385                 }
386
387                 ret = eal_parse_common_option(opt, optarg, &internal_config);
388                 /* common parser is not happy */
389                 if (ret < 0) {
390                         eal_usage(prgname);
391                         ret = -1;
392                         goto out;
393                 }
394                 /* common parser handled this option */
395                 if (ret == 0)
396                         continue;
397
398                 switch (opt) {
399                 case OPT_MBUF_POOL_OPS_NAME_NUM:
400                         internal_config.mbuf_pool_ops_name = optarg;
401                         break;
402                 case 'h':
403                         eal_usage(prgname);
404                         exit(EXIT_SUCCESS);
405                 default:
406                         if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
407                                 RTE_LOG(ERR, EAL, "Option %c is not supported "
408                                         "on FreeBSD\n", opt);
409                         } else if (opt >= OPT_LONG_MIN_NUM &&
410                                    opt < OPT_LONG_MAX_NUM) {
411                                 RTE_LOG(ERR, EAL, "Option %s is not supported "
412                                         "on FreeBSD\n",
413                                         eal_long_options[option_index].name);
414                         } else {
415                                 RTE_LOG(ERR, EAL, "Option %d is not supported "
416                                         "on FreeBSD\n", opt);
417                         }
418                         eal_usage(prgname);
419                         ret = -1;
420                         goto out;
421                 }
422         }
423
424         if (eal_adjust_config(&internal_config) != 0) {
425                 ret = -1;
426                 goto out;
427         }
428
429         /* sanity checks */
430         if (eal_check_common_options(&internal_config) != 0) {
431                 eal_usage(prgname);
432                 ret = -1;
433                 goto out;
434         }
435
436         if (optind >= 0)
437                 argv[optind-1] = prgname;
438         ret = optind-1;
439
440 out:
441         /* restore getopt lib */
442         optind = old_optind;
443         optopt = old_optopt;
444         optreset = old_optreset;
445         optarg = old_optarg;
446
447         return ret;
448 }
449
450 static void
451 eal_check_mem_on_local_socket(void)
452 {
453         const struct rte_memseg *ms;
454         int i, socket_id;
455
456         socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
457
458         ms = rte_eal_get_physmem_layout();
459
460         for (i = 0; i < RTE_MAX_MEMSEG; i++)
461                 if (ms[i].socket_id == socket_id &&
462                                 ms[i].len > 0)
463                         return;
464
465         RTE_LOG(WARNING, EAL, "WARNING: Master core has no "
466                         "memory on local socket!\n");
467 }
468
469 static int
470 sync_func(__attribute__((unused)) void *arg)
471 {
472         return 0;
473 }
474
475 inline static void
476 rte_eal_mcfg_complete(void)
477 {
478         /* ALL shared mem_config related INIT DONE */
479         if (rte_config.process_type == RTE_PROC_PRIMARY)
480                 rte_config.mem_config->magic = RTE_MAGIC;
481 }
482
483 /* return non-zero if hugepages are enabled. */
484 int rte_eal_has_hugepages(void)
485 {
486         return !internal_config.no_hugetlbfs;
487 }
488
489 /* Abstraction for port I/0 privilege */
490 int
491 rte_eal_iopl_init(void)
492 {
493         static int fd;
494
495         fd = open("/dev/io", O_RDWR);
496         if (fd < 0)
497                 return -1;
498         /* keep fd open for iopl */
499         return 0;
500 }
501
502 static void rte_eal_init_alert(const char *msg)
503 {
504         fprintf(stderr, "EAL: FATAL: %s\n", msg);
505         RTE_LOG(ERR, EAL, "%s\n", msg);
506 }
507
508 /* Launch threads, called at application init(). */
509 int
510 rte_eal_init(int argc, char **argv)
511 {
512         int i, fctret, ret;
513         pthread_t thread_id;
514         static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
515         char cpuset[RTE_CPU_AFFINITY_STR_LEN];
516         char thread_name[RTE_MAX_THREAD_NAME_LEN];
517
518         /* checks if the machine is adequate */
519         if (!rte_cpu_is_supported()) {
520                 rte_eal_init_alert("unsupported cpu type.");
521                 rte_errno = ENOTSUP;
522                 return -1;
523         }
524
525         if (!rte_atomic32_test_and_set(&run_once)) {
526                 rte_eal_init_alert("already called initialization.");
527                 rte_errno = EALREADY;
528                 return -1;
529         }
530
531         thread_id = pthread_self();
532
533         eal_reset_internal_config(&internal_config);
534
535         /* set log level as early as possible */
536         eal_log_level_parse(argc, argv);
537
538         if (rte_eal_cpu_init() < 0) {
539                 rte_eal_init_alert("Cannot detect lcores.");
540                 rte_errno = ENOTSUP;
541                 return -1;
542         }
543
544         fctret = eal_parse_args(argc, argv);
545         if (fctret < 0) {
546                 rte_eal_init_alert("Invalid 'command line' arguments.");
547                 rte_errno = EINVAL;
548                 rte_atomic32_clear(&run_once);
549                 return -1;
550         }
551
552         if (eal_plugins_init() < 0) {
553                 rte_eal_init_alert("Cannot init plugins\n");
554                 rte_errno = EINVAL;
555                 rte_atomic32_clear(&run_once);
556                 return -1;
557         }
558
559         if (eal_option_device_parse()) {
560                 rte_errno = ENODEV;
561                 rte_atomic32_clear(&run_once);
562                 return -1;
563         }
564
565         if (rte_bus_scan()) {
566                 rte_eal_init_alert("Cannot scan the buses for devices\n");
567                 rte_errno = ENODEV;
568                 rte_atomic32_clear(&run_once);
569                 return -1;
570         }
571
572         /* autodetect the iova mapping mode (default is iova_pa) */
573         rte_eal_get_configuration()->iova_mode = rte_bus_get_iommu_class();
574
575         if (internal_config.no_hugetlbfs == 0 &&
576                         internal_config.process_type != RTE_PROC_SECONDARY &&
577                         eal_hugepage_info_init() < 0) {
578                 rte_eal_init_alert("Cannot get hugepage information.");
579                 rte_errno = EACCES;
580                 rte_atomic32_clear(&run_once);
581                 return -1;
582         }
583
584         if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
585                 if (internal_config.no_hugetlbfs)
586                         internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
587                 else
588                         internal_config.memory = eal_get_hugepage_mem_size();
589         }
590
591         if (internal_config.vmware_tsc_map == 1) {
592 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
593                 rte_cycles_vmware_tsc_map = 1;
594                 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
595                                 "you must have monitor_control.pseudo_perfctr = TRUE\n");
596 #else
597                 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
598                                 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
599 #endif
600         }
601
602         rte_srand(rte_rdtsc());
603
604         rte_config_init();
605
606         if (rte_eal_memory_init() < 0) {
607                 rte_eal_init_alert("Cannot init memory\n");
608                 rte_errno = ENOMEM;
609                 return -1;
610         }
611
612         if (rte_eal_memzone_init() < 0) {
613                 rte_eal_init_alert("Cannot init memzone\n");
614                 rte_errno = ENODEV;
615                 return -1;
616         }
617
618         if (rte_eal_tailqs_init() < 0) {
619                 rte_eal_init_alert("Cannot init tail queues for objects\n");
620                 rte_errno = EFAULT;
621                 return -1;
622         }
623
624         if (rte_eal_alarm_init() < 0) {
625                 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
626                 /* rte_eal_alarm_init sets rte_errno on failure. */
627                 return -1;
628         }
629
630         if (rte_eal_intr_init() < 0) {
631                 rte_eal_init_alert("Cannot init interrupt-handling thread\n");
632                 return -1;
633         }
634
635         if (rte_eal_timer_init() < 0) {
636                 rte_eal_init_alert("Cannot init HPET or TSC timers\n");
637                 rte_errno = ENOTSUP;
638                 return -1;
639         }
640
641         eal_check_mem_on_local_socket();
642
643         eal_thread_init_master(rte_config.master_lcore);
644
645         ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
646
647         RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%p;cpuset=[%s%s])\n",
648                 rte_config.master_lcore, thread_id, cpuset,
649                 ret == 0 ? "" : "...");
650
651         RTE_LCORE_FOREACH_SLAVE(i) {
652
653                 /*
654                  * create communication pipes between master thread
655                  * and children
656                  */
657                 if (pipe(lcore_config[i].pipe_master2slave) < 0)
658                         rte_panic("Cannot create pipe\n");
659                 if (pipe(lcore_config[i].pipe_slave2master) < 0)
660                         rte_panic("Cannot create pipe\n");
661
662                 lcore_config[i].state = WAIT;
663
664                 /* create a thread for each lcore */
665                 ret = pthread_create(&lcore_config[i].thread_id, NULL,
666                                      eal_thread_loop, NULL);
667                 if (ret != 0)
668                         rte_panic("Cannot create thread\n");
669
670                 /* Set thread_name for aid in debugging. */
671                 snprintf(thread_name, RTE_MAX_THREAD_NAME_LEN,
672                                 "lcore-slave-%d", i);
673                 rte_thread_setname(lcore_config[i].thread_id, thread_name);
674         }
675
676         /*
677          * Launch a dummy function on all slave lcores, so that master lcore
678          * knows they are all ready when this function returns.
679          */
680         rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
681         rte_eal_mp_wait_lcore();
682
683         /* initialize services so vdevs register service during bus_probe. */
684         ret = rte_service_init();
685         if (ret) {
686                 rte_eal_init_alert("rte_service_init() failed\n");
687                 rte_errno = ENOEXEC;
688                 return -1;
689         }
690
691         /* Probe all the buses and devices/drivers on them */
692         if (rte_bus_probe()) {
693                 rte_eal_init_alert("Cannot probe devices\n");
694                 rte_errno = ENOTSUP;
695                 return -1;
696         }
697
698         /* initialize default service/lcore mappings and start running. Ignore
699          * -ENOTSUP, as it indicates no service coremask passed to EAL.
700          */
701         ret = rte_service_start_with_defaults();
702         if (ret < 0 && ret != -ENOTSUP) {
703                 rte_errno = ENOEXEC;
704                 return -1;
705         }
706
707         rte_eal_mcfg_complete();
708
709         return fctret;
710 }
711
712 /* get core role */
713 enum rte_lcore_role_t
714 rte_eal_lcore_role(unsigned lcore_id)
715 {
716         return rte_config.lcore_role[lcore_id];
717 }
718
719 enum rte_proc_type_t
720 rte_eal_process_type(void)
721 {
722         return rte_config.process_type;
723 }
724
725 int rte_eal_has_pci(void)
726 {
727         return !internal_config.no_pci;
728 }
729
730 int rte_eal_create_uio_dev(void)
731 {
732         return internal_config.create_uio_dev;
733 }
734
735 enum rte_intr_mode
736 rte_eal_vfio_intr_mode(void)
737 {
738         return RTE_INTR_MODE_NONE;
739 }
740
741 /* dummy forward declaration. */
742 struct vfio_device_info;
743
744 /* dummy prototypes. */
745 int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
746                 int *vfio_dev_fd, struct vfio_device_info *device_info);
747 int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd);
748 int rte_vfio_enable(const char *modname);
749 int rte_vfio_is_enabled(const char *modname);
750 int rte_vfio_noiommu_is_enabled(void);
751
752 int rte_vfio_setup_device(__rte_unused const char *sysfs_base,
753                       __rte_unused const char *dev_addr,
754                       __rte_unused int *vfio_dev_fd,
755                       __rte_unused struct vfio_device_info *device_info)
756 {
757         return -1;
758 }
759
760 int rte_vfio_release_device(__rte_unused const char *sysfs_base,
761                         __rte_unused const char *dev_addr,
762                         __rte_unused int fd)
763 {
764         return -1;
765 }
766
767 int rte_vfio_enable(__rte_unused const char *modname)
768 {
769         return -1;
770 }
771
772 int rte_vfio_is_enabled(__rte_unused const char *modname)
773 {
774         return 0;
775 }
776
777 int rte_vfio_noiommu_is_enabled(void)
778 {
779         return 0;
780 }