From 7b728cec6fa8655a9a85ffe9c406e845372858a0 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Sun, 20 Sep 2026 02:46:49 +0200 Subject: [PATCH] rtlplayground: do not sleep in idle() while a packet is waiting idle() went to sleep before it looked at the receive buffer, so a packet that arrived just after the loop dozed off waited for the next tick before anything touched it. Every TCP round-trip paid that toll, which is why the web UI felt sluggish even though no phase of the loop was anywhere near busy. Check the receive buffer first and only sleep when it is empty. The read takes its result straight from SFR_DATA_U16 rather than going through reg_read_m() and the sfr_data[] copy, which is what the rest of the tree already does. Measured on SWTGW218AS with this change alone: web UI, median of 15 requests for the main page 88 ms -> 76 ms CPU port under a one-way UDP stream 159 -> 230 packets/s The loop still sleeps normally when there is nothing to do, so this does not turn the core into a busy-wait: loops/ticks stays at 0.99 on an idle switch, and rises above 1.0 only while packets are actually queued. Costs 12 bytes of code and no extra XDATA. --- rtlplayground.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rtlplayground.c b/rtlplayground.c index 1151d397..24c04f08 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -1157,7 +1157,9 @@ void handle_button(void) // void idle(void) { - PCON |= 1; + reg_read(RTL837X_REG_NIC_RX_BUFF_DATA); + if (!SFR_DATA_U16) + PCON |= 1; if (sec_counter >= SYS_TICK_HZ) { sec_counter -= SYS_TICK_HZ; reg_read_m(RTL837X_REG_SEC_COUNTER);