MacLinuxGPUHost rebar prints, for each resizable BAR, the sizes the
device can decode and the size it decodes now. It reads the device's
configuration space through the sysfs "config" file as an observer,
like the pcie command, so it writes nothing and works beside a session.
The parser walks the extended capability list from 0x100 and accepts
the capability only as linuxu's pci_rebar_read does: version 1, one to
six entries inside the space, distinct BARs, and a selected size the
BAR supports. test-device-info checks it against the R9700's capability
(BAR0 256 MB of 256 MB to 32 GB, BAR2 2 MB of 2 MB to 256 MB) and
against malformed lists.
macOS sizes every BAR and the bridge windows above it once, when it
enumerates the device. IOPCIFamily never programs this capability and
takes no BAR above 1 GB, and DriverKit has no call to resize one, so
the size shown as now is the one the driver works with.
Since the device stays up across clients (248), a previous instance whose
last client left keeps its session, and with it the GPU, open. It can
leave only once that session is closed, and Retire, the installer's way to
close it, needs the session-release authorization the signed app does not
have (kIOReturnNotPrivileged). So every upgrade stayed "terminating for
upgrade via delegate" until someone killed the old driver, which panics the
Mac, or power-cycled the GPU.
The installer now hands over without Retire when Retire is refused. It
opens a session client of its own on each previous instance and asks
ShutdownGPU, which any session client may ask and which closes the session
when no other client uses it. The display agents are already stopped for
the upgrade. The installer keeps asking until the instance is gone, and
says which programs still hold it.
When other clients still use the GPU, the driver now remembers the request
(s_closeWhenIdle, session state flag CLOSE_WHEN_IDLE): the last client's
leaving closes the session, even after the installer has given up. The
request goes with the session. Nothing about Retire's authorization
changes. Disconnect GPU uses the same path when its Retire DISCONNECT is
refused.
Tests: test-session-shutdown runs the production code for the upgrade with
no client left (ShutdownGPU closes the session at once, IOKit's Stop then
finishes) and with a client that leaves afterwards (refused, remembered,
closed by that client's leaving, then Stop). test-display-agent covers
reading ShutdownGPU's answers. A previous instance from before build 263
does not remember the request: the installer then asks again after the
clients leave.
The menu bar's new Performance submenu has:
- Performance level (Auto, High, Peak, Low), which maps to
power_dpm_force_performance_level (Peak is profile_peak).
- Power profile, listing every profile the card reports in
pp_power_profile_mode except CUSTOM, which takes parameters. The list is
read from the card, with friendly names for the known ones (Default,
3D Fullscreen, Power Saving, Compute, ...).
- A live line with the current GFX and memory clocks, the temperature and
the power, refreshed each second while the menu is open.
- A place for the runtime power-management modes still to come.
A choice is written at once through SysfsWrite and read back, then kept
in the display prefs (performanceLevel, and the profile by its card name).
A refused write is shown in the submenu, with the driver's reason, and
beeps. The display daemon writes the kept choices again whenever the GPU
comes up: when it opens the GPU (after a probe, a power cycle or an
upgrade) and after a reset that lost VRAM. A profile the card no longer
lists is an error that is shown, never a default. Nothing chosen means
nothing written, so the driver's Auto applies, as on Linux, since pinning
clocks costs idle power.
CLI: "MacLinuxGPUHost performance-level auto|high|peak|low",
"power-profile <name>" (a card name, menu title or index), and
"performance", which prints the current and kept settings and the live
line.
test-display-agent covers the levels and their sysfs spellings, parsing
the R9700's pp_power_profile_mode and the older one-line layout, profile
lookup, the live line, prefs persistence including files from before
these settings, and the reapply plan.
With the device kept up across programs (248), Disconnect GPU could no
longer bring the GPU down. Once the display daemon let go, the session
stayed up with or without programs. The menu bar said "still in use" for
any program with the driver open, even an observer such as mtopg, and
had no way to close the GPU for programs still using it.
- Retire gets a DISCONNECT op (session_state.h). It closes the session
now through the normal close, as QUIESCE with FORCE does, whatever
clients it has. Unlike QUIESCE it keeps admitting sessions, so the next
program to start brings the GPU up again. A raw BAR mapping still
refuses, since a close would quarantine. A quarantine is released only
when provably quiescent, as for Retire. out[2] counts the clients that
lose the GPU.
- The closed session's clients get kIOReturnNoDevice on every further
call (session and Linux-file clients alike), and the driver log says
once per client that the GPU was disconnected. They are never silently
rejoined to a new session with stale state. HSA maps NoDevice to device
lost and now says the GPU was disconnected and the program must
restart.
- The menu bar and `disconnect-gpu` wait for the displays to stop. If the
driver's session is still up, they close it with DISCONNECT. The GPU is
safe to unplug once the session is closed, whatever programs still have
the driver open. Those programs are named: they are told the GPU was
disconnected if they use it.
Tests:
- session shutdown retire-disconnect: the session closes the normal way
for every program with nothing refused, the old clients' generation is
the disconnected one, the call reports IDLE once closed, and the next
program opens a new session.
- retire-disconnect-raw-bar: refused, nothing changes.
- The observer policy admits the op.
- The display agent's readiness: safe with clients named, an open
session means apps connected (even none), closing, and the messages.
Build 242's host started display ops without a structure output, and the
driver refused PROBE, SHOW, OFF, STATUS and MODES for it; the test of the
driver's side offered 4096 bytes in every mocked call, so nothing showed
it.
The start of a display op moves into host/display_call.h
(mlg_display_call_start), which the host app calls: an async call of the
display selector carrying MLG_DISPLAY_REPORT_MAX bytes of structure
output, every op's largest. test-display-async builds that header with
IOConnectCallAsyncMethod replaced by a capture, hands the driver's own
display_call what the kernel would (scalars, structure input, output
capacity, completion) for every op that can sleep, and requires each to
be accepted and completed; the same call without an output capacity is
refused. With the header passing no output the test fails.
The async display call passed no structure output. The driver checks
the call's output capacity (structureOutputMaximumSize) against its
report before PROBE, SHOW, OFF, STATUS and MODES and refused each with
kIOReturnBadArgument, so on 242 no monitor was ever found or mirrored,
and display-probe failed. The call now carries a buffer of the op's
output size; the output still comes with RESULT.
The daemon took a failed STATUS silently: it closed its clients and
opened a new session at once, a full upstream probe and teardown every
two seconds, until a probe failed (-12) and the driver quarantined. A
failed STATUS is now logged with its IOReturn; the clients are reopened
only when the connection is lost, otherwise the daemon waits 10 s. A
failed PROBE is logged too.
The display daemon reads the driver's recovery state (QueryInfo LRST,
cached and never blocking) at its 2 s poll:
- A queue reset (the generation moved): the outputs redraw by
themselves; a mirror that ended around it starts again at once instead
of after the 10 s retry delay.
- A reset that lost VRAM: every mirror stops and starts again (imports
and lights afresh).
- Wedged (the reset failed; only a power-cycle brings the GPU back):
the mirrors stop and the daemon lets go of the GPU as for "Disconnect
GPU". The status carries gpuWedged, and the menu bar shows "The GPU
stopped answering and its reset failed" with "Power-cycle the GPU,
then choose Reconnect GPU". When the GPU leaves the bus the daemon
reconnects to it on its return, as after Disconnect.
test-display-agent covers the decisions (the first read of an instance
only records it) and the status round trip.
ff324ff's mlg_selector_call asks RuntimeBuild before every async call;
mlg_selector_call_on keeps the answer per connection. The host app now
keeps it with the open connection (reset on each open) for instances
that publish MacLinuxGPUSessionCalls = "async"; an instance without it
is still called with IOConnectCallMethod, so the installer can Retire a
pre-243 driver that the check would refuse.
An instance that publishes MacLinuxGPUSessionCalls = "async" but never
completes a Retire would hold the upgrade, and the observer client the
instance waits on, for as long as it answers Ping. Retire now waits at
most 60 s (mlg_owner_call_timed, new in host/owner_call.h: the same wait
with a deadline, kIOReturnTimeout past it; a late completion is dropped
with the call's port). The installer reports which op timed out on which
instance.
test-owner-call also runs the host header against a driver that answers
Ping and never completes: the timed call returns kIOReturnTimeout on
time, and a driver that stops answering Ping ends an untimed wait.
With amdgpu_gpu_recovery off, a job on a hung ring never completed and
every wait on it lasted forever (build 241). Recovery is now upstream's
default: a job that times out resets its queue (amdgpu_job_timedout ->
ring->funcs->reset: a MES queue reset for compute and gfx, an SDMA queue
reset), the guilty job's fence gets -ETIME, its context reports the reset
(AMDGPU_CTX_QUERY2_FLAGS_RESET) and refuses further work, and the work
queued behind it from other contexts runs.
A device reset (mode1 on gfx12, after a failed queue reset, on a ring
without one, or requested by KFD or a user queue) needs platform work not
done yet over Thunderbolt: the PCI configuration's restore with its BARs,
MSI-X, client BAR mappings in the reset window. Until then
(rt_recovery_full_reset_available), rt/recovery.h turns every request for
one into what Linux ends in when a reset fails: the device wedges. The DRM
device is unplugged (new requests fail with -ENODEV), hardware access and
bus mastering stop, every ring's fences complete with -ECANCELED and keep
completing, and KFD's waiters get its reset event. Nothing waits forever
and nothing loops on resets.
rt_recovery_attach hooks this in after the probe without changing
upstream: each scheduler's timeout handler and each queue reset are
wrapped (upstream's run unchanged inside; every recovery handler runs on
the reset domain's one ordered queue), and the KFD and user-queue reset
works are redirected to the wedge. Each queue reset that succeeds, and
the wedge, advance a reset generation. The driver publishes it as
QueryInfo "LRST" (generation, wedged and VRAM-lost flags, queue resets,
VRAM-lost counter, last result), sets MLG_SESSION_FLAG_GPU_WEDGED in the
session state, logs both as unified-log events, and the host app and
read-driver-log.py say to power-cycle the GPU when it is wedged.
The CS fixture resets queues as MES does (fx_ring_reset, with a ring test
that runs on the engine). queue_reset_check hangs a compute job: the
timeout fires, the queue resets without a device reset, another
process's job behind it runs, the guilty context reports the reset and
refuses work, a new context works and the generation advances.
wedge_check (a process of its own) makes the queue reset fail: the device
wedges, blocked work and a wait with no deadline end, new requests fail
with -ENODEV, and no device reset is tried. ttm_evict_check's stalled
move now ends with an SDMA queue reset.
From 243 every selector that can sleep is an async call, and the host
calls them with mlg_selector_call. An earlier driver runs such a call
synchronously and never completes it, so the async wait (whose Ping
only notices a driver that went away) never ends. The installer calls
Retire QUIESCE and TERMINATE on the previous instance over an observer
client: a 242 -> 243 upgrade would hang there, holding the very client
the previous instance waits for before it terminates.
The driver's personality now carries MacLinuxGPUSessionCalls = "async".
The host reads it with each instance and calls an instance without it
with IOConnectCallMethod, as that driver serves every selector.
From 243 SysfsRead is synchronous but bounded: a read over 250 ms returns
kIOReturnTimeout, and while it still runs the next is kIOReturnBusy. The
host read either as "unreadable", so a monitor whose EDID read overran
(a modeset or reset holding the display lock) was keyed by its connector
instead of its EDID, the daemon's choices no longer matched it, and the
hotplug epoch was already taken, so nothing read it again.
readSysfs and readConnectorEDID now report an overrun apart from a
failure. The daemon leaves the epoch unseen and reads the monitors again
on the next poll; a mirroring process ends with the overrun named (the
daemon restarts it); `pcie` says the read overran.
DriverKit delivers every client's calls, and the driver's own Stop, on
one thread, and runs each under its target queue with a synchronous
dispatch. Session clients shared the owner's queue, and observers and
Linux-file clients hopped to it synchronously, so a session call that
slept there (a probe, an allocation that evicts, a fence wait, a session
close), or anything queued behind one, held every client; on a GPU that
stopped, forever (build 241).
Every client now has a queue of its own, and nothing on the delivery
thread waits for the owner's queue:
- Selectors that never sleep answer there: Ping, RuntimeBuild (from flags
the session queue publishes; the context is never touched), the cached
QueryInfo tags, the power query and the power wait's registration, and
OWNER_RESULT (88).
- Every other selector must be called with IOConnectCallAsync*: the call
returns at once with a token and runs on the owner's queue, in arrival
order, exactly as it ran there before; it completes with its IOReturn,
scalar outputs and structure output length, and OWNER_RESULT fetches the
structure output once. EVENT_WAIT keeps its own completion; a wait that
does not start completes at once with the reason. A synchronous call of
such a selector is refused (kIOReturnNotPermitted, logged once per
client).
- SysfsRead and DrmInfo stay synchronous but bounded: the read runs on a
wait-pool thread (rt_bounded_run, new) and the call waits at most
250 ms (kIOReturnTimeout; while one overruns, the next is kIOReturnBusy).
The observer's self-test, Retire and ReleaseQuarantine are async calls.
- A session client's Stop, and an observer's FinishStop, run on the owner's
queue after the client's queued calls. Linux-file clients join the
session on the owner's queue with their first open (LX_CALL_ASYNC),
and the first open's InitDevice and HostWindow are async calls.
- CopyClientMemoryForType no longer touches the session: BOMap makes the
BO's descriptor on the owner's queue and the mapping looks it up; the
raw BAR lease takes its own spinlock.
Clients: host/owner_call.h and host/selector_call.h (header-only) call a
selector as the driver serves it, synchronously or as an awaited async
call; the HSA runtime, the host app (callScalar, callStruct, callMethod)
and libmlg_drm use them, and scripts/mlg_owner_call.py does the same for
drm-selftest.py and display-test.py's initialization. A client older
than this driver fails at its first session call that can sleep, with
the reason in the driver log.
Tests: test-owner-call runs the production owner_call machinery
(extracted, DriverKit mocked) against a session call that sleeps: calls
return at once, cached queries and the power wait answer while it
sleeps, later calls queue in order, completions carry the right layout,
OWNER_RESULT once, BO memory is found without the session, and a hung
bounded read times out within its bound. test-bounded covers
rt_bounded_run on the real wait pool; test-session-shutdown checks the
selector rules and runs the Stop paths through the owner's queue.
The Linux-file client library (libmlg_drm) and the libdrm over it
(libdrm_mlg, which RADV and other DRM clients load) now ship in the app's
runtime payload, signed by the team like the HSA runtime, and the
installer puts them in /Library/MacAMDGPU/runtime and /usr/local/lib in
the same transaction (staged, backed up, restored on failure), so local
apps pick up the libraries that match the driver on every update. Both
have @rpath install names, as before. activate.sh --install-hsa builds
them (make libdrm-mlg); the DMG check and the installer's validation
accept and verify exactly these files.
On 241 a GPU ring hung (no recovery), and the display agent's OUTPUT then
pinned a framebuffer: TTM evicted, the blit waited for an IB from a pool
whose fences never signal, with no timeout, on the call itself. That was
the driver's incoming-call thread, so every client froze with it, the
observer's reads and Linux-file calls included, and the driver could not
even take its own Stop after the GPU was powered off.
Every display op that can sleep (PROBE, SHOW, OFF, STATUS, MODES, IMPORT,
VERIFY, RELEASE, OUTPUT) now needs an async completion: the call takes the
display gate, queues the op on a wait-pool thread (rt_wait_pool, the
threads that already sleep for event waits) and returns at once with a
token. The thread runs the op, keeps its structure output for RESULT
(op 10, once) in a slot the op shares with the client (an op may end after
the client stopped), and completes the call with the token, the op's
IOReturn, its two scalars and its output length. A synchronous call of
one is refused; one while another runs is kIOReturnBusy.
PRESENT stays synchronous and never sleeps: it takes no display gate, and
rt_display_present and rt_display_stats take the display lock with
trylock, -EBUSY while an op holds it. The agent then carries that frame's
damage (moves as rectangles) to the next PRESENT and forgets its tile
hashes, so no later frame moves or skips rows the driver never drew.
A stopped client's imports and output are released on a pool thread once
the display gate is free (after any op of its own that is finishing).
The daemon skips a STATUS poll that finds the display busy instead of
closing its clients.
The host app's display calls are async: IOConnectCallAsyncMethod with a
notification port, the completion received on the calling thread (up to
60 s, then kIOReturnTimeout), and RESULT for the output.
test-display-async runs the production display_call machinery, extracted
from the dext source, with DriverKit mocked and an OUTPUT that never
finishes: the call returns at once, the op does not run on it, PRESENT
and another client are answered meanwhile, a second op is busy, a stop
waits for the op, the completion and RESULT (once) carry its result, and
a refused thread leaves the display free. With the op run on the call
(the 241 behaviour) it fails within 20 s instead of hanging.
Like ejecting a disk. The menu bar's "Disconnect GPU…" (and
MacLinuxGPUHostApp disconnect-gpu) records the choice in displays.json;
the display daemon stops every mirroring process and closes its own
session and observer, so nothing of ours touches the GPU. The menu then
waits up to 20 s and says either that the GPU can be unplugged, or which
apps still use it ("Still using the GPU: amdgpu_mtopg (pid 692). Quit
it, then unplug the GPU.", from IOKit's client records), or that the
driver is still closing its session (participants or closing, from its
session state). "Reconnect GPU" (reconnect-gpu) undoes it, and the
daemon clears the choice itself once the GPU has left the bus, so a GPU
plugged back in mirrors again. Files from before the choice existed read
as connected.
This is in addition to sending every VRAM access through the kernel:
an unplug without disconnecting must not panic either.
The agent also prints how long OUTPUT (the modeset) and each capture
surface's IMPORT took, one-time measurements for the cost of the kernel
route (an import writes the GART page table for its pages).
The PCI core's config file (drivers/pci/pci-sysfs.c pci_read_config) on
the runtime PCI device: cfg_size bytes through the driver's configuration
reads, a byte, a word, whole dwords, a word and a byte, little endian;
read-only (upstream also writes). Linux tools read it for lspci; here the
observer's sysfs read does.
MacLinuxGPUHostApp pcie decodes the PCI Express capability from it: link
speed and width against what the device can do, Max Payload and Max Read
Request against what it supports, extended and 10-bit tags, relaxed
ordering and no snoop. These are what Linux configures at enumeration
(pcie_bus_configure_settings, pcie_set_readrq, extended and 10-bit tags);
a device left at reset values moves data in smaller requests. Nothing
is written.
The 236 -> 237 upgrade hung: the 236 instance stayed "terminating for
upgrade via delegate" while amdgpu_mtopg (pid 692) kept an observer
connection to it, and the installer only reported that Retire was not
answered (kr=0xe00002c1).
0xe00002c1 is kIOReturnNotPrivileged: the driver refuses Retire unless
the caller carries the session-release entitlement, and the signing
flow takes the app's entitlements from its provisioning profile, which
cannot carry that custom key, so no shipped build has been able to
Retire a previous driver. The previous instance then leaves only once
every app connected to it has disconnected. The installer now says so
in those words.
While it waits, it names every app still connected to a previous
instance (from IOKit's IOUserClientCreator records, without its own
connection) and tells the user to quit them. Before each Retire it
posts a Darwin notification, com.geramyloveless.maclinuxgpu.driver-retiring,
whose state is the previous instance's registry ID, so monitoring apps
that follow it (amdgpu_mtopg) close their connection to that instance
and reconnect only to the new driver.
MacLinuxGPUHost menu-bar is a background item (never in the Dock) with,
for each monitor on the GPU, an On/Off toggle and its live state (off,
starting, mirroring at WxH @ Hz, or the last error), the "Start
displays automatically" setting, the log and the app. It never creates
a virtual display: it writes the user's choices and reads the
display daemon's status, with a Darwin notification each way
(DisplayControl, under ~/Library/Application Support/MacLinuxGPU). Its
template icon shows on, off or an error. It runs from its own per-user
LaunchAgent, which the installer registers with the display agent; the
app has a setting to hide it.
The daemon now mirrors each connected monitor the user has not turned
off in its own child (--connector), keyed by the monitor's EDID vendor,
product and serial, so a choice holds across reboots, replugs and
connectors. It holds a session so the GPU is up, reads the monitors from
the driver's cached hotplug state (probing when the hotplug epoch
moves), reconciles its children with the choices on every change, and
publishes what each child reports.
test_display_agent: choices persist and are keyed by identity, a
damaged file reads as defaults, the status round trip and summary, and
the mirroring process's lines. Verified on the R9700: turning the Dell
off removed its display and restored the monitor; on brought it back at
2560x1440.
A display agent started by hand (or by an older app) holds a session,
which keeps the previous driver from handing over the GPU, and would
compete with the LaunchAgent for the monitor. The upgrade now stops
every display agent of the user (SIGTERM: each restores its monitor),
not only the LaunchAgent, and enabling autostart does the same before
it bootstraps the LaunchAgent with the installed app.
display-agent --create --daemon is the per-user LaunchAgent that makes
the monitor on the GPU a Mac display whenever the driver runs (a dext
cannot: the WindowServer is per user session). It waits for the driver
with IOKit matching notifications, opens its own session (bringing the
GPU up if needed), mirrors the connected monitor, follows hotplug from
the driver's cached state, tears down when the driver or the monitor
leaves and comes back when they return. SIGTERM ends it cleanly; it
logs with timestamps to ~/Library/Logs/MacLinuxGPU-display.log and
never shows in the Dock.
DisplayAutostart installs it as
~/Library/LaunchAgents/com.geramyloveless.maclinuxgpu.display-agent.plist
(Aqua sessions, restarted after a failure). The installer enables it
once the driver is verified unless the user turned it off; the app has
a toggle, and display-autostart on|off|status does the same from the
command line. A driver upgrade stops it before the previous driver
hands over the GPU (its session would hold that driver) and starts it
again afterwards.
The mirroring itself is now one function used by both the one-shot
agent and the daemon. The agent becomes a background agent before it
touches the WindowServer and registers a display reconfiguration
callback: CoreGraphics caches the display configuration a process has
seen, so without it a virtual display created later has no modes in
that process. Detached runs ignore SIGHUP.
Measured on the R9700 (build 235, the Dell at 2560x1440): a window
redrawing a 1732x1140 region every frame made every flip copy about
24.8 MB from the capture surface, three times the region: the frame's
damage plus the same region again for each scanout buffer that had
missed it, kept as separate rectangles. At 0.73 ms per MiB over
Thunderbolt that is 17.3 ms of copy per 16.7 ms frame, so frames were
replaced before they could flip (55 flips/s) and the picture lagged; a
full-screen workload stopped the output when its copies backed up past
the flip timeout.
Damage now folds a rectangle into any it overlaps closely (contained,
equal, or overlapping so the box is no larger than the two), so the
region stays one rectangle and is copied once; damage covering nine
tenths of the frame becomes one whole-frame copy. The flip wait first
waits for its own copies (bounded at 2 s, as GPU work), then for the
flip (200 ms), and says which did not complete.
printk_once and the DRM *_ONCE messages are now once per call site:
DM's MST/DSC check logged "dsc precompute is not needed" on every
commit, sixty times a second, filling the kernel log.
The display agent also finishes launching as a background agent only
after its virtual display has a mode: made an NSApplication earlier,
the process never saw the new display's modes.
test_display_pipeline: a window redrawn in place with an item inside
it copies the window's bytes once per flip.
The agent connects to the WindowServer (CGVirtualDisplay,
ScreenCaptureKit) from the app's own executable, but only the move and
full workloads made the app an accessory and finished launching, so in
still mode (and any unattended run) the Dock showed MacLinuxGPUHost
bouncing for as long as the agent ran. --create now sets the accessory
policy and finishes launching before anything else.
System Information builds a PCI GPU's entry from the IOPCIDevice merged
with the properties of its direct children, and properties a dext sets
with SetProperties() reach user space as top-level keys. The dext now
sets the keys it reads on its own service:
model the product name, from libdrm's table (Start)
VRAM,totalMB gmc.real_vram_size (after the probe)
ATY,EFIVersionB the VBIOS part number ("VBIOS Version")
rom-revision the VBIOS version string
so "Display" becomes "AMD Radeon AI Pro R9700" with its VRAM and VBIOS.
A device the table does not list gets no name; Metal and core-count keys
are not published because they would be false.
MacLinuxGPUDevice carries the rest of the identity (IDs, PCIe link, VRAM
type, CUs, ISA target, VBIOS details) and MacLinuxGPUDisplays the DRM
connectors with their monitors' EDID names and modes, updated by the
display operations and removed when the session closes. System
Information cannot list those monitors under this GPU (it only lists
IOFramebuffer kernel objects there), so MacLinuxGPUHost shows the GPU
with its monitors: "MacLinuxGPUHost device", and a GPU panel in its
window, both read from the IORegistry without a user client.
test-device-properties builds the property set with DriverKit container
substitutes, including every allocation failure; test-device-info checks
the host view.
An activation request that replaces the driver does not stop the running
one, and the new driver attaches only after every old instance is gone. The
installer returned .replace and then checked attachment with a ping, which
the old driver answered. The old process stayed attached until someone
killed it.
The installer (the app's installer window and `activate`) now drives the
handover. It tells instances apart by IOUserServerCDHash against the
bundled dext's code signature:
- Before the activation request, each previous instance closes its session
the normal way and admits no new one (Retire QUIESCE). Apps that still
hold a session are listed.
- Once macOS has accepted the replacement, each previous instance is asked
to terminate (Retire TERMINATE) and the installer waits for it to leave
the registry. If it does not, it says why: the clients still attached, a
BAR mapping, or a quarantine that needs a restart. It also gives the
recovery steps and the systemextensionsctl state, and never kills it. A
driver that predates Retire is named as such, with the enclosure power
cycle (232 and later) or a restart as the way out.
- A failed or deferred replacement resumes the previous driver.
- Attachment is verified against the bundled driver only.
- When the bundled version is already enabled, a previous instance left by
an earlier upgrade is retired as well.
New commands: `instances` lists attached driver instances with their
clients and session state. `retire-previous [--force] [--wait S]` finishes
a stuck upgrade, `resume-previous` cancels a quiesce, and `ping-bundled`
pings the bundled driver only. activate.sh retires the previous driver
after the new one is enabled and checks attachment with ping-bundled.
- IMPORT failed on the R9700 with PrepareForDMA refusing the client's
descriptor: the import asked for up to 64 segments, and
IODMACommand::PrepareForDMA takes at most 32 (its IIG declaration
passes IOAddressSegment segments[32]). DEXT_DMA_IMPORT_SEGMENTS_MAX is
32, the mocks assert it, and a refused PrepareForDMA logs its code.
- PROBE, SHOW, OFF, STATUS and MODES failed with a bad argument from the
host app: the frame ops raised MLG_DISPLAY_WORDS to 2 and these ops
required it too. They take and return one status word again; the host
app asks for two, which every build accepts.
display-pin-test [--seconds N] [--width W --height H] [--init] creates
an IOSurface, fills it with rt_surface_pattern(1), imports it once
(IMPORT: its pages as the structure input), and after the call has
returned rewrites it from the CPU every second. Each time the driver
reads it back with SDMA and through its own CPU view (VERIFY): the new
pattern must match exactly and the previous one must not. Then RELEASE,
after which the handle must be gone.
display-agent --create [--connector NAME] [--seconds N] [--init] mirrors
one connected monitor as a macOS display:
- a CGVirtualDisplay from the plan (name, IDs, size, primaries, the
monitor's progressive modes, hiDPI 0), with the private CoreGraphics
classes declared in CGVirtualDisplayPrivate.h;
- OUTPUT at the mode macOS picks for it;
- a ScreenCaptureKit stream of it in BGRA at that mode and refresh,
each capture surface imported once, each frame's dirty rectangles sent
with PRESENT;
- a mode chosen in System Settings relights the monitor at that mode;
- Ctrl-C, SIGTERM or --seconds end it: capture stopped, imports
released, the monitor's previous configuration restored (OFF), the
virtual display removed, and a summary of frames, average copy and
flip times, bytes copied and the agent's CPU time.
It needs Screen Recording permission and says so when it is missing. Any
failing step ends the run with its errno; nothing else is tried.
The frame replies (verify result, present stats) and the damage
conversion live in DisplayAgent.swift, covered by test-display-agent.
A single pass needs no hotplug epoch: it probes at once, so it runs on
drivers without the STATUS op. A driver without STATUS or MODES (before
build 231) now gets a message naming the op and the build, and a
connector without a plan still shows its decoded EDID.
MacLinuxGPUHost init and drm-selftest.py --init called InitDevice
without placing the host window (selector 54), so compute start failed
with gart status -19. Query the aperture size, reserve it aligned, set
the base, then probe, as the HSA runtime does.
MacLinuxGPUHost display-agent --dry-run [--once] [--interval ms] [--init]
follows the GPU's connected monitors through an observer client. It polls
the cached connector state (selector 84 STATUS) and, when the hotplug
epoch moves, probes, reads each connected monitor's mode list (MODES)
and EDID (sysfs), and prints the CGVirtualDisplay it would create, then
the add, update and remove changes against what it had. It creates no
display; without --dry-run it refuses.
The plan takes the identity and colour from the EDID: the monitor name
(else PNP ID and product), the PNP ID word as vendor, the product, the
serial (or a stable hash of the serial string), the CIE primaries and
white point. It takes the modes from the driver's list for the link:
progressive only, duplicates dropped, preferred first, and the largest
mode as max pixels. The size comes from the driver's display_info (else
the EDID's). hiDPI is 0. A monitor with no valid EDID or no progressive
mode is reported and skipped.
The model (report/modes/EDID decoding, the plan, the agent's changes)
moves to host/DisplayAgent.swift, Foundation only, which the Xcode
target now builds; test-display-agent compiles it with a test of its
own. docs/macos-displays.md records what of the frame path exists.
The host app runs the in-driver display test (selector 84) from the
command line, through an observer client:
MacLinuxGPUHost display-probe [--edid]
MacLinuxGPUHost display-test [--connector NAME]
[--pattern bars|white|gradient] [--seconds N] [--init]
MacLinuxGPUHost display-off
--init initializes the GPU through a session client (InitDevice with the
firmware servicer) held for the run; display-test then defaults to 30
seconds. Reports list each connector's status, modes, preferred mode and
the lit outputs; --edid reads and decodes each connected EDID through
SysfsRead. Failures print the failing step's errno.
MacLinuxGPUHostApp power-hold [seconds] asks the driver for low power,
waits (10 s by default), then drops the request: the quiesce and resume
a backgrounded app gets, on demand, so the path that keeps VRAM can be
exercised while a client is running.
MacLinuxGPUHostApp power prints the driver's device power state, and
power-watch stays running with an observer client that asks for low
power on NSWorkspace willSleep and drops the request on didWake, so
clients can quiesce before the driver closes the session for the
sleep. The request needs the session-release entitlement the app
already holds and ends with the process.
The README's limitation no longer says there is no suspend/resume: it
says what a sleep does (the session closes and clients reload, because
the link going down resets the GPU and upstream's dGPU suspend would
evict all of VRAM to system memory) and what a low-power period
without sleep keeps.
Runs the unmodified upstream Linux amdgpu and amdkfd drivers on Apple
Silicon Macs inside a DriverKit system extension, for AMD GPUs attached
over Thunderbolt. The Linux sources come from a pinned submodule and are
compiled against linuxu, a userspace implementation of the Linux kernel
APIs they use. Includes the HSA runtime, the host installer app, the
setup and firmware fetch scripts, and the offline test suite.