Repository navigation
drm/asahi: Export AGX firmware stats to /sys/class/drm/card*/device/agx_stats - #168
Merged
RyanTheTide merged 17 commits intoOct 8, 2026
Merged
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). Signed-off-by: Joshua Warren <[email protected]>
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. Signed-off-by: Joshua Warren <[email protected]>
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. Signed-off-by: Joshua Warren <[email protected]>
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. Signed-off-by: Joshua Warren <[email protected]>
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. Signed-off-by: Joshua Warren <[email protected]>
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. Signed-off-by: Joshua Warren <[email protected]>
The producer contract for agx_stats promises a cumulative completed- submissions counter, but the snapshot never counted anything. Count a submission when its last command completes: JobFence::command_complete bumps the snapshot counter right before the fence signals, via an Arc carried on the fence (Queue -> JobFence). One Relaxed fetch_add per completed submission; no change to the submission or completion path ordering. Signed-off-by: Joshua Warren <[email protected]>
The file prints busy_ns, jobs, pstate, power_mw, util1..util4, temperature_raw and temperature_scale; drop the temperature_tmin / temperature_tmax keys the code never prints, state the u64 wrap semantics of busy_ns honestly instead of a saturation claim, and describe jobs as the host-side completed-submission counter it now is. Signed-off-by: Joshua Warren <[email protected]>
`asahi-y := sysfs.o` made Kbuild treat asahi.o as a composite module whose only part was sysfs.o: the composite link overwrote the object rustc emits for the crate root (both are named asahi.o), so the module — and any kernel built with it — contained the sysfs shim alone and no GPU driver at all. A stock-config boot of such a kernel loses the GPU entirely (observed: no AGX platform driver, apple-dart -16 probe failures on the display darts, dcp missing). Rename the crate root to asahi_core.rs and list both objects: asahi-y := asahi_core.o sysfs.o. The module (or built-in vmlinux) now links the crate and the shim; module metadata keeps name "asahi". Signed-off-by: Joshua Warren <[email protected]>
Arc::new returns Result<Arc<T>, AllocError> in this tree; the stats snapshot creation ignored it, so the crate did not compile once the Makefile actually linked it (the previous shim-only module never compiled the driver). Propagate with ?. Signed-off-by: Joshua Warren <[email protected]>
StatsMsg is a versions-macro type: per-version generics exist, a bare crate::fw::channels::StatsMsg does not, so the snapshot's update_from could not compile (E0432). The first full compile of the driver crate exposed this — the earlier shim-only module never compiled the Rust side at all. Move the decode into StatsChannel::poll, which already runs in the versioned context with fw::channels::* in scope, and write the matched fields straight into the snapshot (last_busy_ts becomes pub(crate) for the FwBusy integration). Timestamps are this tree's fw U64 tuple type, read as .0. StatsSnapshot keeps the plain unversioned struct and note_job. Signed-off-by: Joshua Warren <[email protected]>
StatsMsg is versions-macro generated; the per-version enum is only reachable as StatsMsg::ver inside a versioned item (the macro rewrites it to StatsMsg<VER>). Plain variant paths are for non-versioned enums like EventMsg. Qualify the five match arms. Signed-off-by: Joshua Warren <[email protected]>
The series declared two unconnected statics: Rust wrote its own stats::SNAPSHOT_PTR while the C show callback read the never-written asahi_stats_snapshot_ptr, so agx_stats would print 'unsupported' forever (rustc flagged the C static as unused from the Rust side). Make the C static the single storage location: sysfs.c grows asahi_stats_set_snapshot_ptr() (WRITE_ONCE), sysfs_exports.rs exposes set_snapshot_ptr(), and GpuManager publishes the Arc address through it at probe; asahi_sysfs_unregister keeps clearing it. The unused extern static declaration and the stats::SNAPSHOT_PTR duplicate are gone. Signed-off-by: Joshua Warren <[email protected]>
Window B on the M2 measured three defects against the first verified kernel, all rooted in the cross-language contract: 1. The C sysfs readout crossed field boundaries. StatsSnapshot was repr(Rust): rustc legally reordered it (empirically, rustc 1.98 puts the AtomicU64s first: busy_ns at +8, jobs at +16), while sysfs.c read the declared offsets (busy_ns +48, jobs +56). The file therefore showed busy_ns bouncing in 2^32 steps across reads and jobs stuck at 0 while the counter incremented on every completed submission (the JobFence::command_complete site fires; decode fences must signal for decode to complete at all). Make the layout a contract: #[repr(C)] on the Rust struct and BUILD_BUG_ON offset/size asserts in sysfs.c. 2. stats_export=0 kept the file visible with a zeroed key set. The ABI document promises exactly "unsupported": asahi_sysfs_register() now takes the export flag and the show callback prints "unsupported" when the export is disabled. 3. Document the monotonicity and the layout contract in the ABI entry. The 3 apple-dart -EPROBE_DEFER and 3 dcp supplier-miss lines on the test boot are display-path and out of this series' scope: the series touches only drm/asahi and the ABI document (429 lines, no dcp/dart/display files); the defers come from the 7.1.12 aurora base pairing with the stock 7.1.13-era device tree supplied by the untouched boot.bin. Measured on the retry window (jw14m2, artifacts 20261004T1500Z): decode digests bit-identical on all arms, reader overhead 0.27%, export-off 0.32%.
FwBusy timestamp deltas do not measure compute on T6021: the round-3 window measured a busy fraction of 0.0017 across a saturated 30 s matmul (the FwBusy stream is near-silent under compute), while the Utilization message (tag 0x04) reads 0-100 per-subqueue percentages that track it exactly (100/100/100/100 across the matmul, 0-2 idle, decode on subqueue 3). No T6001 hardware validation of the FwBusy producer exists either; the old ns-magnitude claims were aspirational. busy_ns now integrates utilization-weighted time: each Utilization window adds (ts - prev) / 100 * max(util1..4).min(100), with the last timestamp kept channel-local. Monotonic, bounded by elapsed wall time, and invariant to the firmware tick rate. The FwBusy arm and the snapshot's last_busy_ts field are gone; the C mirror and its offset asserts shrink with it (busy_ns 40, jobs 48, size 56). Signed-off-by: Joshua Warren <[email protected]>
Stats timestamps are 24 MHz ticks, not ns: HwConfig.base_clock_hz is 24_000_000 on every supported SoC (t600x, t602x, t8103, t8112), and the driver chooses ns only for user command timestamps (file.rs), which it converts into base-clock ticks. Window C measured the v1 producer at 22.5e6 raw ticks/s across a saturated matmul = 0.9375 of the base clock: the load was fully tracked, only the unit was missing (the round-3 idle 0.024 fraction was full-time coverage misread as ns, 1e9/24e6 = 1/41.667 exactly). busy_ns now converts once, in one place: StatsChannel carries ts_hz (plumbed from cfg.base_clock_hz at the gpu.rs call site) and each Utilization window adds (ts - prev) * util * 1e9 / (100 * ts_hz) in u128. The ABI document states the tick conversion; expected T6021 matmul fraction 0.94-1.0, idle 0.0002-0.01. Signed-off-by: Joshua Warren <[email protected]>
The first tick-conversion attempt divided a u128 intermediate, and the kernel runtime has no __udivti3: the vmlinux link failed with an undefined reference. Split the window instead: whole seconds contribute util x 1e7 ns each (1e9 / 100 exactly), the tick remainder contributes rem x util x 1e9 / (100 x ts_hz), both in plain 64-bit arithmetic and exact against the u128 formula. Also drop an unnecessary unsafe that rustc flags in the sysfs exports wrapper. Signed-off-by: Joshua Warren <[email protected]>
RyanTheTide
added a commit
that referenced
this pull request
Oct 8, 2026
Preserve the original review commits and retain subsequent published repairs where superseded. Contributor credit; Signed-off-by outstanding: - 4189501: Joshua Warren <[email protected]> Ryan integrates these contributions under DCO (b); no author signature is forged. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
added a commit
that referenced
this pull request
Oct 8, 2026
[follow-up to #168] drm/asahi: tie stats registration to a per-device snapshot owner Original contributor commits are preserved. Conflict resolutions retain the audited shared driver APIs and their integrated review fixes. Contributor credit; Signed-off-by outstanding: - 4189501: Joshua Warren <[email protected]> Ryan integrates these contributions under DCO (b); no author signature is forged. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
DjDeveloperr
pushed a commit
that referenced
this pull request
Oct 16, 2026
drm/asahi: Export AGX firmware stats to /sys/class/drm/card*/device/agx_stats Original contributor commits are preserved. Conflict resolutions retain the audited shared driver APIs and their integrated review fixes. Contributor credit; Signed-off-by outstanding: - 4189501: Joshua Warren <[email protected]> Ryan integrates these contributions under DCO (b); no author signature is forged. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
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_statsSupersedes #157 (rebuilt from the same
aurora-wipbase3bb0a6104a11; everycommit carries
Signed-off-by, which the original series could not gainwithout rewriting its history).
Motivation
The AGX firmware already sends firmware statistics (
StatsMsg:Utilization,PowerState,PowerOn,PowerOff,FwBusy,AvgPower,Temperature) over the statistics ring channel.drm/asahidecodes them indrivers/gpu/drm/asahi/channel.rs::StatsChannel::polland only debug-logsthem. The coreglass producer contract calls for these to be exported as a
key valuefile on the DRM platform device so the live sampler can read themat 10 Hz.
What this does
Seventeen commits on top of
aurora-wip(head993288b37ec4):stats_exportmodule parameter. Default on. Off printsunsupported.repr(C)StatsSnapshotthat the stats channel fills and a Cdevice_attributeshim prints asbusy_ns jobs pstate power_mw util1..util4 temperature_raw temperature_scale. The shim is C because the Rust bindgenbindings for this tree lack
device_create_file.jobscounts completed submissions (JobFence::command_complete, oneRelaxedfetch_add).busy_nsintegrates the firmwareUtilizationmessage: each window adds(ts - prev_ts) * max(util1..util4) / 100, converted from base-clock ticksto nanoseconds with
HwConfig::base_clock_hz(24 MHz on t600x, t602x, t8103and t8112). An earlier revision integrated
FwBusytimestamp deltas andtreated ticks as nanoseconds; both were wrong and are replaced by the last
three commits.
Documentation/ABI/testing/sysfs-driver-asahi-agx-stats.Validation state
checkpatch.pl --strict: 0 errors, 0 checks on every commit.rustfmt --check: clean on all touched Rust files.asahibuilt in,measured 2026-10-05 on head
993288b37ec4:busy_nsis monotonic over 310 samples at 10 Hz: 0 violations, 0 stepsabove 2^31.
(utilization 100 on all four queues, 50 W, pstate 8).
jobscounts real submissions (+8570 across five decode cells).stats_export=0prints exactlyunsupported.stays a draft.
-16lines atboot. They are not from this series.