Skip to content

drm/asahi: m3, g15: expose qualified agx_stats and gpu_memory sysfs - #3490

Merged
DjDeveloperr merged 7 commits into
mainfrom
drm-asahi/m3-g15-agx-stats-sysfs
Dec 3, 2026
Merged

DjDeveloperr merged 7 commits into
mainfrom
drm-asahi/m3-g15-agx-stats-sysfs

Conversation

@maralcbr

@maralcbr maralcbr commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What: Expose qualified agx_stats, gpu_memory / gpu_mem_limit_pct sysfs attributes, and live DRM fdinfo frequencies (drm-curfreq-* / drm-maxfreq-*) on Apple M3 (m3/ T8122) and M3 Pro/Max (g15/ T6030/T6031/T6034) GPUs by generalizing QualifiedReader, adding the stats_m3 accumulator, ordering M3 receive-ring consumer releases with dma_mb(Full), unifying G15/M3 stats ring consumption, draining queued records across PM suspend/resume boundaries, and keeping M3 qualified stats stale while asleep or sleep-held.
Tested: Exact-head 4188bb7c (7.3.0-lab4188bb7c-1780): J614s M4 Pro G17 (boot-health pass, 0 GPU faults, agx_stats firmware-statistics-tag-0x13 17% -> 97%, pstate 2 -> 10, busy_ns 22.6 -> 4776.2 ms, gpu_memory live), J700 A18 Pro G17P (boot-health pass, 0 GPU faults, agx_stats 0% -> 62% -> 0%, pstate 0 -> 10 -> 0, 1470 MHz, gpu_memory live), J416c M2 Max legacy G14 (boot-health pass, 0 GPU faults, legacy agx_stats 14% -> 100%, 444 -> 1398 MHz, gpu_memory intact), and J813 M5 Air (boot-health pass, 0 GPU faults); all host and mutation test suites pass at 4188bb7c (g15-stats-drain-tests.py --mutations 10/10 mutations killed, stats_m3.rs 7/7, m3-sleep-steps-tests.py 4/4, g17-telemetry-integration-tests.py 35/35 + 512 legacy checks). Earlier carry runs: J514s M3 Pro G15S on 7.3.0.aurora4-1 (e6e8509a + #2148: first live G15 telemetry proof, 0% -> 100%, pstate 0 -> 8, 1380 MHz, busy_ns 0 -> 9992 ms, fdinfo 1380 MHz, gpu_memory live, 0 GPU faults); J613 M3 Air (m3/ T8122, equivalent carry/aurora-7.3 tree: idle/load/idle agx_stats, gpu_memory, fdinfo, 0 regressions).
Risk: two-way · M3, M3 Pro, M3 Max (new sysfs export, receive-ring release barrier, deep-sleep stats guard); shared QualifiedReader / sysfs.c refactor touches G17 (M4/M5/Neo) and legacy M1/M2
Not yet: Exact-head 4188bb7c J516s M3 Pro (g15/) live boot + sleep cycle (frontier run requested), exact-head 4188bb7c M3 base (m3/ J613/J615) boot + deep-sleep run (our lab J613 is offline needing hands), and discarding queued ring records on fault/recovery invalidate() (follow-up).

Details
  • Pure telemetry accumulator (drivers/gpu/drm/asahi/stats_m3.rs):
    • Decodes firmware statistics channel tag 0x04 (utilization on legacy 14.7 profile), tag 0x0b (p-state/frequency), and tags 0x02/0x03 (power on/off).
    • Integrates busy_ns and drops the baseline on power-off and suspend so idle intervals are never credited.
    • Clears utilization/pstate/frequency to idle (0%, pstate 0, 0 Hz) immediately on power-gating.
    • Reports utilisation_status unsupported / utilisation_source unsupported honestly on the extended M3 profile rather than fabricating values, and latches had_pstate on valid hardware-derived pstate reads so suspend, sleep-hold, and fault readouts report stale rather than unavailable.
  • Generalized qualified reader (stats.rs, sysfs_exports.rs, sysfs.c, sysfs.h, g17/):
    • Replaces G17-only g17_reader / register_g17 with QualifiedReader (G17, G15, M3) and register_qualified().
    • Uses the existing trailing u32 pad in struct asahi_qualified_stats as util_source (0 = firmware-statistics-tag-0x13, 1 = firmware-statistics-tag-0x04, 2 = unsupported, otherwise unknown), keeping legacy ABI byte-identical.
    • Updates tools/asahi/legacy-frequency-tests.rs for QualifiedReader and documents M3/G15 semantics (including PM suspend/resume boundaries and aurora.stats_export=0) in Documentation/ABI/testing/sysfs-driver-asahi-agx-stats.
  • Receive-ring ordering, unified consumers, PM boundaries, and M3 deep-sleep guard (m3/, g15/):
    • m3/agx_memory.rs adds release_slots() wrapping kernel::sync::barrier::dma_mb(Full) (dmb osh on arm64) before consumer-index stores in legacy drain(), drain_stats_only(), and drain_extended(), dropping redundant pre-read publish() calls (m3_memory::read_u32()/read() already emit acquire barriers).
    • Single transactional stats-ring consumer on both G15 (Channels::drain_stats called by Channels::drain_rings and g15::stats::Reader::read) and M3 (Config::drain_stats_only called by Config::drain and Config::read_qualified_stats), plus compile-time pstate::STATES == board::DVFS_STATES check.
    • PM suspend/resume boundaries (Channels::stats_boundary / Config::stats_boundary) drain queued records under the old admission state before flipping Telemetry::suspended, with backend health checks and a G15 faulted-drain drain_one fallback.
    • After merging main (#3504 M3 deep sleep), m3_runtime.rs guards read_qualified_stats() on inner.asleep (returning a suspended readout without touching MMIO or shared rings) and keeps telemetry suspended across PM_POST_SUSPEND while inner.sleep_held holds firmware stopped after an aborted deep sleep (CompleteAction::Hold).
    • probe_t8122 and probe_g15 register agx_stats + gpu_memory + gpu_mem_limit_pct with rollback on error; probe_g15 configures memacct::LEDGER.
Evidence

Host & mutation tests (at 4188bb7c)

  • tools/asahi/g15-stats-drain-tests.py --mutations: 68,121 consumer/producer pairs, moving-producer exact-once telemetry checks, mid-drain transactional fault check, suspend/resume/faulted-resume boundary checks, and 10/10 mutations killed (boundary-flip-first, boundary-skip-fallback, no-read-barrier, no-release-barrier, no-telemetry, no-wrap, oldest-power-state, resample-producer, skip-fallback, unconditional-consume)
  • tools/asahi/g17-telemetry-integration-tests.py: 35/35 Rust tests + 512 byte-identical legacy prefixes/frequency lookups, G17 capabilities, PM lifecycle and rollback pass
  • tools/asahi/g17-telemetry-tests.rs: 16/16 pass
  • tools/asahi/legacy-frequency-tests.rs: 2/2 pass
  • tools/asahi/asahi-stats-raw-tests.py: 4/4 pass
  • tools/asahi/agx-stats-busy-tests.py (+ --negative-control): 5/5 pass
  • tools/asahi/m3-sleep-steps-tests.py: 4/4 pass
  • drivers/gpu/drm/asahi/stats_m3.rs (rustc --test --edition 2021 -D warnings): 7/7 pass (including extended_profile_latches_pstate_across_suspend_hold_and_fault)

Exact-head 4188bb7c hardware runs (kernel 7.3.0-lab4188bb7c-1780, clang 19.1.7 + rustc 1.93.1, 0 warnings in changed files)

  • J614s M4 Pro (G17, shared QualifiedReader/sysfs.c non-regression):
    • boot-health: pass (0 failed units); 0 GPU faults.
    • /sys/class/drm/card0/device/{agx_stats,gpu_memory,gpu_mem_limit_pct} = 0444/0444/0644, readable unprivileged.
    • utilisation_source firmware-statistics-tag-0x13 preserved; 5 s GLES3 load (Apple M4 Pro (G16S B1), 2966 frames) raises util_device_percent 17 -> 97, pstate 2 -> 10, busy_ns 22.6 ms -> 2402.5 ms -> 4776.2 ms; gpu_memory live (user_resident 789 -> 893 MiB, limit 33499 MiB).
  • J700 A18 Pro (G17P, shared QualifiedReader/sysfs.c non-regression):
    • boot-health: pass (0 failed units); 0 GPU faults.
    • utilisation_source firmware-statistics-tag-0x13; 5 s GLES3 load (Apple A18 Pro (G17P B1)) raises util_device_percent 0 -> 62 -> 0, pstate 0 -> 10 -> 0, achieved_frequency_hz 0 -> 1470000000 -> 0, busy_ns 96.6 ms -> 1225.0 ms; gpu_memory live.
  • J416c M2 Max (legacy G14C agx_stats + engine_frequency non-regression):
    • boot-health: pass (0 failed units); 0 GPU faults.
    • Legacy agx_stats (util1..4 14 -> 100, pstate 1 -> 8, requested_frequency_hz 444 -> 1398 MHz, busy_ns 0 -> 2472 ms -> 4952 ms) + gpu_memory intact.
  • J813 M5 Air: boot-health: pass (0 failed units); 0 GPU faults.

Earlier carry hardware runs (pre-4188bb7c)

  • J514s M3 Pro (G15S on 7.3.0.aurora4-1, carrying e6e8509a + #2148 — first live G15 telemetry proof, predates d8d6a0cc..4188bb7c):
    • boot-health: pass, omarchy-m-test: pass (0 regressions, gpu.driver + gpu.vulkan fixed); 0 GPU faults.
    • agx_stats (firmware-statistics-tag-0x04): idle 0% / pstate 0 / 0 Hz / busy_ns 0 -> 10 s GLES3 load (Apple M3 Pro (G15S B1), 4711 frames) 100% / pstate 8 / 1380 MHz / busy_ns 2992 ms -> post-load idle 0% / pstate 0 / 0 Hz / busy_ns 9992 ms; fdinfo drm-curfreq-*/drm-maxfreq-* 1380 MHz; gpu_memory live (user_resident 545 MiB, limit 11799 MiB).
  • J613 M3 Air (T8122 m3/, equivalent carry/aurora-7.3 tree): boot-health + omarchy-m-test (45 pass, 0 regressions); idle -> 5 s GLES3 load (Apple M3 (G15G C0), 100%, pstate 2, 618 MHz, busy_ns +5160.1 ms, fdinfo 618 MHz / 1338 MHz) -> immediate post-load idle (0%, pstate 0, 0 Hz).

Expose qualified `agx_stats` and `gpu_memory` / `gpu_mem_limit_pct` sysfs
attributes and live DRM fdinfo frequencies (`drm-curfreq-*` /
`drm-maxfreq-*`) on Apple M3 (T8122 `m3/`) and M3 Pro/Max (T6030/T6031/
T6034 `g15/`) GPUs, matching the qualified G17 ABI without inventing
unsupported metrics.

Key changes:
- Add `stats_m3.rs` pure accumulator (with host unit tests) consuming M3/G15
  firmware statistics channel records:
  - Tag `0x04` (8-byte utilization record, legacy 14.7 profile) for
    `util_gpu_percent` / `util_avg_percent` / `util_max_percent` and
    monotonically integrated `busy_ns` (reusing `stats_busy::BusyTime`,
    dropping baseline on power-off/suspend so idle gaps are never credited).
  - Tag `0x06` / `0x02` (p-state/frequency) and tag `0x0a` (power-off) for
    qualified `pstate`, `requested_frequency_hz`, `achieved_frequency_hz`,
    and immediate idle clearing (`0%`, `pstate 0`, `0 Hz`) when power-gated.
  - Extended M3 profile reports `utilisation_status unsupported` and
    `utilisation_source unsupported` honestly rather than fabricating zeros.
- Generalize `StatsSnapshot::qualified_reader` (`QualifiedReader` enum for
  G17, G15, and M3) and `sysfs_exports::register_qualified()` so both
  `probe_t8122` and `probe_g15` register `agx_stats` + `gpu_memory` +
  `gpu_mem_limit_pct` with clean error rollback and PM suspend callbacks.
- Configure `memacct::LEDGER` in `probe_g15` so `gpu_memory` limits are
  initialized for G15.
- Wire `m3/m3_stats.rs` (`m3_drm.rs`, `m3_runtime.rs`, `m3_config.rs`,
  `m3_adt_config.rs`) and `g15/stats.rs` (`g15/channel.rs`, `g15/power.rs`,
  `g15/mod.rs`) without waking a powered-down GPU on sysfs reads.
- Extend `asahi_qualified_stats.util_source` (using the existing trailing
  u32 pad) and document `firmware-statistics-tag-0x04` and `unsupported` in
  `Documentation/ABI/testing/sysfs-driver-asahi-agx-stats`.

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
@maralcbr
maralcbr requested review from a team and DjDeveloperr as code owners November 28, 2026 05:38
maralcbr added a commit to omacom/linux-aurora that referenced this pull request Nov 28, 2026
Expose qualified `agx_stats` and `gpu_memory` / `gpu_mem_limit_pct` sysfs
attributes and live DRM fdinfo frequencies (`drm-curfreq-*` /
`drm-maxfreq-*`) on Apple M3 (T8122 `m3/`) and M3 Pro/Max (T6030/T6031/
T6034 `g15/`) GPUs, matching the qualified G17 ABI without inventing
unsupported metrics.

- Add `stats_m3.rs` pure accumulator (with 6 unit tests) consuming M3/G15
  firmware statistics channel tags `0x04` (utilization on legacy 14.7
  profile), `0x06`/`0x02` (p-state/frequency), and `0x0a` (power-off),
  integrating `busy_ns` via `stats_busy::BusyTime` and clearing to idle
  immediately on power-gating.
- Generalize `StatsSnapshot::qualified_reader` (`QualifiedReader` enum for
  G17, G15, and M3) and `sysfs_exports::register_qualified()`, registering
  `agx_stats` + `gpu_memory` + `gpu_mem_limit_pct` in `probe_t8122` and
  `probe_g15` (including `memacct::LEDGER.configure()` in `probe_g15`).
- Reuse `asahi_qualified_stats`'s trailing u32 pad as `util_source` and
  document `firmware-statistics-tag-0x04` and `unsupported` in
  `Documentation/ABI/testing/sysfs-driver-asahi-agx-stats`.

[7.3 carry port of aurora-silicon/linux#3490 (717a6ff) onto
carry/aurora-7.3 (3058cc5), resolving context diffs against intake
00cbc67 (pre-g14_v27_2 and pre-frequencies_hz).]

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 28, 2026
@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Merge readiness at 4188bb7c: ready to merge

Check Detail
CI at head ok 11 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 4188bb7c
Conflicts ok none
PR text ok Risk: two-way · M3, M3 Pro, M3 Max (new sysfs export, receive-ring release barrier, deep-sleep stats guard); shared QualifiedReader / sysfs.c refactor touches G17 (M4/M5/Neo) and legacy M1/M2

Areas: area:gpu
Merge: gh pr merge 3490 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

satchlj
satchlj previously approved these changes Nov 28, 2026

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code-reviewed exact head 717a6ff246.

  • Clean generalization of QualifiedReader across G17/G15/M3 preserving the StatsSnapshot ABI layout assertions (offset_of!(StatsSnapshot, qualified_reader) == 56) and reusing the existing trailing u32 pad in struct asahi_qualified_stats as util_source (0 preserves G17 firmware-statistics-tag-0x13).
  • stats_m3.rs is pure core-only Rust with bounds-checked table lookups, no panicking unwraps, and explicit suspend/power-off baseline drops so idle time is not credited to busy_ns.
  • probe_g15 / probe_t8122 wire register_qualified() cleanly with error rollback and non-waking stats-ring drains.

(Note: review is code-only; M3 Pro/Max g15/ hardware boot remains untested per PR notes.)

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 28, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@maralcbr thanks, this is close. Here's everything left in one list. Fix these three and it merges:

  1. host-tests fails at 717a6ff2: tools/asahi/legacy-frequency-tests.rs still uses the old reader. It builds StatsSnapshot { g17_reader: Some(g17::stats::Reader), .. }, and its stub g17 module has no telemetry, so stats.rs:54/56/66 (crate::g17::telemetry::Readout, reader.read(), reader.suspend()) don't compile there (E0433/E0599/E0560, log). Update the harness to QualifiedReader/register_qualified() and give its stub g17 a telemetry::Readout, then run python3 tools/asahi/run-host-tests.py --only legacy-frequency.
  2. pr-text: add a plain Tested: line and a Risk: line naming the door (one-way or two-way) and the Macs it touches. Guide.
  3. Hardware row at the exact head: your M3 Air run was on an equivalent carry/aurora-7.3 tree. I'll run the same checks on our J615 (M3 Air, T8122) at your next head: the three sysfs nodes, idle/load/idle values, fdinfo frequencies, one s2idle cycle, 0 GPU faults. The M3 Pro/Max (g15/) live boot can follow as a known-gap issue. It doesn't block the merge.

If you can't get to item 1 by 12-01 12:00 AEDT, I'll push the harness fix to the branch myself. That fix is test-only, so it doesn't invalidate the row.

Update `tools/asahi/legacy-frequency-tests.rs` to construct
`StatsSnapshot.qualified_reader` with `QualifiedReader::G17` and provide
the `g17::telemetry::Readout` + `read()`/`suspend()` stubs required by
the generalized `QualifiedReader` dispatch in `stats.rs`.

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 21:16
maralcbr added a commit to omacom/linux-aurora that referenced this pull request Dec 1, 2026
carry.toml: carry aurora-silicon/linux#3490 (M3/G15 qualified agx_stats + gpu_memory)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Receive-ring acknowledgements use a store-only barrier, allowing firmware to reuse slots before payload reads complete.

3 open issues
What changed in this PR

Extends the Asahi DRM driver’s qualified telemetry to M3 and M3 Pro/Max GPUs, using the shared infrastructure already serving G17.

Changes:

  • Adds an M3 statistics accumulator and backend readers for utilisation, busy time, performance state, and frequency.
  • Wires sysfs telemetry, GPU memory attributes, and live DRM fdinfo frequencies into M3/G15 registration.
  • Generalizes the qualified-reader interface, documents utilisation sources, and updates frequency tests.
File Description
tools/​asahi/​legacy-frequency-tests.rs Adapts frequency tests to QualifiedReader.
drivers/​gpu/​drm/​asahi/​sysfs.h Reuses padding for the utilisation-source selector.
drivers/​gpu/​drm/​asahi/​sysfs.c Reports backend-specific utilisation sources.
drivers/​gpu/​drm/​asahi/​sysfs_exports.rs Generalizes registration and telemetry callbacks.
drivers/​gpu/​drm/​asahi/​stats.rs Adds shared G17/G15/M3 reader dispatch.
drivers/​gpu/​drm/​asahi/​stats_m3.rs Adds telemetry decoding, accumulation, and unit tests.
drivers/​gpu/​drm/​asahi/​m3/​mod.rs Enables the M3 statistics-reader module.
drivers/​gpu/​drm/​asahi/​m3/​m3_stats.rs Adds the mutex-protected M3 reader.
drivers/​gpu/​drm/​asahi/​m3/​m3_runtime.rs Exposes runtime telemetry and suspend hooks.
drivers/​gpu/​drm/​asahi/​m3/​m3_drm.rs Retains and exposes the M3 statistics snapshot.
drivers/​gpu/​drm/​asahi/​m3/​m3_config.rs Feeds telemetry from firmware records and hardware state.
drivers/​gpu/​drm/​asahi/​m3/​m3_adt_config.rs Reads live hardware performance-state words.
drivers/​gpu/​drm/​asahi/​g17/​telemetry.rs Shares status constants and adds source metadata.
drivers/​gpu/​drm/​asahi/​g17/​mod.rs Wraps the existing reader in QualifiedReader.
drivers/​gpu/​drm/​asahi/​g15/​stats.rs Adds G15 statistics draining and qualified readouts.
drivers/​gpu/​drm/​asahi/​g15/​power.rs Makes hardware-state reads available to telemetry.
drivers/​gpu/​drm/​asahi/​g15/​mod.rs Creates and exposes the G15 statistics snapshot.
drivers/​gpu/​drm/​asahi/​g15/​channel.rs Adds telemetry state and polling integration.
drivers/​gpu/​drm/​asahi/​driver.rs Registers M3/G15 exports and configures G15 memory accounting.
drivers/​gpu/​drm/​asahi/​asahi_core.rs Includes the shared M3 accumulator module.
Documentation/​ABI/​testing/​sysfs-driver-asahi-agx-stats Documents M3/G15 telemetry capabilities and sources.

Review effort: Balanced

Comment thread drivers/gpu/drm/asahi/m3/m3_config.rs Outdated
.record_bytes(&raw, now_ns, self.freq_table.max_state());
r = (r + 1) % COUNT;
}
agx_memory::publish();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d8d6a0c (drm/asahi: m3: order receive-ring slot loads before consumer stores): added agx_memory::release_slots() wrapping kernel::sync::barrier::dma_mb(Full) (dmb osh on arm64) before the consumer-index store in legacy drain(), drain_stats_only(), and drain_extended(), and removed the redundant pre-read publish() calls (m3_memory::read_u32()/read() already emit acquire barriers).

Comment thread drivers/gpu/drm/asahi/g15/channel.rs Outdated
Comment on lines 403 to 404
self.channels.drain_stats_only(super::engine::now_ns())?;
self.channels.drain_rings(&dev, &mut self.events)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 71867b6 (drm/asahi: m3, g15: consume the stats ring in one place): unified G15 stats consumption in Channels::note_stats() + transactional Channels::drain_stats(now_ns) called by Channels::drain_rings() and g15::stats::Reader::read(), removing the duplicate pre-drains and g15/stats.rs consumer. Also unified M3 stats consumption through Config::drain_stats_only() and extended tools/asahi/g15-stats-drain-tests.py with moving-producer exact-once telemetry checks and a no-telemetry mutation.

Comment on lines +244 to +246
pub(crate) fn suspend(&mut self, suspended: bool) {
self.suspended = suspended;
self.invalidate();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8ba26a7 (drm/asahi: m3, g15: drain stats ring at PM suspend/resume boundaries): added Channels::stats_boundary() (G15) and Config::stats_boundary() (M3) to drain queued stats records under the old admission state before flipping Telemetry::suspended, with backend health checks in both readers, a G15 faulted-drain drain_one fallback, and suspend/resume/faulted-resume boundary tests + mutations in tools/asahi/g15-stats-drain-tests.py.

@github-actions github-actions Bot added blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) and removed ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 1, 2026
Neither M3 nor G15 powers firmware down across s2idle, so pre-suspend or
sleep-epoch records left queued in the firmware statistics ring could be
drained after resume and stamped with the post-resume host clock as fresh
valid samples.

Drain the statistics ring under the old admission state before flipping
`Telemetry::suspended` at PM boundaries (`Channels::stats_boundary` on
G15, `Config::stats_boundary` on M3):
- On `suspend(true)`, genuine pre-suspend records are flushed before
  invalidating and gating admission.
- On `suspend(false)`, queued records are consumed while `suspended` is
  still `true` (so they are never admitted into `Telemetry`), before
  opening the post-resume epoch.
- Check backend health in `g15::stats::Reader::suspend` and
  `m3::m3_runtime::Runtime::suspend_stats` before touching rings, and add
  a `drain_one` fallback on G15 boundary drain errors so faulted records
  are not left queued across resume.
- Document the boundary contract in `stats_m3.rs` and the sysfs ABI doc,
  and add suspend, resume, and faulted-resume tests plus
  `boundary-flip-first` and `boundary-skip-fallback` mutations to
  `tools/asahi/g15-stats-drain-tests.py`.

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
maralcbr added a commit to omacom/linux-aurora that referenced this pull request Dec 2, 2026
Expose qualified `agx_stats` and `gpu_memory` / `gpu_mem_limit_pct` sysfs
attributes and live DRM fdinfo frequencies (`drm-curfreq-*` /
`drm-maxfreq-*`) on Apple M3 (T8122 `m3/`) and M3 Pro/Max (T6030/T6031/
T6034 `g15/`) GPUs, matching the qualified G17 ABI without inventing
unsupported metrics.

- Add `stats_m3.rs` pure accumulator (with 6 unit tests) consuming M3/G15
  firmware statistics channel tags `0x04` (utilization on legacy 14.7
  profile), `0x0b`/`0x02`/`0x03` (p-state/power transitions), integrating
  `busy_ns` and clearing to idle immediately on power-gating.
- Generalize `StatsSnapshot::qualified_reader` (`QualifiedReader` enum for
  G17, G15, and M3) and `sysfs_exports::register_qualified()`, registering
  `agx_stats` + `gpu_memory` + `gpu_mem_limit_pct` in `probe_t8122` and
  `probe_g15` (including `memacct::LEDGER.configure()` in `probe_g15`).
- Order M3 receive-ring slot loads before consumer stores via
  `agx_memory::release_slots()` (`dma_mb(Full)`), unify G15 and M3
  statistics ring consumption in single transactional paths, and drain
  queued stats records across PM suspend/resume boundaries before flipping
  admission (`stats_boundary`).
- Reuse `asahi_qualified_stats`'s trailing u32 pad as `util_source` and
  document `firmware-statistics-tag-0x04`, `unsupported`, and PM boundary
  semantics in `Documentation/ABI/testing/sysfs-driver-asahi-agx-stats`.

[7.3 carry port of aurora-silicon/linux#3490 (8ba26a7) onto
carry/aurora-7.3 (3058cc5), resolving context diffs against intake
00cbc67 (pre-g14_v27_2 and pre-frequencies_hz).]

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
After an aborted deep sleep (CompleteAction::Hold), the M3 T8122 backend
keeps firmware stopped (inner.asleep and inner.sleep_held remain true)
while leaving runtime health true until the next real deep-sleep wake.
When PM_POST_SUSPEND clears Telemetry::suspended, read_qualified_stats()
would otherwise read PerformanceControl and SGX+0xe01000 from a stopped
GPU and export pstate as valid.

- Return a suspended readout without touching MMIO or shared rings
  whenever inner.asleep is set.
- Keep telemetry suspended in Runtime::suspend_stats() whenever
  inner.sleep_held is set, and skip ring drains while inner.asleep is
  true; also mark telemetry suspended when entering
  sleep_hold_until_deep_sleep().
- Latch Telemetry::had_pstate whenever a valid hardware-derived pstate
  is exported so Extended profile (which has no statistics ring) reports
  STALE rather than UNAVAILABLE across suspend, sleep-hold, and fault
  readouts, and add a unit test covering the sequence.
- Update the M3 ABI documentation note to aurora.stats_export=0.
@maralcbr

maralcbr commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr Thanks for the review — all three items are addressed and main is now merged cleanly at 4188bb7cc:

  1. Single G15/M3 stats-ring consumer (71867b664): Channels::drain_rings() now consumes the stats ring through transactional Channels::drain_stats(now_ns) instead of note_stats(), dropping the duplicate pre-drains in g15/channel.rs and unifying Config::drain() -> Config::drain_stats_only() on M3. tools/asahi/g15-stats-drain-tests.py --mutations covers moving-producer exact-once telemetry, mid-drain fault rollback, and kills no-telemetry (10/10 mutations killed).
  2. M3 consumer release barrier (d8d6a0ccf): agx_memory::release_slots() emits kernel::sync::barrier::dma_mb(Full) (dmb osh on arm64) before every consumer-index store in legacy drain(), drain_stats_only(), and drain_extended() (ordering slot payload loads before consumer publication for CPU<->DMA shared memory, matching M3's dmb osh accessors; happy to switch to mb(Full) for uniformity with G15 if you prefer).
  3. PM suspend/resume boundary drain (8ba26a7e7): Both Channels::stats_boundary() and Config::stats_boundary() drain queued stats records up to the producer under the old admission state before flipping Telemetry::suspended, with backend health checks and a G15 faulted-drain drain_one fallback (verified by boundary-flip-first and boundary-skip-fallback mutations).
  4. main merge + M3 deep-sleep guard (2cd3ad5c5, 4188bb7cc): Merged main (5a870d0f0) cleanly without force-pushing, and added a guard for #3504 (feat/m3-gpu-deep-sleep) so read_qualified_stats() never touches MMIO/shared rings while inner.asleep is set and suspend_stats() keeps telemetry stale across PM_POST_SUSPEND while inner.sleep_held holds firmware stopped after an aborted deep sleep (CompleteAction::Hold), plus latching had_pstate on hardware-derived pstate reads.

Would love to take you up on running the J516s (M3 Pro) G15 live boot at 4188bb7cc and a re-review once CI finishes.

maralcbr added a commit to omacom/linux-aurora that referenced this pull request Dec 2, 2026
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed merge-conflict Conflicts with the base branch (bot) ci-failing A check failed at the PR head (bot) labels Dec 2, 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.

Approve at 4188bb7cce56. All three points from my 12-02 review are fixed:

  • One stats consumer on G15. Channels::drain_stats() now feeds both stats_seen and telemetry from one pass and publishes the read index once. drain_rings() calls it, and the extra pre-drains in devctl_submit() and Firmware::drain_rings() are gone, so a record can no longer be acknowledged without reaching telemetry.
  • M3 consumer barrier. Every consumer-index store in drain(), drain_stats_only() and drain_extended() now comes after release_slots() (dma_mb(Full), dmb osh). That orders the slot loads before the slots go back to the firmware.
  • Stale records across suspend. stats_boundary() drains to the producer under the old admission before flipping suspended, and record_words() ignores records while suspended. Records queued during sleep are consumed without counting, and pre-suspend samples are flushed before gating. The asleep and sleep_held guards keep reads off MMIO and the rings.

Hosted CI at this head is green (apple-build, host-tests, KUnit asahi, pr-text).

One non-blocking note: M3 drain_stats_only() reads the producer index and then the slot payloads with no read barrier between them. The G15 note_stats() has rmb() there. The event and trace loops in drain() have the same gap, so it predates this PR. A dma_rmb() after the index read would match G15.

Left before merge: rows at this head. J516s (M3 Pro, G15) with live agx_stats and gpu_memory and one sleep cycle, one M3 base (m3/ path, J613 or J615) boot, and a G17 regression check for the shared QualifiedReader change.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed changes-requested A reviewer requested changes (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@maralcbr

maralcbr commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

@DjDeveloperr Thanks for the approval!

  1. Read barrier note (m3_memory.rs): Already ordered by m3_memory itself — read_u32() executes dmb oshld immediately after the producer-index load (drivers/gpu/drm/asahi/m3/m3_memory.rs:176), and read() executes dmb osh before the slot-payload loads (m3_memory.rs:165), so an extra dma_rmb() would be redundant. Leaving 4188bb7cc untouched to preserve the green CI and approval; happy to add a clarifying comment in a follow-up.
  2. Exact-head 4188bb7cc regression rows added to the PR body (7.3.0-lab4188bb7c-1780):
    • J614s M4 Pro (G17): boot-health pass, 0 GPU faults, agx_stats (firmware-statistics-tag-0x13) 17% -> 97%, pstate 2 -> 10, busy_ns 22.6 -> 4776.2 ms, gpu_memory live.
    • J700 A18 Pro (G17P): boot-health pass, 0 GPU faults, agx_stats 0% -> 62% -> 0%, pstate 0 -> 10 -> 0, 1470 MHz, gpu_memory live.
    • J416c M2 Max (legacy G14): boot-health pass, 0 GPU faults, legacy agx_stats (14% -> 100%, 444 -> 1398 MHz, busy_ns 0 -> 4952 ms) + gpu_memory intact.
    • J813 M5 Air: boot-health pass, 0 GPU faults.

Holding off on merge for the remaining two exact-head 4188bb7cc rows: J516s (M3 Pro, G15 + sleep cycle) and M3 base (m3/, J613 or J615) (our lab J613 is still offline needing hands). Requesting those from the frontier — happy to also run a J514s (4188bb7cc + #2148) G15 + s2idle check on our side if helpful.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed ready-to-merge Meets the merge policy: merge it (bot) labels Dec 2, 2026
@maralcbr

maralcbr commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Supplementary, not exact head: booted omacom/linux-aurora carry/aurora-7.3.0-5 (c731018151b1, carrying #3490 @ 8ba26a7e7edc + #2148) on a J514s (M3 Pro, T6030 G15S, 18-core [9, 9], fw 14.7) awake in MacLab (j1203-074308-6f8a):

  • agx_stats: utilisation_source firmware-statistics-tag-0x04, live transition idle 0% / pstate 0 / 0 MHz -> GLES3 load 100% / pstate 8 / 1380 MHz / busy_ns 0 -> 9992002293 (utilisation_samples 307 -> 683 -> 1558) -> post-load idle 0% / pstate 0 / 0 MHz.
  • DRM fdinfo: drm-curfreq-vertex/fragment/compute: 1380000000 Hz, drm-maxfreq-*: 1380000000 Hz; gpu_memory live; 0 GPU faults.
  • Did not run s2idle on this volunteer machine; keeping this separate from the exact-head 4188bb7cce56 Tested: rows while exact-head J516s (G15 + sleep) and M3 base rows remain pending.

omarchy-pkgs-merge Bot pushed a commit to omacom/omarchy-pkgs that referenced this pull request Dec 2, 2026
…DCP SDR fallback (#558) (#4508)

Pin linux-aurora and aurora-userpages to immutable tag aurora-7.3.0-5
(omacom/linux-aurora c731018151b1 on carry/aurora-7.3.0-5), built from
integration/aurora-7.3 (omacom/linux-aurora 87005e7e5393):
- Re-pins aurora-silicon/linux#3490 to 8ba26a7e7edc (omacom/linux-aurora#557):
  single-consumer G15 stats ring drain, PM suspend/resume ring drain, and
  M3 receive-ring load/store ordering (resolving the #3490 caveat tracked in #4397)
- Adds aurora-silicon/linux#3872 (omacom/linux-aurora#558): DCP auto SDR
  BT2020_RGB fallback to safe SDR on bandwidth-limited HDMI 2.0 timings
- Preserves intake 4a42f3105002 and all 23 carries from 7.3.0.aurora4-1

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 4188bb7

Checked: Ran the seven exact stats tests with warnings denied. The stopped M3 path returns a suspended readout without reading MMIO or consuming its firmware ring. Sleep-hold survives the post-suspend callback, and a previously valid hardware pstate stays stale across hold and fault. Checked the earlier single-consumer and boundary changes and the current green hosted checks.

@DjDeveloperr

Copy link
Copy Markdown
Contributor

J516s (M3 Pro, T6030, G15S B1, 18-core, macOS 27.2 fw 26B123) non-regression row on current main (622a059b0df6) + #3490 (4188bb7cce56) = b0149bd8df22 (7.3.0-main-pr3490-gb0149bd8df22, boot_id=b87ba3ad-b660-4b5f-aaed-5a5f3ed9d4c7, main's t6030-j516s.dtb):

  • Driver binding note: On 27.2 fw 26B123, J516s binds aurora-g16 (drivers/gpu/drm/asahi/g16/) rather than the fw-14.7 g15/ backend that #3490 wires. Accordingly:
    • /sys/devices/platform/soc/292400000.gpu/agx_stats returns unsupported (export_enabled = false on aurora-g16), and DRM fdinfo reports drm-driver: aurora + drm-engine-compute + drm-total/resident-system without drm-curfreq-* (expected / no regression on g16).
    • gpu_memory and gpu_mem_limit_pct (0) are live and track allocations cleanly across load and s2idle (user_committed 1799916072 -> 1845796968 -> 1800882728, refused 0).
  • GPU execution & s2idle: aurora-g16 reached backstop=0 limit=S8 (1380 MHz, demand S8 / effective S8 in aurora-g16/stats), gpubench --test compute.heavy --depths 1 measured 3970.43 GFLOP/s pre-sleep and 3952.44 GFLOP/s after rtcwake -m mem -s 10 (s2idle, suspend_stats 1/0), health: failed 0 errno 0 degraded 0, 0 GPU faults.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Rows for 4188bb7cce56 on J615 (M3 Air, T8122, G15G, firmware 27.2) and J616s (M4 Pro, T6040, G17 path), both on a local merge of the head into current main 06a7548b71d8 (= d604f85d84d9, clean, 7.3.0-mrpc3490). Each Mac booted a one-shot via aura-try (aura main 70d844e3, U-Boot 5c0d5fe1) with that tree's own DTB (t8122-j615.dtb, t6040-j616s.dtb). Saved defaults were not changed.

Why a merge with main: at the PR's own base (5a870d0f0b3f, 7.3.0-mrp3490, J615 boot a9171106), the J615's GPU never binds: deferred probe pending: aurora-g16: PMP telemetry from /soc/pmp@2d0500000 unavailable. That is fixed on main by #3974, so the desktop fell back to softpipe. That is the base, not this PR.

m3/ path: on a 27.2 handoff crate::g16::claims() takes the T8122 before probe_t8122() (with CONFIG_DRM_ASAHI_G16=y), so the m3/ backend does not bind on J615 on 27.2. The same thing happened on Dj's J516s row. An m3/ row needs a T8122 on a pre-27.2 handoff, and we have none.

J615 (boot 25a61ebc): driver aurora-g16, GPU up (glmark2 on Apple M3 (G15G C0)).

  • agx_stats = unsupported (g16 export off, as on J516s)
  • gpu_memory live: user_committed 851.0 MB idle → 898.2 MB under compute.heavy → 856.7 MB after s2idle; limit 5245163929, client_limit 3914301440, refused 0
  • gpu_mem_limit_pct 50
  • fdinfo: drm-driver: aurora, engine-time lines present, total/resident memory, no curfreq (g16)
  • compute.heavy kind=alu 3356.5 GFLOP/s before and 3358.7 GFLOP/s after s2idle (rtcwake on the PMU RTC, success +1)
  • 0 GPU fault/recovery/timeout lines

J616s, G17 check for the shared QualifiedReader change (boot f2cd7d5a): driver aurora (G17P), /sys/devices/platform/28a600000.gpu.

  • agx_stats valid: utilisation_source firmware-statistics-tag-0x13, pstate_status valid. Under compute.heavy it shows pstate 10, achieved_frequency_hz 1578000000, util_device_percent 100 then 0 two seconds later, and busy_ns advancing in bursts (utilisation_samples 1 → 2 → reset)
  • gpu_memory live with refused 0
  • fdinfo has drm-curfreq-*/drm-maxfreq-* at 1578 MHz
  • 7529 GFLOP/s before and after s2idle (success +1)
  • 0 GPU faults, 0 kernel err lines
  • I have no same-boot base for G17, so this shows the readers work and nothing faults. It does not compare the burstiness of util_device_percent against main.

Both Macs went back to their production defaults afterwards (J615 edge, J616s fleet94; Enforcing, 0 failed units).

@DjDeveloperr
DjDeveloperr merged commit c77250f into main Dec 3, 2026
13 of 16 checks passed
@DjDeveloperr
DjDeveloperr deleted the drm-asahi/m3-g15-agx-stats-sysfs branch December 3, 2026 19:54
@DjDeveloperr

Copy link
Copy Markdown
Contributor

Merged as c77250fb4a9d (main 63abfb01beef + 4188bb7cce56). Its tree is the one I checked plus the radeon/PCI files from #3485 and #3486, which this PR doesn't touch.

Checked before merge, on main dc68a27f33d8 + this head (merge tree afae8232):

  • arm64 LLVM=1 W=1 build of drivers/gpu/drm/asahi/, with G15, G16, G18, M5 and M3_T8122 enabled: builds. The Rust crate gives the same 38 warnings as main alone, none new. sysfs.c has no warnings.
  • Host tests in the pinned host-tests container (stats, telemetry, legacy-frequency, m3, g15- and g17- families): 399/399 pass. stats_m3.rs unit tests: 7/7.
  • Rows for the three asked for in the 12-02 approval:
    • J516s: on main 622a059b + this head.
    • J615: on main 06a7548b + this head.
    • G17: J616s, plus the exact-head J614s, J700, J813 and J416c rows in the body.
  • On firmware 27.2, J516s and J615 bind the g16 backend, so the new g15/ and m3/ exports can't run on any Mac we have. On those two, gpu_memory is live and s2idle passes. The shared reader path ran with 0 faults.
  • Since the J615/J616s rows, main changed only the G14 v27.2 probe in driver.rs among this PR's files. It is unrelated to the new registration.

Still open as follow-ups: a g15/ row on a 14.7 handoff and an m3/ row on a pre-27.2 T8122.

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) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) blast:m4 Macs affected, from Merge risk (bot) blast:m5 Macs affected, from Merge risk (bot) blast:neo Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants