From f7baf60249871e28fff80b6dd00f20bebdb2a1f8 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 11 Apr 2026 09:29:34 +0900 Subject: [PATCH] Pipeline ping rate tests, small=1 large=2 in-flight --- firmware/lib/test_handlers.cpp | 45 ++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/firmware/lib/test_handlers.cpp b/firmware/lib/test_handlers.cpp index 9d3b4d4..01cd67d 100644 --- a/firmware/lib/test_handlers.cpp +++ b/firmware/lib/test_handlers.cpp @@ -164,8 +164,10 @@ struct ping_rate_state { responder resp; timer_handle timer = nullptr; uint16_t ping_id; - uint16_t count = 0; + uint16_t sent = 0; + uint16_t received = 0; uint16_t target; + uint16_t pipeline; uint16_t payload_len; uint32_t start_us; peer_info peer; @@ -177,16 +179,15 @@ struct ping_rate_state { } }; -static void ping_rate_send(std::shared_ptr st, - std::shared_ptr)>> cb) { +static void ping_rate_send_one(std::shared_ptr st) { prepend_buffer<4096> buf; if (st->payload_len > 0) memset(buf.append(st->payload_len), 0xAA, st->payload_len); icmp::prepend_echo_request(buf, st->our_mac, st->our_ip, st->peer.mac, st->peer.ip, st->ping_id, - st->count + 1, st->payload_len); + st->sent + 1, st->payload_len); net_send_raw(buf.span()); - net_add_frame_callback(*cb); + st->sent++; } static void ping_rate_recv(std::shared_ptr st, @@ -202,19 +203,19 @@ static void ping_rate_recv(std::shared_ptr st, return; } - st->count++; - if (st->count >= st->target) { + st->received++; + if (st->received >= st->target) { dispatch_cancel_timer(st->timer); uint32_t elapsed_us = time_us_32() - st->start_us; uint32_t elapsed_ms = elapsed_us / 1000; uint32_t pps = static_cast( - static_cast(st->count) * 1000000 / elapsed_us); - uint64_t total_bytes = static_cast(st->count) * 2 * st->frame_size(); + static_cast(st->received) * 1000000 / elapsed_us); + uint64_t total_bytes = static_cast(st->received) * 2 * st->frame_size(); uint32_t kbps = static_cast(total_bytes * 1000 / elapsed_us); char msg[128]; snprintf(msg, sizeof(msg), "%u rt in %lu ms, %lu pps, %lu bytes, %lu KB/s", - st->count, static_cast(elapsed_ms), + st->received, static_cast(elapsed_ms), static_cast(pps), static_cast(total_bytes), static_cast(kbps)); @@ -222,19 +223,22 @@ static void ping_rate_recv(std::shared_ptr st, return; } - ping_rate_send(st, cb); + if (st->sent < st->target) + ping_rate_send_one(st); + net_add_frame_callback(*cb); } static void start_ping_rate(const responder& resp, uint16_t target, - uint16_t payload_len) { + uint16_t payload_len, uint16_t pipeline) { auto& ns = net_get_state(); discover_peer( - [resp, ns, target, payload_len](const peer_info& peer) { + [resp, ns, target, payload_len, pipeline](const peer_info& peer) { auto st = std::make_shared(); st->resp = resp; st->ping_id = 0x5678; st->target = target; + st->pipeline = pipeline; st->payload_len = payload_len; st->our_mac = ns.mac; st->our_ip = ns.ip; @@ -246,15 +250,18 @@ static void start_ping_rate(const responder& resp, uint16_t target, ping_rate_recv(st, cb, frame); }; + for (uint16_t i = 0; i < st->pipeline && st->sent < st->target; i++) + ping_rate_send_one(st); + net_add_frame_callback(*cb); + st->timer = dispatch_schedule_ms(60000, [st]() { uint32_t elapsed_us = time_us_32() - st->start_us; char msg[64]; - snprintf(msg, sizeof(msg), "timeout after %u rt in %lu ms", - st->count, static_cast(elapsed_us / 1000)); + snprintf(msg, sizeof(msg), "timeout after %u/%u rt in %lu ms", + st->received, st->sent, + static_cast(elapsed_us / 1000)); st->resp.respond(ResponseTest{false, {msg}}); }); - - ping_rate_send(st, cb); }, [resp]() { resp.respond(ResponseTest{false, {"no peer found"}}); @@ -262,11 +269,11 @@ static void start_ping_rate(const responder& resp, uint16_t target, } static void test_ping_rate(const responder& resp) { - start_ping_rate(resp, 8192, 0); + start_ping_rate(resp, 8192, 0, 1); } static void test_ping_rate_1k(const responder& resp) { - start_ping_rate(resp, 1024, 1024); + start_ping_rate(resp, 1024, 1024, 2); } using sync_test_fn = ResponseTest (*)(const responder&);