Repository navigation
drm/asahi: m3, g15: expose qualified agx_stats and gpu_memory sysfs #3490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,390
−95
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
717a6ff
drm/asahi: m3, g15: expose qualified agx_stats and gpu_memory sysfs
maralcbr e6e8509
tools/asahi: update legacy-frequency-tests for QualifiedReader
maralcbr d8d6a0c
drm/asahi: m3: order receive-ring slot loads before consumer stores
maralcbr 71867b6
drm/asahi: m3, g15: consume the stats ring in one place
maralcbr 8ba26a7
drm/asahi: m3, g15: drain stats ring at PM suspend/resume boundaries
maralcbr 2cd3ad5
Merge branch 'main' into drm-asahi/m3-g15-agx-stats-sysfs
maralcbr 4188bb7
drm/asahi: m3: keep qualified stats stale while asleep or sleep-held
maralcbr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
|
|
||
| //! Sysfs qualified statistics reader for the G15 (M3 Pro/Max: T6030/T6031/T6034) backend. | ||
| //! | ||
| //! Owns the shared session handle and DVFS table-A frequencies. Reads acquire | ||
| //! `Shared::state`, drain the statistics ring without waking the GPU or servicing | ||
| //! submissions, and return a qualified `Readout`. | ||
|
|
||
| use core::sync::atomic::Ordering; | ||
| use kernel::{prelude::*, sync::Arc}; | ||
|
|
||
| use super::{ | ||
| channel::{Channels, Ring}, | ||
| engine, | ||
| fw::channels::{STATE_READ, STATE_WRITE}, | ||
| power::pstate::{self, StatsSeen}, | ||
| regs::{mb, rmb, wmb}, | ||
| Shared, | ||
| }; | ||
| use crate::{ | ||
| g17::telemetry::Readout, | ||
| stats_m3::{self, FreqTable, HwPstateSnapshot, Telemetry}, | ||
| }; | ||
|
|
||
| impl Channels { | ||
| fn note_stats_telemetry( | ||
| ring: &Ring, | ||
| seen: &mut StatsSeen, | ||
| telemetry: &mut Telemetry, | ||
| now_ns: u64, | ||
| ) -> Result<Option<u32>> { | ||
| let producer = ring.state.r32(STATE_WRITE)?; | ||
| let read = ring.state.r32(STATE_READ)?; | ||
| let Some(slots) = pstate::pending(read, producer) else { | ||
| return Ok(None); | ||
| }; | ||
| rmb(); | ||
| for slot in slots { | ||
| let at = slot as usize * pstate::STATS_RECORD; | ||
| let tag = ring.ring.r32(at + pstate::STATS_TAG)?; | ||
| let pstate_word = ring.ring.r32(at + pstate::POWER_STATE_INDEX)?; | ||
| seen.note(tag, pstate_word); | ||
| let words = match tag { | ||
| stats_m3::TAG_UTILIZATION | stats_m3::TAG_POWER_STATE => [ | ||
| tag, | ||
| ring.ring.r32(at + 0x04)?, | ||
| ring.ring.r32(at + 0x08)?, | ||
| ring.ring.r32(at + 0x0c)?, | ||
| ring.ring.r32(at + 0x10)?, | ||
| ring.ring.r32(at + 0x14)?, | ||
| ring.ring.r32(at + 0x18)?, | ||
| ring.ring.r32(at + 0x1c)?, | ||
| pstate_word, | ||
| ], | ||
| _ => [tag, 0, 0, 0, 0, 0, 0, 0, pstate_word], | ||
| }; | ||
| telemetry.record_words(&words, now_ns, (pstate::STATES - 1) as u32); | ||
| } | ||
| Ok(Some(producer)) | ||
| } | ||
|
|
||
| /// Drains only the statistics ring, updating both `stats_seen` and `telemetry`, | ||
| /// without touching event, log or trace rings and without waking the GPU. | ||
| pub(crate) fn drain_stats_only(&mut self, now_ns: u64) -> Result { | ||
| let mut seen = self.stats_seen; | ||
| let mut telemetry = self.telemetry.clone(); | ||
| if let Some(producer) = | ||
| Self::note_stats_telemetry(&self.stats, &mut seen, &mut telemetry, now_ns)? | ||
| { | ||
| self.stats_seen = seen; | ||
| self.telemetry = telemetry; | ||
| if self.stats.read()? != producer { | ||
| mb(); | ||
| self.stats.state.w32(STATE_READ, producer)?; | ||
| wmb(); | ||
| } | ||
| return Ok(()); | ||
| } | ||
| self.telemetry.invalidate(); | ||
| let producer = self.stats.state.r32(STATE_WRITE)?; | ||
| if self.stats.state.r32(STATE_READ)? != producer { | ||
| self.stats.state.w32(STATE_READ, producer)?; | ||
| wmb(); | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| pub(crate) struct Reader(pub(super) Arc<Shared>, pub(super) FreqTable); | ||
|
|
||
| impl Reader { | ||
| pub(crate) fn read(&self) -> Readout { | ||
| let mut state = self.0.state.lock(); | ||
| let Some(firmware) = state.as_deref_mut() else { | ||
| return Readout { | ||
| util_source: stats_m3::UTIL_SOURCE_TAG_04, | ||
| ..Readout::default() | ||
| }; | ||
| }; | ||
| let now_ns = engine::now_ns(); | ||
| let unhealthy = self.0.crashed.load(Ordering::Acquire) | ||
| || self.0.orphaned.load(Ordering::Acquire) | ||
| || firmware.recovery.failed().is_some(); | ||
| if unhealthy { | ||
| firmware.channels.telemetry.invalidate(); | ||
| return firmware.channels.telemetry.read(now_ns, None, &self.1); | ||
| } | ||
| if firmware.channels.drain_stats_only(now_ns).is_err() { | ||
| firmware.channels.telemetry.invalidate(); | ||
| return firmware.channels.telemetry.read(now_ns, None, &self.1); | ||
| } | ||
| let hw = firmware.pstate_words().ok().map(|w| HwPstateSnapshot { | ||
| actual: w.actual, | ||
| current: w.current, | ||
| freq_mhz_bits: w.freq_mhz, | ||
| sgx_pstate: None, | ||
| }); | ||
| firmware.channels.telemetry.read(now_ns, hw, &self.1) | ||
| } | ||
|
|
||
| pub(crate) fn suspend(&self, suspended: bool) { | ||
| if let Some(firmware) = self.0.state.lock().as_deref_mut() { | ||
| firmware.channels.telemetry.suspend(suspended); | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn frequency(&self) -> Option<(Option<u64>, u64)> { | ||
| let view = self.read(); | ||
| stats_m3::frequency_pair(&view, &self.1) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 inChannels::note_stats()+ transactionalChannels::drain_stats(now_ns)called byChannels::drain_rings()andg15::stats::Reader::read(), removing the duplicate pre-drains andg15/stats.rsconsumer. Also unified M3 stats consumption throughConfig::drain_stats_only()and extendedtools/asahi/g15-stats-drain-tests.pywith moving-producer exact-once telemetry checks and ano-telemetrymutation.