Repository navigation
Match WiFi module replies by slot and sequence, bound the wait - #1006
Conversation
The reply tag was the number of the TX buffer, which is freed once sent, long before the reply arrives. Every network frame took a TX buffer through BUFARGS and registered its sender as the waiter for that number, though the module never answers frames. A command reply could therefore wake the task that sent a frame, and the real caller waited forever. Replies now use a separate table of slots. A slot is released when its reply is taken or the wait is abandoned, and a reply is delivered only if its sequence matches the one the slot was claimed with. Frames do not register. Commands wait at most 10 s (60 s for scan and connect), and free the reply buffer. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Conflicts: Makefile (host_tests list: keep wifireply beside the new recovery tests) and software/io/wifi/wifi_cmd.h (keep this branch's reply declarations, drop the extern sequence_nr and tasksWaitingForReply that it removes, keep the recovery URL declarations from master). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
BUFARGS_NOREPLY returned pdFALSE (0) when the UART had no free TX buffer. The RPCs answer 0 for success, so every one of them read that as done, and wifi_tx_packet returned ERR_OK for a frame that was never queued. The macro now takes the value to return: -1 for the RPCs (as a missing reply slot already does), pdFALSE for wifi_detect, whose result is a success flag, and ERR_MEM for wifi_tx_packet. The host test builds wifi_cmd.cc against stubs of the UART and the RTOS and checks the RPCs and wifi_detect with no TX buffer, that this uses no reply slot, and that a request without a reply is still -1. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Merged master (9978476) into this branch; it was conflicting. Two conflicts, both mechanical:
Also added one commit: a starved TX buffer is now a failure. Written with Claude Sonnet 5.5 in Claude Code; reviewed adversarially by separate Claude Opus 5.5 sessions before posting. 🤖 Generated with Claude Code |
There was a problem hiding this comment.
Thank you, @JC-000, for addressing both inline findings in 7ead3d2 and replying in their threads.
Both threads are resolved and I verified the fixes. The host suite, ASan/UBSan checks, and GitHub build pass. The five timeout/drain mutations fail 24/5/6/28/25 checks; the legacy model reports five expected assertion failures without crashing. No code-review finding remains open.
Targeted U64 RED/GREEN passes on core 1.50 / FPGA 126: base 9978476 froze on loaded reconnect 1 (UI silent 60 s, 25 successful REST probes); the PR firmware completed 40 loaded reconnects without a stall. Separate WiFi, Ethernet, simultaneous-interface stress, edge-mode and link-recovery checks passed.
It would be appreciated if you could run a controlled at least 1h WiFi/Ethernet soak test (see tests/soak/README.md and specifically network/connection_test.py for details), just to ensure nothing regressed, and add the high-level results here.
Otherwise, this is ready to merge from my perspective.
… belongs The no-reply test passed with the slot release removed: once the leaked slots were used up, the request failed before it was sent, which is -1 too. It now checks that every request is sent, that its wait is bounded by the command timeout, and that all reply slots can be claimed afterwards. The notification stub can now deliver, and like FreeRTOS it writes the notification value even when it returns pdFALSE. The module's reply is checked at three moments: during the wait, after the wait timed out but before the slot is released (only the drain after the release takes it), and after the release. The first two give the caller the reply, not -1, and free its buffer; the last goes to the receive queue and the call is -1. The legacy model of the table indexed it with thread 0xFF. It now checks the thread as the ISR before the fix did (thread < NUM_TX_BUFFERS), so make legacy fails its 5 checks instead of crashing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Hi @JC-000, Could you please perform the soak test mentioned earlier and publish the results? It would be good to merge in past PRs before raising new ones. Many thanks |
|
Soak results for this PR, as asked: a 2 x 60 min run of Setup. Ultimate 64 Elite, core 1.50, firmware 3.15a. Image: this PR's head (7ead3d2) plus #835 (4592eb1) merged on top and nothing else; #835 is there only because it is the UDP change my other bench work needs, and it does not touch the WiFi code. The ESP32 module was master's (V1.6), flashed over a newer bench module for this run. Config reset to defaults before the run; nothing else set. Suite.
Latency, p50 / p99 in ms, last summary line:
The telnet figure is the probe's own pace: its settings operations walk the menu cursor one row at a time, reading the screen back after every key ( Both legs exited 0, and telnet and ftp accepted a new session right after each run. On the Ethernet leg the audio and video stream monitors received 890,492 and 12,801,759 packets with none lost or reordered. Streams are Ethernet-only in the firmware ( Two macOS workarounds, both outside the suite. The ping probe runs There is no baseline on master, so this shows no failures and plausible latencies, not a before/after comparison. Written with Claude Sonnet 5.5 in Claude Code. |
|
Thanks @JC-000 , much appreciated! |
Fixes #1005
Reviewers: @GideonZ (WiFi and UART layer; no area contact is listed for them).
The fix
software/io/wifi/wifi_reply.h: a table of 12 reply slots, separate from the TX buffers.hdr.threadcarries the slot,hdr.sequencea per-request sequence. The module already echoes both, so the module and the wire format are unchanged.wifi_rx_isrdelivers a reply only if the slot is taken and the sequence matches. Anything else goes to the receive queue as before.wifi_tx_packetno longer registers a waiter (BUFARGS_NOREPLY). The module never answers frames.TRANSMITandwifi_setbaudis gone; the ISR releases the slot.BUFARGS_NOREPLYtook the failure value as 0, which the RPCs read as success andwifi_tx_packetasERR_OK. It now takes the value to return: -1 for the RPCs,pdFALSEforwifi_detect(a success flag),ERR_MEMforwifi_tx_packet. A UDP send over WiFi now fails with ENOMEM instead of reporting success when the buffers are starved (lwIP keeps a TCP segment queued and retries it). The power-on mode, wake-on-WiFi and recovery-server writes no longer retry on a starved buffer; they give up at once.wifi_detectandwifi_setbauduse the same path, andwifi_detectfrees its reply buffer.sequence_nris now taken under the same critical section as the slot (it was incremented unlocked).Why this closes the interleavings: a frame can no longer write any slot (A). A reply is accepted only for the sequence its slot was claimed with, and a slot is released by the ISR on delivery or by the owner on timeout (and all slots are cleared when the WiFi command channel is initialised, so a task deleted while it waited cannot be notified later), so a stale or duplicate reply for a reused slot has the wrong sequence and is dropped, and nothing erases a newer owner (B). A timeout releases the slot, so a late reply cannot be taken for the next call and shift the replies (C). A reply that arrives while the owner is abandoning is taken in the drain after the release, so its buffer is freed. The wait is bounded, so a lost reply can no longer hang the caller.
Claiming a slot fails (like running out of TX buffers) if all 12 are in use.
Tests
make -C target/pc/linux/wifireply test(also inmake host_tests). It covers plain delivery, frames while a command waits, a late reply after abandon with the slot reused, unknown reply, exhaustion and sequence wrap. The same target buildswifi_cmd.ccagainst stubs of the UART and the RTOS and checks the RPCs andwifi_detectwhen there is no TX buffer (-1 andpdFALSE, no reply slot used) and that a request without a reply is -1.make legacymodels the old table (it is a model, not master's code) and fails 5 checks. Not run by CI.wifi_misroute.pyfrom WiFi module replies can wake the wrong task, and the real caller then waits forever #1005:make u64_no_esp(size report PASS),make u64ii_no_espandmake -C target/u2plus_L/riscv/ultimatecompile and link the application; the u64ii updater step needs the ESP bins and was not run.Untested
wifi_tx_packetreturningERR_MEMon a starved buffer (compiled, not exercised: the host test does not link wifi.cc). None of the starved-buffer cases can be triggered on demand on a real device, so they are covered by the host test only.The first two commits and the last one were written with Claude Opus 5.5, the merge and the fourth commit with Claude Sonnet 5.5, in Claude Code; reviewed by separate sessions.
🤖 Generated with Claude Code