diff mbox

[1/2] cpufreq, intel_pstate, Fix limits->max_policy_pct rounding error

Message ID 1448063277-12446-2-git-send-email-prarit@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Rafael Wysocki
Headers show

Commit Message

Prarit Bhargava Nov. 20, 2015, 11:47 p.m. UTC
I have a Intel (6,63) processor with a "marketing" frequency (from
/proc/cpuinfo) of 2100MHz, and a max turbo frequency of 2600MHz.  I
can execute

cpupower frequency-set -g powersave --min 1200MHz --max 2100MHz

and the max_freq_pct is set to 80.  When adding load to the system I noticed
that the cpu frequency only reached 2000MHZ and not 2100MHz as expected.

This is because limits->max_policy_pct is calculated as 2100 * 100 /2600 = 80.7
and is rounded down to 80 when it should be rounded up to 81.  This patch
adds a DIV_ROUND_UP() which will return the correct value.

Cc: Srinivas Pandruvada <srinivas.pandruvada@intel.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Alexandra Yates <alexandra.yates@intel.com>
Cc: Kristen Carlson Accardi <kristen@linux.intel.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: linux-pm@vger.kernel.org
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
---
 drivers/cpufreq/intel_pstate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Pandruvada, Srinivas Nov. 21, 2015, 12:04 a.m. UTC | #1
On Fri, 2015-11-20 at 18:47 -0500, Prarit Bhargava wrote:
> I have a Intel (6,63) processor with a "marketing" frequency (from

> /proc/cpuinfo) of 2100MHz, and a max turbo frequency of 2600MHz.  I

> can execute

> 

> cpupower frequency-set -g powersave --min 1200MHz --max 2100MHz

> 

> and the max_freq_pct is set to 80.  When adding load to the system I noticed

> that the cpu frequency only reached 2000MHZ and not 2100MHz as expected.

> 

> This is because limits->max_policy_pct is calculated as 2100 * 100 /2600 = 80.7

> and is rounded down to 80 when it should be rounded up to 81.  This patch

> adds a DIV_ROUND_UP() which will return the correct value.

> 

> Cc: Srinivas Pandruvada <srinivas.pandruvada@intel.com>

> Cc: Len Brown <len.brown@intel.com>

> Cc: Alexandra Yates <alexandra.yates@intel.com>

> Cc: Kristen Carlson Accardi <kristen@linux.intel.com>

> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>

> Cc: Viresh Kumar <viresh.kumar@linaro.org>

> Cc: linux-pm@vger.kernel.org

> Signed-off-by: Prarit Bhargava <prarit@redhat.com>

Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

> ---

>  drivers/cpufreq/intel_pstate.c | 3 ++-

>  1 file changed, 2 insertions(+), 1 deletion(-)

> 

> diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c

> index 001a532..eb75053 100644

> --- a/drivers/cpufreq/intel_pstate.c

> +++ b/drivers/cpufreq/intel_pstate.c

> @@ -1108,7 +1108,8 @@ static int intel_pstate_set_policy(struct cpufreq_policy *policy)

>  	limits = &powersave_limits;

>  	limits->min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;

>  	limits->min_policy_pct = clamp_t(int, limits->min_policy_pct, 0 , 100);

> -	limits->max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;

> +	limits->max_policy_pct = DIV_ROUND_UP(policy->max * 100,

> +					      policy->cpuinfo.max_freq);

>  	limits->max_policy_pct = clamp_t(int, limits->max_policy_pct, 0 , 100);

>  

>  	/* Normalize user input to [min_policy_pct, max_policy_pct] */
diff mbox

Patch

diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 001a532..eb75053 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -1108,7 +1108,8 @@  static int intel_pstate_set_policy(struct cpufreq_policy *policy)
 	limits = &powersave_limits;
 	limits->min_policy_pct = (policy->min * 100) / policy->cpuinfo.max_freq;
 	limits->min_policy_pct = clamp_t(int, limits->min_policy_pct, 0 , 100);
-	limits->max_policy_pct = (policy->max * 100) / policy->cpuinfo.max_freq;
+	limits->max_policy_pct = DIV_ROUND_UP(policy->max * 100,
+					      policy->cpuinfo.max_freq);
 	limits->max_policy_pct = clamp_t(int, limits->max_policy_pct, 0 , 100);
 
 	/* Normalize user input to [min_policy_pct, max_policy_pct] */