New upstream version 16.11.4
[deb_dpdk.git] / lib / librte_eal / linuxapp / eal / eal.c
index 543ef86..59ed788 100644 (file)
@@ -70,6 +70,7 @@
 #include <rte_cpuflags.h>
 #include <rte_interrupts.h>
 #include <rte_pci.h>
+#include <rte_dev.h>
 #include <rte_devargs.h>
 #include <rte_common.h>
 #include <rte_version.h>
@@ -82,6 +83,7 @@
 #include "eal_filesystem.h"
 #include "eal_hugepages.h"
 #include "eal_options.h"
+#include "eal_vfio.h"
 
 #define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
 
@@ -237,7 +239,8 @@ rte_eal_config_attach(void)
        mem_config = (struct rte_mem_config *) mmap(NULL, sizeof(*mem_config),
                        PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
        if (mem_config == MAP_FAILED)
-               rte_panic("Cannot mmap memory for rte_config\n");
+               rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
+                         errno, strerror(errno));
 
        rte_config.mem_config = mem_config;
 }
@@ -262,9 +265,17 @@ rte_eal_config_reattach(void)
        mem_config = (struct rte_mem_config *) mmap(rte_mem_cfg_addr,
                        sizeof(*mem_config), PROT_READ | PROT_WRITE, MAP_SHARED,
                        mem_cfg_fd, 0);
+       if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr) {
+               if (mem_config != MAP_FAILED)
+                       /* errno is stale, don't use */
+                       rte_panic("Cannot mmap memory for rte_config at [%p], got [%p]"
+                                 " - please use '--base-virtaddr' option\n",
+                                 rte_mem_cfg_addr, mem_config);
+               else
+                       rte_panic("Cannot mmap memory for rte_config! error %i (%s)\n",
+                                 errno, strerror(errno));
+       }
        close(mem_cfg_fd);
-       if (mem_config == MAP_FAILED || mem_config != rte_mem_cfg_addr)
-               rte_panic("Cannot mmap memory for rte_config\n");
 
        rte_config.mem_config = mem_config;
 }
@@ -559,11 +570,11 @@ eal_parse_args(int argc, char **argv)
                        break;
 
                case OPT_HUGE_DIR_NUM:
-                       internal_config.hugepage_dir = optarg;
+                       internal_config.hugepage_dir = strdup(optarg);
                        break;
 
                case OPT_FILE_PREFIX_NUM:
-                       internal_config.hugefile_prefix = optarg;
+                       internal_config.hugefile_prefix = strdup(optarg);
                        break;
 
                case OPT_SOCKET_MEM_NUM:
@@ -701,6 +712,33 @@ rte_eal_iopl_init(void)
        return 0;
 }
 
+#ifdef VFIO_PRESENT
+static int rte_eal_vfio_setup(void)
+{
+       int vfio_enabled = 0;
+
+       if (!internal_config.no_pci) {
+               pci_vfio_enable();
+               vfio_enabled |= pci_vfio_is_enabled();
+       }
+
+       if (vfio_enabled) {
+
+               /* if we are primary process, create a thread to communicate with
+                * secondary processes. the thread will use a socket to wait for
+                * requests from secondary process to send open file descriptors,
+                * because VFIO does not allow multiple open descriptors on a group or
+                * VFIO container.
+                */
+               if (internal_config.process_type == RTE_PROC_PRIMARY &&
+                               vfio_mp_sync_setup() < 0)
+                       return -1;
+       }
+
+       return 0;
+}
+#endif
+
 /* Launch threads, called at application init(). */
 int
 rte_eal_init(int argc, char **argv)
@@ -712,6 +750,9 @@ rte_eal_init(int argc, char **argv)
        char cpuset[RTE_CPU_AFFINITY_STR_LEN];
        char thread_name[RTE_MAX_THREAD_NAME_LEN];
 
+       /* checks if the machine is adequate */
+       rte_cpu_check_supported();
+
        if (!rte_atomic32_test_and_set(&run_once))
                return -1;
 
@@ -720,9 +761,6 @@ rte_eal_init(int argc, char **argv)
 
        thread_id = pthread_self();
 
-       if (rte_eal_log_early_init() < 0)
-               rte_panic("Cannot init early logs\n");
-
        eal_log_level_parse(argc, argv);
 
        /* set log level as early as possible */
@@ -761,12 +799,15 @@ rte_eal_init(int argc, char **argv)
 
        rte_config_init();
 
+       if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0)
+               rte_panic("Cannot init logs\n");
+
        if (rte_eal_pci_init() < 0)
                rte_panic("Cannot init PCI\n");
 
-#ifdef RTE_LIBRTE_IVSHMEM
-       if (rte_eal_ivshmem_init() < 0)
-               rte_panic("Cannot init IVSHMEM\n");
+#ifdef VFIO_PRESENT
+       if (rte_eal_vfio_setup() < 0)
+               rte_panic("Cannot init VFIO\n");
 #endif
 
        if (rte_eal_memory_init() < 0)
@@ -781,14 +822,6 @@ rte_eal_init(int argc, char **argv)
        if (rte_eal_tailqs_init() < 0)
                rte_panic("Cannot init tail queues for objects\n");
 
-#ifdef RTE_LIBRTE_IVSHMEM
-       if (rte_eal_ivshmem_obj_init() < 0)
-               rte_panic("Cannot init IVSHMEM objects\n");
-#endif
-
-       if (rte_eal_log_init(logid, internal_config.syslog_facility) < 0)
-               rte_panic("Cannot init logs\n");
-
        if (rte_eal_alarm_init() < 0)
                rte_panic("Cannot init interrupt-handling thread\n");