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;
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'",
}
}
- 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)
{
vec_free (s);
}
-#if USE_DLMALLOC == 0
- /* *INDENT-OFF* */
- foreach_vlib_main (
- ({
- mheap_t *h = mheap_header (clib_per_cpu_mheaps[index]);
- vlib_cli_output (vm, "%sThread %d %s\n", index ? "\n":"", index,
- vlib_worker_threads[index].name);
- vlib_cli_output (vm, " %U\n", format_page_map, pointer_to_uword (h) -
- h->vm_alloc_offset_from_header,
- h->vm_alloc_size);
- vlib_cli_output (vm, " %U\n", format_mheap, clib_per_cpu_mheaps[index],
- verbose);
- index++;
- }));
- /* *INDENT-ON* */
-#else
+
{
if (main_heap)
{
/* 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;
}
/* *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* */
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))
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);
}
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 */
clib_mem_trace (main_heap);
}
- 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",
- .function = enable_disable_memory_trace,
-};
-/* *INDENT-ON* */
-
-
-static clib_error_t *
-test_heap_validate (vlib_main_t * vm, unformat_input_t * input,
- vlib_cli_command_t * cmd)
-{
-#if USE_DLMALLOC == 0
- clib_error_t *error = 0;
- void *heap;
- mheap_t *mheap;
-
- if (unformat (input, "on"))
- {
- /* *INDENT-OFF* */
- foreach_vlib_main({
- heap = clib_per_cpu_mheaps[this_vlib_main->thread_index];
- mheap = mheap_header(heap);
- mheap->flags |= MHEAP_FLAG_VALIDATE;
- // Turn off small object cache because it delays detection of errors
- mheap->flags &= ~MHEAP_FLAG_SMALL_OBJECT_CACHE;
- });
- /* *INDENT-ON* */
-
- }
- else if (unformat (input, "off"))
+ if (numa_id != ~0)
{
- /* *INDENT-OFF* */
- foreach_vlib_main({
- heap = clib_per_cpu_mheaps[this_vlib_main->thread_index];
- mheap = mheap_header(heap);
- mheap->flags &= ~MHEAP_FLAG_VALIDATE;
- mheap->flags |= MHEAP_FLAG_SMALL_OBJECT_CACHE;
- });
- /* *INDENT-ON* */
+ 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);
}
- else if (unformat (input, "now"))
- {
- /* *INDENT-OFF* */
- foreach_vlib_main({
- heap = clib_per_cpu_mheaps[this_vlib_main->thread_index];
- mheap = mheap_header(heap);
- mheap_validate(heap);
- });
- /* *INDENT-ON* */
- vlib_cli_output (vm, "heap validation complete");
- }
- else
- {
- return clib_error_return (0, "unknown input `%U'",
- format_unformat_error, input);
- }
- return error;
-#else
- return clib_error_return (0, "unimplemented...");
-#endif /* USE_DLMALLOC */
+ return 0;
}
/* *INDENT-OFF* */
-VLIB_CLI_COMMAND (cmd_test_heap_validate,static) = {
- .path = "test heap-validate",
- .short_help = "<on/off/now> validate heap on future allocs/frees or right now",
- .function = test_heap_validate,
+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"
+ " [numa-heap <numa-id>]\n",
+ .function = enable_disable_memory_trace,
};
/* *INDENT-ON* */
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;
}