Re: [RFC] Printing numbers in SI units
From: Petr Mladek
Date: Mon May 06 2024 - 11:55:27 EST
On Fri 2024-04-26 17:27:08, Geert Uytterhoeven wrote:
> Hi Rasmus,
>
> On Wed, Jan 24, 2024 at 11:43 PM Rasmus Villemoes
> <linux@xxxxxxxxxxxxxxxxxx> wrote:
> > On 24/01/2024 19.58, Matthew Wilcox wrote:
> > > I was looking at hugetlbfs and it has several snippets of code like
> > > this:
> > >
> > > string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32);
> > > pr_warn("HugeTLB: allocating %u of page size %s failed node%d. Only allocated %lu hugepages.\n",
> > > h->max_huge_pages_node[nid], buf, nid, i);
> > >
> > > That's not terribly ergonomic, so I wondered if I could do better.
> > > Unfortunately, I decided to do it using the SPECIAL flag which GCC
> > > warns about. But I've written the code now, so I'm sending it out in
> > > case anybody has a better idea for how to incorporate it.
> >
> > Well, something that gcc will warn about with Wformat isn't gonna fly,
> > obviously. But my man page also mentions ' as a possible flag for d
> > conversions:
> >
> > ' For decimal conversion (i, d, u, f, F, g, G) the output is
> > to be grouped with thousands'
> > grouping characters if the locale information indicates any.
>
> > Obviously, our printf wouldn't implement that, [...]
>
> Why not? ;-)
>
> Old Gmail-white-space-damaged patch below, which I wrote when I got
> fed up with meticulously counting zeros in GHz-range clock
> frequencies...
:-)
> Author: Geert Uytterhoeven <geert+renesas@xxxxxxxxx>
> Date: Thu Aug 11 13:52:46 2016 +0200
>
> lib/vsprintf.c: Add support for thousands' grouping
>
> Use an underscore as the grouping character.
>
> TODO:
> - Documentation
> - Self test
> - Do we want to use this in /sys/kernel/debug/clk/clk_summary ?
> RFC patch, compatibility was already broken by commit
> e55a839a7a1c561b ("clk: add clock protection mechanism to clk
> core")
Yeah, it should have some users if we want to maintain it.
Best Regards,
Petr