remove useless include of EAL memory config header
[dpdk.git] / lib / librte_eal / linux / eal / eal.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation.
3  * Copyright(c) 2012-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 <dirent.h>
17 #include <fcntl.h>
18 #include <fnmatch.h>
19 #include <stddef.h>
20 #include <errno.h>
21 #include <limits.h>
22 #include <sys/mman.h>
23 #include <sys/queue.h>
24 #include <sys/stat.h>
25 #if defined(RTE_ARCH_X86)
26 #include <sys/io.h>
27 #endif
28
29 #include <rte_compat.h>
30 #include <rte_common.h>
31 #include <rte_debug.h>
32 #include <rte_memory.h>
33 #include <rte_launch.h>
34 #include <rte_eal.h>
35 #include <rte_errno.h>
36 #include <rte_per_lcore.h>
37 #include <rte_lcore.h>
38 #include <rte_service_component.h>
39 #include <rte_log.h>
40 #include <rte_random.h>
41 #include <rte_cycles.h>
42 #include <rte_string_fns.h>
43 #include <rte_cpuflags.h>
44 #include <rte_interrupts.h>
45 #include <rte_bus.h>
46 #include <rte_dev.h>
47 #include <rte_devargs.h>
48 #include <rte_version.h>
49 #include <rte_atomic.h>
50 #include <malloc_heap.h>
51 #include <rte_vfio.h>
52 #include <rte_option.h>
53
54 #include "eal_private.h"
55 #include "eal_thread.h"
56 #include "eal_internal_cfg.h"
57 #include "eal_filesystem.h"
58 #include "eal_hugepages.h"
59 #include "eal_memcfg.h"
60 #include "eal_options.h"
61 #include "eal_vfio.h"
62 #include "hotplug_mp.h"
63
64 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
65
66 #define SOCKET_MEM_STRLEN (RTE_MAX_NUMA_NODES * 10)
67
68 #define KERNEL_IOMMU_GROUPS_PATH "/sys/kernel/iommu_groups"
69
70 /* Allow the application to print its usage message too if set */
71 static rte_usage_hook_t rte_application_usage_hook = NULL;
72
73 /* early configuration structure, when memory config is not mmapped */
74 static struct rte_mem_config early_mem_config;
75
76 /* define fd variable here, because file needs to be kept open for the
77  * duration of the program, as we hold a write lock on it in the primary proc */
78 static int mem_cfg_fd = -1;
79
80 static struct flock wr_lock = {
81                 .l_type = F_WRLCK,
82                 .l_whence = SEEK_SET,
83                 .l_start = offsetof(struct rte_mem_config, memsegs),
84                 .l_len = sizeof(early_mem_config.memsegs),
85 };
86
87 /* Address of global and public configuration */
88 static struct rte_config rte_config = {
89                 .mem_config = &early_mem_config,
90 };
91
92 /* internal configuration (per-core) */
93 struct lcore_config lcore_config[RTE_MAX_LCORE];
94
95 /* internal configuration */
96 struct internal_config internal_config;
97
98 /* used by rte_rdtsc() */
99 int rte_cycles_vmware_tsc_map;
100
101 /* platform-specific runtime dir */
102 static char runtime_dir[PATH_MAX];
103
104 static const char *default_runtime_dir = "/var/run";
105
106 int
107 eal_create_runtime_dir(void)
108 {
109         const char *directory = default_runtime_dir;
110         const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
111         const char *fallback = "/tmp";
112         char tmp[PATH_MAX];
113         int ret;
114
115         if (getuid() != 0) {
116                 /* try XDG path first, fall back to /tmp */
117                 if (xdg_runtime_dir != NULL)
118                         directory = xdg_runtime_dir;
119                 else
120                         directory = fallback;
121         }
122         /* create DPDK subdirectory under runtime dir */
123         ret = snprintf(tmp, sizeof(tmp), "%s/dpdk", directory);
124         if (ret < 0 || ret == sizeof(tmp)) {
125                 RTE_LOG(ERR, EAL, "Error creating DPDK runtime path name\n");
126                 return -1;
127         }
128
129         /* create prefix-specific subdirectory under DPDK runtime dir */
130         ret = snprintf(runtime_dir, sizeof(runtime_dir), "%s/%s",
131                         tmp, eal_get_hugefile_prefix());
132         if (ret < 0 || ret == sizeof(runtime_dir)) {
133                 RTE_LOG(ERR, EAL, "Error creating prefix-specific runtime path name\n");
134                 return -1;
135         }
136
137         /* create the path if it doesn't exist. no "mkdir -p" here, so do it
138          * step by step.
139          */
140         ret = mkdir(tmp, 0700);
141         if (ret < 0 && errno != EEXIST) {
142                 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
143                         tmp, strerror(errno));
144                 return -1;
145         }
146
147         ret = mkdir(runtime_dir, 0700);
148         if (ret < 0 && errno != EEXIST) {
149                 RTE_LOG(ERR, EAL, "Error creating '%s': %s\n",
150                         runtime_dir, strerror(errno));
151                 return -1;
152         }
153
154         return 0;
155 }
156
157 int
158 eal_clean_runtime_dir(void)
159 {
160         DIR *dir;
161         struct dirent *dirent;
162         int dir_fd, fd, lck_result;
163         static const char * const filters[] = {
164                 "fbarray_*",
165                 "mp_socket_*"
166         };
167
168         /* open directory */
169         dir = opendir(runtime_dir);
170         if (!dir) {
171                 RTE_LOG(ERR, EAL, "Unable to open runtime directory %s\n",
172                                 runtime_dir);
173                 goto error;
174         }
175         dir_fd = dirfd(dir);
176
177         /* lock the directory before doing anything, to avoid races */
178         if (flock(dir_fd, LOCK_EX) < 0) {
179                 RTE_LOG(ERR, EAL, "Unable to lock runtime directory %s\n",
180                         runtime_dir);
181                 goto error;
182         }
183
184         dirent = readdir(dir);
185         if (!dirent) {
186                 RTE_LOG(ERR, EAL, "Unable to read runtime directory %s\n",
187                                 runtime_dir);
188                 goto error;
189         }
190
191         while (dirent != NULL) {
192                 unsigned int f_idx;
193                 bool skip = true;
194
195                 /* skip files that don't match the patterns */
196                 for (f_idx = 0; f_idx < RTE_DIM(filters); f_idx++) {
197                         const char *filter = filters[f_idx];
198
199                         if (fnmatch(filter, dirent->d_name, 0) == 0) {
200                                 skip = false;
201                                 break;
202                         }
203                 }
204                 if (skip) {
205                         dirent = readdir(dir);
206                         continue;
207                 }
208
209                 /* try and lock the file */
210                 fd = openat(dir_fd, dirent->d_name, O_RDONLY);
211
212                 /* skip to next file */
213                 if (fd == -1) {
214                         dirent = readdir(dir);
215                         continue;
216                 }
217
218                 /* non-blocking lock */
219                 lck_result = flock(fd, LOCK_EX | LOCK_NB);
220
221                 /* if lock succeeds, remove the file */
222                 if (lck_result != -1)
223                         unlinkat(dir_fd, dirent->d_name, 0);
224                 close(fd);
225                 dirent = readdir(dir);
226         }
227
228         /* closedir closes dir_fd and drops the lock */
229         closedir(dir);
230         return 0;
231
232 error:
233         if (dir)
234                 closedir(dir);
235
236         RTE_LOG(ERR, EAL, "Error while clearing runtime dir: %s\n",
237                 strerror(errno));
238
239         return -1;
240 }
241
242 const char *
243 rte_eal_get_runtime_dir(void)
244 {
245         return runtime_dir;
246 }
247
248 /* Return user provided mbuf pool ops name */
249 const char *
250 rte_eal_mbuf_user_pool_ops(void)
251 {
252         return internal_config.user_mbuf_pool_ops_name;
253 }
254
255 /* Return a pointer to the configuration structure */
256 struct rte_config *
257 rte_eal_get_configuration(void)
258 {
259         return &rte_config;
260 }
261
262 enum rte_iova_mode
263 rte_eal_iova_mode(void)
264 {
265         return rte_eal_get_configuration()->iova_mode;
266 }
267
268 /* parse a sysfs (or other) file containing one integer value */
269 int
270 eal_parse_sysfs_value(const char *filename, unsigned long *val)
271 {
272         FILE *f;
273         char buf[BUFSIZ];
274         char *end = NULL;
275
276         if ((f = fopen(filename, "r")) == NULL) {
277                 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
278                         __func__, filename);
279                 return -1;
280         }
281
282         if (fgets(buf, sizeof(buf), f) == NULL) {
283                 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
284                         __func__, filename);
285                 fclose(f);
286                 return -1;
287         }
288         *val = strtoul(buf, &end, 0);
289         if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
290                 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
291                                 __func__, filename);
292                 fclose(f);
293                 return -1;
294         }
295         fclose(f);
296         return 0;
297 }
298
299
300 /* create memory configuration in shared/mmap memory. Take out
301  * a write lock on the memsegs, so we can auto-detect primary/secondary.
302  * This means we never close the file while running (auto-close on exit).
303  * We also don't lock the whole file, so that in future we can use read-locks
304  * on other parts, e.g. memzones, to detect if there are running secondary
305  * processes. */
306 static int
307 rte_eal_config_create(void)
308 {
309         void *rte_mem_cfg_addr;
310         int retval;
311
312         const char *pathname = eal_runtime_config_path();
313
314         if (internal_config.no_shconf)
315                 return 0;
316
317         /* map the config before hugepage address so that we don't waste a page */
318         if (internal_config.base_virtaddr != 0)
319                 rte_mem_cfg_addr = (void *)
320                         RTE_ALIGN_FLOOR(internal_config.base_virtaddr -
321                         sizeof(struct rte_mem_config), sysconf(_SC_PAGE_SIZE));
322         else
323                 rte_mem_cfg_addr = NULL;
324
325         if (mem_cfg_fd < 0){
326                 mem_cfg_fd = open(pathname, O_RDWR | O_CREAT, 0600);
327                 if (mem_cfg_fd < 0) {
328                         RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
329                                 pathname);
330                         return -1;
331                 }
332         }
333
334         retval = ftruncate(mem_cfg_fd, sizeof(*rte_config.mem_config));
335         if (retval < 0){
336                 close(mem_cfg_fd);
337                 mem_cfg_fd = -1;
338                 RTE_LOG(ERR, EAL, "Cannot resize '%s' for rte_mem_config\n",
339                         pathname);
340                 return -1;
341         }
342
343         retval = fcntl(mem_cfg_fd, F_SETLK, &wr_lock);
344         if (retval < 0){
345                 close(mem_cfg_fd);
346                 mem_cfg_fd = -1;
347                 RTE_LOG(ERR, EAL, "Cannot create lock on '%s'. Is another primary "
348                         "process running?\n", pathname);
349                 return -1;
350         }
351
352         rte_mem_cfg_addr = mmap(rte_mem_cfg_addr, sizeof(*rte_config.mem_config),
353                                 PROT_READ | PROT_WRITE, MAP_SHARED, mem_cfg_fd, 0);
354
355         if (rte_mem_cfg_addr == MAP_FAILED){
356                 close(mem_cfg_fd);
357                 mem_cfg_fd = -1;
358                 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config\n");
359                 return -1;
360         }
361
362         memcpy(rte_mem_cfg_addr, &early_mem_config, sizeof(early_mem_config));
363         rte_config.mem_config = rte_mem_cfg_addr;
364
365         /* store address of the config in the config itself so that secondary
366          * processes could later map the config into this exact location */
367         rte_config.mem_config->mem_cfg_addr = (uintptr_t) rte_mem_cfg_addr;
368
369         rte_config.mem_config->dma_maskbits = 0;
370
371         return 0;
372 }
373
374 /* attach to an existing shared memory config */
375 static int
376 rte_eal_config_attach(void)
377 {
378         struct rte_mem_config *mem_config;
379
380         const char *pathname = eal_runtime_config_path();
381
382         if (internal_config.no_shconf)
383                 return 0;
384
385         if (mem_cfg_fd < 0){
386                 mem_cfg_fd = open(pathname, O_RDWR);
387                 if (mem_cfg_fd < 0) {
388                         RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
389                                 pathname);
390                         return -1;
391                 }
392         }
393
394         /* map it as read-only first */
395         mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
396                         PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
397         if (mem_config == MAP_FAILED) {
398                 close(mem_cfg_fd);
399                 mem_cfg_fd = -1;
400                 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
401                         errno, strerror(errno));
402                 return -1;
403         }
404
405         rte_config.mem_config = mem_config;
406
407         return 0;
408 }
409
410 /* reattach the shared config at exact memory location primary process has it */
411 static int
412 rte_eal_config_reattach(void)
413 {
414         struct rte_mem_config *mem_config;
415         void *rte_mem_cfg_addr;
416
417         if (internal_config.no_shconf)
418                 return 0;
419
420         /* save the address primary process has mapped shared config to */
421         rte_mem_cfg_addr = (void *) (uintptr_t) rte_config.mem_config->mem_cfg_addr;
422
423         /* unmap original config */
424         munmap(rte_config.mem_config, sizeof(struct rte_mem_config));
425
426         /* remap the config at proper address */
427         mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
428                         sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
429                         mem_cfg_fd, 0);
430
431         close(mem_cfg_fd);
432         mem_cfg_fd = -1;
433
434         if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
435                 if (mem_config != MAP_FAILED) {
436                         /* errno is stale, don't use */
437                         RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config at [%p], got [%p]"
438                                 " - please use '--base-virtaddr' option\n",
439                                 rte_mem_cfg_addr, mem_config);
440                         return -1;
441                 }
442                 RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
443                         errno, strerror(errno));
444                 return -1;
445         }
446
447         rte_config.mem_config = mem_config;
448
449         return 0;
450 }
451
452 /* Detect if we are a primary or a secondary process */
453 enum rte_proc_type_t
454 eal_proc_type_detect(void)
455 {
456         enum rte_proc_type_t ptype = RTE_PROC_PRIMARY;
457         const char *pathname = eal_runtime_config_path();
458
459         /* if there no shared config, there can be no secondary processes */
460         if (!internal_config.no_shconf) {
461                 /* if we can open the file but not get a write-lock we are a
462                  * secondary process. NOTE: if we get a file handle back, we
463                  * keep that open and don't close it to prevent a race condition
464                  * between multiple opens.
465                  */
466                 if (((mem_cfg_fd = open(pathname, O_RDWR)) >= 0) &&
467                                 (fcntl(mem_cfg_fd, F_SETLK, &wr_lock) < 0))
468                         ptype = RTE_PROC_SECONDARY;
469         }
470
471         RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n",
472                         ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY");
473
474         return ptype;
475 }
476
477 /* Sets up rte_config structure with the pointer to shared memory config.*/
478 static int
479 rte_config_init(void)
480 {
481         rte_config.process_type = internal_config.process_type;
482
483         switch (rte_config.process_type){
484         case RTE_PROC_PRIMARY:
485                 if (rte_eal_config_create() < 0)
486                         return -1;
487                 eal_mcfg_update_from_internal();
488                 break;
489         case RTE_PROC_SECONDARY:
490                 if (rte_eal_config_attach() < 0)
491                         return -1;
492                 eal_mcfg_wait_complete();
493                 if (eal_mcfg_check_version() < 0) {
494                         RTE_LOG(ERR, EAL, "Primary and secondary process DPDK version mismatch\n");
495                         return -1;
496                 }
497                 if (rte_eal_config_reattach() < 0)
498                         return -1;
499                 eal_mcfg_update_internal();
500                 break;
501         case RTE_PROC_AUTO:
502         case RTE_PROC_INVALID:
503                 RTE_LOG(ERR, EAL, "Invalid process type %d\n",
504                         rte_config.process_type);
505                 return -1;
506         }
507
508         return 0;
509 }
510
511 /* Unlocks hugepage directories that were locked by eal_hugepage_info_init */
512 static void
513 eal_hugedirs_unlock(void)
514 {
515         int i;
516
517         for (i = 0; i < MAX_HUGEPAGE_SIZES; i++)
518         {
519                 /* skip uninitialized */
520                 if (internal_config.hugepage_info[i].lock_descriptor < 0)
521                         continue;
522                 /* unlock hugepage file */
523                 flock(internal_config.hugepage_info[i].lock_descriptor, LOCK_UN);
524                 close(internal_config.hugepage_info[i].lock_descriptor);
525                 /* reset the field */
526                 internal_config.hugepage_info[i].lock_descriptor = -1;
527         }
528 }
529
530 /* display usage */
531 static void
532 eal_usage(const char *prgname)
533 {
534         printf("\nUsage: %s ", prgname);
535         eal_common_usage();
536         printf("EAL Linux options:\n"
537                "  --"OPT_SOCKET_MEM"        Memory to allocate on sockets (comma separated values)\n"
538                "  --"OPT_SOCKET_LIMIT"      Limit memory allocation on sockets (comma separated values)\n"
539                "  --"OPT_HUGE_DIR"          Directory where hugetlbfs is mounted\n"
540                "  --"OPT_FILE_PREFIX"       Prefix for hugepage filenames\n"
541                "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
542                "  --"OPT_CREATE_UIO_DEV"    Create /dev/uioX (usually done by hotplug)\n"
543                "  --"OPT_VFIO_INTR"         Interrupt mode for VFIO (legacy|msi|msix)\n"
544                "  --"OPT_LEGACY_MEM"        Legacy memory mode (no dynamic allocation, contiguous segments)\n"
545                "  --"OPT_SINGLE_FILE_SEGMENTS" Put all hugepage memory in single files\n"
546                "  --"OPT_MATCH_ALLOCATIONS" Free hugepages exactly as allocated\n"
547                "\n");
548         /* Allow the application to print its usage message too if hook is set */
549         if ( rte_application_usage_hook ) {
550                 printf("===== Application Usage =====\n\n");
551                 rte_application_usage_hook(prgname);
552         }
553 }
554
555 /* Set a per-application usage message */
556 rte_usage_hook_t
557 rte_set_application_usage_hook( rte_usage_hook_t usage_func )
558 {
559         rte_usage_hook_t        old_func;
560
561         /* Will be NULL on the first call to denote the last usage routine. */
562         old_func                                        = rte_application_usage_hook;
563         rte_application_usage_hook      = usage_func;
564
565         return old_func;
566 }
567
568 static int
569 eal_parse_socket_arg(char *strval, volatile uint64_t *socket_arg)
570 {
571         char * arg[RTE_MAX_NUMA_NODES];
572         char *end;
573         int arg_num, i, len;
574         uint64_t total_mem = 0;
575
576         len = strnlen(strval, SOCKET_MEM_STRLEN);
577         if (len == SOCKET_MEM_STRLEN) {
578                 RTE_LOG(ERR, EAL, "--socket-mem is too long\n");
579                 return -1;
580         }
581
582         /* all other error cases will be caught later */
583         if (!isdigit(strval[len-1]))
584                 return -1;
585
586         /* split the optarg into separate socket values */
587         arg_num = rte_strsplit(strval, len,
588                         arg, RTE_MAX_NUMA_NODES, ',');
589
590         /* if split failed, or 0 arguments */
591         if (arg_num <= 0)
592                 return -1;
593
594         /* parse each defined socket option */
595         errno = 0;
596         for (i = 0; i < arg_num; i++) {
597                 uint64_t val;
598                 end = NULL;
599                 val = strtoull(arg[i], &end, 10);
600
601                 /* check for invalid input */
602                 if ((errno != 0)  ||
603                                 (arg[i][0] == '\0') || (end == NULL) || (*end != '\0'))
604                         return -1;
605                 val <<= 20;
606                 total_mem += val;
607                 socket_arg[i] = val;
608         }
609
610         return 0;
611 }
612
613 static int
614 eal_parse_base_virtaddr(const char *arg)
615 {
616         char *end;
617         uint64_t addr;
618
619         errno = 0;
620         addr = strtoull(arg, &end, 16);
621
622         /* check for errors */
623         if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
624                 return -1;
625
626         /* make sure we don't exceed 32-bit boundary on 32-bit target */
627 #ifndef RTE_ARCH_64
628         if (addr >= UINTPTR_MAX)
629                 return -1;
630 #endif
631
632         /* align the addr on 16M boundary, 16MB is the minimum huge page
633          * size on IBM Power architecture. If the addr is aligned to 16MB,
634          * it can align to 2MB for x86. So this alignment can also be used
635          * on x86 */
636         internal_config.base_virtaddr =
637                 RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
638
639         return 0;
640 }
641
642 static int
643 eal_parse_vfio_intr(const char *mode)
644 {
645         unsigned i;
646         static struct {
647                 const char *name;
648                 enum rte_intr_mode value;
649         } map[] = {
650                 { "legacy", RTE_INTR_MODE_LEGACY },
651                 { "msi", RTE_INTR_MODE_MSI },
652                 { "msix", RTE_INTR_MODE_MSIX },
653         };
654
655         for (i = 0; i < RTE_DIM(map); i++) {
656                 if (!strcmp(mode, map[i].name)) {
657                         internal_config.vfio_intr_mode = map[i].value;
658                         return 0;
659                 }
660         }
661         return -1;
662 }
663
664 /* Parse the arguments for --log-level only */
665 static void
666 eal_log_level_parse(int argc, char **argv)
667 {
668         int opt;
669         char **argvopt;
670         int option_index;
671         const int old_optind = optind;
672         const int old_optopt = optopt;
673         char * const old_optarg = optarg;
674
675         argvopt = argv;
676         optind = 1;
677
678         while ((opt = getopt_long(argc, argvopt, eal_short_options,
679                                   eal_long_options, &option_index)) != EOF) {
680
681                 int ret;
682
683                 /* getopt is not happy, stop right now */
684                 if (opt == '?')
685                         break;
686
687                 ret = (opt == OPT_LOG_LEVEL_NUM) ?
688                         eal_parse_common_option(opt, optarg, &internal_config) : 0;
689
690                 /* common parser is not happy */
691                 if (ret < 0)
692                         break;
693         }
694
695         /* restore getopt lib */
696         optind = old_optind;
697         optopt = old_optopt;
698         optarg = old_optarg;
699 }
700
701 /* Parse the argument given in the command line of the application */
702 static int
703 eal_parse_args(int argc, char **argv)
704 {
705         int opt, ret;
706         char **argvopt;
707         int option_index;
708         char *prgname = argv[0];
709         const int old_optind = optind;
710         const int old_optopt = optopt;
711         char * const old_optarg = optarg;
712
713         argvopt = argv;
714         optind = 1;
715         opterr = 0;
716
717         while ((opt = getopt_long(argc, argvopt, eal_short_options,
718                                   eal_long_options, &option_index)) != EOF) {
719
720                 /*
721                  * getopt didn't recognise the option, lets parse the
722                  * registered options to see if the flag is valid
723                  */
724                 if (opt == '?') {
725                         ret = rte_option_parse(argv[optind-1]);
726                         if (ret == 0)
727                                 continue;
728
729                         eal_usage(prgname);
730                         ret = -1;
731                         goto out;
732                 }
733
734                 ret = eal_parse_common_option(opt, optarg, &internal_config);
735                 /* common parser is not happy */
736                 if (ret < 0) {
737                         eal_usage(prgname);
738                         ret = -1;
739                         goto out;
740                 }
741                 /* common parser handled this option */
742                 if (ret == 0)
743                         continue;
744
745                 switch (opt) {
746                 case 'h':
747                         eal_usage(prgname);
748                         exit(EXIT_SUCCESS);
749
750                 case OPT_HUGE_DIR_NUM:
751                 {
752                         char *hdir = strdup(optarg);
753                         if (hdir == NULL)
754                                 RTE_LOG(ERR, EAL, "Could not store hugepage directory\n");
755                         else {
756                                 /* free old hugepage dir */
757                                 if (internal_config.hugepage_dir != NULL)
758                                         free(internal_config.hugepage_dir);
759                                 internal_config.hugepage_dir = hdir;
760                         }
761                         break;
762                 }
763                 case OPT_FILE_PREFIX_NUM:
764                 {
765                         char *prefix = strdup(optarg);
766                         if (prefix == NULL)
767                                 RTE_LOG(ERR, EAL, "Could not store file prefix\n");
768                         else {
769                                 /* free old prefix */
770                                 if (internal_config.hugefile_prefix != NULL)
771                                         free(internal_config.hugefile_prefix);
772                                 internal_config.hugefile_prefix = prefix;
773                         }
774                         break;
775                 }
776                 case OPT_SOCKET_MEM_NUM:
777                         if (eal_parse_socket_arg(optarg,
778                                         internal_config.socket_mem) < 0) {
779                                 RTE_LOG(ERR, EAL, "invalid parameters for --"
780                                                 OPT_SOCKET_MEM "\n");
781                                 eal_usage(prgname);
782                                 ret = -1;
783                                 goto out;
784                         }
785                         internal_config.force_sockets = 1;
786                         break;
787
788                 case OPT_SOCKET_LIMIT_NUM:
789                         if (eal_parse_socket_arg(optarg,
790                                         internal_config.socket_limit) < 0) {
791                                 RTE_LOG(ERR, EAL, "invalid parameters for --"
792                                                 OPT_SOCKET_LIMIT "\n");
793                                 eal_usage(prgname);
794                                 ret = -1;
795                                 goto out;
796                         }
797                         internal_config.force_socket_limits = 1;
798                         break;
799
800                 case OPT_BASE_VIRTADDR_NUM:
801                         if (eal_parse_base_virtaddr(optarg) < 0) {
802                                 RTE_LOG(ERR, EAL, "invalid parameter for --"
803                                                 OPT_BASE_VIRTADDR "\n");
804                                 eal_usage(prgname);
805                                 ret = -1;
806                                 goto out;
807                         }
808                         break;
809
810                 case OPT_VFIO_INTR_NUM:
811                         if (eal_parse_vfio_intr(optarg) < 0) {
812                                 RTE_LOG(ERR, EAL, "invalid parameters for --"
813                                                 OPT_VFIO_INTR "\n");
814                                 eal_usage(prgname);
815                                 ret = -1;
816                                 goto out;
817                         }
818                         break;
819
820                 case OPT_CREATE_UIO_DEV_NUM:
821                         internal_config.create_uio_dev = 1;
822                         break;
823
824                 case OPT_MBUF_POOL_OPS_NAME_NUM:
825                 {
826                         char *ops_name = strdup(optarg);
827                         if (ops_name == NULL)
828                                 RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n");
829                         else {
830                                 /* free old ops name */
831                                 if (internal_config.user_mbuf_pool_ops_name !=
832                                                 NULL)
833                                         free(internal_config.user_mbuf_pool_ops_name);
834
835                                 internal_config.user_mbuf_pool_ops_name =
836                                                 ops_name;
837                         }
838                         break;
839                 }
840                 case OPT_MATCH_ALLOCATIONS_NUM:
841                         internal_config.match_allocations = 1;
842                         break;
843
844                 default:
845                         if (opt < OPT_LONG_MIN_NUM && isprint(opt)) {
846                                 RTE_LOG(ERR, EAL, "Option %c is not supported "
847                                         "on Linux\n", opt);
848                         } else if (opt >= OPT_LONG_MIN_NUM &&
849                                    opt < OPT_LONG_MAX_NUM) {
850                                 RTE_LOG(ERR, EAL, "Option %s is not supported "
851                                         "on Linux\n",
852                                         eal_long_options[option_index].name);
853                         } else {
854                                 RTE_LOG(ERR, EAL, "Option %d is not supported "
855                                         "on Linux\n", opt);
856                         }
857                         eal_usage(prgname);
858                         ret = -1;
859                         goto out;
860                 }
861         }
862
863         /* create runtime data directory */
864         if (internal_config.no_shconf == 0 &&
865                         eal_create_runtime_dir() < 0) {
866                 RTE_LOG(ERR, EAL, "Cannot create runtime directory\n");
867                 ret = -1;
868                 goto out;
869         }
870
871         if (eal_adjust_config(&internal_config) != 0) {
872                 ret = -1;
873                 goto out;
874         }
875
876         /* sanity checks */
877         if (eal_check_common_options(&internal_config) != 0) {
878                 eal_usage(prgname);
879                 ret = -1;
880                 goto out;
881         }
882
883         if (optind >= 0)
884                 argv[optind-1] = prgname;
885         ret = optind-1;
886
887 out:
888         /* restore getopt lib */
889         optind = old_optind;
890         optopt = old_optopt;
891         optarg = old_optarg;
892
893         return ret;
894 }
895
896 static int
897 check_socket(const struct rte_memseg_list *msl, void *arg)
898 {
899         int *socket_id = arg;
900
901         if (msl->external)
902                 return 0;
903
904         return *socket_id == msl->socket_id;
905 }
906
907 static void
908 eal_check_mem_on_local_socket(void)
909 {
910         int socket_id;
911
912         socket_id = rte_lcore_to_socket_id(rte_config.master_lcore);
913
914         if (rte_memseg_list_walk(check_socket, &socket_id) == 0)
915                 RTE_LOG(WARNING, EAL, "WARNING: Master core has no memory on local socket!\n");
916 }
917
918 static int
919 sync_func(__attribute__((unused)) void *arg)
920 {
921         return 0;
922 }
923
924 /*
925  * Request iopl privilege for all RPL, returns 0 on success
926  * iopl() call is mostly for the i386 architecture. For other architectures,
927  * return -1 to indicate IO privilege can't be changed in this way.
928  */
929 int
930 rte_eal_iopl_init(void)
931 {
932 #if defined(RTE_ARCH_X86)
933         if (iopl(3) != 0)
934                 return -1;
935 #endif
936         return 0;
937 }
938
939 #ifdef VFIO_PRESENT
940 static int rte_eal_vfio_setup(void)
941 {
942         if (rte_vfio_enable("vfio"))
943                 return -1;
944
945         return 0;
946 }
947 #endif
948
949 static void rte_eal_init_alert(const char *msg)
950 {
951         fprintf(stderr, "EAL: FATAL: %s\n", msg);
952         RTE_LOG(ERR, EAL, "%s\n", msg);
953 }
954
955 /*
956  * On Linux 3.6+, even if VFIO is not loaded, whenever IOMMU is enabled in the
957  * BIOS and in the kernel, /sys/kernel/iommu_groups path will contain kernel
958  * IOMMU groups. If IOMMU is not enabled, that path would be empty.
959  * Therefore, checking if the path is empty will tell us if IOMMU is enabled.
960  */
961 static bool
962 is_iommu_enabled(void)
963 {
964         DIR *dir = opendir(KERNEL_IOMMU_GROUPS_PATH);
965         struct dirent *d;
966         int n = 0;
967
968         /* if directory doesn't exist, assume IOMMU is not enabled */
969         if (dir == NULL)
970                 return false;
971
972         while ((d = readdir(dir)) != NULL) {
973                 /* skip dot and dot-dot */
974                 if (++n > 2)
975                         break;
976         }
977         closedir(dir);
978
979         return n > 2;
980 }
981
982 /* Launch threads, called at application init(). */
983 int
984 rte_eal_init(int argc, char **argv)
985 {
986         int i, fctret, ret;
987         pthread_t thread_id;
988         static rte_atomic32_t run_once = RTE_ATOMIC32_INIT(0);
989         const char *p;
990         static char logid[PATH_MAX];
991         char cpuset[RTE_CPU_AFFINITY_STR_LEN];
992         char thread_name[RTE_MAX_THREAD_NAME_LEN];
993         bool phys_addrs;
994
995         /* checks if the machine is adequate */
996         if (!rte_cpu_is_supported()) {
997                 rte_eal_init_alert("unsupported cpu type.");
998                 rte_errno = ENOTSUP;
999                 return -1;
1000         }
1001
1002         if (!rte_atomic32_test_and_set(&run_once)) {
1003                 rte_eal_init_alert("already called initialization.");
1004                 rte_errno = EALREADY;
1005                 return -1;
1006         }
1007
1008         p = strrchr(argv[0], '/');
1009         strlcpy(logid, p ? p + 1 : argv[0], sizeof(logid));
1010         thread_id = pthread_self();
1011
1012         eal_reset_internal_config(&internal_config);
1013
1014         /* set log level as early as possible */
1015         eal_log_level_parse(argc, argv);
1016
1017         if (rte_eal_cpu_init() < 0) {
1018                 rte_eal_init_alert("Cannot detect lcores.");
1019                 rte_errno = ENOTSUP;
1020                 return -1;
1021         }
1022
1023         fctret = eal_parse_args(argc, argv);
1024         if (fctret < 0) {
1025                 rte_eal_init_alert("Invalid 'command line' arguments.");
1026                 rte_errno = EINVAL;
1027                 rte_atomic32_clear(&run_once);
1028                 return -1;
1029         }
1030
1031         if (eal_plugins_init() < 0) {
1032                 rte_eal_init_alert("Cannot init plugins");
1033                 rte_errno = EINVAL;
1034                 rte_atomic32_clear(&run_once);
1035                 return -1;
1036         }
1037
1038         if (eal_option_device_parse()) {
1039                 rte_errno = ENODEV;
1040                 rte_atomic32_clear(&run_once);
1041                 return -1;
1042         }
1043
1044         if (rte_config_init() < 0) {
1045                 rte_eal_init_alert("Cannot init config");
1046                 return -1;
1047         }
1048
1049         if (rte_eal_intr_init() < 0) {
1050                 rte_eal_init_alert("Cannot init interrupt-handling thread");
1051                 return -1;
1052         }
1053
1054         if (rte_eal_alarm_init() < 0) {
1055                 rte_eal_init_alert("Cannot init alarm");
1056                 /* rte_eal_alarm_init sets rte_errno on failure. */
1057                 return -1;
1058         }
1059
1060         /* Put mp channel init before bus scan so that we can init the vdev
1061          * bus through mp channel in the secondary process before the bus scan.
1062          */
1063         if (rte_mp_channel_init() < 0 && rte_errno != ENOTSUP) {
1064                 rte_eal_init_alert("failed to init mp channel");
1065                 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1066                         rte_errno = EFAULT;
1067                         return -1;
1068                 }
1069         }
1070
1071         /* register multi-process action callbacks for hotplug */
1072         if (eal_mp_dev_hotplug_init() < 0) {
1073                 rte_eal_init_alert("failed to register mp callback for hotplug");
1074                 return -1;
1075         }
1076
1077         if (rte_bus_scan()) {
1078                 rte_eal_init_alert("Cannot scan the buses for devices");
1079                 rte_errno = ENODEV;
1080                 rte_atomic32_clear(&run_once);
1081                 return -1;
1082         }
1083
1084         phys_addrs = rte_eal_using_phys_addrs() != 0;
1085
1086         /* if no EAL option "--iova-mode=<pa|va>", use bus IOVA scheme */
1087         if (internal_config.iova_mode == RTE_IOVA_DC) {
1088                 /* autodetect the IOVA mapping mode */
1089                 enum rte_iova_mode iova_mode = rte_bus_get_iommu_class();
1090
1091                 if (iova_mode == RTE_IOVA_DC) {
1092                         RTE_LOG(DEBUG, EAL, "Buses did not request a specific IOVA mode.\n");
1093
1094                         if (!phys_addrs) {
1095                                 /* if we have no access to physical addresses,
1096                                  * pick IOVA as VA mode.
1097                                  */
1098                                 iova_mode = RTE_IOVA_VA;
1099                                 RTE_LOG(DEBUG, EAL, "Physical addresses are unavailable, selecting IOVA as VA mode.\n");
1100                         } else if (is_iommu_enabled()) {
1101                                 /* we have an IOMMU, pick IOVA as VA mode */
1102                                 iova_mode = RTE_IOVA_VA;
1103                                 RTE_LOG(DEBUG, EAL, "IOMMU is available, selecting IOVA as VA mode.\n");
1104                         } else {
1105                                 /* physical addresses available, and no IOMMU
1106                                  * found, so pick IOVA as PA.
1107                                  */
1108                                 iova_mode = RTE_IOVA_PA;
1109                                 RTE_LOG(DEBUG, EAL, "IOMMU is not available, selecting IOVA as PA mode.\n");
1110                         }
1111                 }
1112 #ifdef RTE_LIBRTE_KNI
1113                 /* Workaround for KNI which requires physical address to work */
1114                 if (iova_mode == RTE_IOVA_VA &&
1115                                 rte_eal_check_module("rte_kni") == 1) {
1116                         if (phys_addrs) {
1117                                 iova_mode = RTE_IOVA_PA;
1118                                 RTE_LOG(WARNING, EAL, "Forcing IOVA as 'PA' because KNI module is loaded\n");
1119                         } else {
1120                                 RTE_LOG(DEBUG, EAL, "KNI can not work since physical addresses are unavailable\n");
1121                         }
1122                 }
1123 #endif
1124                 rte_eal_get_configuration()->iova_mode = iova_mode;
1125         } else {
1126                 rte_eal_get_configuration()->iova_mode =
1127                         internal_config.iova_mode;
1128         }
1129
1130         if (rte_eal_iova_mode() == RTE_IOVA_PA && !phys_addrs) {
1131                 rte_eal_init_alert("Cannot use IOVA as 'PA' since physical addresses are not available");
1132                 rte_errno = EINVAL;
1133                 return -1;
1134         }
1135
1136         RTE_LOG(INFO, EAL, "Selected IOVA mode '%s'\n",
1137                 rte_eal_iova_mode() == RTE_IOVA_PA ? "PA" : "VA");
1138
1139         if (internal_config.no_hugetlbfs == 0) {
1140                 /* rte_config isn't initialized yet */
1141                 ret = internal_config.process_type == RTE_PROC_PRIMARY ?
1142                                 eal_hugepage_info_init() :
1143                                 eal_hugepage_info_read();
1144                 if (ret < 0) {
1145                         rte_eal_init_alert("Cannot get hugepage information.");
1146                         rte_errno = EACCES;
1147                         rte_atomic32_clear(&run_once);
1148                         return -1;
1149                 }
1150         }
1151
1152         if (internal_config.memory == 0 && internal_config.force_sockets == 0) {
1153                 if (internal_config.no_hugetlbfs)
1154                         internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
1155         }
1156
1157         if (internal_config.vmware_tsc_map == 1) {
1158 #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT
1159                 rte_cycles_vmware_tsc_map = 1;
1160                 RTE_LOG (DEBUG, EAL, "Using VMWARE TSC MAP, "
1161                                 "you must have monitor_control.pseudo_perfctr = TRUE\n");
1162 #else
1163                 RTE_LOG (WARNING, EAL, "Ignoring --vmware-tsc-map because "
1164                                 "RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT is not set\n");
1165 #endif
1166         }
1167
1168         if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0) {
1169                 rte_eal_init_alert("Cannot init logging.");
1170                 rte_errno = ENOMEM;
1171                 rte_atomic32_clear(&run_once);
1172                 return -1;
1173         }
1174
1175 #ifdef VFIO_PRESENT
1176         if (rte_eal_vfio_setup() < 0) {
1177                 rte_eal_init_alert("Cannot init VFIO");
1178                 rte_errno = EAGAIN;
1179                 rte_atomic32_clear(&run_once);
1180                 return -1;
1181         }
1182 #endif
1183         /* in secondary processes, memory init may allocate additional fbarrays
1184          * not present in primary processes, so to avoid any potential issues,
1185          * initialize memzones first.
1186          */
1187         if (rte_eal_memzone_init() < 0) {
1188                 rte_eal_init_alert("Cannot init memzone");
1189                 rte_errno = ENODEV;
1190                 return -1;
1191         }
1192
1193         if (rte_eal_memory_init() < 0) {
1194                 rte_eal_init_alert("Cannot init memory");
1195                 rte_errno = ENOMEM;
1196                 return -1;
1197         }
1198
1199         /* the directories are locked during eal_hugepage_info_init */
1200         eal_hugedirs_unlock();
1201
1202         if (rte_eal_malloc_heap_init() < 0) {
1203                 rte_eal_init_alert("Cannot init malloc heap");
1204                 rte_errno = ENODEV;
1205                 return -1;
1206         }
1207
1208         if (rte_eal_tailqs_init() < 0) {
1209                 rte_eal_init_alert("Cannot init tail queues for objects");
1210                 rte_errno = EFAULT;
1211                 return -1;
1212         }
1213
1214         if (rte_eal_timer_init() < 0) {
1215                 rte_eal_init_alert("Cannot init HPET or TSC timers");
1216                 rte_errno = ENOTSUP;
1217                 return -1;
1218         }
1219
1220         eal_check_mem_on_local_socket();
1221
1222         eal_thread_init_master(rte_config.master_lcore);
1223
1224         ret = eal_thread_dump_affinity(cpuset, sizeof(cpuset));
1225
1226         RTE_LOG(DEBUG, EAL, "Master lcore %u is ready (tid=%zx;cpuset=[%s%s])\n",
1227                 rte_config.master_lcore, (uintptr_t)thread_id, cpuset,
1228                 ret == 0 ? "" : "...");
1229
1230         RTE_LCORE_FOREACH_SLAVE(i) {
1231
1232                 /*
1233                  * create communication pipes between master thread
1234                  * and children
1235                  */
1236                 if (pipe(lcore_config[i].pipe_master2slave) < 0)
1237                         rte_panic("Cannot create pipe\n");
1238                 if (pipe(lcore_config[i].pipe_slave2master) < 0)
1239                         rte_panic("Cannot create pipe\n");
1240
1241                 lcore_config[i].state = WAIT;
1242
1243                 /* create a thread for each lcore */
1244                 ret = pthread_create(&lcore_config[i].thread_id, NULL,
1245                                      eal_thread_loop, NULL);
1246                 if (ret != 0)
1247                         rte_panic("Cannot create thread\n");
1248
1249                 /* Set thread_name for aid in debugging. */
1250                 snprintf(thread_name, sizeof(thread_name),
1251                         "lcore-slave-%d", i);
1252                 ret = rte_thread_setname(lcore_config[i].thread_id,
1253                                                 thread_name);
1254                 if (ret != 0)
1255                         RTE_LOG(DEBUG, EAL,
1256                                 "Cannot set name for lcore thread\n");
1257         }
1258
1259         /*
1260          * Launch a dummy function on all slave lcores, so that master lcore
1261          * knows they are all ready when this function returns.
1262          */
1263         rte_eal_mp_remote_launch(sync_func, NULL, SKIP_MASTER);
1264         rte_eal_mp_wait_lcore();
1265
1266         /* initialize services so vdevs register service during bus_probe. */
1267         ret = rte_service_init();
1268         if (ret) {
1269                 rte_eal_init_alert("rte_service_init() failed");
1270                 rte_errno = ENOEXEC;
1271                 return -1;
1272         }
1273
1274         /* Probe all the buses and devices/drivers on them */
1275         if (rte_bus_probe()) {
1276                 rte_eal_init_alert("Cannot probe devices");
1277                 rte_errno = ENOTSUP;
1278                 return -1;
1279         }
1280
1281 #ifdef VFIO_PRESENT
1282         /* Register mp action after probe() so that we got enough info */
1283         if (rte_vfio_is_enabled("vfio") && vfio_mp_sync_setup() < 0)
1284                 return -1;
1285 #endif
1286
1287         /* initialize default service/lcore mappings and start running. Ignore
1288          * -ENOTSUP, as it indicates no service coremask passed to EAL.
1289          */
1290         ret = rte_service_start_with_defaults();
1291         if (ret < 0 && ret != -ENOTSUP) {
1292                 rte_errno = ENOEXEC;
1293                 return -1;
1294         }
1295
1296         /*
1297          * Clean up unused files in runtime directory. We do this at the end of
1298          * init and not at the beginning because we want to clean stuff up
1299          * whether we are primary or secondary process, but we cannot remove
1300          * primary process' files because secondary should be able to run even
1301          * if primary process is dead.
1302          *
1303          * In no_shconf mode, no runtime directory is created in the first
1304          * place, so no cleanup needed.
1305          */
1306         if (!internal_config.no_shconf && eal_clean_runtime_dir() < 0) {
1307                 rte_eal_init_alert("Cannot clear runtime directory\n");
1308                 return -1;
1309         }
1310
1311         eal_mcfg_complete();
1312
1313         /* Call each registered callback, if enabled */
1314         rte_option_init();
1315
1316         return fctret;
1317 }
1318
1319 static int
1320 mark_freeable(const struct rte_memseg_list *msl, const struct rte_memseg *ms,
1321                 void *arg __rte_unused)
1322 {
1323         /* ms is const, so find this memseg */
1324         struct rte_memseg *found;
1325
1326         if (msl->external)
1327                 return 0;
1328
1329         found = rte_mem_virt2memseg(ms->addr, msl);
1330
1331         found->flags &= ~RTE_MEMSEG_FLAG_DO_NOT_FREE;
1332
1333         return 0;
1334 }
1335
1336 int
1337 rte_eal_cleanup(void)
1338 {
1339         /* if we're in a primary process, we need to mark hugepages as freeable
1340          * so that finalization can release them back to the system.
1341          */
1342         if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1343                 rte_memseg_walk(mark_freeable, NULL);
1344         rte_service_finalize();
1345         rte_mp_channel_cleanup();
1346         eal_cleanup_config(&internal_config);
1347         return 0;
1348 }
1349
1350 /* get core role */
1351 enum rte_lcore_role_t
1352 rte_eal_lcore_role(unsigned lcore_id)
1353 {
1354         return rte_config.lcore_role[lcore_id];
1355 }
1356
1357 enum rte_proc_type_t
1358 rte_eal_process_type(void)
1359 {
1360         return rte_config.process_type;
1361 }
1362
1363 int rte_eal_has_hugepages(void)
1364 {
1365         return ! internal_config.no_hugetlbfs;
1366 }
1367
1368 int rte_eal_has_pci(void)
1369 {
1370         return !internal_config.no_pci;
1371 }
1372
1373 int rte_eal_create_uio_dev(void)
1374 {
1375         return internal_config.create_uio_dev;
1376 }
1377
1378 enum rte_intr_mode
1379 rte_eal_vfio_intr_mode(void)
1380 {
1381         return internal_config.vfio_intr_mode;
1382 }
1383
1384 int
1385 rte_eal_check_module(const char *module_name)
1386 {
1387         char sysfs_mod_name[PATH_MAX];
1388         struct stat st;
1389         int n;
1390
1391         if (NULL == module_name)
1392                 return -1;
1393
1394         /* Check if there is sysfs mounted */
1395         if (stat("/sys/module", &st) != 0) {
1396                 RTE_LOG(DEBUG, EAL, "sysfs is not mounted! error %i (%s)\n",
1397                         errno, strerror(errno));
1398                 return -1;
1399         }
1400
1401         /* A module might be built-in, therefore try sysfs */
1402         n = snprintf(sysfs_mod_name, PATH_MAX, "/sys/module/%s", module_name);
1403         if (n < 0 || n > PATH_MAX) {
1404                 RTE_LOG(DEBUG, EAL, "Could not format module path\n");
1405                 return -1;
1406         }
1407
1408         if (stat(sysfs_mod_name, &st) != 0) {
1409                 RTE_LOG(DEBUG, EAL, "Module %s not found! error %i (%s)\n",
1410                         sysfs_mod_name, errno, strerror(errno));
1411                 return 0;
1412         }
1413
1414         /* Module has been found */
1415         return 1;
1416 }