[PATCH 7/8] cpu: cpufreq: make HzToHuman() more efficient
Keng-Yu Lin
kengyu at canonical.com
Wed Jul 25 07:27:24 UTC 2012
On Mon, Jul 23, 2012 at 9:02 PM, Colin King <colin.king at canonical.com> wrote:
> 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
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>
More information about the fwts-devel
mailing list