[PATCH 7/8] cpu: cpufreq: make HzToHuman() more efficient

Colin King colin.king at canonical.com
Mon Jul 23 13:02:57 UTC 2012


From: Colin Ian King <colin.king at canonical.com>

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/cpu/cpufreq/cpufreq.c |   22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
index f4a461b..8cd4da0 100644
--- a/src/cpu/cpufreq/cpufreq.c
+++ b/src/cpu/cpufreq/cpufreq.c
@@ -216,23 +216,23 @@ static unsigned long get_performance_repeat(fwts_framework *fw,
 
 static char *HzToHuman(unsigned long hz)
 {
-	static char buffer[1024];
+	static char buffer[32];
 	unsigned long long Hz;
 
 	Hz = hz;
 
-	/* default: just put the Number in */
-	snprintf(buffer, sizeof(buffer), "%9lli", Hz);
-
-	if (Hz > 1000)
-		snprintf(buffer, sizeof(buffer), "%6lli Mhz",
-			(Hz+500) / 1000);
-
-	if (Hz > 1500000)
+	if (Hz > 1500000) {
 		snprintf(buffer, sizeof(buffer), "%6.2f Ghz",
 			(Hz+50000.0) / 1000000);
-
-	return buffer;
+		return buffer;
+	} else if (Hz > 1000) {
+		snprintf(buffer, sizeof(buffer), "%6lli Mhz",
+			(Hz+500) / 1000);
+		return buffer;
+	} else {
+		snprintf(buffer, sizeof(buffer), "%9lli", Hz);
+		return buffer;
+	}
 }
 
 
-- 
1.7.10.4




More information about the fwts-devel mailing list