Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Documentation/ABI/testing/sysfs-driver-asahi-agx-stats
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ Description:
frequency. No qualified busy-time duration, power unit
or temperature field is available.

M5 firmware (the M5 command set of the shared G17 backend) uses
the same snapshot and keys, with these differences:

pstate_status, pstate
Supported. The firmware reports the performance state
in effect in tag 0x1b, words 1 and 3, which must
agree: an index 1..13 into the board's performance
state table. The end of the interval record before it
(tag 0x19, words 1 and 2) is its firmware timestamp.
A report that names state 0 or a state beyond the
table removes pstate validity. The state reads stale
while the GPU cores are gated.

achieved_frequency_hz
The frequency of pstate in the board's performance
state table, in Hz, while pstate_status is valid.

busy_ns Cumulative u64 since the driver was bound. The tag
0x13 records of this firmware carry a timestamp in
24 MHz ticks (words 1 and 2). Each record credits the
window since the previous record of its epoch at its
device utilisation. A record more than two 8 ms
periods after the previous one, or with an earlier
timestamp, only starts a new window, so time the GPU
spent gated is never credited. MEASURED on T6050
(J716c): 871 and 863 ms for three 300 ms compute jobs
at full clock (905 and 919 ms of work).

requested_frequency_hz, power_mw, temperature_raw
Unsupported.

The host uses a 16 ms age/averaging-window limit for V25G83 and
32 ms for V26A428 (two nominal periods). These are conservative
host policies, not firmware guarantees about packet duration.
Expand Down
56 changes: 49 additions & 7 deletions Documentation/gpu/asahi-usage-stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,25 @@ successful stages that retired before a later failure remain counted. An
unexecuted G17 replay contributes only when it eventually retires successfully.
There is no submit-to-completion wall-time fallback in the current backends.

``drm-cycles-*`` and ``drm-maxfreq-*`` are intentionally absent. The timestamp
clock is independent of the variable GPU execution clock. Treating command timer
ticks as GPU busy cycles, or multiplying time by a sampled/maximum GPU frequency,
would give incorrect frequency-weighted utilization. Per-client execution-cycle
counters would require a separate hardware measurement source.
``drm-cycles-*`` is intentionally absent. The timestamp clock is independent of
the variable GPU execution clock. Treating command timer ticks as GPU busy
cycles, or multiplying time by a sampled/maximum GPU frequency, would give
incorrect frequency-weighted utilization. Per-client execution-cycle counters
would require a separate hardware measurement source.

On the M5 each engine also has the frequency keys::

drm-curfreq-compute: 1620000000 Hz
drm-maxfreq-compute: 1620000000 Hz

``drm-curfreq-<engine>`` is ``achieved_frequency_hz`` of ``agx_stats`` (see
below): the frequency of the performance state the firmware reports. It is
absent while the firmware reports none, as when the GPU is gated.
``drm-maxfreq-<engine>`` is the highest frequency in the board's table. One clock
drives the three engines, so both values are the device's, the same for every
engine and every client. They show the clock at the time of the read and are
not a weight for the engine times: without ``drm-cycles-*`` there is nothing to
scale. Other GPUs print neither key.

Accounting cost
---------------
Expand All @@ -66,7 +80,9 @@ per valid stage, with no new locks or allocations. The native backends reuse
existing timestamp reads. Classic completion callbacks read two internal cells
per stage; commands without application timestamps also execute two existing
timestamp microsequence operations per stage. Reading fdinfo loads three counters
and does not traverse queues, wait for fences or access hardware.
and does not traverse queues, wait for fences or access hardware. On the M5 a
read also takes the device mutex once and drains the statistics rings, as a read
of ``agx_stats`` does, for the frequency keys.

G16S and G17P device utilisation
------------------------------
Expand Down Expand Up @@ -109,11 +125,37 @@ ring on powered cores becomes stale rather than fabricating a zero-utilisation
sample; only gated cores read as zero. Readers
must not convert these percentages into engine nanoseconds or cycles.

M5 performance state and busy time
----------------------------------

The M5 firmware runs on the same backend and decoder, and its statistics ring
carries more. ``agx_stats`` reports there:

