Skip to content

SweetFramebuffer: sweetfb_nowait through a host-tested state machine + self-check fallback (STARLTE, off by default) - #47

Draft
claudiusthebot wants to merge 1 commit into
scion/xnu-12377from
agent/scion-swipe2/present
Draft

claudiusthebot wants to merge 1 commit into
scion/xnu-12377from
agent/scion-swipe2/present

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

sweetfb_nowait=1 rewritten on a host-tested state machine, with a self-check that falls back to the old sleeping path. It is STARLTE only and off by default. It has NOT been run on a phone yet (test kernel nw2 is with phone 1).

  • The tick decides under fLock with hakios.sweetfb_present.h. That header lives in scion-kernel drivers/display/sweetfb/ and reaches this tree through profiles/ios-27.copy, so this needs the scion-kernel PR (sweetfb_nowait: present state machine codec + host test, copied into the ios-27 tree; PRESENT.md section 6 scion-kernel#365) to build. The tick takes a recorded frame only when one atomic load of the GPU queue's done number shows its chains are done. That number comes from the new starlte_gpu_user_done(), and the worker stores it as it retires each chain. Otherwise the frame stays recorded, the tick does not sleep, and a newer swap may replace it. The vsync callback still goes out first on every tick.
  • Self-check: if a frame has waited 4 ticks with the GPU idle (a logic error) or 30 ticks with the GPU busy, the old sleeping path takes it and counts it. The idle case also logs A5XELTE FB nowait: SELF-CHECK: once.
  • The nowait line now reports frames shown done, ticks that left a frame, frames replaced, and both fallback counts.
  • The PR 43 version took the frame out, looked at its chains outside the lock and put the frame back. In nwt1's log, the frames it left for later were in fact shown by a later tick. The stall came after that, and its cause is not identified (details in PRESENT.md section 6).

Builds: STARLTE KERNEL OK (sha256 040ae212…170d); FRANKEL is in the next comment.

🤖 Generated with Claude Code

… with a self-check that falls back to the sleeping path (STARLTE, off by default)

The first sweetfb_nowait (PR 43) took the frame out under fLock, cleared fDirty, looked at its GPU chains outside the lock
and put it back. The tick now decides under fLock with hakios.sweetfb_present.h (scion-kernel drivers/display/sweetfb,
copied in by profiles/ios-27.copy, host-tested there): a recorded frame is taken by the first tick that finds its chains
done, read as one load of the GPU queue's done number (starlte_gpu_user_done, new: the queue's worker stores it as it retires
each chain, woken by the job interrupt with sgu_irq=1), otherwise it stays recorded and the tick does not sleep; a newer swap
replaces it. The vsync callback still goes out first on every tick. A frame that waited 4 ticks with nothing on the GPU
(impossible unless the logic is wrong) or 30 ticks with the GPU busy is taken by the old sleeping path and counted; the first
of the former is logged as SELF-CHECK. The nowait line now gives frames shown done, ticks that left one, frames replaced, and
the two fallbacks. Display off/on and the path without the boot-arg are as before. NOT run on a phone.
@claudiusthebot

Copy link
Copy Markdown
Collaborator Author

FRANKEL builds: KERNEL OK (fork a81c63f with scion-kernel#365), out/nw2p/kernel sha256 3708a3d5…ddcc. STARLTE: KERNEL OK, sha256 040ae212b01b02a15e8d75e1e512b389b59064c2e0dc1471ca5404db694e170d.

@claudiusthebot

Copy link
Copy Markdown
Collaborator Author

Phone 1 result for this kernel (nw2, sha256 040ae212…; E1 bench line + sweetfb_prof=1 sweetfb_nowait=1; 17 Nov 23:20):

  • The mechanism works. No stall and no black screen. Ticks averaged 16 664-16 669 us. "tick slept for the GPU" was about 5 us. SELF-CHECK 0, GPU slow 0.
  • Pacing got worse: swipes 14 % on time / 30.5 motion fps (ref 46-48 % / 38.4); scroll 53 % / 36.0 fps (ref 85-95 %).

Why. CoreAnimation's swap rate does not change: about 27 swaps/s while swiping, with or without nowait. backboardd paces on its own CADisplayTimer; it never registers our type-5 vsync (see the sweetfb_cav comment in SweetFramebuffer.cpp), so a steady tick gains nothing.

The loss comes from replaced frames, 43-64 per 5 s. swap N+1 is held until frame N's chains are done, and it is recorded the instant they are. So N is replaced unless a tick happens to fall in that gap.

Stage times on the old path (sp2's sweetfb_trace, 92 swaps):

stage p50 avg
CA swap-call period 33.4 ms 38.8 ms
SwapEnd hold 0 ms 4.8 ms
recorded → GPU done 13.2 ms 18.0 ms
present 1.9 ms —

CA idles about 20 ms per frame. That fits CA starting frame N+1 at the first 60 Hz timer after frame N is done on the GPU. The limit is CPU encode plus GPU time per frame, not the present.

Do not enable sweetfb_nowait. Keep these PRs as draft: the state machine, the host test and the self-check are correct, but they give no fps. Close them, or keep the self-check for a later present design.

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