Skip to content

drm/asahi: m3: wait for dependencies of other queues to finish - #4163

Closed
DjDeveloperr wants to merge 1 commit into
mainfrom
fix/asahi-sched-dont-pipeline
Closed

DjDeveloperr wants to merge 1 commit into
mainfrom
fix/asahi-sched-dont-pipeline

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

What: On the M3 (T8122) runtime a more urgent GPU job can run before the job of another queue it waits for. LOW producer and MEDIUM consumer is enough, and that needs no privilege. Jobs of other queues now wait until the producer has finished.

Tested: no Mac yet. At f16a9d21b6cf merged with main c09b61228e62: the whole aurora module compiles and links into aurora.o (W=1, arm64) with the M3, G14 27.2, G15, G16, G17, M5 and G18 code enabled, modpost finds no unresolved symbol for it, and the changed files give no warning. Host test queue-priority-tests.py passes, and fails without the fix for LOW->MEDIUM, LOW->HIGH and MEDIUM->HIGH.

Risk: two-way · M3 MacBook Air J613/J615 on GPU firmware 14.8.3, J613 on 26.6.2, and M1/M2 (T8103, T8112) on GPU firmware 27.2, which use the same submission code. M2 Pro (T6020) on 27.2 joins them with #3998. No other Mac runs this code: every other backend has a scheduler per queue, or no DRM scheduler, and never calls the helper.

Not yet: a row on a T8122 that runs the m3/ runtime (27.2 firmware uses the G16 backend and does not reach this code), and a G14 27.2 no-regression row with a throughput check.

Details

The bug. All queues of the runtime share one DRM scheduler (m3_drm.rs:197). For a dependency on another entity of the same scheduler, drm_sched_entity_add_dependency_cb() only waits for the producer's scheduled fence, unless DRM_SCHED_FENCE_DONT_PIPELINE is set on its finished fence. So the consumer reaches run_job() while the producer may still wait in pending. Runtime::submit() (m3_runtime.rs:1500) then inserts it in front of every less urgent packet, its producer included. This needs the producer to be a job of a less urgent queue, the two on different queues, the wait to be a plain scheduler fence (a binary syncobj or an imported sync file; a timeline point is a chain fence and waits fully), and other GPU work in flight.

Who reaches it on main:

Mac and GPU firmware Backend Reaches it
T8122 J613/J615, 14.8.3 m3/, one scheduler, sorted pending yes, LOW to MEDIUM
T8122 J613, 26.6.2 m3/, as above yes, and MEDIUM or LOW to HIGH
T8122, 27.2 G16, a scheduler per queue no
T6030, T6031, T6032 G15 or G16, or no driver, a scheduler per queue (the m3/ runtime refuses them) no
T8103, T8112 on 27.2 G14 27.2, one scheduler, but pending is first in, first out and a render waits for everything before it no, not until something reorders it
T6020 on 27.2, with #3998 G14 27.2, as above no, not until something reorders it
T8103, T8112 on 12.3/13.5, T600x, T602x a scheduler per queue no
T8132 (G16) a scheduler per queue no
G17 (T604x, T8140, T605x) a scheduler per queue and engine no
T8142 (m5/) no DRM scheduler no

The fix sets the flag between arm(), which initializes the fence, and push(), so no consumer can see the fence without it. A small helper in rust/kernel/drm/sched.rs does it. m3_submit.rs is also the submission path of G14 27.2, so the fix covers that backend for a reordering change there.

What it does to pipelining. Jobs of one queue still pipeline: the same-entity check comes before the flag, and one queue has one urgency, so its jobs stay in order. Jobs of different queues that don't depend on each other are not affected. A job that depends on a job of another queue is handed over only after the producer finished, which adds one CPU round trip and no longer joins the producer's render batch if both are in one VM. Every other backend already behaves like this, because its queues have their own schedulers. On G14 27.2 this is a new wait with no bug behind it on main; it has not been measured. A render there already waits for everything published before it, so only a compute job that depends on another queue's compute job loses overlap; other dependent jobs lose the time until the scheduler has handed them over.

