Repository navigation
cpufreq: apple: J700 T8140 cpufreq and SMC CPU thermal policy (reworked; PMP-v2 parked) - #22
Merged
Merged
Conversation
This was referenced Sep 25, 2026
RyanTheTide
force-pushed
the
series/neo-cpufreq-aurora-wip-20260925
branch
from
September 25, 2026 01:24
2533e5c to
564a5b9
Compare
RyanTheTide
marked this pull request as ready for review
September 25, 2026 07:12
RyanTheTide
force-pushed
the
series/neo-kernel-prerequisites-20260925
branch
from
September 25, 2026 12:44
40da0e7 to
efa5bf2
Compare
RyanTheTide
changed the base branch from
series/neo-kernel-prerequisites-20260925
to
aurora-wip
September 25, 2026 13:35
commit d87cb88 upstream. apple_soc_cpufreq_init() adds OPP tables from firmware, but some failure paths do not remove them. The driver also uses dev_pm_opp_remove_all_dynamic(), which is not the right cleanup helper for OPP tables loaded from firmware. Use the cpumask OPP helper after the policy CPU mask has been populated. Pair it with the matching cpumask remove helper on failure paths and in apple_soc_cpufreq_exit(). This also removes the separate dev_pm_opp_set_sharing_cpus() call, as the cpumask helper loads the DT OPP tables for all CPUs in the policy. Fixes: 6286bbb ("cpufreq: apple-soc: Add new driver to control Apple SoC CPU P-states") Cc: [email protected] Signed-off-by: Haoxiang Li <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
apple_soc_cpufreq_exit() drops the static OPP tables with dev_pm_opp_of_cpumask_remove_table(policy->cpus), but policy->cpus is always empty by then. __cpufreq_offline() clears the outgoing CPU from the mask first and calls ->exit() only once the last CPU of the policy has gone, and unbinding the driver takes the same path. The call removes nothing, so every time a cluster goes fully offline and comes back, or the driver is rebound, the OPP table of each of its CPUs is left with one more reference and is never freed. Remove the tables of policy->related_cpus instead, which still lists every CPU the policy covered, as qcom-cpufreq-hw does. The error path of apple_soc_cpufreq_init() keeps using policy->cpus, because the core fills in related_cpus only after ->init() has succeeded. Fixes: d87cb88 ("cpufreq: apple-soc: Fix OPP table cleanup") Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
macsmc_hwmon_read_f32_scaled() decodes the IEEE-754 single-precision values that the SMC returns for most sensor keys, and it mishandles the special encodings: - An exponent field of 0xff (infinity or NaN) is decoded as a huge finite number and saturated, so a sensor without a valid reading is reported as LONG_MAX or LONG_MIN millidegrees, millivolts, milliamps or microwatts. The chip registers HWMON_C_REGISTER_TZ, so a thermal zone built on such a sensor would see an absurd temperature. - The implicit leading one is also added when the exponent field is 0, so zero and subnormal inputs are decoded with the wrong mantissa and exponent. With the scales the driver uses (1000 and 1000000) the result still truncates to 0, so no reported value changes; the decoder now follows IEEE-754 for every exponent. - A negative value whose magnitude is exactly LONG_MAX + 1 was negated after the conversion to long, which is signed overflow. Return -ENODATA for NaN and infinity so that such readings show up as unavailable rather than as extreme values, decode exponent field 0 without the implicit bit and with the minimum exponent, and produce LONG_MIN without negating it. A scaled value that does not fit in a long is now reported as -ERANGE instead of being clamped to LONG_MAX or LONG_MIN: nothing the SMC measures gets anywhere near 9.2e15 degrees, volts or amps, so such a value is a decoding or transport problem, and a clamped number would only hide it from the thermal core and from userspace. Ordinary readings are unchanged and still truncate towards zero. Eryk Wieliczko wrote this change for Aurora's tree (2026-09-08, under the file's GPL-2.0-only OR MIT licence) and verified it against 9045 exact-integer oracle cases under UBSan and on a J700. It is carried here unchanged, without its host-side Python test; his Signed-off-by is outstanding. Fixes: 785205f ("hwmon: Add Apple Silicon SMC hwmon driver") Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
Add the MIDR part numbers of the two core types in the Apple T8140 (A18 Pro) SoC, as read from MIDR_EL1 on a J700: 0x060 for the efficiency cores and 0x061 for the performance cores. The T8140 WFI workaround in the idle code matches on them. These cores have no generational codename, so name them after the SoC codename and the core type, as the "apple,tahiti-e" and "apple,tahiti-p" CPU compatibles for this SoC do. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
On the Apple T8140 (A18 Pro) in the J700, the secondary CPUs can come back from WFI with their general-purpose registers cleared and their FP/SIMD registers lost; SP and memory survive. cpu_do_idle() is C code that expects its callee-saved registers back, so the default idle=wfi corrupts whatever the idle path keeps in them. Until now the only stable setting on J700 was idle=nop, which leaves every core spinning at full clock: measured on J700 at the same load average, the die idled at 85-92 C (peaks of 106.7 C) with idle=nop and at 43.4 C with WFI and this change. On those CPUs, cpu_do_idle() now enters WFI through apple_cpu_wfi(), which stores x18-x30 (the AAPCS64 callee-saved registers, the frame pointer, the link register, and x18, which may hold the shadow call stack pointer) on the stack, issues DSB SY and WFI, and restores them after an ISB. Being an ordinary function call, it already tells the compiler that x0-x17 and the flags are clobbered. Beforehand, fpsimd_save_and_flush_cpu_state() saves any live user FP/SIMD state and drops this CPU's ownership of it, so the next return to userspace reloads the registers even when the same task resumes here. The workaround is chosen once at boot: an early initcall matches the boot CPU's MIDR against the T8140 E and P core IDs and enables a static key. Every other CPU pays one patched-out branch per idle entry, and kernels without CONFIG_ARCH_APPLE compile the path out. The key is set before the secondaries are brought up; the boot CPU idles with plain WFI until then, and only the secondaries are known to be affected. apple_cpu_wfi() lives in .cpuidle.text like the rest of the idle path. The root cause is not known. Other Apple SoCs keep this state across WFI unless the OS asks for a deep state: cpuidle-apple sets bits 25:24 of s3_5_c15_c5_0 (CYC_OVRD) for its power-down state and brackets that state with cpu_pm_enter()/cpu_pm_exit(). The T8140 secondaries may be left by the boot chain with a WFI mode that does not retain state. Until that is understood, this stays a downstream workaround. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The CPU clusters of the Apple T8140 (A18 Pro) use the same command register layout as T8112, with a 5-bit state field, but Linux has to drive them differently: every transition must be verified, the state left by the bootloader must be adopted rather than overwritten, and states above 2 may only be used under a thermal policy. Add the compatible without the generic "apple,cluster-cpufreq" fallback. A kernel that only knows the fallback must not program these clusters: it would drive them without verifying any transition and expose the whole ladder without thermal coupling. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
The Apple T8140 (A18 Pro) clusters take P-state requests through the same command register layout as T8112, but this driver cannot assume that it owns them from the start: the bootloader leaves a state of its own choosing, and nothing guarantees that no other agent writes the register later. Add them with a per-SoC verify_transition mode: - At init, wait for the controller to be idle, read the state left in the command register and adopt it as policy->cur. A state that is not in the OPP table fails init with -ERANGE rather than being replaced by one whose effect is unknown. - Before each request, check that the register still holds the state this driver last set or adopted; anything else means another agent has changed it. After writing, poll until the controller is idle and reports the requested state. A request for the current state is skipped. - A busy timeout, an unexpected state or a completion timeout latches the cluster as failed. The driver logs the command register once and then returns -EIO for every later request without touching the hardware, so the cluster stays wherever the controller stopped and no governor, user limit or thermal cap can move it until the policy is torn down and initialised again. The driver deliberately does not guess a rollback after an unexplained failure. - Fast switching is disabled, because a verified request can busy-wait for up to twice APPLE_DVFS_TRANSITION_TIMEOUT, and that doubled bound is the transition latency the policy advertises when the DT gives none. - T8140 state IDs start at 1, so the info data gains min_pstate. Its DVFS_STATUS layout is not known, so ->get() uses the existing command-register fallback and reports the last accepted request, not a measured frequency. The T8140 ladders go up to P17 (4.044 GHz) on the P cluster and E6 (2.424 GHz) on the E cluster. States above 2 need a thermal policy that can cap them; until one is coupled to this driver, a T8140 OPP table containing them is refused. Three changes apply to every SoC the driver handles: - OPP levels outside [min_pstate, max_pstate] fail init, and apple_soc_cpufreq_set_target() rejects them. The old "fallback" clamp compared the table index rather than the level and ran after the level had been read, so an out-of-range level was shifted unmasked into the command register, over the neighbouring bits. No in-tree Apple DT has such a level. - A cluster node with status = "disabled" is left alone. - The cluster node reference is dropped after of_iomap() instead of before it. All SoCs keep sharing one cpufreq_driver; the match data alone selects the T8140 behaviour. As on the other SoCs, T8140 clusters are set to their lowest state for system suspend. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
The SMC in the J700 (T8140) reports six CPU die temperatures: Te05 and Te0S for the E cluster and Tp01, Tp05, Tp09 and Tp0D for the P cluster. Add a boolean property that makes the SMC hwmon node the telemetry source of the J700 CPU thermal policy. When it is present, the first six temperature channels must be exactly those keys, further channels only report to userspace, and the CPU frequency is held at its minimum while the six readings are unavailable. This describes operating-system policy rather than hardware. The standard description of a thermal sensor is #thermal-sensor-cells on this node plus thermal-zones and cooling-maps in the board DT; the J700 policy does not use that yet because it also holds a minimum-frequency cap while the readings are stale, which DT thermal zones cannot express. The property is a downstream binding and goes away when the J700 CPU thermal policy moves to DT thermal zones. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
Add the CPU thermal policy that the J700 (T8140) needs before apple-soc-cpufreq may use P-states above 2, and couple the cpufreq driver to it. The policy follows the hottest of six SMC CPU die sensors, read every 25 ms through a callback registered with devm_apple_smc_thermal_register() (the SMC hwmon driver provides it). It has two controls: - A thermal zone, "apple-smc-selected", with one passive trip at 95 C and 10 C of hysteresis. Its binding sets both the lower and the upper limit to the maximum state of the two cpufreq cooling devices, so step_wise sends both clusters straight to their lowest frequency when the trip is crossed instead of stepping down the table. - A FREQ_QOS_MAX request per cluster, added at the lowest frequency when cpufreq attaches the cluster. It is released only while the zone is registered and enabled and the last three samples were read within 200 ms, and it is applied again from 103 C until the die is back below 98 C, after any read error or stale sample, when the zone is disabled, when a whole cluster goes offline, and after cpufreq reports a DVFS fault. A 25 ms watchdog re-evaluates it in case sampling stalls. Until a provider registers, both clusters stay at their lowest frequency. apple-soc-cpufreq attaches a T8140 cluster when its OPP table has states above 2 or the SMC hwmon node carries apple,cpu-thermal-policy, registers the cooling device from ->ready(), reports latched DVFS failures, and detaches in ->exit(). This replaces the outright refusal of such tables. If the policy cannot attach, the cluster is not registered. A latched cluster cannot act on the minimum request, but the other cluster is still capped. The thresholds are Linux operating policy, not Apple or silicon limits. The trip was first set at 80 C with a 70 C release, but with the spinning idle loop the J700 needed at the time the die idled at 70-77 C, inside that band, so the throttle never released and the P cluster was held between 1.26 and 2.20 GHz of its 4.044 GHz. The band now sits above the idle temperature, which is around 43 C with WFI idle. SMC readings can lag by about a second under load, so the 25 ms sampling does not bound the sensor age; the 200 ms limit only bounds the host transaction. This is a narrow, J700-only arrangement and not how thermal limits are meant to be described. It bypasses DT thermal zones even though macsmc-hwmon already registers its channels as thermal sensors and apple-soc-cpufreq is a cooling device; it hard-codes two clusters, runs three 25 ms timers (sampling, watchdog and zone polling) and only acts on "apple,j700" machines. DT thermal zones are the intended replacement: this driver, the provider hooks in macsmc-hwmon and apple,cpu-thermal-policy go away once the J700 device tree describes its CPU thermal zones and the stale-reading cap has an equivalent there. The driver is built in only, since it keeps global state and has no unload path. Its entry points are exported so that apple-soc-cpufreq and macsmc-hwmon can still be built as modules. The policy, its cpufreq coupling and the provider interface are Eryk Wieliczko's J700 SMC thermal mitigation for Aurora's tree (2026-09-08, GPL-2.0-only OR MIT), with the thresholds re-tuned as described above and without the auxiliary-zone and boot-cap adaptations that coupled it to the PMP coprocessor policy; those stay on the parked PMP branch. His Signed-off-by is outstanding. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
When the SMC hwmon node carries apple,cpu-thermal-policy (J700 only), supply the CPU die temperatures to the SMC CPU thermal policy: - At probe, check that the first six temperature channels are exactly Te05, Te0S, Tp01, Tp05, Tp09 and Tp0D, each a readable 4-byte "flt " key that is not a function key, and register a sampling callback with devm_apple_smc_thermal_register(). A mismatch, a machine other than the J700 or a failed registration fails the probe. That includes -ENODEV when the thermal policy is not built, in which case the SMC sensors are missing from hwmon altogether. - The callback reads the six keys and returns the highest value in millidegrees. A read error (a NaN reading is now -ENODATA), a value outside the range of an int (-ERANGE) or a round that took 200 ms or more (-ETIMEDOUT) fails the sample. - Each successful round is cached, and reads of temp1 to temp6 are answered from the cache: userspace sees the values the policy acts on and adds no SMC traffic of its own. Those reads return the last sampling error, or -ETIMEDOUT once the cache is older than 200 ms. Channels after the sixth are read from the SMC as before. The channels are identified by position, so the board DT must list the six policy sensors first. Like the property, this is a J700-specific arrangement that goes away when the CPU thermal limits move to DT thermal zones. The provider is part of Eryk Wieliczko's J700 SMC thermal mitigation for Aurora's tree (2026-09-08, GPL-2.0-only OR MIT); the reporting-only channels after the sixth were added to it later in that tree. His Signed-off-by is outstanding. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
The SMC of the Apple T8140 (A18 Pro) is driven like the T8103 one, through the same mailbox protocol and the same "smc" and "sram" register regions; the J700 device tree describes it as "apple,t8140-smc", "apple,t8103-smc". Add the SoC compatible to the list that falls back to apple,t8103-smc. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
The SPMI controller of the Apple T8140 (A18 Pro), which connects the J700's Baku PMIC, is register compatible with the T8103 one. Add the SoC compatible with the apple,t8103-spmi fallback so that the J700 device tree can describe it. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
The J700 (T8140) uses a PMIC called Baku. Like the PMICs already listed, it holds the boot-state scratch registers that apple,smc-reboot uses (boot stage, boot error and panic counters, and the shutdown flag) and exposes them over SPMI; on Baku they start at 0xf700. Add its compatible so that it can be described with the apple,spmi-nvmem fallback. Assisted-by: LLM checkpatch sparse Signed-off-by: Ryan Murray <[email protected]>
The T8140 WFI workaround and the J700 CPU thermal policy are Aurora Silicon code rather than Asahi Linux code, so list their files in the Apple T8140 / J700 entry instead of under ARM/APPLE MACHINE SUPPORT. Changes to the shared drivers (apple-soc-cpufreq, macsmc-hwmon) and to the DT bindings stay with their existing entries. Assisted-by: LLM checkpatch sparse Co-authored-by: Claude Fable 5.1 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
force-pushed
the
series/neo-cpufreq-aurora-wip-20260925
branch
from
September 25, 2026 15:23
ce03603 to
73adb45
Compare
This was referenced Sep 25, 2026
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
J700 CPU frequency scaling and thermal policy, reworked after the 2026-09-25 maintainer audit and rebased onto
aurora-wip.What changed since the audited head (ce036034)
W=1 C=1(sparse) andcheckpatch --strict.commit … upstream.line, followed by a fix for thepolicy->cpus-at-exit leak it inherits (related_cpus).-ENODATA, subnormals, no signed overflow) is its own patch withFixes:; it is Eryk Wieliczko's change and says so..cpuidle.text, and the message states plainly that the root cause is not known.cpufreq_driverfor all SoCs (no second driver selected byof_machine_is_compatible); T8140 support hangs off match data; the interim rule that T8140 P-states above 2 need a thermal policy is enforced in the driver until the policy patch lands; no boot cap, no PMP readback, no exported symbols for another driver.depends on CPU_FREQ_THERMALinstead ofselect CPU_THERMAL, placed among the platform thermal drivers. Both patches credit Eryk Wieliczko's original work; his Signed-off-by is outstanding.apple,cpu-thermal-policyproperty; MAINTAINERS adds the new files to the T8140/J700 entry created by arm64: apple: T8140/J700 platform prerequisites (reworked) #10..rst),depends on !KEXEC_CORE, and the seven Python "selftests". They need a design built onpmp.rsandapple-dartwith a real binding; the original head remains available asce03603421d5.Checks: per-commit object compile with
W=1 C=1(upstream sparse),checkpatch --strict --codespell,checkkconfigsymbols.py --diff,dt_binding_checkon the five schemas, plus three alternative configurations (cpufreq and hwmon as modules; thermal policy disabled; arm64 defconfig withARCH_APPLE=nto proveidle.ocarries no Apple reference).Not run on hardware in this form. The J700 must still confirm: the "preserving registers across WFI" boot message, both clusters reaching 2424000/4044000 kHz within a second of boot, the
apple-smc-selectedzone enabled, an s2idle cycle with the generic suspend hook, and offline/online cycles of the P cluster. The J700 kernel config must enableAPPLE_SMC_CPU_THERMAL; with it disabled andapple,cpu-thermal-policyin the DT, macsmc-hwmon refuses to probe and the T8140 clusters stay unregistered by design.Consequences for #23: the
pmp/pmp_mboxnodes andpmp_v2.thermal_policy=0go away; the hwmon node already lists the six CPU die sensors first.🤖 Generated with Claude Code