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:integration/aurorafrom
m0d16l14n1:j815/g17-m5-stats-v2
Open

m0d16l14n1 wants to merge 2 commits into
aurora-silicon:integration/aurorafrom
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants