Skip to content
Open
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
19 changes: 19 additions & 0 deletions Documentation/devicetree/bindings/power/apple,pmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,25 @@ patternProperties:
The low-power platform profile tells the SMC (apple,smc) that Low
Power Mode is on, in the record that carries High Power mode.

apple,low-power-capacity-ceiling:
type: boolean
description:
When the low-power profile holds a package power target, scale
each CPU cluster's initial frequency ceiling from
apple,low-power-frequency-max-mhz by the ratio of the fastest
cluster's capacity-dmips-mhz to that cluster's capacity-dmips-mhz.
Efficiency clusters then stay uncapped up to the same single-thread
performance level as the performance cluster at the ceiling, and
the power loop steps them down only when package power exceeds the
target.

apple,energy-monitor:
$ref: /schemas/types.yaml#/definitions/phandle
description:
Optional apple,acc-energy node providing hardware CPU and cluster
energy accumulators sampled alongside live GPU power every 100 ms
in the low-power profile, supplementing the slower SMC power key.

apple,gpu-busy-memory-states:
$ref: /schemas/types.yaml#/definitions/uint32-matrix
description:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/soc/apple/apple,acc-energy.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#

title: Apple SoC CPU/cluster hardware energy accumulators

maintainers:
- Nick <nekreshen@yandex.ru>

description: |
Memory-mapped 64-bit hardware energy accumulators in the Apple CPU complex
(per-core and cluster memory energy counters). Each reg entry covers one
16-byte accumulator pair: the primary 64-bit counter at +0x0 and the
companion SRAM 64-bit counter at +0x8, incremented in units of
apple,picojoules-per-tick. Referenced by apple,energy-monitor from a CLPC
node for 100 ms low-power package limiting.

properties:
compatible:
items:
- enum:
- apple,t8142-acc-energy
- const: apple,acc-energy

reg:
minItems: 1
maxItems: 32
description:
16-byte register windows, each containing a pair of 64-bit hardware
energy accumulators (core/cluster logic at +0x0, SRAM at +0x8).

apple,picojoules-per-tick:
$ref: /schemas/types.yaml#/definitions/uint32
minimum: 1
description:
Energy represented by one accumulator tick, in picojoules.

required:
- compatible
- reg
- apple,picojoules-per-tick

additionalProperties: false

examples:
- |
soc {
#address-cells = <2>;
#size-cells = <2>;

power-monitor@210059000 {
compatible = "apple,t8142-acc-energy", "apple,acc-energy";
reg = <0x2 0x10059000 0x0 0x10>,
<0x2 0x10e48000 0x0 0x10>,
<0x2 0x11059000 0x0 0x10>,
<0x2 0x11e48000 0x0 0x10>;
apple,picojoules-per-tick = <25>;
};
};
15 changes: 15 additions & 0 deletions Documentation/devicetree/bindings/soc/apple/apple,clpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ properties:
The low-power platform profile tells the SMC (apple,smc) that Low Power
Mode is on, in the record that carries High Power mode.

apple,low-power-capacity-ceiling:
type: boolean
description:
When the low-power profile holds a package power target, scale each
CPU cluster's initial frequency ceiling from
apple,low-power-frequency-max-mhz by the ratio of the fastest
cluster's capacity-dmips-mhz to that cluster's capacity-dmips-mhz.

apple,energy-monitor:
$ref: /schemas/types.yaml#/definitions/phandle
description:
Optional apple,acc-energy node providing hardware CPU and cluster
energy accumulators sampled alongside live GPU power every 100 ms in
the low-power profile, supplementing the slower SMC power key.

required:
- compatible

Expand Down
19 changes: 19 additions & 0 deletions arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@
};

