eal/windows: implement basic memory management
[dpdk.git] / lib / librte_eal / windows / eal.c
index 2cf7a04..427a555 100644 (file)
 #include <eal_filesystem.h>
 #include <eal_options.h>
 #include <eal_private.h>
+#include <rte_trace_point.h>
 
+#include "eal_hugepages.h"
 #include "eal_windows.h"
 
+#define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL)
+
  /* Allow the application to print its usage message too if set */
 static rte_usage_hook_t        rte_application_usage_hook;
 
@@ -90,6 +94,24 @@ eal_proc_type_detect(void)
        return ptype;
 }
 
+enum rte_proc_type_t
+rte_eal_process_type(void)
+{
+       return rte_config.process_type;
+}
+
+int
+rte_eal_has_hugepages(void)
+{
+       return !internal_config.no_hugetlbfs;
+}
+
+enum rte_iova_mode
+rte_eal_iova_mode(void)
+{
+       return rte_config.iova_mode;
+}
+
 /* display usage */
 static void
 eal_usage(const char *prgname)
@@ -139,7 +161,7 @@ eal_log_level_parse(int argc, char **argv)
 }
 
 /* Parse the argument given in the command line of the application */
-__attribute__((optnone)) static int
+static int
 eal_parse_args(int argc, char **argv)
 {
        int opt, ret;
@@ -221,16 +243,52 @@ rte_eal_init_alert(const char *msg)
        RTE_LOG(ERR, EAL, "%s\n", msg);
 }
 
+/* Stubs to enable EAL trace point compilation
+ * until eal_common_trace.c can be compiled.
+ */
+
+RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
+RTE_DEFINE_PER_LCORE(void *, trace_mem);
+
+void
+__rte_trace_mem_per_thread_alloc(void)
+{
+}
+
+void
+__rte_trace_point_emit_field(size_t sz, const char *field,
+       const char *type)
+{
+       RTE_SET_USED(sz);
+       RTE_SET_USED(field);
+       RTE_SET_USED(type);
+}
+
+int
+__rte_trace_point_register(rte_trace_point_t *trace, const char *name,
+       void (*register_fn)(void))
+{
+       RTE_SET_USED(trace);
+       RTE_SET_USED(name);
+       RTE_SET_USED(register_fn);
+       return -ENOTSUP;
+}
+
  /* Launch threads, called at application init(). */
 int
 rte_eal_init(int argc, char **argv)
 {
        int i, fctret;
 
+       rte_eal_log_init(NULL, 0);
+
        eal_log_level_parse(argc, argv);
 
-       /* create a map of all processors in the system */
-       eal_create_cpu_map();
+       if (eal_create_cpu_map() < 0) {
+               rte_eal_init_alert("Cannot discover CPU and NUMA.");
+               /* rte_errno is set */
+               return -1;
+       }
 
        if (rte_eal_cpu_init() < 0) {
                rte_eal_init_alert("Cannot detect lcores.");
@@ -242,6 +300,60 @@ rte_eal_init(int argc, char **argv)
        if (fctret < 0)
                exit(1);
 
+       /* Prevent creation of shared memory files. */
+       if (internal_config.in_memory == 0) {
+               RTE_LOG(WARNING, EAL, "Multi-process support is requested, "
+                       "but not available.\n");
+               internal_config.in_memory = 1;
+       }
+
+       if (!internal_config.no_hugetlbfs && (eal_hugepage_info_init() < 0)) {
+               rte_eal_init_alert("Cannot get hugepage information");
+               rte_errno = EACCES;
+               return -1;
+       }
+
+       if (internal_config.memory == 0 && !internal_config.force_sockets) {
+               if (internal_config.no_hugetlbfs)
+                       internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE;
+       }
+
+       if (eal_mem_win32api_init() < 0) {
+               rte_eal_init_alert("Cannot access Win32 memory management");
+               rte_errno = ENOTSUP;
+               return -1;
+       }
+
+       if (eal_mem_virt2iova_init() < 0) {
+               /* Non-fatal error if physical addresses are not required. */
+               RTE_LOG(WARNING, EAL, "Cannot access virt2phys driver, "
+                       "PA will not be available\n");
+       }
+
+       if (rte_eal_memzone_init() < 0) {
+               rte_eal_init_alert("Cannot init memzone");
+               rte_errno = ENODEV;
+               return -1;
+       }
+
+       if (rte_eal_memory_init() < 0) {
+               rte_eal_init_alert("Cannot init memory");
+               rte_errno = ENOMEM;
+               return -1;
+       }
+
+       if (rte_eal_malloc_heap_init() < 0) {
+               rte_eal_init_alert("Cannot init malloc heap");
+               rte_errno = ENODEV;
+               return -1;
+       }
+
+       if (rte_eal_tailqs_init() < 0) {
+               rte_eal_init_alert("Cannot init tail queues for objects");
+               rte_errno = EFAULT;
+               return -1;
+       }
+
        eal_thread_init_master(rte_config.master_lcore);
 
        RTE_LCORE_FOREACH_SLAVE(i) {