Skip to content

drm/asahi: g16: cut the added latency of short and interleaved submits - #4034

Open
DjDeveloperr wants to merge 4 commits into
mainfrom
perf/g16-short-submit-latency
Open

DjDeveloperr wants to merge 4 commits into
mainfrom
perf/g16-short-submit-latency

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: Three small g16 scheduling fixes for short and mixed submits: don't run housekeeping in the middle of a single short job, don't hold back a submit to fold it when the queue alternates compute and render (it cannot fold), and run the submit worker at high priority, as g17 does.

Tested: No hardware run at the head of this PR; an earlier combined run is in Evidence. Local checks at 1408ae85c1c4: arm64 W=1 build of drivers/gpu/drm/asahi (clang) with the same warnings as main, run-host-tests.py --only asahi-m4 1/1 and --only g16 2/2, checkpatch --strict clean.

Risk: two-way · M4 (T8132) and M3 (T8122, T6030), which share the g16 backend

Not yet: J773g and J516s base/head ABBA at the head of this PR: sync.signal host d1, concurrent.cr interleave d4, compute.light and render.light d1 to d16, idle.wake, plus GPU clock and temperature limits under a long single job (housekeeping also runs the GPU power service) and one s2idle. No performance gain is claimed until that ABBA is in.

Details
  • On an idle-to-active submit, submit_locked() queued an immediate poll when housekeeping was due. The job was still running, so the poll retired nothing and ran housekeeping under Shared::state while the completion was arriving. The resnap timer and the 1-jiffy backup poll are already armed, so housekeeping now waits for them.
  • can_defer_busy_coalesce() holds a single-queue submit for up to 18 µs so the next one can fold into the same flight. When that queue also has work of the other engine in flight, the next submit alternates and cannot fold, so it is no longer held. The function already requires every active flight to belong to the same queue, so another process's work never turns folding off.
  • The ordered drm_sched submit workqueue becomes WQ_HIGHPRI, and it is pinned to the creating CPU's cluster only when that cluster has more than one CPU.
Evidence

Hardware, supporting only: J773g, gpubench 7a0dfcf8. Stock kernel efed1ae377ba on 12-01 (Mesa dfc5b9016749), against the 16-commit tree 53599499071a as a module on kernel 6c83a2a64539 on 12-02. These are different boots and base kernels, and the stack holds other changes, so this is not an A/B of this PR. All CRCs were valid.

row stock stack
sync.signal host d1, latency 172.2 µs 148.1 µs
concurrent.cr interleave d4 72.4 µs 62.6 µs

Host tests: the idle-to-active housekeeping rule and the idle delivery, the interleaved bypass in both directions, and Scheduler::new() on single-CPU and multi-CPU clusters.

Checks ran on main d1ae4f292b93 plus this branch.

…tion

On an idle-to-active submission (!had_flights with a flight published,
such as d=1 workloads and sync.signal host after its 200 us spin),
submit_locked() previously checked housekeeping_due against the 1 ms
HOUSEKEEPING_NS interval and immediately queued poll_now() onto the
submitting CPU. Because the new single flight is still executing on the
GPU, FAST_POLL_WORK immediately entered poll_step() without retiring
anything and ran run_housekeeping() (session.check(), objects.health(),
service_power(), auxiliary ring drains) under Shared::state right in
the middle of the flight, blocking the incoming EP 0x20 completion and
userspace wakeup.

Skip the eager housekeeping poll_now() kick when transitioning from
idle to active (!had_flights && !flights.is_empty()). submit_locked()
already arms the resnap hrtimer (default 100 us, tunable 25-1000 us)
and 1-jiffy backup poll, so short d=1 flights complete on EP 0x20 and
wake userspace via complete_all() before deferred housekeeping runs.
Long flights still service housekeeping on a later poll tick once the
5 ms ACTIVE_HOUSEKEEPING_NS deadline elapses (the first resnap tick can
precede that deadline), and active bursts (had_flights) keep the 5 ms
ACTIVE_HOUSEKEEPING_NS cadence unchanged.

Add a host selftest regression verifying both idle-to-active suppression
and idle no-flight housekeeping delivery.

Signed-off-by: DjDeveloperr <hey@djdev.me>
…eues

