From patchwork Wed Jul 15 16:25:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 11665905 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E32D21392 for ; Wed, 15 Jul 2020 16:26:17 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C7D3F2065E for ; Wed, 15 Jul 2020 16:26:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7D3F2065E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=eu.citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jvkEN-0002iF-JS; Wed, 15 Jul 2020 16:26:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jvkEM-0002Yi-Am for xen-devel@lists.xenproject.org; Wed, 15 Jul 2020 16:26:02 +0000 X-Inumbo-ID: d0e35540-c6b7-11ea-b7bb-bc764e2007e4 Received: from chiark.greenend.org.uk (unknown [2001:ba8:1e3::]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d0e35540-c6b7-11ea-b7bb-bc764e2007e4; Wed, 15 Jul 2020 16:25:37 +0000 (UTC) Received: from [172.18.45.5] (helo=zealot.relativity.greenend.org.uk) by chiark.greenend.org.uk (Debian Exim 4.84_2 #1) with esmtp (return-path ijackson@chiark.greenend.org.uk) id 1jvkDw-0001sU-VQ; Wed, 15 Jul 2020 17:25:37 +0100 From: Ian Jackson To: xen-devel@lists.xenproject.org Subject: [PATCH 05/12] tools: define ROUNDUP() in tools/include/xen-tools/libs.h Date: Wed, 15 Jul 2020 17:25:04 +0100 Message-Id: <20200715162511.5941-7-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200715162511.5941-1-ian.jackson@eu.citrix.com> References: <20200715162511.5941-1-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Reply-To: incoming+61544a64d0c2dc4555813e58f3810dd7@incoming.gitlab.com, xen-devel@lists.xenproject.org Cc: Juergen Gross , Anthony PERARD , ian.jackson@eu.citrix.com, Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Juergen Gross Today there are multiple copies of the ROUNDUP() macro in various sources and headers. Define it once in tools/include/xen-tools/libs.h. Using xen-tools/libs.h enables removing copies of MIN() and MAX(), too. Signed-off-by: Juergen Gross --- tools/console/daemon/io.c | 6 +----- tools/include/xen-tools/libs.h | 4 ++++ tools/libs/call/buffer.c | 3 +-- tools/libs/foreignmemory/linux.c | 3 +-- tools/libs/gnttab/private.h | 3 --- tools/libxc/xg_private.h | 1 - tools/libxl/libxl_internal.h | 3 --- tools/xenstore/xenstored_core.c | 2 -- 8 files changed, 7 insertions(+), 18 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index a43c57edad..4af27ffc5d 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -49,9 +49,7 @@ #include #include #endif - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#include /* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */ #define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2) @@ -80,8 +78,6 @@ static struct pollfd *fds; static unsigned int current_array_size; static unsigned int nr_fds; -#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) - struct buffer { char *data; size_t consumed; diff --git a/tools/include/xen-tools/libs.h b/tools/include/xen-tools/libs.h index cc7dfc8c64..a16e0c3807 100644 --- a/tools/include/xen-tools/libs.h +++ b/tools/include/xen-tools/libs.h @@ -59,4 +59,8 @@ }) #endif +#ifndef ROUNDUP +#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) +#endif + #endif /* __XEN_TOOLS_LIBS__ */ diff --git a/tools/libs/call/buffer.c b/tools/libs/call/buffer.c index 0b6af2db60..085674d882 100644 --- a/tools/libs/call/buffer.c +++ b/tools/libs/call/buffer.c @@ -16,14 +16,13 @@ #include #include #include +#include #include "private.h" #define DBGPRINTF(_m...) \ xtl_log(xcall->logger, XTL_DEBUG, -1, "xencall:buffer", _m) -#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) - pthread_mutex_t cache_mutex = PTHREAD_MUTEX_INITIALIZER; static void cache_lock(xencall_handle *xcall) diff --git a/tools/libs/foreignmemory/linux.c b/tools/libs/foreignmemory/linux.c index 8daa5828e3..fe73d5ab72 100644 --- a/tools/libs/foreignmemory/linux.c +++ b/tools/libs/foreignmemory/linux.c @@ -25,11 +25,10 @@ #include #include +#include #include "private.h" -#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) - #ifndef O_CLOEXEC #define O_CLOEXEC 0 #endif diff --git a/tools/libs/gnttab/private.h b/tools/libs/gnttab/private.h index c5e23639b1..eb6a6abe54 100644 --- a/tools/libs/gnttab/private.h +++ b/tools/libs/gnttab/private.h @@ -5,9 +5,6 @@ #include #include -/* Set of macros/defines used by both Linux and FreeBSD */ -#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) - #define GTERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gnttab", _f) #define GSERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gntshr", _f) diff --git a/tools/libxc/xg_private.h b/tools/libxc/xg_private.h index f0a4b2c616..40b5baecde 100644 --- a/tools/libxc/xg_private.h +++ b/tools/libxc/xg_private.h @@ -95,7 +95,6 @@ typedef uint64_t x86_pgentry_t; #define PAGE_SIZE_X86 (1UL << PAGE_SHIFT_X86) #define PAGE_MASK_X86 (~(PAGE_SIZE_X86-1)) -#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) #define NRPAGES(x) (ROUNDUP(x, PAGE_SHIFT) >> PAGE_SHIFT) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 94a23179d3..c63d0686fd 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -132,9 +132,6 @@ #define MB(_mb) (_AC(_mb, ULL) << 20) #define GB(_gb) (_AC(_gb, ULL) << 30) -#define ROUNDUP(_val, _order) \ - (((unsigned long)(_val)+(1UL<<(_order))-1) & ~((1UL<<(_order))-1)) - #define DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d)) #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m))) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index 7bd959f28b..9700772d40 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -73,8 +73,6 @@ static unsigned int nr_fds; static int sock = -1; static int ro_sock = -1; -#define ROUNDUP(_x, _w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1)) - static bool verbose = false; LIST_HEAD(connections); int tracefd = -1;