From patchwork Mon Jul 29 12:12:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11063729 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 88FED13AC for ; Mon, 29 Jul 2019 12:14:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75D6D22ADC for ; Mon, 29 Jul 2019 12:14:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A2B9286F9; Mon, 29 Jul 2019 12:14:05 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B018E280B0 for ; Mon, 29 Jul 2019 12:14:04 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hs4Vo-0006lE-Ma; Mon, 29 Jul 2019 12:12:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hs4Vn-0006jK-H0 for xen-devel@lists.xenproject.org; Mon, 29 Jul 2019 12:12:19 +0000 X-Inumbo-ID: 1b64c5d2-b1fa-11e9-803b-2f6df10fe840 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 1b64c5d2-b1fa-11e9-803b-2f6df10fe840; Mon, 29 Jul 2019 12:12:17 +0000 (UTC) Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa6.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: f4kfPd8Kk9C2lKqQCRUk0/B/lVw3mswK6V/oTmKlQUerF1nbg4ldRqPi/owYtXqWBR9ol5rjsa uN+B7jhfva4Q3S7Y8W1XX4MUJmuhFPjhVFsNLl77GDGfc8qwnLUx4WFfaFYdb4LB3BTUHECOwf 6Pvc9nKU3rMTAkmdiJSsE5NjZfBdqIxp638QmYr4IRAcXS+KxLHTjFxfTnmLMFpYfYFo/vy8rb MW7MqClffGt/3ztFOw43sAtlcIX+5JYjx1pjrycE1L1m0SL7TOxufK/zlGbmXXmwg0EwGsohXz nJ8= X-SBRS: 2.7 X-MesageID: 3672670 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,322,1559534400"; d="scan'208";a="3672670" From: Andrew Cooper To: Xen-devel Date: Mon, 29 Jul 2019 13:12:01 +0100 Message-ID: <20190729121204.13559-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190729121204.13559-1-andrew.cooper3@citrix.com> References: <20190729121204.13559-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 07/10] xen/nodemask: Drop nodes_{setall, clear}() and improve the initialisers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Andrew Cooper , Julien Grall , Jan Beulich , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP There is no need to use runtime variable-length clearing when MAX_NUMNODES is known to the compiler. Drop these functions and use the initialisers instead. numa_initmem_init() opencodes nodemask_of_node(), but its implemention is still poor, so replace it with NODEMASK_OF() which is calculated at compile time, and without the use of a locked set_bit() operation. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk v3: * New --- xen/arch/x86/dom0_build.c | 2 +- xen/arch/x86/numa.c | 3 +- xen/common/domain.c | 4 +-- xen/include/xen/nodemask.h | 85 +++++++++++++++++----------------------------- 4 files changed, 35 insertions(+), 59 deletions(-) diff --git a/xen/arch/x86/dom0_build.c b/xen/arch/x86/dom0_build.c index c69570920c..06500c87c6 100644 --- a/xen/arch/x86/dom0_build.c +++ b/xen/arch/x86/dom0_build.c @@ -231,7 +231,7 @@ unsigned int __init dom0_max_vcpus(void) if ( pv_shim ) { - nodes_setall(dom0_nodes); + dom0_nodes = NODEMASK_ALL; /* * When booting in shim mode APs are not started until the guest brings diff --git a/xen/arch/x86/numa.c b/xen/arch/x86/numa.c index 7e1f563012..7473f83b7b 100644 --- a/xen/arch/x86/numa.c +++ b/xen/arch/x86/numa.c @@ -269,8 +269,7 @@ void __init numa_initmem_init(unsigned long start_pfn, unsigned long end_pfn) /* setup dummy node covering all memory */ memnode_shift = BITS_PER_LONG - 1; memnodemap = _memnodemap; - nodes_clear(node_online_map); - node_set_online(0); + node_online_map = NODEMASK_OF(0); for ( i = 0; i < nr_cpu_ids; i++ ) numa_set_node(i, 0); cpumask_copy(&node_to_cpumask[0], cpumask_of(0)); diff --git a/xen/common/domain.c b/xen/common/domain.c index e8e850796e..11565a64b3 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -384,7 +384,7 @@ struct domain *domain_create(domid_t domid, INIT_PAGE_LIST_HEAD(&d->xenpage_list); spin_lock_init(&d->node_affinity_lock); - d->node_affinity = NODE_MASK_ALL; + d->node_affinity = NODEMASK_ALL; d->auto_node_affinity = 1; spin_lock_init(&d->shutdown_lock); @@ -615,7 +615,7 @@ void domain_update_node_affinity(struct domain *d) dom_affinity = cpumask_empty(dom_cpumask_soft) ? dom_cpumask : dom_cpumask_soft; - nodes_clear(d->node_affinity); + d->node_affinity = NODEMASK_NONE; for_each_cpu ( cpu, dom_affinity ) node_set(cpu_to_node(cpu), d->node_affinity); } diff --git a/xen/include/xen/nodemask.h b/xen/include/xen/nodemask.h index 1dd6c7458e..9933fec5c4 100644 --- a/xen/include/xen/nodemask.h +++ b/xen/include/xen/nodemask.h @@ -12,8 +12,6 @@ * * void node_set(node, mask) turn on bit 'node' in mask * void node_clear(node, mask) turn off bit 'node' in mask - * void nodes_setall(mask) set all bits - * void nodes_clear(mask) clear all bits * bool nodemask_test(node, mask) true iff bit 'node' set in mask * int node_test_and_set(node, mask) test and set bit 'node' in mask * @@ -36,9 +34,9 @@ * int cycle_node(node, mask) Next node cycling from 'node', or * MAX_NUMNODES * - * nodemask_t nodemask_of_node(node) Return nodemask with bit 'node' set - * NODE_MASK_ALL Initializer - all bits set - * NODE_MASK_NONE Initializer - no bits set + * nodemask_t NODEMASK_OF(node) Initializer - bit 'node' set + * NODEMASK_ALL Initializer - all bits set + * NODEMASK_NONE Initializer - no bits set * unsigned long *nodemask_bits(mask) Array of unsigned long's in mask * * for_each_node_mask(node, mask) for-loop node over mask @@ -67,7 +65,34 @@ typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t; #define nodemask_bits(src) ((src)->bits) -extern nodemask_t _unused_nodemask_arg_; +#define NODEMASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES) + +#define NODEMASK_NONE \ +((nodemask_t) {{ \ + [0 ... BITS_TO_LONGS(MAX_NUMNODES) - 1] = 0 \ +}}) + +#if MAX_NUMNODES <= BITS_PER_LONG + +#define NODEMASK_ALL ((nodemask_t) {{ NODEMASK_LAST_WORD }}) +#define NODEMASK_OF(node) ((nodemask_t) {{ 1UL << (node) }}) + +#else /* MAX_NUMNODES > BITS_PER_LONG */ + +#define NODEMASK_ALL \ +((nodemask_t) {{ \ + [0 ... BITS_TO_LONGS(MAX_NUMNODES) - 2] = ~0UL, \ + [BITS_TO_LONGS(MAX_NUMNODES) - 1] = NODEMASK_LAST_WORD \ +}}) + +#define NODEMASK_OF(node) \ +({ \ + nodemask_t m = NODES_NONE; \ + m.bits[(node) / BITS_PER_LONG] = 1UL << ((node) % BITS_PER_LONG); \ + m; \ +}) + +#endif /* MAX_NUMNODES */ #define node_set(node, dst) __node_set((node), &(dst)) static inline void __node_set(int node, volatile nodemask_t *dstp) @@ -81,18 +106,6 @@ static inline void __node_clear(int node, volatile nodemask_t *dstp) clear_bit(node, dstp->bits); } -#define nodes_setall(dst) __nodes_setall(&(dst), MAX_NUMNODES) -static inline void __nodes_setall(nodemask_t *dstp, int nbits) -{ - bitmap_fill(dstp->bits, nbits); -} - -#define nodes_clear(dst) __nodes_clear(&(dst), MAX_NUMNODES) -static inline void __nodes_clear(nodemask_t *dstp, int nbits) -{ - bitmap_zero(dstp->bits, nbits); -} - static inline bool nodemask_test(unsigned int node, const nodemask_t *dst) { return test_bit(node, dst->bits); @@ -213,18 +226,6 @@ static inline int __last_node(const nodemask_t *srcp, int nbits) return pnode; } -#define nodemask_of_node(node) \ -({ \ - typeof(_unused_nodemask_arg_) m; \ - if (sizeof(m) == sizeof(unsigned long)) { \ - m.bits[0] = 1UL<<(node); \ - } else { \ - nodes_clear(m); \ - node_set((node), m); \ - } \ - m; \ -}) - #define cycle_node(n, src) __cycle_node((n), &(src), MAX_NUMNODES) static inline int __cycle_node(int n, const nodemask_t *maskp, int nbits) { @@ -235,30 +236,6 @@ static inline int __cycle_node(int n, const nodemask_t *maskp, int nbits) return nxt; } -#define NODE_MASK_LAST_WORD BITMAP_LAST_WORD_MASK(MAX_NUMNODES) - -#if MAX_NUMNODES <= BITS_PER_LONG - -#define NODE_MASK_ALL \ -((nodemask_t) { { \ - [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \ -} }) - -#else - -#define NODE_MASK_ALL \ -((nodemask_t) { { \ - [0 ... BITS_TO_LONGS(MAX_NUMNODES)-2] = ~0UL, \ - [BITS_TO_LONGS(MAX_NUMNODES)-1] = NODE_MASK_LAST_WORD \ -} }) - -#endif - -#define NODE_MASK_NONE \ -((nodemask_t) { { \ - [0 ... BITS_TO_LONGS(MAX_NUMNODES)-1] = 0UL \ -} }) - #if MAX_NUMNODES > 1 #define for_each_node_mask(node, mask) \ for ((node) = first_node(mask); \