Repository navigation
soc: apple: clpc: only step down busy CPU clusters on low-power PHPC - #3488
Conversation
In the low-power platform profile, apple_clpc_profile_limit() reads SMC PHPC (package power, which includes the GPU and display as well as the CPUs) and steps one CPU cluster down on every new reading above low_power_mw. When a GPU or display workload holds PHPC above low_power_mw while the CPUs are idle or lightly loaded, stepping down CPU ceilings saves almost no power, so PHPC stays above target and every CPU cluster walks down to its minimum OPP (300 MHz). Neither SMC nor apple-pmc exposes a per-cluster CPU-only power meter on these platforms (CPU and GPU share PHPC), so gate downward steps on the cluster's scheduler non-idle utilisation (cl->busy >= APPLE_CLPC_BUSY_PCT, already sampled by apple_clpc_sample_cluster()): - Extract apple_clpc_sample_busy() and run it for standalone (!clpc->has_pmc) low-power package-power instances as well, so cl->busy is populated uniformly without SoC gating. - Extract apple_clpc_pick_profile_step() and skip clusters with cl->busy < APPLE_CLPC_BUSY_PCT when stepping down (step < 0), while still stepping every capped cluster back up when PHPC drops below 90% of low_power_mw (step > 0). - Add KUnit test apple_clpc_profile_step_busy_test covering idle clusters under over-budget PHPC, single busy cluster selection, multi-cluster busy ordering, idle recovery on step-up, and step == 0. Fixes: #3450 Signed-off-by: Ryan Murray <[email protected]>
There was a problem hiding this comment.
Verdict: FINISH, then merge at 9163bf17
Blockers:
- All CI checks (
apple-build,host-tests,KUnit clpc,pr-text,readiness, etc.) are stillQUEUED; wait for green CI. - Live hardware verification repeating the low-power GPU/animation + CPU load matrix from
#3450(e.g., T6050J714s/K114s) plus a second-family regression row are pending. - Requires independent code-owner / maintainer approval before merge.
Checked:
drivers/soc/apple/clpc.c: verifiedapple_clpc_sample_busy()extraction preserves PMC-backed sampling behavior and populatescl->busyon standalone (!clpc->has_pmc) instances whenlow && clpc->low_power_mw; verifiedapple_clpc_pick_profile_step()gates only downward steps (step < 0) oncl->busy >= APPLE_CLPC_BUSY_PCTwhile allowingstep > 0to restore idle capped clusters inapple_clpc_steps_first()order.- KUnit test
apple_clpc_profile_step_busy_test: verified coverage of idle-under-overbudget, single-busy selection, multi-cluster busy ordering, idle step-up recovery, andstep == 0. - Non-blocking note: because
cl->busytracks the per-cluster maximum single-CPU utilization againstAPPLE_CLPC_BUSY_PCT(50%), a lightly spread multi-core load (<50% on every core) will not step down; confirm during the hardware matrix that this matches the intended#3450balance. - Checked for Apple material, AI attribution, private serials, and board/SoC gates: none found; human
Signed-off-bypresent.
Evidence
- Head:
9163bf17bea2d9(base: main,mergeable: MERGEABLE, 1 commit). - Code and KUnit test are clean; waiting on CI, hardware rows, and independent approval.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Code review PASS at 9163bf17be.
Verified:
apple_clpc_sample_busy()cleanly factors cluster busy-share sampling and is invoked on non-PMC systems whenlow && clpc->low_power_mw.apple_clpc_pick_profile_step()skips clusters withcl->busy < APPLE_CLPC_BUSY_PCTonly on step-down (step < 0), so GPU/display loads holding PHPC abovelow_power_mwdo not walk idle CPU clusters to their minimum OPP, while step-up (step > 0) restores every capped cluster.Signed-off-bypresent.
|
Hardware row at Same script both times: PHPC (hwmon "Heatpipe Power") and
Step-downs during the low-power screensaver run, and how many came while that cluster read under 50% busy in the 0.5 s samples on either side:
Why I think the gate leaks on T6050: the J714s's CLPC sits under Two possible changes. Neither is tested:
I can build and run either on the J714s, with the same table. |
|
Follow-up with an experiment on the same J714s, on battery: v272-26 +
All 16 rows are low-power, one run. Each starts from a balanced → low-power switch. "Steps down (quiet)" counts the cap reductions per policy 0/5/10; the number in brackets is how many happened while that cluster read under 50% busy in the 0.5 s samples on either side.
What it shows:
One more thing about the PR as it stands: the new My suggestion for #3488: take the window behaviour unconditionally (no parameter), plus the floor. I'm happy to send it as a commit on your branch or as a separate PR, whichever you prefer. The parameters exist only to A/B the variants on one kernel. Experiment patch on top of 9163bf1 (applies to clpc.c at 7f00dc6 + 9163bf1)--- a/drivers/soc/apple/clpc.c
+++ b/drivers/soc/apple/clpc.c
@@ -68,6 +68,19 @@
#define APPLE_CLPC_GPU_BACKOFF_MS 100
/* Package power readings in the low-power profile: every 100 ms */
#define APPLE_CLPC_POWER_MS 100
+/*
+ * Experiment for aurora-silicon/linux #3450 (not for merging as is): how the
+ * low-power package power loop decides that a cluster is busy, and whether it
+ * may step a cluster onto its lowest table row.
+ */
+static bool profile_busy_window;
+module_param(profile_busy_window, bool, 0644);
+MODULE_PARM_DESC(profile_busy_window,
+ "low-power PHPC loop: busy share since the last PHPC reading it acted on, not the last sample");
+static bool profile_floor;
+module_param(profile_floor, bool, 0644);
+MODULE_PARM_DESC(profile_floor,
+ "low-power PHPC loop: never step a cluster down to its lowest table row");
/* Why the last vote was cast, for debugfs */
#define APPLE_CLPC_REASON_CPU BIT(0)
@@ -158,6 +171,8 @@
unsigned int policy_cpu;
cpumask_var_t cpus;
unsigned int busy;
+ /* Busy share since the last package power reading the profile acted on */
+ unsigned int power_busy;
unsigned int streak;
unsigned int level;
unsigned int request[APPLE_CLPC_RAILS];
@@ -273,6 +288,9 @@
unsigned long power_next;
unsigned long power_reads, power_updates;
int power_mw;
+ /* Per-CPU baselines for power_busy, taken at each package power reading */
+ u64 *power_idle;
+ u64 *power_wall;
};
/* Protect publication/removal of provider drvdata, never a submission path. */
@@ -603,8 +621,12 @@
}
}
-static void apple_clpc_sample_busy(struct apple_clpc *clpc,
- struct apple_clpc_cluster *cl)
+/*
+ * The busiest CPU of @cl since @base_wall/@base_idle, in percent, and move
+ * the baselines to now.
+ */
+static unsigned int apple_clpc_busy_since(const struct apple_clpc_cluster *cl,
+ u64 *base_wall, u64 *base_idle)
{
unsigned int cpu, busy = 0;
@@ -618,21 +640,21 @@
* baseline once it is back.
*/
if (!cpu_online(cpu)) {
- clpc->wall[cpu] = 0;
+ base_wall[cpu] = 0;
continue;
}
idle = get_cpu_idle_time(cpu, &wall, 0);
- dw = wall - clpc->wall[cpu];
- di = idle - clpc->idle[cpu];
- valid = clpc->wall[cpu];
- clpc->wall[cpu] = wall;
- clpc->idle[cpu] = idle;
+ dw = wall - base_wall[cpu];
+ di = idle - base_idle[cpu];
+ valid = base_wall[cpu];
+ base_wall[cpu] = wall;
+ base_idle[cpu] = idle;
if (valid && dw && di <= dw)
busy = max_t(unsigned int, busy,
div64_u64((dw - di) * 100, dw));
}
- cl->busy = busy;
+ return busy;
}
static void apple_clpc_sample_cluster(struct apple_clpc *clpc,
@@ -641,8 +663,8 @@
struct cpufreq_policy *policy;
unsigned int busy, q, rail;
- apple_clpc_sample_busy(clpc, cl);
- busy = cl->busy;
+ busy = apple_clpc_busy_since(cl, clpc->wall, clpc->idle);
+ cl->busy = busy;
cl->level = 0;
policy = cpufreq_cpu_get(cl->policy_cpu);
@@ -1012,11 +1034,16 @@
if (!policy[i])
continue;
- if (step < 0 && cl->busy < APPLE_CLPC_BUSY_PCT)
+ if (step < 0 &&
+ (READ_ONCE(profile_busy_window) ? cl->power_busy : cl->busy) <
+ APPLE_CLPC_BUSY_PCT)
continue;
khz = apple_clpc_step_khz(policy[i], cl->max_khz, step > 0);
if (khz == cl->max_khz || khz > cl->top_khz)
continue;
+ if (step < 0 && READ_ONCE(profile_floor) &&
+ khz <= policy[i]->cpuinfo.min_freq)
+ continue;
if (pick < 0 ||
apple_clpc_steps_first(cl->max_khz, policy[i]->cpuinfo.max_freq,
clpc->clusters[pick].max_khz,
@@ -1042,8 +1069,9 @@
{
bool low = READ_ONCE(clpc->low_power);
struct cpufreq_policy *policy[APPLE_CLPC_MAX_CLUSTERS] = {};
- unsigned int i, pick_khz = 0;
+ unsigned int i, cpu, pick_khz = 0;
int mw, step = 0, pick;
+ bool fresh = false;
if (!clpc->low_power_khz || time_before(jiffies, clpc->power_next))
return;
@@ -1054,6 +1082,7 @@
/* The SMC updates the reading less often: act on a new one only. */
if (mw >= 0 && mw != clpc->power_mw) {
clpc->power_updates++;
+ fresh = true;
if (mw > (int)clpc->low_power_mw)
step = -1;
else if (mw < (int)clpc->low_power_mw * 9 / 10)
@@ -1064,8 +1093,13 @@
for (i = 0; i < clpc->nr_clusters; i++) {
struct apple_clpc_cluster *cl = &clpc->clusters[i];
- if (!clpc->has_pmc && low && clpc->low_power_mw)
- apple_clpc_sample_busy(clpc, cl);
+ if (fresh && clpc->power_wall)
+ cl->power_busy = apple_clpc_busy_since(cl, clpc->power_wall,
+ clpc->power_idle);
+ else if (!low && clpc->power_wall)
+ /* The next low-power reading starts a fresh window. */
+ for_each_cpu(cpu, cl->cpus)
+ clpc->power_wall[cpu] = 0;
policy[i] = cpufreq_cpu_get(cl->policy_cpu);
if (!policy[i])
continue;
@@ -1864,6 +1898,14 @@
clpc->saved_floor = apple_pmc_floor_read(clpc->pmc, clpc->agent) &
clpc->mask;
}
+ if (clpc->low_power_khz && clpc->low_power_mw) {
+ clpc->power_idle = devm_kcalloc(dev, nr_cpu_ids, sizeof(*clpc->power_idle),
+ GFP_KERNEL);
+ clpc->power_wall = devm_kcalloc(dev, nr_cpu_ids, sizeof(*clpc->power_wall),
+ GFP_KERNEL);
+ if (!clpc->power_idle || !clpc->power_wall)
+ return -ENOMEM;
+ }
for (i = 0; i < APPLE_CLPC_MAX_CLUSTERS; i++) {
if (!zalloc_cpumask_var(&clpc->clusters[i].cpus, GFP_KERNEL)) {
@@ -1957,6 +1999,9 @@
if (clpc->wall)
for_each_possible_cpu(cpu)
clpc->wall[cpu] = 0;
+ if (clpc->power_wall)
+ for_each_possible_cpu(cpu)
+ clpc->power_wall[cpu] = 0;
clpc->power_next = jiffies;
WRITE_ONCE(clpc->stopped, false);
apple_clpc_queue(clpc, true); |
|
@betizzel thank you. Both runs settle it: as it stands this PR doesn't fix #3450 on T6050, because
I'll merge it into this PR, and your J714s table counts as the hardware row at that head. We still need one regression row on another family, which I'll run. If you'd rather not, say so here and I'll write it from your experiment patch, credit you with |
|
@RyanTheTide opened #3671 against Locally verified on |
There was a problem hiding this comment.
Verdict: MERGE at 9163bf17bea2
Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.
Checked: - drivers/soc/apple/clpc.c: verified apple_clpc_sample_busy() extraction preserves PMC-backed sampling behavior and populates cl->busy on standalone (!clpc->has_pmc) instances when low && clpc->low_power_mw; verified apple_clpc_pick_profile_step() gates only downward steps (step < 0) on cl->busy >= APPLE_CLPC_BUSY_PCT while allowing step > 0 to restore idle capped clusters in apple_clpc_steps_first() order.
- KUnit test
apple_clpc_profile_step_busy_test: verified coverage of idle-under-overbudget, single-busy selection, multi-cluster busy ordering, idle step-up recovery, andstep == 0. - Non-blocking note: because
cl->busytracks the per-cluster maximum single-CPU utilization againstAPPLE_CLPC_BUSY_PCT(50%), a lightly spread multi-core load (<50% on every core) will not step down; confirm during the hardware matrix that this matches the intended#3450balance. - Checked for Apple material, AI attribution, private serials, and board/SoC gates: none found; human
Signed-off-bypresent.
Follow-ups (not blocking): queued CI, T6050 low-power load matrix row, maintainer approval; check spread multi-core load
clpc.c: main added apple_clpc_gpu_busy_clear_test and this branch adds apple_clpc_profile_step_busy_test at the same place, each with its KUNIT_CASE entry. Both tests and both entries are kept.
|
Merged main in at |
|
Merging at |
What
Fix the low-power platform profile walking idle CPU clusters down to their minimum OPP (300 MHz) when a GPU or display workload holds package power (
PHPC) abovelow_power_mw(reported in #3450):apple_clpc_sample_busy()fromapple_clpc_sample_cluster()and call it fromapple_clpc_profile_limit()when!clpc->has_pmcand low-power package power limiting is active, socl->busyis maintained across both PMC-backed and standalone CLPC instances without SoC gating.apple_clpc_pick_profile_step()and skip clusters withcl->busy < APPLE_CLPC_BUSY_PCT(50%) when stepping down (step < 0), while still restoring idle capped clusters whenPHPCfalls below 90% oflow_power_mw(step > 0).apple_clpc_profile_step_busy_testinapple-clpc-policy.Tested
Tested: host tests and KUnit 19/19 (below); J714s hardware row in the comments shows the gate does not engage on has_pmc SoCs (rework pending).
python3 tools/asahi/clpc-gpu-demand-tests.py: PASS (all positive and negative controls).python3 tools/asahi/clpc-high-power-cleanup-tests.py: PASS.scripts/checkpatch.pl:0 errors, 0 warnings.make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- O=out-kunit W=1 drivers/soc/apple/clpc.o: clean, 0 warnings../tools/testing/kunit/kunit.py run --arch=arm64 --cross_compile=aarch64-linux-gnu- --kunitconfig=drivers/soc/apple/clpc.kunitconfig --build_dir=out-kunit --jobs=6 'apple-clpc*': 19/19 passed (apple-clpc-policy: 5/5 includingapple_clpc_profile_step_busy_test,apple-clpc-gpu: 14/14, under KASAN + UBSAN in QEMU).KUnit output summary
Risk
Risk: two-way door · Macs whose CLPC runs the low-power platform profile (T6050 and others). Scoped strictly to
drivers/soc/apple/clpc.clow-powerPHPCstep-down selection. Busy CPU workloads (cl->busy >= 50%) step down in the exact sameapple_clpc_steps_first()order as before; recovery (step > 0) is unchanged; no DT/ABI changes or SoC gates; single-commit revert.Not yet
15x yesmatrix from soc: apple: clpc: low-power profile drives the CPUs to 300 MHz when the GPU holds PHPC above low_power_mw #3450, plus a fleet regression row.Fixes #3450