Skip to content
Merged
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
34 changes: 34 additions & 0 deletions Documentation/devicetree/bindings/power/apple,pmc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,40 @@ patternProperties:
The SMC, whose package power reading the low-power platform profile
holds the CPU clusters to.

apple,gpu-busy-memory-states:
$ref: /schemas/types.yaml#/definitions/uint32-matrix
description:
The DCS state (first row) and fabric state (second row) for GPU work
the GPU driver reports, by the busy share it reports, below each of
the three apple,gpu-busy-permille shares and at or above the last.
A non-zero top DCS state enables the busy-share ladder; without
these properties, reported GPU work gets the compatible's default
floor.
minItems: 2
maxItems: 2
items:
minItems: 4
maxItems: 4
items:
maximum: 15

apple,gpu-busy-permille:
$ref: /schemas/types.yaml#/definitions/uint32-array
description:
The GPU busy shares, in permille of the time the GPU spends
executing, from which reported GPU work gets the second, third and
top column of apple,gpu-busy-memory-states.
minItems: 3
maxItems: 3
items:
maximum: 1000

dependentRequired:
apple,gpu-busy-memory-states:
- apple,gpu-busy-permille
apple,gpu-busy-permille:
- apple,gpu-busy-memory-states

required:
- compatible
- reg
Expand Down
12 changes: 12 additions & 0 deletions arch/arm64/boot/dts/apple/t6041.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,20 @@
apple,static-voters = <1 3>;
};

/*
* The GPU's memory states by the busy share the GPU driver reports, measured
* on a J616c: DCS 1, 2, 4 or 5 and fabric 0, 0, 0 or 3, split at 160, 500
* and 800 permille, and the top column with no share reported. The top
* column matches apple_clpc_hw_t6041's DCS 5 / fabric 3 floor (full memory
* bandwidth), so busy GPU work keeps it; light work such as scrolling a
* browser gets the lower columns. With a 3 GB/s copy: DCS 0 / fabric 0
* 5.46 W at 309 ns DRAM latency, DCS 3 6.22 W at 166 ns, DCS 4 6.92 W at
* 114 ns, DCS 5 7.04 W at 113 ns.
*/
&clpc {
compatible = "apple,t6041-max-clpc", "apple,t6041-clpc";
apple,gpu-busy-memory-states = <1 2 4 5>, <0 0 0 3>;
apple,gpu-busy-permille = <160 500 800>;
};

