Skip to content

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

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

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: not ready yet

Check Detail
CI at head running running: KUnit asahi sep aop
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

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

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) 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants