Skip to content

perf(zaparoo): reduce launcher startup contention#10

Merged
asturur merged 10 commits into
masterfrom
codex/zaparoo-launcher-startup
Jun 15, 2026
Merged

perf(zaparoo): reduce launcher startup contention#10
asturur merged 10 commits into
masterfrom
codex/zaparoo-launcher-startup

Conversation

@asturur

@asturur asturur commented Jun 13, 2026

Copy link
Copy Markdown
Member

Summary

  • add a Zaparoo lifecycle-gated scheduler sleep so Main_MiSTer yields CPU while the launcher is pending or running
  • keep the initial Main_MiSTer CRT fb mode write before fork, but remove the post-startup 100 ms rewrite and the 1 s retry rewrite
  • snapshot the boot/current framebuffer mode before CRT launch and restore it when returning to stock mode
  • replace the agetty/shell trampoline with direct tty2 setup and direct frontend exec
  • restore non-blocking spawn finalization so tty readiness polling does not stall input polling
  • skip the forced Zaparoo menu RBF reload when MiSTer.ini bootcore already targets the menu RBF, so bootcore can own that load

Validation

  • ./docker-build.sh
  • git diff --check

Hardware validation still needed

  • confirm Main_MiSTer CPU usage drops while frontend starts/runs
  • confirm frontend input still works
  • confirm OSD overlay opens/responds over frontend
  • confirm CRT path shows clean 320x240 framebuffer without stale frames
  • [] confirm clean launcher exit restores the boot framebuffer mode

Summary by CodeRabbit

  • New Features

    • Added startup timing instrumentation
  • Refactor

    • Optimized scheduler with conditional sleep behavior
    • Improved native CRT framebuffer handling and mode restoration
    • Enhanced process spawning and TTY initialization for better core launching

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@asturur, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 24 seconds. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 00e4118b-ce9f-4d94-936c-7ffed86b39a1

📥 Commits

Reviewing files that changed from the base of the PR and between 92cf0a8 and c634ffc.

📒 Files selected for processing (2)
  • support/zaparoo/alt_launcher.cpp
  • user_io.cpp
📝 Walkthrough

Walkthrough

The PR refactors the Zaparoo alternate launcher: it replaces bash-script process spawning with direct exec in the child (with CPU affinity, session/TTY setup, and stdio redirection), adds framebuffer mode save/restore for native CRT transitions, introduces TTY deadline and CRT finish timers, adds a zaparoo_alt_launcher_start_for_menu() entry point, gates a scheduler usleep(100) on a new query function, and logs a startup timestamp in main().

Changes

Alt Launcher CRT/TTY/Spawn Refactor + Scheduler Sleep

Layer / File(s) Summary
New public API declarations
support/zaparoo/alt_launcher.h
Declares alt_launcher_scheduler_sleep_enabled() and zaparoo_alt_launcher_start_for_menu() as new exported symbols.
Timer state and framebuffer mode save/restore
support/zaparoo/alt_launcher.cpp
Adds global TTY deadline, CRT finish, and native status timer fields plus saved FB mode storage; implements save_current_fb_mode() (reads kernel parameter) and restore_saved_fb_mode() (writes back with fixed fallback).
Native CRT enable/disable/prepare/finish routines
support/zaparoo/alt_launcher.cpp
Reworks CRT disable to restore saved FB mode and clear new timers; adds prepare routine saving FB mode, switching to CRT mode, and starting a finish timer; adds finish routine blanking the shmem scan-out buffer and re-enabling status routing; extends state reset to cover new timer fields.
Direct exec spawn replacing bash-script trampoline
support/zaparoo/alt_launcher.cpp
Replaces bash-script spawning with exec_launcher_child() that sets env vars, pins to CPU 0, creates a session, attaches TTY via TIOCSCTTY, redirects stdio, and execs the frontend with optional --crt; adds finalize_spawn() for post-fork VT/FB/CRT wiring and menu hiding; refactors alt_launcher_start() to centralize TTY deadline and CRT state.
Runtime polling: CRT finish, TTY deadline, spawn finalization
support/zaparoo/alt_launcher.cpp
Updates polling to call the CRT finish routine when its timer expires, route native CRT status via the new timer, reset TTY deadline on child exit, and finalize spawning when TTY is ready or the deadline expires.
Menu entry points, scheduler sleep, and startup log
support/zaparoo/alt_launcher.cpp, user_io.cpp, scheduler.cpp, main.cpp
Adds zaparoo_alt_launcher_start_for_menu() and routes it through a new prepare_menu_state helper; user_io_init branches on zaparoo_is_native_core() to call it; adds conditional usleep(100) in the scheduler loop; logs a startup timestamp in main().

Sequence Diagram(s)