Sleep. A dependent job can now reach the runtime while it drains for sleep. Both runtimes take it into pending and publish it after resume (m3_runtime.rs:1485, g14_v27_2.rs:951), as they do for any job the scheduler still held.

Not fixed by changing the insertion: the runtime doesn't know a packet's producers, and one rule that lets a job stop before its producer also has to keep the order of the jobs behind it.

Evidence
  • python3 tools/asahi/queue-priority-tests.py: 9 producer/consumer priority pairs (LOW, MEDIUM, HIGH), a three-queue chain, independent urgent work still first, same-queue work still handed over together. It compiles the real submission tail and the real insertion code against a model of the scheduler rule, and checks that the rule in sched_entity.c and the helper still say what the model assumes.
  • Build of the merge tree: make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- W=1 drivers/gpu/drm/asahi/aurora.ko drivers/gpu/drm/apple/appledrm.ko drivers/hwmon/macsmc-hwmon.ko with CONFIG_DRM_ASAHI_M3_T8122, _G14_V27_2, _G15, _G16, _G18 and _M5 set (gcc 16.2.0, rustc 1.100.1). Modpost was run on these three modules only: nothing is missing for aurora.ko or macsmc-hwmon.ko, and appledrm.ko lacks 10 symbols of modules that were not built, so no .ko was linked. In aurora.o the only function that calls rust_helper_set_bit is the submit of m3_submit::Queue, so no other generation's code has the call.
  • On the merge tree, run-host-tests.py --only: queue-priority 1/1, m3- 19/19, g14- 25/25.
  • Mutations that make queue-priority-tests.py fail: dropping dont_pipeline() from the submission, calling it after push(), setting the flag on the scheduled fence, setting another bit, clearing the bit, changing the rule in sched_entity.c, and making the runtime's queue first in, first out. Without the flag it reports ["LOW->MEDIUM", "LOW->HIGH", "MEDIUM->HIGH"] as published in the wrong order.
  • m3-batching-tests.rs: 12 passed.
  • rustfmt --check on sched.rs: no new findings (7 existing). checkpatch --strict: 0 errors, 0 warnings, 0 checks.

All queues of the M3 and G14 27.2 runtimes share one DRM scheduler. For a
dependency on another entity of the same scheduler, drm_sched only waits
until the producer was passed to run_job(), which is enough as long as the
driver publishes jobs in that order.

The M3 runtime doesn't: it publishes more urgent packets first. A MEDIUM
job that waits for a LOW job of another queue reaches the runtime while
the LOW job is still pending, is inserted in front of it, and runs before
the work it depends on. The same happens with a HIGH job and a MEDIUM
one. LOW and MEDIUM queues need no privilege.

Set DRM_SCHED_FENCE_DONT_PIPELINE on the finished fence before the job is
pushed, so jobs of other queues wait until it has finished. Jobs of one
queue are not affected: they share one urgency, so they stay in order, and
drm_sched ignores dependencies within an entity.

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

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

The flag is set on the finished fence after arm and before the fence is published. That makes a dependent job on another entity wait for the producer to finish, while the scheduler still handles same-entity dependencies first. The host model exercises the LOW-to-MEDIUM case and higher-priority variants. Hardware and the G14 throughput check are still pending.

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review December 3, 2026 08:58
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 08:58

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Verdict: FINISH, then merge at f16a9d21b6cf
Blockers:

  1. Hardware rows only: one T8122 that runs the m3/ runtime (J613/J615 on 14.8.3, or J613 on 26.6.2), and one G14 27.2 no-regression row with a throughput check. No code change is needed.