&{/soc} {
cpu_energy: power-monitor@210059000 {
compatible = "apple,t8142-acc-energy", "apple,acc-energy";
reg = <0x2 0x10059000 0x0 0x10>,
<0x2 0x10159000 0x0 0x10>,
<0x2 0x10259000 0x0 0x10>,
<0x2 0x10359000 0x0 0x10>,
<0x2 0x10459000 0x0 0x10>,
<0x2 0x10559000 0x0 0x10>,
<0x2 0x10e48000 0x0 0x10>,
<0x2 0x11059000 0x0 0x10>,
<0x2 0x11159000 0x0 0x10>,
<0x2 0x11259000 0x0 0x10>,
<0x2 0x11359000 0x0 0x10>,
<0x2 0x11e48000 0x0 0x10>;
apple,picojoules-per-tick = <25>;
};

cpufreq_e: performance-controller@210e20000 {
compatible = "apple,t8142-cluster-cpufreq";
reg = <0x2 0x10e20000 0 0x1000>;
Expand Down Expand Up @@ -256,6 +273,8 @@
apple,low-power-gpu-cap;
/* Tell the SMC when the low-power platform profile is on. */
apple,low-power-smc-notice;
apple,low-power-capacity-ceiling;
apple,energy-monitor = <&cpu_energy>;
/* The ANE engine clock follows the P cluster's frequency */
apple,ane-cpu-opp = <&pcluster_opp_4176>;
/*
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/asahi/g17/clpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ void asahi_clpc_gpu_clear_busy(struct apple_clpc_gpu *gpu)
apple_clpc_gpu_clear_busy(gpu);
}

void asahi_clpc_gpu_set_power_mw(struct apple_clpc_gpu *gpu, unsigned int power_mw)
{
apple_clpc_gpu_set_power_mw(gpu, power_mw);
}

unsigned int asahi_clpc_gpu_power_cap(struct apple_clpc_gpu *gpu)
{
return apple_clpc_gpu_power_cap(gpu);
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/asahi/g17/clpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ int asahi_clpc_gpu_get(void *dev, struct apple_clpc_gpu **out);
void asahi_clpc_gpu_set_active(struct apple_clpc_gpu *gpu, bool active);
void asahi_clpc_gpu_set_busy(struct apple_clpc_gpu *gpu, unsigned int permille);
void asahi_clpc_gpu_clear_busy(struct apple_clpc_gpu *gpu);
void asahi_clpc_gpu_set_power_mw(struct apple_clpc_gpu *gpu, unsigned int power_mw);
unsigned int asahi_clpc_gpu_power_cap(struct apple_clpc_gpu *gpu);
void asahi_clpc_gpu_put(struct apple_clpc_gpu *gpu);
#endif
7 changes: 7 additions & 0 deletions drivers/gpu/drm/asahi/g17/fw/m5/initdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,13 @@ pub(crate) const M5_STATUS_CONFIG_LINK_WORD: usize = 0x774;

pub(crate) const M5_STATUS_CONFIG_LINK_PTR: usize = 0x778;

/// Fast host power-target words in the M5 status config (inside the unshifted
/// `0x000..0x1dc` band across all M5 firmware layouts): enable flag, target in mW,
/// and policy reason word.
pub(crate) const M5_STATUS_CONFIG_POWER_TARGET_ENABLE: usize = 0x128;
pub(crate) const M5_STATUS_CONFIG_POWER_TARGET_MW: usize = 0x12c;
pub(crate) const M5_STATUS_CONFIG_POWER_TARGET_REASON: usize = 0x144;

/// Submission-history period and slot count (two u64), its generation word and its per-slot
/// bytes in the status config, at 26A428 offsets.
pub(crate) const M5_STATUS_CONFIG_HISTORY: usize = 0x73c;
Expand Down
61 changes: 61 additions & 0 deletions drivers/gpu/drm/asahi/g17/initdata/m5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,67 @@ impl InitData {
self.m5_policy = m::m5_policy(layouts);
}

/// M5 only: reads the live status-config power target word (mW).
pub(in crate::g17) fn m5_power_target(&self) -> Result<u32> {
if !self.m5 {
return Err(EINVAL);
}
let private = self.object(self.cluster)?;
let offset = self
.m5_status_config
.relocate(m::M5_STATUS_CONFIG_POWER_TARGET_MW)
.ok_or(EINVAL)?;
Ok(private
.word(self.graph.private.status_config + offset)?
.load(Ordering::Relaxed))
}

/// M5 only: publishes the fast status-config power target (mW) and policy reason.
/// The reason sits on another cache line than the target and enable words, so it is
/// written, cleaned and drained first: the firmware never sees the new enable and
/// target with the old reason. Then the target, then the enable, each cleaned and
/// drained before the next store.
pub(in crate::g17) fn publish_m5_power_target(&self, target_mw: u32, reason: u32) -> Result {
if !self.m5 {
return Err(EINVAL);
}
let private = self.object(self.cluster)?;
let base = self.graph.private.status_config;
let field = |offset| {
self.m5_status_config
.relocate(offset)
.map(|at| base + at)
.ok_or(EINVAL)
};
let enable_at = field(m::M5_STATUS_CONFIG_POWER_TARGET_ENABLE)?;
let target_at = field(m::M5_STATUS_CONFIG_POWER_TARGET_MW)?;
let reason_at = field(m::M5_STATUS_CONFIG_POWER_TARGET_REASON)?;
let enable_word = private.word(enable_at)?;
let target_word = private.word(target_at)?;
let reason_word = private.word(reason_at)?;
let enable_line = private.pointer(enable_at, 4)?;
let target_line = private.pointer(target_at, 4)?;
let reason_line = private.pointer(reason_at, 4)?;
// SAFETY: the pointer lies inside the retained host mapping of the
// private cluster; cleaning its cache line and draining publishes the
// naturally aligned store before it to the firmware.
let publish = |line: *mut u8| unsafe {
core::arch::asm!(
"dc cvac, {line}",
"dsb sy",
line = in(reg) line,
options(nostack, preserves_flags)
)
};
reason_word.store(reason, Ordering::Relaxed);
publish(reason_line);
target_word.store(target_mw, Ordering::Relaxed);
publish(target_line);
enable_word.store(1, Ordering::Relaxed);
publish(enable_line);
Ok(())
}

/// Counts `submissions` in the firmware's submission history, in the slot of this moment.
pub(crate) fn note_m5_submission_history(&self, submissions: u8) -> Result {
if !self.m5 { return Err(EINVAL); }
Expand Down
53 changes: 45 additions & 8 deletions drivers/gpu/drm/asahi/g17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,8 @@ struct Firmware {
hold: power::Hold,
/// M5: host GPU power budget governor (Region C's budget word).
governor: thermal::Governor,
/// M5: fast CLPC low-power target (status config `+0x12c`).
power_target: thermal::PowerTarget,
registration_power_release_pending: bool,
variant: &'static fw::Variant,
queues: runtime::Registry,
Expand Down Expand Up @@ -971,6 +973,8 @@ impl Firmware {
// preparations, or the sleep's commit: the firmware no longer runs, and its latched
// effort must not keep the fans boosted.
if !self.primary.running || power::Control::crashed(self) {
// No stale GPU power in CLPC's loop while the firmware is not running.
self.port.set_power_mw(0);
return None;
}
let now = now_ns();
Expand All @@ -985,28 +989,32 @@ impl Firmware {
self.governor.note_activity(now);
}
// The low-power profile's GPU power cap (CLPC), applied while the GPU is busy.
let cap = self.port.power_cap_mw();
let busy = thermal::requested() && self.governor.recent_activity(now);
let power = if busy { self.init.m5_gpu_power_mw().unwrap_or(0) } else { 0 };
self.port.set_power_mw(power);
let raw_cap = self.port.power_cap_mw();
let active_cap = if busy { raw_cap } else { 0 };
// Prefer the fast M5 status-config power target; fall back to Region C if absent.
let cap = if self.apply_power_target(active_cap) { 0 } else { raw_cap };
// Without the budget controller (not requested, or the SoC die zone or its passive trip
// gone) only the fan assistance and the cap run (FanBoost::apply). A budget the
// controller left below the calibrated maximum (or the cap) goes back, and a failed write
// is retried.
if !thermal::enabled() {
let busy = thermal::requested() && self.governor.recent_activity(now);
let cap = if busy { cap } else { 0 };
if let Ok(current) = self.init.m5_power_budget() {
self.governor.set_maximum(current);
}
if let Some(budget) = self.governor.restore_capped(cap) {
self.publish_budget(budget);
}
let again = busy || fans || self.governor.pending();
let again = busy || fans || self.governor.pending() || self.power_target.pending();
return Some((again, thermal::CpuAdvice::Release, busy));
}
let Ok(current) = self.init.m5_power_budget() else {
return Some((false, thermal::CpuAdvice::Release, false));
return Some((self.power_target.pending(), thermal::CpuAdvice::Release, false));
};
self.governor.set_maximum(current);
let power = self.init.m5_gpu_power_mw().unwrap_or(0);
let clamped = self.init.m5_firmware_clamped().unwrap_or(false);
let (publish, again) = self.governor.tick(temp_mc, power, clamped, cap, now);
if let Some(budget) = publish {
Expand All @@ -1015,8 +1023,25 @@ impl Firmware {
let advice = self.governor.cpu_advice(power, now);
let want_fans = self.governor.fans_wanted(now);
// Keep ticking while the fans are still boosted, so the hold can expire, and while a
// budget write is owed.
Some((again || fans || self.governor.pending(), advice, want_fans))
// budget or status-config target write is owed.
Some((
again || fans || self.governor.pending() || self.power_target.pending(),
advice,
want_fans,
))
}

/// Publishes the fast M5 status-config power target when available; returns true if handled.
fn apply_power_target(&mut self, cap_mw: u32) -> bool {
let Ok(current) = self.init.m5_power_target() else {
return false;
};
if let Some((target_mw, reason)) = self.power_target.apply(cap_mw, current) {
if self.init.publish_m5_power_target(target_mw, reason).is_err() {
self.power_target.publish_failed();
}
}
true
}

/// Publishes a budget the governor returned; a failed write stays owed for the next step.
Expand All @@ -1026,14 +1051,24 @@ impl Firmware {
}
}

/// Restore the calibrated maximum budget (shutdown).
/// Restore the calibrated maximum budget and status-config power target (shutdown).
fn governor_restore(&mut self) {
self.port.set_power_mw(0);
if let Ok(current) = self.init.m5_power_target() {
if let Some((target_mw, reason)) = self.power_target.restore(current) {
let _ = self.init.publish_m5_power_target(target_mw, reason);
}
}
if let Some(budget) = self.governor.restore() {
let _ = self.init.publish_m5_power_budget(budget);
}
}

fn apply_effort(&mut self, effort: u32) -> Result {
// The power target is lazy (thermal::PowerTarget): a zero cap only restores a cap this
// driver put in, so leaving the low-power profile under load uncaps at once.
let cap = if effort == 0 { 0 } else { self.port.power_cap_mw() };
let _ = self.apply_power_target(cap);
Self::apply_shared_effort(
&self.primary.state.shared,
&self.init,
Expand Down Expand Up @@ -2675,6 +2710,7 @@ impl Gpu {
effort: power::Effort::new(),
hold: power::Hold::new(),
governor: thermal::Governor::new(),
power_target: thermal::PowerTarget::new(),
registration_power_release_pending: false,
variant: shared.variant,
queues <- runtime::Registry::with_waiters(
Expand Down Expand Up @@ -2884,6 +2920,7 @@ impl Gpu {
effort: power::Effort::new(),
hold: power::Hold::new(),
governor: thermal::Governor::new(),
power_target: thermal::PowerTarget::new(),
registration_power_release_pending: false,
variant: shared.variant,
queues <- runtime::Registry::with_waiters(
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/asahi/g17/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,11 @@ impl Port {
self.effort_full.store(true, Ordering::SeqCst);
}

/// Reports live GPU power draw in mW to the CLPC low-power loop.
pub(super) fn set_power_mw(&self, power_mw: u32) {
self.demand.set_power_mw(power_mw);
}

/// The power in mW the low-power profile allows the GPU's power budget, 0 for no limit.
pub(super) fn power_cap_mw(&self) -> u32 {
self.demand.power_cap_mw()
Expand Down
Loading
Loading