summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vlib/error.c7
-rw-r--r--src/vpp/stats/stat_segment.c36
2 files changed, 30 insertions, 13 deletions
diff --git a/src/vlib/error.c b/src/vlib/error.c
index 1a48c9e89c2..17447b07119 100644
--- a/src/vlib/error.c
+++ b/src/vlib/error.c
@@ -109,10 +109,11 @@ vlib_error_drop_buffers (vlib_main_t * vm,
return n_buffers;
}
-void vlib_stats_register_error_index (u8 *, u64 *, u64)
+void vlib_stats_register_error_index (void *, u8 *, u64 *, u64)
__attribute__ ((weak));
void
-vlib_stats_register_error_index (u8 * notused, u64 * notused2, u64 notused3)
+vlib_stats_register_error_index (void *noutused, u8 * notused2,
+ u64 * notused3, u64 notused4)
{
};
@@ -180,7 +181,7 @@ vlib_register_errors (vlib_main_t * vm,
{
error_name = format (0, "/err/%v/%s%c", n->name, error_strings[i], 0);
/* Note: error_name consumed by the following call */
- vlib_stats_register_error_index (error_name, em->counters,
+ vlib_stats_register_error_index (oldheap, error_name, em->counters,
n->error_heap_index + i);
}
}
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c
index b9d5b23e33e..442a750ce7f 100644
--- a/src/vpp/stats/stat_segment.c
+++ b/src/vpp/stats/stat_segment.c
@@ -152,7 +152,8 @@ vlib_stats_pop_heap (void *cm_arg, void *oldheap, u32 cindex,
}
void
-vlib_stats_register_error_index (u8 * name, u64 * em_vec, u64 index)
+vlib_stats_register_error_index (void *oldheap, u8 * name, u64 * em_vec,
+ u64 index)
{
stat_segment_main_t *sm = &stat_segment_main;
stat_segment_shared_header_t *shared_header = sm->shared_header;
@@ -162,17 +163,32 @@ vlib_stats_register_error_index (u8 * name, u64 * em_vec, u64 index)
ASSERT (shared_header);
vlib_stat_segment_lock ();
+ u32 next_vector_index = vec_len (sm->directory_vector);
+ clib_mem_set_heap (oldheap); /* Exit stats segment */
- memcpy (e.name, name, vec_len (name));
- e.name[vec_len (name)] = '\0';
- e.type = STAT_DIR_TYPE_ERROR_INDEX;
- e.offset = index;
- e.offset_vector = 0;
- vec_add1 (sm->directory_vector, e);
+ u32 vector_index = lookup_or_create_hash_index (oldheap, (char *) name,
+ next_vector_index);
- /* Warn clients to refresh any pointers they might be holding */
- shared_header->directory_offset =
- stat_segment_offset (shared_header, sm->directory_vector);
+ /* Back to stats segment */
+ clib_mem_set_heap (sm->heap); /* Re-enter stat segment */
+
+ if (next_vector_index == vector_index)
+ {
+ memcpy (e.name, name, vec_len (name));
+ e.name[vec_len (name)] = '\0';
+ e.type = STAT_DIR_TYPE_ERROR_INDEX;
+ e.offset = index;
+ e.offset_vector = 0;
+ vec_add1 (sm->directory_vector, e);
+
+ /* Warn clients to refresh any pointers they might be holding */
+ shared_header->directory_offset =
+ stat_segment_offset (shared_header, sm->directory_vector);
+ }
+ else
+ {
+ vec_free (name);
+ }
vlib_stat_segment_unlock ();
}