Re: [Qemu-block] [PATCH v7 7/9] qemu/units: add SI decimal units

2019-08-09 Thread Eric Blake
On 6/18/19 6:43 AM, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> ---
>  include/qemu/units.h | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/include/qemu/units.h b/include/qemu/units.h
> index 692db3fbb2..52ccc7445c 100644
> --- a/include/qemu/units.h
> +++ b/include/qemu/units.h
> @@ -17,4 +17,11 @@
>  #define PiB (INT64_C(1) << 50)
>  #define EiB (INT64_C(1) << 60)
>  
> +#define SI_k 1000LL
> +#define SI_M 100LL
> +#define SI_G 10LL
> +#define SI_T 1LL
> +#define SI_P 1000LL
> +#define SI_E 100LL

Looks correct; and it's the sort of thing that if we do once here, we
don't have to repeat elsewhere. But bike-shedding a bit, would it be any
easier to read as:

#define SI_k 1000LL
#define SI_M (1000LL * 1000)
#define SI_G (1000LL * 1000 * 1000)
...

or even:

#define SI_k 1000LL
#define SI_M (SI_k * 1000)
#define SI_G (SI_M * 1000)
...

Also, would it be worth swapping out existing constants in the code base
that should instead be using these macros, so that they actually have a
use and so that we can see whether using them adds legibility?

For example, block/nvme.c, block/qapi.c, block/sheepdog.c, blockdev.c,
util/async.c, util/oslib-win32.c, util/qemu-thread-posix.c,
util/qemu-timer.c all seem to be dealing with conversions between
seconds and subdivisions thereof, where constants 100 or larger are
in use and could be rewritten with these.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



signature.asc
Description: OpenPGP digital signature


[Qemu-block] [PATCH v7 7/9] qemu/units: add SI decimal units

2019-06-18 Thread Vladimir Sementsov-Ogievskiy
Signed-off-by: Vladimir Sementsov-Ogievskiy 
---
 include/qemu/units.h | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/include/qemu/units.h b/include/qemu/units.h
index 692db3fbb2..52ccc7445c 100644
--- a/include/qemu/units.h
+++ b/include/qemu/units.h
@@ -17,4 +17,11 @@
 #define PiB (INT64_C(1) << 50)
 #define EiB (INT64_C(1) << 60)
 
+#define SI_k 1000LL
+#define SI_M 100LL
+#define SI_G 10LL
+#define SI_T 1LL
+#define SI_P 1000LL
+#define SI_E 100LL
+
 #endif
-- 
2.18.0