cpufreq: conservative: Ensure requested_freq is greater than min frequency

Message ID 20230912060957.2516790-1-liaochang1@huawei.com
State New
Headers
Series cpufreq: conservative: Ensure requested_freq is greater than min frequency |

Commit Message

Liao Chang Sept. 12, 2023, 6:09 a.m. UTC
  The governor ensures that the requested frequency is greater than the
minimum frequency when the condition for decreasing frequency is
satisfied. This is done by either reducing the frequency step from the
current frequency if the current frequency is greater than the sum of
the frequency step and the minimum frequency, or setting the frequency
to the minimum one otherwise.

Signed-off-by: Liao Chang <liaochang1@huawei.com>
---
 drivers/cpufreq/cpufreq_conservative.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Viresh Kumar Oct. 5, 2023, 10:57 a.m. UTC | #1
On 12-09-23, 06:09, Liao Chang wrote:
> The governor ensures that the requested frequency is greater than the
> minimum frequency when the condition for decreasing frequency is
> satisfied. This is done by either reducing the frequency step from the
> current frequency if the current frequency is greater than the sum of
> the frequency step and the minimum frequency, or setting the frequency
> to the minimum one otherwise.
> 
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
>  drivers/cpufreq/cpufreq_conservative.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
> index 56500b25d77c..54e09242b2e2 100644
> --- a/drivers/cpufreq/cpufreq_conservative.c
> +++ b/drivers/cpufreq/cpufreq_conservative.c
> @@ -130,7 +130,7 @@ static unsigned int cs_dbs_update(struct cpufreq_policy *policy)
>  		if (requested_freq == policy->min)
>  			goto out;
>  
> -		if (requested_freq > freq_step)
> +		if (requested_freq > policy->min + freq_step)
>  			requested_freq -= freq_step;
>  		else
>  			requested_freq = policy->min;

I think all we want to ensure here is that we don't end up getting a
negative number (since requested_freq is unsigned int, it will end up
being a very large freq). __cpufreq_driver_target() will eventually
set the freq to policy->min only as we are using CPUFREQ_RELATION_LE
here.
  

Patch

diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 56500b25d77c..54e09242b2e2 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -130,7 +130,7 @@  static unsigned int cs_dbs_update(struct cpufreq_policy *policy)
 		if (requested_freq == policy->min)
 			goto out;
 
-		if (requested_freq > freq_step)
+		if (requested_freq > policy->min + freq_step)
 			requested_freq -= freq_step;
 		else
 			requested_freq = policy->min;