Repository navigation
drm: asahi: add T8140/G17 GPU driver - #171
Closed
DjDeveloperr wants to merge 105 commits into
Closed
DjDeveloperr wants to merge 105 commits into
DjDeveloperr wants to merge 105 commits into
Conversation
The kernel requires Rust 1.85, which supports const f32::to_bits. Replace the equivalent transmute and its obsolete lint allowances, including the unnecessary_transmutes lint unknown to Rust 1.85. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
drm_sched_fini() passes each job left on the pending list to cancel_job and frees it right after. Such a job is in one of three states: its hardware fence callback is still armed, the callback has already completed the job, or drm_sched_stop() detached the job from its hardware fence, returning its credits but not its score. cancel_job_cb() treated every job as unfinished and signalled its finished fence with -ECANCELED. For a completed job, that sets an error on a signalled fence. For a job whose callback is still armed, the callback stays armed on a job that is about to be freed, and the job's credits and score are never returned. For a detached job, the score is never returned. drm_sched_fini() stops the scheduler workers, but not the hardware fence, so remove the callback first. Fence callbacks run under the fence lock, so dma_fence_remove_callback() either disarms the callback or waits for it to complete. Then, unless the callback completed the job, return the job's score and any credits drm_sched_stop() has not already returned, as drm_sched_job_done() would have, and signal the finished fence with -ECANCELED. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
drm_sched_entity_destroy() does not necessarily free the jobs still queued on the entity: drm_sched_entity_kill() hands each of them to a work item on the system workqueue, possibly only once the job's last dependency has signalled, and that work calls job->sched->ops->free_job(). The scheduler is embedded in SchedulerInner, which is freed as soon as the last Scheduler or Entity handle is dropped, so dropping a scheduler right after its last entity can leave that work dereferencing freed memory. Let every job hold a reference to the scheduler allocation. Finalizing the scheduler must not wait for those references, since drm_sched_fini() is what cancels and frees the pending jobs, so move it to a separate SchedulerOwner that only the Scheduler and Entity handles reference. The owner is allocated before drm_sched_init(), so that nothing can fail once the scheduler is initialized. The scheduler is now only reachable through shared references while C code keeps mutating it, so store it in an Opaque. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
drm_sched_stop() belongs to the reset recovery protocol, and its documentation says not to call it before drm_sched_fini(). At teardown it detaches every in-flight job from its hardware fence and frees the jobs that have already completed. That is redundant: drm_sched_fini() stops the scheduler workers itself and hands every remaining job to cancel_job, which now handles jobs with an armed, completed or detached hardware fence callback. Call drm_sched_fini() alone, so that cancel_job sees each job's actual state and accounts for it exactly once. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Drivers that recover individual jobs without the scheduler reset protocol need to keep unfinished jobs pending while retaining their original fences. Expose DRM_GPU_SCHED_STAT_NO_HANG as Status::NoHang: the scheduler reinserts the job, rearms its timeout, and frees it when completion is observed. Add Job::is_finished() to detect completion between timeout expiry and its handler. The finished fence is initialized only when armed, so an unarmed job reports false. Let a driver also reconsider a timeout before entering recovery, for work whose execution window has just been renewed. The false_timeout callback defaults to false and must not stop or restart the scheduler. Returning true follows the same NoHang reinsertion path. Existing drivers retain their timeout behavior unless they opt into the new callback or return Status::NoHang. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Some co-processors place their shared buffers themselves, such as the GPU co-processors of the T8140 (A18 Pro). Their buffer requests carry the IOVA of memory the co-processor already uses, and the request must be acknowledged by sending it back unchanged, whereas RTKit sends nothing for such buffers today. These co-processors also have their crashlog endpoint started while the endpoint map is handled, before the map is acknowledged, instead of together with the other system endpoints after the last map message. Add a flags field to struct apple_rtkit_ops, with an APPLE_RTKIT_COPROC_PLACES_BUFFERS flag selecting this behavior. The buffer is still set up through shmem_setup, which lets the driver provide the memory behind the co-processor's IOVA, for instance to read crash logs from it. Without the flag, RTKit sends exactly the same messages as before. Expose the flag to Rust drivers as Operations::COPROC_PLACES_BUFFERS. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
The T8140 (A18 Pro) GPU is run by two firmware co-processors, GFX and GFX1, each with its own control registers and mailbox. Its node therefore has three register ranges (asc, asc1, sgx) and two mailboxes. The firmware shares the GPU MMU translation tables, page tables and handoff structure through the same reserved memory regions as on earlier GPUs, but needs neither calibration blobs nor a global variable region, and it does not use apple,firmware-abi. The GPU power domain and the performance states are required. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
The GPU co-processors of the T8140 (A18 Pro) use the v4 ASC mailbox layout. Unlike the other T8140 ASC mailboxes, described by apple,t8140-asc-mailbox, they do not need the application processor to enable their receive FIFO. Add apple,t8140-gfx-asc-mailbox for them, with apple,asc-mailbox-v4 as the fallback. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Add the power domain of the GPU and its co-processors, and keep the afggfxni0 domain always on. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Add the GPU, the mailboxes of its two co-processors, its performance states and the reserved memory regions it shares with its firmware. The mailbox nodes describe only the mailbox block of each co-processor wrapper, at offset 0x8000. The bootloader fills in the reserved memory regions and the device-specific performance states. It also reserves uat-l2-pagetables for GPU page tables; the GPU node does not reference that region. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Enable the GPU and its mailboxes, and add the gpu alias through which the bootloader finds the GPU node. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Extend the UAPI for the G17 generation of GPUs: - drm_asahi_params_global gains the shader instruction set generation and the command stream generation (enum drm_asahi_gpu_hal_generation), which userspace needs to select its code generation and the layout of its control streams. - DRM_ASAHI_FEATURE_VM_STATUS and DRM_ASAHI_PARAM_GROUP_VM_STATUS report the sticky error of a VM, so that userspace can tell whether work behind a signalled fence executed successfully. - DRM_ASAHI_FEATURE_VM_STATUS_MIRROR and DRM_ASAHI_PARAM_GROUP_VM_STATUS_MIRROR let userspace register a word that the kernel keeps equal to that error. - DRM_ASAHI_FEATURE_INDEPENDENT_QUEUES and DRM_ASAHI_PARAM_GROUP_QUEUE_LIMITS report how many queues the device supports and how many jobs of a queue may run at once. - DRM_ASAHI_FEATURE_PER_COMMAND_INPUT_SYNCS promises that every command of a submission waits for all of its input syncs. - The background and end-of-tile resource specifiers of G17 are 64 bits wide. Their high halves are appended to drm_asahi_cmd_render and flagged with DRM_ASAHI_RENDER_RSRC_SPEC_HI, which older kernels reject. The existing driver reports the generations of the G13 and G14 GPUs it supports and none of the new features. It still accepts render commands of the previous size, zero-filling the new fields, and rejects the new flag. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
The file and ioctl layer uses a manager trait that also exposes G13/G14 firmware allocators, VM slots, event handling and control channels. A GPU with a different firmware interface cannot implement those internals. Separate the DRM-facing operations into Gpu: VM and queue creation, timestamp mapping, sequence IDs, crash state, timer frequency and hardware parameters. Existing managers implement it directly and expose their firmware-specific interface through Gpu::manager(). Keep the legacy firmware-global update at ioctl entry after flag validation, before queue lookup and userspace copies, outside the queue mutex. Invalid queue submissions still refresh the firmware idle policy. Legacy operation ordering and reported hardware values are unchanged. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
G13 and G14 GPUs translate 39 input address bits per UAT root, and the driver hardcodes that width in the page table walker, the user and kernel VA ranges and the user range reported to userspace. Newer GPUs use the same 16 KiB granule and three-level walk, but translate 42 bits per root. Describe the address width of a UAT instance with a UatGeometry (input and output address bits) and derive the ranges from it: the user range spans the lower root, the dummy page sits two pages below its top, and the driver-managed kernel range is the third top-level entry of the upper root. The input width becomes per-SoC configuration data next to the output width, Uat::new takes the geometry instead of the firmware configuration, the page table walker takes the input width per table, and the file layer gets the user range from the device instead of a constant. All G13/G14 configurations describe a 39-bit input width, for which every derived value equals the constant it replaces: user top 1 << 39, dummy page 0x7f_ffff_8000, kernel range 0xffff_ffa0_0000_0000 to 0xffff_ffb0_0000_0000, upper range from 0xffff_ff80_0000_0000, and the walker's input mask. No functional change on those SoCs. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
A borrowed root does not determine ownership of its child tables. The handoff firmware interface leaves the driver owning all child tables in its managed range; another interface may publish its own child tables into that root. Make shared child-table ownership explicit when borrowing a root. In that mode, record each driver allocation before publishing its pointer and free only recorded tables. Keep the borrowed root itself unowned. The existing handoff caller selects non-shared children, preserving its allocation and teardown behavior without an extra ownership allocation. Driver-allocated roots also retain their existing ownership behavior. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Provide boot, address translation and retained firmware resources for T8140, with independent render and compute queues behind the existing GPU interface. Keep visible command storage and VM pins through exact retirement, firmware drain or processor stop, and finish fences outside the device lock. Implement the G17 command ABI, per-VM status, logical ordering, asynchronous resource growth and recovery isolation together so every exposed operation has its firmware and ownership consumers. Validate shared recovery views and use bounded halted-slot identity reads to resolve ambiguous render blame. Retain unexecuted compute work for bounded replay when no firmware consumer has already depended on it. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Allow a kernel waiter to request a temporary minimum utilization while preserving the task's requested clamp and aggregate runqueue accounting. Balance nested scopes in LIFO order and restore the previous floor on exit. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Associate a bounded utilization hint with a DRM file after successful submission. Apply it only around a blocking syncobj wait while it remains valid, and release the scheduler scope on every wait exit. Expose the hint setter to Rust DRM drivers. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Detect sustained render completion intervals and request temporary CPU capacity while submissions remain latency-sensitive. Retain detector ownership through completion, service the actuator on one work item, and remove its frequency requests after joining producers during shutdown. Provide an expiring syncobj wait hint only while the detector and applied capacity request agree. Keep this policy separate from firmware execution, queue depth and resource retirement. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
An event batch without a usable queue identity must still observe completed compute commands. Use the full scan for zero masks while retaining QID filtering for identified batches, so coalesced notifications cannot strand an otherwise retired command. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Consume prepared VM guards in order without shifting the remaining vector for every command. Iterator destruction still releases unused pins on partial enqueue failure. Capture shared attachment metadata under one binding-lock hold per footprint, preserving range insertion order and releasing the lock before allocation. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Entity teardown can free a queued job without invoking its cancellation callback. Signal its independent completion fence through the existing unpublished cancellation path so cross-engine timestamp dependencies can retire. Leave jobs whose publication has already been claimed with their existing owner. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Submission collectors are sized for one physical queue, but recovery can settle retained commands from every compute queue. Reserve for the complete replay pass before changing any queue, including the publication that follows it. Skip reservation when no queue needs recovery work, preserving the small collector used by healthy submissions. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
A shared completion scan needs only the control word of unrelated QIDs. Retain a bounded record view, capture control once, and read descriptor and queue identity before the two timestamps used for retirement. This avoids unused payload loads while preserving the single Acquire-ordered scan and exact kick matching. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Read the opening control counters after the final one-millisecond wait, matching the existing firmware initialization polling budget. Firmware that retires the records during that last interval now completes initialization instead of being torn down as timed out. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
The initial sample precedes the bounded wait intervals; the final interval also ends with a counter sample. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Prepared mapping batches can fail after earlier leaves have committed. Update canonical context metadata with each successful leaf so context setup observes mappings already visible in the VM. Preflight arithmetic in a compact map plan and retain displaced GEM references until reservation locks are released. Preserve canonical invalidation when quarantined unmaps enter deferred cleanup. Remove the duplicate ioctl update vector, extra object references and post-batch metadata pass. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Remove canonical candidates under the existing GPUVM exec guard after successful object unmap. Keep deferred acceptance invalidation under the lifetime lock, with the queued GEM reference retaining the object. This prevents a trailing close callback from erasing a newer committed binding without adding locking or allocation. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Report the independently reserved logical queue capacity and per-command input synchronization already provided by G17. Userspace can then expose multiple queues and preserve independent command roots while forwarding input syncs to each submission. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Order firmware event payload reads after the producer cursor establishes that the record is available. Move the existing acquire fence to this boundary, preserving the record-copy and consumer-store ordering without adding a barrier to nonempty drains. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
The comment on the constant word tables recorded how they were produced and named an out-of-tree workspace. State what the tables are instead. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
The runtime registry and the retained compute queues each defined an identical now_ns() over the monotonic clock source. Define it once in the G17 module; the runtime's submodules keep their existing path through a re-export. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Growing the table of contexts awaiting a scheduler release past its preallocated 128 entries is ordinary behaviour under a burst of closes; the one-shot log line that reported it informed nobody and the table still grows the same way. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
A vacated compute queue (USC pool given back) still owns its 4 MiB descriptor ring. Once the queue is idle without an owner, the firmware's job list and context item only name consumed descriptors, so drop the ring and its aliases together with the pool backing, and allocate a fresh ring when an owner re-arms the queue, before the bind that aliases it into the client VM. Submissions to a vacant queue report EAGAIN until the re-arm, as for the pool. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
A compute queue whose closed owner was killed stayed quarantined with its exit transaction retained for the device's lifetime, so every fault or kill with work in flight consumed one of the finite compute QIDs for good until the device ran out and queue creation failed. The firmware acknowledges each kill (ContextKilled) and the driver settles every killed command before marking the transaction released; use that as the witness: reset the item ring to empty at the firmware's consumer cursor, clear the quarantine and exit state, and treat the queue as a released idle queue that must give its USC pool and descriptor ring back and be re-armed fresh before the next owner binds it. Recycled queues are vacated regardless of the warm cap. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Each logical context that has rendered keeps a render pool with about 24 MiB of pinned USC backing for the rest of its life, also while the client is idle and the machine is reclaiming memory. When pressure reclaim has evicted a client's VM (it was idle for the reclaim quiet window and has no job or binding in progress) and the firmware has consumed the pool's final free-list release, the event worker now detaches the pool's backing and both of its aliases and hands them to its deferred batch, which frees them after the device mutex is released. The pool keeps its ID, control and state objects. Before that client's next render, the submission path installs fresh backing, and the changed backing makes the next staging rewrite the control header and descriptor row, as for a new owner of the slot. A vacated pool is never staged. Clients whose VM was not evicted are unaffected; an evicted client already restores its VM before its next job. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
…ware Every queue the driver creates uses firmware priority class 2 and policy 2, written as constants into the queue record, queue configuration, kick announcement, kick header, work-ring selection, doorbells and render registration token, and the QoS row class and share are constants too. The DRM queue priority is validated at queue creation and then dropped. Give each logical queue a scheduling profile (priority class, policy word, QoS class and QoS share), fixed when its context is created, and take every one of those fields from the owning context's profile. LOW queues use priority class 3 and MEDIUM queues keep class 2; the other profile fields are unchanged because no different values are known for class 3. HIGH and REALTIME remain refused. A physical queue takes a new owner's profile only at the existing rebind boundaries, which require it to be idle: a same-VM render rebind also replaces the priority and policy words of both queue records when they differ, compute owner changes do the same in their record, and a render pair whose registration carries another class is registered again at its next publication, under the same power hold as a first install. Work slots mark the first slot naming a queue per priority class, since each class has its own work rings. With only MEDIUM queues, every record, ring, doorbell and token keeps the values and store order it had before. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
map_in_range_with_guard_size() and prepare_bind_object() take seven parameters including self, which is clippy's default too_many_arguments threshold, not above it. The allowances silenced a lint that does not fire. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
InitData::build placed and initialized every boot object in one 360-line function with two placement closures. Keep the placement inputs in a small environment and perform the same steps, in the same order, as one function per region: register windows, descriptor tables, render free lists, the render pool, the compute pools, the bundle with its rings and regions, and the firmware-object initialization. The four fences keep their positions and the firmware objects are byte-identical. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
…r_pair build_render_pair() held the device-locked selection of how a slot is built, the three off-lock-then-locked install paths and the final locked warm-up in one 400-line function. Move each install path into its own function: install_fresh_pair(), install_parked_pair() and rebind_pair() construct off the lock and install under it exactly as before, and finish_render_build() rebases a fresh graph and warms its pool. A small Copy context carries the lease, allocator, resources, slot and first packet to the install steps. Statement order, lock scopes and error handling are unchanged; the selection stays a block expression in build_render_pair() because returning the selected resources and build by value doubled their stack slots (+1.3 KiB on the scheduler run_job path). The three install steps are inlined: as separate frames they deepen the run_job path, which is close to its stack budget. With them inlined the path measures 17,616 of 18,432 bytes against 17,392 before this change. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
…and announce Pair::publish() checked the pair, assembled the kick barriers, committed the descriptors and announced the pair to the firmware in one 350-line function with two near-identical failure blocks. Move the entry checks into publication_preflight(), the barrier assembly into render_barriers(), the announcement with its failure path into announce_publication(), and the shared tail of both failure paths (terminal status, deferred failure, failed flag) into record_publication_failure(). The checks, the barrier rules and the order of every effect on failure are unchanged. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
…iguration Queue::publish() checked the queue, built the descriptor arguments and the queue configuration record, and committed and announced the kick in one 330-line function. Move the entry checks into publication_preflight(), which hands back the epoch and the bound owner's per-queue addresses as values, and the configuration record into queue_config(). The commit and announcement stay one closure: its visible/accounted state decides the rollback for both phases. Checks, record contents and effect order are unchanged. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
…in flight Each retained compute queue carried a 4 MiB descriptor ring: 256 slots of 16 KiB, one per kick-ring slot, although at most IN_FLIGHT (16) kicks are outstanding and every kick names its descriptor by address. Index the ring by kick slot modulo 32, so a descriptor is rewritten only once the kick 32 publications later is issued, long after its own completion. The ring shrinks to 512 KiB per queue; with the fourteen queues of a desktop and a game that is 49 MiB less pinned memory. Retirement records match on descriptor address and kick timestamp together, so a reused address cannot alias an older kick. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Revocable CPU VMAs hold PFN mappings without ordinary rmap references. Dropping either the device page array or sparse CPU page references can make those pages reclaimable while a user PTE still names them. Mark the object purged and unmap all DRM VMAs, including the TLB invalidation, before releasing either array or clearing unevictable protection. This matches the existing idle-release ordering and covers both SG-first faults and sparse CPU backing. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Both GPU probe paths allocate a DRM device before creating the GPU manager. A successful no-op PinInit incorrectly claimed that AsahiData was initialized, so ordinary firmware, identity or allocation failures could run its destructor over uninitialized GPU and platform references. Add explicit two-phase allocation to the existing Rust DRM device. Keep the pinned data slot in UnsafeCell<MaybeUninit<_>> and publish destructor ownership only after the real initializer succeeds. Use a static allocation vtable while release state itself is uninitialized. Preserve the ordinary initialized constructor and inline workqueue offsets. Convert both Asahi probes to the explicit API, avoiding references to uninitialized data. Partial initializer failures unwind their own fields; post-initialization failures retain normal data destruction. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
drm/shmem: revoke CPU PFNs before releasing purge backing
Each tiler heap (TVB) block is 128 KiB and is mapped at a 160 KiB VA stride, so that an unmapped 32 KiB guard follows it. The backing object used the same stride: block i was mapped from offset i * 160 KiB, and an object of n blocks was (n - 1) * 160 KiB + 128 KiB long. Every block but the last therefore carried 32 KiB of allocated, zeroed and pinned backing that no GPU mapping covers, 20 % of all tiler heap memory. Map block i from offset i * 128 KiB and size the backing to n * 128 KiB. The VA placement, the guards and the addresses handed to the firmware are unchanged. At the in-world peak of a measured Subnautica session the render pairs held 2,057 blocks in 49 objects, so this returns 62.7 MiB. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Boot allocates three groups of 1 MiB pool blocks that no GPU mapping ever covers and nothing writes: - render blocks 23..27: the render pool maps blocks 0..21 and keeps the compute page list in block 22, but allocated 28 blocks; - the 23rd block of the device-wide compute backing: compute VMs map 22 of the 23 blocks; - the backing of the two zeroed compute blocks: their VAs fall inside the compute pool's page-list mapping, and the objects were never aliased anywhere. Each block is a zeroed, pinned kernel object for the life of the device. Allocate only the mapped render blocks plus the page-list block, only the mapped compute blocks, and no zero-block backing. Every firmware-visible address and table is unchanged; this returns 8 MiB. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
A render pair's tiler heap (TVB) grows on demand, by firmware request or from the sampled page high-water, and never shrinks. A pair that grew for one heavy scene keeps that growth for its whole life, also after the client returns to a light scene or goes idle; in a measured Subnautica session the game's pairs held 260 MiB of growth until it exited. The macOS driver shrinks its parameter buffers (AGXParameterManagement::checkForShrink). It folds the page high-water into an average once per check, average = max((sample + 4 * average) / 5, sample). For each check in which the average stays below a quarter of the capacity it removes one 512 KiB block, and a buffer that has been idle for ten seconds returns to its minimum. Apply the same policy from the event worker, with a minimum that keeps what recent work used, so a shrink never makes the next pass at the recent load grow again: - once per second, sample the page high-water (sharing the sample with the growth check) and update the average; a period with a sample or a prepared pass also enters a window of the last ten such periods; - each second the average is below a quarter of the capacity earns 512 KiB of shrink; - a pair with no pass prepared or in flight for ten seconds may shrink to its floor; - the floor is the largest of the primary backing, the blocks of the last pass layout, and the size below which the automatic growth check would grow again for the largest sample in the window. No shrink goes below it. A shrink removes whole trailing growth extensions only, and only while the pair is idle and every block is back in the inventory ring. The kept blocks are laid out as a fresh heap is (ring entries and page list from the read cursor, state counts, both inventory cursors), and the PB descriptor row is reloaded, as an idle-host growth does. The removed blocks' client aliases leave the VM cache under the device mutex; the worker unmaps and frees them after it. A shrink is best effort and leaves the heap unchanged if anything fails. While some heap can still shrink, the worker wakes at least once per second. If the inventory of an idle heap does not hold every block, the heap is left as it is and the first such heaps are reported once each with their inventory cursors. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
A compute queue whose owner closed or exited stays installed for reuse, and up to four such queues (the warm cap) keep their 23 MiB USC private-memory pool populated for as long as no newer queue displaces them. On J700, the kernel's GEM after each game exit sat 54-78 MiB above its level before the game started, mostly in these warm pools. The macOS driver frees a client's USC pools with the client and also shrinks idle pools. Releasing every pool as soon as its owner is gone (a cap of zero) would make each new client re-arm fresh backing in its first submission, which costs about 2.3 ms on a cold start (measured at cap 0 on hardware). Keep the warm cap for bursts of short-lived clients, and additionally release a retained pool once it has been idle for ten seconds, the same period as the idle tiler-heap shrink. The event worker schedules its wake for the next expiry, and retries 100 ms later when a pass could not release every due pool. Queues without a release time stay bounded by the cap only, as before. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Every populated asahi GEM object keeps its shmem pages referenced: by the device SG table, a kernel vmap or a PFN CPU mapping. Those pages sit on the unevictable LRU and cannot migrate, but the compaction migrate scanner still isolates them (compact_unevictable_allowed) and every migration fails. In-world on J700, with about 5 GB of GEM held, background compaction isolated about 3,400 pages a second and 97 % of the migrations failed (pgmigrate_fail 3,203/s against pgmigrate_success 104/s). Mark the shmem mapping of a held object inaccessible. Compaction skips folios of inaccessible mappings before isolating them, and migration refuses them; the flag comes with unevictable, as mapping_set_inaccessible() sets it. Nothing reads or writes a GEM shmem file through its mapping. Kernel objects are marked when created; other objects when they take a device SG table. Releasing idle backing to reclaim, or purging, clears the mark, so released pages can be swapped and migrated again. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Use the existing DSB helper before outer-shareable TLB invalidations. A sequentially consistent Rust fence emits DMB and does not provide the completion required before the GPU discards its cached translations. Publish new page-table leaves even when no context currently names the root, so a later binding cannot expose incomplete table stores. Keep invalidation ranges, queue admission and submission batching intact. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Keep an incomplete idle inventory unchanged without a global report counter or per-heap diagnostic state. Correct the backing-layout comment and place it on Tvb rather than the deferred release container. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]>
Each render pair keeps sixteen generations, with a 32 KiB auxiliary framebuffer in each generation. Allocating a second alias from the fixed 4 MiB auxiliary arena exhausts that arena as logical contexts accumulate, returning ENOSPC and stale GL readback despite spare backing memory. Use the existing full state mapping and its auxiliary offset. The state owner already retains both the pages and their client-VM mapping for the required lifetime. This preserves queue depth and concurrent contexts. Tested on A18 Pro with 16 retained contexts, 128 immediate context recreations, targeted native GL/Zink rendering, native/x86-64/i686 compute oracles and MRT, and GL/GLES glmark2 scene validation. Unknown scene validations remain unknown; this is not a CTS conformance claim. Assisted-by: LLM Signed-off-by: Diljit Singh <[email protected]> (cherry picked from commit 27178c4)
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
G17 GPU driver for the A18 Pro (T8140) —
neo-gpu→aurora-wipThis series brings up the
drm/asahiRust driver on the G17 GPU of the A18 Pro SoC (T8140) as found in the Apple MacBook Neo (J700),and adds the shared DRM, scheduler, GPUVM and shmem-helper pieces it needs. 94 commits; head
5ad7b191f7e6.Since the last update (16 commits,
9c10d7198c8e..5ad7b191f7e6)Contents
Platform and firmware interface
dt-bindingsforapple,agx-t8140and the GPU mailboxes.Shared kernel pieces
drm/sched(Rust): job accounting on cancel, keep the scheduler alive while jobs reference it, no stop before teardown, driver-handled timeouts, timeout state separated from submission state.drm/gpuvm: non-blocking private-mapping traversal; the shared GPUVM and scheduler interfaces the driver uses; the duplicate-reservation flag exposed.drm/shmem-helper: revocable CPU mappings with idle backing release, fault pages indexed by object offset, revocable mappings populated one page at a time.drm/syncobjexpiring capacity hints during blocking waits;sched/corescoped utilization floors for kernel waiters; the driver requests temporary CPU capacity for sustained GPU feeds.tools/aurora-bindgen).Driver: submission, completion, recovery
DRM_ASAHI_RENDER_FEW_PRIMITIVES(passes with at most four known primitives) andDRM_ASAHI_RENDER_FRAGMENT_BARRIERS(barriers order only the fragment stage; compute dependencies keep ordering the tiling kick).Memory: residency, reclaim, retention
DRM_ASAHI_GEM_MADVISE(DONTNEED/WILLNEED) with purge under pressure and restoration bookkeeping.Cleanup
Hardware evidence (MacBook Neo, A18 Pro, 8 GB; serial console captured on every boot)
SUBMIT/VM_BINDstall below 100 ms (260–280 ms before the reclaim quiet window).Unevictabledrop under pressure matched the traced unpin bytes within 1.5 MiB in 21/21 samples.GEM_MADVISEfixture on both ABIs: DONTNEED retained, shared objects rejected with EINVAL, purged under a 1.5 GB swap ramp, contents exact after restore.Known gaps
Assisted-by: LLM