Skip to content

drm/asahi: g16: lease a TA/FS render queue pair to each rendering VM - #3352

Closed
DjDeveloperr wants to merge 4 commits into
fix/g16-cross-vm-render-drain-stackfrom
perf/g16-per-vm-render-pairs
Closed

DjDeveloperr wants to merge 4 commits into
fix/g16-cross-vm-render-drain-stackfrom
perf/g16-per-vm-render-pairs

Conversation

@DjDeveloperr

Copy link
Copy Markdown
Contributor

Draft, for an early design review. It stacks on the linux#3201 fix (fix/g16-cross-vm-render-drain-stack, which waits on #3180 and #3185) and carries only these 4 commits. Hardware gates are still running.

What: on the g16 backend, each VM that renders leases its own firmware TA/FS queue pair, the way compute already leases per-VM workqueues (62e450e). Renders of different VMs then overlap again without sharing one queue.

  • Why:
    • The linux#3201 fix has to drain the engine before a render of another VM, because two VMs' renders on the one shared TA/FS pair fault the GPU.
    • That serializes multi-process rendering. render.light procs runs at about 130 µs per submit at every depth; Metal 4 is 104.5 µs at d4 and 94.8 µs at d16.
  • macOS:
    • A hypervisor capture of Metal render.light procs with 2 and 4 processes, on macOS 26B123 on the J773g, shows every process with its own TA queue and FS queue, each with its own job-list entry.
    • All processes ring the same doorbell, and the firmware chooses among the queues.
    • This change gives each VM its own pair the same way, behind the same doorbells.

Design:

  1. Events through RenderRefs. A render's completion events travel in RenderRefs. Pair p uses TA 0x70 + 2p and FS 0x71 + 2p. Pair 0 keeps 0x70/0x71, so the render goldens don't change.
  2. Per-pair queue state, with one pair.
    • Graphs, stamps, targets, heads, registration, retirement, progress and recovery blame become per pair.
    • This commit sets RENDER_PAIRS = 1 and changes no behaviour.
  3. Displacement in publication order.
    • A PB slot or pass slot goes to another owner only after a render published after the owner's last render has retired.
    • This used to be "the last retirement observed", which only held while renders retired in order on one queue.
    • With one pair, it decides exactly as before.
  4. Eight pairs, leased per VM.
    • Lease: a VM keeps its pair while any of its renders are in flight. Otherwise it takes its last pair if free, else the lowest free one.
    • Same-pair rule: two VMs' renders are never in flight on one pair at the same time. Admission and publication both check this; it's the linux#3201 rule.
    • Handoff: when every pair holds another VM's renders, the pair with the fewest passes in flight drains for the waiting VM while the others keep running. This mirrors compute_handoff_pipe.
    • Stage order:
      • A render's first pass waits for the TA and FS of the newest render in flight on another pair. Those two waits take the place of the pair's own prev_barrier and fs_dep, so a pass still uses at most 5 ring entries.
      • So renders reach the TA and FS engines in publication order across pairs, and one VM's TA still overlaps another VM's FS.
      • That keeps the displacement proof sound without extra PB slots.
    • Unchanged: a render beside another VM's compute still drains, both ways, and so does any InitBM flight.
    • Firmware registration: pairs register with the firmware on their first record, so pairs 2–7 stay unused until three or more VMs render at once.
    • Probe cost: about 1.5 MiB of firmware objects for the seven extra pairs.
    • Stats: a render_pairs: line counts publications per pair and cross-pair overlaps.

Tested:

  • Host selftests: asahi-m4 passes 26/26 at every commit. New tests cover:
    • leasing, stickiness, handoff and the same-pair rule;
    • render↔compute draining;
    • the stage-order barriers;
    • out-of-order retirement and the latched channel receipt;
    • displacement in publication order, for both PB and pass slots;
    • per-pair progress;
    • 0x72/0x73 decoding;
    • per-pair recovery blame.
  • Lab prototype on the J773g, with two pairs, VM → pair by load, and no stage-order barriers (38dbbc32, one boot):
    • render.light procs went from 126.6 to 100.9 µs at d4 (1.04× Metal) and from 128.8 to 102.7 µs at d16 (0.92× Metal), against one shared pair.
    • Single-process rows didn't change.
    • 151,718 renders were admitted while another VM rendered on the other pair.
    • With two pairs, the full multi_queue list with 3 workers and the full blit_image list with 8 jobs ran with 0 GPU faults.
  • This series on hardware: kit 03afc089 compiles on the J773g. Its first boot, with the linux#3201 lists, drm/asahi: g16: keep renders of a multisampling VM apart from other VMs #3180's hot list and the procs rows, is queued.

Risk: two-way door.

  • Scope: render admission and publication on the g16 backend: M4, and the M3 parts on the 26B123 protocol.
  • Main unknowns:
    • Cross-VM stage-order waits on another pair's stamps are new on hardware. Compute already waits across pipes.
    • Pairs 2–7 have never run on the firmware.

Not yet:

The TA and FS work images, the scene's own-TA wait and the FS finalize
name the render queue's completion events. They were the literals 0x70
and 0x71 of the one TA/FS queue pair. Take them from RenderRefs::event
instead, filled from work::render_pair::events(pair), which gives pair p
the events 0x70 + 2p and 0x71 + 2p. The block 0x70..0x80 is bits 16..32
of type-1 event word 4, so it can name up to eight pairs.

Every render still uses pair 0, so the encoded images are byte-identical
and the render goldens are unchanged.

