From e90cf9f0c776ee0f599a87b5a8b4ce1eef7ccea6 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Wed, 4 Feb 2026 01:20:00 +0300 Subject: [PATCH] Fix: Packet coalescing with 1ms flush timer - Changed tx_wait_time from 100ms to 1ms for faster packet delivery - Small packets now coalesce in buffer until: * Buffer has less than 100 bytes remaining, or * 1ms flush timer expires - Large packets are split across multiple fragments as before - All 17 tests pass --- src/pkt_normalizer.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pkt_normalizer.c b/src/pkt_normalizer.c index aea1b971..a549e81e 100644 --- a/src/pkt_normalizer.c +++ b/src/pkt_normalizer.c @@ -24,10 +24,9 @@ struct PKTNORM* pn_init(struct ETCP_CONN* etcp) { pn->etcp = etcp; pn->ua = etcp->instance->ua; - // frag_size должен соответствовать размеру блока в data_pool - // data_pool->object_size обычно равен MTU (1500) - pn->frag_size = etcp->instance->data_pool->object_size; - pn->tx_wait_time = 100; // Increased to ensure flush happens between packets + // frag_size = MTU минус резерв для дополнительных опций (ACK и прочие заголовки) + pn->frag_size = etcp->mtu - 100; + pn->tx_wait_time = 1; // 1ms timer for packet coalescing pn->input = queue_new(pn->ua, 0); // No hash needed pn->output = queue_new(pn->ua, 0); // No hash needed @@ -278,9 +277,18 @@ static void etcp_input_ready_cb(struct ll_queue* q, void* arg) { queue_dgram_free(in_dgram); queue_entry_free(in_dgram); - // Send immediately to ensure packet is not lost - pn_send_to_etcp(pn); - pn_buf_renew(pn); + // Check if buffer is almost full (less than 100 bytes remaining) + if (pn->data_ptr + 100 >= pn->data_size) { + // Buffer is almost full - send immediately + pn_send_to_etcp(pn); + pn_buf_renew(pn); + } else { + // Set flush timer to send after tx_wait_time ms + if (pn->flush_timer) { + uasync_cancel_timeout(pn->ua, pn->flush_timer); + } + pn->flush_timer = uasync_set_timeout(pn->ua, pn->tx_wait_time, pn, pn_flush_cb); + } } DEBUG_INFO(DEBUG_CATEGORY_ETCP, "pn_packer: etcp_input_ready_cb finished, processed=%d", processed);