From 544c49819597c0f456f947a1f7058a35e2b30da5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Thu, 19 Nov 2026 23:15:35 +1100 Subject: [PATCH] cpufreq: apple-soc: verify every SoC's transitions lazily on fast switch Lazy verification was enabled by a separate lazy_verify flag set only on T8140. The other SoCs whose command register reads back the accepted state (T8142, T8152, T6050) still waited about a transition per request on every frequency change, and so kept schedutil off the fast-switch path: every change woke the governor kthread, which then busy-waited on the register. Nothing in the lazy scheme is specific to T8140. It needs what verify_transition already describes: a command register whose PS1 field reads back the accepted state and a BUSY bit. It uses the per-SoC transition timeout for its deadline, so T8152 and T6050 keep their 2 ms bound, and it still stops all requests when the accepted state is not the one last written, so an unexpected owner is caught as before, one request later. Waited-for requests (initial check, static governors) are unchanged; suspend first settles a pending request, as on T8140. Drop lazy_verify and key the lazy path on verify_transition. Every policy can now switch from the scheduler, and a lowered fast die-temperature limit is applied to the cluster at once on all of them, as on T8140. The lazy scheme itself is Diljit Singh's. Fixes: b11a5e9e8cd8 ("cpufreq: apple: verify T8140 transitions on the next request") Signed-off-by: Ryan Murray --- drivers/cpufreq/apple-soc-cpufreq.c | 52 +++++++++++++++-------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/drivers/cpufreq/apple-soc-cpufreq.c b/drivers/cpufreq/apple-soc-cpufreq.c index 09233d4b4208d..9f26e2e38d01e 100644 --- a/drivers/cpufreq/apple-soc-cpufreq.c +++ b/drivers/cpufreq/apple-soc-cpufreq.c @@ -202,8 +202,13 @@ static int apple_fast_die_hp_state; struct apple_soc_cpufreq_info { bool has_ps2; + /* + * The command register reads back the accepted state, and each + * request is checked against it. Requests from the scheduler's + * fast-switch path are checked by a timer instead of waited for, + * see "Lazy verification". + */ bool verify_transition; - bool lazy_verify; /* Fail closed when the DT describes no fast die-temperature limit. */ bool needs_thermal_policy; bool needs_thermal_owner; @@ -289,15 +294,11 @@ static const struct apple_soc_cpufreq_info soc_t8112_info = { /* * T8140 uses 5-bit PS1 state IDs starting at 1. The command register reads * back the last accepted request, not a measured frequency; each request is - * verified. Requests from the scheduler's fast-switch path are verified by a - * timer rather than waited for, so schedutil can switch from the scheduler, - * see apple_soc_cpufreq_lazy_request(); requests through ->target_index - * (suspend, the static governors) are still waited for. Voltage, PLL and - * firmware throttling configuration are left as the bootloader set them. + * verified. Voltage, PLL and firmware throttling configuration are left as + * the bootloader set them. */ static const struct apple_soc_cpufreq_info soc_t8140_info = { .verify_transition = true, - .lazy_verify = true, .needs_thermal_policy = true, .min_pstate = 1, .max_pstate = 31, @@ -525,7 +526,7 @@ static int apple_soc_cpufreq_request(struct cpufreq_policy *policy, } /* - * Lazy verification (lazy_verify SoCs) + * Lazy verification (verify_transition SoCs) * * A transition takes about 50 us. The scheduler's fast-switch path must not * wait for one, nor drop a request: schedutil records the frequency it asked @@ -734,9 +735,9 @@ static unsigned int apple_soc_cpufreq_lazy_request(struct cpufreq_policy *policy /* * Applies a new fast die-temperature limit, whose highest P-state is @cap at - * @freq, to a lazy_verify cluster at once. schedutil picks up a lower limit - * only at its next frequency update, which a nohz_full CPU running with its - * tick stopped may not have for a long time. The cluster is moved to the + * @freq, to a verify_transition cluster at once. schedutil picks up a lower + * limit only at its next frequency update, which a nohz_full CPU running with + * its tick stopped may not have for a long time. The cluster is moved to the * P-state the scheduler last asked for, at most @cap, and later requests are * clamped to @cap. That also restores the request when the limit rises * again before schedutil has seen it fall: the QoS request is then left @@ -808,7 +809,7 @@ static int apple_soc_cpufreq_set_target(struct cpufreq_policy *policy, struct apple_cpu_priv *priv = policy->driver_data; /* A waited-for request replaces a pending one, see "Lazy verification". */ - if (priv->info->lazy_verify) + if (priv->info->verify_transition) apple_soc_cpufreq_drain(priv); return apple_soc_cpufreq_request(policy, index); @@ -827,13 +828,13 @@ static unsigned int apple_soc_cpufreq_pstate_freq(struct cpufreq_policy *policy, } /* - * On a lazy_verify SoC policy->cur is the last fast-switch request, which the - * cluster may not hold: it may still be pending, be lost to a failure that - * stopped requests, or have been moved since by a fast die-temperature limit, - * see apple_soc_cpufreq_lazy_cap(). The core skips a suspend frequency equal - * to policy->cur, so settle the cluster first, writing and verifying the - * pending request or reporting the failure, and record the state it settled - * in as policy->cur before the generic suspend. + * On a verify_transition SoC policy->cur is the last fast-switch request, + * which the cluster may not hold: it may still be pending, be lost to a + * failure that stopped requests, or have been moved since by a fast + * die-temperature limit, see apple_soc_cpufreq_lazy_cap(). The core skips a + * suspend frequency equal to policy->cur, so settle the cluster first, + * writing and verifying the pending request or reporting the failure, and + * record the state it settled in as policy->cur before the generic suspend. */ static int apple_soc_cpufreq_suspend(struct cpufreq_policy *policy) { @@ -852,7 +853,7 @@ static int apple_soc_cpufreq_suspend(struct cpufreq_policy *policy) spin_unlock_bh(&fd->lock); } - if (priv->info->lazy_verify) { + if (priv->info->verify_transition) { int pstate = apple_soc_cpufreq_drain(priv); unsigned int freq; int ret; @@ -913,7 +914,7 @@ static unsigned int apple_soc_cpufreq_fast_switch(struct cpufreq_policy *policy, if (idx < 0) return 0; - if (priv->info->lazy_verify) + if (priv->info->verify_transition) return apple_soc_cpufreq_lazy_request(policy, idx); if (apple_soc_cpufreq_request(policy, idx)) return 0; @@ -1010,8 +1011,8 @@ static void apple_fast_die_arm(struct apple_fast_die *fd) } /* - * Applies @limit to a lazy_verify cluster at once, as its fastest state at or - * below the limit, see apple_soc_cpufreq_lazy_cap(). + * Applies @limit to a verify_transition cluster at once, as its fastest state + * at or below the limit, see apple_soc_cpufreq_lazy_cap(). */ static void apple_fast_die_cap(struct apple_fast_die *fd, unsigned int limit) { @@ -1021,7 +1022,7 @@ static void apple_fast_die_cap(struct apple_fast_die *fd, unsigned int limit) unsigned int cap = 0, freq = 0; int moved; - if (!priv->info->lazy_verify) + if (!priv->info->verify_transition) return; cpufreq_for_each_valid_entry(pos, policy->freq_table) { @@ -1537,7 +1538,8 @@ static int apple_soc_cpufreq_init(struct cpufreq_policy *policy) policy->cpuinfo.transition_latency = transition_latency; policy->dvfs_possible_from_any_cpu = true; - policy->fast_switch_possible = !info->verify_transition || info->lazy_verify; + /* Verified transitions are checked lazily on the fast-switch path. */ + policy->fast_switch_possible = true; policy->suspend_freq = freq_table[0].frequency; return 0;