Skip to content

icd_shim: the gate's period is the panel's, and a mailbox slot is freed at the compositor's release - #72

Open
joshuatam wants to merge 2 commits into
masterfrom
fix/frame-pacing
Open

joshuatam wants to merge 2 commits into
masterfrom
fix/frame-pacing

Conversation

@joshuatam

Copy link
Copy Markdown
Collaborator

What this is

Two places where a rate the shim books was decided by a constant instead of by the session's own measurements. Both were measured on one uncapped 120 Hz session, and together they are 200 → 330 fps on it.

The gate booked 1e9 / cap against a panel whose measured period is not 1e9 / refresh, so its clock and the display's were two free-running clocks close to each other. The slot park booked a display release for a buffer that was never displayed, so 40 % of the session's commits waited out a bound instead of a release.

The gate's period is the panel's, not the nominal refresh

1e9 / 120 is 8 333 333 ns. The panel measures 8 257 000 ns on Nova and 8 260 500 on Odin 3. The gate slips 76 µs a frame, sweeps the whole vblank interval every ~108 frames, and every frame that lands late of its vblank waits one it did not need — 80-90 fps under a 120 cap on a 120 Hz panel, with the release intervals visibly alternating between one and two periods.

pacing() now delegates to paced_on(cap, latch_grid()): a cap the panel can express is booked as the whole number of the panel's measured periods nearest to it, so the phase never moves and every interval is the same length. A cap the panel cannot express keeps its own 1e9 / cap — 90 on 120 Hz is 33 % from a multiple, and its achieved rate is already quantized by the display.

cap own period booked reads
30 33.333 ms 4 × 8.2605 = 33.042 ms 30.26
60 16.667 ms 2 × 8.2605 = 16.521 ms 60.53
120 8.333 ms 1 × 8.2605 ms 121.06
90 11.111 ms unmapped 90.00
144 6.944 ms unmapped 144.00

Rounding goes to the nearest multiple, which lands the rate marginally above its nominal, because the multiple is the panel's measured period and not its nominal one. Rounding up instead would cost a whole divisor. The same tolerance means a cap within 2 % of a multiple is served at that multiple even when it is not one — 119 on that panel reads 121.06, +1.73 % — which is the mapping's cost and is documented rather than avoided; the alternative is leaving the cap to beat against the panel.

Pacing is still Off | Clock and Schedule is untouched: this changes the period a gated session books, not the kind of release. Generation keeps its own clock (Declared::Generating takes on_clock), and a session with no reported grid behaves exactly as before, so nothing here reaches LSFG or an X11 present route.

A mailbox slot is freed at the compositor's release

on_buffer_release parked a slot only when the served mode was in its synced set, and that set held MAILBOX. f41381e grew it because choose_live_mode serves both IMMEDIATE and FIFO_RELAXED as MAILBOX: once the key moved from the declared mode to the served one, those two could only stay parked by dragging a genuine mailbox guest in with them.

The two verdicts it collapsed are about different buffers. A mailbox buffer that reaches the panel is scanned for a full period and must be held that long. One that is superseded in the pending slot never was, and nothing else holds it. Parking both holds the latched frames and also waits out the bound for the superseded ones, because only a latched frame is ever released and so only it gets a note.

Odin 3, Hades II, uncapped mailbox, 4 slots, 120 Hz:

parked mailbox this change
fps (5 samples) 200.4 330 (328.7-331.0)
hold 2.42 periods 1.46 periods
slot_waits 34 671 / 40 047 2 / 59 356
acquire mean 3 670 µs 15.3 µs
park_timeouts 16 104 0
notes 23 938 0
GPU 79.9 % @ 607 MHz 84 % @ 1050 MHz

commits was 200.4/s against notes 119.8/s — the panel rate — so 40 % of commits had no note to wait for and fell to release_note_limit_ns(). The daemon measures the display's own hold at 1.0-1.5 periods, which is what the 1.46 now is.

The governor followed the load: 607 → 1050 MHz. That is why the GPU reads 84 % on both, and it is the reason the fps gain (65 %) is smaller than the clock gain (73 %) — the frame is not cheaper, there are just more of them.

The set is FIFO and FIFO_RELAXED again, so a mailbox, immediate or FIFO-relaxed declaration all free at the compositor's wl_buffer.release.

What this gives up, recorded rather than buried: a mailbox buffer that does reach the panel can be written again while it is being scanned, so the reuse tear is open on this path by construction. This is the pre-f41381e rule — payload 20261110.1's 342.5 fps is the same rule on the same device — so it is a restored behaviour and not a new one, but it is a real cost and not a footnote. The authority that separates the two buffers is wp_presentation_feedback.discarded: park what was latched, free what was discarded. It is not subscribed yet (present::expect_feedback requests nothing when the present carries no id, so the census reads presented=0 discarded=0), and that is the follow-up this leaves open.

