All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 06/20] Add print_freq() to display frequencies nicely
Date: Tue, 28 Apr 2015 12:13:12 +0800	[thread overview]
Message-ID: <CAEUhbmW8P7UsQMdiGqwP=1TULYxwx8oyTGCknqQoX-=3uLh-ZQ@mail.gmail.com> (raw)
In-Reply-To: <1430174911-27538-7-git-send-email-sjg@chromium.org>

Hi Simon,

On Tue, Apr 28, 2015 at 6:48 AM, Simon Glass <sjg@chromium.org> wrote:
> Add a function similar to print_size() that works for frequencies. It can
> handle from Hz to GHz.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  include/display_options.h | 11 +++++++++++
>  lib/display_options.c     | 41 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 52 insertions(+)
>
> diff --git a/include/display_options.h b/include/display_options.h
> index c222ea2..10b4641 100644
> --- a/include/display_options.h
> +++ b/include/display_options.h
> @@ -23,6 +23,17 @@
>  void print_size(uint64_t size, const char *suffix);
>
>  /**
> + * print_freq() - Print a frequency with a suffix
> + *
> + * print frequencies as "x.xx GHz", "xxx KHz", etc as needed; allow for

print->Print

> + * optional trailing string (like "\n")
> + *
> + * @freq:      Frequency to print in Hz
> + * @suffix     String to print after the frequency
> + */
> +void print_freq(uint64_t freq, const char *suffix);
> +
> +/**
>   * print_buffer() - Print data buffer in hex and ascii form
>   *
>   * Data reads are buffered so that each memory address is only read once.
> diff --git a/lib/display_options.c b/lib/display_options.c
> index 3f32bcd..cf6f50b 100644
> --- a/lib/display_options.c
> +++ b/lib/display_options.c
> @@ -7,6 +7,7 @@
>
>  #include <config.h>
>  #include <common.h>
> +#include <div64.h>
>  #include <inttypes.h>
>  #include <version.h>
>  #include <linux/ctype.h>
> @@ -22,6 +23,46 @@ int display_options (void)
>         return 0;
>  }
>
> +#ifndef CONFIG_SH
> +/* SH gcc 4.6 toolchain produces "undefined reference to '__umoddi3' here */
> +void print_freq(uint64_t freq, const char *s)
> +{
> +       unsigned long m = 0, n;
> +       uint32_t f;
> +       static const char names[] = {'G', 'M', 'K'};
> +       unsigned long d = 1e9;
> +       char c = 0;
> +       unsigned int i;
> +
> +       for (i = 0; i < ARRAY_SIZE(names); i++, d /= 10) {

I think this is broken. Should be d /= 1000;

> +               if (freq >= d) {
> +                       c = names[i];
> +                       break;
> +               }
> +       }
> +
> +       if (!c) {
> +               printf("%" PRIu64 " Hz%s", freq, s);
> +               return;
> +       }
> +
> +       f = do_div(freq, d);
> +       n = freq;
> +
> +       /* If there's a remainder, show the first few digits */
> +       if (f) {
> +               m = f % 1000;

This is broken too. Should be m = f % d;

> +               while (!(m % 10))

And I think you need add a variable to control how many first few
digits you want to show in this loop.

> +                       m /= 10;
> +       }
> +
> +       printf("%lu", n);
> +       if (m)
> +               printf(".%ld", m);
> +       printf(" %cHz%s", c, s);
> +}
> +#endif
> +
>  void print_size(uint64_t size, const char *s)
>  {
>         unsigned long m = 0, n;
> --

Regards,
Bin

  reply	other threads:[~2015-04-28  4:13 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27 22:48 [U-Boot] [PATCH 00/20] x86: Add CPU uclass and multi-core support for Minnowboard MAX Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 01/20] Fix comment nits in board_f.c Simon Glass
2015-04-28  1:54   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 02/20] dm: core: Add a function to bind a driver for a device tree node Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 03/20] x86: Remove unwanted MMC debugging Simon Glass
2015-04-28  1:59   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 04/20] x86: Disable -Werror Simon Glass
2015-04-28  1:59   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 05/20] Move display_options functions to their own header Simon Glass
2015-04-28  2:10   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 06/20] Add print_freq() to display frequencies nicely Simon Glass
2015-04-28  4:13   ` Bin Meng [this message]
2015-04-27 22:48 ` [U-Boot] [PATCH 07/20] x86: Add support for the Simple Firmware Interface (SFI) Simon Glass
2015-04-28  6:51   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 08/20] dm: Implement a CPU uclass Simon Glass
2015-04-28  7:24   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 09/20] Add a 'cpu' command to print CPU information Simon Glass
2015-04-28  7:34   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 10/20] x86: Add atomic operations Simon Glass
2015-04-28  7:38   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 11/20] x86: Add defines for fixed MTRRs Simon Glass
2015-04-28  7:45   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 12/20] x86: Add an mfence macro Simon Glass
2015-04-28  7:48   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 13/20] x86: Store the GDT pointer in global_data Simon Glass
2015-04-28  7:55   ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 14/20] x86: Provide access to the IDT Simon Glass
2015-04-28  8:16   ` Bin Meng
2015-04-29  2:08     ` Simon Glass
2015-04-29  5:23       ` Bin Meng
2015-04-27 22:48 ` [U-Boot] [PATCH 15/20] x86: Add multi-processor init Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 16/20] x86: Add functions to set and clear bits on MSRs Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 17/20] x86: Allow CPUs to be set up after relocation Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 18/20] x86: Add a CPU driver for baytrail Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 19/20] x86: Tidy up the LAPIC init code Simon Glass
2015-04-27 22:48 ` [U-Boot] [PATCH 20/20] x86: Enable multi-core init for Minnowboard MAX Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEUhbmW8P7UsQMdiGqwP=1TULYxwx8oyTGCknqQoX-=3uLh-ZQ@mail.gmail.com' \
    --to=bmeng.cn@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.