diff options
author | Florin Coras <fcoras@cisco.com> | 2018-05-04 15:46:57 -0700 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2018-05-09 11:34:06 +0000 |
commit | 8e43d04ca4f4496aaefc4f5e2b6e1c0951624099 (patch) | |
tree | 3addc5766002d5224dde2c7fa4efe018480830e4 /src/tests/vnet | |
parent | ee7f0bd9e7ce4106d3b9511b0efede4326bded51 (diff) |
session: cleanup session tx function
- rework the function to declutter and avoid building more than one tx
frame
- add dual loop although benefits in my tests seem to be minimal
- improve tcp/udp echo external apps. They have slightly better
throughput than internal echo apps.
- udp bugfixes
Change-Id: Iea4a245b1b1bb407a7f403dedcce2664a49f774b
Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/tests/vnet')
-rw-r--r-- | src/tests/vnet/session/tcp_echo.c | 59 | ||||
-rw-r--r-- | src/tests/vnet/session/udp_echo.c | 69 |
2 files changed, 79 insertions, 49 deletions
diff --git a/src/tests/vnet/session/tcp_echo.c b/src/tests/vnet/session/tcp_echo.c index 0108b16ac7b..d3d4c0ad0a6 100644 --- a/src/tests/vnet/session/tcp_echo.c +++ b/src/tests/vnet/session/tcp_echo.c @@ -85,7 +85,7 @@ typedef struct int i_am_master; /* drop all packets */ - int drop_packets; + int no_return; /* Our event queue */ svm_queue_t *our_event_queue; @@ -117,6 +117,7 @@ typedef struct u32 client_bytes_received; u8 test_return_packets; u64 bytes_to_send; + u32 fifo_size; /** Flag that decides if socket, instead of svm, api is used to connect to * vpp. If sock api is used, shm binary api is subsequently bootstrapped @@ -250,7 +251,6 @@ application_send_attach (echo_main_t * em) vl_api_application_tls_cert_add_t *cert_mp; vl_api_application_tls_key_add_t *key_mp; - u32 fifo_size = 4 << 20; bmp = vl_msg_api_alloc (sizeof (*bmp)); memset (bmp, 0, sizeof (*bmp)); @@ -260,8 +260,8 @@ application_send_attach (echo_main_t * em) bmp->options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_ACCEPT_REDIRECT | APP_OPTIONS_FLAGS_ADD_SEGMENT; bmp->options[APP_OPTIONS_PREALLOC_FIFO_PAIRS] = 16; - bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = fifo_size; - bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = fifo_size; + bmp->options[APP_OPTIONS_RX_FIFO_SIZE] = em->fifo_size; + bmp->options[APP_OPTIONS_TX_FIFO_SIZE] = em->fifo_size; bmp->options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 128 << 20; bmp->options[APP_OPTIONS_SEGMENT_SIZE] = 256 << 20; vl_msg_api_send_shmem (em->vl_input_queue, (u8 *) & bmp); @@ -757,11 +757,10 @@ vl_api_connect_session_reply_t_handler (vl_api_connect_session_reply_t * mp) static void send_test_chunk (echo_main_t * em, svm_fifo_t * tx_fifo, int mypid, u32 bytes) { + u32 bytes_to_snd, enq_space, min_chunk = 16 << 10; u8 *test_data = em->connect_test_data; u64 bytes_sent = 0; int test_buf_offset = 0; - u32 bytes_to_snd; - u32 queue_max_chunk = 128 << 10, actual_write; session_fifo_event_t evt; int rv; @@ -771,11 +770,12 @@ send_test_chunk (echo_main_t * em, svm_fifo_t * tx_fifo, int mypid, u32 bytes) while (bytes_to_snd > 0 && !em->time_to_stop) { - actual_write = (bytes_to_snd > queue_max_chunk) ? - queue_max_chunk : bytes_to_snd; - rv = svm_fifo_enqueue_nowait (tx_fifo, actual_write, + enq_space = svm_fifo_max_enqueue (tx_fifo); + if (enq_space < clib_min (bytes_to_snd, min_chunk)) + continue; + rv = svm_fifo_enqueue_nowait (tx_fifo, + clib_min (bytes_to_snd, enq_space), test_data + test_buf_offset); - if (rv > 0) { bytes_to_snd -= rv; @@ -787,9 +787,8 @@ send_test_chunk (echo_main_t * em, svm_fifo_t * tx_fifo, int mypid, u32 bytes) /* Fabricate TX event, send to vpp */ evt.fifo = tx_fifo; evt.event_type = FIFO_EVENT_APP_TX; - - svm_queue_add (em->vpp_event_queue, - (u8 *) & evt, 0 /* do wait for mutex */ ); + svm_queue_add (em->vpp_event_queue, (u8 *) & evt, + 0 /* do wait for mutex */ ); } } } @@ -824,7 +823,7 @@ client_send_data (echo_main_t * em) if (leftover) send_test_chunk (em, tx_fifo, mypid, leftover); - if (!em->drop_packets) + if (!em->no_return) { f64 timeout = clib_time_now (&em->clib_time) + 10; @@ -839,6 +838,7 @@ client_send_data (echo_main_t * em) } } } + em->time_to_stop = 1; } @@ -911,7 +911,7 @@ client_run (echo_main_t * em) } /* Init test data */ - vec_validate (em->connect_test_data, 128 * 1024 - 1); + vec_validate (em->connect_test_data, 1024 * 1024 - 1); for (i = 0; i < vec_len (em->connect_test_data); i++) em->connect_test_data[i] = i & 0xff; @@ -1130,7 +1130,7 @@ server_handle_fifo_event_rx (echo_main_t * em, session_fifo_event_t * e) } /* Reflect if a non-drop session */ - if (!em->drop_packets && n_read > 0) + if (!em->no_return && n_read > 0) { offset = 0; do @@ -1342,13 +1342,13 @@ tcp_echo_api_hookup (echo_main_t * em) int main (int argc, char **argv) { - int i_am_master = 1, drop_packets = 0, test_return_packets = 0; + int i_am_server = 1, test_return_packets = 0; echo_main_t *em = &echo_main; unformat_input_t _argv, *a = &_argv; u8 *chroot_prefix; u8 *heap, *uri = 0; u8 *bind_uri = (u8 *) "tcp://0.0.0.0/1234"; - u8 *connect_uri = (u8 *) "tcp://6.0.1.2/1234"; + u8 *connect_uri = (u8 *) "tcp://6.0.1.1/1234"; u64 bytes_to_send = 64 << 10, mbytes; char *app_name; u32 tmp; @@ -1365,11 +1365,11 @@ main (int argc, char **argv) vec_validate (em->rx_buf, 128 << 10); em->session_index_by_vpp_handles = hash_create (0, sizeof (uword)); - em->my_pid = getpid (); em->configured_segment_size = 1 << 20; em->socket_name = 0; em->use_sock_api = 1; + em->fifo_size = 64 << 10; clib_time_init (&em->clib_time); init_error_string_table (em); @@ -1388,12 +1388,12 @@ main (int argc, char **argv) em->configured_segment_size = tmp << 20; else if (unformat (a, "segment-size %dG", &tmp)) em->configured_segment_size = tmp << 30; - else if (unformat (a, "master")) - i_am_master = 1; - else if (unformat (a, "slave")) - i_am_master = 0; - else if (unformat (a, "drop")) - drop_packets = 1; + else if (unformat (a, "server")) + i_am_server = 1; + else if (unformat (a, "client")) + i_am_server = 0; + else if (unformat (a, "no-return")) + em->no_return = 1; else if (unformat (a, "test")) test_return_packets = 1; else if (unformat (a, "mbytes %lld", &mbytes)) @@ -1408,6 +1408,8 @@ main (int argc, char **argv) ; else if (unformat (a, "use-svm-api")) em->use_sock_api = 0; + else if (unformat (a, "fifo-size %d", &tmp)) + em->fifo_size = tmp << 10; else { fformat (stderr, "%s: usage [master|slave]\n"); @@ -1429,9 +1431,8 @@ main (int argc, char **argv) em->connect_uri = format (0, "%s%c", connect_uri, 0); } - em->i_am_master = i_am_master; + em->i_am_master = i_am_server; em->segment_main = &svm_fifo_segment_main; - em->drop_packets = drop_packets; em->test_return_packets = test_return_packets; em->bytes_to_send = bytes_to_send; em->time_to_stop = 0; @@ -1439,7 +1440,7 @@ main (int argc, char **argv) setup_signal_handlers (); tcp_echo_api_hookup (em); - app_name = i_am_master ? "tcp_echo_server" : "tcp_echo_client"; + app_name = i_am_server ? "tcp_echo_server" : "tcp_echo_client"; if (connect_to_vpp (app_name) < 0) { svm_region_exit (); @@ -1447,7 +1448,7 @@ main (int argc, char **argv) exit (1); } - if (i_am_master == 0) + if (i_am_server == 0) client_run (em); else server_run (em); diff --git a/src/tests/vnet/session/udp_echo.c b/src/tests/vnet/session/udp_echo.c index fe5461d2c59..54e00b181bd 100644 --- a/src/tests/vnet/session/udp_echo.c +++ b/src/tests/vnet/session/udp_echo.c @@ -125,6 +125,8 @@ typedef struct uword *segments_table; u8 do_echo; + u8 have_return; + u64 bytes_to_send; } udp_echo_main_t; #if CLIB_DEBUG > 0 @@ -147,7 +149,6 @@ static void stats_signal (int signum) { udp_echo_main_t *um = &udp_echo_main; - um->time_to_print_stats = 1; } @@ -593,15 +594,20 @@ send_test_chunk (udp_echo_main_t * utm, app_session_t * s, u32 bytes) u8 *test_data = utm->connect_test_data; int test_buf_offset = 0; u64 bytes_sent = 0; - u32 bytes_to_snd; + u32 bytes_to_snd, enq_space, min_chunk; int rv; + min_chunk = clib_min (65536, s->tx_fifo->nitems); bytes_to_snd = (bytes == 0) ? vec_len (test_data) : bytes; if (bytes_to_snd > vec_len (test_data)) bytes_to_snd = vec_len (test_data); while (bytes_to_snd > 0 && !utm->time_to_stop) { + enq_space = svm_fifo_max_enqueue (s->tx_fifo); + if (enq_space < clib_min (bytes_to_snd, min_chunk)) + continue; + rv = app_send (s, test_data + test_buf_offset, bytes_to_snd, 0); if (rv > 0) { @@ -621,12 +627,14 @@ recv_test_chunk (udp_echo_main_t * utm, app_session_t * s) void client_send_data (udp_echo_main_t * utm) { - u8 *test_data; + f64 start_time, end_time, delta; app_session_t *session; + char *transfer_type; u32 n_iterations; + u8 *test_data; int i; - vec_validate (utm->connect_test_data, 64 * 1024 - 1); + vec_validate (utm->connect_test_data, 1024 * 1024 - 1); for (i = 0; i < vec_len (utm->connect_test_data); i++) utm->connect_test_data[i] = i & 0xff; @@ -635,22 +643,38 @@ client_send_data (udp_echo_main_t * utm) ASSERT (vec_len (test_data) > 0); vec_validate (utm->rx_buf, vec_len (test_data) - 1); - n_iterations = NITER; + n_iterations = utm->bytes_to_send / vec_len (test_data); + if (!n_iterations) + n_iterations = 1; + start_time = clib_time_now (&utm->clib_time); for (i = 0; i < n_iterations; i++) { send_test_chunk (utm, session, 0); - recv_test_chunk (utm, session); + if (utm->have_return) + recv_test_chunk (utm, session); if (utm->time_to_stop) break; } - f64 timeout = clib_time_now (&utm->clib_time) + 5; - while (clib_time_now (&utm->clib_time) < timeout) + if (utm->have_return) { - recv_test_chunk (utm, session); + f64 timeout = clib_time_now (&utm->clib_time) + 5; + while (clib_time_now (&utm->clib_time) < timeout) + recv_test_chunk (utm, session); } + end_time = clib_time_now (&utm->clib_time); + delta = end_time - start_time; + transfer_type = utm->have_return ? "full-duplex" : "half-duplex"; + clib_warning ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds", + utm->bytes_to_send, utm->bytes_to_send / (1ULL << 20), + utm->bytes_to_send / (1ULL << 30), delta); + clib_warning ("%.2f bytes/second %s", ((f64) utm->bytes_to_send) / (delta), + transfer_type); + clib_warning ("%.4f gbit/second %s", + (((f64) utm->bytes_to_send * 8.0) / delta / 1e9), + transfer_type); } static void @@ -1205,7 +1229,7 @@ int main (int argc, char **argv) { udp_echo_main_t *utm = &udp_echo_main; - u8 *uri = (u8 *) "udp://0.0.0.0/1234"; + u8 *uri = (u8 *) "udp://6.0.1.1/1234"; unformat_input_t _argv, *a = &_argv; int i_am_server = 1; app_session_t *session; @@ -1217,27 +1241,27 @@ main (int argc, char **argv) int i; clib_mem_init (0, 256 << 20); - heap = clib_mem_get_per_cpu_heap (); h = mheap_header (heap); - /* make the main heap thread-safe */ h->flags |= MHEAP_FLAG_THREAD_SAFE; + svm_fifo_segment_main_init (0x200000000ULL, 20); vec_validate (utm->rx_buf, 8192); - utm->session_index_by_vpp_handles = hash_create (0, sizeof (uword)); utm->my_pid = getpid (); utm->configured_segment_size = 1 << 20; utm->segments_table = hash_create_vec (0, sizeof (u8), sizeof (u64)); - + utm->have_return = 1; + utm->bytes_to_send = 1024; + utm->fifo_size = 128 << 10; + utm->segment_main = &svm_fifo_segment_main; + utm->cut_through_session_index = ~0; clib_time_init (&utm->clib_time); + init_error_string_table (utm); - svm_fifo_segment_main_init (0x200000000ULL, 20); unformat_init_command_line (a, argv); - utm->fifo_size = 128 << 10; - while (unformat_check_input (a) != UNFORMAT_END_OF_INPUT) { if (unformat (a, "chroot prefix %s", &chroot_prefix)) @@ -1254,6 +1278,12 @@ main (int argc, char **argv) i_am_server = 1; else if (unformat (a, "client")) i_am_server = 0; + else if (unformat (a, "no-return")) + utm->have_return = 0; + else if (unformat (a, "mbytes %d", &tmp)) + utm->bytes_to_send = (u64) tmp << 20; + else if (unformat (a, "fifo-size %d", &tmp)) + utm->fifo_size = tmp << 10; else { fformat (stderr, "%s: usage [server|client]\n"); @@ -1261,9 +1291,7 @@ main (int argc, char **argv) } } - utm->cut_through_session_index = ~0; utm->i_am_server = i_am_server; - utm->segment_main = &svm_fifo_segment_main; setup_signal_handlers (); tcp_echo_api_hookup (utm); @@ -1290,7 +1318,7 @@ main (int argc, char **argv) if (i_am_server == 0) { client_test (utm); - exit (0); + goto done; } /* $$$$ hack preallocation */ @@ -1304,6 +1332,7 @@ main (int argc, char **argv) udp_server_test (utm); +done: vl_client_disconnect_from_vlib (); exit (0); } |