aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vpp/vnet/main.c52
-rw-r--r--src/vppinfra/bihash_template.c25
-rw-r--r--src/vppinfra/bihash_template.h7
3 files changed, 19 insertions, 65 deletions
diff --git a/src/vpp/vnet/main.c b/src/vpp/vnet/main.c
index 0e8a2064ae6..397cf8328c5 100644
--- a/src/vpp/vnet/main.c
+++ b/src/vpp/vnet/main.c
@@ -471,34 +471,12 @@ vlib_app_num_thread_stacks_needed (void)
#include <vppinfra/bihash_8_8.h>
-typedef struct
-{
- u8 *name;
- u64 actual_virt_size;
- u64 configured_virt_size;
-} name_sort_t;
-
-static int
-name_sort_cmp (void *a1, void *a2)
-{
- name_sort_t *n1 = a1;
- name_sort_t *n2 = a2;
-
- return strcmp ((char *) n1->name, (char *) n2->name);
-}
-
static clib_error_t *
show_bihash_command_fn (vlib_main_t * vm,
unformat_input_t * input, vlib_cli_command_t * cmd)
{
int i;
clib_bihash_8_8_t *h;
- u64 total_actual_virt_size = 0;
- u64 total_configured_virt_size = 0;
- u64 actual_virt_size;
- u64 configured_virt_size;
- name_sort_t *names = 0;
- name_sort_t *this;
int verbose = 0;
if (unformat (input, "verbose"))
@@ -507,37 +485,9 @@ show_bihash_command_fn (vlib_main_t * vm,
for (i = 0; i < vec_len (clib_all_bihashes); i++)
{
h = (clib_bihash_8_8_t *) clib_all_bihashes[i];
- if (alloc_arena (h) || verbose)
- {
- vec_add2 (names, this, 1);
- this->name = format (0, "%s%c", h->name, 0);
- configured_virt_size = h->memory_size;
- actual_virt_size = alloc_arena (h) ? h->memory_size : 0ULL;
- this->actual_virt_size = actual_virt_size;
- this->configured_virt_size = configured_virt_size;
- total_actual_virt_size += actual_virt_size;
- total_configured_virt_size += configured_virt_size;
- }
+ vlib_cli_output (vm, "\n%U", h->fmt_fn, h, verbose);
}
- vec_sort_with_function (names, name_sort_cmp);
-
- vlib_cli_output (vm, "%-30s %8s %s", "Name", "Actual", "Configured");
-
- for (i = 0; i < vec_len (names); i++)
- {
- vlib_cli_output (vm, "%-30s %8U %U", names[i].name,
- format_memory_size,
- names[i].actual_virt_size,
- format_memory_size, names[i].configured_virt_size);
- vec_free (names[i].name);
- }
-
- vec_free (names);
-
- vlib_cli_output (vm, "%-30s %8U %U", "Total",
- format_memory_size, total_actual_virt_size,
- format_memory_size, total_configured_virt_size);
return 0;
}
diff --git a/src/vppinfra/bihash_template.c b/src/vppinfra/bihash_template.c
index e408d157da7..561855a5644 100644
--- a/src/vppinfra/bihash_template.c
+++ b/src/vppinfra/bihash_template.c
@@ -197,7 +197,8 @@ void BV (clib_bihash_init2) (BVT (clib_bihash_init2_args) * a)
h->log2_nbuckets = max_log2 (a->nbuckets);
h->memory_size = BIHASH_USE_HEAP ? 0 : a->memory_size;
h->instantiated = 0;
- h->fmt_fn = a->fmt_fn;
+ h->fmt_fn = BV (format_bihash);
+ h->kvp_fmt_fn = a->kvp_fmt_fn;
alloc_arena (h) = 0;
@@ -327,7 +328,8 @@ void BV (clib_bihash_initiator_init_svm)
(u64) BV (clib_bihash_get_offset) (h, freelist_vh->vector_data);
h->freelists = (void *) (freelist_vh->vector_data);
- h->fmt_fn = NULL;
+ h->fmt_fn = BV (format_bihash);
+ h->kvp_fmt_fn = NULL;
h->instantiated = 1;
}
@@ -377,14 +379,15 @@ void BV (clib_bihash_responder_init_svm)
h->alloc_lock = BV (clib_bihash_get_value) (h, h->sh->alloc_lock_as_u64);
h->freelists = BV (clib_bihash_get_value) (h, h->sh->freelists_as_u64);
- h->fmt_fn = NULL;
+ h->fmt_fn = BV (format_bihash);
+ h->kvp_fmt_fn = NULL;
}
#endif /* BIHASH_32_64_SVM */
void BV (clib_bihash_set_kvp_format_fn) (BVT (clib_bihash) * h,
- format_function_t * fmt_fn)
+ format_function_t * kvp_fmt_fn)
{
- h->fmt_fn = fmt_fn;
+ h->kvp_fmt_fn = kvp_fmt_fn;
}
void BV (clib_bihash_free) (BVT (clib_bihash) * h)
@@ -1009,11 +1012,11 @@ u8 *BV (format_bihash) (u8 * s, va_list * args)
u64 active_buckets = 0;
u64 linear_buckets = 0;
- s = format (s, "Hash table %s\n", h->name ? h->name : (u8 *) "(unnamed)");
+ s = format (s, "Hash table '%s'\n", h->name ? h->name : (u8 *) "(unnamed)");
#if BIHASH_LAZY_INSTANTIATE
if (PREDICT_FALSE (h->instantiated == 0))
- return format (s, "[empty, uninitialized]");
+ return format (s, " empty, uninitialized");
#endif
for (i = 0; i < h->nbuckets; i++)
@@ -1052,11 +1055,11 @@ u8 *BV (format_bihash) (u8 * s, va_list * args)
}
if (verbose)
{
- if (h->fmt_fn)
+ if (h->kvp_fmt_fn)
{
s = format (s, " %d: %U\n",
j * BIHASH_KVP_PER_PAGE + k,
- h->fmt_fn, &(v->kvp[k]), verbose);
+ h->kvp_fmt_fn, &(v->kvp[k]), verbose);
}
else
{
@@ -1106,8 +1109,8 @@ u8 *BV (format_bihash) (u8 * s, va_list * args)
c = c->next;
}
s = format (s,
- " heap: %u chunks allocated\n"
- " used %UB, scrap %UB\n", n_chunks,
+ " heap: %u chunk(s) allocated\n"
+ " bytes: used %U, scrap %U\n", n_chunks,
format_memory_size, total_size,
format_memory_size, bytes_left);
}
diff --git a/src/vppinfra/bihash_template.h b/src/vppinfra/bihash_template.h
index a6990ff5999..83c94279668 100644
--- a/src/vppinfra/bihash_template.h
+++ b/src/vppinfra/bihash_template.h
@@ -156,6 +156,7 @@ BVS (clib_bihash)
u32 log2_nbuckets;
u64 memory_size;
u8 *name;
+ format_function_t *fmt_fn;
void *heap;
BVT (clib_bihash_alloc_chunk) * chunks;
@@ -174,7 +175,7 @@ BVS (clib_bihash)
/**
* A custom format function to print the Key and Value of bihash_key instead of default hexdump
*/
- format_function_t *fmt_fn;
+ format_function_t *kvp_fmt_fn;
/** Optional statistics-gathering callback */
#if BIHASH_ENABLE_STATS
@@ -192,7 +193,7 @@ typedef struct
char *name;
u32 nbuckets;
uword memory_size;
- format_function_t *fmt_fn;
+ format_function_t *kvp_fmt_fn;
u8 instantiate_immediately;
u8 dont_add_to_all_bihash_list;
} BVT (clib_bihash_init2_args);
@@ -346,7 +347,7 @@ void BV (clib_bihash_responder_init_svm)
#endif
void BV (clib_bihash_set_kvp_format_fn) (BVT (clib_bihash) * h,
- format_function_t * fmt_fn);
+ format_function_t * kvp_fmt_fn);
void BV (clib_bihash_free) (BVT (clib_bihash) * h);