sequenceDiagram
  participant user_io_init
  participant zaparoo_alt_launcher_start_for_menu
  participant alt_launcher_start
  participant fork as fork()
  participant exec_launcher_child
  participant finalize_spawn
  participant scheduler_run
  participant alt_launcher_scheduler_sleep_enabled

  rect rgba(100, 150, 255, 0.5)
    Note over user_io_init,alt_launcher_start: Menu bootstrap (native core path)
    user_io_init->>zaparoo_alt_launcher_start_for_menu: zaparoo_is_native_core() == true
    zaparoo_alt_launcher_start_for_menu->>alt_launcher_start: start=true
    alt_launcher_start->>alt_launcher_start: set TTY deadline, CRT fields
  end

  rect rgba(100, 200, 100, 0.5)
    Note over alt_launcher_start,finalize_spawn: Spawn child (direct exec)
    alt_launcher_start->>fork: spawn process
    fork-->>exec_launcher_child: child: setenv, affinity, setsid, TIOCSCTTY, execv
    fork-->>finalize_spawn: parent: switch VT / enable FB or CRT routing, hide menu
  end

  rect rgba(255, 180, 50, 0.5)
    Note over scheduler_run,alt_launcher_scheduler_sleep_enabled: Scheduler sleep gate
    scheduler_run->>alt_launcher_scheduler_sleep_enabled: query
    alt_launcher_scheduler_sleep_enabled-->>scheduler_run: true (TTY deadline or CRT finish active)
    scheduler_run->>scheduler_run: usleep(100)
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • ZaparooProject/Main_MiSTer#1: Both PRs modify the native CRT enable/disable flow and launcher init/polling behavior in support/zaparoo/alt_launcher.cpp.
  • ZaparooProject/Main_MiSTer#2: Both PRs add new "init/start for menu" entry points in alt_launcher.* and change menu bootstrap branching in user_io.cpp.
  • ZaparooProject/Main_MiSTer#4: Both PRs touch the child process spawn/exec path for the Zaparoo frontend in alt_launcher.cpp.

Poem

🐇 Hop, hop — no more shell script delay,
The child now exec's the right way!
CRT timers tick, TTY deadline set,
The framebuffer mode? Saved — don't fret!
A micro-sleep guards the scheduler's beat,
And a menu start makes the launch complete. 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf(zaparoo): reduce launcher startup contention' directly and concisely summarizes the primary objective of the pull request—reducing CPU contention during Zaparoo launcher startup through performance optimizations like scheduler sleep and non-blocking spawn finalization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/zaparoo-launcher-startup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@asturur asturur force-pushed the codex/zaparoo-launcher-startup branch from 259fb52 to e4db6cd Compare June 13, 2026 13:44
@asturur asturur force-pushed the codex/zaparoo-launcher-startup branch from e4db6cd to 89def92 Compare June 13, 2026 14:05
@asturur asturur force-pushed the codex/zaparoo-launcher-startup branch from 89def92 to 94f370e Compare June 13, 2026 14:06
@asturur asturur force-pushed the codex/zaparoo-launcher-startup branch from afe163b to 831f7af Compare June 14, 2026 14:12
Comment thread main.cpp

int main(int argc, char *argv[])
{
printf("ZAPAROO_T2 main_start_ms=%lu\n", GetTimer(0));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i want to know when main start during boot. is the time we want to save before this line? if yes we should stop looking here.

@asturur asturur marked this pull request as ready for review June 14, 2026 17:30
@asturur

asturur commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

The reason for those changes would be to be a bit faster, but also to enable a way from frontend to override mister and menu with our forks, and go back to normal with a toggle, restoring backups.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@support/zaparoo/alt_launcher.cpp`:
- Around line 140-181: The s_saved_fb_mode_valid flag is never cleared after
restore_saved_fb_mode() completes, causing save_current_fb_mode() to exit early
on subsequent calls due to its initial guard check. In the
restore_saved_fb_mode() function, after the fprintf and fclose calls that write
and close the framebuffer mode file, add s_saved_fb_mode_valid = false to reset
the flag so that the next CRT session will capture a fresh framebuffer mode
snapshot instead of reusing the stale original one.

In `@user_io.cpp`:
- Around line 1472-1473: The native-core boot path at line 1473 calls
zaparoo_alt_launcher_start_for_menu(), but this function should be mutually
exclusive with zaparoo_alt_launcher_init_for_menu() which is called later at
line 1549. Currently both execute in sequence, resetting launcher state after
spawn setup. Add a guard condition at line 1549 where
zaparoo_alt_launcher_init_for_menu() is called to prevent its execution when the
native-core path was taken (i.e., when zaparoo_is_native_core() was true and the
other conditions at line 1473 were met). This ensures only one of the two
functions executes per boot cycle.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 73f2368f-763f-4107-9844-c13c9439cacc

📥 Commits

Reviewing files that changed from the base of the PR and between 7a05c05 and 92cf0a8.

📒 Files selected for processing (5)
  • main.cpp
  • scheduler.cpp
  • support/zaparoo/alt_launcher.cpp
  • support/zaparoo/alt_launcher.h
  • user_io.cpp

Comment thread support/zaparoo/alt_launcher.cpp
Comment thread user_io.cpp
@asturur asturur merged commit 5d28969 into master Jun 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant