From f263d2cbdf176b6edbd604147b9c3fed89d44aac Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Wed, 20 Aug 2025 21:33:04 -0700 Subject: [PATCH] fix divide by zero error tcp_stream clients don't receive any payload, and so would try to divide by zero when used with --rx-zerocopy. Renames a few local variables to avoid line splitting. --- thread.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/thread.c b/thread.c index 2ae4030..63d4bda 100644 --- a/thread.c +++ b/thread.c @@ -662,16 +662,17 @@ int run_main_thread(struct options *opts, struct callbacks *cb, control_plane_destroy(cp); if (opts->rx_zerocopy) { - uint64_t total_rx_zc_bytes = 0; - uint64_t total_rx_bytes = 0; - uint64_t percent_mmaped; + uint64_t total_zc_bytes = 0; + uint64_t total_bytes = 0; + uint64_t percent_mmaped = 0; for (int i = 0; i < opts->num_threads; i++) { - total_rx_zc_bytes += ts[i].io_stats.rx_zc_bytes; - total_rx_bytes += ts[i].io_stats.rx_bytes; + total_zc_bytes += ts[i].io_stats.rx_zc_bytes; + total_bytes += ts[i].io_stats.rx_bytes; } - percent_mmaped = 100 * total_rx_zc_bytes / total_rx_bytes; - PRINT(cb, "bytes_mmaped", "%lu", total_rx_zc_bytes); + if (total_zc_bytes > 0) + percent_mmaped = 100 * total_zc_bytes / total_bytes; + PRINT(cb, "bytes_mmaped", "%lu", total_zc_bytes); PRINT(cb, "percent_mmaped", "%lu", percent_mmaped); if (percent_mmaped < 10) { LOG_WARN(cb, "Little traffic is being handled by "