Repository navigation
stage3: two boot-time performance improvements - #24
Open
BlairLeduc wants to merge 2 commits into
Open
BlairLeduc wants to merge 2 commits into
BlairLeduc wants to merge 2 commits into
Conversation
wait_ready() and rcvr_datablock() slept 100 us between polls. The card only moves on while it is being clocked, so each sleep stalled it, and reading a sector took about 3 ms. Poll continuously instead, with the same 500 ms and 100 ms timeouts, now measured in time rather than in iterations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
read_bootmode() watched the keyboard for 0.5 s on every boot, then a command from bl_stage3_command() replaced whatever it had read. Check for the command first and watch the keyboard only when there is none. A boot with no command behaves as before; a commanded one (a RAM app from the menu, or an app returning to it) no longer waits 0.5 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
This PR submits two small, independent changes to stage3. Neither commit changes the boot process. This is a performance improvement only.
Poll the SD card without sleeping (
common/petit_fatfs/diskio.c).wait_ready()andrcvr_datablock()sleep 100µs between polls. The card only makes progress while it is clocked, so every sleep stalls it, and a sector took about 3ms to read. They now poll continuously, withthe same 500ms and 100ms timeouts measured in time rather than in
iterations.
Read the command before waiting for a key (
stage3/stage3.c).read_bootmode()watches the keyboard for half a second on every boot, andthen any command from
bl_stage3_command()replaces the key press, if any.The command is now checked first, and the keyboard is watched only when
there isn't a command. A boot without a command (power-on, or an app's reboot)
behaves exactly as before.
Measured
I used a PicoCalc with a Pimoroni Pico Plus 2 W,
pico2build, SDK 2.3.1,GCC 15.2, each stage3 written at offset 0 over SWD. A 118KB RAM app
logs a line on UART0, reboots itself with
BOOT_RAMand its own path1s later, and logs again at its next start; the time is the gap
between the two lines minus that 1s, five runs each:
BOOT_RAMto the appThe two savings add up: about 0.09s from the polling and 0.50s from
the command.
BOOT_SD(an app returning to the menu) takes the samepath through stage3 with
LOADERas the file.stage3 grows by 80B on
pico2(6,740 → 6,820B of 8KB) and 72B onpico(6,636 → 6,708B); RAM is unchanged.Not checked
picobuild compiles but I have not run it.as nothing reads it. The apps I ran set it up themselves.
🤖 Generated with Claude Code and edited by Blair Leduc.