Verified

  • 135 tests pass, cargo clippy --all-targets -D warnings clean.
  • Gate: five tests over the mapping — the divisor cells, a cap the panel cannot divide, the cap-just-off-a-divisor boundary pinned on both sides, a cap above the panel keeping its own period, and a delayed release that does not overrun.
  • Slot: measured on device, the table above, from a build of 23732f5 with only this diff on top ([shim 202611211203 23732f5-dirty]), 180 s, five census samples.
  • Not yet measured: a capped session after the mapping — cap=120 on 120 Hz should show gate=clock with acq_spacing collapsing into the 8.26 ms bucket. The uncapped session the fps table comes from has cap=0 gate=off, so it says nothing about the gate.
  • Not yet measured: whether the reuse tear is visible at 330, and whether it changes as the rate crosses the panel rate.
  • docs/10's gate section, the two rate claims above its table and the census sentence are corrected with it; the earlier "within 1 %" was wrong in direction and in size, and "the limit is a maximum by construction" is now qualified to the booked period. docs/10 and docs/15 both claimed the hold follows the served mode and that both served modes are synced; corrected with the measurement.

The gate booked `1e9 / cap` and nothing else, so its clock and the panel's were
two free-running clocks close to each other. `1e9 / 120` is 8 333 333 ns against
a measured 8 257 000 ns on Nova and 8 260 500 on Odin 3: the gate slips 76 us a
frame, sweeps the whole vblank interval every ~108 frames, and every frame that
lands late of its vblank waits one it did not need. Measured 80-90 fps under a
120 cap on a 120 Hz panel, with `gate=clock` and the release intervals visibly
alternating between one and two periods.

`pacing()` now delegates to `paced_on(cap, latch_grid())`: a cap the panel can
express is booked as the whole number of the panel's measured periods nearest to
it, so the phase never moves and every interval is the same length. A cap the
panel cannot express keeps its own `1e9 / cap` -- 90 on 120 Hz is 33 % from a
multiple, and its achieved rate is already quantized by the display.

The rounding goes to the *nearest* multiple, which lands the rate marginally
above its nominal: the multiple is the panel's measured period, not its nominal
one, so 60 on a 121 Hz panel is 60.55. Rounding up instead would cost a whole
divisor. The same tolerance means a cap within 2 % of a multiple is served at
that multiple even when it is not one -- 119 on that panel reads 121.06, +1.73 %
-- which is the mapping's cost and is documented rather than avoided: the
alternative is leaving the cap to beat against the panel.

`Pacing` is still `Off | Clock` and `Schedule` is untouched: this changes the
period a gated session books, not the kind of release. Generation keeps its own
clock (`Declared::Generating` takes `on_clock`), and a session with no reported
grid behaves exactly as before, so nothing about this reaches LSFG or an X11
present route.

docs/10's gate section, the two rate claims above the table and the census
sentence are corrected with it; the earlier "within 1 %" was wrong in direction
and in size, and "the limit is a maximum by construction" is now qualified to the
booked period. Five tests: the divisor cells, a cap the panel cannot divide, the
cap-just-off-a-divisor boundary, a cap above the panel, and a delayed release
that does not overrun.

135 tests pass; clippy clean with -D warnings.
… a note

`on_buffer_release` parked a slot only when the *served* mode was in its `synced`
set, and that set held MAILBOX. `f41381e` grew it because `choose_live_mode` serves
both `IMMEDIATE` and `FIFO_RELAXED` as MAILBOX: once the key moved from the declared
mode to the served one, those two could only stay parked by dragging a genuine
mailbox guest in with them.

The two verdicts it collapsed are about different buffers. A mailbox buffer that
reaches the panel is scanned for a full period and must be held that long. One that
is superseded in the pending slot never was, and nothing else holds it. Parking both
holds the latched frames and also waits out the bound for the superseded ones,
because only a latched frame is ever released and so only it gets a note.

Measured on Odin 3, Hades II, uncapped mailbox, 4 slots, 120 Hz panel: `commits`
200.4/s against `notes` 119.8/s, which is the panel rate, so 40 % of commits had no
note to wait for and fell to `release_note_limit_ns()`; every slot averaged 2.42
display periods against a hold the daemon measures at 1.0-1.5, `slot_waits` was
34 671 of 40 047 acquires, and the acquire itself averaged 3 670 us.

The set is FIFO and FIFO-relaxed again, so a mailbox, immediate or FIFO-relaxed
declaration all free at the compositor's `wl_buffer.release`. Same session after:
330 fps (5 samples, 328.7-331.0), `slot_waits` 2 of 59 356, `park_timeouts` 0, a
1.46-period hold, and the acquire down to 15.3 us. The governor followed the load —
607 MHz to 1050 MHz — which is why the GPU reads 84 % on both.

What this gives up, recorded rather than hidden: a mailbox buffer that does reach
the panel can be written again while it is being scanned, so the reuse tear is open
on this path by construction. The authority that separates the two buffers is
`wp_presentation_feedback.discarded`, and it is not subscribed yet
(`present::expect_feedback` requests nothing when the present carries no id, so the
census reads `presented=0 discarded=0`). Parking what was latched and freeing what
was discarded is the shape that keeps this rate without the window.

docs/10 and docs/15 both claimed the hold follows the served mode and that both
served modes are synced; corrected with the measurement.

135 tests pass; clippy clean with -D warnings.
@joshuatam

Copy link
Copy Markdown
Collaborator Author

Companion app change: utkarshdalal/GameNative#2484 — the app-side half (the cap reaching the shim, and the GL stack a GL guest needs). It bumps the payload to 20261121.1, which does not contain this branch; its next bump should.

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