Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v3] cpufreq: rcpufreq_dt: implement software boost support
@ 2026-12-03  3:23 Poil Zero
  2026-12-03  4:33 ` Zhongqiu Han
  0 siblings, 1 reply; 2+ messages in thread
From: Poil Zero @ 2026-12-03  3:23 UTC (permalink / raw)
  To: Viresh Kumar, Rafael J. Wysocki; +Cc: linux-pm, rust-for-linux, Zhongqiu Han

rcpufreq_dt advertises boost support but its set_boost() callback returns
success without updating the policy limits. As a result, enabling boost
can leave boost frequencies outside the policy's usable range.

Use cpufreq_boost_set_sw() through a Rust Policy wrapper so the callback
updates the frequency limits and QoS request. Start with driver-level
boost disabled, as cpufreq-dt does.

Signed-off-by: Poil Zero <poilandgginchi@gmail.com>
---
Changes in v3:
- Resend with git send-email. The patch is unchanged from v2.

Changes in v2:
- Resend to fix line wrapping in v1. No code changes.

 drivers/cpufreq/rcpufreq_dt.rs |  8 +++++---
 rust/kernel/cpufreq.rs         | 15 ++++++++++++++-
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
index 2b1f18b..e0e1814 100644
--- a/drivers/cpufreq/rcpufreq_dt.rs
+++ b/drivers/cpufreq/rcpufreq_dt.rs
@@ -60,7 +60,9 @@ impl opp::ConfigOps for CPUFreqDTDriver {}
 impl cpufreq::Driver for CPUFreqDTDriver {
     const NAME: &'static CStr = c"cpufreq-dt";
     const FLAGS: u16 = cpufreq::flags::NEED_INITIAL_FREQ_CHECK | cpufreq::flags::IS_COOLING_DEV;
-    const BOOST_ENABLED: bool = true;
+    // Keep the initial driver level boost state disabled and let the userspace enable it if
+    // required, like the C driver does.
+    const BOOST_ENABLED: bool = false;
 
     type PData = Arc<CPUFreqDTDevice>;
 
@@ -190,8 +192,8 @@ impl cpufreq::Driver for CPUFreqDTDriver {
         policy.generic_get()
     }
 
-    fn set_boost(_policy: &mut cpufreq::Policy, _state: i32) -> Result {
-        Ok(())
+    fn set_boost(policy: &mut cpufreq::Policy, state: i32) -> Result {
+        policy.set_boost_sw(state)
     }
 
     fn register_em(policy: &mut cpufreq::Policy) {
diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
index f316711..ad01387 100644
--- a/rust/kernel/cpufreq.rs
+++ b/rust/kernel/cpufreq.rs
@@ -544,6 +544,16 @@ impl Policy {
         Ok(unsafe { bindings::cpufreq_generic_get(u32::from(self.cpu())) })
     }
 
+    /// Provides a wrapper to the generic software boost routine.
+    ///
+    /// This recomputes the policy's `cpuinfo` limits from its frequency table, taking the
+    /// current driver and per-policy boost state into account.
+    #[inline]
+    pub fn set_boost_sw(&mut self, state: i32) -> Result {
+        // SAFETY: By the type invariant, the pointer stored in `self` is valid.
+        to_result(unsafe { bindings::cpufreq_boost_set_sw(self.as_mut_ref(), state) })
+    }
+
     /// Provides a wrapper to the register with energy model using the OPP core.
     #[cfg(CONFIG_PM_OPP)]
     #[inline]
@@ -741,7 +751,10 @@ pub trait Driver {
     /// Driver's flags.
     const FLAGS: u16;
 
-    /// Boost support.
+    /// Initial state of the driver level boost support.
+    ///
+    /// This maps to `cpufreq_driver.boost_enabled`. Boost support itself is advertised to the
+    /// core by implementing [`Driver::set_boost`].
     const BOOST_ENABLED: bool;
 
     /// Policy specific data.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] cpufreq: rcpufreq_dt: implement software boost support
  2026-12-03  3:23 [PATCH v3] cpufreq: rcpufreq_dt: implement software boost support Poil Zero
@ 2026-12-03  4:33 ` Zhongqiu Han
  0 siblings, 0 replies; 2+ messages in thread
From: Zhongqiu Han @ 2026-12-03  4:33 UTC (permalink / raw)
  To: Poil Zero, Viresh Kumar, Rafael J. Wysocki
  Cc: linux-pm, rust-for-linux, Zhongqiu Han

