From patchwork Thu Jan 3 21:33:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 10747815 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C542414DE for ; Thu, 3 Jan 2019 21:37:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B46B91FF1E for ; Thu, 3 Jan 2019 21:37:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A7DC3212E8; Thu, 3 Jan 2019 21:37:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E46671FF1E for ; Thu, 3 Jan 2019 21:37:06 +0000 (UTC) Received: from localhost ([127.0.0.1]:58025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gfAfp-0006u9-Og for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Jan 2019 16:37:05 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gfAcy-0004oO-Hr for qemu-devel@nongnu.org; Thu, 03 Jan 2019 16:34:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gfAcs-0003Ot-EP for qemu-devel@nongnu.org; Thu, 03 Jan 2019 16:34:08 -0500 Received: from mail-eopbgr810121.outbound.protection.outlook.com ([40.107.81.121]:16142 helo=NAM01-BY2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gfAcs-0003OP-5B; Thu, 03 Jan 2019 16:34:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janustech.onmicrosoft.com; s=selector1-janustech-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E5/qQq2RRARDdF8j0qCeYprXFJkMTN26JrC+/VGDL5A=; b=D5q7QDl4m5uX7v7DPGXCVmwLgPY0LhAqwZbuGjJIlIl/cPjDzz4XZDmQzIkb4tUOMjYW4eO1sLHQr99d6No9RG897iibniIsNK188X0Amw4s+ypxAqdqRKFc3hFGynqrwRUanaZNgNy98GZGsVSfpBIrCjjVYrFTa0QzYGcLfKM= Received: from CY1PR07MB2619.namprd07.prod.outlook.com (10.167.16.145) by CY1PR07MB2475.namprd07.prod.outlook.com (10.167.11.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1495.6; Thu, 3 Jan 2019 21:33:59 +0000 Received: from CY1PR07MB2619.namprd07.prod.outlook.com ([fe80::64b4:97dd:3f6f:c474]) by CY1PR07MB2619.namprd07.prod.outlook.com ([fe80::64b4:97dd:3f6f:c474%3]) with mapi id 15.20.1471.021; Thu, 3 Jan 2019 21:33:59 +0000 From: Leonid Bloch To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v2 1/1] include: Auto-generate the sizes lookup table Thread-Index: AQHUo6wKOwhIQYc+Jkemj2Ct54Aymg== Date: Thu, 3 Jan 2019 21:33:59 +0000 Message-ID: <20190103213320.2653-2-lbloch@janustech.com> References: <20190103213320.2653-1-lbloch@janustech.com> In-Reply-To: <20190103213320.2653-1-lbloch@janustech.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: LNXP265CA0042.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::30) To CY1PR07MB2619.namprd07.prod.outlook.com (2a01:111:e400:c637::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=lbloch@janustech.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [212.199.57.192] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; CY1PR07MB2475; 6:UPotFdLo/mX0jD0wmDMbHZcuTN5pietaOC2r7YNgofvGWGTOrQTSBI1CRdGph2x6noTx6P68uE/LdOe68hAaA2k6wWTrOQUD7gCW0//BwxOSsqYDGyXyYSgjw6St2cnjCVl4iBueWGAcBc+JiZ9ZyaRcqrQ141ewn/HDuMf9AczJrzQA0BEYcA/Uqs6PPxVDxxVWDTBeL/qByvIsjwOdLEwhadT41S+F2O2XQVrvyFZYhuEa4bL7gyNcLWrFvlOUDnAk1+oKT/OCLrCRtKvhNytUjDfkDkD09Tq89acEIY7kOTIPXipjNljNQndzduI++IZNKqe0UfdRslh/bUr9I8xdTe0reoLNj8etqgSebElCrjK5DO+chX4w1diwIcEjeEXiBF0L1eTyNYvqZDBjFxEeM0Yai1O3FXzgsdnKOTNYXHRBc2od4CGME69codI264nrCQ6axlovGn8+RYNk3w==; 5:AS3wehSt6uyENEjjwwlPB2OD4BZG3PcU0i/jojEVV4LpJEX9lqCDPWWQxn/701sfrvRZrAZze4hiQNyYK7kbNZq6dAYeXLKDItEPwJXZRoIu3PW0YDUOw+Kq+YVpxe1VxRa/wAbJuUmuw7sKlSxim9wts59dxfuh8wZ9lhL3h4j34qXYlDCPyVzHO0LSVorSmqTXuiWMeaVYRAcEoJSeZA==; 7:7rGjaPi4dXAcNOTOeS6WFxScQp8YhiDM6U02piYyzTKjV849ErbXVXwJwxJHRGKAGJdBecdrsE0BSgOhw6WqbT+33Hg5IiY0o7uzcThwyO8B+cmidJgg3xytSYWm7KZgIhV607G04EGayh/P7rEn4Q== x-ms-office365-filtering-correlation-id: 20a93179-2cb7-43e4-7e9f-08d671c32c2e x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(7021145)(8989299)(5600109)(711020)(4534185)(7022145)(4603075)(4627221)(201702281549075)(8990200)(7048125)(7024125)(7027125)(7023125)(2017052603328)(7153060)(7193020); SRVR:CY1PR07MB2475; x-ms-traffictypediagnostic: CY1PR07MB2475: x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(3230021)(908002)(999002)(5005026)(6040522)(8220060)(2401047)(8121501046)(3002001)(3231475)(944501520)(52105112)(10201501046)(93006095)(93001095)(6041310)(20161123562045)(20161123560045)(20161123558120)(20161123564045)(2016111802025)(6043046)(201708071742011)(7699051)(76991095); SRVR:CY1PR07MB2475; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2475; x-forefront-prvs: 0906E83A25 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(396003)(366004)(39830400003)(346002)(136003)(189003)(199004)(6486002)(5660300001)(305945005)(446003)(186003)(6436002)(8936002)(71190400001)(14454004)(476003)(105586002)(54906003)(106356001)(486006)(97736004)(86362001)(53936002)(316002)(6512007)(1076003)(66066001)(76176011)(36756003)(4326008)(508600001)(2616005)(386003)(256004)(2351001)(2906002)(6116002)(6916009)(26005)(81166006)(81156014)(5640700003)(99286004)(71200400001)(102836004)(2501003)(3846002)(8676002)(68736007)(6506007)(52116002)(25786009)(7736002)(11346002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2475; H:CY1PR07MB2619.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: janustech.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: U1HJJRa0EndKdIoz1rwzsue52enwbyFAew0aUXYiDl+DJcej1G+46wQ3hp3hP1e3nEujF+tLYRfeZuA6kgaQoBQrs0Shu5Z5abXISAW/QiItjya6eaS14N3iymt6vZaromQsQifhp4T3TnzZkBowa7b+ah54XDbosV+Kppwy6IcafGK5z5ribGl4F67K/nWyXAOSxVLeY9yJP7zW1Y65oGSTYixkV1W7AKJAcsmGIMUYWWNBUQtuCpc+C750Q3XFIK6YbhKpncvC3/qGyldDqqSUglwi5bObPZ0wqkrhrV+4Kk5KOyqDVE/o4d90RcUe spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20a93179-2cb7-43e4-7e9f-08d671c32c2e X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jan 2019 21:33:59.8674 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2475 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.81.121 Subject: [Qemu-devel] [PATCH v2 1/1] include: Auto-generate the sizes lookup table X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , "qemu-block@nongnu.org" , Stefan Weil , Markus Armbruster , Max Reitz , Leonid Bloch , =?iso-8859-1?q?Philippe_Mathieu-Daud=E9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The lookup table for power-of-two sizes is now auto-generated during the build, and not hard-coded into the units.h file. This partially reverts commit 540b8492618eb. Signed-off-by: Leonid Bloch --- .gitignore | 1 + Makefile | 5 +++ block/qcow2.h | 2 +- block/vdi.c | 1 + include/qemu/units.h | 73 -------------------------------------------- scripts/gen-sizes.sh | 66 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 74 deletions(-) create mode 100755 scripts/gen-sizes.sh diff --git a/.gitignore b/.gitignore index 0430257313..721a7f4454 100644 --- a/.gitignore +++ b/.gitignore @@ -59,6 +59,7 @@ /qemu-version.h /qemu-version.h.tmp /module_block.h +/pow2_sizes.h /scsi/qemu-pr-helper /vhost-user-scsi /vhost-user-blk diff --git a/Makefile b/Makefile index dd53965f77..db72786ccb 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,8 @@ endif GENERATED_FILES += module_block.h +GENERATED_FILES += pow2_sizes.h + TRACE_HEADERS = trace-root.h $(trace-events-subdirs:%=%/trace.h) TRACE_SOURCES = trace-root.c $(trace-events-subdirs:%=%/trace.c) TRACE_DTRACE = @@ -499,6 +501,9 @@ ifdef CONFIG_MPATH scsi/qemu-pr-helper$(EXESUF): LIBS += -ludev -lmultipath -lmpathpersist endif +pow2_sizes.h: $(SRC_PATH)/scripts/gen-sizes.sh + $(call quiet-command,sh $(SRC_PATH)/scripts/gen-sizes.sh $@,"GEN","$@") + qemu-img-cmds.h: $(SRC_PATH)/qemu-img-cmds.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@") diff --git a/block/qcow2.h b/block/qcow2.h index a98d24500b..f5fa419ae7 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -27,7 +27,7 @@ #include "crypto/block.h" #include "qemu/coroutine.h" -#include "qemu/units.h" +#include "pow2_sizes.h" //#define DEBUG_ALLOC //#define DEBUG_ALLOC2 diff --git a/block/vdi.c b/block/vdi.c index 2380daa583..06d7335b3e 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -51,6 +51,7 @@ #include "qemu/osdep.h" #include "qemu/units.h" +#include "pow2_sizes.h" #include "qapi/error.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-block-core.h" diff --git a/include/qemu/units.h b/include/qemu/units.h index 1c959d182e..692db3fbb2 100644 --- a/include/qemu/units.h +++ b/include/qemu/units.h @@ -17,77 +17,4 @@ #define PiB (INT64_C(1) << 50) #define EiB (INT64_C(1) << 60) -/* - * The following lookup table is intended to be used when a literal string of - * the number of bytes is required (for example if it needs to be stringified). - * It can also be used for generic shortcuts of power-of-two sizes. - * This table is generated using the AWK script below: - * - * 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); - * } - * } - */ - -#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 diff --git a/scripts/gen-sizes.sh b/scripts/gen-sizes.sh new file mode 100755 index 0000000000..28fe62a4c2 --- /dev/null +++ b/scripts/gen-sizes.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +size_suffix() { + case ${1} in + 1) + printf "KiB" + ;; + 2) + printf "MiB" + ;; + 3) + printf "GiB" + ;; + 4) + printf "TiB" + ;; + 5) + printf "PiB" + ;; + 6) + printf "EiB" + ;; + esac +} + +print_sizes() { + local p=10 + while [ ${p} -lt 64 ] + do + local pad=' ' + local n=$((p % 10)) + n=$((1 << n)) + [ $((n / 100)) -eq 0 ] && pad=' ' + [ $((n / 10)) -eq 0 ] && pad=' ' + local suff=$((p / 10)) + printf "#define S_%u%s%s%20u\n" ${n} "$(size_suffix ${suff})" \ + "${pad}" $((1 << p)) + p=$((p + 1)) + done +} + +print_header() { + cat < + */ + +#ifndef QEMU_SIZES_H +#define QEMU_SIZES_H + +EOF +} + +print_footer() { + printf "\n#endif /* QEMU_SIZES_H */\n" +} + +print_header > "${1}" +print_sizes >> "${1}" +print_footer >> "${1}"