lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1478668678-21556-1-git-send-email-akshay.adiga@linux.vnet.ibm.com>
Date:   Wed,  9 Nov 2016 10:47:58 +0530
From:   Akshay Adiga <akshay.adiga@...ux.vnet.ibm.com>
To:     trenn@...e.com, rafael.j.wysocki@...el.com, jtanenba@...hat.com,
        linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Akshay Adiga <akshay.adiga@...ux.vnet.ibm.com>
Subject: [PATCH] cpupower: Warn if values are truncated in frequency-info

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@...ux.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