/ {
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/g17/clpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ void asahi_clpc_gpu_set_active(struct apple_clpc_gpu *gpu, bool active)
{
apple_clpc_gpu_set_active(gpu, active);
}

void asahi_clpc_gpu_set_busy(struct apple_clpc_gpu *gpu, unsigned int permille)
{
apple_clpc_gpu_set_busy(gpu, permille);
}

void asahi_clpc_gpu_put(struct apple_clpc_gpu *gpu)
{
apple_clpc_gpu_put(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 @@ -5,5 +5,6 @@ struct device;
struct apple_clpc_gpu;
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_put(struct apple_clpc_gpu *gpu);
#endif
14 changes: 8 additions & 6 deletions drivers/gpu/drm/asahi/g17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1076,12 +1076,14 @@ impl Firmware {
}
power::IdleAction::Recheck(delay) => Some(delay),
};
Ok(
match (effort, self.idle_hold(now_ns, in_flight || submitted)) {
(Some(a), Some(b)) => Some(a.min(b)),
(a, b) => a.or(b),
},
)
let busy_recheck = if in_flight {
self.port.report_busy(now_ns);
self.port.busy_recheck_delay(now_ns)
} else {
None
};
let hold = self.idle_hold(now_ns, in_flight || submitted);
Ok([effort, hold, busy_recheck].into_iter().flatten().min())
}

/// Drives the idle hold (see power::Hold); returns the delay in ns for its next check. A
Expand Down
117 changes: 104 additions & 13 deletions drivers/gpu/drm/asahi/g17/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ pub(super) struct Port {
/// Full firmware effort is applied; cleared before an idle clear rechecks `submissions`.
effort_full: AtomicBool,
demand: super::power::Demand,
/// Serializes busy-share window accounting and CLPC busy updates.
#[pin]
busy: SpinLock<super::power::BusyShare>,
/// Mirrored from `busy` and `qos` for a lock-free fast path in `note_gpu_activity()`.
busy_window_start: AtomicU64,
busy_below_top: AtomicBool,
oldest_in_flight_any: AtomicU64,
statistics_epoch: AtomicU64,
last_submission_ns: AtomicU64,
submissions: AtomicU64,
Expand Down Expand Up @@ -174,6 +181,10 @@ impl Port {
publications: AtomicU64::new(0),
effort_full: AtomicBool::new(false),
demand,
busy <- new_spinlock!(super::power::BusyShare::new(), "g17::Port::busy"),
busy_window_start: AtomicU64::new(0),
busy_below_top: AtomicBool::new(false),
oldest_in_flight_any: AtomicU64::new(0),
statistics_epoch: AtomicU64::new(0),
last_submission_ns: AtomicU64::new(0),
submissions: AtomicU64::new(0),
Expand Down Expand Up @@ -427,10 +438,14 @@ impl Port {
policy: Policy,
) -> Result<qos::Publication> {
let view = self.qos_view()?;
let publication = self
.qos
.lock()
.publish(&view, owner, scheduler, policy, qos::clock)?;
let publication = {
let mut qos = self.qos.lock();
let publication =
qos.publish(&view, owner, scheduler, policy, qos::clock, super::now_ns())?;
self.oldest_in_flight_any
.store(qos.oldest_in_flight_any(), Ordering::Relaxed);
publication
};
self.rx_update();
Ok(publication)
}
Expand All @@ -443,17 +458,31 @@ impl Port {
policy: Policy,
) -> Result<[qos::Publication; 2]> {
let view = self.qos_view()?;
let publications =
self.qos
.lock()
.publish_owners(&view, owners, scheduler, policy, qos::clock)?;
let publications = {
let mut qos = self.qos.lock();
let publications = qos.publish_owners(
&view,
owners,
scheduler,
policy,
qos::clock,
super::now_ns(),
)?;
self.oldest_in_flight_any
.store(qos.oldest_in_flight_any(), Ordering::Relaxed);
publications
};
self.rx_update();
Ok(publications)
}

pub(super) fn qos_cancel(&self, publication: qos::Publication) -> Result {
let view = self.qos_view()?;
self.qos.lock().cancel(&view, publication)
let mut qos = self.qos.lock();
qos.cancel(&view, publication)?;
self.oldest_in_flight_any
.store(qos.oldest_in_flight_any(), Ordering::Relaxed);
Ok(())
}

/// Clears the QoS table rows of released QoS IDs (`QosIds::forget_released`); returns
Expand All @@ -468,7 +497,12 @@ impl Port {

pub(super) fn qos_complete(&self, owners: &[qos::Owner]) -> Result {
let view = self.qos_view()?;
self.qos.lock().complete(&view, owners)?;
{
let mut qos = self.qos.lock();
qos.complete(&view, owners, super::now_ns())?;
self.oldest_in_flight_any
.store(qos.oldest_in_flight_any(), Ordering::Relaxed);
}
self.rx_update();
Ok(())
}
Expand Down Expand Up @@ -538,7 +572,15 @@ impl Port {

pub(super) fn set_effort_full(&self, full: bool) {
self.effort_full.store(full, Ordering::SeqCst);
self.demand.set_active(full);
if full {
self.demand.set_active(true);
} else {
let mut busy = self.busy.lock();
self.demand.set_active(false);
busy.clear_active();
self.busy_window_start.store(0, Ordering::Relaxed);
self.busy_below_top.store(false, Ordering::Relaxed);
}
}

/// The next statistics drain and reader discard what the decoder holds.
Expand All @@ -550,6 +592,54 @@ impl Port {
self.statistics_epoch.load(Ordering::Acquire)
}

/// Reports the busiest GPU engine's share of the last window (including unretired
/// in-flight commands) to CLPC once a window elapses or an in-flight command
/// saturates its engine. Lock-free on the common in-window path.
pub(super) fn report_busy(&self, now_ns: u64) {
if !self.demand.has_provider() {
return;
}
let start = self.busy_window_start.load(Ordering::Relaxed);
let window_due =
start == 0 || now_ns.saturating_sub(start) >= super::power::BUSY_WINDOW_NS;
let long_due = !window_due
&& self.busy_below_top.load(Ordering::Relaxed)
&& {
let oldest = self.oldest_in_flight_any.load(Ordering::Relaxed);
oldest != 0
&& now_ns.saturating_sub(oldest) >= super::power::BUSY_LONG_COMMAND_NS
};
if !window_due && !long_due {
return;
}
// Read retired time (Acquire) before qos (lock Acquire): retirement calls
// qos_complete() before usage::Client::add() Release-adds ENGINE_NS, so we
// never observe both the retired time and the old in-flight timestamp.
let retired = crate::usage::ENGINE_NS
.each_ref()
.map(|ns| ns.load(Ordering::Acquire));
let oldest = self.qos.lock().oldest_in_flight();
let now_ns = super::now_ns().max(now_ns);
let mut busy = self.busy.lock();
if let Some(permille) = busy.sample(now_ns, retired, oldest) {
self.demand.set_busy(permille);
}
self.busy_window_start
.store(busy.window_start().map_or(0, |s| s.max(1)), Ordering::Relaxed);
self.busy_below_top
.store(busy.below_top(), Ordering::Relaxed);
}

/// Wake delay (ns) for `idle_check` while a solo long command is running below
/// the top CLPC busy column, or `None` when already at top or idle.
pub(super) fn busy_recheck_delay(&self, now_ns: u64) -> Option<u64> {
if !self.demand.has_provider() || !self.busy_below_top.load(Ordering::Relaxed) {
return None;
}
let oldest = self.oldest_in_flight_any.load(Ordering::Relaxed);
super::power::BusyShare::recheck_delay_for(now_ns, oldest)
}

pub(super) fn note_gpu_activity(&self) {
// Observe gating before activity can wake the cores. A lockless
// publisher cannot clear the decoder under the device mutex; this
Expand All @@ -561,9 +651,10 @@ impl Port {
{
self.statistics_epoch.fetch_add(1, Ordering::Release);
}
self.last_submission_ns
.store(super::now_ns(), Ordering::Relaxed);
let now_ns = super::now_ns();
self.last_submission_ns.store(now_ns, Ordering::Relaxed);
self.demand.set_active(true);
self.report_busy(now_ns);
}

pub(super) fn write_power(&self, f: &mut kernel::fmt::Formatter<'_>) -> kernel::fmt::Result {
Expand Down
Loading
Loading