All of lore.kernel.org
 help / color / mirror / Atom feed
From: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
To: trenn@suse.com, rafael.j.wysocki@intel.com, jtanenba@redhat.com,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
Subject: [PATCH] cpupower: Warn if values are truncated in frequency-info
Date: Wed,  9 Nov 2016 10:47:58 +0530	[thread overview]
Message-ID: <1478668678-21556-1-git-send-email-akshay.adiga@linux.vnet.ibm.com> (raw)

frequency-info currently rounds the frequnecy values to 2 decimal places
while printing "available frequency steps". Hence frequencies with 3rd
decimal place being greater than 5 will be rounded to next higher number
like 2.227GHz will be rounded to 2.23Ghz. On setting this frequency,
using "cpupower frequency-set -f <freq>" ,if the value does not match,
then it will set to the next lowest frequency greater than provided
frequency value (according to the userspace governor).

Hence adding a warning if there are any cases where the displayed
frequency cannot be used directly to set a perticular frequency, and
insist the user to use the "-n" option.

Simple usecase where it give counter intuitive results :
bash# cpupower frequency-info
...
  available frequency steps: 2.43 GHz, 2.39 GHz, 2.36 GHz, 2.33 GHz,
2.29 GHz, 2.26 GHz, 2.23 GHz, 2.19 GHz, 2.16 GHz, 2.13 GHz

bash# cpupower frequency-info -n
...
available frequency steps: 2.427000 GHz, 2.394000 GHz, 2.360000 GHz,
2.327000 GHz, 2.294000 GHz, 2.261000 GHz, 2.227000 GHz, 2.194000 GHz,
2.161000 GHz, 2.128000 GHz

bash# cpupower frequency-set -f 2.23Ghz

bash# cpupower frequency-info
...
 current CPU frequency: 2.26 GHz (asserted by call to hardware)

Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
---
 tools/power/cpupower/utils/cpufreq-info.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c
index 590d12a..4f13b06 100644
--- a/tools/power/cpupower/utils/cpufreq-info.c
+++ b/tools/power/cpupower/utils/cpufreq-info.c
@@ -85,6 +85,7 @@ static void proc_cpufreq_output(void)
 }
 
 static int no_rounding;
+static int freq_info_truncated;
 static void print_speed(unsigned long speed)
 {
 	unsigned long tmp;
@@ -103,8 +104,10 @@ static void print_speed(unsigned long speed)
 	} else {
 		if (speed > 1000000) {
 			tmp = speed%10000;
-			if (tmp >= 5000)
+			if (tmp >= 5000) {
+				freq_info_truncated = 1;
 				speed += 10000;
+			}
 			printf("%u.%02u GHz", ((unsigned int) speed/1000000),
 				((unsigned int) (speed%1000000)/10000));
 		} else if (speed > 100000) {
@@ -243,6 +246,7 @@ static int get_boost_mode(unsigned int cpu)
 			printf(_("    %.0f MHz max turbo 1 active cores\n"),
 			       ratio * bclk);
 	}
+
 	return 0;
 }
 
@@ -641,5 +645,12 @@ int cmd_freq_info(int argc, char **argv)
 			return ret;
 		printf("\n");
 	}
+
+	if (freq_info_truncated) {
+		printf("  Warning! Frequency values shown are rounded off\n");
+		printf("  To set frequency use frequency values provided\n");
+		printf("  by \"cpupower frequency-info -n \"\n");
+	}
+
 	return ret;
 }
-- 
2.5.5

                 reply	other threads:[~2016-11-09  5:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1478668678-21556-1-git-send-email-akshay.adiga@linux.vnet.ibm.com \
    --to=akshay.adiga@linux.vnet.ibm.com \
    --cc=jtanenba@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=trenn@suse.com \
    /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.