Checked: the ordering claim against this kernel's scheduler, fence lifetime and locking in the helper, sleep, what it costs on the other GPUs, the build and the host tests on a merge with main c09b61228e62. No Apple material, no chip or firmware gate, no new parameter.

Evidence

The bug is real and the flag fixes it. drm_sched_entity_add_dependency_cb() (sched_entity.c:496) replaces a dependency on the same scheduler by the producer's scheduled fence, and that fence signals right after run_job() (sched_main.c:1064). On m3/ run_job() only inserts the packet into pending, sorted by urgency, so a more urgent consumer passes its producer. With the flag on the finished fence the consumer stays in the scheduler until the producer has finished. Credits and prepare_job play no part: the runtime has no prepare callback, and the dependency check comes before a job takes credits.

Right fence, no race. Consumers only ever get the finished fence, and the test reads the flags of that fence. drm_sched_job_arm() writes the flags once, when it initializes the fence. The call is after that and before push() and the syncobj updates, so nobody else can see the fence yet, and it cannot be scheduled or signalled. The job holds the fence reference until free_job, and the ArmedJob still owns the job, so the pointer in the unsafe block is valid. set_bit is atomic and the bit is the first user bit (6 in the generated bindings), which the scheduler reserves for this.

Other cases. A job without dependencies takes the same path as before. A dependency in the same queue is dropped before the flag is looked at, so one queue still pipelines. A wait on a timeline point keeps the chain fence (file.rs uses chain_find_seqno, not the syncobj helper that unwraps it) and always waited fully; a binary syncobj or sync file made from such a point carries the flagged fence. Dependencies between contexts and processes are the same case, because all queues share the one scheduler. A signalled or failed producer takes the path it took before.

Sleep. A consumer can now arrive while the runtime drains for sleep. asleep only stops publishing on m3/, and G14 27.2 does the same, so the job waits in pending and runs after resume. Only the state after an aborted deep sleep refuses jobs, as it does for any job.

Cost. Only a job that depends on another queue's job pays, with a scheduler round trip, and on m3/ it can't join that job's render batch. MEDIUM to MEDIUM pays it too, although it was in order before: the producer can't know its consumers. On G14 27.2 a render is already a boundary, so only dependent compute loses overlap. Both are worth the throughput numbers in the rows.

Other GPUs. The helper has one caller. In the built aurora.o, rust_helper_set_bit is called from m3_submit::Queue::submit and nothing else. That queue is only created by m3/ (m3_drm.rs:582) and G14 27.2 (g14_v27_2.rs:2470). G15, G16, G17 and the M1/M2 12.3/13.5 backend have a scheduler per queue, so a dependency from another queue already waits until it has finished, and they don't call the helper. J516s, J773g, J714s and J700 rows are not needed. One addition: #3998 moves M2 Pro (T6020) on 27.2 to the G14 27.2 runtime, so J414s can give that G14 row.

Run on the merge with main c09b61228e62 (what landed on main since touches G17 files and devicetrees only):

  • W=1 arm64 build with the M3, G14 27.2, G15, G16, G17, M5 and G18 code: aurora.o links, no unresolved symbol for aurora.ko, no warning in the changed files.
  • run-host-tests.py --only: queue-priority 1/1, m3- 19/19, g14- 25/25. checkpatch --strict: 0/0/0. rustfmt --check on sched.rs: 7 findings, the same 7 as main.
  • 7 mutations of the fix and of the rules it relies on, all caught by queue-priority-tests.py.

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:rust Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at f16a9d21: ready to merge

Check Detail
CI at head ok 12 checks passed
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok in the PR body at f16a9d21
Conflicts ok none
PR text ok Risk: two-way · M3 MacBook Air J613/J615 on GPU firmware 14.8.3, J613 on 26.6.2, and M1/M2 (T8103, T8112) on GPU firmware 27.2, which use the same submission code. M2 Pro (T6020) on 27.2 joins them with #3998. No other Mac runs this code: every other backend has a scheduler per queue, or no DRM scheduler, and never calls the helper.

