All of lore.kernel.org
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
Cc: Prarit Bhargava <prarit@redhat.com>,
	Srinivas Pandruvada <srinivas.pandruvada@intel.com>,
	Len Brown <len.brown@intel.com>,
	Alexandra Yates <alexandra.yates@intel.com>,
	Kristen Carlson Accardi <kristen@linux.intel.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Viresh Kumar <viresh.kumar@linaro.org>,
	linux-pm@vger.kernel.org
Subject: [PATCH 1/2] cpufreq, intel_pstate, Fix limits->max_policy_pct rounding error
Date: Fri, 20 Nov 2015 18:47:56 -0500	[thread overview]
Message-ID: <1448063277-12446-2-git-send-email-prarit@redhat.com> (raw)
In-Reply-To: <1448063277-12446-1-git-send-email-prarit@redhat.com>

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(-)

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] */
-- 
1.8.3.1


  reply	other threads:[~2015-11-20 23:48 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-20 23:47 [PATCH 0/2 v3] cpufreq, intel_pstate, Fix rounding errors Prarit Bhargava
2015-11-20 23:47 ` Prarit Bhargava [this message]
2015-11-21  0:04   ` [PATCH 1/2] cpufreq, intel_pstate, Fix limits->max_policy_pct rounding error Pandruvada, Srinivas
2015-11-20 23:47 ` [PATCH 2/2] cpufreq, intel_pstate, fix limits->max_perf " Prarit Bhargava
2015-11-21  0:04   ` Pandruvada, Srinivas
2015-11-21  2:31 ` [PATCH 0/2 v3] cpufreq, intel_pstate, Fix rounding errors Viresh Kumar
2015-11-23 22:46   ` Rafael J. Wysocki
  -- strict thread matches above, loose matches on Subject: below --
2015-11-20 12:32 [PATCH 0/2 v2] " Prarit Bhargava
2015-11-20 12:32 ` [PATCH 1/2] cpufreq, intel_pstate, Fix limits->max_policy_pct rounding error Prarit Bhargava
2015-11-20 13:18   ` Viresh Kumar
2015-11-20 15:10     ` Prarit Bhargava
2015-11-20 15:19       ` Viresh Kumar
2015-11-20 15:43         ` Prarit Bhargava
2015-11-20 20:02           ` Pandruvada, Srinivas
2015-11-20 20:02             ` Pandruvada, Srinivas
2015-11-20 23:47             ` Prarit Bhargava
2015-11-20 23:57               ` Pandruvada, Srinivas
2015-11-20 23:57                 ` Pandruvada, Srinivas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1448063277-12446-2-git-send-email-prarit@redhat.com \
    --to=prarit@redhat.com \
    --cc=alexandra.yates@intel.com \
    --cc=kristen@linux.intel.com \
    --cc=len.brown@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=srinivas.pandruvada@intel.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.