From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 12/23] include: Add a lookup table of sizes
Date: Mon, 1 Oct 2018 19:18:50 +0200 [thread overview]
Message-ID: <20181001171901.11004-13-kwolf@redhat.com> (raw)
In-Reply-To: <20181001171901.11004-1-kwolf@redhat.com>
From: Leonid Bloch <lbloch@janustech.com>
Adding a lookup table for the powers of two, with the appropriate size
prefixes. This is needed when a size has to be stringified, in which
case something like '(1 * KiB)' would become a literal '(1 * (1L << 10))'
string. Powers of two are used very often for sizes, so such a table
will also make it easier and more intuitive to write them.
This table is generatred using the following AWK script:
BEGIN {
suffix="KMGTPE";
for(i=10; i<64; i++) {
val=2**i;
s=substr(suffix, int(i/10), 1);
n=2**(i%10);
pad=21-int(log(n)/log(10));
printf("#define S_%d%siB %*d\n", n, s, pad, val);
}
}
Signed-off-by: Leonid Bloch <lbloch@janustech.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
include/qemu/units.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/include/qemu/units.h b/include/qemu/units.h
index 692db3fbb2..68a7758650 100644
--- a/include/qemu/units.h
+++ b/include/qemu/units.h
@@ -17,4 +17,59 @@
#define PiB (INT64_C(1) << 50)
#define EiB (INT64_C(1) << 60)
+#define S_1KiB 1024
+#define S_2KiB 2048
+#define S_4KiB 4096
+#define S_8KiB 8192
+#define S_16KiB 16384
+#define S_32KiB 32768
+#define S_64KiB 65536
+#define S_128KiB 131072
+#define S_256KiB 262144
+#define S_512KiB 524288
+#define S_1MiB 1048576
+#define S_2MiB 2097152
+#define S_4MiB 4194304
+#define S_8MiB 8388608
+#define S_16MiB 16777216
+#define S_32MiB 33554432
+#define S_64MiB 67108864
+#define S_128MiB 134217728
+#define S_256MiB 268435456
+#define S_512MiB 536870912
+#define S_1GiB 1073741824
+#define S_2GiB 2147483648
+#define S_4GiB 4294967296
+#define S_8GiB 8589934592
+#define S_16GiB 17179869184
+#define S_32GiB 34359738368
+#define S_64GiB 68719476736
+#define S_128GiB 137438953472
+#define S_256GiB 274877906944
+#define S_512GiB 549755813888
+#define S_1TiB 1099511627776
+#define S_2TiB 2199023255552
+#define S_4TiB 4398046511104
+#define S_8TiB 8796093022208
+#define S_16TiB 17592186044416
+#define S_32TiB 35184372088832
+#define S_64TiB 70368744177664
+#define S_128TiB 140737488355328
+#define S_256TiB 281474976710656
+#define S_512TiB 562949953421312
+#define S_1PiB 1125899906842624
+#define S_2PiB 2251799813685248
+#define S_4PiB 4503599627370496
+#define S_8PiB 9007199254740992
+#define S_16PiB 18014398509481984
+#define S_32PiB 36028797018963968
+#define S_64PiB 72057594037927936
+#define S_128PiB 144115188075855872
+#define S_256PiB 288230376151711744
+#define S_512PiB 576460752303423488
+#define S_1EiB 1152921504606846976
+#define S_2EiB 2305843009213693952
+#define S_4EiB 4611686018427387904
+#define S_8EiB 9223372036854775808
+
#endif
--
2.13.6
next prev parent reply other threads:[~2018-10-01 17:19 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-01 17:18 [Qemu-devel] [PULL 00/23] Block layer patches Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 01/23] file-posix: Include filename in locking error message Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 02/23] qemu-io: Fix writethrough check in reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 03/23] file-posix: x-check-cache-dropped should default to false on reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 04/23] block: Remove child references from bs->{options, explicit_options} Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 05/23] block: Don't look for child references in append_open_options() Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 06/23] block: Allow child references on reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 07/23] block: Forbid trying to change unsupported options during reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 08/23] file-posix: " Kevin Wolf
2018-10-05 12:55 ` Peter Maydell
2018-10-05 13:10 ` Kevin Wolf
2018-10-05 13:40 ` [Qemu-devel] [Qemu-block] " Alberto Garcia
2018-10-05 13:41 ` Alberto Garcia
2018-10-05 13:47 ` Peter Maydell
2018-10-01 17:18 ` [Qemu-devel] [PULL 09/23] block: Allow changing 'discard' on reopen Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 10/23] block: Allow changing 'detect-zeroes' " Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 11/23] qcow2: Options' documentation fixes Kevin Wolf
2018-10-01 17:18 ` Kevin Wolf [this message]
2018-10-01 17:18 ` [Qemu-devel] [PULL 13/23] qcow2: Make sizes more humanly readable Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 14/23] qcow2: Avoid duplication in setting the refcount cache size Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 15/23] qcow2: Assign the L2 cache relatively to the image size Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 16/23] qcow2: Increase the default upper limit on the L2 cache size Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 17/23] qcow2: Resize the cache upon image resizing Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 18/23] qcow2: Set the default cache-clean-interval to 10 minutes Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 19/23] qcow2: Explicit number replaced by a constant Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 20/23] block-backend: Set werror/rerror defaults in blk_new() Kevin Wolf
2018-10-01 17:18 ` [Qemu-devel] [PULL 21/23] qcow2: Fix cache-clean-interval documentation Kevin Wolf
2018-10-01 17:19 ` [Qemu-devel] [PULL 22/23] test-replication: Lock AioContext around blk_unref() Kevin Wolf
2018-10-01 17:19 ` [Qemu-devel] [PULL 23/23] tests/test-bdrv-drain: Fix too late qemu_event_reset() Kevin Wolf
2018-10-02 8:06 ` [Qemu-devel] [PULL 00/23] Block layer patches Peter Maydell
2018-10-03 15:46 ` Peter Maydell
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=20181001171901.11004-13-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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.