Skip to content

Commit f97aef0

Browse files
committed
cpufreq: Make drivers using CPUFREQ_ETERNAL specify transition latency
Commit a755d0e ("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: a755d0e ("cpufreq: Honour transition_latency over transition_delay_us") Closes: https://lore.kernel.org/linux-pm/[email protected]/ Reported-by: Shawn Guo <[email protected]> Reviewed-by: Mario Limonciello (AMD) <[email protected]> Reviewed-by: Jie Zhan <[email protected]> Acked-by: Viresh Kumar <[email protected]> Cc: 6.6+ <[email protected]> # 6.6+ Signed-off-by: Rafael J. Wysocki <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Fix typo in new symbol name, drop redundant type cast from Rust binding ] Tested-by: Shawn Guo <[email protected]> # with cpufreq-dt driver Reviewed-by: Qais Yousef <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent d3f8f8d commit f97aef0

File tree

9 files changed

+14
-10
lines changed

9 files changed

+14
-10
lines changed

drivers/cpufreq/cpufreq-dt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static int cpufreq_init(struct cpufreq_policy *policy)
104104

105105
transition_latency = dev_pm_opp_get_max_transition_latency(cpu_dev);
106106
if (!transition_latency)
107-
transition_latency = CPUFREQ_ETERNAL;
107+
transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
108108

109109
cpumask_copy(policy->cpus, priv->cpus);
110110
policy->driver_data = priv;

drivers/cpufreq/imx6q-cpufreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static int imx6q_cpufreq_probe(struct platform_device *pdev)
442442
}
443443

444444
if (of_property_read_u32(np, "clock-latency", &transition_latency))
445-
transition_latency = CPUFREQ_ETERNAL;
445+
transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
446446

447447
/*
448448
* Calculate the ramp time for max voltage change in the

drivers/cpufreq/mediatek-cpufreq-hw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int mtk_cpufreq_hw_cpu_init(struct cpufreq_policy *policy)
309309

310310
latency = readl_relaxed(data->reg_bases[REG_FREQ_LATENCY]) * 1000;
311311
if (!latency)
312-
latency = CPUFREQ_ETERNAL;
312+
latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
313313

314314
policy->cpuinfo.transition_latency = latency;
315315
policy->fast_switch_possible = true;

drivers/cpufreq/rcpufreq_dt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl cpufreq::Driver for CPUFreqDTDriver {
123123

124124
let mut transition_latency = opp_table.max_transition_latency_ns() as u32;
125125
if transition_latency == 0 {
126-
transition_latency = cpufreq::ETERNAL_LATENCY_NS;
126+
transition_latency = cpufreq::DEFAULT_TRANSITION_LATENCY_NS;
127127
}
128128

129129
policy

drivers/cpufreq/scmi-cpufreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static int scmi_cpufreq_init(struct cpufreq_policy *policy)
294294

295295
latency = perf_ops->transition_latency_get(ph, domain);
296296
if (!latency)
297-
latency = CPUFREQ_ETERNAL;
297+
latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
298298

299299
policy->cpuinfo.transition_latency = latency;
300300

drivers/cpufreq/scpi-cpufreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static int scpi_cpufreq_init(struct cpufreq_policy *policy)
157157

158158
latency = scpi_ops->get_transition_latency(cpu_dev);
159159
if (!latency)
160-
latency = CPUFREQ_ETERNAL;
160+
latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
161161

162162
policy->cpuinfo.transition_latency = latency;
163163

drivers/cpufreq/spear-cpufreq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static int spear_cpufreq_probe(struct platform_device *pdev)
182182

183183
if (of_property_read_u32(np, "clock-latency",
184184
&spear_cpufreq.transition_latency))
185-
spear_cpufreq.transition_latency = CPUFREQ_ETERNAL;
185+
spear_cpufreq.transition_latency = CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
186186

187187
cnt = of_property_count_u32_elems(np, "cpufreq_tbl");
188188
if (cnt <= 0) {

include/linux/cpufreq.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
*/
3333

3434
#define CPUFREQ_ETERNAL (-1)
35+
36+
#define CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS NSEC_PER_MSEC
37+
3538
#define CPUFREQ_NAME_LEN 16
3639
/* Print length for names. Extra 1 space for accommodating '\n' in prints */
3740
#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)

rust/kernel/cpufreq.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ use macros::vtable;
3939
const CPUFREQ_NAME_LEN: usize = bindings::CPUFREQ_NAME_LEN as usize;
4040

4141
/// Default transition latency value in nanoseconds.
42-
pub const ETERNAL_LATENCY_NS: u32 = bindings::CPUFREQ_ETERNAL as u32;
42+
pub const DEFAULT_TRANSITION_LATENCY_NS: u32 =
43+
bindings::CPUFREQ_DEFAULT_TRANSITION_LATENCY_NS;
4344

4445
/// CPU frequency driver flags.
4546
pub mod flags {
@@ -400,13 +401,13 @@ impl TableBuilder {
400401
/// The following example demonstrates how to create a CPU frequency table.
401402
///
402403
/// ```
403-
/// use kernel::cpufreq::{ETERNAL_LATENCY_NS, Policy};
404+
/// use kernel::cpufreq::{DEFAULT_TRANSITION_LATENCY_NS, Policy};
404405
///
405406
/// fn update_policy(policy: &mut Policy) {
406407
/// policy
407408
/// .set_dvfs_possible_from_any_cpu(true)
408409
/// .set_fast_switch_possible(true)
409-
/// .set_transition_latency_ns(ETERNAL_LATENCY_NS);
410+
/// .set_transition_latency_ns(DEFAULT_TRANSITION_LATENCY_NS);
410411
///
411412
/// pr_info!("The policy details are: {:?}\n", (policy.cpu(), policy.cur()));
412413
/// }

0 commit comments

Comments
 (0)