From e09ae01f6777434f41ba8a5a564c8078565ecfea Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Wed, 19 Aug 2020 06:59:53 -0400 Subject: vppinfra: minor tweaks for cgo interoperation 'type' is a keyword in golang, so s/type/event_type/ in elog.h and elsewhere. Add vec_len_not_inline(...), elog_write_file_not_inline(...) and elog_read_file_not_inline(...) since the inline forms aren't usable. More such tweaks may follow. Type: improvement Signed-off-by: Dave Barach Change-Id: I9a80a6afa635f5cdedee554ee9abe400fafc1cb6 --- src/vppinfra/elog.c | 56 +++++++++++++++++++++++++++++++++++--------- src/vppinfra/elog.h | 9 +++++-- src/vppinfra/vec.c | 12 ++++++++++ src/vppinfra/vec.h | 2 ++ src/vppinfra/vec_bootstrap.h | 1 + 5 files changed, 67 insertions(+), 13 deletions(-) (limited to 'src/vppinfra') diff --git a/src/vppinfra/elog.c b/src/vppinfra/elog.c index caddf6f3757..62bd9797acc 100644 --- a/src/vppinfra/elog.c +++ b/src/vppinfra/elog.c @@ -302,7 +302,7 @@ format_elog_event (u8 * s, va_list * va) void *d = (u8 *) e->data; char arg_format[64]; - t = vec_elt_at_index (em->event_types, e->type); + t = vec_elt_at_index (em->event_types, e->event_type); f = t->format; a = t->format_args; @@ -420,8 +420,8 @@ format_elog_track (u8 * s, va_list * args) { if (e->track != track_index) continue; - s = format (s, "%U%18.9f: %U\n", format_white_space, indent, e->time + dt, - format_elog_event, em, e); + s = format (s, "%U%18.9f: %U\n", format_white_space, indent, + e->time + dt, format_elog_event, em, e); } vec_free (es); return s; @@ -732,10 +732,11 @@ elog_merge (elog_main_t * dst, u8 * dst_tag, elog_main_t * src, u8 * src_tag, /* Across all (copied) src events... */ for (e = dst->events + l; e < vec_end (dst->events); e++) { - elog_event_type_t *t = vec_elt_at_index (src->event_types, e->type); + elog_event_type_t *t = + vec_elt_at_index (src->event_types, e->event_type); /* Remap type from src -> dst. */ - e->type = find_or_create_type (dst, t); + e->event_type = find_or_create_type (dst, t); /* Remap string table offsets for 'T' format args */ maybe_fix_string_table_offset (e, t, @@ -847,11 +848,11 @@ serialize_elog_event (serialize_main_t * m, va_list * va) { elog_main_t *em = va_arg (*va, elog_main_t *); elog_event_t *e = va_arg (*va, elog_event_t *); - elog_event_type_t *t = vec_elt_at_index (em->event_types, e->type); + elog_event_type_t *t = vec_elt_at_index (em->event_types, e->event_type); u8 *d = e->data; u8 *p = (u8 *) t->format_args; - serialize_integer (m, e->type, sizeof (e->type)); + serialize_integer (m, e->event_type, sizeof (e->event_type)); serialize_integer (m, e->track, sizeof (e->track)); serialize (m, serialize_f64, e->time); @@ -914,18 +915,18 @@ unserialize_elog_event (serialize_main_t * m, va_list * va) { u16 tmp[2]; - unserialize_integer (m, &tmp[0], sizeof (e->type)); + unserialize_integer (m, &tmp[0], sizeof (e->event_type)); unserialize_integer (m, &tmp[1], sizeof (e->track)); - e->type = tmp[0]; + e->event_type = tmp[0]; e->track = tmp[1]; /* Make sure it fits. */ - ASSERT (e->type == tmp[0]); + ASSERT (e->event_type == tmp[0]); ASSERT (e->track == tmp[1]); } - t = vec_elt_at_index (em->event_types, e->type); + t = vec_elt_at_index (em->event_types, e->event_type); unserialize (m, unserialize_f64, &e->time); @@ -1158,6 +1159,39 @@ unserialize_elog_main (serialize_main_t * m, va_list * va) } } +#ifdef CLIB_UNIX +clib_error_t * +elog_write_file_not_inline (elog_main_t * em, char *clib_file, int flush_ring) +{ + serialize_main_t m; + clib_error_t *error; + + error = serialize_open_clib_file (&m, clib_file); + if (error) + return error; + error = serialize (&m, serialize_elog_main, em, flush_ring); + if (!error) + serialize_close (&m); + return error; +} + +clib_error_t * +elog_read_file_not_inline (elog_main_t * em, char *clib_file) +{ + serialize_main_t m; + clib_error_t *error; + + error = unserialize_open_clib_file (&m, clib_file); + if (error) + return error; + error = unserialize (&m, unserialize_elog_main, em); + if (!error) + unserialize_close (&m); + return error; +} +#endif /* CLIB_UNIX */ + + /* * fd.io coding-style-patch-verification: ON * diff --git a/src/vppinfra/elog.h b/src/vppinfra/elog.h index 9f957e336d0..ee63d5b491b 100644 --- a/src/vppinfra/elog.h +++ b/src/vppinfra/elog.h @@ -68,7 +68,7 @@ typedef struct }; /** Event type index. */ - u16 type; + u16 event_type; /** Track for this event. Tracks allow events to be sorted and displayed by track. Think of 2 dimensional display with time and @@ -324,7 +324,7 @@ elog_event_data_inline (elog_main_t * em, e = vec_elt_at_index (em->event_ring, ei); e->time_cycles = cpu_time; - e->type = type_index; + e->event_type = type_index; e->track = track_index; /* Return user data for caller to fill in. */ @@ -543,6 +543,9 @@ elog_write_file (elog_main_t * em, char *clib_file, int flush_ring) return error; } +clib_error_t *elog_write_file_not_inline (elog_main_t * em, char *clib_file, + int flush_ring); + always_inline clib_error_t * elog_read_file (elog_main_t * em, char *clib_file) { @@ -558,6 +561,8 @@ elog_read_file (elog_main_t * em, char *clib_file) return error; } +clib_error_t *elog_read_file_not_inline (elog_main_t * em, char *clib_file); + #endif /* CLIB_UNIX */ #endif /* included_clib_elog_h */ diff --git a/src/vppinfra/vec.c b/src/vppinfra/vec.c index 05a557ebb54..441e1acc576 100644 --- a/src/vppinfra/vec.c +++ b/src/vppinfra/vec.c @@ -140,6 +140,18 @@ clib_mem_is_vec_h (void *v, uword header_bytes) return clib_mem_is_heap_object (vec_header (v, header_bytes)); } +u32 +vec_len_not_inline (void *v) +{ + return vec_len (v); +} + +void +vec_free_not_inline (void *v) +{ + vec_free (v); +} + /** \cond */ #ifdef TEST diff --git a/src/vppinfra/vec.h b/src/vppinfra/vec.h index d4063e64bdc..1fcb5f1a374 100644 --- a/src/vppinfra/vec.h +++ b/src/vppinfra/vec.h @@ -379,6 +379,8 @@ do { \ */ #define vec_free(V) vec_free_h(V,0) +void vec_free_not_inline (void *v); + /**\brief Free vector user header (syntactic sugar) @param h vector header @void diff --git a/src/vppinfra/vec_bootstrap.h b/src/vppinfra/vec_bootstrap.h index 501db61c016..53968070c0e 100644 --- a/src/vppinfra/vec_bootstrap.h +++ b/src/vppinfra/vec_bootstrap.h @@ -140,6 +140,7 @@ vec_aligned_header_end (void *v, uword header_bytes, uword align) */ #define vec_len(v) ((v) ? _vec_len(v) : 0) +u32 vec_len_not_inline (void *v); /** \brief Vector's NUMA id (lvalue-capable) -- cgit 1.2.3-korg