Repository navigation
drm/asahi: Export AGX firmware stats to /sys/class/drm/card*/device/agx_stats - #157
Closed
joshuaswarren wants to merge 6 commits into
Closed
joshuaswarren wants to merge 6 commits into
joshuaswarren wants to merge 6 commits into
Conversation
Opt-out toggle for the AGX firmware stats sysfs export. When 1 (the default), StatsChannel::poll retains the values it already decodes into the StatsSnapshot exposed via /sys/class/drm/card*/device/agx_stats. When 0, the export is suppressed and the file is not created — matching today's behaviour exactly (the channel is still polled, the messages are still debug-logged).
Add the per-GpuManager StatsSnapshot type and an update_from(&StatsMsg) that mirrors StatsChannel::poll's debug path. The type holds the latest util1..util4, pstate, avg_power_mw, temperature (raw, scale, tmin, tmax) and a cumulative busy_ns derived from successive FwBusy timestamps. A module-level SNAPSHOT_PTR (AtomicU64) is published by GpuManager::make so the C-side sysfs shim can find the live snapshot without walking the kernel object graph. StatsChannel::poll is not yet wired up; that comes in the next commit alongside the module-param read.
Construct the StatsSnapshot in GpuManager::make_mgr, publish its raw pointer to the module-level SNAPSHOT_PTR, and clone a reference into the new StatsChannel field. StatsChannel::poll now calls snap.update_from() on every decoded message when module_parameters::stats_export is non-zero. No change to scheduling or power behaviour — the firmware already sends the messages and the channel already polls them; we only retain the values.
Add the C sidecar drivers/gpu/drm/asahi/sysfs.c that owns the device_attribute and the formatted show output. Bindgen for this kernel tree does not include <linux/sysfs.h>, so device_create_file is unavailable to Rust — the shim is the lowest-risk way to expose the file. Rust binds to asahi_sysfs_register/unregister via drivers/gpu/drm/asahi/sysfs_exports.rs. The Makefile adds sysfs.o to asahi-y so both objects link into asahi.ko (and vmlinux when CONFIG_DRM_ASAHI=y). All writes are field-keyed through AtomicU* so the IRQ-side update_from and the sysfs show never need a lock.
Stash the platform device's raw struct device pointer in AsahiDriver::raw_dev and call asahi_sysfs_register() after drm::driver::Registration::new_foreign_owned. The Drop impl calls asahi_sysfs_unregister() which both removes the attribute and clears SNAPSHOT_PTR — the lifetime of the StatsSnapshot is owned by GpuManager::make_mgr, which outlives the AsahiDriver by construction.
Add the description for /sys/class/drm/card*/device/agx_stats. The file is the consumer contract for the AGX firmware stats export; this doc describes each key, the stats_export module parameter, and the pending validation of util1..util4 semantics against a controlled MLX load (T6001 13.5 firmware). busy_ns is documented as firmware-timestamp units, with saturation at u64::MAX. jobs starts at 0 on T6001 and is reserved for the submission-completion landing.
Contributor
Author
|
Superseded by #168 (same base, rebuilt series). Reasons for the replacement, factual only:
Branch: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
drm/asahi: Export AGX firmware stats to
/sys/class/drm/card*/device/agx_statsMotivation
The AGX firmware already sends firmware statistics (
StatsMsg:Utilization,PowerState,PowerOn,PowerOff,FwBusy,AvgPower,Temperature) over the statistics ring channel.drm/asahidecodesthem in
drivers/gpu/drm/asahi/channel.rs::StatsChannel::polland onlydebug-logs them. The producer contract in
~/src/coreglass/docs/DESIGN.md(coreglass GPU item 1) calls for theseto be exported as a
key valuefile on the DRM platform device so thecoreglass dashboard / live sampler can read them at 10 Hz.
What this does
Six small commits on top of
aurora-wip:(
asahi.stats_export, default 1). When 0, no values are retainedand no file is registered.
the per-GpuManager
StatsSnapshot(latest util1..util4, pstate,avg_power_mw, temperature, cumulative busy_ns, jobs) and an
update_from(&StatsMsg)decoder. A module-levelSNAPSHOT_PTR(AtomicU64) is published for the C-side show callback.
the snapshot is built in
GpuManager::make_mgr, its raw pointer ispublished to
SNAPSHOT_PTR, a clone is held byStatsChannel.StatsChannel::pollcallssnap.update_from()on every decodedmessage when
module_parameters::stats_exportis non-zero.drivers/gpu/drm/asahi/sysfs.cthat owns thedevice_attributeand the formatted
key valueshow callback. Bindgen for thiskernel tree does not pull in <linux/sysfs.h>, so device_create_file is
not available to Rust — the shim is the lowest-risk bridge. The
Rust side declares the FFI in
sysfs_exports.rs. The Makefile addssysfs.otoasahi-yso both objects link intoasahi.ko(andvmlinuxwhenCONFIG_DRM_ASAHI=y). All writes are atomic, soIRQ-side
update_fromand sysfsshownever need a lock.drop — stash the platform device's raw
struct device *inAsahiDriver::raw_devand callasahi_sysfs_register()afterdrm::driver::Registration::new_foreign_owned. TheDropimplcalls
asahi_sysfs_unregister(), which both removes the attributeand clears
SNAPSHOT_PTR— the lifetime of the StatsSnapshot isowned by
GpuManager::make_mgr, which outlives the AsahiDriver.description for
/sys/class/drm/card*/device/agx_stats, one keyper line, all unit meanings and saturation rules.
What it does NOT do
sends the messages and the channel already polls them).
AtomicU*fields.
stats_export=1keeps today's debug-log behaviourintact and adds the retention file alongside.
Producer contract
The file format matches the coreglass producer contract exactly:
Validation
Field semantics are documented per-key in
Documentation/ABI/testing/sysfs-driver-asahi-agx-statsand indrivers/gpu/drm/asahi/stats.rs. The firmware field meanings(units of
util1..util4, the units ofFwBusytimestamps) areunconfirmed as of right now and need validation against a controlled
MLX load:
FwBusytimestamp unit isreported by the firmware as nanoseconds; convert via delta against
the prior
FwBusymessage. Validate by readingbusy_nsunderidle vs an MLX 4096×4096 fp16 matmul loop — expect flat under
idle and a steady delta under load.
Utilizationu32 fields are reported raw, as thefirmware does not pre-scale them. We surface them unscaled per
the producer contract. Per-chip scaling will land in a follow-up
once validated on M1 (T8103), M2 (T6021), and M2 Ultra (T8140).
The assignment's hardware feasibility check on jw16 found
CONFIG_DRM_ASAHI=y(built-in) on the stock kernel, so the OOTmodule-swap gate that the PR155 ane driver used is not available
on jw16. The patch is therefore staged for a one-shot kernel boot
on a separate machine (T6021 M2 Max, jw14m2) where the w73 lane has
a proven boot/fallback recipe. A module swap is also impossible on
jw14m2's stock kernel; the field-semantics validation will land on
a dedicated one-shot boot. Module swap is only viable in places where
the asahi driver is built as a loadable module — currently none in
the lab fleet.
The hw-validation milestones on jw16 are reduced to: rustfmt clean,
checkpatch-clean on the patches (this tree has no scripts/checkpatch
copy; manual review against Documentation/CodingStyle follows). The
in-tree patch keeps the unsocketed part of the validation gated on
the M2 lane handoff.
Out of scope (separate PRs)
busy_nsandjobskeysfor the ANE engine (
omarchy-ane, notlinux-aurora). That landsin
omarchy-aneper DESIGN.md and is a separate entry.util1..util4scaling.