* ``pstate``: the performance state in effect, from the firmware's state
reports (tag ``0x1b``, words 1 and 3, which must agree). It is an index into
the board's performance state table, 1 to 13. The interval record before a
report (tag ``0x19``) gives its firmware timestamp. A report that names state
0 or a state beyond the table is not used, and ``pstate_status`` reads
``stale`` while the cores are gated.
* ``achieved_frequency_hz``: the frequency of that state in the board's table,
while ``pstate_status`` is ``valid``.
* ``busy_ns``: the M5 utilisation records carry their own timestamps (words 1
and 2, 24 MHz ticks), so each record closes a window of known length, which
is credited at the record's device utilisation. A record that follows the
previous one by more than two 8 ms periods, or whose timestamp went back,
only starts a new window: time the GPU spent gated is never credited. The
total keeps counting across power epochs.

``requested_frequency_hz``, ``power_mw`` and ``temperature_raw`` stay
unsupported. ``busy_ns`` is device-wide, as on G13 and G14; it does not change
fdinfo's per-client ``drm-engine-*`` counters.

Deferred shared power telemetry
------------------------------

Current pstate and requested/achieved frequency remain unsupported for these
firmware graphs. The shared-power snapshot ABI is not sufficiently specified
firmware graphs (the M5 firmware reports its state in the statistics ring, see
above). The shared-power snapshot ABI is not sufficiently specified
to implement a read-only reader. For **each** of G16S and G17P, it still needs:

* The firmware-version-to-layout mapping, containing allocation and bounds,
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/asahi/asahi_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ module! {
default: 512,
description: "G13/G14: GPU event-drain utilization minimum (0..1024)",
},
compute_timeout_max_ms: u32 {
default: 30000,
description: "G17: longest compute watchdog allowance a queue may set, ms (floor 2000)",
},
g15_deadline_ms: u32 {
default: 5000,
description: "G15: host deadline of a published prefix without progress, ms (min 100)",
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ impl drm::driver::Driver for AsahiDrmDriver {
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::gem_madvise),
(ASAHI_GEM_USERPTR, drm_asahi_gem_userptr,
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::gem_userptr),
(ASAHI_GEM_RESIDENCY, drm_asahi_gem_residency,
ioctl::AUTH | ioctl::RENDER_ALLOW, crate::file::File::gem_residency),
}
}

Expand Down
54 changes: 53 additions & 1 deletion drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ pub(crate) const DRM_ASAHI_FEATURE_COMPUTE_VISIBLE_COMPLETION: u64 =
/// command may wait for it in firmware.
pub(crate) const DRM_ASAHI_COMPUTE_VISIBLE_COMPLETION: u32 =
uapi::drm_asahi_compute_flags_DRM_ASAHI_COMPUTE_VISIBLE_COMPLETION as u32;
/// Queues take a watchdog allowance for their compute commands
/// (`drm_asahi_queue_create::compute_timeout_ms`).
pub(crate) const DRM_ASAHI_FEATURE_COMPUTE_TIMEOUT: u64 =
uapi::DRM_ASAHI_FEATURE_COMPUTE_TIMEOUT as u64;
/// The tiling half waits only on the render and compute prefixes of the command's stage-prefix
/// fields, its fragment half on the whole ones.
#[allow(dead_code)]
Expand Down Expand Up @@ -378,6 +382,8 @@ pub(crate) struct File {
/// Largest size this file has asked GET_PARAMS for the global parameters with
/// ([`gpu::Gpu::admit_vm`]).
params_size: core::sync::atomic::AtomicU64,
/// The device's statistics, for the GPU frequency in fdinfo.
stats: Option<Arc<crate::stats::StatsSnapshot>>,
/// The queues were drained once for an exiting task.
drained: AtomicBool,
}
Expand All @@ -401,9 +407,10 @@ impl drm::file::DriverFile for File {
let user_range = gpu.user_range();
let mem = memacct::Client::new()?;
let usage = Arc::new(crate::usage::Client::new(), GFP_KERNEL)?;
let stats = gpu.stats_snapshot();

mod_dev_dbg!(device, "[File {}]: DRM device opened\n", id);
KBox::pin_init(File::new(id, user_range, mem, usage), GFP_KERNEL)
KBox::pin_init(File::new(id, user_range, mem, usage, stats), GFP_KERNEL)
})
}

Expand All @@ -428,6 +435,11 @@ impl drm::file::DriverFile for File {
}
}

/// One clock drives every engine.
fn engine_frequency(&self) -> Option<(Option<u64>, u64)> {
self.stats.as_ref()?.engine_frequency()
}

fn as_raw(&self) -> *mut bindings::drm_file {
todo!()
}
Expand All @@ -442,6 +454,7 @@ impl File {
user_range: Range<u64>,
mem: Arc<memacct::Client>,
usage: Arc<crate::usage::Client>,
stats: Option<Arc<crate::stats::StatsSnapshot>>,
) -> impl PinInit<Self, Error> {
// SAFETY: The initializer supplies aligned, pinned storage for Self.
// XArray::new is infallible; each pinned array is initialized in place,
Expand Down Expand Up @@ -473,6 +486,7 @@ impl File {
addr_of_mut!((*slot).mem).write(mem);
addr_of_mut!((*slot).usage).write(usage);
addr_of_mut!((*slot).params_size).write(core::sync::atomic::AtomicU64::new(0));
addr_of_mut!((*slot).stats).write(stats);
addr_of_mut!((*slot).drained).write(AtomicBool::new(false));
Ok(())
})
Expand Down Expand Up @@ -568,6 +582,9 @@ impl File {
if Self::supports_user_memory(reg_data) {
params.features |= uapi::DRM_ASAHI_FEATURE_USERPTR as u64;
}
if Self::supports_residency_control(reg_data) {
params.features |= uapi::DRM_ASAHI_FEATURE_GEM_RESIDENCY as u64;
}

let size = core::mem::size_of::<uapi::drm_asahi_params_global>().min(data.size.try_into()?);

Expand Down Expand Up @@ -997,6 +1014,34 @@ impl File {
Ok(0)
}

/// Whether this GPU takes residency requests (DRM_IOCTL_ASAHI_GEM_RESIDENCY): only G17 user
/// VMs release idle memory under pressure.
fn supports_residency_control(reg_data: &driver::AsahiDrmRegistrationData<'_>) -> bool {
reg_data.gpu.as_any().is::<crate::g17::Gpu>()
}

/// IOCTL: gem_residency: Keep an object's memory resident, or return it to the default
/// policy.
pub(crate) fn gem_residency(
_device: &AsahiDrmDevice,
reg_data: &driver::AsahiDrmRegistrationData<'_>,
data: &mut uapi::drm_asahi_gem_residency,
file: &DrmFile,
) -> Result<u32> {
if !Self::supports_residency_control(reg_data) {
return Err(EOPNOTSUPP);
}
if data.flags & !uapi::drm_asahi_gem_residency_flags_DRM_ASAHI_GEM_RESIDENCY_KEEP != 0 {
return Err(EINVAL);
}
let gem = gem::Object::lookup_handle(file, data.handle)?;
gem::set_keep_resident(
&gem,
data.flags & uapi::drm_asahi_gem_residency_flags_DRM_ASAHI_GEM_RESIDENCY_KEEP != 0,
)?;
Ok(0)
}

/// IOCTL: gem_mmap_offset: Assign an mmap offset to a GEM object.
pub(crate) fn gem_mmap_offset(
device: &AsahiDrmDevice,
Expand Down Expand Up @@ -1584,6 +1629,10 @@ impl File {
data.flags,
);

if data.pad != 0 {
cls_pr_debug!(Errors, "queue_create: Invalid arguments\n");
return Err(EINVAL);
}
if data.flags != 0 || data.priority > uapi::drm_asahi_priority_DRM_ASAHI_PRIORITY_REALTIME {
cls_pr_debug!(Errors, "queue_create: Invalid arguments\n");
return Err(EINVAL);
Expand Down Expand Up @@ -1655,6 +1704,9 @@ impl File {
)?;

queue.reserve_render_scs(data.render_scs_layout)?;
if data.compute_timeout_ms != 0 {
data.compute_timeout_ms = queue.set_compute_timeout(data.compute_timeout_ms)?;
}

data.queue_id = resv.index().try_into()?;
resv.fill(Arc::pin_init(
Expand Down
9 changes: 7 additions & 2 deletions drivers/gpu/drm/asahi/g17/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ pub(crate) struct Rings {
}

impl Rings {
pub(crate) fn new(graph: super::fw::variant::InitGraph) -> Result<Self> {
/// `m5`: the firmware runs the M5 protocol, whose statistics records are decoded too.
pub(crate) fn new(graph: super::fw::variant::InitGraph, m5: bool) -> Result<Self> {
Ok(Self {
quarantined: [[false; 2]; 2],
reports: super::reports::Reports::new()?,
telemetry: super::telemetry::Telemetry::default(),
telemetry: if m5 {
super::telemetry::Telemetry::m5()
} else {
super::telemetry::Telemetry::default()
},
max_age_ns: super::stats::max_age_ns(graph),
suspended: false,
discard_statistics: [false; 2],
Expand Down
Loading
Loading