Skip to content

feat(presentation): raise frame-scheduler thread priority - #37

Merged
SpaceK33z merged 1 commit into
mainfrom
kees/frame-scheduler-thread-priority
Jul 13, 2026
Merged

feat(presentation): raise frame-scheduler thread priority#37
SpaceK33z merged 1 commit into
mainfrom
kees/frame-scheduler-thread-priority

Conversation

@SpaceK33z

Copy link
Copy Markdown
Collaborator

Summary

Elevates the laser-frame-scheduler thread to ThreadPriority::Max so its pacing sleeps are less likely to be preempted under system load, reducing output timing jitter. Resolves the follow-up deferred from #26.

The call is best-effort: on systems that disallow raising priority without privileges (e.g. Linux without CAP_SYS_NICE) it logs a warning and continues at default priority rather than failing the session.

Why Max and not true realtime

thread-priority's set_current_thread_priority maps the requested priority into the current scheduling policy's allowed range rather than forcing a realtime policy. So Max:

  • needs no elevated privileges on macOS/Windows,
  • falls back to niceness under the default SCHED_OTHER on Linux,

avoiding the system-starvation and privilege pitfalls of SCHED_FIFO while still nudging the scheduler in our favor.

Changes

  • Cargo.toml / Cargo.lock: add cross-platform thread-priority = "3" (always-on).
  • src/presentation/session.rs: raise priority as the scheduler thread's first action (inside the closure, so it targets the correct OS thread); warn-and-continue on failure.

Testing

  • cargo build clean, cargo clippy clean.
  • Presentation test suite passes (96 tests).
  • Manual smoke test confirmed the priority call returns Ok on macOS without special privileges.

Closes #35

Elevate the laser-frame-scheduler thread to ThreadPriority::Max so its
pacing sleeps are less likely to be preempted under system load, reducing
output timing jitter. Best-effort: on systems that disallow raising
priority without privileges (e.g. Linux without CAP_SYS_NICE) it logs a
warning and continues at default priority rather than failing the session.

Uses the cross-platform thread-priority crate (deferred from #26). Max
maps into the current scheduling policy's range, so it needs no elevated
privileges on macOS/Windows and falls back to niceness on Linux.

Closes #35
@SpaceK33z
SpaceK33z merged commit de44989 into main Jul 13, 2026
20 checks 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.

Request elevated (real-time) scheduling priority for the frame-scheduler thread

1 participant