physmem: Add physmem map support 06/15806/3
authorMohsin Kazmi <sykazmi@cisco.com>
Wed, 7 Nov 2018 15:55:18 +0000 (16:55 +0100)
committerDamjan Marion <dmarion@me.com>
Thu, 8 Nov 2018 16:09:21 +0000 (16:09 +0000)
This patch adds support for mapping the virtual address to physical
address and size of memory allocated.

Change-Id: I7659a1881308e89b215c486fecd7c973076d0773
Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
src/vlib/physmem.c
src/vppinfra/pmalloc.c
src/vppinfra/pmalloc.h

index f881e0a..37bf693 100755 (executable)
@@ -112,7 +112,7 @@ show_physmem (vlib_main_t * vm,
 {
   vlib_physmem_main_t *vpm = &vm->physmem_main;
   unformat_input_t _line_input, *line_input = &_line_input;
-  u32 verbose = 0;
+  u32 verbose = 0, map = 0;
 
   if (unformat_user (input, unformat_line_input, line_input))
     {
@@ -126,20 +126,26 @@ show_physmem (vlib_main_t * vm,
            verbose = 2;
          else if (unformat (line_input, "d"))
            verbose = 2;
+         else if (unformat (line_input, "map"))
+           map = 1;
          else
            break;
        }
       unformat_free (line_input);
     }
 
-  vlib_cli_output (vm, "  %U", format_pmalloc, vpm->pmalloc_main, verbose);
+  if (map)
+    vlib_cli_output (vm, " %U", format_pmalloc_map, vpm->pmalloc_main);
+  else
+    vlib_cli_output (vm, " %U", format_pmalloc, vpm->pmalloc_main, verbose);
+
   return 0;
 }
 
 /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_physmem_command, static) = {
   .path = "show physmem",
-  .short_help = "Show physical memory allocation",
+  .short_help = "show physmem [verbose | detail | map]",
   .function = show_physmem,
 };
 /* *INDENT-ON* */
index 46ccd7f..62b4f60 100644 (file)
@@ -687,6 +687,27 @@ format_pmalloc (u8 * s, va_list * va)
   return s;
 }
 
+u8 *
+format_pmalloc_map (u8 * s, va_list * va)
+{
+  clib_pmalloc_main_t *pm = va_arg (*va, clib_pmalloc_main_t *);
+
+  u32 index;
+  s = format (s, "%16s %13s %8s", "virtual-addr", "physical-addr", "size");
+  vec_foreach_index (index, pm->lookup_table)
+  {
+    uword *lookup_val, pa, va;
+    lookup_val = vec_elt_at_index (pm->lookup_table, index);
+    va = pointer_to_uword (pm->base) + (index << pm->lookup_log2_page_sz);
+    pa = va - *lookup_val;
+    s =
+      format (s, "\n %16p %13p %8U", uword_to_pointer (va, u64),
+             uword_to_pointer (pa, u64), format_log2_page_size,
+             pm->lookup_log2_page_sz);
+  }
+  return s;
+}
+
 /*
  * fd.io coding-style-patch-verification: ON
  *
index 9cd6529..eae317f 100644 (file)
@@ -120,6 +120,7 @@ void *clib_pmalloc_alloc_from_arena (clib_pmalloc_main_t * pm, void *arena_va,
                                     uword size, uword align);
 
 format_function_t format_pmalloc;
+format_function_t format_pmalloc_map;
 
 always_inline clib_error_t *
 clib_pmalloc_last_error (clib_pmalloc_main_t * pm)