From 03a6213fb5022d37ea92f974a1814db1c70bcbdf Mon Sep 17 00:00:00 2001 From: Mohammed Hawari Date: Tue, 18 Jul 2017 09:25:01 +0200 Subject: [PATCH] =?utf8?q?ping:=20fixing=20wrong=20value=20when=20there=20?= =?utf8?q?are=20worker=20threads=20-=20the=20echo=5Freply=5Fnode=20is=20no?= =?utf8?q?w=20notifying=20the=20cli=20process=20on=20the=20main=20thread/v?= =?utf8?q?lib=5Fmain=20-=20the=20timestamp=20for=20the=20icmp=20reply=20is?= =?utf8?q?=20now=20acquired=20in=20the=20echo=5Freply=5Fnode=20and=20not?= =?utf8?q?=20in=20the=20cli=20process=20to=20avoid=20an=20off=20by=2010ms?= =?utf8?q?=20error=20(see=20=E3=80=90vpp-dev=E3=80=91delay=20is=20error=20?= =?utf8?q?in=20ping=20with=20multi=20worker=20thread)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I21d37002b0376b4f2ccab08d8f04c2f2944b9b39 Signed-off-by: Mohammed Hawari --- src/vnet/ip/ping.c | 29 ++++++++++++++++++++--------- src/vnet/ip/ping.h | 1 + 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/vnet/ip/ping.c b/src/vnet/ip/ping.c index c664772f6b4..eee2575a2ea 100755 --- a/src/vnet/ip/ping.c +++ b/src/vnet/ip/ping.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include /** * @file @@ -53,8 +55,7 @@ format_icmp_echo_trace (u8 * s, va_list * va) */ static int -signal_ip46_icmp_reply_event (vlib_main_t * vm, - u8 event_type, vlib_buffer_t * b0) +signal_ip46_icmp_reply_event (u8 event_type, vlib_buffer_t * b0) { ping_main_t *pm = &ping_main; u16 net_icmp_id = 0; @@ -84,13 +85,19 @@ signal_ip46_icmp_reply_event (vlib_main_t * vm, return 0; ping_run_t *pr = vec_elt_at_index (pm->ping_runs, p[0]); + vlib_main_t *vm = vlib_mains[pr->cli_thread_index]; if (vlib_buffer_alloc (vm, &bi0_copy, 1) == 1) { - void *dst = vlib_buffer_get_current (vlib_get_buffer (vm, bi0_copy)); + void *dst = vlib_buffer_get_current (vlib_get_buffer (vm, + bi0_copy)); clib_memcpy (dst, vlib_buffer_get_current (b0), b0->current_length); } /* If buffer_alloc failed, bi0_copy == 0 - just signaling an event. */ - + f64 nowts = vlib_time_now (vm); + /* Pass the timestamp to the cli_process thanks to the vnet_buffer unused metadata field */ + clib_memcpy (vnet_buffer + (vlib_get_buffer + (vm, bi0_copy))->unused, &nowts, sizeof (nowts)); vlib_process_signal_event (vm, pr->cli_process_id, event_type, bi0_copy); return 1; } @@ -116,7 +123,7 @@ ip6_icmp_echo_reply_node_fn (vlib_main_t * vm, bi0 = from[0]; b0 = vlib_get_buffer (vm, bi0); - next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP6, b0) ? + next0 = signal_ip46_icmp_reply_event (PING_RESPONSE_IP6, b0) ? ICMP6_ECHO_REPLY_NEXT_DROP : ICMP6_ECHO_REPLY_NEXT_PUNT; if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) @@ -174,7 +181,7 @@ ip4_icmp_echo_reply_node_fn (vlib_main_t * vm, bi0 = from[0]; b0 = vlib_get_buffer (vm, bi0); - next0 = signal_ip46_icmp_reply_event (vm, PING_RESPONSE_IP4, b0) ? + next0 = signal_ip46_icmp_reply_event (PING_RESPONSE_IP4, b0) ? ICMP4_ECHO_REPLY_NEXT_DROP : ICMP4_ECHO_REPLY_NEXT_PUNT; if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) @@ -497,8 +504,9 @@ print_ip6_icmp_reply (vlib_main_t * vm, u32 bi0) { vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); icmp6_echo_request_header_t *h0 = vlib_buffer_get_current (b0); - f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent; - + f64 rtt = 0; + clib_memcpy (&rtt, vnet_buffer (b0)->unused, sizeof (rtt)); + rtt -= h0->icmp_echo.time_sent; vlib_cli_output (vm, "%d bytes from %U: icmp_seq=%d ttl=%d time=%.4f ms", clib_host_to_net_u16 (h0->ip6.payload_length), @@ -513,7 +521,9 @@ print_ip4_icmp_reply (vlib_main_t * vm, u32 bi0) { vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); icmp4_echo_request_header_t *h0 = vlib_buffer_get_current (b0); - f64 rtt = vlib_time_now (vm) - h0->icmp_echo.time_sent; + f64 rtt = 0; + clib_memcpy (&rtt, vnet_buffer (b0)->unused, sizeof (rtt)); + rtt -= h0->icmp_echo.time_sent; u32 rcvd_icmp_len = clib_host_to_net_u16 (h0->ip4.length) - (4 * (0xF & h0->ip4.ip_version_and_header_length)); @@ -565,6 +575,7 @@ run_ping_ip46_address (vlib_main_t * vm, u32 table_id, ip4_address_t * pa4, pool_get (pm->ping_runs, pr); ping_run_index = pr - pm->ping_runs; pr->cli_process_id = curr_proc; + pr->cli_thread_index = vlib_get_thread_index (); pr->icmp_id = icmp_id; hash_set (pm->ping_run_by_icmp_id, icmp_id, ping_run_index); for (i = 1; i <= ping_repeat; i++) diff --git a/src/vnet/ip/ping.h b/src/vnet/ip/ping.h index 0af9d5871f1..b1b71f685fe 100644 --- a/src/vnet/ip/ping.h +++ b/src/vnet/ip/ping.h @@ -43,6 +43,7 @@ typedef struct ping_run_t u16 icmp_id; u16 curr_seq; uword cli_process_id; + uword cli_thread_index; } ping_run_t; typedef struct ping_main_t -- 2.16.6