vppinfra: numa vector placement support
[vpp.git] / src / vlib / cli.c
index 0ecdac3..8504988 100644 (file)
@@ -392,8 +392,6 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
   unformat_input_t sub_input;
   u8 *string;
   uword is_main_dispatch = cm == &vm->cli_main;
-  uword value;
-  u8 *key;
 
   parent = vec_elt_at_index (cm->commands, parent_command_index);
   if (is_main_dispatch && unformat (input, "help"))
@@ -428,17 +426,15 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
       else
        {
          vlib_cli_sub_rule_t *sr, *subs = 0;
+         vlib_cli_sub_command_t *sc;
 
-          /* *INDENT-OFF* */
-          hash_foreach_mem (key, value, c->sub_command_index_by_name,
-          ({
-            (void) key;
-            vec_add2 (subs, sr, 1);
-            sr->name = c->sub_commands[value].name;
-            sr->command_index = value;
-            sr->rule_index = ~0;
-          }));
-          /* *INDENT-ON* */
+         vec_foreach (sc, c->sub_commands)
+         {
+           vec_add2 (subs, sr, 1);
+           sr->name = sc->name;
+           sr->command_index = sc->index;
+           sr->rule_index = ~0;
+         }
 
          vec_sort_with_function (subs, vlib_cli_cmp_rule);
 
@@ -562,7 +558,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
                    u32 c;
                  } *ed;
                  ed = ELOG_DATA (&vm->elog_main, e);
-                 ed->c = elog_string (&vm->elog_main, c->path);
+                 ed->c = elog_string (&vm->elog_main, "%v", c->path);
                }
 
              if (!c->is_mp_safe)
@@ -588,7 +584,7 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
                    u32 c, err;
                  } *ed;
                  ed = ELOG_DATA (&vm->elog_main, e);
