* [PATCH v2 1/4] lib/string_helpers: export string_units_{2,10} for others
@ 2016-01-21 15:22 Andy Shevchenko
[not found] ` <1453389752-68175-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Andy Shevchenko @ 2016-01-21 15:22 UTC (permalink / raw)
To: Matt Fleming, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
linux-efi, Rasmus Villemoes, Andrew Morton, linux-kernel
Cc: Andy Shevchenko
There is one user coming which would like to use those string arrays. It might
be useful for any other user in the future.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/string_helpers.h | 6 ++++++
lib/string_helpers.c | 21 ++++++++++++---------
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/include/linux/string_helpers.h b/include/linux/string_helpers.h
index dabe643..a55c9cc 100644
--- a/include/linux/string_helpers.h
+++ b/include/linux/string_helpers.h
@@ -10,6 +10,12 @@ enum string_size_units {
STRING_UNITS_2, /* use binary powers of 2^10 */
};
+#define STRING_UNITS_10_NUM 9
+#define STRING_UNITS_2_NUM 9
+
+extern const char *const string_units_10[STRING_UNITS_10_NUM];
+extern const char *const string_units_2[STRING_UNITS_2_NUM];
+
void string_get_size(u64 size, u64 blk_size, enum string_size_units units,
char *buf, int len);
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 5939f63..7ee4644 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -13,6 +13,15 @@
#include <linux/string.h>
#include <linux/string_helpers.h>
+const char * const string_units_10[STRING_UNITS_10_NUM] = {
+ "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB",
+};
+EXPORT_SYMBOL(string_units_10);
+const char * const string_units_2[STRING_UNITS_2_NUM] = {
+ "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB",
+};
+EXPORT_SYMBOL(string_units_2);
+
/**
* string_get_size - get the size in the specified units
* @size: The size to be converted in blocks
@@ -29,15 +38,9 @@
void string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
char *buf, int len)
{
- static const char *const units_10[] = {
- "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"
- };
- static const char *const units_2[] = {
- "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"
- };
static const char *const *const units_str[] = {
- [STRING_UNITS_10] = units_10,
- [STRING_UNITS_2] = units_2,
+ [STRING_UNITS_10] = string_units_10,
+ [STRING_UNITS_2] = string_units_2,
};
static const unsigned int divisor[] = {
[STRING_UNITS_10] = 1000,
@@ -92,7 +95,7 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
}
out:
- if (i >= ARRAY_SIZE(units_2))
+ if (i >= STRING_UNITS_2_NUM)
unit = "UNK";
else
unit = units_str[units][i];
--
2.7.0.rc3
^ permalink raw reply related [flat|nested] 10+ messages in thread[parent not found: <1453389752-68175-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* [PATCH v2 2/4] lib/string_helpers: fix indentation in few places
[not found] ` <1453389752-68175-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2016-01-21 15:22 ` Andy Shevchenko
2016-01-23 5:13 ` [PATCH v2 1/4] lib/string_helpers: export string_units_{2,10} for others James Bottomley
1 sibling, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2016-01-21 15:22 UTC (permalink / raw)
To: Matt Fleming, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
linux-efi-u79uwXL29TY76Z2rM5mHXA, Rasmus Villemoes, Andrew Morton,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
Cc: Andy Shevchenko
Fix the indentation of label and put snprintf() to one line.
There is no functional change.
Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
lib/string_helpers.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/string_helpers.c b/lib/string_helpers.c
index 7ee4644..51fcea2 100644
--- a/lib/string_helpers.c
+++ b/lib/string_helpers.c
@@ -94,14 +94,13 @@ void string_get_size(u64 size, u64 blk_size, const enum string_size_units units,
tmp[j+1] = '\0';
}
- out:
+out:
if (i >= STRING_UNITS_2_NUM)
unit = "UNK";
else
unit = units_str[units][i];
- snprintf(buf, len, "%u%s %s", (u32)size,
- tmp, unit);
+ snprintf(buf, len, "%u%s %s", (u32)size, tmp, unit);
}
EXPORT_SYMBOL(string_get_size);
--
2.7.0.rc3
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v2 1/4] lib/string_helpers: export string_units_{2,10} for others
[not found] ` <1453389752-68175-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-01-21 15:22 ` [PATCH v2 2/4] lib/string_helpers: fix indentation in few places Andy Shevchenko
@ 2016-01-23 5:13 ` James Bottomley
[not found] ` <1453525999.2339.56.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
1 sibling, 1 reply; 10+ messages in thread
From: James Bottomley @ 2016-01-23 5:13 UTC (permalink / raw)
To: Andy Shevchenko, Matt Fleming, Thomas Gleixner, Ingo Molnar,
H. Peter Anvin, linux-efi-u79uwXL29TY76Z2rM5mHXA,
Rasmus Villemoes, Andrew Morton,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
On Thu, 2016-01-21 at 17:22 +0200, Andy Shevchenko wrote:
> There is one user coming which would like to use those string arrays.
> It might
> be useful for any other user in the future.
Well, let's not do it until we have an actual consumer because that
will help us get the interface correct.
> Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> ---
> include/linux/string_helpers.h | 6 ++++++
> lib/string_helpers.c | 21 ++++++++++++---------
> 2 files changed, 18 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/string_helpers.h
> b/include/linux/string_helpers.h
> index dabe643..a55c9cc 100644
> --- a/include/linux/string_helpers.h
> +++ b/include/linux/string_helpers.h
> @@ -10,6 +10,12 @@ enum string_size_units {
> STRING_UNITS_2, /* use binary powers of 2^10
> */
> };
>
> +#define STRING_UNITS_10_NUM 9
> +#define STRING_UNITS_2_NUM 9
> +
> +extern const char *const string_units_10[STRING_UNITS_10_NUM];
> +extern const char *const string_units_2[STRING_UNITS_2_NUM];
> +
> void string_get_size(u64 size, u64 blk_size, enum string_size_units
> units,
> char *buf, int len);
>
> diff --git a/lib/string_helpers.c b/lib/string_helpers.c
> index 5939f63..7ee4644 100644
> --- a/lib/string_helpers.c
> +++ b/lib/string_helpers.c
> @@ -13,6 +13,15 @@
> #include <linux/string.h>
> #include <linux/string_helpers.h>
>
> +const char * const string_units_10[STRING_UNITS_10_NUM] = {
> + "B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB",
> +};
> +EXPORT_SYMBOL(string_units_10);
> +const char * const string_units_2[STRING_UNITS_2_NUM] = {
> + "B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB",
> +};
> +EXPORT_SYMBOL(string_units_2);
> +
This is a pretty silly thing to do; how does someone who adds a unit to
one of the string_units know to increment STRING_UNITS_X_NUM? Even if
you add a comment admonishing them to do it, it's far better to have
this calculated at compile time like it was before this patch.
James
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 3/4] x86/efi: print size and base in binary units in efi_print_memmap
2016-01-21 15:22 [PATCH v2 1/4] lib/string_helpers: export string_units_{2,10} for others Andy Shevchenko
[not found] ` <1453389752-68175-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2016-01-21 15:22 ` Andy Shevchenko
[not found] ` <1453389752-68175-3-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-01-21 15:22 ` [PATCH v2 4/4] x86/efi: Use proper units in efi_find_mirror() Andy Shevchenko
2 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2016-01-21 15:22 UTC (permalink / raw)
To: Matt Fleming, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
linux-efi, Rasmus Villemoes, Andrew Morton, linux-kernel
Cc: Robert Elliott, Andy Shevchenko
From: Robert Elliott <elliott@hpe.com>
Print the base in the best-fit B, KiB, MiB, etc. units rather than
always MiB. This avoids rounding, which can be misleading.
Use proper IEC binary units (KiB, MiB, etc.) rather than misuse SI
decimal units (KB, MB, etc.).
old:
efi: mem61: [Persistent Memory | | | | | | | |WB|WT|WC|UC] range=[0x0000000880000000-0x0000000c7fffffff) (16384MB)
new:
efi: mem61: [Persistent Memory | | | | | | | |WB|WT|WC|UC] range=[0x0000000880000000-0x0000000c7fffffff] (16 GiB)
Signed-off-by: Robert Elliott <elliott@hpe.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
arch/x86/platform/efi/efi.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index e0846b5..3badc8a 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -35,10 +35,12 @@
#include <linux/efi.h>
#include <linux/efi-bgrt.h>
#include <linux/export.h>
+#include <linux/bitops.h>
#include <linux/bootmem.h>
#include <linux/slab.h>
#include <linux/memblock.h>
#include <linux/spinlock.h>
+#include <linux/string_helpers.h>
#include <linux/uaccess.h>
#include <linux/time.h>
#include <linux/io.h>
@@ -117,6 +119,14 @@ void efi_get_time(struct timespec *now)
now->tv_nsec = 0;
}
+static char * __init efi_size_format(char *buf, size_t size, u64 bytes)
+{
+ unsigned long i = bytes ? __ffs64(bytes) / 10 : 0;
+
+ snprintf(buf, size, "%llu %s", bytes >> (i * 10), string_units_2[i]);
+ return buf;
+}
+
void __init efi_find_mirror(void)
{
void *p;
@@ -225,21 +235,20 @@ int __init efi_memblock_x86_reserve_range(void)
void __init efi_print_memmap(void)
{
#ifdef EFI_DEBUG
- efi_memory_desc_t *md;
void *p;
int i;
for (p = memmap.map, i = 0;
p < memmap.map_end;
p += memmap.desc_size, i++) {
- char buf[64];
+ efi_memory_desc_t *md = p;
+ u64 size = md->num_pages << EFI_PAGE_SHIFT;
+ char buf[64], buf3[32];
- md = p;
- pr_info("mem%02u: %s range=[0x%016llx-0x%016llx] (%lluMB)\n",
+ pr_info("mem%02u: %s range=[0x%016llx-0x%016llx] (%s)\n",
i, efi_md_typeattr_format(buf, sizeof(buf), md),
- md->phys_addr,
- md->phys_addr + (md->num_pages << EFI_PAGE_SHIFT) - 1,
- (md->num_pages >> (20 - EFI_PAGE_SHIFT)));
+ md->phys_addr, md->phys_addr + size - 1,
+ efi_size_format(buf3, sizeof(buf3), size));
}
#endif /* EFI_DEBUG */
}
--
2.7.0.rc3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 4/4] x86/efi: Use proper units in efi_find_mirror()
2016-01-21 15:22 [PATCH v2 1/4] lib/string_helpers: export string_units_{2,10} for others Andy Shevchenko
[not found] ` <1453389752-68175-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-01-21 15:22 ` [PATCH v2 3/4] x86/efi: print size and base in binary units in efi_print_memmap Andy Shevchenko
@ 2016-01-21 15:22 ` Andy Shevchenko
2 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2016-01-21 15:22 UTC (permalink / raw)
To: Matt Fleming, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
linux-efi, Rasmus Villemoes, Andrew Morton, linux-kernel
Cc: Andy Shevchenko
Like in efi_print_mmap() use the proper units when printing sizes.
Currently it's hardcoded to 'MiB', though it might be changed to adaptive
efi_size_format() in the future.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
arch/x86/platform/efi/efi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
index 3badc8a..95f70da 100644
--- a/arch/x86/platform/efi/efi.c
+++ b/arch/x86/platform/efi/efi.c
@@ -144,8 +144,8 @@ void __init efi_find_mirror(void)
}
}
if (mirror_size)
- pr_info("Memory: %lldM/%lldM mirrored memory\n",
- mirror_size>>20, total_size>>20);
+ pr_info("Memory: %lld MiB/%lld MiB mirrored memory\n",
+ mirror_size >> 20, total_size >> 20);
}
/*
--
2.7.0.rc3
^ permalink raw reply related [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-01-23 11:50 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-21 15:22 [PATCH v2 1/4] lib/string_helpers: export string_units_{2,10} for others Andy Shevchenko
[not found] ` <1453389752-68175-1-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-01-21 15:22 ` [PATCH v2 2/4] lib/string_helpers: fix indentation in few places Andy Shevchenko
2016-01-23 5:13 ` [PATCH v2 1/4] lib/string_helpers: export string_units_{2,10} for others James Bottomley
[not found] ` <1453525999.2339.56.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2016-01-23 11:50 ` Andy Shevchenko
2016-01-21 15:22 ` [PATCH v2 3/4] x86/efi: print size and base in binary units in efi_print_memmap Andy Shevchenko
[not found] ` <1453389752-68175-3-git-send-email-andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-01-21 22:35 ` Andrew Morton
2016-01-22 7:08 ` Andy Shevchenko
[not found] ` <CAHp75VcCvpbamGurVVzXBGcYMCexpTZ4esg8YbKmzAu+iibyrw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-01-22 15:11 ` Matt Fleming
[not found] ` <20160122151100.GA3747-mF/unelCI9GS6iBeEJttW/XRex20P6io@public.gmane.org>
2016-01-22 20:10 ` Andrew Morton
2016-01-21 15:22 ` [PATCH v2 4/4] x86/efi: Use proper units in efi_find_mirror() Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).