On 12/3/2026 11:23 AM, Poil Zero wrote:
> rcpufreq_dt advertises boost support but its set_boost() callback returns
> success without updating the policy limits. As a result, enabling boost
> can leave boost frequencies outside the policy's usable range.
> 
> Use cpufreq_boost_set_sw() through a Rust Policy wrapper so the callback
> updates the frequency limits and QoS request. Start with driver-level
> boost disabled, as cpufreq-dt does.
> 
> Signed-off-by: Poil Zero <poilandgginchi@gmail.com>

The change looks correct to me, and I tested it on QEMU:

Reviewed-by: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>

For reference, the no-op set_boost() and BOOST_ENABLED = true were
introduced by 06149d8f2216 ("cpufreq: Add Rust-based cpufreq-dt
driver"), in case a Fixes: tag is wanted. No respin needed for now.

> ---
> Changes in v3:
> - Resend with git send-email. The patch is unchanged from v2.
> 
> Changes in v2:
> - Resend to fix line wrapping in v1. No code changes.
> 
>   drivers/cpufreq/rcpufreq_dt.rs |  8 +++++---
>   rust/kernel/cpufreq.rs         | 15 ++++++++++++++-
>   2 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/cpufreq/rcpufreq_dt.rs b/drivers/cpufreq/rcpufreq_dt.rs
> index 2b1f18b..e0e1814 100644
> --- a/drivers/cpufreq/rcpufreq_dt.rs
> +++ b/drivers/cpufreq/rcpufreq_dt.rs
> @@ -60,7 +60,9 @@ impl opp::ConfigOps for CPUFreqDTDriver {}
>   impl cpufreq::Driver for CPUFreqDTDriver {
>       const NAME: &'static CStr = c"cpufreq-dt";
>       const FLAGS: u16 = cpufreq::flags::NEED_INITIAL_FREQ_CHECK | cpufreq::flags::IS_COOLING_DEV;
> -    const BOOST_ENABLED: bool = true;
> +    // Keep the initial driver level boost state disabled and let the userspace enable it if
> +    // required, like the C driver does.
> +    const BOOST_ENABLED: bool = false;
>   
>       type PData = Arc<CPUFreqDTDevice>;
>   
> @@ -190,8 +192,8 @@ impl cpufreq::Driver for CPUFreqDTDriver {
>           policy.generic_get()
>       }
>   
> -    fn set_boost(_policy: &mut cpufreq::Policy, _state: i32) -> Result {
> -        Ok(())
> +    fn set_boost(policy: &mut cpufreq::Policy, state: i32) -> Result {
> +        policy.set_boost_sw(state)
>       }
>   
>       fn register_em(policy: &mut cpufreq::Policy) {
> diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs
> index f316711..ad01387 100644
> --- a/rust/kernel/cpufreq.rs
> +++ b/rust/kernel/cpufreq.rs
> @@ -544,6 +544,16 @@ impl Policy {
>           Ok(unsafe { bindings::cpufreq_generic_get(u32::from(self.cpu())) })
>       }
>   
> +    /// Provides a wrapper to the generic software boost routine.
> +    ///
> +    /// This recomputes the policy's `cpuinfo` limits from its frequency table, taking the
> +    /// current driver and per-policy boost state into account.
> +    #[inline]
> +    pub fn set_boost_sw(&mut self, state: i32) -> Result {
> +        // SAFETY: By the type invariant, the pointer stored in `self` is valid.
> +        to_result(unsafe { bindings::cpufreq_boost_set_sw(self.as_mut_ref(), state) })
> +    }
> +
>       /// Provides a wrapper to the register with energy model using the OPP core.
>       #[cfg(CONFIG_PM_OPP)]
>       #[inline]
> @@ -741,7 +751,10 @@ pub trait Driver {
>       /// Driver's flags.
>       const FLAGS: u16;
>   
> -    /// Boost support.
> +    /// Initial state of the driver level boost support.
> +    ///
> +    /// This maps to `cpufreq_driver.boost_enabled`. Boost support itself is advertised to the
> +    /// core by implementing [`Driver::set_boost`].
>       const BOOST_ENABLED: bool;
>   
>       /// Policy specific data.


-- 
Thx and BRs,
Zhongqiu Han

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-03  4:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03  3:23 [PATCH v3] cpufreq: rcpufreq_dt: implement software boost support Poil Zero
2026-12-03  4:33 ` Zhongqiu Han

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox