Skip to content

drm/asahi: g17: count busy time across power gates, in timestamp order (#1611 follow-up) - #1879

Open
m0d16l14n1 wants to merge 2 commits into
aurora-silicon:mainfrom
m0d16l14n1:j815/g17-m5-stats-v2
Open

m0d16l14n1 wants to merge 2 commits into
aurora-silicon:mainfrom
m0d16l14n1:j815/g17-m5-stats-v2

Conversation

@m0d16l14n1

@m0d16l14n1 m0d16l14n1 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

The follow-up to #1611 that @DjDeveloperr asked for in this review, reworked from the two commits I offered there (8c58f1d, 2c515ec). Two commits on integration/aurora.

The problem

On a J815 (M5) under a frame-paced load (es2gears + vkcube, 20 s), the cores power-gate about 95 times a second (power_epoch 10861), usually with one utilisation record per power epoch. busy_ns stayed 0 although the 0x13 records kept arriving:

  • busy time needed two records in one epoch, because every boundary cleared the window start (busy_ts);
  • the records queued before a boundary, and those drained while the cores read gated, never reached the decoder.

What changed from the earlier commits, by review point

  • Accounting is separate from the utilisation epoch. The decoder keeps the firmware timestamp up to which it has credited busy time (busy_mark). Power gates, suspend and restarts keep it. A record at or before the mark adds nothing, so an older queued record, a repeat, or the other role's record for the same time is never credited twice in any drain order. This also covers drm/asahi: g17: M5: report the performance state, its frequency and busy time #1611's note 3 (one baseline for both roles).
  • The first record after a gap is qualified. It closes only its own 8 ms sampling period, and that period lies after the mark, so the gap is never credited. Within two periods of the mark a record closes the window since it, as before.
  • The cut-off records go to busy time only. record_busy() takes 0x13 records that a power boundary kept out, and nothing else. The utilisation average, its delivery cadence and the performance state never see them. Suspend, a real invalidation's discard and quarantine still keep everything out.
  • The pstate rule is unchanged here. No retained "valid while gated" state and no record_timed() path into the publisher. drm/asahi: g17: A18 Pro: report the performance state, its frequency and busy time #1853 changes the gated reading separately.
  • No gpu_power_gated and no per-pstate residency. Nothing new in the common formatter, so G16S/G17P output doesn't change.
  • Docs. The ABI and asahi-usage-stats.rst now describe the mark, the one-period rule and the busy-only path. They also fix "Tick deltas are never accumulated…" (drm/asahi: g17: M5: report the performance state, its frequency and busy time #1611 note 4: it is about tag 0x10).
  • Quarantine. busy_ns reads stale once a statistics ring is quarantined (drm/asahi: g17: M5: report the performance state, its frequency and busy time #1611 note 2), instead of a frozen value that reads valid.
  • The status-label commit (the part you called separable) prints stale/unavailable for pstate and achieved_frequency_hz instead of unsupported. Where pstate is unsupported, output is byte for byte the same, which includes every non-M5 G16S/G17P firmware through qualify().

Credited windows never overlap and each ends at its own record's timestamp, so busy_ns stays bounded by elapsed time.

Changed on this head (review)

  • The clock-restart bound is no longer a fixed 60 s. Protocol::rebase_ticks() is a full statistics ring (STATISTICS_SLOTS, 256) of the other role's utilisation records, one per interval, times two for margin: 4.1 s on the M5 (8 ms) and 8.2 s on the A18 Pro (16 ms). It follows the protocol's own period.
  • Rebased onto integration/aurora cc14570. Both commits carry only my Signed-off-by.
  • aurora.ko builds at each commit with W=1, with no new warnings. The Rust warnings it prints are the same at both commits and come from elsewhere in the driver.
  • The ring size is a local STATISTICS_RING_RECORDS (256, the same as fw::channels::STATISTICS_SLOTS), so telemetry.rs still builds on its own for the host tests. tools/asahi/run-host-tests.py --only telemetry passes 13/13 on this head, 4f86a73e, including the clock-restart case and every mutant.

Testing

  • Host: tools/asahi/run-host-tests.py --only telemetry 13/13, on each commit separately.
    • New decoder cases: a gate between every record, records kept out of the epoch, interleaved roles, a clock restart.
    • New ring case: records cut off at a gate and drained while gated count; a repeat from the other role does not; suspend keeps them out; quarantine reads stale.
    • Each of these mutants fails the tests: the mark reset at an epoch boundary, a record at or before the mark credited, the gap after a gate credited in full, record_busy dropped (in the decoder or in the ring), and record_busy without the percentage check.
    • The fixture's existing quarantine mutation still fails: the admission and the read share statistics_quarantined().
  • aurora.ko builds (LLVM, Rust 1.99) with no warnings in these files.
  • Not yet run on the J815 with this change. I'll post agx_stats and fdinfo under the same es2gears + vkcube load, plus busy_ns against the commands' own execution intervals from asahi_g17_report/asahi_g17_complete traces (as drm/asahi: g17: A18 Pro: report the performance state, its frequency and busy time #1853 did on the J700).

With #1853

These two commits conflict textually with #1853, since both rework telemetry.rs, the ABI doc and the formatter. I've rebased them onto #1853 at j815/g17-m5-stats-v2-on-1853, host tests 13/13 there. On that base the rule uses the firmware's own period, so it covers the A18 Pro's 16 ms records too. #1853's A18 Pro case then expects one 16 ms period after its >2-period gap instead of nothing. Whichever lands second, I'll switch this PR to match.

Still owed (HW rows): the busy_ns delta against the fdinfo engine-time delta over the 20 s es2gears + vkcube run on the J815 (ratio, and the power_epoch count). The same on an A18 Pro (Neo), which now uses the new gap rule too. Pass: busy_ns within a few percent of fdinfo and never above elapsed time; 0 failed units, 0 SELinux denials, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@m0d16l14n1 m0d16l14n1 changed the title drm/asahi: g17: M5: count busy time across power gates, in timestamp order (#1611 follow-up) drm/asahi: g17: count busy time across power gates, in timestamp order (#1611 follow-up) Nov 14, 2026
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

Rebased on integration/aurora 1f5037a, after #1853. Head is now 99daf59, still two commits.

#1853 moved the M5 decoder onto Protocol, so this is a port, not only a conflict fix:

  • busy_mark, record_busy() and the gap rule use Protocol::integrates_busy(), util_period_ticks and max_window_ticks() in place of the M5-only constants. The new accounting therefore applies to the A18 Pro too, with its 16 ms period. 25G83 is unchanged.
  • One A18 Pro expectation changes: in a18_pro_busy_time_integrates_16_ms_windows, a record more than two periods after the last now credits its own 16 ms period (28 → 32 ms) instead of only resetting the baseline. That is the same rule as on M5.
  • drm/asahi: g17: A18 Pro: report the performance state, its frequency and busy time #1853's gated reading (off, a valid 0) is kept as it is. The first commit now prints the status word only where the state isn't valid, so a gated GPU still reads pstate 0, achieved_frequency_hz 0.
  • Docs: the ABI and asahi-usage-stats.rst text for busy_ns describes both periods. The J700 measurement is kept and marked as taken with the earlier per-epoch windows.

Host tests (--only telemetry): the decoder's 13 cases, the integration fixture and every mutation pass, with no warnings. checkpatch --strict is clean. I haven't rebuilt aurora.ko or rerun this on the J815 in this form, so it stays a draft until I do.

@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr out of draft (#1611 follow-up). On the J815, pstate stays valid across the ~95 power gates per second under load (36/36 records), and busy_ns tracks fdinfo engine time. Green and mergeable; please review.

Assisted-by: Claude Opus 5.5

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

I checked the ordering logic in drivers/gpu/drm/asahi/g17/telemetry.rs:288-305. The mark - timestamp arm can't underflow, because it is only reached when timestamp <= mark. After a long gap, the credited period [ts - period, ts] starts after the mark, so credited windows can't overlap. record_busy() (telemetry.rs:269-280) applies the same tag and the same > 100 checks as record(). In channel.rs, accept_busy keeps suspend, discard and quarantine out of both paths, and only the power boundary is relaxed for busy time. The sysfs status words match asahi_stats_quality().

  1. Attribution: both commits (8629b26, 99daf59) carry Assisted-by: Claude Opus 5.5. Drop it from the commits, which keep your Signed-off-by. The PR body's last line should read Assisted-by: LLM (Claude:Opus 5.5).

  2. Nit, telemetry.rs:51: BUSY_REBASE_TICKS is a fixed 60 s, but its comment derives the bound from the ring (256 records). Compute it from what bounds a queued record, ring capacity x util_period_ticks with margin, so it follows the protocol's own period instead of a chosen constant.

HW row: the J815 comment reports pstate valid across gates (36/36) and busy_ns tracking fdinfo, but gives no numbers. Post busy_ns delta against the fdinfo engine-time delta over the 20 s es2gears + vkcube run (ratio, and power_epoch count). The A18 Pro now uses the new gap rule too, so run the same on a Neo. Pass criteria: busy_ns within a few percent of fdinfo, never above elapsed time, and the regression line showing 0 failed units, 0 SELinux denials and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

pstate and achieved_frequency_hz printed "unsupported" whenever
pstate_status wasn't valid. On a firmware that reports its state (M5,
A18 Pro), the state is "stale" after the cores power up, until the
firmware's next state report, and the file then read as a missing
feature. Print the status word instead. achieved_frequency_hz keeps
"unsupported" for a valid state with no frequency in the board's table.

busy_ns also gets a "stale" reading, for a total that stopped (used by
the next change); every other non-valid busy status still reads
"unsupported".

Where pstate is unsupported (25G83, and always there through
g17::stats::qualify), the status word is "unsupported", so that output
is byte for byte the same. The integration test's formatter cases follow
the new readings and check "busy_ns stale".

Signed-off-by: Nick <nekreshen@yandex.ru>
@m0d16l14n1
m0d16l14n1 force-pushed the j815/g17-m5-stats-v2 branch 2 times, most recently from 6440b4c to 4f86a73 Compare November 21, 2026 12:59
@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

@RyanTheTide fixed.

  1. The trailers are dropped.
  2. BUSY_REBASE_TICKS is replaced by Protocol::rebase_ticks() = 2 × STATISTICS_SLOTS × util_period_ticks: 4.1 s on the M5, 8.2 s on the A18 Pro.

Rebased onto cc14570, and aurora.ko builds with W=1 and no new warnings. The ring size is a local STATISTICS_RING_RECORDS, so telemetry.rs stays standalone for the host tests (13/13 on this head). The busy_ns vs fdinfo numbers (J815, and a Neo) are still owed.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 4f86a73: No blockers.

Earlier points:

  1. Resolved. Both commits (27320d8, 4f86a73) carry only the author's Signed-off-by, and the PR body ends with Assisted-by: LLM (Claude:Opus 5.5).
  2. Resolved. drivers/gpu/drm/asahi/g17/telemetry.rs:101 Protocol::rebase_ticks() is 2 x ring records x util_period_ticks (4.1 s at 192000 ticks, 8.2 s at 384000), and telemetry.rs:309 uses it. For Protocol::NONE it is 0, but record_busy() and the utilisation path return before integrate_busy() when integrates_busy() is false, so the zero bound is never used.

What changed since: only the rebase bound above. The other differences in channel.rs and sysfs.c come from the new base. I found no problems.

  1. Nit, telemetry.rs:51: STATISTICS_RING_RECORDS repeats fw::channels::STATISTICS_SLOTS (fw/channels.rs:30) with nothing tying the two. A const _: () = assert!(telemetry::STATISTICS_RING_RECORDS == STATISTICS_SLOTS); in g17/channel.rs, which is built only in the kernel and already imports STATISTICS_SLOTS, would catch a ring-size change while leaving telemetry.rs standalone for the host tests.

HW row (still open): over the 20 s es2gears + vkcube run on a J815 and on a Neo, the busy_ns delta against the fdinfo engine-time delta (ratio, and the power_epoch count). It passes if busy_ns is within a few percent of fdinfo, never above elapsed time, with 0 failed units, 0 SELinux denials and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

On a J815 (M5) under a frame-paced load (es2gears + vkcube, 20 s), the
cores power-gate about 95 times a second (power_epoch 10861), usually with
one utilisation record per power epoch. busy_ns stayed 0 although the
0x13 records kept arriving:

- busy time needed two records in one epoch, because every boundary
  cleared the window start (busy_ts);
- the records queued before a boundary, and those drained while the cores
  read gated, never reached the decoder.

Busy time now has its own ordering, separate from the utilisation epoch,
on every firmware whose Protocol integrates it (M5 and A18 Pro):

- The decoder keeps the firmware timestamp up to which it has credited
  busy time (busy_mark). Epoch boundaries keep it. A record at or before
  it adds nothing, so an older queued record, a repeat, or the other
  role's record for the same time is never credited twice, whatever the
  drain order.
- A later record closes the window since the mark when that is at most two
  utilisation periods, as before. After a longer gap it closes only its
  own period (8 ms on M5, 16 ms on the A18 Pro), which lies after the
  mark: the gap is never credited. Before, such a record only set the
  baseline. The first record after a gate now credits its period at its
  own device utilisation.
- Records a power boundary keeps out of the averaging epoch (cut off, or
  drained while gated) are decoded for busy time only (record_busy). The
  utilisation average, its delivery cadence and the performance state do
  not see them. Suspend, a real invalidation's discard and quarantine
  still keep everything out.
- A record further behind the mark than a full statistics ring of
  utilisation records (256 x the record interval, twice over: 4.1 s at
  8 ms, 8.2 s at 16 ms) cannot still be queued; it means the firmware
  clock started again and only sets a new mark.
- busy_ns reads stale once a statistics ring is quarantined, since
  nothing adds to it any more.

Credited windows never overlap and each lies at or before its own
record's timestamp, so busy_ns stays bounded by elapsed time. 25G83
integrates no busy time and is unchanged. The gated performance state
(off, valid 0) is left as it is.

Host tests: tools/asahi/run-host-tests.py --only telemetry passes: the
decoder's 13 cases, the integration fixture and every listed mutation.
New decoder cases: gates between every record, records kept out of the
epoch, interleaved roles, clock restart. The A18 Pro window case now
expects a record after a gap longer than two periods to credit its own
16 ms period. New ring case: records cut off at a gate and drained
while gated count, a repeat from the other role does not, suspend keeps
them out, quarantine reads stale. The fixture's quarantine mutation now
hits both the admission and the read, through statistics_quarantined().

Not yet run on hardware in this form; the M5 behaviour is the one
measured on the J815 before the A18 Pro protocol work.

Signed-off-by: Nick <nekreshen@yandex.ru>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 412fe1e: no blockers. The only change since 4f86a73 is the compile-time check that ties the decoder's ring size to the firmware ring (drivers/gpu/drm/asahi/g17/channel.rs:18-20; both are u32). telemetry.rs stays standalone for the host tests.

HW row (still owed, at 412fe1e): run the 20 s es2gears + vkcube load on a J815 and on a Neo, and post the busy_ns delta against the fdinfo engine-time delta (ratio and power_epoch count). Pass: busy_ns within a few percent of fdinfo and never above elapsed time, with 0 failed units, 0 SELinux denials and 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@m0d16l14n1

Copy link
Copy Markdown
Contributor Author

@RyanTheTide nit done in 412fe1e8. STATISTICS_RING_RECORDS is pub(crate), and g17/channel.rs asserts it at build time with const _: () = assert!(super::telemetry::STATISTICS_RING_RECORDS == STATISTICS_SLOTS);. telemetry.rs still builds on its own for the host tests.

Checks: aurora.o builds in-tree with W=1 and no warnings in channel.rs or telemetry.rs, and the telemetry host tests pass 13/13.

The busy_ns against fdinfo rows (J815 and a Neo) are still owed.

Assisted-by: LLM (Claude:Opus 5.5)

@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026

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

Verdict: HOLD at 412fe1e8

Blockers:

  • drivers/gpu/drm/asahi/g17/channel.rs:20 / tools/asahi/g17-telemetry-integration-tests.py:70 (CI failure): host-tests failed (E0080: assertion failed: super::telemetry::STATISTICS_RING_RECORDS == STATISTICS_SLOTS) because the integration fixture stubs STATISTICS_SLOTS = 8 while STATISTICS_RING_RECORDS = 256. Fix by guarding the compile-time assertion (e.g. #[cfg(not(test))]) or passing STATISTICS_SLOTS into the decoder so the constant is not duplicated, and re-verify the full tools/asahi/run-host-tests.py --only telemetry suite (including the integration fixture and its mutations).
  • Rebase / merge conflicts (CONFLICTING against main): #2864 (ad9558d5860d) refactored Protocol (Protocol::PSTATE_8MS / Protocol::PSTATE_16MS), Rings::new(graph, protocol, max_pstate), sysfs.c, the integration fixture, and the stats docs to enable pstate/busy-time telemetry on T6041 (M4 Max, 25G83). Rebase onto live main and update the PR/docs/comments where they still assume 25G83 never integrates busy time (only T6040 25G83 stays on Protocol::NONE).
  • PR body (§4 attribution): remove the AI-attribution footer at the end of the PR description (current policy prohibits tool/model attribution anywhere in PR bodies, comments, or commits; commits 27320d85 and 412fe1e8 are already clean).
  • PR body & HW evidence (§5): add the required What:, Tested:, Risk:, and Not yet: header lines, and post on-hardware results at the rebased head SHA (busy_ns delta vs fdinfo engine-time delta, ratio, power_epoch count, bounded by elapsed time) plus the regression line (0 SELinux denials, 0 failed units, 0 new kernel errors) on M5 and A18 Pro (and T6041 after rebasing onto #2864, or explicitly request runs on hardware you don't have).

Checked: Code diff (telemetry.rs, channel.rs, sysfs.c, docs, integration tests), §1–§6 pre-PR checklist, commit hygiene (27320d85, 412fe1e8), CI (host-tests failed), mergeability (CONFLICTING), and HW evidence rows.

Evidence

Code audit

  • Timestamp ordering & math (drivers/gpu/drm/asahi/g17/telemetry.rs:102-104, 278-314): Core algorithm is sound.
    • gap = timestamp - mark is guarded by timestamp > mark; mark - timestamp is only evaluated when timestamp <= mark (no underflow).
    • For gap <= max_window_ticks() (at most 2 * util_period_ticks, 768,000 ticks at 16 ms), window * u64::from(device) * 1_000_000_000 is at most 7.68e16 (< u64::MAX), and busy_ns uses saturating_add.
    • After a gap > 2 * util_period_ticks, crediting only util_period_ticks ([ts - period, ts]) starts strictly after mark, so credited windows never overlap and busy_ns stays bounded by elapsed time.
    • Interleaved Primary/Secondary role drains serialize under the device mutex and share one busy_mark, preventing double-counting in any drain order.
    • Clock-restart fallback (mark - timestamp > rebase_ticks()) resets busy_mark without crediting.
  • Power-gate / suspend / quarantine gating (drivers/gpu/drm/asahi/g17/channel.rs:180-194, 225-245, 305-313):
    • accept_busy keeps suspend, invalidation discard (discard_statistics), and quarantine (statistics_quarantined()) out of both record() and record_busy(). Only power-gate cutoffs and records drained while gated route to record_busy(), leaving utilisation averages, delivery cadence, and pstate untouched.
    • read_statistics() converts busy_status from VALID to STALE once either role's statistics ring is quarantined.
    • channel.rs:20 compile-time assertion breaks the host integration fixture where STATISTICS_SLOTS is stubbed to 8.
  • Sysfs formatting & non-regression (drivers/gpu/drm/asahi/sysfs.c:105-130):
    • Legacy G13–G16 path (stats->read == NULL) is untouched.
    • On Protocol::NONE, g17::stats::qualify() forces pstate_status = UNSUPPORTED and busy_status = UNSUPPORTED, keeping output unchanged.
    • Minor non-blocking nit: the comment on the busy_status == 2 branch in sysfs.c says M5:, whereas after #1853 and #2864 busy-time integration applies to every protocol with util_period_ticks != 0 (M5, A18 Pro, T6041). Same for the commit/doc notes that say 25G83 never integrates busy time.

Pre-PR checklist (§1–§6)

  • §1 (No model gating): Pass in the diff logic (keyed on Protocol::integrates_busy() and util_period_ticks). Needs rebase onto #2864's Protocol::PSTATE_8MS/PSTATE_16MS refactor.
  • §2 (Production-ready): Pass — default kernel command line, no new params, no sleep/retry workarounds.
  • §3 (Safety): Pass — read-only telemetry accounting and sysfs output; no hardcoded hardware protection limits.
  • §4 (IP & attribution): Commits 27320d85 and 412fe1e8 carry only Signed-off-by: Nick <nekreshen@yandex.ru> (clean). Blocker: PR body still carries an attribution footer at the bottom; remove it.
  • §5 (Evidence & PR structure): Blocker: PR body lacks What: / Tested: / Risk: / Not yet: lines, and exact-head HW + regression rows are still owed.
  • §6 (Naming): Pass.

CI & Mergeability

  • host-tests (Host tests, run 45039037435 / job 137259128493): FAILURE — g17-telemetry-integration-tests.py fails to compile g17/channel.rs:20 (error[E0080]: evaluation panicked: assertion failed: super::telemetry::STATISTICS_RING_RECORDS == STATISTICS_SLOTS).
  • Mergeability: CONFLICTING (mergeStateStatus: DIRTY) against main (base 371066885814 predates #2864 ad9558d5860d).

@github-actions github-actions Bot added changes-requested A reviewer requested changes (bot) merge-conflict Conflicts with the base branch (bot) and removed merge-conflict Conflicts with the base branch (bot) labels Nov 24, 2026
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) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) merge-conflict Conflicts with the base branch (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants