From patchwork Mon Jul 23 13:02:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 172666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id BE6FF2C0354 for ; Mon, 23 Jul 2012 23:03:05 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1StIHw-0001A6-HC for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 13:03:04 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1StIHt-00019a-O0 for fwts-devel@lists.ubuntu.com; Mon, 23 Jul 2012 13:03:01 +0000 Received: from cpc37-craw6-2-0-cust191.16-3.cable.virginmedia.com ([92.239.39.192] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1StIHt-0005pR-Ld for fwts-devel@lists.ubuntu.com; Mon, 23 Jul 2012 13:03:01 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 7/8] cpu: cpufreq: make HzToHuman() more efficient Date: Mon, 23 Jul 2012 14:02:57 +0100 Message-Id: <1343048578-13332-8-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343048578-13332-1-git-send-email-colin.king@canonical.com> References: <1343048578-13332-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu --- 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; + } }