diff mbox

[2/4] cpu: cpufreq: print MHz as float, remove erroneous rounding

Message ID 1400848963-18477-3-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 23, 2014, 12:42 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Print MHz frequencies as floats, like the GHz ranges too.

The original code rounded up the integer values when being divided
down by GHz or Mhz values, but this is wrong for floating point values
so remove this.

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

Comments

Keng-Yu Lin May 26, 2014, 12:29 a.m. UTC | #1
On Fri, May 23, 2014 at 8:42 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Print MHz frequencies as floats, like the GHz ranges too.
>
> The original code rounded up the integer values when being divided
> down by GHz or Mhz values, but this is wrong for floating point values
> so remove this.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/cpu/cpufreq/cpufreq.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index 39d22ae..91e44f9 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -177,11 +177,11 @@ static char *hz_to_human(const uint64_t hz)
>
>         if (hz > 1000000) {
>                 snprintf(buffer, sizeof(buffer), "%6.3f GHz",
> -                       (hz+50000.0) / 1000000);
> +                       (double)hz / 1000000.0);
>                 return buffer;
>         } else if (hz > 1000) {
> -               snprintf(buffer, sizeof(buffer), "%" PRIu64 " MHz",
> -                       (hz+500) / 1000);
> +               snprintf(buffer, sizeof(buffer), "%6.3f MHz",
> +                       (double)hz / 1000.0);
>                 return buffer;
>         } else {
>                 snprintf(buffer, sizeof(buffer), "%" PRIu64 " Hz", hz);
> --
> 2.0.0.rc0
>
>

Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung May 28, 2014, 3:29 a.m. UTC | #2
On 05/23/2014 08:42 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Print MHz frequencies as floats, like the GHz ranges too.
>
> The original code rounded up the integer values when being divided
> down by GHz or Mhz values, but this is wrong for floating point values
> so remove this.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/cpufreq/cpufreq.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index 39d22ae..91e44f9 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -177,11 +177,11 @@ static char *hz_to_human(const uint64_t hz)
>
>   	if (hz > 1000000) {
>   		snprintf(buffer, sizeof(buffer), "%6.3f GHz",
> -			(hz+50000.0) / 1000000);
> +			(double)hz / 1000000.0);
>   		return buffer;
>   	} else if (hz > 1000) {
> -		snprintf(buffer, sizeof(buffer), "%" PRIu64 " MHz",
> -			(hz+500) / 1000);
> +		snprintf(buffer, sizeof(buffer), "%6.3f MHz",
> +			(double)hz / 1000.0);
>   		return buffer;
>   	} else {
>   		snprintf(buffer, sizeof(buffer), "%" PRIu64 " Hz", hz);
>

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
index 39d22ae..91e44f9 100644
--- a/src/cpu/cpufreq/cpufreq.c
+++ b/src/cpu/cpufreq/cpufreq.c
@@ -177,11 +177,11 @@  static char *hz_to_human(const uint64_t hz)
 
 	if (hz > 1000000) {
 		snprintf(buffer, sizeof(buffer), "%6.3f GHz",
-			(hz+50000.0) / 1000000);
+			(double)hz / 1000000.0);
 		return buffer;
 	} else if (hz > 1000) {
-		snprintf(buffer, sizeof(buffer), "%" PRIu64 " MHz",
-			(hz+500) / 1000);
+		snprintf(buffer, sizeof(buffer), "%6.3f MHz",
+			(double)hz / 1000.0);
 		return buffer;
 	} else {
 		snprintf(buffer, sizeof(buffer), "%" PRIu64 " Hz", hz);