diff options
author | Dave Barach <dave@barachs.net> | 2016-11-02 18:37:56 -0400 |
---|---|---|
committer | Damjan Marion <dmarion.lists@gmail.com> | 2016-11-03 13:29:13 +0000 |
commit | 393252a6b1757690fb83ce744e8e63af46a64453 (patch) | |
tree | 438f554a6f2060f14b82357c29d8fe32ba3c5b63 | |
parent | ed4a2fdd4d62c46a2237157cd3a72bda16fceb6a (diff) |
Timestamp now a 64-bit integer: ns since 1/1/1970
Properly initialize allocated buffers
Change-Id: Ib2005e605c89a164a4856790db6968fcd7520f5c
Signed-off-by: Dave Barach <dave@barachs.net>
-rw-r--r-- | plugins/flowperpkt-plugin/flowperpkt/flowperpkt.c | 4 | ||||
-rw-r--r-- | plugins/flowperpkt-plugin/flowperpkt/flowperpkt.h | 4 | ||||
-rw-r--r-- | plugins/flowperpkt-plugin/flowperpkt/node.c | 22 | ||||
-rw-r--r-- | vnet/vnet/flow/flow_report.c | 6 |
4 files changed, 30 insertions, 6 deletions
diff --git a/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.c b/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.c index 824fc50ec57..ac508582669 100644 --- a/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.c +++ b/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.c @@ -486,6 +486,10 @@ flowperpkt_init (vlib_main_t * vm) vec_validate (fm->frames_per_worker, num_threads - 1); vec_validate (fm->next_record_offset_per_worker, num_threads - 1); + /* Set up time reference pair */ + fm->vlib_time_0 = vlib_time_now (vm); + fm->nanosecond_time_0 = unix_time_now_nsec (); + return error; } diff --git a/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.h b/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.h index 54d978ab1ea..5ddba9ce1da 100644 --- a/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.h +++ b/plugins/flowperpkt-plugin/flowperpkt/flowperpkt.h @@ -48,6 +48,10 @@ typedef struct /** next record offset, per worker thread */ u16 *next_record_offset_per_worker; + /** Time reference pair */ + u64 nanosecond_time_0; + f64 vlib_time_0; + /** convenience vlib_main_t pointer */ vlib_main_t *vlib_main; /** convenience vnet_main_t pointer */ diff --git a/plugins/flowperpkt-plugin/flowperpkt/node.c b/plugins/flowperpkt-plugin/flowperpkt/node.c index 0991c91d2dc..b01f2be3a05 100644 --- a/plugins/flowperpkt-plugin/flowperpkt/node.c +++ b/plugins/flowperpkt-plugin/flowperpkt/node.c @@ -31,7 +31,7 @@ typedef struct /** ToS bits */ u8 tos; /** packet timestamp */ - f64 timestamp; + u64 timestamp; /** size of the buffer */ u16 buffer_size; } flowperpkt_trace_t; @@ -45,7 +45,7 @@ format_flowperpkt_trace (u8 * s, va_list * args) flowperpkt_trace_t *t = va_arg (*args, flowperpkt_trace_t *); s = format (s, - "FLOWPERPKT: sw_if_index %d, tos %0x2, timestamp %.6f, size %d", + "FLOWPERPKT: sw_if_index %d, tos %0x2, timestamp %lld, size %d", t->sw_if_index, t->tos, t->timestamp, t->buffer_size); return s; } @@ -81,7 +81,7 @@ typedef enum * @param fm flowperpkt_main_t * flow-per-packet main structure pointer * @param sw_if_index u32 interface handle * @param tos u8 ToS bits from the packet - * @param timestamp f64 timestamp, floating-point seconds since vpp started + * @param timestamp u64 timestamp, nanoseconds since 1/1/70 * @param length u16 ip length of the packet * @param do_flush int 1 = flush all cached records, 0 = construct a record */ @@ -90,7 +90,7 @@ static inline void add_to_flow_record (vlib_main_t * vm, flowperpkt_main_t * fm, u32 sw_if_index, - u8 tos, f64 timestamp, u16 length, int do_flush) + u8 tos, u64 timestamp, u16 length, int do_flush) { u32 my_cpu_number = vm->cpu_index; flow_report_main_t *frm = &flow_report_main; @@ -103,6 +103,7 @@ add_to_flow_record (vlib_main_t * vm, vlib_buffer_t *b0; u16 offset; u32 bi0; + vlib_buffer_free_list_t *fl; /* Find or allocate a buffer */ b0 = fm->buffers_per_worker[my_cpu_number]; @@ -117,7 +118,13 @@ add_to_flow_record (vlib_main_t * vm, /* $$$$ drop counter? */ if (vlib_buffer_alloc (vm, &bi0, 1) != 1) return; + + /* Initialize the buffer */ b0 = fm->buffers_per_worker[my_cpu_number] = vlib_get_buffer (vm, bi0); + fl = + vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); + vlib_buffer_init_for_free_list (b0, fl); + VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0); offset = 0; } else @@ -265,7 +272,7 @@ flowperpkt_flush_callback (void) add_to_flow_record (vm, fm, 0 /* sw_if_index */ , 0 /* ToS */ , - 0.0 /* timestamp */ , + 0ULL /* timestamp */ , 0 /* length */ , 1 /* do_flush */ ); } @@ -281,7 +288,10 @@ flowperpkt_node_fn (vlib_main_t * vm, ip_lookup_main_t *lm = &im->lookup_main; vnet_feature_config_main_t *cm = &lm->feature_config_mains[VNET_IP_TX_FEAT]; flowperpkt_main_t *fm = &flowperpkt_main; - f64 now = vlib_time_now (vm); + u64 now; + + now = (u64) ((vlib_time_now (vm) - fm->vlib_time_0) * 1e9); + now += fm->nanosecond_time_0; from = vlib_frame_vector_args (frame); n_left_from = frame->n_vectors; diff --git a/vnet/vnet/flow/flow_report.c b/vnet/vnet/flow/flow_report.c index 6750105c559..46333288436 100644 --- a/vnet/vnet/flow/flow_report.c +++ b/vnet/vnet/flow/flow_report.c @@ -78,6 +78,7 @@ int send_template_packet (flow_report_main_t *frm, udp_header_t * udp; vlib_main_t * vm = frm->vlib_main; flow_report_stream_t * stream; + vlib_buffer_free_list_t *fl; ASSERT (buffer_indexp); @@ -109,6 +110,11 @@ int send_template_packet (flow_report_main_t *frm, b0 = vlib_get_buffer (vm, bi0); + /* Initialize the buffer */ + fl = vlib_buffer_get_free_list (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX); + vlib_buffer_init_for_free_list (b0, fl); + VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b0); + ASSERT (vec_len (fr->rewrite) < VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES); clib_memcpy (b0->data, fr->rewrite, vec_len (fr->rewrite)); |