Repository navigation
drm/asahi: g17: bound submit syncs, install repeated timeline outputs once, return closed queues' identities at close - #3200
DjDeveloperr wants to merge 12 commits into
Conversation
A SUBMIT names its input and output syncs by count and pointer, and the ioctl parses every one of them before the queue sees the submission: each becomes a parsed record holding a syncobj and fence reference, and each timeline output a chain node its syncobj keeps once installed. G17 put no bound on their number. G15 and G16 refuse more than 4096 in total, but only in their queues, after parsing. Move that bound to file.rs as MAX_SYNCS_PER_SUBMISSION, which G15 and G16 now name, and give the GPU trait a max_syncs() admission bound that the ioctl checks next to max_cmdbuf_size(), before anything is copied or allocated. G17 returns the shared bound, so userspace that submits on G15 and G16 submits the same way on G17. Other generations keep their current behaviour. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
Every output of a submission receives the same fence. Installing a timeline point, drm_syncobj_add_point() walks the syncobj's chain for garbage collection, one node per step while the fence it holds is unsignalled, and each installation adds a node. N outputs that name one timeline syncobj therefore cost N(N+1)/2 chain steps under the queue lock, and keep N chain nodes on the syncobj. G17 installs its outputs both when it accepts a submission and when it refuses one after resolving them, so an empty command stream is enough. Such submissions are not only malformed ones: the Vulkan runtime merges a signal-only batch into the batch before it, so one submission can signal a timeline at two rising points. Merge those outputs before any chain node is allocated: keep the last output of each timeline syncobj, at the highest of its points. Waits are unchanged: dma_fence_chain_find_seqno() resolves any of the merged points to the one node, whose fence is the submission's, and the syncobj's last submitted point is the same. Binary outputs are left as they are, and the cumulative anchor never merges, so an output aliasing it is still refused. The merge sorts the outputs that can merge, and allocates only when a submission has two or more of them. KUnit: asahi_submit_outputs. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
A queue's context holds an execution identity, a QoS ID and, on some variants, a render identity, all from small device-wide pools. If the firmware saw the context, closing the queue arms a scheduler release, and the identities return when the firmware has consumed it. If it never saw the context, teardown::Pending::close() keeps nothing, and the identities return only with the context's last reference. That reference can outlive the queue by as long as userspace likes. When a client exits, its scheduler entities cancel the jobs still waiting for an input fence, but drm_sched frees such a job only once every one of its dependencies has signalled (drm_sched_entity_kill_jobs_work()), and the job holds the queue's backend and so its context. Meanwhile the queue's admission slot and its process's queue share are returned at close. Each exiting client with such a job then leaves an execution identity in use that no open queue accounts for. On M5, where every queue has its own, enough of them leave a new queue waiting for contexts that are not closing, and it fails with ENOSPC. Once both schedulers are torn down nothing of the queue can be published any more, so the firmware can never see that context: return its execution identity, QoS ID and unused render identity at close, next to the queue's admission. The cancelled jobs keep only memory, and still signal their outputs after their inputs, as drm_sched requires. QosLease now gives its ID back once, early or on drop. KUnit: asahi_g17_qos_capacity (an_id_given_back_early_is_given_back_once). Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Verdict at Blockers: none At Checked:
Evidence
|
|
Update, J773g (M4 Mac mini, G16G) at How it was run: two guarded one-shots on the default cmdline, the same day on the same Mac.
CTS:
All four fails are different cases from the same
None of them fails on its own: all four ran 25 times each on the stock kernel, 100/100 pass, with no kernel lines. I read them as the same flaky family on both arms, not something this PR adds. I didn't repeat them on the candidate kernel. Other checks: Not run: the Both boots returned to the stock kernel, and the kits were removed from the Mac. Earlier run, at J773g (M4 Mac mini, G16G) at How it was run: two guarded one-shots on the default cmdline.
CTS:
Both boots lost the device on the same early case,
So these faults come from the base, the cross-instance external-semaphore tests, as in #3201. Whether this PR makes them escalate can't be told from one run per arm. Other checks:
Not yet: the same subset on both kernels with one worker and without the |
…d the sync bound Two host tests compile driver files against stand-ins that lacked what this branch's earlier commits use. g17-admission-order-tests.py builds release_queue(), which now calls Context::release_unpublished(); its stand-in Context gets it as a no-op, since the fixture models slot holds, not identities. test-command-stream.py builds g16/command.rs, whose MAX_SYNCS now names file::MAX_SYNCS_PER_SUBMISSION; its stand-in file module gets the constant. No runtime code changes. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
J700 (MacBook Neo, A18 Pro, G17P) at
|
There was a problem hiding this comment.
Verdict: MERGE at 7121f2e once current hosted checks pass.
Checked: The merge-up type fix accepts the same KVVec that main now uses for parsed syncs. It changes the parameter type without changing coalescing order or the close path. The current-head J700 result matches stock on the sync CTS subset and passes duplicate outputs and kill/teardown stress.
Keep main's execution_share_id() and this branch's release_unpublished() next to each other in g17/context.rs. release_unpublished() releases the execution identity through release_execution(), which on main goes through the exec_share Use: a shared context only leaves its share, and the last sharer releases the root. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merged main ( Checks on
The J700 row at |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: MERGE at fa5571a77bab once the J700 and J714s rows below pass at this head.
Blockers: none in the code.
Checked: the merge of main 18edb08a is a clean merge plus the one g17/context.rs conflict, fixed by keeping both functions: main's execution_share_id() and this PR's release_unpublished(). Against main, the net diff is line for line the one approved at 7121f2eb. Main's shared-execution code doesn't change what release_unpublished() relies on, because each release it calls runs at most once (exec_share::Use::release_execution(), ExecutionRoot::release(), QosLease::give_back(), release_render_id()). A later release from teardown or drop is therefore still safe. CI at this head: apple-build and KUnit asahi pass. host-tests was cancelled, so I ran the full host-test suite at this head in the CI's Ubuntu 24.04 image: 952/952 pass, including g17-admission-order-tests and the asahi-m4 selftests. No Apple material, no gates.
Rows still owed at this head: J700 and J714s, the Vulkan sync CTS subset vs base, the duplicate-timeline-output test, and a kill/teardown stress.
Evidence
git merge-tree --write-tree --merge-base=42169a041546 7121f2ebd2f8 18edb08ad329conflicts only ing17/context.rs. Every other path is identical to the tree offa5571a7.- The added and removed lines of
18edb08a..fa5571a7are identical to those of42169a04..7121f2eb(+213/-10, 10 files). tools/asahi/run-host-tests.py --jobs 20atfa5571a7(tree6669eacd), rustc 1.96.0, Python 3.14.10, no network: 952/952 passed in 327 s.
There was a problem hiding this comment.
Verdict: MERGE at fa5571a
Checked: The merge keeps both the execution-share accessor and unpublished-context teardown. A published context still takes the existing release path. An unpublished shared context releases only its own Use, whose done flag prevents double release; the last share releases the root. The sync bound and output coalescing are unchanged by the conflict resolution. The author reported 329/329 G17 host checks and the ABI suite passing at this head.
RyanTheTide
left a comment
There was a problem hiding this comment.
The merge crosses a binary replacement on the same syncobj. The parser accepts timeline 9, binary, then timeline 7 for one handle. Today the middle output replaces the fence, so the final timeline ends at 7. Coalescing timeline outputs across that replacement moves point 9 to the last output and publishes 9 instead. Treat a same-object binary output as a boundary when coalescing.
A binary output replaces the syncobj's fence, chain and points. With timeline 9, binary, then timeline 7 on one syncobj the last point is 7, but merging the two timeline outputs across the binary one moved point 9 to the last output and published 9. Keep the binary outputs in the merge list as boundaries. Add a KUnit case, and a host test that checks every list of up to five outputs on two syncobjs against installing each output in order. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Right, that was a real bug. There is a KUnit case for it, and a new host test ( |
RyanTheTide
left a comment
There was a problem hiding this comment.
The binary replacement case from the previous review is fixed. A binary output ends the timeline group for that syncobj and leaves other syncobjs independent. I ran the exact-head submit-output host test: 6/6 passed, including the comparison with in-order installation of short output lists. Restoring the old merge across binary outputs fails both boundary tests. Hardware rows remain pending.
What: Three fixes on the G17 submit and queue-close paths. A SUBMIT's syncs get the bound G15 and G16 already apply, checked before they are parsed. Timeline outputs of one submission that name the same syncobj are installed once, at their highest point, instead of once each. A closed queue whose context the firmware never saw returns that context's execution identity, QoS ID and unused render identity at close, instead of when its last cancelled job is freed.
Tested: build and host tests on the current code: the arm64 driver builds with KUnit on, no new warning;
run-host-tests.py --only g17331/331, includingg17-submit-outputs-tests(it fails on the code before that commit). An older head (7121f2ebd2f8) has a J700 row, but the output merge has changed since, so it does not count for this one.Risk: two-way door · every Mac for the output merge (shared
file.rssync parsing); A18 Pro and M5 for the sync bound and the close path.Not yet: J700 (A18 Pro) and J714s (M5 Pro) rows for the current code: the Vulkan sync CTS subset against base, both tests below, and a kill/teardown stress. They are required: the output merge and the close path change at run time.
Details
1.
drm/asahi: g17: bound a submission's syncs before parsing themThe ioctl parses every input and output sync before the queue sees the submission. Each becomes a parsed record holding a syncobj and fence reference, and each timeline output also gets a chain node that its syncobj keeps once the output is installed. G17 had no bound on how many. G15 and G16 refuse more than 4096 in total, but only in their queues, after parsing.
The bound moves to
file.rsasMAX_SYNCS_PER_SUBMISSION, which G15 and G16 now name; their behaviour is unchanged. A newGpu::max_syncs()admission bound is checked next tomax_cmdbuf_size(), before anything is copied or allocated. G17 returns the shared bound, so userspace that submits on G15 and G16 submits the same way on G17. Other generations keep returning no bound.2.
drm/asahi: install a submission's timeline outputs on one syncobj onceEvery output of a submission gets the same fence.
drm_syncobj_add_point()walks the syncobj's chain after each installation, one node per step while the fence it holds is unsignalled, and each installation adds a node. N outputs naming one timeline syncobj therefore cost N(N+1)/2 chain steps under the queue lock. G17 installs outputs both when it accepts a submission and when it refuses one after resolving its outputs, so an empty command stream is enough.This isn't only a malformed-input case. Mesa's Vulkan runtime merges a signal-only batch into the batch before it, so one submission can signal a timeline at two rising points.
The parser now merges them before any chain node is allocated. It keeps the last output of each timeline syncobj, raised to the highest of that syncobj's points. Waits don't change:
dma_fence_chain_find_seqno()resolves any of the merged points to that one node, whose fence is the submission's, and the syncobj's last submitted point is the same. Binary outputs are left alone, and one that names the same syncobj ends a merge: it replaces the chain, so timeline 9, binary, timeline 7 still ends at 7. The cumulative anchor never merges, so an output aliasing it is still refused. The merge sorts the outputs, and allocates only when there are at least two timeline outputs.This sits in shared
file.rs, so every generation's submissions get it. It changes nothing a waiter can observe.3.
drm/asahi: g17: return a closed queue's unpublished identities at closeA context holds an execution identity, a QoS ID and, on some variants, a render identity, all from small device-wide pools. If the firmware saw the context, closing the queue arms a scheduler release, and the identities return once the firmware has consumed it. If it never saw the context,
teardown::Pending::close()keeps nothing, and the identities return only with the context's last reference.That reference can outlive the queue for as long as userspace likes. When a client exits, its scheduler entities cancel the jobs still waiting for an input fence. drm_sched frees such a job only after every one of its dependencies has signalled (
drm_sched_entity_kill_jobs_work()), and the job holds the queue's backend, and through it the context. The queue's admission slot and its process's queue share, though, are returned at close. So each exiting client with such a job leaves an execution identity in use that no open queue accounts for. On M5, where every queue has its own, enough of them leave a new queue waiting for contexts that aren't actually closing, until it fails with ENOSPC.Once both schedulers are torn down, nothing of the queue can be published, so the firmware can never see that context.
release_queue()now returns its execution identity (through the shared-context bookkeeping on A18 Pro), its QoS ID and its unused render identity right there, next to the queue's admission. The cancelled jobs keep only memory, and still signal their outputs after their inputs, as drm_sched requires.QosLeasegives its ID back exactly once, either early or on drop. A published context is unchanged: its identities still wait for the consumed release.Merging with #3021
#3021 turns the sync list into a
KVVec. Whichever of the two lands second needscoalesce_outputs()to take the other's vector type; the logic doesn't change.Evidence
./linux-build/build kernel --profile asahi <tree> -- drivers/gpu/drm/asahi/at43f3740cfbd05, exit 0. No warning in a changed line.--strict: 0/0/0 on all three commits.asahi_submit_outputs(distinct syncobjs untouched; rising and falling points keep the last output at the highest point; 4096 repeats of one point leave one output) andasahi_g17_qos_capacity::an_id_given_back_early_is_given_back_once.dup-outputs: raw ioctls with no GPU work. It names one timeline syncobj from 1024, 2048 and 4096 outputs, then rising points 1 to 4096, then 4097 syncs. It expects time to grow about linearly, every point to be waitable, and 4097 to be refused with nothing installed, and timeline 9, binary, timeline 7 on one syncobj to end at 7.killed-jobs: twelve clients each submit a fill behind a chain of bounded compute dispatches (8 × ~0.8 s, each inside the 2 s watchdog) and are SIGKILLed while the chain runs. It compares/sys/kernel/debug/aurora-g17/capacityafter the kills against after the chain finished. Expected: no execution contexts or QoS IDs held by the killed jobs.killed-jobsrounds, then a kernel log check.