Repository navigation
drm/asahi: m3: wait for dependencies of other queues to finish - #4163
DjDeveloperr wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at f16a9d21b6cf
Blockers:
- 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.olinks, no unresolved symbol foraurora.ko, no warning in the changed files. run-host-tests.py --only:queue-priority1/1,m3-19/19,g14-25/25.checkpatch --strict: 0/0/0.rustfmt --checkonsched.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.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
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
f16a9d21b6cfmerged with mainc09b61228e62: the wholeauroramodule compiles and links intoaurora.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 testqueue-priority-tests.pypasses, 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'sscheduledfence, unlessDRM_SCHED_FENCE_DONT_PIPELINEis set on itsfinishedfence. So the consumer reachesrun_job()while the producer may still wait inpending.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:m3/, one scheduler, sortedpendingm3/, as abovem3/runtime refuses them)pendingis first in, first out and a render waits for everything before itm5/)The fix sets the flag between
arm(), which initializes the fence, andpush(), so no consumer can see the fence without it. A small helper inrust/kernel/drm/sched.rsdoes it.m3_submit.rsis 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
pendingand 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 insched_entity.cand the helper still say what the model assumes.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.kowithCONFIG_DRM_ASAHI_M3_T8122,_G14_V27_2,_G15,_G16,_G18and_M5set (gcc 16.2.0, rustc 1.100.1). Modpost was run on these three modules only: nothing is missing foraurora.koormacsmc-hwmon.ko, andappledrm.kolacks 10 symbols of modules that were not built, so no.kowas linked. Inaurora.othe only function that callsrust_helper_set_bitis thesubmitofm3_submit::Queue, so no other generation's code has the call.run-host-tests.py --only:queue-priority1/1,m3-19/19,g14-25/25.queue-priority-tests.pyfail: droppingdont_pipeline()from the submission, calling it afterpush(), setting the flag on the scheduled fence, setting another bit, clearing the bit, changing the rule insched_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 --checkonsched.rs: no new findings (7 existing).checkpatch --strict: 0 errors, 0 warnings, 0 checks.