Areas: area:gpu, area:rust
Merge: gh pr merge 4163 --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 removed the ci-failing A check failed at the PR head (bot) label Dec 3, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Exact-head G14 27.2 no-regression, ordering, CTS, and ABBA throughput row on J473 (Apple M2 Mac mini, apple,j473 / T8112, G14G B0 firmware 27.2, Fedora 45, Enforcing, Mesa 26.3.0-devel d4ad4a4dce):

  • Builds (identical .config 8a859e6e5bf3, identical own t8112-j473.dtb 43d942ef48d0 via one-shot aura-try Stage 2 41ecfa0e8142, default cmdline):
    • A (main 8ec8740a1e6f): 7.3.0-b6m4163, Image d4e9a686697a, aurora.ko 05044c195b11.
    • B (PR head f16a9d21b6cf): 7.3.0-b6p4163, Image 6a18b35bb054, aurora.ko a7c6340a0b3a.
  • 1. Desktop boot + 10 min soak (head B1): GNOME Wayland (gnome-shell) active, Enforcing, 611.1 s uptime, 0 new GPU lines in journalctl -k -b vs main, 0 GPU fault/error/Oops/WARN lines. (Note: speakerguardd-v2-switchtest.service showed failed on both main and head trial boots due to deferred audio self-check on kernel/DTB change; unrelated to GPU; 0 failed units on restored default.)
  • 2. Ordering (pr4080-kit-20261203.tar.gz, sha256 2c245b275c4c5f89): ./run.sh --check -> CHECK OK. Three rounds × 100 each of prioload order low medium 100, medium medium 100, medium low 100 (unprivileged user, GPU otherwise idle):
    • main (8ec8740a1e6f): stale 0 on all 9 runs (low->medium: 0, 0, 0; medium->medium: 0, 0, 0; medium->low: 0, 0, 0). Expected on main G14 27.2 because pending is FIFO until reordering is added.
    • Head (f16a9d21b6cf): stale 0 on all 9 runs (low->medium: 0, 0, 0; medium->medium: 0, 0, 0; medium->low: 0, 0, 0).
  • 3. dEQP-VK synchronization suites (0 new fails vs main, exact match):
    • dEQP-VK.synchronization.basic.*: 21/29 Passed, 0 Failed (8 Not supported) on both main and head.
    • dEQP-VK.synchronization.cross_instance.*: 3924/31306 Passed, 0 Failed (27382 Not supported) on both main and head.
    • dEQP-VK.synchronization.global_priority_transition.*: 18/396 Passed, 0 Failed (378 Not supported) on both main and head.
  • 4. ABBA × 3 throughput (6 runs A [A1+A2] vs 6 runs B [B1+B2]):
    • prioload order medium medium 100 (wall ms, lower is faster):
      • main: A1 4369.5, 4368.8, 4368.5 (med 4368.8); A2 4378.9, 4368.1, 4374.4 (med 4374.4) -> pooled median 4369.2 ms
      • head: B1 4389.1, 4378.9, 4384.0 (med 4384.0); B2 4417.2, 4384.9, 4385.7 (med 4385.7) -> pooled median 4385.3 ms (+0.37%, within 3%).
    • prioload load medium 10 100 (jobs / p50 ms):
      • main: A1 2618, 2618, 2596 (p50 11.47, 11.47, 11.57); A2 2607, 2594, 2613 (p50 11.52, 11.58, 11.49) -> pooled median 2610.0 jobs / 11.50 ms
      • head: B1 2614, 2608, 2618 (p50 11.48, 11.51, 11.47); B2 2611, 2602, 2600 (p50 11.50, 11.54, 11.55) -> pooled median 2609.5 jobs / 11.50 ms (+0.02%, identical).
    • vkmark (2025.01, --winsys headless, score, higher is faster):
      • main: A1 6137, 6118, 6119 (med 6119); A2 5966, 6111, 6252 (med 6111) -> pooled median 6118.5
      • head: B1 6027, 5879, 6143 (med 6027); B2 5862, 5964, 5874 (med 5874) -> pooled median 5921.5 (-3.22%, flagged >3%).
      • Per-scene breakdown (6 A vs 6 B medians): 12 of 13 scenes are within -2.56%..+1.18% (vertex -0.11%/-1.63%, texture -0.96%/-1.27%, shading -1.18%..+1.18%, effect2d -0.70%/-1.60%, desktop -1.60%, cube -2.56%). The entire >3% score swing comes from [clear] <default> (main median 20060 vs head 18189, -9.33%), which showed bimodal ~17k vs ~20k FPS runs on both kernels (main A2 [17358, 20185, 20309]; head B1 [18558, 16702, 19861], B2 [17820, 19741, 17427]).
  • Overlap with drm/asahi: enable HIGH priority GPU queues across G14 v27.2, G15-G17 and split-KMS compositors #4080 (5c50caa34196): Both heads were tested independently on J473. Both add RUST_CONST_HELPER_DRM_SCHED_FENCE_DONT_PIPELINE in rust/bindings/bindings_helper.h, a DRM_SCHED_FENCE_DONT_PIPELINE helper in rust/kernel/drm/sched.rs (ArmedJob::dont_pipeline() here vs JobFences::set_dont_pipeline() in drm/asahi: enable HIGH priority GPU queues across G14 v27.2, G15-G17 and split-KMS compositors #4080), the call in drivers/gpu/drm/asahi/m3/m3_submit.rs, and test coverage in tools/asahi/queue-priority-tests.py. Merging drm/asahi: m3: wait for dependencies of other queues to finish #4163 first is clean; drm/asahi: enable HIGH priority GPU queues across G14 v27.2, G15-G17 and split-KMS compositors #4080 will then merge main and drop its duplicate helper in favor of drm/asahi: m3: wait for dependencies of other queues to finish #4163's dont_pipeline().

@RyanTheTide

Copy link
Copy Markdown
Contributor

Row: f16a9d2 + J615 (MacBook Air 15" M3, G15G, macOS 27.2 / 26B123 stub) + default cmdline + PASS, no regression (27.2 runs the g16 backend, so this checks the shared parts, not the m3/ fix)

Three one-boot DT trials with each kernel's own t8122-j615.dtb, same body. Order: head, main 8ec8740a1e6f (this PR's merge-base), head again. #4080 kit (prioload) on the last two.

head (1) main head (2)
dEQP-VK synchronization.basic 29/29 29/29 29/29
synchronization.cross_instance 10004 pass, 0 fail same same
synchronization.global_priority_transition 66 pass, 0 fail (8 warn) same same
prioload order low/med, med/med, med/low x3 - stale 0 stale 0
order medium medium 100 wall, median of 3 - 4.00 s 3.97 s
load medium 10 100 jobs, median of 3 - 2891 2892
glmark2 build / texture, median of 3 4887 / 4980 4858 / 4943 4867 / 4967
GPU error lines, Oops, failed units 0 0 0

The head isn't slower: order -0.8 %, load +0.03 %, build/texture within 1 %. glmark2 terrain is heat-bound on this fanless Mac after the CTS: every arm ends at 357-360, and first runs vary from 360 to 864. So I left it out of the 3 % check.

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Closing: #4080 is merged (2533c76f02e3) and makes the same change. m3/m3_submit.rs on main sets DRM_SCHED_FENCE_DONT_PIPELINE on the finished fence between arm() and push(), through JobFences::set_dont_pipeline(), and g14-v27-2-try-bind-tests.py covers the LOW->MEDIUM and MEDIUM->HIGH order. Only a second host test would be left here, so nothing of this branch needs a row any more.

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) area:rust Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 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