Repository navigation
Conversation
On G18G application compute dispatches, prepare_application_compute() currently does three expensive operations on every submission: 1. Exact-plan shared compute pool replacement: any difference between the incoming shader's G18ComputePlan and the retained pool triggers a full pool replacement and firmware descriptor switch. Multi-kernel compute workloads (such as LLM inference where shaders alternate between 3-block and 4-block plans) thrash between pool sizes on almost every dispatch, generating 1,100+ pool reallocations per short decode run. 2. Per-job UAT pool alias teardown and remapping: job.aliases is cleared and every directory page, block list, and scratch block (~526 UAT page entries) is unmapped, remapped, and translation-walked on every dispatch even when the client VM and pool are unchanged. 3. Per-job driver_preempt GEM alloc/map/free: the 48 KiB process-VM preemption object at 0x11_0000_0000 is destroyed and reallocated with page-table walks on every dispatch. Add G18ComputePlan::covers() and G18ComputePlan::union() to size the shared compute pool monotonically as a high-water mark that never shrinks, recomputing chunks_per_usc/bytes/block_count so the backing covers the combined chunk_counters[1] + sma_units + header (falling back cleanly to the incoming plan if a union would exceed G18_COMPUTE_MAX_BYTES). Retain the job's UAT pool aliases and driver_preempt mapping across retired submissions when the client VM id, pool binding generation, preempt mode, and driver_preempt geometry all match, re-zeroing the preemption buffer in place before reuse. Add the 0644 module parameter g18_app_fastpath (default 1; 0 restores exact-plan pool replacement and per-job remap; other values refuse the submission), read once per submission in ApplicationComputeKnobs. Bypass the fastpath during g18_app_prepare_test and g18_app_pool_test E2E diagnostics, and invalidate cached aliases/driver_preempt on VM switch, pool replacement, mode change, fastpath=0, preparation error rollback, recovery, and quarantine. Measured same-boot A/B on J873g M6 Mac mini (G18G B1, Vulkan via Borealis, Qwen2.5-3B Q4_K_M, g18_app_fastpath=0 vs 1): - Pool reallocations (G18_APP_COMPUTE_POOL_PENDING): 1,104 -> 1 - Host submit prep (G18_JOB_PHASES): 3-8 us - pp128: 64.60 -> 92.27 t/s (+43%) - pp512: 192.57 -> 243.13 t/s (+26%) - tg: 1.30 -> 2.38 t/s (+83%) - Coherent output, 0 faults across 300k+ compute submits and 5-min soak. Signed-off-by: Kevin loo <kevin@loo.ski>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
One change before merge. drivers/gpu/drm/asahi/g18/initdata/application_compute.rs adds the g18_app_fastpath module knob. New code has to choose its behaviour itself, with no runtime switch. Please make the monotonic pool and the cached aliases the only path (keep the bypass for the diagnostic and pool-test modes), drop the knob, and keep the 0/1 switch in your A/B kit.
I checked covers() and union(), and the cache clearing on error, recovery and quarantine, and found nothing else. pair still comes from the command's own plan, so a larger pool does not trip the descriptor check.
After that, merging needs a J873g boot and compute row at the new head. The numbers in the description come from the earlier equivalent patch, as the Not yet line says.
What: Eliminate per-dispatch shared compute pool thrashing, UAT pool alias remapping (~526 pages/job), and 48 KiB
driver_preemptGEM alloc/free churn on G18G application compute by sizing the compute pool monotonically (G18ComputePlan::covers()/union()) and caching same-VM UAT aliases plus re-zeroeddriver_preemptacross retired submissions (g18_app_fastpath, default1).Tested: At
e7fe3d54c(rebased ontob3a5fda63): ARM64 Linux kernel build (make ARCH=arm64 LLVM=-22 W=1 drivers/gpu/drm/asahi/aurora.o,CONFIG_DRM_ASAHI_G18=y,rustc 1.85.0) succeeded with 0 warnings in modified files; host teststools/asahi/g18-client-handoff-tests.py --mutations(12/12 mutants killed) andtools/asahi/g18-job-error-tests.py --mutations(10/10 mutants killed) passed; standalone unit tests forG18ComputePlan::covers()/union()passed (3/3). Equivalent fastpath implementation hardware-qualified via same-boot A/B (g18_app_fastpath=0vs1) on J873g M6 Mac mini (Mac18,5,apple,t8152,G18G B1, Borealis Vulkan): pool reallocations (G18_APP_COMPUTE_POOL_PENDING) dropped1,104 -> 1, host submit prep (G18_JOB_PHASES)3-8 us,Qwen2.5-3B Q4_K_Mpp12864.60 -> 92.27 t/s(+43%),pp512192.57 -> 243.13 t/s(+26%),tg1.30 -> 2.38 t/s(+83%), coherent output, 0 faults across 300k+ compute submits and a 5-minute soak.Risk: two-way door · M6 (T8152 / G18G) application compute path only; non-G18 Macs and G18 graphics/render paths are untouched,
g18_app_fastpath=0restores exact-plan pool replacement and per-job remap at runtime, andg18_app_prepare_test/g18_app_pool_testE2E modes bypass the fastpath.Not yet: Live boot on J873g M6 at the exact rebased head
e7fe3d54c(which adds single-readApplicationComputeKnobssnapshotting,union()chunk-capacity recomputation, and error-rollback/recovery cache clearing on top of the hardware-tested Stage 2 patch), and testing on J804 M6 MacBook Pro.Details
Root Cause
On G18G application compute dispatches,
prepare_application_compute()currently performs three expensive operations on every submission:job.pool.shared_compute_plan() != Some(plan)triggers a full replacement pool allocation and firmware descriptor switch whenever consecutive dispatches differ inG18ComputePlan. Multi-kernel compute workloads (such as LLM inference where shaders alternate between 3-block and 4-block scratch plans) thrash between pool sizes on nearly every dispatch (1,104pool reallocations in a short decode run).job.aliases.clear()unmaps every directory anchor/tail page, block list, and scratch block (~526 UAT entries), thenpool.compute_application_aliases()remaps and translation-walks all of them on every dispatch even when the client VM and pool are unchanged.driver_preemptGEM churn:job.driver_preempt = Nonefrees the 48 KiB process-VM preemption object at0x11_0000_0000, andMappedObject::new_wc_in_range_with_guards()allocates, zeroes, maps, and translation-walks a fresh GEM object on every dispatch.Changes & Safety Invariants
drivers/gpu/drm/asahi/g18/uapi/compute_plan.rs):G18ComputePlan::covers(&self, other)checks every backing, launch-pair, chunk-counter, per-USC chunk, andsma_unitsdimension.G18ComputePlan::union(&self, other)takes the component-wise maximum acrossideal,minimum, andsma_unitsand recomputeschunks_per_usc/bytes/block_countso backing capacity always covers the combinedchunk_counters[1] + sma_units + header(returningNoneand falling back cleanly tootherif a union would exceedG18_COMPUTE_MAX_BYTES). The pool never shrinks underg18_app_fastpath=1.d550/d558register pair andsma_units) still come from the incoming command's own descriptor and remain bounds-checked against the retained pool.driver_preempt(drivers/gpu/drm/asahi/g18/initdata/application_compute.rs):knobs.fastpath_active,fail_checkpoint == 0,replacement.is_none(),job.successful_retirement,job.aliases_vm_id == Some(vm.id())(device-monotonic 64-bit VM ID),job.aliases_pool_gen == binding.generation,job.aliases_preempt_mode == knobs.preempt_mode,!job.aliases.is_empty(), and forpreempt_mode == 1exact livedriver_preemptgeometry (dp.iova() == driver && dp.logical_size == driver_bytes as usize).KernelMappingnodes (refused to userspaceVM_BINDviaensure_unmapped/kernel_range()), matching howApplicationJobretains render aliases across frames for the same VM.job.preempt(mode 0) orjob.driver_preempt(mode 1) is zeroed in place viawith_bytes_mutprior toself.compute.prepare()(fence(Ordering::SeqCst)) and doorbell publication.preempt_modeswitch,g18_app_fastpath=0,g18_app_prepare_test, org18_app_pool_testdropsjob.aliasesandjob.driver_preemptbefore callingpool.compute_application_aliases()(preserving cross-VM scratch zeroing inclear_scratch_for()and theretired < dropped < aliasedinvariant). Failed preparation attempts also clear cached aliases while the local VM guard is held soapplication_compute_unpublished()stays true forJobFailure::Refused. Recovery (retire_recovered_application_compute) clears aliases/preempt and cache identity before dropping the VM guard; quarantine (quarantine_application_compute) invalidates cache identity while keeping stranded owners retained.g18_app_fastpath,0644, default1):app_knob!convention inapplication_compute.rs: read once per submission inApplicationComputeKnobs::read()(no mid-submit TOCTOU), rejects values> 1withG18_APP_COMPUTE_REFUSED/-EINVAL, logged inG18_APP_COMPUTE_KNOBS, and bypassed duringg18_app_prepare_test/g18_app_pool_testE2E diagnostics.boot/recovery.rs,boot/session.rs,initdata/mod.rs,params.rs); zero file overlap.Evidence
Same-boot M6 hardware A/B (
J873g/Mac18,5/G18G B1, Borealis Vulkan,Qwen2.5-3B Q4_K_M)g18_app_fastpath=0g18_app_fastpath=1G18_APP_COMPUTE_POOL_PENDING)G18_JOB_PHASES)pp128throughputpp512throughputtgthroughput"The capital of France is Paris."), 0 faults (300k+ submits, 5-min soak)Build & host tests at
e7fe3d54c