can_defer_busy_coalesce() holds a single-queue submission for up to
COALESCE_WINDOW_US (18 us) when the queue already has >= 2 commands of
that class in flight so consecutive same-class submits fold into one
multi-command flight. When the same queue already has active flights of
the other engine class (such as single-queue compute/render interleaving
in concurrent.cr interleave), the next submit alternates classes and
cannot fold, so holding for 18 us only stalls cross-engine overlap.

Bypass busy coalescing in can_defer_busy_coalesce() whenever the other
engine class is currently active in flights, and extend
test-publication.py to cover same-queue interleaved C+R bypass in both
directions.

Signed-off-by: DjDeveloperr <hey@djdev.me>
G16 logical queues currently allocate their ordered drm_sched submit
workqueue with OwnedQueue::new_ordered_reclaim() (normal nice-0 CFS
priority) and unconditionally restrict it to the creating CPU's cluster.
When a host-signalled or dependency-blocked submission wakes via
drm_sched_entity_wakeup() (such as sync.signal host after
DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL), the submit kworker competes at
normal CFS priority with busy application threads on the same cluster
before running SchedJob::run() and ringing the doorbell.

Switch Scheduler::new() to OwnedQueue::new_ordered_highpri_reclaim()
(WQ_MEM_RECLAIM | WQ_HIGHPRI) and restrict to the creating CPU's
cluster only when cluster.weight() > 1, matching g17/job.rs. Raising
worker priority reduces contention with normal-priority threads, though
scheduler latency remains possible. Add a host selftest regression
executing production Scheduler::new() for both multi-CPU and single-CPU
cluster topologies.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 01:49
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at e492e5d9: ready to merge

Check Detail
CI at head ok 9 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok comment at e492e5d9
Conflicts ok none
PR text ok Risk: two-way · M4 (T8132) and M3 (T8122, T6030), which share the g16 backend

Areas: area:gpu
Merge: gh pr merge 4034 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@github-actions github-actions Bot added the needs-hw-row No hardware row at the PR head (bot) label Dec 3, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1408ae8. The mixed-flight checks bypass a wait that cannot fold the head job. Idle-to-active submit keeps the completion and timer paths for housekeeping, and the high-priority worker retains cluster affinity where topology permits it. Hardware A/B is pending.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s (M3 Pro) g16batch row: FAIL (judge exit 1). Except for one CPU-time flag that looks like noise, every failure also happens on base.

For this PR: sync.signal latency -3.3 %, concurrent.cr -3.6 %, compute.light us_per_submit within 2.2 %, idle.wake within noise, s2idle 1/1. The long-job check can't run on the J516s (see below).

Kernel 7.3.0-g16batch, base c09b61228e62, batch tip 95212b64f7eb (#4032 #4033 #4034 #4035; #4056 #4057 in both arms). ABBA, one boot per slot, arm checked by the aurora.ko build id: a1 base d006ff51, b1 batch a9e3e314, b2 batch dd5516d2, a2 base 01025e37.

Same on both arms:

  • VK-CTS: command_buffers 60 pass / 0 fail, draw 4508 / 0, robustness 2183 / 0. 0 tests differ.
  • Stream gate: 6 bad root addresses, 0 accepted. +4, +2 and the kernel range get EINVAL, unmapped gets ENOENT (base does the same). The next clean run is valid.
  • Hang case 1 (9 clients + a hung render): bad 0, err 0 in all 6 rounds.
  • 48 clients open/close: 0 failed. pb kept 4-7 epochs, the same range on both arms. s2idle 1/1 on a1 and b1.

Why the judge says FAIL:

  • Long jobs: the first 2.5 s job ends in a GPU firmware recovery (fault_scan: GPU powered down, event 0x71) and a lost device. This happens in all four slots, on base and batch alike. The 1 recovery and 5 GPU kernel lines before the hang step come from this. The J516s can't judge the long-job check.
  • Hang case 2 (one client + a hung render): the other client gets a lost device in 2 of 3 rounds on batch, and in 2 of 3 on base. The batch doesn't make it worse, and it doesn't fix it on the J516s.
  • Speed: render.light d8 submit_cpu_us median went from 4.45 to 6.91 µs (+55 %). At d8, us_per_submit is +0.6 % and p95 is 17.8 / 17.2 µs. The other submit_cpu_us rows swing 30-40 % both ways (d32 -41 %, render.mdi +33 %), so this looks like noise. The slot pair was not re-run. gpu_us is within 0.6 % on every row. us_per_submit is within 2.6 %, except render.mdi d1 at +7.2 % (noise 13.5 %).

The J516s is back on its stock kernel (7.3.0-f3822, boot 98468598), and the kit is removed from it.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J516s render.light d8 recheck (batch merge tip 95212b64f7eb against base c09b61228e62, one boot each: base 70f9b303, batch 6a96f1dc, 5 repeats per core): pinned to a P-core, submit_cpu_us is 4.88 base and 4.88 batch; pinned to an E-core, 7.67 and 7.58; unpinned, 4.75 and 4.92 (+3.6 %); us_per_submit within 1 %; 0 new faults. The earlier +55 % (4.45 to 6.91 µs) is the submit thread landing on an E-core (E/P = 1.56x), not this change, so the d8 flag is cleared. Evidence work/g16batch-20261203/results/j516s/d8-recheck/.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Both J516s arms lost the device on the 2.5 s long job. The remaining row at 1408ae85c1c4 is J773g ABBA on sync.signal, concurrent.cr, compute.light, render.light and idle.wake, with a completed long job and its power, clock and temperature recorded. Follow it with a successful s2idle cycle and a checked GPU job.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Mac mini M4, T8132, G16G B0) g16batch ABBA hardware row — short-job ABBA + s2idle PASS; longjob INCOMPLETE (kit VERDICT FAIL from longjob timeout on all 4 slots)

