Repository navigation
soc: apple: clpc: fast GPU power target, CPU energy monitor and capacity-scaled LPM ceiling (J813/J815) - #3873
m0d16l14n1 wants to merge 6 commits into
Conversation
Describe two optional low-power properties on both CLPC bindings (apple,pmc.yaml and apple,clpc.yaml): - apple,low-power-capacity-ceiling: scale each CPU cluster's initial low-power frequency ceiling by capacity-dmips-mhz relative to the fastest cluster when the package power limiter is active, matching macOS's performance-level ceiling (leaving efficiency clusters uncapped until the power loop steps them down). - apple,energy-monitor: phandle to an apple,acc-energy node describing memory-mapped 64-bit CPU/cluster hardware energy accumulators and their picojoule-per-tick scale for 100 ms power limiting. Signed-off-by: Nick <nekreshen@yandex.ru>
…-limited Applying apple,low-power-frequency-max-mhz directly as a raw MHz ceiling on every cluster caps efficiency cores well below the single-thread throughput of performance cores at that frequency (on T8142, capping E at 2352 MHz while macOS leaves E uncapped up to 2964 MHz and lets the 5 W package limiter step it down under load). When apple,low-power-capacity-ceiling is set and the package power limiter is active, scale each cluster's initial low-power ceiling from low_power_khz by max(capacity-dmips-mhz) / cluster(capacity-dmips-mhz) read from the CPU DT nodes. Boards without the property, without capacity-dmips-mhz, or without an active package power limiter keep the existing raw-frequency ceiling so static-ceiling-only boards do not regress power draw. Adds a KUnit test covering T8142 E/P capacity scaling and missing-metadata fallback. Signed-off-by: Nick <nekreshen@yandex.ru>
The SMC package power keys (PHPC/PPSM) update at ~1 Hz, so a low-power limiter driven by SMC alone can wait up to a second before reacting to sudden CPU or GPU bursts. Add optional support for reading memory-mapped 64-bit hardware CPU/cluster energy accumulators described by apple,energy-monitor (with a torn-read-safe lo/hi/lo reader and exact integer pJ/ns -> mW conversion) together with live GPU power reported by the GPU driver via apple_clpc_gpu_set_power_mw(). In the low-power loop, combine the 100 ms hardware reading with the 1 Hz SMC reading (taking max(hw_mw, smc_mw) when both exist) so CPU/GPU bursts step down within 100 ms while SMC still covers unmeasured SoC rails. Resets the energy baseline cleanly on suspend/resume, leaving low-power mode, or counter wrap, exposes energy_mw and gpu power in debugfs, and adds KUnit tests for delta math, wrap handling, and power combination. Signed-off-by: Nick <nekreshen@yandex.ru>
The M5 firmware exposes a fast host power target in the status-config block (+0x128 enable, +0x12c target mW, +0x144 policy reason, all inside the unshifted 0x000..0x1dc band and relocated via M5StatusConfigMap) that the firmware polls continuously (~12 ms), separate from Region C +0x88's slower (~1 s) thermal budget word. Drive the status-config power target directly from CLPC's low-power GPU cap (writing reason 0x31200003 while capped and restoring the initial status-config maximum with reason 0x3000001d when uncapped, idle, or shutting down), keeping Region C +0x88 strictly for the thermal budget governor while retaining a Region C fallback if the status-config target is unavailable. Re-publishes automatically if firmware initdata is re-initialized after wake or recovery, and retries failed writes. Also reports live M5 GPU power (m5_gpu_power_mw()) to CLPC via apple_clpc_gpu_set_power_mw() for the 100 ms low-power loop, and extends g17-m5-governor-stop-tests.py to cover the status-config power target path. Signed-off-by: Nick <nekreshen@yandex.ru>
…capacity ceiling Describe the T8142 per-core and cluster hardware energy accumulators (6 E-cores + E-CPM + 4 P-cores + P-CPM, 25 pJ/tick) and wire them with apple,low-power-capacity-ceiling on the J813/J815 CLPC node so the low-power profile reacts to CPU/GPU bursts at 100 ms and leaves the E-cluster uncapped up to its top OPP until total package power crosses the target. Signed-off-by: Nick <nekreshen@yandex.ru>
2e0a1fc to
2870f8b
Compare
|
Tested on J815 (MacBook Pro 14" M5, T8142,
Note on Local verification on |
|
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.
Verdict: MERGE at 2870f8b479063aaf960c89ae9d99ec81b237648c
Blockers: none (note: this branch targets main while carrying the 4 commits from still-open #3646 at 6fe3caf379, which is already approved — merge #3646 first or land #3873 as the superset)
Checked: no Apple material, DT-property opt-in (no model gating), default command-line compatibility, apple,pmc.yaml / apple,clpc.yaml / apple,acc-energy.yaml, t8142-j813-j815.dtsi, clpc.c accumulator math / hybrid step policy / capacity ceiling / suspend & stop cleanup, g17 M5 status-config power target and cache-line cleaning, KUnit & host test coverage, J815 9/9 hardware receipt, PR text
Evidence
Documentation/devicetree/bindings/&arch/arm64/boot/dts/apple/t8142-j813-j815.dtsi: all new behavior is opt-in via DT properties (apple,power-key-id,apple,low-power-gpu-cap,apple,low-power-capacity-ceiling,apple,energy-monitor/apple,acc-energywith 12 T8142 windows at 25 pJ/tick).drivers/soc/apple/clpc.c&include/linux/soc/apple/clpc.h:apple_clpc_read_acc64()uses ahi/lo/hi2loop safe against 32-bit rollovers;apple_clpc_energy_delta_mw()guards zero windows, wraps, and multiplication overflow beforediv64_u64(delta * pj_per_tick, delta_ns).apple_clpc_power_step()acts onmax(hw_mw, smc_mw)on fresh 1 Hz SMC samples, allows immediate 100 ms step-down on hardware bursts above target without oscillating on stale SMC values, and falls back cleanly to bidirectional hardware control if SMC is absent.apple_clpc_cluster_low_power_khz()scales cleanly bycapacity-dmips-mhzwith fallback when metadata is absent;apple_clpc_stop()dropsgpu->cap_mwandapple_clpc_resume()resets baselines and caps cleanly.
drivers/gpu/drm/asahi/g17/(initdata/m5.rs,thermal.rs,mod.rs): verifiedstatus_configis 64-byte aligned (next_packed_allocation(..., 0x40)), so+0x128(enable) and+0x12c(target) share a 64-byte cache line while+0x144(reason) is cleaned on the adjacent line.PowerTargetcleanly decouples fast CLPC capping from the slow Region C thermal governor with Region C fallback, initdata-reload re-publish, failed-write retry, and shutdown restore. (Non-blocking nit: cleaningreason_linebeforetarget_lineinpublish_m5_power_target()guaranteesreasonreaches PoC ahead of the sharedenable/targetline.)- Tests & hardware row at exact head
2870f8b47906:pr-readinessgreen (MERGEABLE, zero conflicts; note hostedapple-build/dt-checks/host-tests/KUnitwereskippedon this fork PR while localW=1arm64 LLVM builds ofclpc.o,drivers/gpu/drm/asahi/, and J813/J815 DTBs,checkpatch.pl,clpc-*.py, andg17-*.pysuites all passed) and J815 hardware row (#issuecomment-7343000266) passed 9/9 across CPU, GPU, and mixed loads with 0 SErrors and 0 GPU faults.
The merge-base changed after approval.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Not approving at 2870f8b4 yet. The code looks right, but this PR's own "Not yet" row is still open, and the branch will conflict once #3868 lands.
What I checked: the five commits on top of #3646: the bindings; in clpc.c, the capacity ceiling, the energy monitor and the step policy; the g17 status-config power target; and the J813/J815 DT.
- The CLPC side only runs where the DT opts in. Without
apple,energy-monitorandapple,low-power-capacity-ceiling,apple_clpc_power_limited()and the ceilings work as before. governor_tick()now reads GPU power only while the GPU is busy. This doesn't change the thermal governor:Governor::tick()andcpu_advice()already ignore power when there was no recent activity.
Missing before merge:
-
A J714s (M5 Pro) row at head. Owner: the M5 lead.
- The g17 change runs on every M5 GPU. Each governor step reads status-config
+0x12c, and if that word changes under the driver, it writes+0x128,+0x12cand+0x144back. - J714s has no
apple,low-power-gpu-cap, so it should never write. This row also stands in for the PR's "Not yet" line about M5 Pro/Max/Ultra. - The row: boot the exact head, then run a GPU load (GPUBench
rt.sceneor GTA V) in balanced and in performance, before and after onememsleep. Check:- no GPU faults and no new firmware clamps;
- FPS within noise of main;
- if you have a status-config reader,
+0x128,+0x12cand+0x144still at their boot values.
- The g17 change runs on every M5 GPU. Each governor step reads status-config
-
Conflicts after #3868. Owner: m0d16l14n1.
- Once #3868 merges, this branch conflicts in
apple,pmc.yamlandapple,clpc.yaml, where both PRs add properties afterapple,low-power-gpu-cap. Keep both. - It also conflicts in
t8142-j813-j815.dtsi. Keepapple,low-power-smc-notice;and your two new lines. clpc.c,g17/mod.rsand the test scripts merge cleanly. I checked with a local merge-tree of this head onto main + #3868.- Your J815 kernel already carried all three PRs, so the merged content is what you tested. Please merge main, without a force push, after #3868 lands.
- Once #3868 merges, this branch conflicts in
Before merge, on our side:
- Hosted CI skipped
apple-build,dt-checks,host-testsand KUnit on this fork PR. I'll run the local equivalents on the merge tree:- W=1 builds of
clpc.o(plain and KUnit) anddrivers/gpu/drm/asahi/; - the J813/J815 DTBs;
dt_binding_checkfor the newapple,acc-energy.yaml;- the clpc and g17 host tests.
- W=1 builds of
clpc-gpu-demand-tests.pycurrently fails on main itself, att6041_from_dtafter #3965's T6041 DT change. That failure isn't from this PR.
Small fix (not blocking), same as the earlier nit: publish_m5_power_target() in g17/initdata/m5.rs cleans the enable/target line before the reason line, and issues dsb sy only after both. So the firmware can see the new enable and target before the new reason. To close that window: store the reason, dc cvac its line and dsb, then store target and enable and clean that line.
Conflicts with aurora-silicon#3868 and aurora-silicon#3992, resolved to keep both sides: - apple,pmc.yaml and apple,clpc.yaml: apple,low-power-smc-notice, then apple,low-power-capacity-ceiling and apple,energy-monitor. - t8142-j813-j815.dtsi: the notice, then the ceiling and the energy monitor on the CLPC node. - clpc.c: KUnit only. Keep the T6050 GPU fabric case and the capacity ceiling and energy power cases. The other files merge cleanly. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
#3868 is in How the conflicts were resolved, keeping both sides:
Local checks on the merge (clang 23, arm64):
Still owed before merge:
Your J815 row at |
There was a problem hiding this comment.
Verdict: MERGE at 1566d16
Checked: The new energy node and both CLPC binding variants pass dt-doc-validate. I ran the exact-head GPU demand and profile cleanup suites. The hardware energy loop rejects invalid deltas, samples independently of the slower SMC floor, and uses the opt-in capacity scaling only on boards that declare it. The merge retains the mainline SMC notice, with the new flags and accumulator phandle alongside it.
Follow-ups: Please keep the independent fast GPU target and CPU energy changes in separate reviewable PRs in future series.
DjDeveloperr
left a comment
There was a problem hiding this comment.
Approving at 1566d16957397a103cc4f83a4dcf6b47e57104e5. I read the whole diff against current main and found nothing that has to change. Two rows at this head still come first (below), so please don't merge on this alone. The last push is also ours (the merge of main).
What I checked
- Energy and power units: pJ / ns = mW is right, the multiplication is guarded, a counter that goes back drops the window, and the result is clamped before it meets the
intcompare. The first sample after a profile change or a resume only sets the baseline. - Locking and lifetime: the accumulators are read only under
sample_lockand not oncestoppedis set, so not across suspend. The GPU power is a single word in the refcounted input and is cleared on put. The power target only changes under the device lock. - Boards without the new properties:
apple_clpc_power_limited(), the ceilings and the power step take the same decisions as main. This includes T6050, which has a 15 W target and an SMC but no energy monitor. On the J700 the power target returns at once and the governor never arms, so what's left is one extra read per submission. - Rules: opt-in by DT property, no new parameter, no board or SoC test.
- The earlier note about the order of the two cache cleans is withdrawn. The status config is mapped write-combined, and its enable word is already 1 from boot, so there's nothing to reorder.
The J815 row still counts. From the head it ran on to this one, the PR's functions and the g17 files around them are the same, except g17/mod.rs, where main changed only calibration code that T8142 doesn't run. The J815 device tree gained only #3868's line, which that kernel already had. The rest is main's own CLPC work. I couldn't read that kernel's commit (66c55f0d3c02 isn't published), so this takes your description of it as given. If a built line of the PR changes, the J815 needs to run again.
Before merge, both ours:
- An M5 Pro row: balanced, performance, low power and one deep sleep, with a probe on the write of the three status-config words. It has to stay at zero hits.
- A short Neo row on a kernel that also has other work: GPU load, idle, reboot.
Not blocking
- The Risk line says the status-config target matters only with a non-zero cap. The code goes further: with no cap, if the firmware ever changes
+0x12c,set_maximum()andapply()inthermal.rswrite the boot value back, with enable and a reason. Nobody has watched that word on an M5 Pro or Max yet, and 24240 mW would be low there. That is what row 1 looks for. If it sees one write, the fix is to leave the words alone until a cap has been published. governor_tick()returns early when the firmware has stopped or crashed, beforeset_power_mw(). The last GPU power then stays in CLPC, and the 100 ms loop would keep adding it. No board can hit this today (J813/J815 report 0), but it needs a 0 there before an M5 Pro or Max getsapple,energy-monitor.- With
m5_thermal_governor=0the governor never runs. The cap is then published fromapply_effort(), but leaving low power under a steady GPU load keeps the old cap until the GPU idles, because a cap of 0 is skipped there. apple_clpc_init_energy_monitor()usesdevm_ioremap(), which ignores the bus'snonposted-mmio. These are reads and the J815 saw no SError, butdevm_ioremap_resource()handles it.- The 100 ms loop sees only CPU bursts on J813/J815, since GPU power reads 0 there. The commit message and the binding say CPU and GPU. One sentence in the PR on how 25 pJ, the register windows and
0x31200003were found would help the next reader.
What: Follow-up Low Power Mode series stacked on #3646: (1) drive the M5 GPU's fast status-config power target (+0x12c, ~12 ms firmware polling) from CLPC's low-power cap instead of sharing Region C +0x88 with the slower thermal governor, (2) read T8142 memory-mapped 64-bit CPU/cluster hardware energy accumulators + live GPU power for 100 ms burst limiting alongside the 1 Hz SMC
PPSMfloor, and (3) scale each CPU cluster's initial low-power ceiling bycapacity-dmips-mhzwhen the package power limiter is active (leaving the E-cluster uncapped at 2964 MHz until package power crosses the target).Tested: Booted and verified on J815 (
7.3.0-aurora-j815-dev, exact2870f8b47906commits: 9/9 PASS, 0 errors — CPU energy1097 -> 20311 mW, capacity ceiling2220 / 2964 MHz, steady CPU hold4838 mWwith zero oscillation, GPU hold4965 mWwith cap1250 mWand CPU ceilings untouched, mix4933 mW). LocalARCH=arm64 LLVM=1 W=1builds (clpc.oplain + KUnit,drivers/gpu/drm/asahi/,t8142-j813.dtb,t8142-j815.dtb),checkpatch.pl, and allclpc-*.py/g17-*.pyhost suites PASS.Risk: Two-way door · opt-in via DT properties (
apple,low-power-capacity-ceiling,apple,energy-monitor) on J813/J815 (t8142); M5 status-config power target affects M5 GPUs only when CLPC reports a non-zero low-power cap and falls back to Region C if unavailable.Not yet: Live
m5_gpu_power_mw()reporting on M5 Pro/Max/Ultra (J714/J716c/J775D; J81526B123usesis_common26()wherem5_gpu_power_mw()returns-EINVALby design).Details
Stacked on #3646 (
fork:j815/t8142-lpm-limit,6fe3caf3799b). Each topic is isolated in its own commit:apple,pmc.yaml,apple,clpc.yaml,apple,acc-energy.yaml):apple,low-power-capacity-ceiling: scales each CPU cluster's initial low-power frequency ceiling fromapple,low-power-frequency-max-mhzbymax(capacity-dmips-mhz) / cluster(capacity-dmips-mhz)when the package power limiter is active.apple,energy-monitor/apple,acc-energy: describes memory-mapped 64-bit CPU/cluster energy accumulator pairs (+0x0core/cluster logic,+0x8SRAM) andapple,picojoules-per-tick.drivers/soc/apple/clpc.c):E = 671,P = 1024,low_power_khz = 2220 MHz), P caps at 2220 MHz while E's equivalent ceiling (3388 MHz) exceeds its 2964 MHz top OPP so E stays uncapped until total package power exceeds the target (matching macOS J815 traces).apple,low-power-capacity-ceilingandapple_clpc_power_limited(clpc)so boards without a package power limiter keep the static raw-MHz ceiling.drivers/soc/apple/clpc.c,include/linux/soc/apple/clpc.h):hi/lo/hi) with exact integerpJ / ns = mWconversion plusapple_clpc_gpu_set_power_mw().apple_clpc_power_step()): acts onmax(hw_mw, smc_mw)on fresh 1 Hz SMC readings, lets fresh 100 ms hardware bursts above target step down immediately without acting on stale SMC readings or stepping up prematurely, and falls back to bidirectionalhw_mwcontrol when SMC is absent.balancedand resets baselines cleanly on profile transitions, suspend/resume, or counter wrap.drivers/gpu/drm/asahi/g17/):+0x12cmW,+0x144reason0x31200003,+0x128enable1, relocated viaM5StatusConfigMap) and restores the initial status-config maximum with reason0x3000001don uncap, idle, or shutdown.+0x88strictly for the slow thermal budget governor (with automatic Region C fallback if status-config is unavailable), re-publishes if firmware initdata reloads after wake/recovery, retries failed writes, and reports livem5_gpu_power_mw()to CLPC.t8142-j813-j815.dtsi):25 pJ/tick) and opts&clpcintoapple,energy-monitorandapple,low-power-capacity-ceiling.Evidence
aurora-kbuild(ARCH=arm64 LLVM=1 W=1):drivers/soc/apple/clpc.o(both plain andCONFIG_KUNIT=y),drivers/gpu/drm/asahi/,apple/t8142-j813.dtb,apple/t8142-j815.dtb: 0 errors, 0 new warnings.clpc-gpu-demand-tests.py,clpc-high-power-cleanup-tests.py(+--old-ref 677be395),g17-m5-governor-stop-tests.py(incl. status-config power target + all 3 mutations killed), and all othertools/asahi/g17-*.pysuites PASS.2870f8b47906): 9/9 PASS (see comment #issuecomment-7343000266).