zephyr-cp/wifi: bound the scan wait and run background tasks - #11214
Open
mikeysklar wants to merge 1 commit into
Open
zephyr-cp/wifi: bound the scan wait and run background tasks#11214mikeysklar wants to merge 1 commit into
mikeysklar wants to merge 1 commit into
Conversation
common_hal_wifi_scannednetworks_next() waited with k_poll(K_FOREVER). That wait ends only on a result, a channel_done signal, or ctrl-C. Nothing guarantees any of those arrive, so if the driver stops reporting there is no way out of the loop. This is a defensive bound, not a fix for an observed field failure. A normal scan is unaffected: results arrive steadily and the loop cycles well inside the limit. espressif and raspberrypi both bound their equivalent loops and run background tasks inside them (ports/espressif/common-hal/wifi/ScannedNetworks.c:39, ports/raspberrypi/common-hal/wifi/ScannedNetworks.c:67). zephyr-cp did neither. Poll in 50 ms slices with background tasks between them, and end the scan if nothing arrives for 10 s. The window restarts whenever a channel completes, so the limit is on the driver going quiet rather than on how long a full sweep takes. Elapsed time is an unsigned subtraction from the start, which stays correct across the 32-bit millisecond rollover. No new state: the start timestamp is a local, so this costs no RAM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
common_hal_wifi_scannednetworks_next()waited withk_poll(K_FOREVER). That wait ends only on a result, achannel_donesignal, or ctrl-C. Nothing guarantees any of those arrive, so if the driver stops reporting there is no way out of the loop.This is a defensive bound, not a fix for an observed field failure. A normal scan is unaffected: results arrive steadily and the loop cycles well inside the limit.
Why
espressif and raspberrypi both bound their equivalent loops and run background tasks inside them:
ports/espressif/common-hal/wifi/ScannedNetworks.c:39ports/raspberrypi/common-hal/wifi/ScannedNetworks.c:67zephyr-cp did neither.
How
Poll in 50 ms slices with background tasks between them, and end the scan if nothing arrives for 10 s. The window restarts whenever a channel completes, so the limit is on the driver going quiet rather than on how long a full sweep takes.
Elapsed time is an unsigned subtraction from the start, which stays correct across the 32-bit millisecond rollover. The start timestamp is a local, so this adds no per-object state.
Testing
One board, one host, before and after builds from the same tree on the same day.
10.3.0-alpha.4-63-g88c0b27e1a-dirty, built 2026-08-18Both builds report the same version string, because only working tree files differ between them and that is what
-dirtycovers. The two images are distinguished by the build log:RUN_BACKGROUND_TASKSappears 0 times in the before image and 1 time in the after image.Method: hard reset the board, run one scan to completion, and poll
/cp/version.jsonfrom the host every 0.25 s throughout, recording HTTP status and response time for the samples that fall inside the scan window.RUN_BACKGROUND_TASKSin buildNo regression: scanning works the same and the web workflow stays served.
The difference in network count is ordinary RF variance between runs, not an effect of the patch. A separate clean scan on the before image returned 73 networks in 6.68 s.
Worst case response time during a scan was lower on the after image, which is the direction adding
RUN_BACKGROUND_TASKSwould predict. This is one run per side, so treat it as an observation rather than a measured result.Not tested: the timeout path itself. Reaching it needs the driver to stop delivering results, which I could not induce on demand. A second DK2605A was available but on a host without flashing tools, so all results above are from a single board.
Scope
Bounds the wait and runs background tasks. Does not change how results are collected or deduplicated.
AI assistance
Written with Claude Code. I ran the hardware myself. The numbers above are from the board, not from a model.