From 689f2f91cc94da196482d1717a89604c6fac14c2 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Tue, 3 Nov 2026 01:42:11 -0600 Subject: [PATCH 1/6] soc: apple: vote GPU activity to the PMP so memory leaves idle DVFS on t600x On the M1 Max (t6001) the PMP keeps memory at its idle floor for a busy GPU until the AGX power request, bit 9 of the PMP report's PS-REQ word, is set. Nothing sets it on Linux, so GPU reads top out at 241 GB/s. The same chip reads 361 GB/s on macOS. Report GPU activity to the PMP. The GPU driver calls apple_pmp_agx_activity_begin() when a submission starts and apple_pmp_agx_activity_end() when it finishes. pmp-report sets bit 9 when the first operation starts and clears it 100 ms after the last one ends. It also clears it at once when the GPU driver unbinds or the report goes away, so the request is never left set past the GPU's power-domain release. The register sequence is the one apple_pmp_report_set_state() already uses for report entries: read 0xf80, write 0x107c0, poll 0x1000, status 0x10, 50 ms acknowledge. A set that is not acknowledged is cleared again and not retried for a second. The vote is off by default. pmp_report.agx_vote=1 turns it on, and pmp_report.agx_vote_idle_ms (default 100) sets the hold. With it off nothing is written. It applies to apple,t6001 only; t6000 is untested. The decisions (set, clear, hold, retry, wrap of the 32-bit millisecond clock) are plain functions in pmp-agx-vote.h with no kernel dependency. Setting the bit by hand with a test module on a 16-inch M1 Max moved a GPU read microbenchmark from 241 to 368 GB/s. This patch has not yet been run on hardware. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/gpu/drm/asahi/driver.rs | 3 + drivers/gpu/drm/asahi/gpu.rs | 5 + drivers/pmdomain/apple/pmp-agx-vote.h | 122 ++++++++++++++++++ drivers/pmdomain/apple/pmp-report.c | 172 ++++++++++++++++++++++++++ include/linux/soc/apple/pmp-report.h | 20 +++ rust/bindings/bindings_helper.h | 1 + 6 files changed, 323 insertions(+) create mode 100644 drivers/pmdomain/apple/pmp-agx-vote.h diff --git a/drivers/gpu/drm/asahi/driver.rs b/drivers/gpu/drm/asahi/driver.rs index 80582ece5d2391..6eff6f06bf4338 100644 --- a/drivers/gpu/drm/asahi/driver.rs +++ b/drivers/gpu/drm/asahi/driver.rs @@ -231,6 +231,9 @@ impl platform::Driver for AsahiPlatformDriver { _pdev: &'bound platform::Device>, 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(); diff --git a/drivers/gpu/drm/asahi/gpu.rs b/drivers/gpu/drm/asahi/gpu.rs index 84d82bb1880ef2..60acb7a2d5b376 100644 --- a/drivers/gpu/drm/asahi/gpu.rs +++ b/drivers/gpu/drm/asahi/gpu.rs @@ -1284,6 +1284,9 @@ impl GpuManager::ver { .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) @@ -1804,5 +1807,7 @@ impl GpuManagerPriv for GpuManager::ver { .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() }; } } diff --git a/drivers/pmdomain/apple/pmp-agx-vote.h b/drivers/pmdomain/apple/pmp-agx-vote.h new file mode 100644 index 00000000000000..70ad71c514e395 --- /dev/null +++ b/drivers/pmdomain/apple/pmp-agx-vote.h @@ -0,0 +1,122 @@ +/* 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 +/* 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 +#include +typedef uint32_t agx_ms_t; +typedef int32_t agx_sms_t; +#endif + +/* 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 */ + 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; +} + +/* An operation starts. True: run the reconcile step now. */ +static inline bool agx_vote_begin(struct agx_vote *v) +{ + v->users++; + return v->enabled && !v->voted; +} + +/* 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) + return v->voted ? AGX_VOTE_CLEAR : AGX_VOTE_NONE; + if (v->users) + return !v->voted && (!v->failures || agx_vote_reached(now, v->retry_at)) ? 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. */ +static inline agx_ms_t agx_vote_next(const struct agx_vote *v, agx_ms_t now) +{ + agx_ms_t at; + + if (!v->enabled) + return 0; + if (v->users && !v->voted && v->failures) + at = v->retry_at; + else if (!v->users && v->voted) + at = v->idle_at + v->idle_ms; + else + return 0; + return agx_vote_reached(now, at) ? 0 : 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: drop the vote now. True when bit 9 is set and the caller must write the clear. */ +static inline bool agx_vote_release(struct agx_vote *v) +{ + bool was_voted = v->voted; + + v->voted = false; + return was_voted; +} + +#endif /* PMP_AGX_VOTE_H */ diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 9aac3ced17cda1..fe2aa14788b11b 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -31,6 +31,7 @@ #include #include +#include "pmp-agx-vote.h" #include "pmp-report-validation.h" #define PMP_REPORT_READY 0x1 @@ -80,6 +81,18 @@ struct apple_pmp_report { }; static const struct apple_pmp_report_offsets apple_pmp_offsets_t6030; +static const struct apple_pmp_report_offsets apple_pmp_offsets_t600x; + +/* T6001 AGX request (see the engine below set_state): AGX is soc-device record 9 on the T6001. */ +#define APPLE_PMP_T6001_AGX_ID 9 +static bool agx_vote; +static struct agx_vote apple_pmp_agx_vote_state = {.idle_ms = 100}; +static DEFINE_SPINLOCK(apple_pmp_agx_vote_lock); +/* Serializes the vote work, the unbind release and the report's removal. */ +static DEFINE_MUTEX(apple_pmp_agx_vote_mutex); +static void apple_pmp_agx_vote_fn(struct work_struct *work); +static DECLARE_DELAYED_WORK(apple_pmp_agx_vote_work, apple_pmp_agx_vote_fn); +static void apple_pmp_agx_vote_stop(void); /* Bound report regions, protected by RCU until managed teardown drains readers. */ static LIST_HEAD(apple_pmp_reports); @@ -168,6 +181,11 @@ static void apple_pmp_report_release(void *data) /* Withdraw child providers while their power callbacks can still use MMIO. */ of_platform_depopulate(rep->dev); + if (rep->offsets == &apple_pmp_offsets_t600x) { + cancel_delayed_work_sync(&apple_pmp_agx_vote_work); + guard(mutex)(&apple_pmp_agx_vote_mutex); + apple_pmp_agx_vote_stop(); + } mutex_lock(&apple_pmp_reports_lock); if (!list_empty(&rep->list)) list_del_rcu(&rep->list); @@ -1295,6 +1313,160 @@ static int apple_pmp_report_set_state(struct apple_pmp_report *rep, u32 id, 50000); } +/* + * T6001 AGX request. T2 showed that setting PS-REQ bit 9 (AGX, soc-device record 9) lifts the GPU read roof from 241 to 368 GB/s: the PMP + * leaves memory at its idle floor for a GPU that is busy but has not asked. The GPU driver reports operations in flight + * (apple_pmp_agx_activity_begin/end); the request is set while any operation runs and cleared agx_vote_idle_ms after the last one ends, at + * GPU unbind and when this report goes away. The decisions are in pmp-agx-vote.h (unit tested); this is the glue. + * Off by default (pmp_report.agx_vote): with it off nothing is written. + */ +static unsigned int agx_vote_idle_ms = 100; + +static agx_ms_t apple_pmp_agx_now_ms(void) +{ + return jiffies_to_msecs(jiffies); +} + +static void apple_pmp_agx_vote_kick(unsigned long delay_ms) +{ + mod_delayed_work(system_wq, &apple_pmp_agx_vote_work, msecs_to_jiffies(delay_ms)); +} + +static int apple_pmp_agx_vote_param_set(const char *val, const struct kernel_param *kp) +{ + int ret = param_set_bool(val, kp); + + if (!ret) + apple_pmp_agx_vote_kick(0); /* switching off clears at once, switching on votes if the GPU is busy */ + return ret; +} + +static const struct kernel_param_ops apple_pmp_agx_vote_ops = { + .set = apple_pmp_agx_vote_param_set, + .get = param_get_bool, +}; +module_param_cb(agx_vote, &apple_pmp_agx_vote_ops, &agx_vote, 0644); +MODULE_PARM_DESC(agx_vote, "T6001: set the AGX power request in the PMP report while the GPU has work in flight (default: off)"); +module_param(agx_vote_idle_ms, uint, 0644); +MODULE_PARM_DESC(agx_vote_idle_ms, "Keep the AGX request this many ms after the last GPU operation ends (default: 100)"); + +/* Write the AGX request of the bound T6001 report: -ENODEV without one, -EAGAIN (nothing written) when the PMP does not run. */ +static int apple_pmp_agx_write(bool enable, bool no_ack) +{ + struct apple_pmp_report *rep; + int ret = -ENODEV; + + if (!of_machine_is_compatible("apple,t6001")) + return ret; + rcu_read_lock(); + list_for_each_entry_rcu(rep, &apple_pmp_reports, list) { + if (rep->offsets != &apple_pmp_offsets_t600x) + continue; + if (enable && !(readq(rep->base + rep->offsets->status) & PMP_REPORT_READY)) + ret = -EAGAIN; + else + ret = apple_pmp_report_set_state(rep, APPLE_PMP_T6001_AGX_ID, enable, no_ack); + break; + } + rcu_read_unlock(); + return ret; +} + +/* Clear a request that is still set. Caller holds apple_pmp_agx_vote_mutex. */ +static void apple_pmp_agx_vote_stop(void) +{ + unsigned long flags; + bool voted; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + voted = agx_vote_release(&apple_pmp_agx_vote_state); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + if (voted) + apple_pmp_agx_write(false, true); +} + +static void apple_pmp_agx_vote_fn(struct work_struct *work) +{ + struct agx_vote *v = &apple_pmp_agx_vote_state; + enum agx_vote_action act; + unsigned long flags; + agx_ms_t now, next = 0; + int ret = 0; + + guard(mutex)(&apple_pmp_agx_vote_mutex); + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v->enabled = READ_ONCE(agx_vote); + v->idle_ms = READ_ONCE(agx_vote_idle_ms); + now = apple_pmp_agx_now_ms(); + act = agx_vote_decide(v, now); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + + if (act != AGX_VOTE_NONE) { + const bool set = act == AGX_VOTE_SET; + + ret = apple_pmp_agx_write(set, false); + if (ret == -ETIMEDOUT) { + pr_err("pmp_report: AGX request %s not acknowledged, clearing\n", set ? "set" : "clear"); + apple_pmp_agx_write(false, true); + } + if (!set) + ret = 0; /* a clear is final: the state is "not voted" whatever happened */ + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + agx_vote_applied(v, act, ret, now); + next = agx_vote_next(v, apple_pmp_agx_now_ms()); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + } else { + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + next = agx_vote_next(v, now); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + } + if (next) + apple_pmp_agx_vote_kick(next); +} + +void apple_pmp_agx_activity_begin(void) +{ + struct agx_vote *v = &apple_pmp_agx_vote_state; + unsigned long flags; + bool kick; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v->enabled = READ_ONCE(agx_vote); + kick = agx_vote_begin(v); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + if (kick) + apple_pmp_agx_vote_kick(0); +} +EXPORT_SYMBOL_GPL(apple_pmp_agx_activity_begin); + +void apple_pmp_agx_activity_end(void) +{ + struct agx_vote *v = &apple_pmp_agx_vote_state; + unsigned long flags; + agx_ms_t delay; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v->enabled = READ_ONCE(agx_vote); + v->idle_ms = READ_ONCE(agx_vote_idle_ms); + delay = agx_vote_end(v, apple_pmp_agx_now_ms()); + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + if (delay) + apple_pmp_agx_vote_kick(delay); +} +EXPORT_SYMBOL_GPL(apple_pmp_agx_activity_end); + +/* + * The GPU driver unbinds: clear the request now instead of waiting out the idle time, so it is never left set past the GPU's + * power-domain release (the T6030 fix clears before it releases its vote). Process context. + */ +void apple_pmp_agx_activity_release(void) +{ + cancel_delayed_work_sync(&apple_pmp_agx_vote_work); + guard(mutex)(&apple_pmp_agx_vote_mutex); + apple_pmp_agx_vote_stop(); +} +EXPORT_SYMBOL_GPL(apple_pmp_agx_activity_release); + /* Find and check the report before taking the GPU vote; optionally update it. */ static int apple_pmp_report_t6030_gfx(struct device *supplier, const bool *enable) { diff --git a/include/linux/soc/apple/pmp-report.h b/include/linux/soc/apple/pmp-report.h index 1d0689f31c2039..7fb5327a7b9646 100644 --- a/include/linux/soc/apple/pmp-report.h +++ b/include/linux/soc/apple/pmp-report.h @@ -21,7 +21,27 @@ int apple_pmp_report_set_t6030_gfx(struct device *supplier, bool enable); int apple_pmp_report_wait_ready(struct device_node *entry, unsigned long timeout); int apple_pmp_report_fast_die_effort(const struct device_node *np, unsigned int lane, u8 *effort); +/* + * T6001: the GPU driver reports each operation in flight. With the pmp_report.agx_vote parameter set, the AGX request (PS-REQ bit 9) is + * set while any operation runs and cleared agx_vote_idle_ms after the last one ends. Parameter off: no effect. Both may be called from + * any context. release() clears the request at once (GPU driver unbind), process context. + */ +void apple_pmp_agx_activity_begin(void); +void apple_pmp_agx_activity_end(void); +void apple_pmp_agx_activity_release(void); #else +static inline void apple_pmp_agx_activity_begin(void) +{ +} + +static inline void apple_pmp_agx_activity_end(void) +{ +} + +static inline void apple_pmp_agx_activity_release(void) +{ +} + static inline int apple_pmp_report_wait_supplier_ready(struct device *supplier, unsigned int timeout_ms) { diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index f981774335c7ca..15046badff5f37 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -102,6 +102,7 @@ #include #include #include +#include #include #include #include From f7ad8cffcacb77bcba84adbfb67965e8ea865bb0 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Tue, 3 Nov 2026 01:56:22 -0600 Subject: [PATCH 2/6] pmdomain: apple: pmp-report: export a locked, acknowledged update of one power request bit The PS-REQ word of the PMP report is shared by every client of the PMP: the report entries (display, ISP, video decode, the AFNC IOAs), the T6001 AGX vote (bit 9) and, out of tree, the ANE clock level of omarchy-ane (bit 10). The report entries and the AGX vote read-modify-write the word under rep->lock. A module outside this driver could only map the window and read-modify-write it without that lock, so a concurrent write of another bit could be lost. apple_pmp_report_set_request(report_np, id, enable, no_ack) is the one writer a client outside this file may use. It calls the same apple_pmp_report_set_state() the entries use, so it takes the same lock and does the same acknowledge poll (at most 50 ms). The caller owns the bit it asks for. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/pmdomain/apple/pmp-report.c | 43 ++++++++++++++++++++++++++++ include/linux/soc/apple/pmp-report.h | 12 ++++++++ 2 files changed, 55 insertions(+) diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index fe2aa14788b11b..915191daa21f92 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -1523,6 +1523,49 @@ int apple_pmp_report_set_t6030_gfx(struct device *supplier, bool enable) } EXPORT_SYMBOL_GPL(apple_pmp_report_set_t6030_gfx); +/** + * apple_pmp_report_set_request() - set or clear one bit of the PMP power request word of a bound report + * @report_np: device tree node of the report region (compatible apple,t6000-pmp-v2-report and its + * siblings) + * @id: bit number of the request, the index of the soc-device record, 0 to 63 (ANE0 is 10 and AGX + * is 9 on the T6001) + * @enable: set or clear the bit + * @no_ack: do not wait for the acknowledge + * + * One read-modify-write of the word, made under the report's lock: the same lock every report + * entry and the AGX vote take, so requests for different bits cannot lose each other. Unless + * @no_ack, waits (atomic poll, at most 50 ms) until the acknowledge word shows the bit as + * requested. A PMP that does not run has nothing to acknowledge: the request is written and 0 is + * returned, as for a report entry. + * + * The caller owns the bit it requests; this function does not arbitrate between callers of the + * same bit. On the T6001 bit 9 belongs to the AGX vote (pmp_report.agx_vote), so other callers + * must not use it. + * + * Context: process context (the acknowledge wait is a busy poll of up to 50 ms). + * Return: 0, -ENODEV if no report is bound to @report_np, -EINVAL if @id is out of range, + * -ETIMEDOUT if the acknowledge did not follow. + */ +int apple_pmp_report_set_request(const struct device_node *report_np, unsigned int id, + bool enable, bool no_ack) +{ + struct apple_pmp_report *rep; + int ret = -ENODEV; + + if (id > 63) + return -EINVAL; + rcu_read_lock(); + list_for_each_entry_rcu(rep, &apple_pmp_reports, list) { + if (rep->dev->of_node == report_np) { + ret = apple_pmp_report_set_state(rep, id, enable, no_ack); + break; + } + } + rcu_read_unlock(); + return ret; +} +EXPORT_SYMBOL_GPL(apple_pmp_report_set_request); + static int apple_pmp_report_entry_set_state(struct generic_pm_domain *genpd, bool enable) { struct apple_pmp_report_entry *ent = genpd_to_apple_pmp_report_entry(genpd); diff --git a/include/linux/soc/apple/pmp-report.h b/include/linux/soc/apple/pmp-report.h index 7fb5327a7b9646..345848c91dbc36 100644 --- a/include/linux/soc/apple/pmp-report.h +++ b/include/linux/soc/apple/pmp-report.h @@ -21,6 +21,12 @@ int apple_pmp_report_set_t6030_gfx(struct device *supplier, bool enable); int apple_pmp_report_wait_ready(struct device_node *entry, unsigned long timeout); int apple_pmp_report_fast_die_effort(const struct device_node *np, unsigned int lane, u8 *effort); +/* + * Set or clear one bit of the PMP power request word of the report bound to @report_np, under the + * report's lock, with the acknowledge wait (see pmp-report.c). + */ +int apple_pmp_report_set_request(const struct device_node *report_np, unsigned int id, + bool enable, bool no_ack); /* * T6001: the GPU driver reports each operation in flight. With the pmp_report.agx_vote parameter set, the AGX request (PS-REQ bit 9) is * set while any operation runs and cleared agx_vote_idle_ms after the last one ends. Parameter off: no effect. Both may be called from @@ -69,6 +75,12 @@ static inline int apple_pmp_report_fast_die_effort(const struct device_node *np, { return -ENODEV; } + +static inline int apple_pmp_report_set_request(const struct device_node *report_np, + unsigned int id, bool enable, bool no_ack) +{ + return -ENODEV; +} #endif #endif /* _LINUX_SOC_APPLE_PMP_REPORT_H_ */ From e033631c7dddcd8cd47b8efde090d0ac3e7e9a5e Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Tue, 3 Nov 2026 02:13:48 -0600 Subject: [PATCH 3/6] pmdomain: apple: pmp-report: keep the AGX bit out of the export, document clearing apple_pmp_report_set_request() lets a client outside pmp-report update one bit of the PS-REQ word. On the T6001 bit 9 is the AGX request, which the GPU vote owns: a second writer could clear it while the GPU works, or set it and leave it set. Refuse it from the export with -EBUSY on a t600x report. The vote itself writes through apple_pmp_report_set_state() and is not affected. Document what a caller must do after -ETIMEDOUT: the request was written but not acknowledged and stays in the word, so the caller clears it with @enable false and @no_ack true before giving up. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/pmdomain/apple/pmp-report.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 915191daa21f92..b96b48cbbd68be 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -1539,12 +1539,13 @@ EXPORT_SYMBOL_GPL(apple_pmp_report_set_t6030_gfx); * returned, as for a report entry. * * The caller owns the bit it requests; this function does not arbitrate between callers of the - * same bit. On the T6001 bit 9 belongs to the AGX vote (pmp_report.agx_vote), so other callers - * must not use it. + * same bit. On the T6001 bit 9 belongs to the AGX vote (pmp_report.agx_vote) and is refused here + * with -EBUSY. After -ETIMEDOUT the request was written but not acknowledged and stays in the + * word: the caller must clear it (@enable false, @no_ack true) before giving up. * * Context: process context (the acknowledge wait is a busy poll of up to 50 ms). * Return: 0, -ENODEV if no report is bound to @report_np, -EINVAL if @id is out of range, - * -ETIMEDOUT if the acknowledge did not follow. + * -EBUSY for the T6001 AGX bit, -ETIMEDOUT if the acknowledge did not follow. */ int apple_pmp_report_set_request(const struct device_node *report_np, unsigned int id, bool enable, bool no_ack) @@ -1557,7 +1558,10 @@ int apple_pmp_report_set_request(const struct device_node *report_np, unsigned i rcu_read_lock(); list_for_each_entry_rcu(rep, &apple_pmp_reports, list) { if (rep->dev->of_node == report_np) { - ret = apple_pmp_report_set_state(rep, id, enable, no_ack); + if (id == APPLE_PMP_T6001_AGX_ID && rep->offsets == &apple_pmp_offsets_t600x) + ret = -EBUSY; /* the AGX vote owns this bit */ + else + ret = apple_pmp_report_set_state(rep, id, enable, no_ack); break; } } From 9f2a319c3b01e418da2f589aecf1b826311840a9 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Tue, 3 Nov 2026 02:32:58 -0600 Subject: [PATCH 4/6] pmdomain: apple: pmp-report: hold the AGX request 250 ms after the last operation A 9B model at 8192 tokens of context had one gap of up to 111.5 ms between two decoded tokens in every process, once per run, with the GPU idle for a good part of it. The 100 ms default hold dropped the request in that gap, which costs one slow token while the PMP raises memory again. The longest gap in any other configuration measured was 64 ms. Raise the default to 250 ms, about 2.2 times the longest gap seen. The cost is a few hundred milliseconds of the higher memory state after the last job. pmp_report.agx_vote_idle_ms still overrides it at run time. The default is one constant, AGX_VOTE_IDLE_MS_DEFAULT, used for both the parameter and the initial state. The userspace test has a case that rides through a 112 ms gap with the default and still drops the request after a long idle. Signed-off-by: Joshua Warren <816217+joshuawarren@users.noreply.github.com> --- drivers/pmdomain/apple/pmp-agx-vote.h | 4 ++++ drivers/pmdomain/apple/pmp-report.c | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/pmdomain/apple/pmp-agx-vote.h b/drivers/pmdomain/apple/pmp-agx-vote.h index 70ad71c514e395..715ab63e424943 100644 --- a/drivers/pmdomain/apple/pmp-agx-vote.h +++ b/drivers/pmdomain/apple/pmp-agx-vote.h @@ -22,6 +22,10 @@ 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 diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index b96b48cbbd68be..6d795310b139e5 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -86,7 +86,7 @@ static const struct apple_pmp_report_offsets apple_pmp_offsets_t600x; /* T6001 AGX request (see the engine below set_state): AGX is soc-device record 9 on the T6001. */ #define APPLE_PMP_T6001_AGX_ID 9 static bool agx_vote; -static struct agx_vote apple_pmp_agx_vote_state = {.idle_ms = 100}; +static struct agx_vote apple_pmp_agx_vote_state = {.idle_ms = AGX_VOTE_IDLE_MS_DEFAULT}; static DEFINE_SPINLOCK(apple_pmp_agx_vote_lock); /* Serializes the vote work, the unbind release and the report's removal. */ static DEFINE_MUTEX(apple_pmp_agx_vote_mutex); @@ -1320,7 +1320,7 @@ static int apple_pmp_report_set_state(struct apple_pmp_report *rep, u32 id, * GPU unbind and when this report goes away. The decisions are in pmp-agx-vote.h (unit tested); this is the glue. * Off by default (pmp_report.agx_vote): with it off nothing is written. */ -static unsigned int agx_vote_idle_ms = 100; +static unsigned int agx_vote_idle_ms = AGX_VOTE_IDLE_MS_DEFAULT; static agx_ms_t apple_pmp_agx_now_ms(void) { @@ -1348,7 +1348,7 @@ static const struct kernel_param_ops apple_pmp_agx_vote_ops = { module_param_cb(agx_vote, &apple_pmp_agx_vote_ops, &agx_vote, 0644); MODULE_PARM_DESC(agx_vote, "T6001: set the AGX power request in the PMP report while the GPU has work in flight (default: off)"); module_param(agx_vote_idle_ms, uint, 0644); -MODULE_PARM_DESC(agx_vote_idle_ms, "Keep the AGX request this many ms after the last GPU operation ends (default: 100)"); +MODULE_PARM_DESC(agx_vote_idle_ms, "Keep the AGX request this many ms after the last GPU operation ends (default: 250)"); /* Write the AGX request of the bound T6001 report: -ENODEV without one, -EAGAIN (nothing written) when the PMP does not run. */ static int apple_pmp_agx_write(bool enable, bool no_ack) From 78ebe0eb83ddac7b0390f3d3e6768384ce880c86 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Tue, 3 Nov 2026 03:54:14 -0600 Subject: [PATCH 5/6] soc: apple: show the fabric, DCS and PMP request words in debugfs (read only) Two read-only debugfs views for sampling next to a timing: apple-pmgr-misc exposes the whole clock-generator word of the fabric and DCS system devices, and the PMP report status gains the request and actual words and, on the T6001, the AGX vote state. They answer which hardware state a measurement ran in without a separate investigation. Nothing is written and nothing changes with them absent. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/pmdomain/apple/pmp-report.c | 26 ++++++++++++++++++--- drivers/soc/apple/apple-pmgr-misc.c | 36 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 6d795310b139e5..7ae2c5866e6427 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -94,6 +94,19 @@ static void apple_pmp_agx_vote_fn(struct work_struct *work); static DECLARE_DELAYED_WORK(apple_pmp_agx_vote_work, apple_pmp_agx_vote_fn); static void apple_pmp_agx_vote_stop(void); +/* The vote state for the report status, copied under the vote's lock. */ +static void apple_pmp_agx_vote_show(struct seq_file *s) +{ + struct agx_vote v; + unsigned long flags; + + spin_lock_irqsave(&apple_pmp_agx_vote_lock, flags); + v = apple_pmp_agx_vote_state; + spin_unlock_irqrestore(&apple_pmp_agx_vote_lock, flags); + seq_printf(s, "agx_vote: enabled=%u voted=%u users=%u idle_ms=%u failures=%u\n", v.enabled, v.voted, v.users, v.idle_ms, + v.failures); +} + /* Bound report regions, protected by RCU until managed teardown drains readers. */ static LIST_HEAD(apple_pmp_reports); static DEFINE_MUTEX(apple_pmp_reports_lock); @@ -151,7 +164,7 @@ EXPORT_SYMBOL_GPL(apple_pmp_report_fast_die_effort); static void apple_pmp_start_show(struct seq_file *s, struct apple_pmp_start *st); -/* Read only the documented status and fast-die entries, never the aperture. */ +/* Read only the documented status and fast-die entries, and the two request words (request and actual) the driver itself reads on every set. Never the rest of the aperture. */ static int apple_pmp_report_status_show(struct seq_file *s, void *unused) { struct apple_pmp_report *rep = s->private; @@ -163,7 +176,14 @@ static int apple_pmp_report_status_show(struct seq_file *s, void *unused) seq_printf(s, "running: %u\n", !!(status & PMP_REPORT_READY)); if (rep->start) apple_pmp_start_show(s, rep->start); - if (!(status & PMP_REPORT_READY) || !offs->fast_die) + if (!(status & PMP_REPORT_READY)) + return 0; + + seq_printf(s, "request: 0x%016llx\nactual: 0x%016llx\n", (unsigned long long)readq(rep->base + offs->tgt_read), + (unsigned long long)readq(rep->base + offs->actual)); + if (offs == &apple_pmp_offsets_t600x) + apple_pmp_agx_vote_show(s); + if (!offs->fast_die) return 0; effort = readl(rep->base + offs->fast_die); @@ -1151,7 +1171,7 @@ static int apple_pmp_report_probe(struct platform_device *pdev) list_add_tail_rcu(&rep->list, &apple_pmp_reports); mutex_unlock(&apple_pmp_reports_lock); - if (rep->offsets->fast_die || rep->start) + if (rep->offsets->fast_die || rep->start || rep->offsets == &apple_pmp_offsets_t600x) rep->debugfs = debugfs_create_file(dev_name(dev), 0400, apple_pmp_report_debugfs, rep, &apple_pmp_report_status_fops); diff --git a/drivers/soc/apple/apple-pmgr-misc.c b/drivers/soc/apple/apple-pmgr-misc.c index 53170aad4d4b4f..a659defa6a63c6 100644 --- a/drivers/soc/apple/apple-pmgr-misc.c +++ b/drivers/soc/apple/apple-pmgr-misc.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -17,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -465,6 +467,37 @@ static bool apple_pmgr_init_device(struct apple_pmgr_misc *misc, return true; } +/* Read only: the whole clock-generator word of one system device (the desired state is bits 3:0, the actual state bits 7:4), no side effect. */ +static int apple_pmgr_misc_ps_show(struct seq_file *s, void *unused) +{ + const struct apple_pmgr_sys_device *d = s->private; + + seq_printf(s, "%#010x\n", readl_relaxed(d->base + APPLE_CLKGEN_PSTATE)); + return 0; +} +DEFINE_SHOW_ATTRIBUTE(apple_pmgr_misc_ps); + +static void apple_pmgr_misc_debugfs_remove(void *dir) +{ + debugfs_remove(dir); +} + +static void apple_pmgr_misc_debugfs_init(struct apple_pmgr_misc *misc) +{ + static const char * const names[DEV_MAX] = { "fabric_ps", "dcs_ps" }; + char *dirname = devm_kasprintf(misc->dev, GFP_KERNEL, "apple-pmgr-misc-%s", dev_name(misc->dev)); + struct dentry *dir; + int i; + + if (!dirname) + return; + dir = debugfs_create_dir(dirname, NULL); + for (i = 0; i < DEV_MAX; i++) + if (misc->devices[i].base) + debugfs_create_file(names[i], 0400, dir, &misc->devices[i], &apple_pmgr_misc_ps_fops); + devm_add_action_or_reset(misc->dev, apple_pmgr_misc_debugfs_remove, dir); +} + static int apple_pmgr_misc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -486,6 +519,9 @@ static int apple_pmgr_misc_probe(struct platform_device *pdev) platform_set_drvdata(pdev, misc); + if (!ret) + apple_pmgr_misc_debugfs_init(misc); + /* * With PMP enabled its firmware owns the fabric and DCS p-states. * Writing them for suspend as well leaves the system unable to resume From d366ab11442bc5e0fbdbdcea1725d6473eb0251c Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Tue, 3 Nov 2026 04:47:53 -0600 Subject: [PATCH 6/6] pmdomain: apple: pmp-report: create the status file for every report The status file was created only for reports with fast-die entries or a PMP this driver starts. It now exists for every report: it prints running, and only while the PMP runs the request and actual words (and on the T6001 the AGX vote state). This also keeps the probe free of a reference to the T6001 offsets, which the host test of the T6030 PMP graph extracts and compiles without them. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/pmdomain/apple/pmp-report.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 7ae2c5866e6427..725af1c5abc79a 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -1171,10 +1171,7 @@ static int apple_pmp_report_probe(struct platform_device *pdev) list_add_tail_rcu(&rep->list, &apple_pmp_reports); mutex_unlock(&apple_pmp_reports_lock); - if (rep->offsets->fast_die || rep->start || rep->offsets == &apple_pmp_offsets_t600x) - rep->debugfs = debugfs_create_file(dev_name(dev), 0400, - apple_pmp_report_debugfs, rep, - &apple_pmp_report_status_fops); + rep->debugfs = debugfs_create_file(dev_name(dev), 0400, apple_pmp_report_debugfs, rep, &apple_pmp_report_status_fops); /* Publish the region before child power callbacks start looking it up. */ ret = of_platform_populate(np, NULL, NULL, dev);