History

cpufreq: Make drivers using CPUFREQ_ETERNAL specify transition latency

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.

Rafael J. Wysocki committed 1 year ago

Commit f97aef01 parent d3f8f8d9 files · +14 −10Browse files

Unified · Split

9 files
  1. drivers/cpufreq/cpufreq-dt.c +1 −1
  2. drivers/cpufreq/imx6q-cpufreq.c +1 −1
  3. drivers/cpufreq/mediatek-cpufreq-hw.c +1 −1
  4. drivers/cpufreq/rcpufreq_dt.rs +1 −1
  5. drivers/cpufreq/scmi-cpufreq.c +1 −1
  6. drivers/cpufreq/scpi-cpufreq.c +1 −1
  7. drivers/cpufreq/spear-cpufreq.c +1 −1
  8. include/linux/cpufreq.h +3 −0
  9. rust/kernel/cpufreq.rs +4 −3
drivers/cpufreq/cpufreq-dt.c+1−1
@@ -104,7 +104,7 @@ static int cpufreq_init(struct cpufreq_policy *policy) · 103 unmodified lines
104 104
105 transition_latency = dev_pm_opp_get_max_transition_latency(cpu_dev);105 transition_latency = dev_pm_opp_get_max_transition_latency(cpu_dev);
106 if (!transition_latency)106 if (!transition_latency)
107 transition_latency = CPUFREQ_ETERNAL;107 transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
108 108
109 cpumask_copy(policy->cpus, priv->cpus);109 cpumask_copy(policy->cpus, priv->cpus);
110 policy->driver_data = priv;110 policy->driver_data = priv;
drivers/cpufreq/imx6q-cpufreq.c+1−1
@@ -442,7 +442,7 @@ soc_opp_out: · 441 unmodified lines
442 }442 }
443 443
444 if (of_property_read_u32(np, "clock-latency", &transition_latency))444 if (of_property_read_u32(np, "clock-latency", &transition_latency))
445 transition_latency = CPUFREQ_ETERNAL;445 transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
446 446
447 /*447 /*
448 * Calculate the ramp time for max voltage change in the448 * Calculate the ramp time for max voltage change in the
drivers/cpufreq/mediatek-cpufreq-hw.c+1−1
@@ -309,7 +309,7 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy) · 308 unmodified lines
309 309
310 latency = readl_relaxed(data->reg_bases[REG_FREQ_LATENCY]) * 1000;310 latency = readl_relaxed(data->reg_bases[REG_FREQ_LATENCY]) * 1000;
311 if (!latency)311 if (!latency)
312 latency = CPUFREQ_ETERNAL;312 latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
313 313
314 policy->cpuinfo.transition_latency = latency;314 policy->cpuinfo.transition_latency = latency;
315 policy->fast_switch_possible = true;315 policy->fast_switch_possible = true;
drivers/cpufreq/rcpufreq_dt.rs+1−1
@@ -123,7 +123,7 @@ impl cpufreq::Driver for CPUFreqDTDriver { · 122 unmodified lines
123 123
124 let mut transition_latency = opp_table.max_transition_latency_ns() as u32;124 let mut transition_latency = opp_table.max_transition_latency_ns() as u32;
125 if transition_latency == 0 {125 if transition_latency == 0 {
126 transition_latency = cpufreq::ETERNAL_LATENCY_NS;126 transition_latency = cpufreq::DEFAULT_TRANSITION_LATENCY_NS;
127 }127 }
128 128
129 policy129 policy
drivers/cpufreq/scmi-cpufreq.c+1−1
@@ -294,7 +294,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy) · 293 unmodified lines
294 294
295 latency = perf_ops->transition_latency_get(ph, domain);295 latency = perf_ops->transition_latency_get(ph, domain);
296 if (!latency)296 if (!latency)
297 latency = CPUFREQ_ETERNAL;297 latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
298 298
299 policy->cpuinfo.transition_latency = latency;299 policy->cpuinfo.transition_latency = latency;
300 300
drivers/cpufreq/scpi-cpufreq.c+1−1
@@ -157,7 +157,7 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy) · 156 unmodified lines
157 157
158 latency = scpi_ops->get_transition_latency(cpu_dev);158 latency = scpi_ops->get_transition_latency(cpu_dev);
159 if (!latency)159 if (!latency)
160 latency = CPUFREQ_ETERNAL;160 latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
161 161
162 policy->cpuinfo.transition_latency = latency;162 policy->cpuinfo.transition_latency = latency;
163 163
drivers/cpufreq/spear-cpufreq.c+1−1
@@ -182,7 +182,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev) · 181 unmodified lines
182 182
183 if (of_property_read_u32(np, "clock-latency",183 if (of_property_read_u32(np, "clock-latency",
184 &spear_cpufreq.transition_latency))184 &spear_cpufreq.transition_latency))
185 spear_cpufreq.transition_latency = CPUFREQ_ETERNAL;185 spear_cpufreq.transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
186 186
187 cnt = of_property_count_u32_elems(np, "cpufreq_tbl");187 cnt = of_property_count_u32_elems(np, "cpufreq_tbl");
188 if (cnt <= 0) {188 if (cnt <= 0) {
include/linux/cpufreq.h+3−0
@@ -32,6 +32,9 @@ · 31 unmodified lines
32 */32 */
33 33
34#define CPUFREQ_ETERNAL (-1)34#define CPUFREQ_ETERNAL (-1)
35
36#define CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS NSEC_PER_MSEC
37
35#define CPUFREQ_NAME_LEN 1638#define CPUFREQ_NAME_LEN 16
36/* Print length for names. Extra 1 space for accommodating '\n' in prints */39/* Print length for names. Extra 1 space for accommodating '\n' in prints */
37#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)40#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)
rust/kernel/cpufreq.rs+4−3
@@ -39,7 +39,8 @@ use macros::vtable; · 38 unmodified lines
39const CPUFREQ_NAME_LEN: usize = bindings::CPUFREQ_NAME_LEN as usize;39const CPUFREQ_NAME_LEN: usize = bindings::CPUFREQ_NAME_LEN as usize;
40 40
41/// Default transition latency value in nanoseconds.41/// Default transition latency value in nanoseconds.
42pub const ETERNAL_LATENCY_NS: u32 = bindings::CPUFREQ_ETERNAL as u32;42pub const DEFAULT_TRANSITION_LATENCY_NS: u32 =
43 bindings::CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
43 44
44/// CPU frequency driver flags.45/// CPU frequency driver flags.
45pub mod flags {46pub mod flags {
@@ -400,13 +401,13 @@ impl TableBuilder { · 354 unmodified lines
400/// The following example demonstrates how to create a CPU frequency table.401/// The following example demonstrates how to create a CPU frequency table.
401///402///
402/// ```403/// ```
403/// use kernel::cpufreq::{ETERNAL_LATENCY_NS, Policy};404/// use kernel::cpufreq::{DEFAULT_TRANSITION_LATENCY_NS, Policy};
404///405///
405/// fn update_policy(policy: &mut Policy) {406/// fn update_policy(policy: &mut Policy) {
406/// policy407/// policy
407/// .set_dvfs_possible_from_any_cpu(true)408/// .set_dvfs_possible_from_any_cpu(true)
408/// .set_fast_switch_possible(true)409/// .set_fast_switch_possible(true)
409/// .set_transition_latency_ns(ETERNAL_LATENCY_NS);410/// .set_transition_latency_ns(DEFAULT_TRANSITION_LATENCY_NS);
410///411///
411/// pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur()));412/// pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur()));
412/// }413/// }