-                 ed->c = elog_string (&vm->elog_main, c->path);
+                 ed->c = elog_string (&vm->elog_main, "%v", c->path);
                  if (c_error)
                    {
                      vec_add1 (c_error->what, 0);
@@ -737,9 +733,10 @@ show_memory_usage (vlib_main_t * vm,
                   unformat_input_t * input, vlib_cli_command_t * cmd)
 {
   int verbose __attribute__ ((unused)) = 0;
-  int api_segment = 0, stats_segment = 0, main_heap = 0;
+  int api_segment = 0, stats_segment = 0, main_heap = 0, numa_heaps = 0;
   clib_error_t *error;
   u32 index = 0;
+  int i;
   uword clib_mem_trace_enable_disable (uword enable);
   uword was_enabled;
 
@@ -754,6 +751,8 @@ show_memory_usage (vlib_main_t * vm,
        stats_segment = 1;
       else if (unformat (input, "main-heap"))
        main_heap = 1;
+      else if (unformat (input, "numa-heaps"))
+       numa_heaps = 1;
       else
        {
          error = clib_error_return (0, "unknown input `%U'",
@@ -762,9 +761,9 @@ show_memory_usage (vlib_main_t * vm,
        }
     }
 
-  if ((api_segment + stats_segment + main_heap) == 0)
+  if ((api_segment + stats_segment + main_heap + numa_heaps) == 0)
     return clib_error_return
-      (0, "Please supply one of api-segment, stats-segment or main-heap");
+      (0, "Need one of api-segment, stats-segment, main-heap or numa-heaps");
 
   if (api_segment)
     {
@@ -805,6 +804,7 @@ show_memory_usage (vlib_main_t * vm,
       vec_free (s);
     }
 
+
 #if USE_DLMALLOC == 0
   /* *INDENT-OFF* */
   foreach_vlib_main (
@@ -853,6 +853,32 @@ show_memory_usage (vlib_main_t * vm,
        /* Restore the trace flag */
        clib_mem_trace_enable_disable (was_enabled);
       }
+    if (numa_heaps)
+      {
+       struct dlmallinfo mi;
+       void *mspace;
+
+       for (i = 0; i < ARRAY_LEN (clib_per_numa_mheaps); i++)
+         {
+           if (clib_per_numa_mheaps[i] == 0)
+             continue;
+           if (clib_per_numa_mheaps[i] == clib_per_cpu_mheaps[i])
+             {
+               vlib_cli_output (vm, "Numa %d uses the main heap...", i);
+               continue;
+             }
+           was_enabled = clib_mem_trace_enable_disable (0);
+           mspace = clib_per_numa_mheaps[i];
+
+           mi = mspace_mallinfo (mspace);
+           vlib_cli_output (vm, "Numa %d:", i);
+           vlib_cli_output (vm, "  %U\n", format_page_map,
+                            pointer_to_uword (mspace_least_addr (mspace)),
+                            mi.arena);
+           vlib_cli_output (vm, "  %U\n", format_mheap,
+                            clib_per_numa_mheaps[index], verbose);
+         }
+      }
   }
 #endif /* USE_DLMALLOC */
   return 0;
@@ -861,7 +887,8 @@ show_memory_usage (vlib_main_t * vm,
 /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (show_memory_usage_command, static) = {
   .path = "show memory",
-  .short_help = "show memory [api-segment][stats-segment][verbose]",
+  .short_help = "show memory [api-segment][stats-segment][verbose]\n"
+  "            [numa-heaps]",
   .function = show_memory_usage,
 };
 /* *INDENT-ON* */
@@ -909,6 +936,7 @@ enable_disable_memory_trace (vlib_main_t * vm,
   int api_segment = 0;
   int stats_segment = 0;
   int main_heap = 0;
+  u32 numa_id = ~0;
   void *oldheap;
 
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -924,6 +952,8 @@ enable_disable_memory_trace (vlib_main_t * vm,
        stats_segment = 1;
       else if (unformat (line_input, "main-heap"))
        main_heap = 1;
+      else if (unformat (line_input, "numa-heap %d", &numa_id))
+       ;
       else
        {
          unformat_free (line_input);
@@ -932,10 +962,12 @@ enable_disable_memory_trace (vlib_main_t * vm,
     }
   unformat_free (line_input);
 
-  if ((api_segment + stats_segment + main_heap + (enable == 0)) == 0)
+  if ((api_segment + stats_segment + main_heap + (enable == 0)
+       + (numa_id != ~0)) == 0)
     {
       return clib_error_return
-       (0, "Need one of main-heap, stats-segment or api-segment");
+       (0, "Need one of main-heap, stats-segment, api-segment,\n"
+        "numa-heap <nn> or disable");
     }
 
   /* Turn off current trace, if any */
@@ -979,13 +1011,31 @@ enable_disable_memory_trace (vlib_main_t * vm,
       clib_mem_trace (main_heap);
     }
 
+  if (numa_id != ~0)
+    {
+      if (numa_id >= ARRAY_LEN (clib_per_numa_mheaps))
+       return clib_error_return (0, "Numa %d out of range", numa_id);
+      if (clib_per_numa_mheaps[numa_id] == 0)
+       return clib_error_return (0, "Numa %d heap not active", numa_id);
+
+      if (clib_per_numa_mheaps[numa_id] == clib_mem_get_heap ())
+       return clib_error_return (0, "Numa %d uses the main heap...",
+                                 numa_id);
+      current_traced_heap = clib_per_numa_mheaps[numa_id];
+      oldheap = clib_mem_set_heap (current_traced_heap);
+      clib_mem_trace (1);
+      clib_mem_set_heap (oldheap);
+    }
+
+
   return 0;
 }
 
 /* *INDENT-OFF* */
 VLIB_CLI_COMMAND (enable_disable_memory_trace_command, static) = {
   .path = "memory-trace",
-  .short_help = "memory-trace on|off [api-segment][stats-segment][main-heap]\n",
+  .short_help = "memory-trace on|off [api-segment][stats-segment][main-heap]\n"
+  "                   [numa-heap <numa-id>]\n",
   .function = enable_disable_memory_trace,
 };
 /* *INDENT-ON* */
@@ -1221,7 +1271,7 @@ add_sub_command (vlib_cli_main_t * cm, uword parent_index, uword child_index)
                    vec_len (p->sub_rules));
       vec_add2 (p->sub_rules, sr, 1);
       sr->name = sub_name;
-      sr->rule_index = q[0];
+      sr->rule_index = sr - p->sub_rules;
       sr->command_index = child_index;
       return;
     }