Skip to content

Player HUD clock prewarm, plus the capture kit for the back-buffer waits - #370

Merged
GLinnik21 merged 7 commits into
mainfrom
perf/player-backbuffer-waits
Oct 1, 2026
Merged

GLinnik21 merged 7 commits into
mainfrom
perf/player-backbuffer-waits

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

What

After the player sub-menus landed (#335, #345–#347, #352, #357, #365) a ~90 s leg on the television still shows a handful of frames over 20 ms, on every route including Home and Settings. The app's own spans cannot say why: the frame is finished on time and the wait is in the first framebuffer command of the next one. This PR lands one fix and the instruments needed to name the cause on the next device session.

Fix

  • Player HUD: the transport clocks are rasterised from PlayerScreen::prepare (player_hud::ClockWarm) instead of on the frame that first draws a new minute/second string, so a clock tick no longer uploads glyphs inside the present path.

Diagnostics (dev triggers, devtriggers builds only)

  • framecb: stamps each FRAMEDROP line with the compositor's wl_surface.frame callback time and splits the present into phases.
  • framering[=ms]: logs only frames over the threshold plus four before and three after, so the detector no longer perturbs what it measures. Takes effect only while framedrop is armed.
  • Per-stretch wall / CPU / run-queue split with wait_at=, to tell "blocked in the driver" from "runnable but off the CPU".
  • wldebug: sets WAYLAND_DEBUG=client before any thread exists (it is armed ahead of telemetry::boot(), which starts sentry's worker pool).

The frame probe resolves its four libwayland entry points once through dlsym(RTLD_DEFAULT) and is a silent no-op when any is absent. The whole probe is cfg(all(not(hostsim), devtriggers)), so the shipping build carries only the stubs.

Capture kit

  • tools/tv-sched-trace.sh: a bounded kernel scheduler trace from the set (sched_switch, sched_wakeup, irq events, GPU events where present). It requires the TV lock, mounts tracefs only if it is absent, refuses to run if another tracer already has events enabled, and restores every setting it changed from a trap.
  • tools/analyze-sched-trace.py, tools/analyze-hwcnt-wait.py: readers that correlate the trace and Mali hardware counters with FRAMEDROP timestamps. Both carry a --self-test wired into make check.
  • .claude/hooks/tv-lock-guard.py now treats tv-sched-trace.sh as a device command.
  • docs/player-submenus.md records the three-leg plan (scheduler trace, hardware counters, Wayland protocol log).

Verification

  • make check on the committed tree: test result: ok. 5428 passed; 0 failed; 7 ignored, test result: ok. 102 passed; 0 failed, test result: ok. 5508 passed; 0 failed; 7 ignored; both analyser self-tests ok; tv-lock-guard: 63/63 cases correct.
  • cargo +nightly check --lib --no-default-features: clean, no warnings.
  • make (ARM cross-build): ok.
  • Firmware load matrix (tools/fwcompat.py --min-release 4.4.2) OK on 4.4.2 through 11.2.0 for the debug build; no DT_NEEDED drift, no new link-time import beyond getrusage/pread (GLIBC_2.4).

Not verified on the device: tv-sched-trace.sh was exercised only against a fake tv-ssh and a fake tracefs on the host, and the three-leg capture has not been run. The clock prewarm did not measurably change the slow-frame count on the television; leg-to-leg variance is larger than its effect.

🤖 Generated with Claude Code

GLinnik21 and others added 7 commits October 1, 2026 22:03
The elapsed and remaining clocks are new strings once a second, and the
draw met each cold after the frame's first framebuffer command, where the
driver waits for a free back buffer. Work after that wait moves the commit
toward the compositor's next repaint: on the TV those frames read
clear:12.4 ... textx2:1.1 and ran 19.5-22 ms under an open Tracks/More
popover, where the transport stays up.

PlayerScreen::prepare now queues this second's pair and the next second's
(player_hud::ClockWarm); prepare_window drains the queue ahead of the
clear. Measured on the TV, 95 s legs, panel off, guest + mock: frames with
text rasterised after the clear went 80 -> 0 (menu open) and 91 -> 1
(submenu oscillation).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
/tmp/plxnative-framecb adds to each FRAMEDROP line the compositor's own
wl_surface.frame stamp for the frame's commit, and the frame thread's CPU
time and involuntary context switches over the draw after the back buffer
is acquired and over the swap. Together they tell a late compositor
repaint from a late commit, and a busy commit phase from a descheduled
one. Unarmed it is one latched bool per presented frame; the libwayland
entry points are resolved from process scope at first use, so nothing is
added to the link.

docs/player-submenus.md records what the probe showed on 2026-10-01.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…stsim

/tmp/plxnative-framering[=<ms>] makes the detector write only frames of
<ms> or more (default 17) with the four frames before and the three after,
instead of every frame. A pacing investigation needs the neighbours of a
slow frame, and getting them used to mean framedrop=0.01: ~60 scrub + open
+ append + close round trips a second on the frame thread, inside the
phase being measured. The lines are still formatted every frame; only the
slow ones and their context reach the log.

frame_probe_armed is now compiled only where its callers are, which the
hostsim unit build flagged as dead code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and blocked

The probe now marks the frame thread before the first framebuffer command
as well as after it and before the swap, and reads the scheduler's own
run-queue wait (/proc/thread-self/schedstat) and the voluntary switch
count beside CPU time. FRAMEDROP carries w= (the back-buffer wait), d=
(the draw) and s= (the swap) as wall/cpu/runq ms with slept/preempted
switch counts, and wait_at= for lining a frame up with a kernel trace.
Wall time that is neither CPU nor run-queue wait was spent blocked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
/tmp/plxnative-wldebug sets WAYLAND_DEBUG=client before SDL connects the
display, so every request and event is printed with a microsecond stamp to
plxnative-stderr.log: when wl_buffer.release and wl_callback.done arrive
against when the driver's attach/commit went out. The armed line logs the
realtime-to-monotonic offset, so the stamps line up with FRAMEDROP's mono=.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ders, with host self-tests

tools/tv-sched-trace.sh drives a kernel sched/irq trace on the TV through tools/tv-ssh under the
TV lock and always restores tracefs; tools/analyze-sched-trace.py and tools/analyze-hwcnt-wait.py
read the results and carry --self-test, wired into make check. The tv-lock guard now blocks
tv-sched-trace.sh outside a lease. docs/player-submenus.md gets the three-leg plan for the next
TV session, stated as not yet run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…build; arm WAYLAND_DEBUG before sentry's threads

wl_sym did a CString + dlsym on every armed present and a lookup per done callback, charged to the
s= stretch the probe reports; the four symbols are now resolved once in a OnceLock before the swap
mark. The probe body is cfg(all(not(hostsim), devtriggers)) with the stubs on the complement.
arm_wayland_debug writes the environment, and sentry_init starts the sentry-tele worker threads
(logs/metrics default on in 0.16.6), so it now runs before telemetry::boot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit c0d3e8d into main Oct 1, 2026
18 of 20 checks passed
@GLinnik21
GLinnik21 deleted the perf/player-backbuffer-waits branch October 1, 2026 19:42
GLinnik21 added a commit that referenced this pull request Oct 1, 2026
…lay preload debounce (#372)

The underlay preload debounce from #365 was never wired: the dispatcher
called want_corners directly, so the ~8 ms reconstruction latched on the
first quiescent frame instead of waiting out the playback-start frames. The
prepare pass now calls ModalUnderlay::note_at_rest once per pass; a note
stands only after PRELOAD_REST_FRAMES consecutive passes at rest over the
same envelope, and a changed envelope or a pass with nothing to note
withdraws it. A test through Dispatcher::frame covers the call site.

Simplifications over the #365 and #370 code, behaviour-preserving:
ModalUnderlay::latch_corners replaces two copies of the corner latch,
PanelMotion::warm_open replaces is_warm and the duplicated guard in the
Tracks and More menus, and four items lose visibility they did not need.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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