hsa: add timed runs option for echo client 76/42576/19
authorSemir Sionek <[email protected]>
Wed, 26 Mar 2025 13:29:32 +0000 (13:29 +0000)
committerFlorin Coras <[email protected]>
Fri, 4 Apr 2025 07:04:49 +0000 (07:04 +0000)
Introduce the run-time parameter for echo client, which allows for
running for a certain time with a full buffer as opposed to running
until n amount of data is bounced back.

Type: improvement
Change-Id: I7b5b2138fe3fbbc36511331095a02dafd776fa94
Signed-off-by: Semir Sionek <[email protected]>
src/plugins/hs_apps/echo_client.c
src/plugins/hs_apps/echo_client.h

index b08edaa..f57fd74 100644 (file)
@@ -79,21 +79,27 @@ ec_session_get (ec_worker_t *wrk, u32 ec_index)
 static void
 send_data_chunk (ec_main_t *ecm, ec_session_t *es)
 {
+  const u64 max_burst = 128000;
   u8 *test_data = ecm->connect_test_data;
   int test_buf_len, test_buf_offset, rv;
+  u64 bytes_to_send;
   u32 bytes_this_chunk;
+  svm_fifo_t *f = es->tx_fifo;
 
   test_buf_len = vec_len (test_data);
   ASSERT (test_buf_len > 0);
+  if (ecm->run_time)
+    bytes_to_send = clib_min (svm_fifo_max_enqueue_prod (f), max_burst);
+  else
+    bytes_to_send = clib_min (es->bytes_to_send, max_burst);
   test_buf_offset = es->bytes_sent % test_buf_len;
-  bytes_this_chunk =
-    clib_min (test_buf_len - test_buf_offset, es->bytes_to_send);
+
+  bytes_this_chunk = clib_min (test_buf_len - test_buf_offset, bytes_to_send);
 
   if (!es->is_dgram)
     {
       if (ecm->no_copy)
        {
-         svm_fifo_t *f = es->tx_fifo;
          rv = clib_min (svm_fifo_max_enqueue_prod (f), bytes_this_chunk);
          svm_fifo_enqueue_nocopy (f, rv);
          session_program_tx_io_evt (es->tx_fifo->vpp_sh, SESSION_IO_EVT_TX);
@@ -105,7 +111,6 @@ send_data_chunk (ec_main_t *ecm, ec_session_t *es)
     }
   else
     {
-      svm_fifo_t *f = es->tx_fifo;
       u32 max_enqueue = svm_fifo_max_enqueue_prod (f);
 
       if (max_enqueue < sizeof (session_dgram_hdr_t))
@@ -147,8 +152,11 @@ send_data_chunk (ec_main_t *ecm, ec_session_t *es)
   if (rv > 0)
     {
       /* Account for it... */
-      es->bytes_to_send -= rv;
       es->bytes_sent += rv;
+      if (ecm->run_time)
+       es->bytes_to_receive += rv;
+      else
+       es->bytes_to_send -= rv;
 
       if (ecm->cfg.verbose)
        {
@@ -266,7 +274,7 @@ ec_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
     {
       ecm->repeats++;
       ecm->prev_conns = vec_len (conns_this_batch);
-      if (ecm->repeats == 500000)
+      if (ecm->repeats == 500000 && !ecm->run_time)
        {
          ec_err ("stuck clients");
        }
@@ -297,7 +305,7 @@ ec_node_fn (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
          delete_session = 0;
        }
 
-      if (PREDICT_FALSE (delete_session == 1))
+      if (PREDICT_FALSE (delete_session == 1) || ecm->timer_expired)
        {
          clib_atomic_fetch_add (&ecm->tx_total, es->bytes_sent);
          clib_atomic_fetch_add (&ecm->rx_total, es->bytes_received);
@@ -356,6 +364,7 @@ ec_reset_runtime_config (ec_main_t *ecm)
   ecm->tls_engine = CRYPTO_ENGINE_OPENSSL;
   ecm->no_copy = 0;
   ecm->run_test = EC_STARTING;
+  ecm->timer_expired = false;
   ecm->ready_connections = 0;
   ecm->connect_conn_index = 0;
   ecm->rx_total = 0;
@@ -368,6 +377,7 @@ ec_reset_runtime_config (ec_main_t *ecm)
   ecm->attach_flags = 0;
   ecm->syn_timeout = 20.0;
   ecm->test_timeout = 20.0;
+  ecm->run_time = 0;
   vec_free (ecm->connect_uri);
 }
 
@@ -1072,7 +1082,7 @@ ec_command_fn (vlib_main_t *vm, unformat_input_t *input,
   ec_main_t *ecm = &ec_main;
   uword *event_data = 0, event_type;
   clib_error_t *error = 0;
-  int rv, had_config = 1;
+  int rv, timed_run_conflict = 0, had_config = 1;
   u64 total_bytes;
   f64 delta;
 
@@ -1101,11 +1111,13 @@ ec_command_fn (vlib_main_t *vm, unformat_input_t *input,
        ;
       else if (unformat (line_input, "bytes %U", unformat_memory_size,
                         &ecm->bytes_to_send))
-       ;
+       timed_run_conflict++;
       else if (unformat (line_input, "test-timeout %f", &ecm->test_timeout))
        ;
       else if (unformat (line_input, "syn-timeout %f", &ecm->syn_timeout))
        ;
+      else if (unformat (line_input, "run-time %f", &ecm->run_time))
+       ;
       else if (unformat (line_input, "echo-bytes"))
        ecm->echo_bytes = 1;
       else if (unformat (line_input, "fifo-size %U", unformat_memory_size,
@@ -1149,6 +1161,9 @@ ec_command_fn (vlib_main_t *vm, unformat_input_t *input,
        }
     }
 
+  if (timed_run_conflict && ecm->run_time)
+    return clib_error_return (0, "failed: invalid arguments for a timed run!");
+
 parse_config:
 
   ecm->cfg.num_test_sessions = ecm->expected_connections =
@@ -1234,11 +1249,22 @@ parse_config:
       goto stop_test;
     }
 
+  /* Testing officially starts now */
+  ecm->test_start_time = vlib_time_now (ecm->vlib_main);
+  ec_cli ("Test started at %.6f", ecm->test_start_time);
+
+  /*
+   * If a timed run, wait and expire timer
+   */
+  if (ecm->run_time)
+    {
+      vlib_process_suspend (vm, ecm->run_time);
+      ec_main.timer_expired = true;
+    }
+
   /*
    * Wait for the sessions to finish or test_timeout seconds pass
    */
-  ecm->test_start_time = vlib_time_now (ecm->vlib_main);
-  ec_cli ("Test started at %.6f", ecm->test_start_time);
   vlib_process_wait_for_event_or_clock (vm, ecm->test_timeout);
   event_type = vlib_process_get_events (vm, &event_data);
   switch (event_type)
@@ -1332,8 +1358,8 @@ cleanup:
 VLIB_CLI_COMMAND (ec_command, static) = {
   .path = "test echo clients",
   .short_help =
-    "test echo clients [nclients %d][bytes <bytes>[m|g]]"
-    "[test-timeout <time>][syn-timeout <time>][echo-bytes][fifo-size <size>]"
+    "test echo clients [nclients %d][bytes <bytes>[m|g]][test-timeout <time>]"
+    "[run-time <time>][syn-timeout <time>][echo-bytes][fifo-size <size>]"
     "[private-segment-count <count>][private-segment-size <bytes>[m|g]]"
     "[preallocate-fifos][preallocate-sessions][client-batch <batch-size>]"
     "[uri <tcp://ip/port>][test-bytes][verbose]",
index 5868c36..d06f237 100644 (file)
@@ -57,6 +57,7 @@ typedef struct
   volatile u64 rx_total;
   volatile u64 tx_total;
   volatile int run_test; /**< Signal start of test */
+  volatile bool timer_expired; /**< Signal end of timed test */
 
   f64 syn_start_time;
   f64 test_start_time;
@@ -97,6 +98,7 @@ typedef struct
   u64 appns_secret;                    /**< App namespace secret */
   f64 syn_timeout;                     /**< Test syn timeout (s) */
   f64 test_timeout;                    /**< Test timeout (s) */
+  f64 run_time;                                /**< Length of a test (s) */
 
   /*
    * Flags