Skip to content
Draft
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
15 changes: 9 additions & 6 deletions drivers/gpu/drm/asahi/m3/m3_adt_config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT


Expand Down Expand Up @@ -182,9 +182,9 @@
}

/// Clamp the `asahi.m3_max_pstate` and `asahi.m3_boot_pstate` settings to the published table
/// of `hwdata` (the generated HwData object image), and to `ceiling` when given (the T8122
/// start experiment's `asahi.t8122_pstate_cap`).
fn new(dev: &device::Device, hwdata: &[u8], ceiling: Option<u32>) -> Result<Self> {
/// of `hwdata` (the generated HwData object image), and to an explicit T8122 experiment
/// cap. Its omitted cap permits the table with thermal control, starting at state 2.
fn new(dev: &device::Device, hwdata: &[u8], experiment: Option<&Experiment>) -> Result<Self> {
let hwb_max = offset_of!(raw::HwDataBG15V14_8_3, max_pstate);
let hwb_freq = offset_of!(raw::HwDataBG15V14_8_3, frequencies);
let table_max = read_u32(hwdata, hwb_max)?;
Expand All @@ -194,6 +194,7 @@
let freq = |i: u32| read_u32(hwdata, hwb_freq + 4 * i as usize);
// Unset: the thermal limit is on.
let thermal = m3_params::thermal_param().unwrap_or(ThermalMode::On);
let limits = experiment.map(|e| e.pstate_limits(thermal != ThermalMode::Off));
// Unset: the whole table when the thermal limit bounds the runtime cap, the default cap
// otherwise.
let requested = m3_params::max_pstate_param().unwrap_or(match thermal {
Expand All @@ -219,7 +220,7 @@
);
max = ADT_MAX_PSTATE_LIMIT;
}
if let Some(ceiling) = ceiling {
if let Some(ceiling) = limits.as_ref().and_then(|l| l.ceiling) {
if max > ceiling {
dev_info!(
dev,
Expand All @@ -234,7 +235,9 @@
// starts at (and never goes below) the cap used without it.
let safe = match thermal {
ThermalMode::Off => max,
ThermalMode::Hold | ThermalMode::On => max.min(ADT_MAX_PSTATE_LIMIT),
ThermalMode::Hold | ThermalMode::On => {
max.min(limits.as_ref().map_or(ADT_MAX_PSTATE_LIMIT, |l| l.safe))
}
};
let boot = m3_params::boot_pstate_param()
.unwrap_or(u64::from(safe))
Expand Down Expand Up @@ -313,7 +316,7 @@
storage::validate_iomaps(iomaps).map_err(|_| EINVAL)?;
let images = build_images(dev, firmware, soc, experiment, iomaps)?;
let hwdata = images.get(HWDATA).and_then(|i| i.as_deref()).ok_or(EINVAL)?;
let pstates = PstatePolicy::new(dev, hwdata, experiment.map(|e| e.pstate_cap()))?;
let pstates = PstatePolicy::new(dev, hwdata, experiment)?;
let table = match soc.pstates {
PstateTable::Fixed { states, top_mhz } => (states, top_mhz),
PstateTable::DeviceTree => crate::m3::m3_board::opp_table_shape(pdev, soc).ok_or_else(|| {
Expand Down
51 changes: 48 additions & 3 deletions drivers/gpu/drm/asahi/m3/t8122_knobs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT

//! The parameters of the T8122 start experiment (`t8122_start`): their text, defaults, accepted
Expand Down Expand Up @@ -25,11 +25,11 @@
/// No unit-mask bit outside these is accepted: the default masks.
pub(crate) const UNIT_MASK_A_LIMIT: u64 = 0x7_0000_0003;
pub(crate) const UNIT_MASK_B_LIMIT: u64 = 0x7;
/// The default performance-state ceiling: the lowest two states.
/// The startup and sensor-failure cap, also the fixed ceiling with thermal control off.
pub(crate) const PSTATE_CAP: u32 = 2;
/// The highest performance-state ceiling the experiment accepts. The same as the driver's own
/// limit when the fast-die temperature controller is off (`m3_adt_config::ADT_MAX_PSTATE_LIMIT`):
/// J613/J615 have no SoC die temperature zone yet, so there is no thermal feedback above it.
/// limit when thermal control is off (`m3_adt_config::ADT_MAX_PSTATE_LIMIT`). An omitted cap
/// lets thermal control use the published table; explicit experiment caps remain bounded.
pub(crate) const PSTATE_CAP_MAX: u32 = 5;

/// Parse a decimal or `0x`-prefixed hexadecimal `u64`. A leading sign is not accepted.
Expand Down Expand Up @@ -162,6 +162,25 @@
pub(crate) unit_mask_a: u64,
pub(crate) unit_mask_b: u32,
pub(crate) pstate_cap: u32,
pub(crate) pstate_cap_explicit: bool,
}

/// Firmware ceiling and initial runtime cap for one T8122 boot.
pub(crate) struct PstateLimits {
/// None lets the existing policy select the ceiling from the published table.
pub(crate) ceiling: Option<u32>,
pub(crate) safe: u32,
}

impl Values {
/// Only thermal control may lift an omitted experiment cap. Explicit caps retain their
/// fixed ceiling and initial cap, including when thermal control is disabled.
pub(crate) fn pstate_limits(&self, thermal_enabled: bool) -> PstateLimits {
PstateLimits {
ceiling: (self.pstate_cap_explicit || !thermal_enabled).then_some(self.pstate_cap),
safe: self.pstate_cap,
}
}
}

/// A parameter given with a value it does not accept: its name and what it accepts.
Expand Down Expand Up @@ -217,6 +236,7 @@
unit_mask_a,
unit_mask_b,
pstate_cap,
pstate_cap_explicit: raw.pstate_cap != UNSET,
})
}

Expand Down Expand Up @@ -265,6 +285,7 @@
assert_eq!(v.sgx_setup, Some((0xd1_4000, 0x7_0001)));
assert_eq!((v.unit_mask_a, v.unit_mask_b), (0x7_0000_0003, 7));
assert_eq!(v.pstate_cap, 2);
assert!(!v.pstate_cap_explicit);
}

#[test]
Expand Down Expand Up @@ -330,6 +351,30 @@
assert_eq!(PSTATE_CAP_MAX, 5);
}

#[test]
fn omitted_cap_allows_the_table_only_with_thermal_control() {
let v = resolve(&with(|_| {})).unwrap();
let controlled = v.pstate_limits(true);
assert_eq!(controlled.ceiling, None);
assert_eq!(controlled.safe, 2);
let fixed = v.pstate_limits(false);
assert_eq!(fixed.ceiling, Some(2));
assert_eq!(fixed.safe, 2);
}

#[test]
fn explicit_caps_preserve_their_ceiling_and_startup_cap() {
for cap in 1..=PSTATE_CAP_MAX {
let v = resolve(&with(|r| r.pstate_cap = u64::from(cap))).unwrap();
assert!(v.pstate_cap_explicit);
for thermal_enabled in [false, true] {
let limits = v.pstate_limits(thermal_enabled);
assert_eq!(limits.ceiling, Some(cap));
assert_eq!(limits.safe, cap);
}
}
}

#[test]
fn a_leading_sign_is_rejected() {
for text in ["+1", "-1", "0x+1", "0x-1", "+0x10"] {
Expand Down
29 changes: 10 additions & 19 deletions drivers/gpu/drm/asahi/m3/t8122_start.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT

//! T8122 (M3, G15G) board-default startup and bounded experiment values.
Expand All @@ -16,7 +16,10 @@
//! | `asahi.t8122_sgx_setup` | `t6030`: SGX+0xd14000 = 0x70001 | `none` |
//! | `asahi.t8122_unit_mask_a` | `0x700000003` | nonzero, within `0x700000003` |
//! | `asahi.t8122_unit_mask_b` | `0x7` | nonzero, within `0x7` |
//! | `asahi.t8122_pstate_cap` | `2` | 1 to 5 |
//! | `asahi.t8122_pstate_cap` | thermal policy (below) | fixed ceiling 1 to 5 |
//!
//! An omitted cap uses the full table with thermal control, starting/falling back at state 2.
//! With thermal control off it retains a fixed ceiling of 2.
//!
//! The defaults are the T8122 table's values. A parameter given with a value it does not accept
//! refuses the start. Unlisted boards remain refused by the existing backend admission.
Expand Down Expand Up @@ -220,9 +223,9 @@
self.0.sgx_setup
}

/// The highest performance state the firmware may use (`asahi.t8122_pstate_cap`).
pub(crate) fn pstate_cap(&self) -> u32 {
self.0.pstate_cap
/// T8122 ceiling and startup cap, retaining an explicit `asahi.t8122_pstate_cap`.
pub(crate) fn pstate_limits(&self, thermal_enabled: bool) -> knobs::PstateLimits {
self.0.pstate_limits(thermal_enabled)
}
}

Expand Down Expand Up @@ -283,7 +286,7 @@
let e = Experiment(v);
dev_warn!(
dev,
"M3 G15G start: armed (board default or asahi.t8122_start=1, boot loader handoff admitted): initdata_version={:#018x} fender={:#x} clkgen={} sgx_setup={} unit_mask_a={:#x} unit_mask_b={:#x} pstate_cap={}\n",
"M3 G15G start: armed (board default or asahi.t8122_start=1, boot loader handoff admitted): initdata_version={:#018x} fender={:#x} clkgen={} sgx_setup={} unit_mask_a={:#x} unit_mask_b={:#x} pstate_cap={} pstate_cap_explicit={}\n",
v.initdata_version,
v.fender,
clkgen_label(v.clock_gen, v.fender),
Expand All @@ -293,27 +296,15 @@
},
v.unit_mask_a,
v.unit_mask_b,
v.pstate_cap
v.pstate_cap,
v.pstate_cap_explicit
);
dev_warn!(
dev,
"M3 G15G start: the T8122 table's InitData words, HwData placement and register lists; {} IO mappings at firmware VA {:#x}\n",
e.mapping_count(),
storage::IOMAP_BASE
);
// J613/J615 have no SoC die temperature zone yet, so a cap above the no-feedback limit runs
// the fanless GPU without any temperature feedback (`m3_thermal` holds the cap but gets no
// reading). The runtime cap and the firmware ceiling stay equal, because the cap is at most
// the no-feedback limit.
if v.pstate_cap > knobs::PSTATE_CAP {
dev_warn!(
dev,
"M3 G15G start: pstate_cap={} is above {}: no SoC die temperature zone on this board, so states up to {} run with no temperature feedback\n",
v.pstate_cap,
knobs::PSTATE_CAP,
v.pstate_cap
);
}
Ok(Some(e))
}

Expand Down
178 changes: 176 additions & 2 deletions tools/asahi/m3-runtime-tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT

//! Host tests for the production M3 admission, IO ownership, thermal policy and the T8122
Expand All @@ -5,13 +5,187 @@
//! Run: rustc --edition=2021 --test tools/asahi/m3-runtime-tests.rs -o /tmp/m3-runtime-tests
#![allow(dead_code)]

#[path = "../../drivers/gpu/drm/asahi/m3/t8122_admission.rs"]
mod t8122_admission;
#[path = "../../drivers/gpu/drm/asahi/m3/m3_init_layout.rs"]
mod m3_init_layout;
#[path = "../../drivers/gpu/drm/asahi/m3/m3_init_storage.rs"]
mod m3_init_storage;
#[path = "../../drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs"]
mod m3_thermal_policy;
#[path = "../../drivers/gpu/drm/asahi/m3/t8122_admission.rs"]
mod t8122_admission;
#[path = "../../drivers/gpu/drm/asahi/m3/t8122_hwdata.rs"]
mod t8122_hwdata;

// Only the unrelated firmware-version default needs a kernel-free fixture. All parameter
// parsing, cap selection and thermal decisions below use the production modules directly.
mod m3 {
pub mod m3_firmware {
pub const G15_V14_8_3_INITDATA: u64 = 0x0c08_e21e_8380_0490;
}
}
#[path = "../../drivers/gpu/drm/asahi/m3/t8122_knobs.rs"]
mod t8122_knobs;

#[cfg(test)]
mod t8122_performance {
use super::m3_thermal_policy::{Policy, Reading, Source, Why, S};
use super::t8122_knobs::{self as knobs, Raw};

fn policy(raw: Raw, adjust: bool) -> Policy {
let limits = knobs::resolve(&raw).unwrap().pstate_limits(true);
Policy::new(adjust, limits.safe, limits.ceiling.unwrap_or(8), 80_000)
}

fn cool_to_ceiling(policy: &mut Policy) {
for i in 0..8 {
let now = i * 2 * S;
let (reading, _) = policy.update(
now,
Reading::Temp {
mc: 45_000 + i as i32,
at: now,
zones: 1,
},
);
assert!(reading.is_ok());
}
}

#[test]
fn default_reaches_full_table_and_sensor_failure_restores_state_two() {
let mut p = policy(Raw::NONE, true);
assert_eq!(p.cap(), 2);
assert_eq!(p.ceiling(), 8);
let _ = p.update(0, Reading::None);
assert_eq!(p.cap(), 2);
cool_to_ceiling(&mut p);
assert_eq!(p.cap(), 8);
let (_, change) = p.update(
16 * S,
Reading::Failed {
errno: -19,
at: 16 * S,
},
);
let change = change.unwrap();
assert_eq!((change.from, change.to), (8, 2));
assert_eq!(change.why, Why::NoTemperature(Source::Failed(-19)));
}

#[test]
fn full_cap_steps_down_on_heat_and_keeps_the_upward_pacing() {
let mut p = policy(Raw::NONE, true);
cool_to_ceiling(&mut p);
let (_, change) = p.update(
16 * S,
Reading::Temp {
mc: 80_000,
at: 16 * S,
zones: 1,
},
);
assert_eq!(change.unwrap().why, Why::Hot);
assert_eq!(p.cap(), 7);
let _ = p.update(
17 * S,
Reading::Temp {
mc: 45_000,
at: 17 * S,
zones: 1,
},
);
assert_eq!(p.cap(), 7);
let _ = p.update(
18 * S,
Reading::Temp {
mc: 45_001,
at: 18 * S,
zones: 1,
},
);
assert_eq!(p.cap(), 8);
}

#[test]
fn missing_stale_stuck_and_critical_readings_cannot_keep_the_full_cap() {
let cases = [
Reading::None,
Reading::Temp {
mc: 45_000,
at: 12 * S,
zones: 1,
},
Reading::Temp {
mc: 5_000,
at: 16 * S,
zones: 1,
},
Reading::Temp {
mc: 88_000,
at: 16 * S,
zones: 1,
},
];
for reading in cases {
let mut p = policy(Raw::NONE, true);
cool_to_ceiling(&mut p);
let _ = p.update(16 * S, reading);
assert_eq!(p.cap(), 2, "{reading:?}");
}
let mut p = policy(Raw::NONE, true);
cool_to_ceiling(&mut p);
let _ = p.update(
16 * S,
Reading::Temp {
mc: 45_007,
at: 16 * S,
zones: 1,
},
);
assert_eq!(p.cap(), 8);
let _ = p.update(
76 * S,
Reading::Temp {
mc: 45_007,
at: 76 * S,
zones: 1,
},
);
assert_eq!(p.cap(), 2);
}

#[test]
fn hold_and_explicit_caps_do_not_gain_higher_runtime_states() {
let mut held = policy(Raw::NONE, false);
cool_to_ceiling(&mut held);
assert_eq!(held.cap(), 2);
assert_eq!(held.ceiling(), 8);
for cap in 1..=5 {
let mut limited = policy(
Raw {
pstate_cap: cap,
..Raw::NONE
},
true,
);
cool_to_ceiling(&mut limited);
assert_eq!(limited.cap(), cap as u32);
assert_eq!(limited.ceiling(), cap as u32);
}
}

#[test]
fn failure_to_obey_a_lowered_cap_is_still_detected() {
let mut p = policy(Raw::NONE, true);
cool_to_ceiling(&mut p);
let _ = p.update(16 * S, Reading::None);
assert_eq!(p.allowed(16 * S), 8);
assert_eq!(p.allowed(17 * S), 2);
for i in 0..19 {
assert!(p.note_check(17 * S + i * S / 5, true).is_none());
}
assert!(p.note_check(21 * S, true).is_some());
p.note_check(22 * S, false);
assert!(p.note_check(23 * S, true).is_none());
}
}
Loading
Loading