vlib: add max-size configuration parameter for pmalloc
[vpp.git] / src / vlib / physmem.c
index 37bf693..846f9a0 100755 (executable)
 #include <vlib/pci/pci.h>
 #include <vlib/linux/vfio.h>
 
+#if defined(__x86_64__) && !defined(CLIB_SANITIZE_ADDR)
+/* we keep physmem in low 38 bits of VA address space as some
+   IOMMU implamentation cannot map above that range */
+#define VLIB_PHYSMEM_DEFAULT_BASE_ADDDR                (1ULL << 36)
+#else
+/* let kernel decide */
+#define VLIB_PHYSMEM_DEFAULT_BASE_ADDDR                0
+#endif
+
 clib_error_t *
 vlib_physmem_shared_map_create (vlib_main_t * vm, char *name, uword size,
                                u32 log2_page_sz, u32 numa_node,
@@ -57,6 +66,7 @@ vlib_physmem_shared_map_create (vlib_main_t * vm, char *name, uword size,
   map->fd = a->fd;
   map->n_pages = a->n_pages * a->subpages_per_page;
   map->log2_page_size = a->log2_subpage_sz;
+  map->numa_node = a->numa_node;
 
   for (i = 0; i < a->n_pages; i++)
     {
@@ -101,7 +111,16 @@ vlib_physmem_init (vlib_main_t * vm)
                              CLIB_CACHE_LINE_BYTES);
   memset (p, 0, sizeof (clib_pmalloc_main_t));
   vpm->pmalloc_main = (clib_pmalloc_main_t *) p;
-  clib_pmalloc_init (vpm->pmalloc_main, 0);
+
+  if (vpm->base_addr == 0)
+    vpm->base_addr = VLIB_PHYSMEM_DEFAULT_BASE_ADDDR;
+
+  clib_pmalloc_init (vpm->pmalloc_main, vpm->base_addr, vpm->max_size);
+
+  /* update base_addr and max_size per actual allocation */
+  vpm->base_addr = (uword) vpm->pmalloc_main->base;
+  vpm->max_size = (uword) vpm->pmalloc_main->max_pages <<
+    vpm->pmalloc_main->def_log2_page_sz;
 
   return error;
 }
@@ -150,6 +169,28 @@ VLIB_CLI_COMMAND (show_physmem_command, static) = {
 };
 /* *INDENT-ON* */
 
+static clib_error_t *
+vlib_physmem_config (vlib_main_t * vm, unformat_input_t * input)
+{
+  vlib_physmem_main_t *vpm = &vm->physmem_main;
+
+  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
+    {
+      if (unformat (input, "base-addr 0x%lx", &vpm->base_addr))
+       ;
+      else if (unformat (input, "max-size %U",
+                        unformat_memory_size, &vpm->max_size))
+       ;
+      else
+       return unformat_parse_error (input);
+    }
+
+  unformat_free (input);
+  return 0;
+}
+
+VLIB_EARLY_CONFIG_FUNCTION (vlib_physmem_config, "physmem");
+
 /*
  * fd.io coding-style-patch-verification: ON
  *