Commit Graph
2 Commits
Author SHA1 Message Date
Anees Iqbal 072b940f5b 🐛 Wait for the host's answers behind a compile with no deadline
A pipeline create waited 60 s for its reflection. On a slow host or a cold
compile the app got nil, and the destroy posted behind the create cancelled a
compile that would have succeeded. Other waits for host answers had the same
problem. A queue's create (30 s), SURFACE_PAGES (30 s), shared events (60 s),
a CPU lock's wait for its surface's writes and the host's copies (2 s), a new
block's wait for a write-back (10 s) and the bundle's library chunk acks
(10 s) all sit behind the context's earlier work on the host, a compile among
it. At their bounds a lock read whatever bytes the pages held.

Each of those waits now has no deadline, as Metal's own calls wait for the
GPU's driver (RgfxAnswerWait.hpp). It sleeps THREAD_INTERRUPTIBLE, so a caught
signal never ends it, and it ends only:
- at the answer;
- at the device's stop: quiesce wakes every waiter, and the waiter finds the
  device stopped;
- at the thread's abort (SIGKILL, a fatal signal, exit), returning
  kIOReturnAborted.
An aborted create still gets its destroy posted behind it. A CPU lock waits
with no deadline for the device to complete its writes' buffers. Its 2 s bound
now counts only from that completion to the bundle's retire, so a process
that locks a surface on the thread that would retire it still goes on.

The 64 lifecycle waiters are split by kind: 32 for the processes' creates and
shared events, 16 for surface pages and downloads, and 16 for the device's
own asks (queue create, close, pool takes, kept answers, video). Creates
waiting on compiles can no longer take the waiters WindowServer's surface,
queue and close asks need. A waiter take that ends unanswered returns
kIOReturnBusy, so a caller never mistakes an unposted message for a posted
one.

The waits that do not depend on host work keep their deadlines, each with its
reason in a comment: ring room, display commands, the start's kept answers,
a context's close, the display pipe, arm64 video sends and the region-room
wait.

What the guest now sees: a lock or present behind a slow compile waits for
it, and a create returns its pipeline however long the compile takes.
2026-11-21 00:55:09 -08:00
Anees Iqbal 2b1b29a759 🐛 Stream each library through a window made for it
A process's first library over 8 KiB took a staging window of 64 MiB and kept
it for the process's life. On a busy desktop on the RTX 5080 host, nine
processes held 576 of the 731 MiB of the region outside WindowServer's
reserve that way (mediaanalysisd held nothing else), so the region ran out at
41 processes. From there, libraries, buffers and queue rings came back nil,
and Games, Photos, Photo Booth, Maps, the Dock's extras, NotificationCenter
and WebKit's GPU process crashed.

The window is now made for one stream and sized to its library: as few
chunks of at most 32 MiB as hold it, split evenly in whole pages, and a
second block only where there are two or more chunks. It goes back to the
region once the host has acked every chunk. Where the region refuses it,
smaller chunks are asked for, down to a page, so a library is made while any
room for three pages is left. A window whose chunk the host never acks is
kept, so nothing the host may still read is given out again.

The stream moves to RgfxLibraryStream.cpp, so the serialiser check covers it
against a host of its own: the shapes, the fallbacks and their bytes and
order, the window given back, and one kept when an ack never comes.
2026-11-05 21:59:27 -08:00