Tested in g16batch-20261203 (SHA256SUMS 5d61509ed258dd96, kit.sh --check 30/30 ok, kernel 7.3.0-g16batch, ABBA slots a1/b1/b2/a2, base c09b61228e62 vs batch 95212b64f7eb including #4034 at exact head 1408ae85c1c4).

  • Short & interleaved ABBA timing (0 regressions across 82 rows):
    • idle.wake gap_ms=200 wake_latency_us: 465.01 -> 422.54 us (-9.1%, noise 1.0%, faster); gap_ms=2 -0.1%, gap_ms=20 +0.0%.
    • sync.signal host d1 latency_us: 253.33 -> 250.57 us (-1.1%, noise 0.1%).
    • concurrent.cr interleave: us_per_submit 62.47 -> 62.60 us (+0.2%), latency_us 242.74 -> 243.58 us (+0.3%).
    • compute.light d1..d16: us_per_submit -3.7% to +1.3%.
    • render.light tri d1..d64: us_per_submit -1.1% to +0.2%.
  • s2idle: S2IDLE success 0 -> 1 fail 0 and post-wake checked render PASS on both a1 (base) and b1 (batch).
  • Long jobs (g16pair long 2500 6) — INCOMPLETE: Hit VK_ERROR_DEVICE_LOST (rc=42, 0/6 long jobs completed, firmware recovery event=0x71/0x75) during initial g16pair calibration identically on all 4 slots (a1, b1, b2, a2) (ok=1, err=1, lost=1; power effective S10 on all 4 slots). That identical kit calibration timeout also accounted for the sole pre-hang recovery (recoveries 1, 5 GPU-side lines) on each slot.
  • Health: WARN=0, FAILED_UNITS=0, health: failed 0 errno 0 degraded 0 on all 4 slots; VK-CTS 0 diff / 0 new fails.

@github-actions github-actions Bot removed the ready-to-merge Meets the merge policy: merge it (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

The long-job failure in the g16batch row comes from the test, not the driver.

g16pair long 2500 6 made a single render longer and longer, aiming for 2.5 s. The GPU firmware's fragment-stage watchdog (recovery event 0x71/0x75) killed it well before that. It happened the same way on all 4 J773g slots (device lost 0.68-0.70 s after the step started) and all 4 J516s slots (0.46 s), base c09b61228e62 included. The kernel's own 5 s deadline never came into it, and the 100000-iteration render just before completed with a correct image on all 8 slots. So the step says nothing about this PR, and the one recovery each slot shows before the hang step is this kill.

New kit: work/j773g-g16-4034-longjob-20261203/ (SHA256SUMS b1d2d8b4f970). On 7.3.0-g16batch it runs base and batch ABBA. Each slot runs 100000-iteration renders (the size that passed everywhere) one at a time for 20 s. It checks job times, time in S10, that utilization and temperature keep updating during the jobs, and that no recovery or GPU kernel line appears. Housekeeping runs every 5 ms during a job, so every job spans many power-service passes, which is the path this PR changes. The offline check is 15/15. It hasn't run on a Mac yet. M4 can run ./kit.sh row <slot> inside the #4032 proof kit's boots.

@github-actions github-actions Bot added the ready-to-merge Meets the merge policy: merge it (bot) label Dec 3, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Hardware row at head 1408ae85c1c4 (tested in g16batch merge 95212b64f7eb = base c09b61228e62 + #4032 a4e1852dc19d + #4033 0fe0c64f5da5 + #4034 1408ae85c1c4 + #4035 00f3d43b9640) on J773g (M4 mini, G16G B0, 27.2): PASS.

Kit: work/j773g-g16-4034-longjob-20261203 (--check 23/23 ok), kernel 7.3.0-g16batch, aurora-base.ko (1f43c0ef3f95) vs aurora-batch.ko (6e2cd6dbc069).
Receipt: work/j773g-g16-4034-longjob-20261203/results/j773g/{a1,b1,b2,a2,verdict.txt}.

Boots:

  • a1 (base, 1f43c0ef3f95): boot_id=2d4769f8-4a5c-452a-998d-0ddfb21efdb0 — 247 jobs, ok=247 bad=0 err=0 lost=0, recoveries 0 -> 0
  • b1 (batch, 6e2cd6dbc069): boot_id=048b8963-f31c-448d-a391-02e1379635b8 — 247 jobs, ok=247 bad=0 err=0 lost=0, recoveries 0 -> 0
  • b2 (batch, 6e2cd6dbc069): boot_id=c9c5bcf4-c901-4dd6-a518-b669cf529c22 — 247 jobs, ok=247 bad=0 err=0 lost=0, recoveries 0 -> 0
  • a2 (base, 1f43c0ef3f95): boot_id=be754dc9-7809-458a-ab8c-032c01743b97 — 247 jobs, ok=247 bad=0 err=0 lost=0, recoveries 0 -> 0
slot  arm     jobs  median ms   p95 ms  samples  top % states            util  T start  T max
a1    base     247      80.59    81.90      200  100.0 S10                 97    44.50  53.50
b1    batch    247      80.58    81.87      200  100.0 S10                 97    46.00  55.00
b2    batch    247      80.58    81.88      200  100.0 S10                 97    46.00  54.75
a2    base     247      80.58    81.65      200  100.0 S10                 97    46.00  55.00
job median: base 80.59 ms, batch 80.58 ms, delta -0.0 % (limit 5.0 %, A/A B/B spread 0.0 %)
time in S10 during the jobs: base 100.0 %, batch 100.0 % (limit 10.0 points)
max temperature: base 55.00 C, batch 55.00 C
VERDICT PASS

Bring the branch up to main c042c5f. The merge is clean, and
nothing main changed in g16 since d1ae4f2 (#4198, #4240 and
others) touches the code this branch changes, so nothing was dropped
or adjusted.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Dec 4, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Mac mini M4, 27.2) row at head e492e5d: FAIL, so not for merge as is.
Same kit and run (b1, b2 against a1, a2 in ABBA order).

  • idle.wake d1 (20 ms gaps), wake latency: main 191.1/191.6 us, this PR 204.6/210.2 us. That is 8.4 % worse; the tolerance is 5 % and the spreads are 0.3 % / 2.7 %. The p5 moves from 174 to 196-206 us.
  • The same rows without a gap match main (awake latency 193.8/192.6 vs 193.9/200.2). So the ~10 us cost is on the first submit after idle, the idle-to-active path that "defer idle-to-active housekeeping until flight completion" changes.
  • Also: compute.light d16 is +4.6 % (within tolerance, but both PR boots are slower).
  • Within tolerance: compute.light d1, concurrent.cr interleave d4, render.light d1/d16, long job (80.55 ms on both).
  • sync.signal host d1 is too noisy on this kernel to judge (main 256/173).
  • Functional: long job, hang rounds and fresh render passed, no WARN.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-hw-row No hardware row at the PR head (bot) labels Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants