From 8d0f6132e5e3d9932a57ba8d4ea80f5393e847e4 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sat, 31 Oct 2026 10:58:12 -0400 Subject: [PATCH] drm/asahi: let T8122 thermal control use the full performance table The omitted T8122 experiment cap resolves to state 2 and is then applied as a firmware ceiling, so the thermal governor cannot raise the runtime cap even with valid SoC temperature readings. On J613 the captured boot reports eight table states but a firmware/runtime range of 2..2. Track whether the experiment cap was explicitly supplied. With thermal control enabled, let omission use the table ceiling while retaining state 2 for startup and sensor/critical-temperature fallback. Keep the fixed state-2 policy with thermal control off, and preserve all explicit caps 1..5 and other SoCs' policy. Hold mode exposes the table but keeps the runtime cap at state 2 for qualification. Exercise the production parser and thermal decisions in the existing host suite, including sensor failures, heat, pacing and cap enforcement. Correct the experiment help and update its installer checksum together. Native affected-driver compilation and host tests pass. Higher-state hardware correctness, thermal behavior and performance remain untested. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/m3/m3_adt_config.rs | 15 +- drivers/gpu/drm/asahi/m3/t8122_knobs.rs | 51 +++++- drivers/gpu/drm/asahi/m3/t8122_start.rs | 29 ++-- tools/asahi/m3-runtime-tests.rs | 178 +++++++++++++++++++- tools/aurora-sep/air-gpu/air-gpu-oneshot.sh | 2 +- tools/aurora-sep/install-aurora-sep.sh | 2 +- 6 files changed, 245 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/asahi/m3/m3_adt_config.rs b/drivers/gpu/drm/asahi/m3/m3_adt_config.rs index 1893c113cf2a7d..6ebb0670d07dc2 100644 --- a/drivers/gpu/drm/asahi/m3/m3_adt_config.rs +++ b/drivers/gpu/drm/asahi/m3/m3_adt_config.rs @@ -182,9 +182,9 @@ impl PstatePolicy { } /// 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) -> Result { + /// 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 { 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)?; @@ -194,6 +194,7 @@ impl PstatePolicy { 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 { @@ -219,7 +220,7 @@ impl PstatePolicy { ); 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, @@ -234,7 +235,9 @@ impl PstatePolicy { // 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)) @@ -313,7 +316,7 @@ impl Contents { 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(|| { diff --git a/drivers/gpu/drm/asahi/m3/t8122_knobs.rs b/drivers/gpu/drm/asahi/m3/t8122_knobs.rs index ca0f8a6d499ccd..491591ae27aded 100644 --- a/drivers/gpu/drm/asahi/m3/t8122_knobs.rs +++ b/drivers/gpu/drm/asahi/m3/t8122_knobs.rs @@ -25,11 +25,11 @@ pub(crate) const UNIT_MASK_B: u32 = 0x7; /// 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. @@ -162,6 +162,25 @@ pub(crate) struct Values { 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, + 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. @@ -217,6 +236,7 @@ pub(crate) fn resolve(raw: &Raw) -> Result { unit_mask_a, unit_mask_b, pstate_cap, + pstate_cap_explicit: raw.pstate_cap != UNSET, }) } @@ -265,6 +285,7 @@ mod tests { 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] @@ -330,6 +351,30 @@ mod tests { 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"] { diff --git a/drivers/gpu/drm/asahi/m3/t8122_start.rs b/drivers/gpu/drm/asahi/m3/t8122_start.rs index 737034dd6f8c13..56643059a8a306 100644 --- a/drivers/gpu/drm/asahi/m3/t8122_start.rs +++ b/drivers/gpu/drm/asahi/m3/t8122_start.rs @@ -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. @@ -220,9 +223,9 @@ impl Experiment { 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) } } @@ -283,7 +286,7 @@ pub(crate) fn arm(dev: &device::Device, soc: &Soc) -> Result> 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), @@ -293,7 +296,8 @@ pub(crate) fn arm(dev: &device::Device, soc: &Soc) -> Result> }, v.unit_mask_a, v.unit_mask_b, - v.pstate_cap + v.pstate_cap, + v.pstate_cap_explicit ); dev_warn!( dev, @@ -301,19 +305,6 @@ pub(crate) fn arm(dev: &device::Device, soc: &Soc) -> Result> 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)) } diff --git a/tools/asahi/m3-runtime-tests.rs b/tools/asahi/m3-runtime-tests.rs index fd4dc90489e817..4ae5ad17336520 100644 --- a/tools/asahi/m3-runtime-tests.rs +++ b/tools/asahi/m3-runtime-tests.rs @@ -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()); + } +} diff --git a/tools/aurora-sep/air-gpu/air-gpu-oneshot.sh b/tools/aurora-sep/air-gpu/air-gpu-oneshot.sh index 2231a78b2a3465..66083c0d0651b9 100755 --- a/tools/aurora-sep/air-gpu/air-gpu-oneshot.sh +++ b/tools/aurora-sep/air-gpu/air-gpu-oneshot.sh @@ -40,7 +40,7 @@ t8122_clkgen e1c|e5c|none clock-generator slot: t8122_sgx_setup none|t6030 SGX write before the firmware starts: none (default) or T6030 0x70001 t8122_unit_mask_a 0x[0-9a-fA-F]{1,9}|[1-9][0-9]{0,10} HwDataB unit mask A: nonzero, within 0x700000001 (default) t8122_unit_mask_b 0x[1-7]|[1-7] HwDataB unit mask B: nonzero, within 0x7 (default 0x3) -t8122_pstate_cap [1-5] highest GPU performance state, 1 to 5 (default 2; above 2 has no temperature feedback yet) +t8122_pstate_cap [1-5] ceiling 1..5; default thermal, fallback 2 m3_expose -1|0|1 render node: -1 auto (on for J613/J615, the default), 0 off, 1 on m3_timeout_nohang 0|1 on a job timeout, fail the job without the hang path ' diff --git a/tools/aurora-sep/install-aurora-sep.sh b/tools/aurora-sep/install-aurora-sep.sh index 778bf309e518e1..36f2476558bac2 100755 --- a/tools/aurora-sep/install-aurora-sep.sh +++ b/tools/aurora-sep/install-aurora-sep.sh @@ -678,7 +678,7 @@ M3_PERSISTENT_TRANSACTION_ACTIVE=0 M3_PERSISTENT_MAIN_ARMED=0 M3_GPU_BIN=/usr/local/bin M3_GPU_SCRIPTS=( - "air-gpu-oneshot.sh d0259869b8519439a4dbcdae08ef1b0e17fdcaf84ac746fca61febf6a325f8aa" + "air-gpu-oneshot.sh 56a97ae3858abe92a911bafb7b7185d26200773935416a0f2977eeb6d8f79892" "air-gpu-collect.sh face8fac811b59c31a8e98e6ca704a2cb33eceada8bc37986397cb393b050b30" "air-gpu-job.sh 9a0eb9aab52fd099488054e4ed4846c579b19fc9f78144245242b6975a40da1d" )