hsa: various echo client fixes 80/43680/7
authorSemir Sionek <[email protected]>
Tue, 9 Sep 2025 12:47:44 +0000 (12:47 +0000)
committerFlorin Coras <[email protected]>
Fri, 12 Sep 2025 18:00:45 +0000 (18:00 +0000)
Now last_total variables for datagrams are properly initialized.
Batch size for UDP runs when using throughput limiting now caps at 1460
to avoid splitting datagrams.
Final throughput avg printout is now rounded to the nearest integer.

Type: fix
Change-Id: Ia52687b73bd22ec682a971f9ee902572c9212436
Signed-off-by: Semir Sionek <[email protected]>
extras/hs-test/echo_test.go
extras/hs-test/infra/utils.go
src/plugins/hs_apps/echo_client.c

index b4d25d2..7353197 100644 (file)
@@ -242,7 +242,7 @@ func TcpWithLossTest(s *VethsSuite) {
        if !s.CoverageRun {
                s.Log("\nBaseline:  %.2f bytes/s\nWith loss: %.2f bytes/s", baseline, withLoss)
                s.AssertGreaterEqual(baseline, withLoss)
-               s.AssertGreaterEqual(withLoss, baseline*0.15)
+               s.AssertGreaterEqual(withLoss, uint64(float64(baseline)*0.15))
        }
 }
 
@@ -297,6 +297,6 @@ func TcpWithLoss6Test(s *Veths6Suite) {
        if !s.CoverageRun {
                s.Log("\nBaseline:  %.2f bytes/s\nWith loss: %.2f bytes/s", baseline, withLoss)
                s.AssertGreaterEqual(baseline, withLoss)
-               s.AssertGreaterEqual(withLoss, baseline*0.15)
+               s.AssertGreaterEqual(withLoss, uint64(float64(baseline)*0.15))
        }
 }
index e63b8e4..6812ae7 100644 (file)
@@ -10,6 +10,7 @@ import (
        "net/http/httputil"
        "os"
        "os/exec"
+       "regexp"
        "strconv"
        "strings"
        "time"
@@ -368,19 +369,16 @@ func (s *HstSuite) StartUdpEchoServer(addr string, port int) *net.UDPConn {
        return conn
 }
 
-// Parses transfer speed ("N bytes/second full-duplex")
-func (s *HstSuite) ParseEchoClientTransfer(stats string) (float64, error) {
-       lines := strings.Split(strings.TrimSpace(stats), "\n")
-       for i := len(lines) - 1; i >= 0; i-- {
-               line := strings.TrimSpace(lines[i])
-               if strings.Contains(line, "bytes/second") {
-                       parts := strings.Fields(line)
-                       if len(parts) == 0 {
-                               return 0, errors.New("check format of stats")
-                       }
-                       num := strings.ReplaceAll(parts[0], ",", "")
-                       return strconv.ParseFloat(num, 64)
-               }
+// Parses transfer speed ("NBps full-duplex")
+func (s *HstSuite) ParseEchoClientTransfer(stats string) (uint64, error) {
+       pattern := regexp.MustCompile(`(?i)(\d+)\s+bytes/second\s+(?:half|full)-duplex`)
+       match := pattern.FindStringSubmatch(stats)
+       if len(match) == 0 {
+               return 0, errors.New("throughput pattern not found")
+       }
+       uVal, err := strconv.ParseUint(match[1], 10, 64)
+       if err != nil {
+               return 0, fmt.Errorf("failed to parse numeric value '%s': %w", match[1], err)
        }
-       return 0, errors.New(`"bytes/second" not found`)
+       return uVal, nil
 }
index c4c64ba..57f888e 100644 (file)
@@ -493,6 +493,8 @@ ec_reset_runtime_config (ec_main_t *ecm)
   ecm->last_print_time = 0;
   ecm->last_total_tx_bytes = 0;
   ecm->last_total_rx_bytes = 0;
+  ecm->last_total_rx_dgrams = 0;
+  ecm->last_total_tx_dgrams = 0;
   clib_memset (&ecm->rtt_stats, 0, sizeof (ec_rttstat_t));
   ecm->rtt_stats.min_rtt = CLIB_F64_MAX;
   if (ecm->rtt_stats.w_lock == NULL)
@@ -772,7 +774,9 @@ ec_calc_tput (ec_main_t *ecm)
   /* find a suitable pacing window length & data chunk size */
   bytes_paced_target =
     ecm->throughput * ecm->pacing_window_len / ecm->n_clients;
-  while (bytes_paced_target > target_size_threshold)
+  while (
+    bytes_paced_target > target_size_threshold ||
+    (ecm->transport_proto == TRANSPORT_PROTO_UDP && bytes_paced_target > 1460))
     {
       ecm->pacing_window_len /= 2;
       bytes_paced_target /= 2;
@@ -1415,10 +1419,12 @@ ec_print_final_stats (vlib_main_t *vm, f64 total_delta)
   transfer_type = ecm->echo_bytes ? "full-duplex" : "half-duplex";
   ec_cli ("%lld bytes (%lld mbytes, %lld gbytes) in %.2f seconds", total_bytes,
          total_bytes / (1ULL << 20), total_bytes / (1ULL << 30), total_delta);
-  ec_cli ("%.2f bytes/second %s", ((f64) total_bytes) / (total_delta),
+  ec_cli ("%u bytes/second %s",
+         flt_round_nearest (((f64) total_bytes) / (total_delta)),
+         transfer_type);
+  ec_cli ("%UBps %s", format_base10,
+         flt_round_nearest (((f64) total_bytes) / (total_delta)),
          transfer_type);
-  ec_cli ("%.4f gbit/second %s",
-         (((f64) total_bytes * 8.0) / total_delta / 1e9), transfer_type);
 }
 
 static clib_error_t *