Repository navigation
Conversation
extract.awk prints one function definition from a C or C++ file, as it is. The WiFi TX host tests build against the production wifi.cc by extracting the functions they exercise instead of linking the file. The WiFi series adds the same file; this copy lets the TX change stand alone. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add counters for host network stalls, so that a measurement can be decided
from one console line instead of by guessing:
- WiFi linkoutput: the wait for a UART TX buffer, as a histogram in
ticks (0, 1, 2-9, 10-99, 100-999, timed out) and the longest wait. It
runs under the lwIP core lock, so a long wait is a network-wide stall.
- DMA UART: the overflow status bit (counted and cleared with bit 3 of
the interrupt control register, which leaves the enables alone) and
received frames longer than CMD_BUF_SIZE.
net_counters.h is in network/ because that directory is on the include
path of the lwIP libraries as well as of the applications, and the
variable is a weak definition in the header, so every program that
builds dma_uart.cc links without makefile changes. A task started by
initLwip() prints "NETCTR ..." every 5 s when a counter has changed.
The per-frame console bytes of wifi_rx_isr ('N' and '~') are removed; the
'^' and '!' of the ISR mark starvation, not frames, and stay.
Host tests in io/network/tests: the histogram boundaries, and the real dma_uart.cc and
cmd_buffer.c driven through a model of uart_dma.vhd. The register block
of dma_uart.h is a volatile struct whose status/ictrl and length
registers share an address, so the Makefile generates a test copy of the
header with proxy fields. Each part has a red target with models that
must fail.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The counters stay in every build: other code reads them. The task that prints them every 5 s does not: a production build must not write to the console on a timer, and over WiFi a printed line is a syslog frame that changes the counters the next line prints. The reporter and its xTaskCreate are now compiled only when NET_COUNTERS_REPORT is 1 (default 0 in net_counters.h; a diagnostic build sets it). The printf code stays in place, inside the #if. The host test cuts the real reporter and initLwip out of network_interface.cc and runs them against FreeRTOS stand-ins: the default creates no task and prints nothing, the diagnostic setting creates one task and prints at most one line per 5 s round, only on a change. Bounded and measurable. Production does no periodic console output and no task wakeup from the reporter; the reporter is at most one line per 5 s round. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The branches that add counters insert keys into the line, so the test pins the start and the end of the line, not every key between. C64-never-waits: no runtime change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wifi_tx_packet is called by lwIP with the core lock held, and waited up to 5 s (1000 ticks) for one of the 12 UART TX buffers. While the module does not drain the UART (it rebooted, holds RTS, or its dispatcher is blocked), that froze Ethernet, every socket, DHCP and DNS for as long as the module stalled, 5 s per frame. It now takes a buffer without waiting, and only when more than WIFI_TX_RESERVE (2) are free; otherwise it returns ERR_MEM, which TCP answers by keeping the segment (TF_NAGLEMEMERR) and UDP by ENOMEM. Requests (BUFARGS) keep their wait and may use the reserve, so control traffic is not starved by bulk data. A refused frame raises wifi_tx_starved. The DMA UART interrupt calls a hook after it has freed a transmitted buffer (DmaUART::SetTxFreeCallback, generic: the updater and the module link register nothing); wifi.cc's hook, when the flag is up and the free count is above the reserve again, posts a preallocated callback message to the tcpip thread (tcpip_callbackmsg_trycallback_fromisr), which runs tcp_txnow(). Without it a held-back segment waits for the next ACK, the retransmit timer or lwIP's poll. sys_mbox_trypost_fromisr, which lwIP declares but sys_arch.c lacked, is added and reports a woken task as ERR_NEED_SCHED so that the interrupt switches context. NETCTR gets refused=<n>; the wait histogram keeps counting the frames that got a buffer, in its first bucket. Moves toward the real-time design: the core lock is never held across a wait on the module link. Host tests (software/io/network/tests): wifi-tx-nowait (no wait, reserve, the wake, the race between check and flag) and wifi-tx-sim (real lwIP TCP over the real DmaUART ISR on a simulated clock: throughput old against new, a 3 s module stall, the wake), each with models that must fail. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
With two TCP connections that both fill the UART, wifi_tx_free_isr posted tcp_txnow() after every freed buffer once the pool was above the reserve, and lwIP tried and was refused three times per frame: 12771 refusals in 10 s (1277/s) in the real-lwIP simulation (make wifi-tx-sim), each after the TCP checksum of the segment, on the Nios. The wake now needs the pool to be more than WIFI_TX_RESERVE + WIFI_TX_WAKE_HYSTERESIS (2) buffers free. Same two-connection run, RTT 5 ms: refusals 12771 -> 4257 (1277/s -> 425/s, one per frame), wake posts 4257 -> 0, delivered 6215220 bytes in both (old blocking model 6215220). The price: the first TCP frame after a stalled drain is taken 5.0 ms later instead of 0.6 ms, and after other traffic took the pool 6.6 ms instead of 2.2 ms (a frame is 2.3 ms on the UART). Also tried: refusing frames up to reserve+2 while the starved flag is up; it gives 709 refusals/s for the same bytes, so the refusal side stays at the reserve. wifi-tx-sim asserts at most 450 refusals/s for the two connections, a first frame within 6 ms after the stall and within 8 ms after the other traffic; wifi-tx-nowait pins no post at reserve+1 and reserve+2 and one above. Red models: wake without hysteresis (1277/s fails the refusal bound), hysteresis +8 (19.7 ms fails the restart bound), at-the-edge and +1 variants in the unit suite. The C64 never waits on the CPU: fewer refused frames means fewer wasted TCP checksums on the Nios per frame sent, measured as the refused counter in NETCTR; the restart delay stays within a few UART frame times. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
chrisgleissner
left a comment
There was a problem hiding this comment.
@JC-000 thanks for the thorough work here. Returning ERR_MEM from linkoutput is safe: no pbuf is owned, TCP keeps the segment and tcp_txnow retries it, and the starved-flag recheck means a buffer freed in between is not missed.
Requesting changes on these points:
- Unrelated removal.
wifi_cmd.ccdrops the'N'and'~'debug UART writes from the receive interrupt. That is not mentioned in the description. Please explain it or move it to its own change. - Dead counters.
wifi_tx_wait[1..5],wifi_tx_wait_maxandNET_WTX_TIMEOUTcan no longer change, but theNETCTRline still prints them. Please remove them or say why they stay. - Unchecked allocation. If
tcpip_callbackmsg_newreturns NULL, the wake never fires and TCP waits for the next send. Please handle that return value. - Description. UDP, ICMP and ARP frames are not retried, only TCP segments, so "ARP re-queues" is not accurate.
I'll merge once these are in.
|
@JC-000 thank you for the careful work on the WiFi TX path. I had said I would take this PR over. I am handing it back to you, so please treat it as yours again. I pushed nothing to your branch. This is what is outstanding:
Once these are done, I will review it again. |
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The previous commits dropped them without saying so. tooling/c64u_monitor.py counts the '~' of unsolicited ESP32 messages. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ead wait counters wifi_tx_wake_init left wifi_txnow_msg NULL when tcpip_callbackmsg_new failed, so the TX-done interrupt could never wake the tcpip thread and TCP waited for its next send. A refused frame now retries the allocation. Host test no_message_at_init_is_retried_at_the_next_refusal fails without it (make wifi-tx-nowait-red-no-msg-retry). wifi_tx_wait[], wifi_tx_wait_max and NET_WTX_* cannot change any more, so they are removed from net_counters.h and the NETCTR line, with the histogram test. Nothing reads the NETCTR layout: the reporter test is the only consumer. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ake_init in the WiFi task host tests The wake message is now a static struct tcpip_msg (TCPIP_MSG_CALLBACK_STATIC) filled in by wifi_tx_wake_init: nothing is allocated, so there is no NULL to handle, no retry and no lost wake; this replaces the retry added in the previous commit. The host test checks that the interrupt posts that message and that the tcpip thread's call of it reaches tcp_txnow (red model: wifi-tx-nowait-red-no-msg-init). wifi_tx_wake_init is stubbed in io/wifi/tests/wifi_task_stubs.cpp, since WiFi::Init, which that suite extracts, now calls it. io/wifi/tests and io/network/tests (all targets) pass in an ubuntu:24.04 container. Correction to the previous commit message: nothing upstream reads the NETCTR layout, but our own bench parser (net_bench.py) does and is updated outside this repository. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for handing it back. All six points are done in new commits on top of a merge of master; nothing was rebased.
Host tests: Written with Claude Opus and Claude Sonnet in Claude Code. |
|
Thanks, the four points are addressed: the N and ~ writes are back, the dead counters are gone, the wake message is static so there is no allocation to check, and the description is corrected. The red run on the Elite is a good addition. One thing left before I approve. The hardware rows ran an earlier form of the change. The head now wakes TCP through a static tcpip message and the counters were removed, and those are covered by host tests only. Could you run the hold test once on the head (ping gap, loss and REST latency) on a C64 Ultimate or the Elite and add the row? No other open points. |
|
Thanks. I ran the hold test on the head's code on the Ultimate 64 Elite, as a RAM bench build with the hold command and the full-size UDP change (#835) added, with the same test and settings as the earlier rows: three 3000 ms holds, ping max gap 111.2 / 110.5 / 113.9 ms (10 Hz ping), loss 0 %, REST max latency 22 / 49 / 23 ms. The row is added to the description. The head has no counters, so the hold itself is confirmed only by the module's "00,OK". Written with Claude Opus and Claude Sonnet in Claude Code. |
…etwork/tests/Makefile
|
@JC-000 thanks for the work on this and for the re-run on the head. I am taking the remaining merge work. What I am adding: one commit that merges current master (6f89946 plus #1085) into Testing: I will repeat the hold test red/green on the Ultimate 64 Elite and, if the module can be loaded there, on the C64 Ultimate and the U2+L. The hold needs your bench-only module command that stops the module accepting frames. Could you push it somewhere I can build from (a branch or a patch in a gist), or say which commit carries it? I will not add it to this PR. If you disagree with the merge commit, say so and I will revert it. |
|
@JC-000 to save you some time, I'm happy to write the bench-only module command for the hold test and run it red/green on all three devices, now that the C64 Ultimate can take module builds too. I'll post it with the results, and none of it will be added to this PR. If you already have the command on a branch, a pointer is welcome and I'll use yours. |
|
Thanks. We have this underway: one bench-only hold command for both #1071 and #1078 (an optional RTS-off flag for the forced overflow, plus an end-of-hold event that reports whether the RX FIFO overflowed), ported onto current master for raw_u64, u64ctrl and raw_c3. It applies cleanly to master, to this PR's head and to #1078's head, and it builds and passes host tests. It has not run on hardware yet; that happens on our Elite today. I'll post the branch link with the results afterwards. If you'd rather not wait, go ahead with your own. Written with Claude Sonnet 5.5 and Claude Opus 5.5 in Claude Code. |
|
@JC-000 great, thank you. This is all yours: I'll wait for your branch and your results and won't run a version of my own. Your bench work across #1071, #1078 and #1079 is much appreciated. If extra devices help once your branch is up, I'm happy to run the same steps on our C64 Ultimate and U2+L and add the numbers. Just say if you'd like that. |
|
The hold branch is up: https://github.com/JC-000/1541ultimate/tree/45bb9428bea4778857bdff5b1c0650878dfa9aec/repro/module-hold (branch What ran on our Ultimate 64 Elite, on our bench image plus this branch. That image still has the waiting TX code, so these are the #1071 "before" numbers, under a steady 600 packets/s UDP stream to the WiFi address:
Every hold answered Written with Claude Sonnet 5.5 and Claude Opus 5.5 in Claude Code. |
Fixes #1060
Problem
Whenever the ESP32 WiFi module stops taking frames for a moment, the whole network stack — Ethernet included — freezes for several seconds. When the module stops draining its UART (its RX FIFO fills and it asserts RTS, as a congested or briefly busy module does), the host's pool of TX command buffers empties. The WiFi
linkoutputthen waits up to 5 s for a buffer while holding the lwIP core lock, so every part of the stack that needs that lock stops too — including Ethernet and the REST API, which have nothing to do with WiFi.Cause, on current master:
wifi_tx_packet(software/io/wifi/wifi.cc:452) gets a TX buffer through theBUFARGS_NOREPLYpath, which blocks onGetBufferwith a timeout while the lwIP core lock is held. A frame that cannot get a buffer waits the full timeout before failing.What changed and why
linkoutputnever waits: it takes a buffer only if the free pool is above a small reserve (GetBufferKeeping, reserve 2), otherwise it returnsERR_MEMimmediately. A TCP segment that gets ERR_MEM is kept by TCP and sent again (tcp_txnowon the wake, or its normal retransmit). UDP, ICMP and ARP frames are not retried by the driver; the protocols' own timers apply. A TX-done interrupt wakes the TX path (above a hysteresis) via an lwIPtcpip_callbackmsg, so throughput recovers at once when buffers free. RPC traffic is untouched (it still waits, as before). Every refusal is counted.The wake after a refusal is a static lwIP message, so nothing is allocated. The 'N' and '~' console writes of the receive interrupt are unchanged.
This change carries the host network counters it is measured with (
refused,ovfandrxlong): the counters are the only hardware instrument for it, so they ship with it.Products. every product with the WiFi module: the Ultimate 64, Ultimate 64 Elite II, C64 Ultimate and the Ultimate-II cartridges (U2+, U2+L). Tested on the Ultimate 64 Elite and the C64 Ultimate.
How I tested it
Host: macOS, with the device-free tests run in an Ubuntu 24.04 container (g++ 13.3). The hardware runs used the test harness from the same machine.
Host tests (device-free, run before and after the change):
make -C software/io/network/tests all-redtargets: for wifi-tx-nowait the legacy waiting code and 15 broken variants, all failing as required; the wifi-tx-sim ones as before (the simulation of the old path shows a longest block of 2975 ms against 0 ms)make -C software/io/wifi/tests(three builds: 104, 104 and 50 tests) passes.wifi.ccincludeslwip/priv/tcpip_priv.hfor the static message, the same way lwIP's owntcpip_callbackmsg_newbuilds it;wifi.ccand the lwIP library are built with the same lwipopts, so the message layout matches.Hardware.
RED = the image with only the WiFi send function reverted to master's waiting code; GREEN = the fix. The C64 Ultimate images were loaded cold. On the Elite, RED is a RAM build of the red tree and GREEN is the flashed image. Same test and settings for both: three 3000 ms holds of the module's receive side under a 300 pkt/s WiFi flood. A bench-only diagnostic makes the module stop accepting frames so its transmit buffers run out — the condition a congested or briefly busy module creates.
C64 Ultimate:
Ultimate 64 Elite:
The syslog counters did not arrive in the Elite window, so the refused counts are not part of the Elite rows. The RED and GREEN images carry the earlier form of the change. The "current head" column is a RAM build of the PR head with the same bench hold command and #835 added, run with the same test and settings. The head has no counters, so in that run the hold is confirmed only by the module's "00,OK" reply; the ping gap stays at the 10 Hz ping interval (baseline before the holds: 110.2 ms gap, 19.5 ms REST).
Host suites
wifi-tx-nowait(15) andwifi-tx-sim(7) pass; built-in RED/legacy targets and mutants are killed.Standard profile (
./run-tests --profile standard), red = master, green = a build carrying this landing set of fixes (this change included), report frompython3 tools/e2e_report.py:iec-partition-config: it stops at a key-send step because the upstream test's REST backend has noF2key alias (rest_backend.py:556), a test-side limitation, not an app difference.iec-partition-config, here at a "menu screen unavailable" step that also fails on master, so it is not from these changes.Soaks pass on both devices: mount-cache-leak, listener-soak, network-connection.
Untested
dma_uart.cc/.hconflict with open PR Add authenticated HTTPS to the existing target 6 HTTP interface #936;network/tests/Makefilewith Send the whole HTTP request, and give up on a stalled server (#1039) #1043 and Give lwIP enough reference pbufs for concurrent UDP sends #1038.Written with Claude Opus 5.5 in Claude Code.