Signed-off-by: DjDeveloperr <[email protected]>
Give the render side the structure the compute pipes got in 62e450e,
so later renders can use more than one firmware TA/FS queue pair.
RENDER_PAIRS stays 1 here, and every render still uses pair 0.

- Graphs::render holds RENDER_PAIRS render graphs. Each pair has its
  own TA and FS qinfo, qstate, work ring, job list, stamps, notifier
  page and threshold. sched_ctx is shared, and the context still
  registers once, through pair 0's TA queue.
- Pair p completes with events 0x70 + 2p and 0x71 + 2p.
  Events::drain decodes them from word 4. The stage cells (event times
  and the recovery snapshot) keep pair 0 at 0/1 and put pairs 1.. after
  the compute pipes. RetiredStamps keeps a TA and an FS history per
  pair.
- Each pair numbers its stamps and thresholds with its own dense draw
  ordinal. The UMA counters and the work UUID keep the global one.
- The engine keeps TA/FS targets, heads and registered flags per pair.
  A flight records its pair, and an fs2c barrier waits on the waited
  render's pair.
- Retirement takes the oldest render flight of each pair. A later
  flight on the same pair makes the queue and stamp proof a "passed"
  one. Any other render flight or later record makes the proof on the
  shared TA/FS submit channels a "passed" one.
- Progress is sampled per pair and renews the one render deadline.
- Recovery maps a snapshot event to its pair and blames only that
  pair's flights, since dense per-pair stamps collide across pairs.

With one pair every value and image is as before; the host suite
covers the per-pair paths with two pairs in its mocks.

Signed-off-by: DjDeveloperr <[email protected]>
A PB/UMA allocator slot or render pass slot passes to another owner
only once it is displaced. After its last render retires, a slot stays
the TA and FS engines' current one until they run a render of another
slot. Both ledgers inferred that from the order in which retirements
were observed: the PB pool from the last cleanly retired slot, and the
pass ledger from a later publication retired on the same queue. That
holds while every render runs on one TA/FS queue pair, because the pair
retires in publication order.

Renders on different queue pairs are observed retiring out of
publication order, so the observed order says nothing about which
render the engines ran last. Decide by the publication sequence
instead:

- Pools::publish_flight returns the render's sequence, and
  retire_flight takes it back. A clean retirement displaces every other
  slot whose newest render was published before it.
- The render pass ledger has ordered pipes: a later publication that
  retired displaces an owner whatever pair it ran on. Each pair still
  retires its own owners in order, and pass slots are published on
  their flight's pair. The compute ledger keeps per-pipe displacement.

This relies on renders running on the TA and FS engines in publication
order. With the one pair in use, both rules decide exactly as before.

Signed-off-by: DjDeveloperr <[email protected]>
Every VM's renders shared one firmware TA/FS queue pair. While two VMs'
passes are published on one pair, the GPU faults in the one whose pass
runs (linux#3201), so a render of another VM drained the engine first
(8722b2e). That serialized multi-process rendering: gpubench
render.light with 2 to 16 processes took about 127 µs per frame against
Metal's 104 µs. macOS 26B123 gives every Metal process its own TA and FS
queue, each with its own job-list entry, all rung through one doorbell.

Lease one of RENDER_PAIRS = 8 pairs to each rendering VM instead. The
completion-event block 0x70..0x80 names eight pairs, so a compositor and
seven clients render without a handoff. Each pair costs fourteen 16 KiB
pages at probe. A pair registers with the firmware on its first record,
and a VM takes the lowest free pair, so unused pairs stay unregistered.

- Leasing. A VM keeps the pair of its renders in flight, so its render
  waits never leave one in-order pair. Otherwise it takes its last pair
  if free, else the lowest free pair. Two VMs' renders are never in
  flight on one pair (cross_vm_render_conflict).
- Handoff. When every pair holds another VM's renders, the pair with
  the fewest passes in flight drains for the waiting render, as
  compute_handoff_pipe drains a compute pipe, and the other pairs keep
  running. This replaces the full engine drain.
- Render vs another VM's compute still drains, in both directions, and
  so does any InitBM flight.
- Stage order. A prefix's first pass waits for the TA and FS of the
  newest render in flight when that render is on another pair. Renders
  so reach the TA and FS engines in publication order, as on one pair,
  which the PB and pass slot displacement proofs rely on. That render's
  completion implies every earlier one's, so these waits take the place
  of the pair's own prev_barrier and fs_dep, and a pass still takes at
  most MAX_RENDER_RING_ENTRIES entries per ring. One VM's TA still
  overlaps another VM's FS. Since a pair can wait on another, the pairs
  keep one render deadline.
- Shared submit channels. Like the compute pipes on Channel::Compute,
  TA/FS channel receipts are latched before another pair's records can
  lap a long flight, and no record is posted that would lap an unlatched
  one.
- aurora-g16/stats gains "render_pairs: publications <per pair>
  cross_pair <n>": the renders published on each pair, and those
  published while another VM's renders were in flight on another pair.

A prototype with two pairs and per-VM pairs ran on the J773g with no GPU
fault or recovery. render.light procs d2/d4/d8/d16 went from 126.9,
126.6, 127.4 and 128.8 µs to 105.6, 100.9, 102.4 and 102.7 µs; single-VM
rows were unchanged. The stage-order barriers and the eight pairs are
new here.

Signed-off-by: DjDeveloperr <[email protected]>
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Replaced by #3355. It has the same 4 commits, rebased onto the linux#3201 fix PR (#3353) without the old stack branch's duplicate commits. Closing this draft.

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