Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
689f2f9
soc: apple: vote GPU activity to the PMP so memory leaves idle DVFS o…
joshuaswarren Nov 3, 2026
f7ad8cf
pmdomain: apple: pmp-report: export a locked, acknowledged update of …
joshuaswarren Nov 3, 2026
e033631
pmdomain: apple: pmp-report: keep the AGX bit out of the export, docu…
joshuaswarren Nov 3, 2026
5b54de3
pmdomain: apple: pmp-report: hold the AGX request 250 ms after the la…
joshuaswarren Nov 3, 2026
6ece082
pmdomain: apple: pmp-report: close the races in the AGX vote and stop…
joshuaswarren Nov 3, 2026
e8ddbd9
tools: asahi: give the T6030 graph harness the two names the extracte…
joshuaswarren Nov 3, 2026
1142df9
tools: asahi: host suite for the T6001 AGX vote policy, with mutant c…
joshuaswarren Nov 3, 2026
db48e98
tools: asahi: pin the vote clock wrap and require a passing base in t…
joshuaswarren Nov 3, 2026
825e9ac
tools: asahi: vote suite cases for the end-during-SET race, the backo…
joshuaswarren Nov 3, 2026
a7330a5
pmdomain: apple: pmp-agx-vote: drain the SET-write race, bound the re…
joshuaswarren Nov 3, 2026
2ec389c
pmdomain: apple: pmp-agx-vote: give begin the clock so a backoff cann…
joshuaswarren Nov 3, 2026
efff25c
tools: asahi: drop the dead second begin-ignores-retry control entry
joshuaswarren Nov 3, 2026
fb8cba3
tools: asahi: vote suite case for the SET-timeout race (red at this c…
joshuaswarren Nov 3, 2026
a594075
pmdomain: apple: pmp-agx-vote: arm the retry from begin when the writ…
joshuaswarren Nov 3, 2026
4574c14
tools: asahi: vote suite case for the idle retry (red at this commit)
joshuaswarren Nov 3, 2026
85a68bf
pmdomain: apple: pmp-agx-vote: arm the retry when the write outlasts …
joshuaswarren Nov 3, 2026
09613a9
pmdomain: apple: pmp-report: turn the AGX vote on by default on the t…
joshuaswarren Nov 11, 2026
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
6 changes: 6 additions & 0 deletions drivers/gpu/drm/asahi/driver.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT

//! Top-level GPU driver implementation.
Expand Down Expand Up @@ -231,6 +231,9 @@
_pdev: &'bound platform::Device<Core<'_>>,
this: Pin<&Self::Data<'bound>>,
) {
// SAFETY: Takes no arguments, process context. Clears the T6001 AGX request in the PMP report if the pmp_report.agx_vote
// parameter set it; a no-op everywhere else.
unsafe { bindings::apple_pmp_agx_activity_release() };
if let Some(gpu) = this.g17.as_ref() {
// Driver data is dropped after devres, so CPU control must happen in unbind.
gpu.shutdown();
Expand All @@ -249,6 +252,9 @@
) -> impl PinInit<Self::Data<'bound>, Error> + 'bound {
debug::update_debug_flags();

// SAFETY: Takes no arguments, process context. Lets the T6001 AGX vote run again after an earlier unbind released it; a no-op everywhere else.
unsafe { bindings::apple_pmp_agx_activity_resume() };

dev_info!(pdev.as_ref(), "Probing...\n");

let cfg = match info.ok_or(ENODEV)? {
Expand Down
5 changes: 5 additions & 0 deletions drivers/gpu/drm/asahi/gpu.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: GPL-2.0-only OR MIT

//! Top-level GPU manager
Expand Down Expand Up @@ -1284,6 +1284,9 @@
.with(|raw, _inner| raw.pending_submissions.fetch_add(1, Ordering::Acquire));

mod_dev_dbg!(self.dev, "OP start (pending: {})\n", val + 1);
// SAFETY: Takes no arguments and does nothing unless pmp_report.agx_vote is set on a T6001. The matching end call is made
// by OpGuard's Drop, and the guard is created right below, so every path out of here (including a failed kick) pairs it.
unsafe { kernel::bindings::apple_pmp_agx_activity_begin() };
let guard = OpGuard(self.clone());
self.kick_firmware()?;
Ok(guard)
Expand Down Expand Up @@ -1804,5 +1807,7 @@
.with(|raw, _inner| raw.pending_submissions.fetch_sub(1, Ordering::Release));

mod_dev_dbg!(self.dev, "OP end (pending: {})\n", val - 1);
// SAFETY: Pairs with the begin call in start_op(); callable from any context.
unsafe { kernel::bindings::apple_pmp_agx_activity_end() };
}
}
174 changes: 174 additions & 0 deletions drivers/pmdomain/apple/pmp-agx-vote.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
/*
* When the T6001 AGX request (PS-REQ bit 9 of the PMP report) is set and cleared.
*
* The GPU driver counts operations in flight (begin/end). The request is set when the first operation starts and cleared
* idle_ms after the last one ends, so a decode stream (a burst every ~10 ms) holds one vote and an idle GPU drops it. All state
* changes are in these functions; the caller serializes them with one spinlock and does the register write between
* agx_vote_decide() and agx_vote_applied(). Times are milliseconds from any wrapping clock.
*/
#ifndef PMP_AGX_VOTE_H
#define PMP_AGX_VOTE_H

#ifdef __KERNEL__
#include <linux/types.h>
/* jiffies_to_msecs() returns u32: the clock wraps every 49.7 days, and every compare below is done in 32 bits. */
typedef u32 agx_ms_t;
typedef s32 agx_sms_t;
#else
#include <stdbool.h>
#include <stdint.h>
typedef uint32_t agx_ms_t;
typedef int32_t agx_sms_t;
#endif

/* How long the request is held after the last operation ends. w7X measured idle gaps of up to 111.5 ms inside one 9B generation, so 100 ms
* was not enough; 250 ms is about 2.2 times the largest gap seen. The parameter pmp_report.agx_vote_idle_ms overrides it at run time. */
#define AGX_VOTE_IDLE_MS_DEFAULT 250

/* After a set that was not acknowledged (or a PMP that is not running), wait this long before trying again. */
#define AGX_VOTE_RETRY_MS 1000

struct agx_vote {
bool enabled; /* the module parameter */
bool voted; /* bit 9 is set and was acknowledged */
bool stopped; /* released (GPU unbind, report removal, sleep): no new vote until agx_vote_resume() */
unsigned int users; /* GPU operations in flight */
agx_ms_t idle_ms; /* keep the vote this long after the last operation ends */
agx_ms_t idle_at; /* when users last fell to 0 */
unsigned int failures; /* consecutive failed sets; the backoff applies only while this is nonzero */
agx_ms_t retry_at; /* with failures: no new set before this */
};

enum agx_vote_action {
AGX_VOTE_NONE,
AGX_VOTE_SET,
AGX_VOTE_CLEAR,
};

static inline bool agx_vote_reached(agx_ms_t now, agx_ms_t t)
{
return (agx_sms_t)(now - t) >= 0;
}

/* A retry deadline more than one backoff window in the future cannot be real: an idle gap beyond half the
* 32-bit millisecond range makes the wrapped arithmetic read an expired deadline as future. Treat it as expired. */
static inline bool agx_vote_retry_reached(const struct agx_vote *v, agx_ms_t now)
{
return agx_vote_reached(now, v->retry_at)
|| (agx_sms_t)(v->retry_at - now) > (agx_sms_t)AGX_VOTE_RETRY_MS;
}

/* An operation starts. now is the operation's start time in ms (any wrapping clock; the caller reads it
* under its lock). Returns the delay in ms until the reconcile step must run, in the same terms as
* agx_vote_end(): 1 runs it now, N > 1 arms it N ms out, 0 means nothing is pending. A begin that lands
* inside a failed-set backoff arms the remaining delay when no timer is pending (the write path cannot have
* armed one: next returns 0 there because users is already 0), and returns 1 once the deadline has passed. */
static inline agx_ms_t agx_vote_begin(struct agx_vote *v, agx_ms_t now)
{
v->users++;
if (!v->enabled || v->stopped)
return 0;
if (v->voted)
return 0;
return (!v->failures || agx_vote_retry_reached(v, now)) ? 1 : v->retry_at - now;
}

/* An operation ends. Returns the delay in ms after which the reconcile step must run, 0 when none is needed. */
static inline agx_ms_t agx_vote_end(struct agx_vote *v, agx_ms_t now)
{
if (!v->users) /* unbalanced end: ignored */
return 0;
if (--v->users)
return 0;
v->idle_at = now;
if (!v->enabled || !v->voted)
return 0;
return v->idle_ms ? v->idle_ms : 1;
}

/* What the reconcile step must do now. */
static inline enum agx_vote_action agx_vote_decide(const struct agx_vote *v, agx_ms_t now)
{
if (!v->enabled || v->stopped)
return v->voted ? AGX_VOTE_CLEAR : AGX_VOTE_NONE;
if (v->users)
return !v->voted && (!v->failures || agx_vote_retry_reached(v, now)) ? AGX_VOTE_SET : AGX_VOTE_NONE;
if (v->voted && agx_vote_reached(now, v->idle_at + v->idle_ms))
return AGX_VOTE_CLEAR;
return AGX_VOTE_NONE;
}

/*
* Delay in ms until the reconcile step must run again, 0 when no timer is needed. 1 when work is due now: an
* operation began while a clear was being written (begin saw voted still true and did not kick), or an end
* landed inside the SET write so the vote is set with an already-reached idle deadline. The caller must run the
* reconcile those cases would otherwise skip; it cannot read 1 as "nothing pending".
*/
static inline agx_ms_t agx_vote_next(const struct agx_vote *v, agx_ms_t now)
{
agx_ms_t at;

if (!v->enabled || v->stopped)
return 0;
if (v->users && !v->voted && !v->failures)
return 1;
if (v->users && !v->voted && v->failures)
at = agx_vote_retry_reached(v, now) ? now : v->retry_at;
else if (!v->users && v->voted)
at = v->idle_at + v->idle_ms;
else if (!v->users && !v->voted && v->failures)
/* The write outlasted the operation: arm the retry from the failure state
* itself. The caller clears failures when this reconcile finds nobody waiting
* (decide returns NONE), so it fires once. */
at = agx_vote_retry_reached(v, now) ? now : v->retry_at;
else
return 0;
/* An already-reached deadline returns 1: there is work, due now. The SET-write race leaves exactly
* this state (voted, no user, deadline passed), and 0 here would strand the vote set forever. */
return agx_vote_reached(now, at) ? 1 : at - now;
}

/* Record the outcome of the register write for `action` (ret 0: acknowledged). */
static inline void agx_vote_applied(struct agx_vote *v, enum agx_vote_action action, int ret, agx_ms_t now)
{
if (action == AGX_VOTE_SET) {
if (ret) {
v->failures++;
v->retry_at = now + AGX_VOTE_RETRY_MS;
} else {
v->voted = true;
v->failures = 0;
}
} else if (action == AGX_VOTE_CLEAR) {
v->voted = false; /* the write was made; the caller logs an unacknowledged clear */
}
}

/*
* The GPU driver unbinds, the report goes away, or the system sleeps: drop the vote now and refuse new ones. True when bit 9 is set and the caller must
* write the clear. An operation that begins afterwards (an ioctl already past the unplug check) counts as a user but does not vote.
*/
static inline bool agx_vote_release(struct agx_vote *v)
{
bool was_voted = v->voted;

v->voted = false;
v->stopped = true;
return was_voted;
}

/* Refuse new votes without touching the one that is set (the first step of a release, before the work item is waited out). */
static inline void agx_vote_refuse(struct agx_vote *v)
{
v->stopped = true;
}

/* The GPU probes (or the report comes back, or the system resumes): votes are allowed again. True when work is already in flight and the caller must run the reconcile step. */
static inline bool agx_vote_resume(struct agx_vote *v)
{
v->stopped = false;
return v->enabled && v->users && !v->voted;
}

#endif /* PMP_AGX_VOTE_H */
Loading