Repository navigation
drm/asahi: g16: Wave 2–5 GPU submit, concurrency, DVFS, ZLS/prefixes, and hang-recovery fixes - #2787
Conversation
|
Reviewed the 16 commits on top of #2741 (65a87c4..9ce6f75). No gates, knobs or taint wording found. Concerns, by commit:
Testing: all hardware results are from the J773g Mac mini, which has a fan. Rows still needed at 9ce6f75: J713 power/thermal as above, J713 vk-mustpass-short and gles-smoke, and a GPU-fault recovery run under concurrent compute+render on either M4. Assisted-by: LLM (Claude:Opus 5.5) |
9ce6f75 to
5610a84
Compare
|
@RyanTheTide Thanks for the thorough review — pushed R2 (
Assisted-by: LLM (Gemini:4 Neon) |
|
Part of a non-author adversarial pass over the stack at its tip, 1b85b1e (lifetime, concurrency, firmware-shared memory, accounting). Only items new relative to the earlier rounds here; line numbers at 1b85b1e. The two largest findings (the retained 1. Late-snapshot exemption remembers one stamp per stage (7075616 + f5a4612). With this PR, one flight carries several members, each with its own stamps (compute horizons, multi-pass render batches), and 2. Compute 3. Recovery PB slot lease does not keep the shared PB heap mapped (5610a84). 4. Low: the MethodRead-only review at 1b85b1e, with findings attributed by blame. Asahi-m4 host suite 25/25 at the tip. Item 1 and item 3 each have one unproven firmware link, named above. Items 2 and 4 are confirmed by code. Assisted-by: LLM (Claude:Opus 5.5) |
65a87c4 to
ba6a7be
Compare
5610a84 to
87fdefd
Compare
|
@RyanTheTide Rebased Point-by-point fixes (
|
Previously Cache::prepare() popped a spare PbEpoch (cap 4) or allocated and UAT-mapped a fresh 80 KiB PbEpoch for every queued render job, only for almost every render to reuse the slot's existing epoch and discard the unused epoch on drop once submission depth exceeded 4. Keep a shared per-VM standby pool in Cache::standby guarded by SpinLockIrq with the invariant epochs.len() >= reserved for all accepted unpublished render commands. Cache::prepare() tops up only the deficit in SUBMIT ioctl context before any fence exists, waiting interruptibly on a CondVar for standby headroom during bursts instead of failing with E2BIG (matching Budget::reserve's 10-second administrative bound) and retrying if a concurrent InitBM pops an epoch before commit. Steady-state queued renders at any depth allocate zero PbEpochs and perform zero UAT mappings or window syncs. Fresh InitBM publications draw from standby under the device lock without allocating, unpublished rollbacks return the unexposed epoch, and Cache::close() drops surplus epochs immediately while retaining only reserved epochs until accepted jobs drain. Signed-off-by: Diljit Singh <[email protected]>
…C reads Previously every compute dispatch zeroed 288.8 KiB of write-combined memory (256 KiB context_store, 16 KiB aux, 16 KiB preempt, unused seq, and 16 B its) and read back the 160-byte UMA descriptor byte by byte with read_volatile(). Every render pass zeroed ~530 KiB to >1 MiB of WC memory (including dead-code ta_scratch/fs_scratch, work/seq images immediately overwritten by prefix_render(), aux, scene_user, full 48 KiB preemption buffers, and tpc_dirty) synchronously under Shared::state. Track per-slot full-scrub necessity in Slots: - First use, cross-VM switch, cancelled preparation, affected error receipts, and firmware recovery (invalidate_scrub) perform the full scrub so no client or faulted state can ever leak. - Clean same-VM compute reuse zeroes only the 16-byte internal timestamp pair (its). - Clean same-VM render reuse zeroes only its (32 B), active heap header (4 KiB), tilemap_dirty, and active preemption record headers (2 KiB), preserving the tpc_dirty high-water mark until the next full scrub. - Upgrade FwObject::read() to 64-bit volatile word loads for aligned spans, reducing compute descriptor WC bus reads by 8x. Signed-off-by: Diljit Singh <[email protected]>
…it ring can_queue_behind() previously refused to pipeline behind any in-flight compute command carrying timestamp_outputs, forcing depth-4+ timed compute workloads down to depth-1 serialization. Each compute flight already owns its own private ComputeSlot (its/work), and retire_oldest() publishes timestamps in FIFO publication order before signalling the flight's fence, so timed same-VM compute commands can pipeline freely. Expand hw::sizes::COMPUTE_UNITS and params::compute_units() from 8/6 to 16 (placing extension units at 0x7080000000..0x70b8000000, clear of the 0x7040000000..0x7080000000 dynamic PB page-list aperture and below PB_HEAP at 0x70c0000000, using hardware UMA slots 1..=16). With displacement lifetime tracking, 16 units sustain up to 15 in-flight compute commands per bursting VM instead of 5. Signed-off-by: Diljit Singh <[email protected]>
…ll overhead Pipelined submissions previously never retired completed flights inside submit_locked(), forcing a workqueue round-trip whenever in-flight slots filled and producing hold[0] stalls and 300-500 us tail bubbles. At the same time, every EP 0x20 interrupt triggered full housekeeping in submit_locked(), every publish_checked() ran Session::check() (including the cross-core UAT handoff lock and full TTB scan), every TA (0x70) completion triggered a 50 us EVENT_RETIRE_POLLS busy-spin while FS was still running, every retire_once() polled all nine log sub-rings and the trace ring, and retired timestamps were re-read from WC memory for both accounting and empty timestamp outputs. Deferring the full Session::check() checks (ASC_RUN, pstate > top, and check_adopted_bindings()) to the 1 ms housekeeping tick is safe because: - publish_checked() still runs Session::transport() on every submit so RTKit crashes and latched transport errors stop publication immediately; - host VM bind/unbind updates ttbs[slot] and owned_user_roots[slot] atomically under uat.inner.lock() before submit/publish, so check_adopted_bindings() detects only unexpected firmware/external TTBAT corruption rather than normal host binding races; - the host never writes pstate > top (policy::limit() bounds every published selector to 1..=top), avoiding per-submit PPL handoff lock contention; - full Session::check() still runs on every >=1 ms housekeeping tick, on the first submit after >=1 ms idle, and whenever recovery_pending() is true. Fix the hot submit and retirement paths: - Eagerly retire completed flights inside submit_locked() when an EP 0x20 event arrived, housekeeping/recovery is due, or the oldest flight's terminal fw_stamp has reached its target, leaving evented cleared when work retires so queued poll work does not spin. - Separate 1 ms housekeeping (Session::check, object health, power, auxiliary log/trace ring drain) from per-submit fast publication, using Session::transport() in publish_checked(). - Track fragment completion events (0x71) alongside stage events so TA-only (0x70) interrupts do not trigger receipt-tail busy-spins or short-repoll storms while FS is still executing, and step the initial receipt-tail backoff from 1 us -> 2 us -> 5 us. - Split channel draining into fast event+stats draining on retirement and auxiliary log/trace draining on 1 ms housekeeping, skip ktime_get() on empty event rings, reuse retired_snapshot() GPU ticks in stat_retire(), and skip WC timestamp reads when timestamp_outputs is empty. Signed-off-by: Diljit Singh <[email protected]>
…en poll cadence Eliminate four layers of host-side latency on the G16 submit/completion round trip while preserving sleep-transition safety: 1. Direct inline submit from SUBMIT ioctl: when the previous job on the logical queue has already started, all input fences are signalled, and Shared::state is uncontended (try_lock), Scheduler::push() publishes immediately on the submitting CPU before pushing to drm_sched (whose subsequent run() observes started == true as a no-op while preserving credits, fence ownership, and QUEUE_DESTROY drain semantics). Contended or dependency-blocked jobs fall back to drm_sched in strict queue order. 2. Submitter-pinned dedicated completion worker: replace WORK_CPU_UNBOUND on system_highpri_wq for EP 0x20 / hrtimer wakeups with a per-CPU high-priority reclaim OwnedQueue (aurora_g16_events) enqueued on the last submitting CPU, keeping WC receipt reads and fence wakeups hot on the submitting core; join cleanly in sleep::join_workers(). 3. Tighten post-event retirement tail: extend post-EP-0x20 trailing 5 us polls from 4 (20 us) to 10 (50 us) to absorb firmware's WC receipt tail without falling into a 100 us resnap hrtimer sleep, and rearm at repoll_us (15 us) if an evented flight is still settling. 4. Split fast completion drain from 1 ms housekeeping and stop hrtimer / delayed-work thrash: throttle power-governor updates, host-window health checks, full Session::check(), and administrative hang checks to 1 ms cadence while keeping transport checks, ring drains, and recovery/fault checks immediate; avoid cancelling/reprogramming the hrtimer or re-arming the 1-jiffy backup when a sufficient timer is already armed. Guard run_poll(), submit_locked(), and try_submit_inline() with lock-held sleeping.load(Ordering::Acquire) checks so suspend never races inline or polled publication. Signed-off-by: Diljit Singh <[email protected]>
…ork writes With RENDER_SLOTS = 8, render pipelining capped out at 7 in-flight passes (stalling depth 8 and 16 workloads), while each render pass recomputed Geometry::new() three times and rewrote the untouched zero middle gaps of both ta_work (0x360..0x740, 992 bytes) and fs_work (0x460..0x780, 800 bytes) into write-combining memory on every clean same-VM reuse. Both WORK_STRIDE and RENDER_SLOTS are host client-VA layout choices rather than firmware bounds: firmware receives explicit 64-bit VAs for each pass object rather than indexing by stride. Each pass slot spans +0x0..+0x1c00000 (28 MiB: TILEMAP at +0x1400000 plus 8 MiB TILEMAP_SIZE), which rounds to a 32 MiB power-of-two stride (4 MiB guard) and yields 16 slots inside the 512 MiB window 0x7020000000..0x7040000000 (matching COMPUTE_UNITS = 16). - Halve WORK_STRIDE / PASS_STRIDE from 64 MiB to 32 MiB and expand RENDER_SLOTS from 8 to 16 inside the existing 0x7020000000..0x7040000000 window, raising pipelined render depth from 7 to 15. - Keep full 16 MiB TPC / 8 MiB tilemap capacity on the two base pass slots (0..BASE_RENDER_SLOTS) and size extension slots (2..16) to 2 MiB TPC / 1 MiB tilemap so bursting VMs support 15 concurrent passes up to 4K multi-layer and 8K without inflating per-VM RAM. - Track RenderOwners::last_full (mirroring ComputeOwners::last_full) and write only the active head and tail spans of ta_work and fs_work on clean same-VM reuse, saving 1,792 bytes of WC writes per render pass while full-scrub claims still write the complete images. - Compute render Geometry once per publication and update only layer_metadata after claiming the pass slot. Signed-off-by: Diljit Singh <[email protected]>
…d decouple PB/UMA slots Compact the per-pass render VA layout from 256 MiB to 64 MiB stride within 0x7020000000..0x7040000000 (verified by compile-time overlap assertions), expanding RENDER_SLOTS from 2 to 8, and move scene_list (0x4000 bytes) from the shared per-allocator Allocator into per-pass PassSlot (client VA client::SCENE_LIST + i * PASS_STRIDE, 0x7020180000). Giving each PassSlot its own scene_list matches G15's per-pass storage and prevents TA(N)/FS(N-1) overlap corruption when render pipelining is enabled. This commit is bisect-safe on its own with render overlap still off: Order::ready() and Firmware::can_queue_behind() still serialize renders at depth 1 until the following commit, so the compacted 64 MiB pass stride and per-PassSlot scene_list run cleanly under single-flight render execution. Keep base RenderArena at 2 pass slots for single-pass or light VMs and lazily allocate extension pass slots 2..8 in RenderExtArena on render bursts (mirroring compute_ext). Box RenderOwners in Slots alongside ComputeOwners and switch its displacement ledger to pipelined mode (Lifetime::<8>::new(true)), keeping up to 7 concurrent passes in flight. Decouple the two device-wide PB/UMA allocator slots (parameter_id 0/1, hardware UMA slot 33) from PassSlot index 0..8: same-VM renders stay on their active reusable allocator slot with cumulative uma_submitted tracking (PoolSet::prepare_in_flight / retired_at), while cross-VM switches and post-recovery/error renders drain and switch to the displaced alternate slot. Aborted receipts permanently quarantine the affected allocator slot and retain its VM and arena leases. Check Pools::exhausted(), per-VM Pools::exhausted_for(), and Slots::render_exhausted_within() in publish_checked() so blocked render VMs cancel immediately with ECANCELED instead of spinning on EAGAIN and stalling unrelated compute. Signed-off-by: Diljit Singh <[email protected]>
Every SUBMIT ioctl currently takes 10-40 separate gpuvm.lock_inner() holds across command root validation, attachment checks, and per-record stream-gate walks, decodes the command stream twice, calls ktime_get() on every submit even after extension arenas are allocated, and unconditionally notifies the standby condvar even with zero waiters. - Batch page-aligned VM range checks in g16/command.rs through a 48-entry stack SpanBatch calling vm.covers_ranges_batch() once per render or compute command, preserving exact per-span EINVAL/ENOENT/EACCES error reporting on failure. - Collapse command::prepare()'s two stream decode passes into one. - Reuse page coverage across 256-byte window cache hits in g16/gate.rs instead of calling cover() on every record in the same page. - Skip ktime_get() burst tracking in g16/resources.rs once extension arenas are already allocated, and skip standby_available.notify_all() when no waiter is blocked. - Add a host unit test in test-stream-gate.py verifying window-cached coverage reuse. Signed-off-by: Diljit Singh <[email protected]>
…nt barriers, and deeper queues Lift depth-1 render serialization so same-VM renders pipeline across PassSlot 0..RENDER_SLOTS while sharing the active exposed PB/UMA allocator slot, and remove remaining host-side queue-depth and wakeup-placement caps: - Allow same-engine render orders in Order::ready() to follow the queue's published render frontier while keeping cross-engine dependencies gated on full completion. - Extend Firmware::can_queue_behind() to admit healthy same-VM renders behind in-flight non-InitBM renders of the same VM (up to params::render_flights() = RENDER_SLOTS - 1), while still draining across VM switches, cross-engine transitions, InitBM priming renders, and error/recovery paths. - Emit explicit TA/FS hardware barriers in prefix_render() for queued renders: fragment-only or barrier-free renders overlap TA(N) with FS(N-1) (advertising DRM_ASAHI_FEATURE_FRAGMENT_BARRIERS); full render barriers hold TA(N) on FS(N-1) in hardware. - Remove the render_busy skip in Shared::submit_locked() so queued renders publish immediately on submit, and extend queue_passed() and retired_snapshot() for in-order passed receipts across Channel::Ta, Channel::Fs, shared notifier stamps, and cumulative PoolSet::retired_at() UMA completion. - Bound clean same-VM tilemap scrubbing in Slots::claim_pass_in() to tilemap_dirty.min(current_tilemap_bytes) while retaining the high-water mark for larger subsequent passes and cross-VM/recovery full scrubs. - Raise FLIGHTS (16 -> 32), SCHEDULER_CREDITS (16 -> 32), AHEAD_RECORDS (64 -> 128), and params::compute_flights() (16 -> 32), give each logical queue's drm_sched a creator-cluster-restricted ordered reclaimable workqueue, and implement gpu::Gpu::syncobj_wait_hint() with a lock-free active-burst uclamp hint (matching G17). Signed-off-by: Diljit Singh <[email protected]>
…s-engine barriers Previously, G16 serialized compute and render work strictly: can_queue_behind() rejected any mixed-class overlap, Order::ready() forced cross-engine dependencies to wait for full host retirement, and poll.rs only retired flights[0], leaving the compute and TA/FS hardware pipelines unable to overlap. Enable concurrent same-VM compute and render flights with per-class retirement, per-class hang deadlines, drain fairness, and hardware ring barriers: - Allow healthy same-VM non-InitBM compute and render commands to queue concurrently up to their respective per-class flight caps, while preserving cross-VM, InitBM, and query_access serialization. - Gate alt-class fallback selection on !needs_engine_drain(&job) so class-cap overlap runs concurrently on primed same-VM queues while drain-requiring head jobs (unprimed same-VM InitBM render, cross-VM switch, failed VM, or doomed/recovery/InitBM flight in progress) are never starved; advance queue fairness turns only after publish_prefix() succeeds so transient EAGAIN does not burn a turn. - Emit hardware Hold ring barriers for same-queue cross-engine dependencies (fs2c0 on the compute ring using the FS fw_stamp, and c2ta0 on the TA ring using the compute fw_stamp via a dedicated PassSlot::compute_barrier FwObject), walking all commands of a flight so multi-command compute batches resolve their exact member stamp and defer with EAGAIN if an unretired predecessor is missing. - Retire the oldest compute flight and oldest render flight independently in poll.rs, track progress and administrative/warning deadlines per class (render deadline_ns vs compute_deadline_ns) so an advancing class never masks a hung flight on the other class, and convert Job::full_retired to a 64-bit command bitmask so mixed-class jobs can retire out of class order while preserving completion proofs. - Read only the published engine's WC qstate WRITE register(s) during publication instead of touching both compute and render rings. - Add host selftests covering concurrent compute+render publication, drain fairness and EAGAIN turn preservation, fs2c0/c2ta0 barriers across multi-command flights, out-of-order per-class retirement, and independent per-class progress/timeout enforcement. Signed-off-by: Diljit Singh <[email protected]>
…l fences early Firmware::retire() previously ran up to EVENT_RETIRE_POLLS (10) x 5 us udelay() loops while holding Shared::state whenever flights remained non-empty after an EP 0x20 interrupt. At queue depth d > 1, retiring the oldest flight left subsequent flights in self.engine.flights, causing every EP 0x20 interrupt to spin for 50 us under Shared::state (bouncing concurrent try_submit_inline() submissions onto drm_sched) and to arm a 15 us short_repoll hrtimer even though retirement had succeeded. Periodic 1 ms housekeeping also ran before retiring and signalling completed fences. Split polling into a non-sleeping Firmware::poll_step() and Firmware::retire_once() that report whether any flight retired: - Stop the EP 0x20 trailing retry loop immediately as soon as any flight retires (or flights drain, a receipt fault occurs, or the engine freezes/fails), and set short_repoll only when an event with active flights still retired nothing after the trailing retries. - Release Shared::state and complete any ready jobs before each 5 us udelay() retry so concurrent inline submissions can acquire the lock without contention. - Retire and publish ready work before periodic 1 ms housekeeping, deferring housekeeping until after job::complete_all() wakes userspace whenever jobs retired on that pass. Signed-off-by: Diljit Singh <[email protected]>
…rnor On depth-1 submission loops, the engine briefly drains between consecutive jobs, causing Power::report_work(false) to toggle apple_clpc_gpu_set_active() on every job boundary (triggering mod_delayed_work(..., 0) flushes in drivers/soc/apple/clpc.c even though CLPC itself already holds rails for APPLE_CLPC_HOLD_MS = 32 ms on a 4 ms sampling cadence) and forcing the utilization governor to wait a full 20 ms window before stepping up from FLOOR. Add short 2 ms CLPC idle-hold hysteresis and an asymmetric 5 ms fast-ramp upward path to the G16 power governor: - Hold the CLPC active hint for 2 ms (CLPC_IDLE_HOLD_NS, half of clpc.c's APPLE_CLPC_SAMPLE_MS = 4 ms) across brief sub-ms depth-1 inter-job gaps via policy::ClpcHold, releasing it from service_power() once expired and re-arming run_poll() while held idle. This suppresses redundant mod_delayed_work flushes without holding across 60 Hz (16.67 ms) or 120 Hz (8.33 ms) frames. - Release CLPC immediately via Power::release_clpc_now() on fail-stop (fail_flights) and system sleep commit (sleep_down). - Add a 5 ms upward-only ramp window (RAMP_WINDOW_NS = SAMPLE_NS, aligned with the existing PMP sampling cadence) and ramp_demand() matching demand()'s upward thresholds (>= 70% -> top, >= 40% -> +1) so sustained bursts reach top within 5 ms while light 60 Hz desktop frames stay near FLOOR and 20 ms slow decay is preserved. Clamp stored Governor::demand to the active thermal/user limit on the fast-ramp path so cooling relaxation steps cleanly instead of jumping. - Add unit tests in g16/power/policy.rs and wiring checks in test-thermal-policy.py covering fast ramp, 60 Hz non-pumping, decay preservation, clamped cooling ceilings, and CLPC idle-hold expiry/reset. Signed-off-by: Diljit Singh <[email protected]>
Advertise DRM_ASAHI_FEATURE_COMPUTE_NO_QUERY_ACCESS in G16 GET_PARAMS and accept DRM_ASAHI_COMPUTE_NO_QUERY_ACCESS in compute stream/command validation. G16 publishes command timestamp outputs from the CPU during retire_oldest(). Record on each Flight whether it carries timestamp outputs and, in Firmware::can_queue_behind(), hold a same-queue compute command with a compute barrier behind an in-flight timed predecessor unless DRM_ASAHI_COMPUTE_NO_QUERY_ACCESS is set (clearing ComputeCommand::query_access). Ordinary compute dispatches that pass NO_QUERY_ACCESS continue to pipeline freely behind timed compute work, while query copy/reset compute shaders wait for host timestamp publication. Extend test-command-stream.py and test-publication.py with host coverage for the compute flag and query-access pipelining rules. Signed-off-by: Diljit Singh <[email protected]>
Every render pass claim previously ran PassSlot::scrub() synchronously while holding the device mutex (Shared::state), stalling concurrent submissions and retirement behind WC tilemap/heap/preemption zeroing. Move clean same-VM pass slot scrubbing outside Shared::state with a race-free synchronous fallback: - Record clean render retirements in Slots::note_render_retired() and stage remaining idle displaced, cleanly retired render pass slots (never Published or undisplaced Retired slots) right before dropping Shared::state via stage_and_take_scrubs(), only when the engine is neither failed nor frozen. Staging after publication avoids self-blocking immediate slot reuse within the same lock hold and skips staging on pure compute workloads. - Run staged scrubs in run_poll(), submit(), and try_submit_inline() after dropping Shared::state and after signalling retired completion fences via job::complete_all(). - Coordinate slot selection (pass_available, pick_pass, pick_pass_in) and off-lock scrub completion via SeqCst scrubbing/waiter atomics so in-flight scrubbing slots are skipped, pre-cleaned slots are preferred, and blocked waiters trigger an immediate poll_now(). - Skip synchronous WC fills in claim_pass_in()/claim_pass_for() when a same-VM slot was pre-cleaned, while falling back synchronously on first use, cross-VM switch, recovery invalidation, error/cancel, or any failed/dropped off-lock scrub. - Wait for active off-lock scrubs to drain in sleep_quiet() before entering system sleep. - Add host selftests in test-resources.py covering displaced-only staging, post-publish staging without blocking immediate reuse, off-lock scrub + zero-fill claim, waiter wakeup, dropped batch cleanup, and synchronous fallback on error/recovery/cross-VM. Signed-off-by: Diljit Singh <[email protected]>
…cation batches When publish_checked() publishes multiple commands in a single pass (multi-command SUBMITs or queued back-to-back submissions), each command still posts its own SubmitRecord and advances qstate::WRITE individually per the M4 firmware contract, but previously called session.ring(channel) on every iteration. Defer doorbell ringing into a per-batch channel bitmask and ring each touched channel once via Firmware::flush_doorbells() after the batch loop finishes (preserving FS-before-TA ordering for render batches and fail-stopping on any post-visibility doorbell error). Count commands that share a coalesced doorbell pass in Engine::stats.grouped. Add host tests in test-publication.py covering coalesced compute/render doorbells, deferred-follower flushing, and doorbell error fail-stop. Signed-off-by: Diljit Singh <[email protected]>
…imelines off-lock Ready submissions with already-signalled inputs previously still allocated and armed a drm_sched job and woke the scheduler kworker even when inline publication succeeded, and `try_submit_inline()` used `try_lock()` on `Shared::state`, bouncing bursts during brief poll-lock windows onto `drm_sched` wakeups and causing 350-520 us gap95 tail stalls on multi-depth workloads. In addition, `Timeline::complete()` held `Timeline::pending` across `dma_fence_signal()` callbacks. Bypass `drm_sched` allocation and kworker wakeup in `Scheduler::push()` when `prev_started` is true and `Job::try_start_inline()` succeeds, rolling back `accepted` and falling through to `drm_sched` otherwise. Track active firmware recovery in `Shared::recovering` (guarded via RAII in `Firmware::recover()`) so `Shared::try_submit_inline()` can bail out only during sleep or recovery and otherwise acquire `Shared::state` directly. Finally, split `Timeline::complete()` so ready head fences are drained in fixed stack batches under `signaller -> pending` and signalled without holding `Timeline::pending`. Extend `test-job-failure.py` and `test-fence-signalling.py` to cover `Scheduler::push()` inline bypass/fallback rollback, recovery bailout, and off-pending FIFO batch signalling. Signed-off-by: Diljit Singh <[email protected]>
…scene Every G16 compute dispatch previously copied the full 8 KiB ComputeWork object (0x2000 bytes) into write-combined firmware memory, even though encode_compute_for() and the firmware only touch 0x000..0x150 (header plus up to 25 register records) and 0x720..0xf08 (metadata, ABI fields, embedded sequence, notifier, UMA descriptor, tail) — leaving 5,832 bytes (71%) perpetually zero. Similarly, every render pass zeroed and copied the full 16 KiB scene object (0x4000 bytes) to WC memory even though only 0x000..0x780 (rounded up to 0x800, 2 KiB) is touched by host or firmware. - Track on ComputeOwners whether each unit's latest claim required a full scrub (first use, cross-VM switch, cancelled prep, error, or firmware recovery). On clean same-VM reuse, prefix_compute() writes only the two active spans (0..0x150 and 0x720..0xf08: 2,360 bytes instead of 8,192 bytes); full-scrub claims still write all 0x2000 bytes after preserving any existing UMA descriptor. - Zero the full 16 KiB PassSlot::scene in PassSlot::scrub(full = true), size Scratch::scene to scene::ACTIVE_SIZE (0x800), and allow fill_scene() to zero and populate that active 2 KiB prefix, cutting 14,336 bytes (87.5%) of CPU memset and WC writes per render pass. - Extend test-resources.py to verify compute_needs_full_work() state transitions and PassSlot::scene full-scrub coverage. Signed-off-by: Diljit Singh <[email protected]>
Mirror the G15 logical-queue contract on G16: - Add params::queue_limits() (max_queues = MAX_QUEUES = 58, max_in_flight_per_queue = FLIGHTS = 32) and return it from Gpu::queue_limits(), which enables DRM_ASAHI_FEATURE_INDEPENDENT_QUEUES and DRM_ASAHI_PARAM_GROUP_QUEUE_LIMITS in the shared frontend. - Track live logical queues per open DRM file in usage::Client via an RAII QueueCredit guard (ENOSPC at MAX_QUEUES), stored after Scheduler in Queue so capacity returns only after scheduler drain. Because G16 logical queues own no firmware execution contexts, keeping QueueCredit per-file while file.rs enforces per-process queue_share::Share bounds ensures a client that opens MAX_QUEUES queues cannot starve a later process (such as a compositor) from creating its own queue. - Extend test-publication.py and usage.rs unit tests to cover queue limits, INDEPENDENT_QUEUES, per-file QueueCredit isolation and release, and multi-queue compute+render concurrency on one VM. Signed-off-by: Diljit Singh <[email protected]>
When pipelining a healthy same-VM non-InitBM render behind an in-flight render (class_behind), prefix_render() encoded both prev_barrier (TA->TA under early tiling or TA->FS otherwise) and fs_dep (FS->FS under early tiling) with BarrierType::Hold (type 1), holding each consecutive TA/FS stage for the predecessor software-job teardown even though own_barrier on the same FS ring already uses BarrierType::Stamp (type 0). Use BarrierType::from_stamp_only(!init_buffer) for both same-class render->render barriers (prev_barrier and fs_dep), matching own_barrier and G15's proven RENDER_INTERNAL_HOLD = 0 policy while keeping cross-engine barriers (fs2c and c2ta) strictly BarrierType::Hold on G16's class-2 queues. G16 uses firmware-initiated phase recovery and never writes G15 kill controls, and any failed/suspect/cross-VM/InitBM transition still drains the engine first. Signed-off-by: Diljit Singh <[email protected]>
Wire the HAL200 compressed ZLS metadata registers (`fs::SEL[44..52]`) and the four `JobParameters3` partial-render mirrors (`0x958`, `0x970`, `0x988`, `0x9a0`) in `encode_fs_for()`, all of which lie inside the clean-reuse active work spans (`0..fs::HEAD_ACTIVE_SIZE` and `fs::TAIL_ACTIVE_START..fs::WORK_SIZE`). Widen `zls_ctrl` admission in `g16/command.rs` to admit the four load and store compression bits (`0x154`, mask `0x00000000060cc1fe`), enforce symmetric load/store compression bits per plane, remove the `EOPNOTSUPP` refusal on `comp_base`/`comp_stride`, and validate compressed metadata alignment, stride encoding, and read-write VM span coverage through the layer count via `SpanBatch`. Add host selftests covering 1x, 2x, and layered compressed depth/stencil admission, invalid control/alignment/span rejection, 25G83/26B123 FS encoding parity, and clean-reuse scrubbing of compressed ZLS fields. Signed-off-by: Diljit Singh <[email protected]>
Accept the 480-byte drm_asahi_cmd_render_m5 render payload when DRM_ASAHI_RENDER_STAGE_PREFIXES is set, decode the 32-byte drm_asahi_render_stage_prefixes tail with compile-time layout assertions, and record per-stage TA compute and render wait-through prefixes on Order via narrow_tiling() (refusing any TA wait later than the FS wait, nonzero reserved words, or combination with DRM_ASAHI_RENDER_FRAGMENT_BARRIERS). Add per-pass ta_fs_barrier and fs_compute_barrier objects to PassSlot, resolve independent TA and FS compute/render barrier stamps in prefix_render() via plan_render_barriers(), and advertise DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2 in G16 params so Mesa can emit independent TA and FS waits on G16G. Signed-off-by: Diljit Singh <[email protected]>
Multi-pass render frames (shadow maps, deferred G-buffer + lighting, post-processing, and Zink multi-pass submits) currently pay per-pass VM span coverage locks, per-pass VDM root reads, and per-pass TA/FS ring publications with individual SubmitRecords and UMA submitted counter updates. Batch validation and publication across consecutive render passes within a single SUBMIT without delaying fence completion for separate jobs: - Lift SpanBatch to Prepared::validate() so render passes within a SUBMIT deduplicate shared VM spans and flush coverage in one lock acquisition, and replace gate::vdm() with gate::vdm_batch() to verify all render VDM root words under a single Vm::read_lock() with a 256-byte intra-page read window. - Add ordered multi-pass slot tracking (Claims::pass_count), replace PoolSet::publish() with PoolSet::publish_batch() (submitted += 2 * renders), and add Job::can_fold_render_cmd() so consecutive ready non-InitBM render passes in one SUBMIT fold into a single Flight, one TA/FS producer advance, one SubmitRecord kick, and one UMA submitted update while preserving exact per-pass barriers (wait_stamp_for_with), recovery matching (r_ta_stamp/r_fs_stamp), per-pass scene ITS verification, and ordered pass-slot retirement. - Add host selftests covering batched VDM root admission, submit-wide span deduplication, ordered wrapped multi-pass retirement and publish_batch(), same-batch render wait stamps, can_fold_render_cmd, and interior render-stamp recovery preparation. Signed-off-by: Diljit Singh <[email protected]>
Cache::prepare() previously gated RenderExtArena allocation on compute's 2 ms BURST_GAP_NS and 3-command BURST_COMMANDS thresholds. Heavy multi-millisecond pipelined renders arrive more than 2 ms apart and would reset render_burst to 0 on every submit, staying capped at BASE_RENDER_SLOTS (2 slots), whereas simply widening the idle gap to cover 60/120 Hz frame periods would force every steady depth-1 compositor or window client to allocate 14 extension pass slots it never uses. Track live prepared render jobs per VM in Cache::active_renders (incremented on returning Prepared and decremented in Prepared::drop), keep the 2 ms BURST_GAP_NS for back-to-back single-pass bursts, and expand RenderExtArena when a render overlaps an active in-flight render (active_renders != 0), submits at least BASE_RENDER_SLOTS passes in one SUBMIT, or sustains a sub-2 ms burst. Add a host unit test covering steady 60/120 fps depth-1 non-expansion, multi-ms overlap, sub-2 ms bursts, and multi-pass submits. Signed-off-by: Diljit Singh <[email protected]>
… slot is quarantined Fresh user VMs start with only BASE_COMPUTE_UNITS (2) compute units and BASE_RENDER_SLOTS (2) render pass slots, allocating extension slots lazily on bursts, overlap, or multi-pass submits. After a hang recovery quarantines one base compute unit (0 or 1) while the other base unit is the newest-retired undisplaced owner, compute_exhausted_within(2) becomes true even though 14+ extension compute units remain healthy. Every subsequent fresh single-command compute client then submits with only 2 units, hits compute_exhausted_within(2) in engine publication, and fails immediately with ECANCELED without ever running on an extension unit to displace the surviving base unit. The same deadlock occurs for fresh single-pass render clients when a base pass slot is quarantined. Track base-slot quarantine state in Lifetime::any_quarantined_within(), publish lockless hints on Shared whenever Slots::quarantine() runs, and pass them via PrepareHints into Cache::prepare() so fresh VMs expand compute_ext / render_ext immediately once a base slot is quarantined. Add host unit tests covering both compute and render base-slot quarantine recovery and displacement. Signed-off-by: Diljit Singh <[email protected]>
…ender hangs Physical render PB/UMA allocators (hardware UMA slot 33) were previously capped at two fixed slots (parameter_id 0 and 1). Once both slots had been used across VMs (for example compositor plus benchmark), a single render hang on the active slot called pools.invalidate() and pools.quarantine_flight(), leaving the other slot undisplaced and immediately tripping Pools::exhausted() -> render_failed=1, degraded=1, and device wedged even with 14+ healthy render pass slots remaining. Expand the client-VA render allocator window to PB_SLOTS = 6 (parameter_id 0..6 in a 64 MiB stride across 0x7008000000..0x7020000000, disjoint from base compute units, render pass slots, dynamic PB page lists, and extension compute units). Keep non-fault VMs at BASE_PB_SLOTS = 2 with zero extra RAM overhead; lazily allocate per-slot PoolExtArena recovery allocators sharing the VM's existing PB heap only after a render hang quarantines an allocator slot, signaled locklessly via Shared::needed_pb_slots. Generalize Pools selection, displacement, and exhaustion checks to PB_SLOTS while preserving the two-slot working set in normal cross-VM switching and per-job limit checks (pick_slot_within / can_pipeline_within / exhausted_for_within) so pre-hang jobs cancel cleanly instead of spinning on EAGAIN. Add host unit tests covering the exact cross-VM single-render-hang recovery and survivor displacement path, multi-hang survival up to four quarantines, and clean exhaustion at the slot limit. Signed-off-by: Diljit Singh <[email protected]>
…dle power Address adversarial review findings and idle power regressions across the pipelined G16 submission stack: - Replace single-entry last_retired with a 64-entry per-stage RetiredStamps ring recording every retired compute/TA/FS member so late recovery snapshots after pipelined bursts still resolve safely. - Use Firmware::compute_ticks() in publish_timestamps() so 26B123 work_ticks fallback works for client timestamp queries as well as stats. - Retain base RenderArena alongside PoolExtArena in PbOwnerArena::Ext so shared PB heap mappings outlive Cache::close() until displacement. - Track queued drm_sched jobs via Scheduler::pending_sched counter instead of per-push Arc allocations or retaining Arc<Job>, ensuring VmJobGuard drops immediately on completion. - Remove dead recovering check under Shared::state in try_submit_inline() and ensure retire_oldest() forgets failed-stop flights on every early return. - Extract Shared::arm_idle_power_poll() across all three idle-exit paths, call power.report_work(false) on drain, and gate syncobj_wait_hint on a G17-style 8-submit burst streak with 8 ms auto-expiry. Signed-off-by: Diljit Singh <[email protected]>
87fdefd to
c2c0085
Compare
ba6a7be to
9f14889
Compare
Bring in integration/aurora through the updated base. The only conflict is the g16/params.rs module comment: it now lists VDM_USC_INVALIDATE from the shared file.rs together with the fragment-only render barriers and COMPUTE_NO_QUERY_ACCESS this series advertises. Signed-off-by: Diljit Singh <[email protected]>
Bring in main through the updated base. Conflicts: - g16/gate.rs, test-stream-gate.py: main lets a VDM root carry the USC cache invalidate (VDM_USC_INVALIDATE). vdm_batch(), which replaces vdm() here, now admits it too, and the root-barrier test checks both words through vdm_batch(). - usage.rs: Client keeps the logical queue credit next to main's NUM_ENGINES-sized engine ledger. - g16/params.rs: the module comment lists VDM_USC_INVALIDATE with the features this series advertises. Signed-off-by: Diljit Singh <[email protected]>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers:
Checked: this PR's own commits against its base; no Apple material in code or commit messages; no chip or board gates; no new parameters ( |
What: G16 (M4) submit, concurrency, DVFS and recovery work, stacked on #2741: inline retirement on submit, 16 render pass slots, concurrent compute and render flights with cross-engine barriers, CLPC idle hysteresis and a fast-ramp governor, drm_sched bypass for ready inline submits, independent queue limits, stamp-only barriers, compressed ZLS depth/stencil,
RENDER_STAGE_PREFIXES_V2, batched multi-pass renders, extension and recovery PB/UMA slots, and hardened recovery history and lifetimes.Tested: M4 Mac mini (J773g, G16G B0, 26B123) on earlier heads of this branch, not the current one: render-hang recovery runs, gpubench Wave-1 57/57, concurrent.sram 10/10 with exact CRCs. Host tests 25/25.
Risk: two-way · M4 (J773g, J713)
Not yet: a row at the current head (the branch was rebuilt after the rows above); CI, which runs once the base lands and this PR targets
main.Details (original description)
Summary
Seventeen-commit R2 (
5610a84b974e5) G16 (M4 / T8132,26B123firmware) GPU performance, concurrency, and hang-recovery series stacked cleanly on#2741(djdev/g16-perf-272-prat65a87c442d99), introducing zero module knobs or debugfs switches and addressing all 10 review items from@RyanTheTide(#issuecomment-7078017919):bbd2af5c36515Inline retirement & poll trim: retire completed flights inline on submit and trim poll-loop overhead (documents why 1 msSession::check()deferral is safe whilepublish_checked()keeps per-submitSession::transport()).042b94b1ea2fb16 render pass slots & clean-reuse work trims: expand render pass slots to 16 inside0x7020000000..0x7040000000(32 MiB stride = 28 MiB pass layout + 4 MiB guard) and trim clean-reuse WC writes.752c66d26f295Batched VM coverage checks: batch VM range checks and trim per-SUBMITCPU overhead.612dabbe9f4feConcurrent compute + render flights: allow concurrent same-VM compute and render flights with cross-engineHoldbarriers (walking all commands of multi-command flights), independent per-class progress/hang deadlines (deadline_nsvscompute_deadline_ns), and squashed alt-class drain-fairness guard (!needs_engine_drain(&job)) +EAGAINturn preservation so every commit bisects cleanly.1cad4da5fb6e7CLPC idle-hold hysteresis & fast-ramp DVFS governor:2 msCLPC_IDLE_HOLD_NS(half ofclpc.c's4 mssample cadence),5 msRAMP_WINDOW_NS(== SAMPLE_NS),>= 70% / >= 40%thresholds matchingdemand(), and clampedGovernor::demandunder thermal limits.7b54ab53b397bOff-lock slot pre-scrubbing: pre-scrub displaced render pass slots off-lock.6d376201cd880Ready inlinedrm_schedbypass & off-lock timeline signaling: bypassdrm_schedon ready inline submits and signal timeline fences off-lock.058731de1f0afIndependent queue limits: expose per-class queue limits with per-fileQueueCreditisolation inusage::Clientso one client cannot starve other processes.70756169505cdBarrier-free compute horizon batching: batch barrier-free compute horizons into one doorbell while tracking per-member completion stamps for cross-engine waits and recovery snapshots.70c082c6d03a7Inactive WC poll skip & submit allocation trims: skip inactive WC poll reads (hold[0]poll storm-93.2%) and trim submit allocations.379a034591e92Stamp-only barriers for pipelined same-VM renders: use stamp-only barriers for pipelined same-VM renders while keeping cross-engine barriersHold.469144bdac255Compressed ZLS depth/stencil support: enable compressed ZLS depth and stencil attachments.33a7c5223bd63DRM_ASAHI_RENDER_STAGE_PREFIXES_V2: support v2 render stage prefixes (feature bit 33).f5a4612e16f69Batched multi-pass render validation & publication: validate and publish multi-pass render batches together.c4e5905be6fc0Lazy render extension slots on overlap or burst: replace25 msburst gap withCache::active_rendersoverlap tracking +2 mssub-ms burst / multi-pass expansion so steady 60/120 Hz depth-1 clients stay on 2 base slots.ca433600f9e7bQuarantine-triggered extension expansion (live-caught fix): expand extension compute/render slots when a base slot is quarantined so fresh single-command clients do not deadlock onECANCELED.5610a84b974e5Lazy recovery PB/UMA allocator slots (PB_SLOTS = 6, live-caught fix): keep non-fault VMs atBASE_PB_SLOTS = 2(zero extra RAM) and lazily allocate per-slot recoveryPoolExtArenaallocators only after a render hang quarantines an allocator slot, preventing prematurerender_failed=1 / degraded=1 / device wedgedafter a single render hang.Verification
Host checks (
5610a84b974e5)scripts/checkpatch.pl --strict --ignore FILE_PATH_CHANGES:0 errors, 0 warnings, 0 checksacross all 17 commits.run-host-tests.py:25 / 25PASS (including new tests for per-class hang deadlines, multi-command cross-engine barriers, 60 Hz DVFS non-pumping & clamped cooling ceiling, per-fileQueueCredit, 60/120 Hz render non-expansion, base-slot quarantine expansion, and multi-hang PB/UMA recovery).0newrustcwarnings across the full kernel build.Live hardware (
Apple M4 (G16G B0),J773g,0x8132,26B123firmware)render.heavy d=4):recoveries 0 -> 1(526.9 ms), concurrent renderrc=0(33,622submits), immediate freshcompute.heavy d=1/compute.light d=1/render.heavy d=1allrc=0with0ECANCELED.compute.heavy d=4):recoveries 1 -> 2(113.6 ms), concurrent computerc=0(16,179submits),render_failed=0,degraded=0, no[drm] device wedged, immediate freshrender.heavy d=1+render.postfx(CRC=EXACT 668d6f0a) +compute.heavy d=1allrc=0.recoveries 2 -> 3(128.9 ms), concurrent computerc=0(16,170submits),render_failed=0,degraded=0,pb: bad 0, post-3-recoveryvk-mustpass-short87/87PASS,0kernelBUG/WARN/Oops.5610a84b974e5differs from the hardware-tested commitaf25205059308solely by adding#[allow(dead_code)]onPbOwnerArenainresources.rs:293-300, zero codegen change.)gpubenchWave-157/57 OK(0.8027×M4 Metal),concurrent.sram10/10 PASS(1.00–1.04×Metal,EXACTCRC),hold[0]poll-storm-93.2%.vk-mustpass-short87/87 PASS,dEQP-VK.draw.*indirect*3,710/0 PASS,gles-smoke3,086/0 PASS, real Deep Sleep S2R (apple-sleep: back from sleep, boot object resumes 0 -> 1) + post-wakevk-mustpass-short87/87 PASS.Stacked on
#2741(djdev/g16-perf-272-pr); will retarget ontointegration/auroraonce#2741lands.