Repository navigation
pmdomain: apple: pmp-report: turn the AGX vote on by default on the t6001 (stacked on #334) - #441
joshuaswarren wants to merge 17 commits into
Conversation
…n t600x On the M1 Max (t6001) the PMP keeps memory at its idle floor for a busy GPU until the AGX power request, bit 9 of the PMP report's PS-REQ word, is set. Nothing sets it on Linux, so GPU reads top out at 241 GB/s. The same chip reads 361 GB/s on macOS. Report GPU activity to the PMP. The GPU driver calls apple_pmp_agx_activity_begin() when a submission starts and apple_pmp_agx_activity_end() when it finishes. pmp-report sets bit 9 when the first operation starts and clears it 100 ms after the last one ends. It also clears it at once when the GPU driver unbinds or the report goes away, so the request is never left set past the GPU's power-domain release. The register sequence is the one apple_pmp_report_set_state() already uses for report entries: read 0xf80, write 0x107c0, poll 0x1000, status 0x10, 50 ms acknowledge. A set that is not acknowledged is cleared again and not retried for a second. The vote is off by default. pmp_report.agx_vote=1 turns it on, and pmp_report.agx_vote_idle_ms (default 100) sets the hold. With it off nothing is written. It applies to apple,t6001 only; t6000 is untested. The decisions (set, clear, hold, retry, wrap of the 32-bit millisecond clock) are plain functions in pmp-agx-vote.h with no kernel dependency. Setting the bit by hand with a test module on a 16-inch M1 Max moved a GPU read microbenchmark from 241 to 368 GB/s. This patch has not yet been run on hardware. Signed-off-by: Joshua Warren <[email protected]>
…one power request bit The PS-REQ word of the PMP report is shared by every client of the PMP: the report entries (display, ISP, video decode, the AFNC IOAs), the T6001 AGX vote (bit 9) and, out of tree, the ANE clock level of omarchy-ane (bit 10). The report entries and the AGX vote read-modify-write the word under rep->lock. A module outside this driver could only map the window and read-modify-write it without that lock, so a concurrent write of another bit could be lost. apple_pmp_report_set_request(report_np, id, enable, no_ack) is the one writer a client outside this file may use. It calls the same apple_pmp_report_set_state() the entries use, so it takes the same lock and does the same acknowledge poll (at most 50 ms). The caller owns the bit it asks for. Signed-off-by: Joshua Warren <[email protected]>
…ment clearing apple_pmp_report_set_request() lets a client outside pmp-report update one bit of the PS-REQ word. On the T6001 bit 9 is the AGX request, which the GPU vote owns: a second writer could clear it while the GPU works, or set it and leave it set. Refuse it from the export with -EBUSY on a t600x report. The vote itself writes through apple_pmp_report_set_state() and is not affected. Document what a caller must do after -ETIMEDOUT: the request was written but not acknowledged and stays in the word, so the caller clears it with @enable false and @no_ack true before giving up. Signed-off-by: Joshua Warren <[email protected]>
…st operation A 9B model at 8192 tokens of context had one gap of up to 111.5 ms between two decoded tokens in every process, once per run, with the GPU idle for a good part of it. The 100 ms default hold dropped the request in that gap, which costs one slow token while the PMP raises memory again. The longest gap in any other configuration measured was 64 ms. Raise the default to 250 ms, about 2.2 times the longest gap seen. The cost is a few hundred milliseconds of the higher memory state after the last job. pmp_report.agx_vote_idle_ms still overrides it at run time. The default is one constant, AGX_VOTE_IDLE_MS_DEFAULT, used for both the parameter and the initial state. The userspace test has a case that rides through a 112 ms gap with the default and still drops the request after a long idle. Signed-off-by: Joshua Warren <[email protected]>
… it across unbind and sleep Review of the AGX vote found four problems. 1. agx_vote=1 on the kernel command line runs the parameter setter from parse_args(), before workqueue_init_early() has created the workqueues, and the setter queued work on a NULL workqueue. kick() now returns while system_dfl_wq does not exist; begin() and the work function read the parameter themselves, so the first GPU operation votes. It also uses system_dfl_wq instead of the deprecated system_wq. 2. An operation that began while the clear was being written saw voted still true and did not kick; after the clear nothing scheduled a set, so the GPU ran at the idle floor until the next begin. agx_vote_next() now reports a set that is owed (1 ms) when users > 0, the request is not voted and no set has failed. 3. release() did not stop a later begin() from setting the bit again, and the report's removal had the same shape. A stopped flag, set under the vote lock at release and at report removal, is checked by begin(), decide() and next(); it is cleared by a new apple_pmp_agx_activity_resume() called at GPU probe and at report probe. 4. The request is withdrawn on PM_SUSPEND_PREPARE and PM_HIBERNATION_PREPARE and decided again on PM_POST_SUSPEND and PM_POST_HIBERNATION: holding the bit through s2idle may cost power (a held display request cost about 0.25 W on J514S), and the PMP may drop the word across sleep, which would leave voted true with nothing on the wire. Each case has a test in tools/ptd-vote of the research repository that carries the policy header (cases 14 to 17 of the vote simulator, and a source check for the boot-time kick); they were written to fail first. Signed-off-by: Joshua Warren <[email protected]>
…d report probe now uses The report probe tells the AGX vote that a T6001 report came back (apple_pmp_agx_activity_resume) and compares rep->offsets with the T6001 table. The harness extracts the probe verbatim and compiles it standalone, so production.h failed with an undeclared apple_pmp_offsets_t600x and an implicit declaration of apple_pmp_agx_activity_resume. An empty T6001 table that never matches and an empty resume function are enough: the harness models the T6030 graph. All 21 graph cases pass, and the supplier harness passes (ASan needs ASLR off on this host: setarch -R). Signed-off-by: Joshua Warren <[email protected]>
…ontrols The vote policy is a header of static inline transition functions, so the suite compiles pmp-agx-vote-tests.c against a copy of it and drives the same begin, decide, next and applied calls the kernel glue makes, with a fake clock, a fake PMP bit and a fake timer. 18 cases: the parameter off, the set and idle drop, decode-like bursts, a drop cancelled by new work, the failed set backoff, unbalanced ends, the parameter switched off mid-flight, the zero idle tick, millisecond clock wraps, release and refuse, resume with and without work in flight, sleep and resume, and the two asserts from review (the begin inside a clear write must be re-set, and begin must refuse while stopped). --mutation and --mutations remove one guard each (the owed-set branch, the !failures in it, and the stopped check in begin and decide) and require the suite to fail. The two mutants that survived before the races fix (begin not refusing while stopped, and the retry deadline indistinguishable from the 1 ms owed-set kick) are the stopped-in-begin and owed-set-branch controls: at 5b54de3 (the pre-fix header) both survive because the guarded lines do not exist; at this head each is caught at the case that pins it. Registered in tools/aurora-ci/host-tests.json (base, --mutations, four single-mutant entries, the .c as a helper). Proof: plain run passes (18 cases, AGX-VOTE-SELFCHECK-OK); --mutations exits 0 with all four caught; --ref 5b54de3 --mutation stopped-in-begin and --mutation owed-set-branch print SURVIVED there. Signed-off-by: Joshua Warren <[email protected]>
…he mutation modes Review of 1142df9 by w7X, two non-blocking items folded in before push. Case 19 pins the signed 32-bit compare in agx_vote_reached: with idle_at 0xFFFFFFF0, idle_ms 100 and voted, decide at 0xFFFFFFF8 must be NONE and next must return the 92 ms to the wrapped deadline, and a retry_at that has wrapped must not read as reached either. The wrap-reached mutant (now >= t) survives the old cases because they jump straight to the wrapped deadline; it dies at line 306. Registered as a fifth mutation entry. The mutation modes now assert the unmutated suite passed first, so a base failure cannot make every mutant read as caught. The negative control (--ref) is exempt: the pre-fix header cannot compile this suite, which is the point. The suite runs under setarch -R when available; ASan startup crashes under ASLR on a loaded host otherwise. Proof: plain run passes; --mutations exits 0 with all five mutants caught; wrap-reached CAUGHT at line 306; at 5b54de3 the owed-set-branch and stopped-in-begin mutants still print SURVIVED. Signed-off-by: Joshua Warren <[email protected]>
…ff kick storm and the revived retry Three cases for chriskearney's findings on AsahiLinux#334, written first and red at this commit: - Case 20: an end lands between decide (SET) and applied. The end sees voted false, arms nothing, and applied then sets the vote with no user and an already-reached idle deadline. next() must return 1 there, not 0: 0 is the suite's "nothing pending", so the caller would never run the reconcile that clears the vote. - Case 21: an idle gap beyond half the 32-bit millisecond range makes the wrapped arithmetic read an expired retry deadline as future, which would keep the vote off for days. A retry deadline more than one backoff window in the future cannot be real and counts as reached. - Case 22: during backoff, begin must not ask for a reconciliation decide would refuse; the retry timer already drives the set. Three mutants pin them (set-write-ends, retry-revival, begin-backoff-kick), and stopped-in-begin now matches the begin line the fix will produce. Red here: case 20 fails at `agx_vote_next(&v, 5001) == 1`. Signed-off-by: Joshua Warren <[email protected]>
…try deadline and quiet the backoff kicks Three findings from chriskearney's review of AsahiLinux#334; the suite cases landed first (825e9ac, red) and this is the smallest change that turns them green. - end() during the SET write (between decide and applied) sees voted false and arms nothing; applied then leaves the vote set with no user and an already-reached idle deadline, and next() answered 0, which the caller reads as nothing pending. An already-reached deadline now returns 1, so the caller runs the reconcile that clears the vote. It settles one step later: decide CLEAR, applied, next 0. - A retry deadline more than one backoff window in the future cannot be real (an idle gap beyond half the 32-bit millisecond range reads an expired deadline as future through the wrapped compare), so the new agx_vote_retry_reached() treats it as expired instead of keeping the vote off for days. - begin() no longer asks for a reconciliation while a failed set is in backoff: decide would return NONE, and the retry timer already drives the set. One kick per operation during the window was pure waste. The mutants in tools/asahi/pmp-agx-vote-tests.py pin each: set-write-ends dies at the race assert, retry-revival at the bound assert, begin-backoff-kick at the kick-count assert, and the five earlier mutants still die. Plain suite: 22 cases, selfcheck ok. Signed-off-by: Joshua Warren <[email protected]>
…ot strand or spam the vote w7X's review of the first cut (a7330a5) found a blocking regression and two correct behaviours to keep. The gate on begin had to know the time, so agx_vote_begin() now takes now (the caller reads it under its lock; the glue passes apple_pmp_agx_now_ms() beside its existing end and next reads): - begin returns false during a failed-set backoff before the deadline (decide would return NONE; the retry timer drives the set), and true again once the deadline has passed. The first cut's unconditional !v->failures stranded the vote after one failed set whose retry timer fired idle: failures is only cleared by a successful SET, so every later begin refused forever. Case 23 is that sequence (failed set, end before the retry, timer fires idle, a later begin must kick and the set must land); the begin-ignores-retry mutant is exactly the first cut's expression and dies at it (line 363). - The other direction is pinned too: begin-backoff-kick (kick during the window regardless of the deadline) dies at the kick-storm case (line 357), so the gate cannot silently decay into "always kick" again. Case 23 exists because the simulator cases kept the operation alive through the backoff; this one ends it first. The begin signature change touches the suite's helper, four header-only call sites, and the one glue call. Proof: plain suite 23 cases selfcheck ok; --mutations catches all nine mutants (owed-set-branch, owed-failures, stopped-in-begin, stopped-in-decide, wrap-reached, set-write-ends, begin-backoff-kick, begin-ignores-retry, retry-revival); check-kick-guard still passes on pmp-report.c; the tree runner passes the registered vote entries. Signed-off-by: Joshua Warren <[email protected]>
w7X's re-review nit: next() takes the first match, so the second entry could never be selected. Nine distinct mutants; --mutations still passes. Signed-off-by: Joshua Warren <[email protected]>
…ommit) chriskearney's second blocker at efff25c: the last operation ends during a SET ack that then times out. applied records the failure with no user and no timer (next returns 0 on that path), and a begin before the retry deadline must arm the remaining delay instead of reporting no kick, or the retry never runs. The case also walks the release/resume cycle: an idle release does not write a clear, an idle resume does not kick, and a begin past the deadline still kicks. Red here: the begin result is 0 where the remaining 998 ms delay is required (FAIL line 397). Signed-off-by: Joshua Warren <[email protected]>
…e path could not chriskearney's second blocker at efff25c: when the last operation ends during a SET ack that then times out, applied records the failure with users already 0, so next() returns 0 on that path and no timer is armed. A begin before the retry deadline reported "no kick" (the clock gate from 2ec389c), so nothing ever ran the retry: the vote stayed off until some unrelated reconcile. agx_vote_begin() now returns the same delay contract as agx_vote_end(): 1 run the reconcile now, N arm it N ms out, 0 nothing pending. A begin inside a failed-set backoff arms the remaining delay; past the deadline it returns 1 as before; a voted overlap, stopped or disabled still return 0. The glue passes the delay to the kicker instead of a boolean, and an idle release/resume cycle does not clear the retry state, so the next begin still arms it. Case 24 (fb8cba3, red at line 397) walks the whole sequence including the release/resume variant. Controls re-pointed at the new return: begin-no-retry- arm (returns 0 where the delay belongs) and begin-backoff-kick (returns 1, the kick storm) both die; begin-ignores-retry is gone because the delay branch subsumes it. Proof: plain suite 24 cases selfcheck ok; --mutations catches all nine mutants; the tree runner passes the registered entries. Signed-off-by: Joshua Warren <[email protected]>
The residual w7X flagged on the delay contract: the end lands inside a failed SET write and no new operation starts. The write path arms nothing (users is already 0 when applied runs), so failures lingers with no timer, and a begin before the deadline reports "no kick". Case 25 walks it: the retry must be armed from the failure state itself, and when the retry fires with nobody waiting the backoff must be cleared once instead of re-arming forever. The header-alone asserts pin next(): 500 at 500 ms before the deadline, 1 at it. Red here: FAIL line 424, s.armed is false after the race. Signed-off-by: Joshua Warren <[email protected]>
…the operation The residual from the delay-contract review: when the last operation ends inside a failed SET write, applied records the failure with users already 0, and next() returned 0 on that path, so no timer existed and a begin before the deadline reported "no kick" (2ec389c's clock gate) - the retry never ran. next() now arms the retry from the failure state itself (users 0, not voted, failures set): the remaining delay, or 1 when the deadline is already reached. That alone would re-arm forever once the retry fired idle, so the work function also clears a spent backoff: a reconcile that finds nobody waiting and an expired deadline (decide returned NONE) sets failures to 0, and the state settles. A later operation then starts a fresh attempt, exactly like the first. Case 25 (4574c14, red at s.armed) walks the sequence through the release/resume cycle; the retry-dropped-when-idle mutant removes the new branch and dies there. The sim's begin helper now arms the returned delay (delay 1 is "due now" within a tick), case 23's spent-backoff assert and case 24's next() assert updated to the new contract. Plain suite 25 cases, ten mutants, all caught; the tree runner passes the registered entries. Signed-off-by: Joshua Warren <[email protected]>
…6001 The vote lifts the read roof from 241 to 368 GB/s and cuts decode time per token by 21 to 24 percent at 512, 2048 and 8192 tokens of context on a 16-inch M1 Max. pmp_report.agx_vote now defaults to on; pmp_report.agx_vote=0 turns it off. Only the t6001 has an AGX request. The vote state now reads agx_vote through apple_pmp_agx_enabled(), which also requires apple,t6001, so any other chip never votes and never counts a failed write while its GPU is busy. Signed-off-by: Joshua Warren <[email protected]>
5714e13 to
09613a9
Compare
|
CI is green on Two more measurements on the 16-inch M1 Max, same setup as the table above. Hold time. ctx8192 decode, 8 fresh processes in order off, 50, 100, 250, 250, 100, 50, off ms (the vote on with that hold): off 29.6 and 29.5 ms/token, 50 ms 22.3 and 22.3, 100 ms 22.3 and 22.4, 250 ms 22.4 and 22.3. Prefill: off 27.15 and 27.14 s, every vote-on process 23.97 to 23.99 s. On this 4B model the token gap is about 22 ms, far under 50 ms, so the hold does not change anything here. The 250 ms default stays for the 9B case in #334, where one token gap measured 118 ms. Idle power with light GPU activity (one tiny GPU evaluation every 100 ms in a process that keeps the GPU open, 150 s per segment, order off, on, on, off): vote on 11.63 and 11.45 W, vote off 11.75 W for the first segment. The last off segment read 24.55 W because another job was running on the machine, so I leave it out. The vote adds nothing measurable at idle with light activity either. |
|
Prefill on the 16-inch M1 Max, Qwen3-4B 4-bit, 8 fresh processes per context in order off, on, on, off, off, on, on, off:
No GPU timeout and no Thunderbolt event in any process. The vote speeds up prefill at both lengths, the same direction as decode. |
scottjones
left a comment
There was a problem hiding this comment.
Thanks Joshua, this is a really nice result. Getting memory out of idle DVFS while the GPU is busy is a real win, and the measurements on the 16-inch M1 Max make the case well.
A few things before it goes in:
-
Rebase once #334 lands. This sits on an older #334 head (merge-base 85a68bf), so it's missing c3487a5 (the half-range retry fix), bfb4186 and b36d019. Merging it first would also pull in 16 #334 commits that are still under review. A cherry-pick onto b36d019 applies cleanly with the vote tests passing, so it should be mechanical.
-
The retry path, now it's on by default. If the PMP stays READY, never acks bit 9, and the GPU stays busy, we retry every second (AGX_VOTE_RETRY_MS) with no end: a SET, a 50 ms busy-wait, a clear and a pr_err (pmp-report.c:1442-1445). That's about 5% of a CPU plus log spam, not a hang, and it didn't show up in your measurements. Since this turns it on for j314c, j316c and j375c, could you ratelimit the log and add a growing backoff or a cap?
-
Small one: could you cache the t6001 compatible check at init instead of calling of_machine_is_compatible() on every GPU begin/end (pmp-report.c:1369-1372)?
-
Sign-off: same ask as on #334: coding-assistants.rst asks that only the human author adds Signed-off-by, with an Assisted-by tag for assistant help. Could you re-sign this one yourself, with Assisted-by where it applies?
-
Later, when hardware allows: s2idle runs on j316c with agx_vote=0 and agx_vote=1. #329 puts that board on the PMP and it has an open failed-resume report. Not a blocker.
Happy to approve once it's rebased onto #334 with the backoff in.
|
[Joshua's agent] Thanks Scott, and sorry for the two days without a reply. Plan: rebase onto #334's new head once it's updated; ratelimit the retry log and add a capped, growing backoff (the same change as on #334); cache the t6001 compatible check at init; Joshua re-signs the commit himself, with Assisted-by. The s2idle runs on j316c with agx_vote=0 and agx_vote=1 are noted for when that hardware is free. |
|
Covered by aurora-silicon/linux commit a2fb0b2 (PMP report status made optional). Superseded by the Nov 17 consolidation to aurora-silicon/linux. [Joshua's agent] |
Stacked on #334: this branch carries the #334 commits plus one commit,
09613a933661. Review that commit only; the diff shrinks to it when #334 merges.#334 adds the AGX vote and leaves it off. This pull request turns it on by default on the t6001 and makes sure no other chip runs the vote path.
What the commit changes.
agx_votedefaults to true (pmp_report.agx_vote=0turns it off; the hold staysagx_vote_idle_ms, default 250).apple_pmp_agx_enabled(), which also requiresapple,t6001. Without it a default-on parameter would make every other chip with this driver try a write on each GPU burst, get-ENODEV, count a failure and retry once a second while the GPU is busy. A 14-inch M2 Max (t6021) already runs with the parameter set; decode there is flat (14.3 against 14.4 ms/token), so the vote is inert there, and now it also does no work.Measurements (16-inch M1 Max, lab kernel 7.1.12 form of the vote with the hold set to 250 ms; Qwen3-4B 4-bit, 256 generated tokens; each cell is 8 fresh processes in off, on, on, off, off, on, on, off order, ANE idle; the generated token ids hash is the same in every process):
Prefill at 8192 tokens: 27.2 s off, 24.0 s on (-11.6%).
Soak. 28 fresh 8192-token decode processes back to back with the vote on, two 13-minute runs (the second starts after the first ends), 0 GPU timeouts, 0 Thunderbolt or PCIe tunnel events in the kernel journal, decode 21.8 to 22.3 ms/token in every process.
Idle power (SMC total system power, 150 s per segment after a 20 s settle, no GPU process, order off, on, on, off): off 12.01 and 11.37 W, on 11.81 and 11.47 W. The segments differ by 0.6 W with no pattern between the arms, so the vote leaves idle power unchanged (it drops 250 ms after the last GPU operation).
Power under load. During decode the vote draws 2.5 W more at 512 tokens of context (54.0 against 51.5 W) and 5 W more at 2048 (65.5 against 60.4 W), a rise of 5 to 8 percent against a 21 percent shorter token time. These are whole-process means that include model load, so treat them as rough.
One open question. A GPU timeout storm on this machine at 16:54 CST coincided with a Thunderbolt authorization change made by another job in the same second (the journal shows the tunnel reset time out 22 ms before the first timeout). That run had the vote on. An earlier fault at 14:51 CST, before any vote run, carried the same address and fault tuple. The cause is not proven. No timeout occurred in any of more than 60 vote-on processes since, soak included.
Checked.
pmp-report.ccompiles with the lab kernel config (7.3.0 lab tree, clang 22) with no warning from the changed lines. The vote logic inpmp-agx-vote.his untouched, so the userspace policy test is unchanged. Not run: a full image boot of this exact commit; the measurements above used the lab-kernel form with the parameter set at run time.