]> www.infradead.org Git - users/hch/misc.git/commitdiff
cpufreq: Make drivers using CPUFREQ_ETERNAL specify transition latency
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 26 Sep 2025 10:12:37 +0000 (12:12 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 1 Oct 2025 11:56:24 +0000 (13:56 +0200)
Commit a755d0e2d41b ("cpufreq: Honour transition_latency over
transition_delay_us") caused platforms where cpuinfo.transition_latency
is CPUFREQ_ETERNAL to get a very large transition latency whereas
previously it had been capped at 10 ms (and later at 2 ms).

This led to a user-observable regression between 6.6 and 6.12 as
described by Shawn:

"The dbs sampling_rate was 10000 us on 6.6 and suddently becomes
 6442450 us (4294967295 / 1000 * 1.5) on 6.12 for these platforms
 because the default transition delay was dropped [...].

 It slows down dbs governor's reacting to CPU loading change
 dramatically.  Also, as transition_delay_us is used by schedutil
 governor as rate_limit_us, it shows a negative impact on device
 idle power consumption, because the device gets slightly less time
 in the lowest OPP."

Evidently, the expectation of the drivers using CPUFREQ_ETERNAL as
cpuinfo.transition_latency was that it would be capped by the core,
but they may as well return a default transition latency value instead
of CPUFREQ_ETERNAL and the core need not do anything with it.

Accordingly, introduce CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS and make
all of the drivers in question use it instead of CPUFREQ_ETERNAL.  Also
update the related Rust binding.

Fixes: a755d0e2d41b ("cpufreq: Honour transition_latency over transition_delay_us")
Closes: https://lore.kernel.org/linux-pm/20250922125929.453444-1-shawnguo2@yeah.net/
Reported-by: Shawn Guo <shawnguo@kernel.org>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Reviewed-by: Jie Zhan <zhanjie9@hisilicon.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Cc: 6.6+ <stable@vger.kernel.org> # 6.6+
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/2264949.irdbgypaU6@rafael.j.wysocki
[ rjw: Fix typo in new symbol name, drop redundant type cast from Rust binding ]
Tested-by: Shawn Guo <shawnguo@kernel.org> # with cpufreq-dt driver
Reviewed-by: Qais Yousef <qyousef@layalina.io>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpufreq/cpufreq-dt.c
drivers/cpufreq/imx6q-cpufreq.c
drivers/cpufreq/mediatek-cpufreq-hw.c
drivers/cpufreq/rcpufreq_dt.rs
drivers/cpufreq/scmi-cpufreq.c
drivers/cpufreq/scpi-cpufreq.c
drivers/cpufreq/spear-cpufreq.c
include/linux/cpufreq.h
rust/kernel/cpufreq.rs

index 506437489b4db241a7a6259274ae84e688772e66..7d5079fd1688257062bc9660143d6f3b498570a6 100644 (file)
@@ -104,7 +104,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 
        transition_latency = dev_pm_opp_get_max_transition_latency(cpu_dev);
        if (!transition_latency)
-               transition_latency = CPUFREQ_ETERNAL;
+               transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
 
        cpumask_copy(policy->cpus, priv->cpus);
        policy->driver_data = priv;
index db1c88e9d3f9cd363775cbfd8937846963b6d41a..e93697d3edfd9b0905cadc6443f5bf03157566aa 100644 (file)
@@ -442,7 +442,7 @@ soc_opp_out:
        }
 
        if (of_property_read_u32(np, "clock-latency", &transition_latency))
-               transition_latency = CPUFREQ_ETERNAL;
+               transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
 
        /*
         * Calculate the ramp time for max voltage change in the
index fce5aa5ceea033bb70537ad9280e9ee02e3671cc..ae4500ab48913d71a68a83285dd78eb8dde43757 100644 (file)
@@ -309,7 +309,7 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
 
        latency = readl_relaxed(data->reg_bases[REG_FREQ_LATENCY]) * 1000;
        if (!latency)
-               latency = CPUFREQ_ETERNAL;
+               latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
 
        policy->cpuinfo.transition_latency = latency;
        policy->fast_switch_possible = true;
index 7e1fbf9a091f74065f9e14e7e9b5195213642452..3909022e1c7448ecc21f40944c330c92bef7204d 100644 (file)
@@ -123,7 +123,7 @@ impl cpufreq::Driver for CPUFreqDTDriver {
 
         let mut transition_latency = opp_table.max_transition_latency_ns() as u32;
         if transition_latency == 0 {
-            transition_latency = cpufreq::ETERNAL_LATENCY_NS;
+            transition_latency = cpufreq::DEFAULT_TRANSITION_LATENCY_NS;
         }
 
         policy
index 38c165d526d144bd5d6d72c8bec0b813d5070b07..d2a110079f5fd587d8c5680057239f9682268a4d 100644 (file)
@@ -294,7 +294,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
 
        latency = perf_ops->transition_latency_get(ph, domain);
        if (!latency)
-               latency = CPUFREQ_ETERNAL;
+               latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
 
        policy->cpuinfo.transition_latency = latency;
 
index dcbb0ae7dd476cc3cdd9893388bbefcaa0f98ca1..e530345baddf6a7b40eb1d27dabe3c7ba01c3d27 100644 (file)
@@ -157,7 +157,7 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy)
 
        latency = scpi_ops->get_transition_latency(cpu_dev);
        if (!latency)
-               latency = CPUFREQ_ETERNAL;
+               latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
 
        policy->cpuinfo.transition_latency = latency;
 
index 707c71090cc3228afabf91a2593783f28faa776f..2a1550e1aa21fc6f9fff2ed4422ea6c7a76b28c4 100644 (file)
@@ -182,7 +182,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
 
        if (of_property_read_u32(np, "clock-latency",
                                &spear_cpufreq.transition_latency))
-               spear_cpufreq.transition_latency = CPUFREQ_ETERNAL;
+               spear_cpufreq.transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
 
        cnt = of_property_count_u32_elems(np, "cpufreq_tbl");
        if (cnt <= 0) {
index 40966512ea1812fb63a782f3f69ead46e8d9a2e4..bc8c083bc16a66fb893eaf123fdc84b514d66a96 100644 (file)
@@ -32,6 +32,9 @@
  */
 
 #define CPUFREQ_ETERNAL                        (-1)
+
+#define CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS  NSEC_PER_MSEC
+
 #define CPUFREQ_NAME_LEN               16
 /* Print length for names. Extra 1 space for accommodating '\n' in prints */
 #define CPUFREQ_NAME_PLEN              (CPUFREQ_NAME_LEN + 1)
index eea57ba95f241dc06218e2d65a0986a1f9c1415c..2ea735700ae75db60f7ca51d454824feb7b7b95f 100644 (file)
@@ -39,7 +39,8 @@ use macros::vtable;
 const CPUFREQ_NAME_LEN: usize = bindings::CPUFREQ_NAME_LEN as usize;
 
 /// Default transition latency value in nanoseconds.
-pub const ETERNAL_LATENCY_NS: u32 = bindings::CPUFREQ_ETERNAL as u32;
+pub const DEFAULT_TRANSITION_LATENCY_NS: u32 =
+        bindings::CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
 
 /// CPU frequency driver flags.
 pub mod flags {
@@ -400,13 +401,13 @@ impl TableBuilder {
 /// The following example demonstrates how to create a CPU frequency table.
 ///
 /// ```
-/// use kernel::cpufreq::{ETERNAL_LATENCY_NS, Policy};
+/// use kernel::cpufreq::{DEFAULT_TRANSITION_LATENCY_NS, Policy};
 ///
 /// fn update_policy(policy: &mut Policy) {
 ///     policy
 ///         .set_dvfs_possible_from_any_cpu(true)
 ///         .set_fast_switch_possible(true)
-///         .set_transition_latency_ns(ETERNAL_LATENCY_NS);
+///         .set_transition_latency_ns(DEFAULT_TRANSITION_LATENCY_NS);
 ///
 ///     pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur()));
 /// }