Skip to content

drm/asahi: g15: keep short-prefix VMs ahead while a flight has room - #2756

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
perf/g15-same-vm-affinity
Nov 22, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
perf/g15-same-vm-affinity

Conversation

@malik-na

@malik-na malik-na commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

With two or more GPU clients, G15 never uses its second flight. publish() (g15/engine.rs) posts a prefix behind a running one only if it is of the same VM, and pick() serves the least recently served queue first, so consecutive prefixes alternate VMs. Each prefix of the other VM then waits for the flights to drain and for the host to see the retirement before it is published. On a J516C on integration/aurora, two vkmark clients get 1143 fps together where one alone gets 2099.

This change keeps the tail's VM ahead while a flight has room, within bounds:

  • Engine::pick_affine(): when the round-robin pick is another VM's job and the flights can still take a prefix, publish the best ready job of the tail's VM instead (same order as pick(), at the round-robin pick's priority or higher).
  • A run stops after AFFINITY_RUN = 8 prefixes or AFFINITY_NS = 2 ms from its first pick, so the other client's queue is served next. Another client waits at most AFFINITY_NS plus one prefix beyond the drain it already waited for.
  • It applies only while the tail VM's prefixes average under 2 ms from publication to retirement (VmState::prefix_ns, a 1/4-weight moving average updated in stat_retire()).
  • Only the order among independent queues changes. Each queue's jobs stay in submission order (EXACT_PRIOR ordinals and barriers unaffected), and priority still outranks.
  • aurora-g15/stats counts these picks as affine N on the gaps … line.

3 files, +89/−6: g15/engine.rs, g15/poll.rs, g15/vm.rs.

Results: MacBook Pro 16" M3 Max (J516C, T6031, G15C 40 cores)

integration/aurora ffe545f (the PR base plus 28 commits, none in drivers/gpu/drm/asahi), booted normally on the default command line with the driver loading by itself and Hyprland running. Stock and patched differ only in aurora.ko (same kernel image, each in its own initramfs/UKI, one boot each). vkmark shading=phong, duration=8, total fps of all clients, mean of 3:

Size Clients Stock Patched Δ
3456x2234 1 2099 2088 −1%
3456x2234 2 1143 1826 +60%
3456x2234 3 1100 1792 +63%
800x600 1 3186 3240 +2%
800x600 2 2450 3414 +39%
800x600 3 2078 3386 +63%

Clients stay evenly matched (e.g. 911 / 916 fps).

Heavy + light at the same time (effect2d:kernel=blur at 8192x8192, beside phong at 800x600), same boots: heavy 129 → 136 fps, light 150 → 158 fps.

Compositor: Hyprland at 3456x2234@120 Hz, a vsync'd (fifo) 1280x800 vkmark window plus headless clients. Present intervals from the DCP swap counter (/sys/kernel/debug/dcp-j516c, polled every 0.5 ms), mean of 3:

Load beside the window Stock fps Patched fps Stock / patched p50 interval
none 120 120 8.33 / 8.33 ms
2 × phong 800x600 120 120 8.33 / 8.33 ms, 0 intervals > 12.5 ms
blur 8192x8192 41 58 24.4 / 16.7 ms

Why 8 prefixes and 2 ms

  • Drain cost: about 0.4 ms per switch. With two 3456x2234 clients on stock, nearly every prefix drains, and one is published every 0.87 ms; one client alone gets one every 0.48 ms with two flights. The idle gaps themselves are only ~9 µs; the loss is the pipelining.
  • Gate: light clients' prefixes average 0.85–0.95 ms from publication to retirement; the 8K blur's average 3.9–5.0 ms. 2 ms keeps the first ahead and leaves the second on the alternation, with about 2x margin each way, and is a quarter of a 120 Hz frame.
  • Sweep (one boot per variant, mean of 3, two clients, total fps):
Variant 3456x2234 800x600 Heavy / light
4 prefixes, 2 ms 1805 3379 136 / 158
8 prefixes, 2 ms (this PR) 1826 3414 136 / 158
16 prefixes, 2 ms 1840 3463 136 / 158
8 prefixes, 1 ms 1524 3444 136 / 158
8 prefixes, 4 ms 1948 3394 136 / 156

16 prefixes gains 1% for twice the run. 1 ms closes the gate for full-size prefixes. 4 ms gains 6% at 3456x2234 and kept the compositor beside the blur at 57 fps, but it doubles how long another client can be held and admits the blur's prefixes. The 4 ms 800x600 figure is from the full run; its sweep-only boot read 3681, which didn't reproduce.

Conformance and regression (same boots)

  • deqp-vk (VK-GL-CTS vulkan-cts-1.4.7.1), stock and patched identical: dEQP-VK.api.smoke.* 8/8, dEQP-VK.synchronization.basic.* 24 pass / 5 not supported, dEQP-VK.compute.pipeline.basic.* 79 pass / 2 not supported, dEQP-VK.draw.renderpass.simple_draw.* 4/4. 0 failures.
  • 0 failed units, 0 GPU errors, 0 new kernel errors during the runs. Both boots log the same pre-existing errors (Bluetooth Failed to read codec capabilities, cpufreq Cannot enable BOOST). SELinux is not enabled on this install (Arch).
Setup
  • Kernel: integration/aurora ffe545f + this commit, built on the machine with clang/LLD 23.1.3 from the running kernel's config with debug info off (disk space), 7.3.0-g15ab+. Booted as a Limine one-shot entry, so any reset returns to the default entry.
  • Userspace: Omarchy with mesa-aurora/vulkan-aurora d4ad4a4dce6 from aurora-silicon/alarm-aurora testing-20261121.4 (the Oct 31 Omarchy build doesn't accept the aurora DRM name, so Vulkan and Hyprland don't start on integration/aurora with it).
  • Firmware: OS firmware 14.7 (GPU "macOS 14.7 stub firmware"), J516C.

Not tested

Related

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, this is a clear write-up and a big win on the two-client case. I read it against pick() and publish() at 9ce9dd0.

What holds:

  • pick_affine() keeps the same tie-break as pick() (priority, then least-recently-served turn, then the first in pending), and only looks at the tail VM's jobs at the round-robin pick's priority or better. Jobs of one queue stay in submission order, and nothing can jump ahead of a higher-priority job.
  • The run is bounded: once AFFINITY_RUN or AFFINITY_NS is reached pick_affine() returns None, the other VM's job waits for the drain as before, and affinity_run resets when it is published on an idle engine. So the other client's extra wait is bounded by the run plus one drain.
  • prefix_ns is measured from publication to retirement, so prefixes posted behind others read longer and the gate tightens by itself under contention. That is the right direction.

What it needs before merge:

  1. A run on this tree. The numbers come from a 7.2.11 package kernel with the module loaded by insmod under modprobe.blacklist=asahi. Please repeat the two-client and heavy+light rows on integration/aurora with this PR, booted normally (default command line, the driver loading on its own), and the heavy+light pair under the same conditions for stock and patched (the stock row had Hyprland running, the patched row didn't).
  2. Where 8 prefixes and 2 ms come from. Both bound how long another client can be kept waiting, so they are fairness limits, not just tuning. Either show a small sweep (for example 4/8/16 and 1/2/4 ms on the two-client and heavy+light rows) that picks them, or tie them to something measured, such as the drain cost you are avoiding. The commit message should say which.
  3. One compositor row: a desktop with a GPU client running, showing the compositor's frame times don't get worse (the case the 2 ms gate is there to protect).
  4. Other G15 parts: the M3 (T8122) Air shares this engine code; a two-client vkmark A/B there would show the gain isn't specific to the 40-core part. Vulkan CTS isn't needed for a scheduling-order change, but a short deqp-vk smoke run with 0 new failures would be good.

Attribution: the commit carries Co-Authored-By: Claude ... and the description ends with "Generated with Claude Code". This tree keeps commits to human sign-offs only and puts tool use as the last line of the PR description, as Assisted-by: LLM (Claude:Opus 5.5) (see https://github.com/aurora-silicon/agent-guidelines). Please drop the trailer the next time you push the commit, and change the last line of the description.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr 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.

Adversarial review at live head 6f93a3b3ec74dad6c9de32481ce665d42a4d2137: 0 functional code bugs, 0 §1/§3/§4/§6 blockers, and host-tests CI is green, but requesting changes for §2 checklist blockers and incomplete §5 performance/hardware evidence.

Technical check (code is sound)

  • Scheduling & ordering (g15/engine.rs:514-547, 629-670): pick_affine() preserves priority ordering (job.queue.priority > priority skips strictly lower-priority jobs, so a lower-priority tail VM cannot preempt a higher-priority queue) and per-queue submission order (strict t < bt tie-break keeps the oldest pending job of a queue first). When flights drains (!behind), affinity_run resets cleanly and multi-VM round-robin handoff stays symmetric across 2+ VMs.
  • Prefix EWMA (g15/poll.rs:537-542, g15/vm.rs:192): stat_retire() only updates VmState::prefix_ns on result.is_ok() retirements, uses overflow/underflow-safe old - old / 4 + d / 4, and measures publication-to-retirement latency so queuing behind an in-flight prefix naturally tightens the gate under contention.
  • Attribution (§4): Clean on 6f93a3b3 — human author/committer and human Signed-off-by only; PR body ends with Assisted-by:.

Blockers before APPROVE

  1. §2 Default command line & target tree (hard rule): All hardware numbers come from an older 7.2.11-14-1-ARCH package kernel booted with modprobe.blacklist=asahi and a manually insmod-loaded module; the PR has not been run on integration/aurora (7.3) or on the default kernel command line. Please re-prove on integration/aurora booted normally with the default command line.
  2. §2 Unjustified fairness constants (hard rule — no magic delay/depth): AFFINITY_RUN = 8 and AFFINITY_NS = 2_000_000 (2 ms) are hardcoded fairness limits with no derivation or sweep in the commit message or PR body. Please either show a small sensitivity sweep (e.g. 4/8/16 prefixes and 1/2/4 ms across the two-client and heavy+light workloads) or tie them to a measured quantity such as cross-VM drain latency, and record the basis in the commit message.
  3. §5 Performance A/B & evidence gaps:
    • Re-run the heavy+light A/B under identical conditions for stock and patched (currently stock ran with Hyprland active while patched ran headless in a blacklist boot).
    • Add a conformance check (deqp-vk smoke / Vulkan CTS) confirming 0 new failures (currently under "Not tested").
    • Add a compositor frame-time measurement under concurrent GPU load to verify the 2 ms gate protects desktop responsiveness.
    • Include the §5 boot regression check (0 SELinux denials, 0 failed units, 0 new kernel errors) on the normal integration/aurora boot.
    • Ask for (or include) a two-client A/B on another G15 SoC (e.g. M3 T8122 Air or T6030/T6034) since this engine code applies across G15.

Assisted-by: LLM (Gemini 4 Neon)

publish() posts a second prefix behind a running one only if it belongs
to the same VM, and pick() serves the least recently served queue first.
With two or more GPU clients the two rules alternate the VMs on every
prefix: each prefix of another VM waits for the flights to drain and for
the host to see the retirement before it is published, so the second
flight is never used. On a J516C (T6031) two vkmark clients get 1143 fps
together where one alone gets 2099.

When the round-robin pick is another VM's job and a flight can still
take a prefix behind the tail, pick_affine() publishes the best ready
job of the tail's VM instead, at the round-robin pick's priority or
higher. It stops after AFFINITY_RUN (8) prefixes or AFFINITY_NS (2 ms)
from the first of a run, and applies only while the tail VM's prefixes
average under AFFINITY_NS from publication to retirement
(VmState::prefix_ns, a moving average updated in stat_retire()). Only
the order among independent queues changes; each queue's jobs stay in
submission order, and priority still wins. aurora-g15/stats counts these
picks as "affine".

Both limits bound how long another client waits: at most AFFINITY_NS
plus one prefix beyond the drain it already waited for. They come from
measurements on the J516C (aurora-g15/stats, vkmark):

- The drain costs about 0.4 ms per switch: two 3456x2234 clients
  publish a prefix every 0.87 ms when each waits for the drain, one
  client every 0.48 ms with two flights.
- Light clients' prefixes average 0.85-0.95 ms from publication to
  retirement, an 8192x8192 blur's 3.9-5.0 ms. 2 ms keeps the first
  ahead and the second on the alternation, with about 2x margin each
  way, and is a quarter of a 120 Hz frame.
- A sweep, two clients, total fps (3456x2234 / 800x600): 4 prefixes
  1805 / 3379, 8 1826 / 3414, 16 1840 / 3463; 1 ms 1524 / 3444,
  2 ms 1826 / 3414, 4 ms 1948 / 3394. Heavy+light is 136-137 / 158-160
  fps in every case. 16 prefixes gains 1% for twice the run; 1 ms
  closes the gate for full-size prefixes; 4 ms gains 6% at 3456x2234
  but doubles the other client's wait and admits the blur's prefixes.

integration/aurora, J516C, booted normally (Hyprland running), vkmark
shading=phong, total fps of all clients, mean of 3:

  3456x2234  1 client   2099 -> 2088
             2 clients  1143 -> 1826  (+60%)
             3 clients  1100 -> 1792  (+63%)
  800x600    1 client   3186 -> 3240
             2 clients  2450 -> 3414  (+39%)
             3 clients  2078 -> 3386  (+63%)

An 8192x8192 blur beside an 800x600 client: heavy 129 -> 136 fps,
light 150 -> 158 fps. Hyprland at 120 Hz with a vsync'd window: 120 fps
before and after beside two light clients, 41 -> 57 fps beside the blur.

Signed-off-by: Naeem Malik <[email protected]>
@malik-na
malik-na force-pushed the perf/g15-same-vm-affinity branch from 6f93a3b to 1d39569 Compare November 22, 2026 08:02
@malik-na

Copy link
Copy Markdown
Member Author

Thanks @RyanTheTide and @DjDeveloperr. Pushed 1d395693: the code is unchanged from 9ce9dd07, and the commit message now has the integration/aurora numbers and the basis for both limits. The PR description has the full tables.

1. Run on this tree, booted normally. integration/aurora ffe545f (the base plus 28 commits, none in drivers/gpu/drm/asahi) on the J516C, default command line, the driver loading by itself, Hyprland running. Stock and patched differ only in aurora.ko, one boot each, same conditions. Two clients at 3456x2234: 1143 → 1826 fps (+60%). Three: 1100 → 1792 (+63%). At 800x600, +39% / +63%. Heavy+light under the same conditions for both: heavy 129 → 136, light 150 → 158.

The installed Omarchy Mesa (Oct 31) doesn't accept the aurora DRM name, so on this tree Vulkan and Hyprland failed to start until I installed mesa-aurora/vulkan-aurora d4ad4a4dce6 from alarm-aurora testing-20261121.4. Stock and patched both ran on that Mesa.

2. 8 prefixes and 2 ms. Both are tied to measurements, and a sweep picked them (one boot per variant, two clients, total fps at 3456x2234 / 800x600):

3456x2234 800x600
4 prefixes 1805 3379
8 prefixes, 2 ms 1826 3414
16 prefixes 1840 3463
1 ms 1524 3444
4 ms 1948 3394

Heavy+light is 136 / 156–158 in every variant.

  • Drain cost: about 0.4 ms per switch. On stock, two full-size clients publish a prefix every 0.87 ms when each waits for the drain; one client publishes every 0.48 ms with two flights. The idle gaps themselves are only about 9 µs; the loss is the pipelining.
  • Gate: the light clients' prefixes average 0.85–0.95 ms from publication to retirement, the 8K blur's 3.9–5.0 ms. 2 ms sits between them with about 2x margin each way, and is a quarter of a 120 Hz frame.
  • Sweep: 1 ms closes the gate for full-size prefixes. 16 prefixes buys 1% for twice the run.
  • 4 ms is the trade-off to weigh: it gives +6% at 3456x2234 and the compositor beside the blur was the same (57 fps). But it doubles how long another client can be held, to half a 120 Hz frame, and admits the blur's prefixes. I kept 2 ms; happy to change it if you'd rather have the throughput.

3. Compositor. Hyprland at 120 Hz, a vsync'd window plus headless clients. I measured present intervals from the DCP swap counter (/sys/kernel/debug/dcp-j516c, polled every 0.5 ms):

  • Beside two light clients: 120 fps before and after, p50 8.33 ms, no interval over 12.5 ms. The headless clients themselves went from 749 to about 1235 fps each.
  • Beside the 8K blur: 41 → 58 fps (p50 24.4 → 16.7 ms).

4. Other parts, conformance, regression.

  • deqp-vk (vulkan-cts-1.4.7.1): stock and patched identical, 0 failures:
    • api.smoke.*: 8/8
    • synchronization.basic.*: 24 pass, 5 not supported
    • compute.pipeline.basic.*: 79 pass, 2 not supported
    • draw.renderpass.simple_draw.*: 4/4
  • Regression: 0 failed units, 0 GPU errors and 0 new kernel errors during the runs. Both boots log the same pre-existing Bluetooth and cpufreq-boost errors. SELinux isn't enabled on this install.
  • Not done: an A/B on another G15 part. I only have the J516C; if anyone has an M3 Air (T8122), T6030 or T6034, a two-client vkmark run of stock vs this commit would close it.

Attribution: the trailer is gone from the commit, and the description ends with the Assisted-by: line.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr DjDeveloperr 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.

Re-review against pre-pr-checklist.md (§1–§6) at verified live head 1d39569326220cbfa3ef7069f09061181a47c197: APPROVE (0 blockers, CI host-tests: pass, mergeable/clean).

Prior blockers — all resolved

  1. §2 Default command line & target tree: Re-proved on integration/aurora (ffe545f, base + 28 non-asahi commits) on J516C (M3 Max, T6031, G15C), booted normally on the default command line with the driver loading on its own and Hyprland running; stock vs patched differ only in aurora.ko under identical conditions.
  2. §2 Fairness constants (AFFINITY_RUN = 8, AFFINITY_NS = 2 ms): Well-grounded by both cross-VM drain measurements (~0.4 ms/switch; light prefixes 0.85–0.95 ms vs 8K blur 3.9–5.0 ms) and the full 4/8/16 prefix and 1/2/4 ms sensitivity sweep across 3456x2234, 800x600, heavy+light, and compositor, recorded in both the commit message and PR body. No module parameters or switches added.
  3. §4 Attribution: Clean — commit 1d395693 carries human author/committer (Naeem Malik) and human Signed-off-by: only, and the PR body ends with Assisted-by:.
  4. §5 Evidence (complete for G15):
    • Same-machine J516C A/B: 2-client 3456x2234 1143 → 1826 fps (+60%), 3-client 1100 → 1792 (+63%); 800x600 2-client 2450 → 3414 (+39%), 3-client 2078 → 3386 (+63%); 1-client within noise (−1% / +2%).
    • Heavy+light under matching conditions: heavy 129 → 136 fps, light 150 → 158 fps.
    • Compositor (Hyprland 3456x2234@120 Hz, DCP swap counter): 120 fps / 8.33 ms p50 / 0 intervals > 12.5 ms beside 2 light clients; 41 → 58 fps (24.4 → 16.7 ms p50) beside 8K blur.
    • Conformance unchanged (deqp-vk vulkan-cts-1.4.7.1, stock and patched identical, 0 failures across api.smoke.*, synchronization.basic.*, compute.pipeline.basic.*, draw.renderpass.simple_draw.*).
    • Regression run: 0 failed units, 0 GPU errors, 0 new kernel errors (pre-existing BT/cpufreq identical across boots; SELinux disabled on Arch).
  5. §1 / §3 / §6: Clean. Code in g15/engine.rs, g15/poll.rs, and g15/vm.rs is unchanged and verified sound (priority and per-queue FIFO ordering preserved, bounded affinity run resets on !behind, overflow-safe EWMA in stat_retire()). The change is scoped to G15, and the author explicitly asked for confirmation runs on other G15 parts (T8122 Air / T6030 / T6034) they do not own, satisfying §1.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train re-review (MERGETRAIN-LINUX3) at 1d39569: NO BLOCKERS. I checked that 1d39569 changes only the commit message against 9ce9dd0: the trees are identical (a125e69d), the parent is the same, and range-diff shows only message hunks. Our earlier review therefore holds at this head.

Two nits, neither worth a re-push on its own. The commit message and the body give different fps figures (57 vs 58; 158-160 vs 156-158). The Signed-off-by uses a noreply address.

Still to run: a two-client A/B on another G15 part and firmware, for example the M3 Air (G15G, 27.2 firmware). So far the only hardware row is J516C on 14.7.

@RyanTheTide
RyanTheTide merged commit b1124e0 into integration/aurora Nov 22, 2026
1 check passed
@RyanTheTide
RyanTheTide deleted the perf/g15-same-vm-affinity branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants