raspberrypi: keep core1's mutex-contention wait path out of flash#11120
Open
mikeysklar wants to merge 1 commit into
Open
raspberrypi: keep core1's mutex-contention wait path out of flash#11120mikeysklar wants to merge 1 commit into
mikeysklar wants to merge 1 commit into
Conversation
When core1 posts a USB event while core0 holds the TinyUSB queue mutex, core1 falls into the pico-sdk blocking wait, which lived in flash. Core1 cannot execute from flash, so a contended moment hard faults core1 and USB host goes silent. Fixes adafruit#11116. On USB host builds only, --wrap best_effort_wfe_or_timeout and time_us_64 with RAM-resident implementations in usb_host/Port.c. The best_effort replacement mirrors the SDK's own documented PICO_TIME_DEFAULT_ALARM_POOL_DISABLED fallback (poll the clock, allow early return), so no alarm pool machinery is pulled into RAM. The time_us_64 replacement keeps the SDK's hi/lo/hi rollover re-read loop. Also RAM-place pico_int64_ops_aeabi.o (50 bytes) next to divider.o in the linker scripts: mutex_enter_timeout_ms multiplies ms to us through __aeabi_lmul, and the SDK already wraps that symbol so it cannot be wrapped again per-feature. Cost: +64 bytes RAM on USB host builds, 50 bytes on builds with CIRCUITPY_USB_HOST=0 (Pico baseline 70320 -> 70384). The previous approach in this branch cost 1216 bytes on every build. With this, the core1 flash-call checker (adafruit#11115) passes on Feather RP2040 USB Host, Fruit Jam, and Raspberry Pi Pico builds. Smoke tested on the Feather: 20 SCSI read/write cycles to a flash drive. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
Author
|
@dhalbert - Initially this fix was up to 3.4kB of RAM, but I knew nobody would allow that so the LLM used linker --wrap and kept memory usage under 64 bytes. |
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.
Fixes #11116, the last bug found by the checker in #11115.
When core1 posts a USB event while core0 holds the TinyUSB queue mutex, core1 falls into the pico-sdk blocking wait, which lived in flash. Core1 cannot run flash code, so one contended moment hard faults core1 and USB host goes silent.
Fix: on USB host builds only,
--wrapthe two flash functions on that path (best_effort_wfe_or_timeout,time_us_64) with RAM implementations in usb_host/Port.c. The best_effort replacement is the SDK's own documented no-alarm-pool fallback (poll the clock, early return allowed), so nothing else gets dragged into RAM. Also moves the 50-byte__aeabi_lmulhelper to RAM next to divider.o in the linker scripts, since the SDK already wraps that symbol.Cost: +64 bytes RAM on USB host builds, 50 bytes otherwise (measured on Pico: 70320 -> 70384). Earlier drafts of this fix cost 1.2-3.4 kB on every board;
--wrapwas chosen because this port already uses it for 150+ libgcc symbols and the shims are tiny and contract-stable.With this, the #11115 checker passes on Feather RP2040 USB Host, Fruit Jam, and Pico builds, so every known core1 flash hazard is fixed and the checker can become a CI gate. Smoke tested on the Feather: 20 SCSI read/write cycles to a flash drive.