From patchwork Wed Dec 9 15:54:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 11961789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB477C433FE for ; Wed, 9 Dec 2020 15:55: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 64A202251E for ; Wed, 9 Dec 2020 15:55:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64A202251E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aepfle.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.48402.85583 (Exim 4.92) (envelope-from ) id 1kn1o1-0000OJ-Gz; Wed, 09 Dec 2020 15:55:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 48402.85583; Wed, 09 Dec 2020 15:55:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kn1o1-0000OC-D4; Wed, 09 Dec 2020 15:55:05 +0000 Received: by outflank-mailman (input) for mailman id 48402; Wed, 09 Dec 2020 15:55:04 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kn1nz-0000O2-TZ for xen-devel@lists.xenproject.org; Wed, 09 Dec 2020 15:55:04 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [81.169.146.160]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 193b3f80-78c8-41b1-9d02-4ede601b9ffe; Wed, 09 Dec 2020 15:55:01 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.6.3 DYNA|AUTH) with ESMTPSA id 007720wB9Fst0b8 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Wed, 9 Dec 2020 16:54:55 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 193b3f80-78c8-41b1-9d02-4ede601b9ffe DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1607529300; s=strato-dkim-0002; d=aepfle.de; h=Message-Id:Date:Subject:Cc:To:From:From:Subject:Sender; bh=OFKa3btZzlVY9IFyVAhE+lCMTDnS9LRZ3EMEfMGxlXM=; b=Gvx2UPoo8egL6unaM2cLF+QU4V2KXJD43rGE9TtcF5aPEiIYMcV7CKBpK1Q6VkLk3c LOUlELThVMO30qszvH91zMApd6zN6ONeyqQT4rUeaAdAKDExaBIlZv9VqfoxcWV65H44 FbNSCNVcRVlgDZTty2uYXWzknyJDDSy690NI7E5gNFkA4rcBxiJzvO+B67CnLLWvYePs KRLWidGi4Wav9ykskYz1hbqRhQihKiJCvL1ocRSFtLFRoy0/jryfYtzqbmDG6iyqHXOR jS2QEcxJUn/QDwgozz0P72m5TmgupcMhbJfq8uZddKqPjvc/W/28wDJs4KEsRiDh+fgf 62Dw== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuz7MdiQehTvc3KJf+TWodQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v1 1/3] tools: allocate bitmaps in units of unsigned long Date: Wed, 9 Dec 2020 16:54:49 +0100 Message-Id: <20201209155452.28376-1-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Allocate enough memory so that the returned pointer can be safely accessed as an array of unsigned long. The actual bitmap size in units of bytes, as returned by bitmap_size, remains unchanged. Signed-off-by: Olaf Hering Acked-by: Wei Liu --- tools/libs/ctrl/xc_bitops.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h index 3d3a09772a..d6c5ea5138 100644 --- a/tools/libs/ctrl/xc_bitops.h +++ b/tools/libs/ctrl/xc_bitops.h @@ -21,7 +21,10 @@ static inline unsigned long bitmap_size(unsigned long nr_bits) static inline void *bitmap_alloc(unsigned long nr_bits) { - return calloc(1, bitmap_size(nr_bits)); + unsigned long longs; + + longs = (nr_bits + BITS_PER_LONG - 1) / BITS_PER_LONG; + return calloc(longs, sizeof(unsigned long)); } static inline void bitmap_set(void *addr, unsigned long nr_bits) From patchwork Wed Dec 9 15:54:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 11961793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2973BC4167B for ; Wed, 9 Dec 2020 15:55:20 +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 E0CA82251E for ; Wed, 9 Dec 2020 15:55:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0CA82251E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aepfle.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.48403.85588 (Exim 4.92) (envelope-from ) id 1kn1o1-0000Ok-Pn; Wed, 09 Dec 2020 15:55:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 48403.85588; Wed, 09 Dec 2020 15:55:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kn1o1-0000OX-KP; Wed, 09 Dec 2020 15:55:05 +0000 Received: by outflank-mailman (input) for mailman id 48403; Wed, 09 Dec 2020 15:55:04 +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.92) (envelope-from ) id 1kn1o0-0000O7-7s for xen-devel@lists.xenproject.org; Wed, 09 Dec 2020 15:55:04 +0000 Received: from mo4-p00-ob.smtp.rzone.de (unknown [81.169.146.216]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 33b82ef4-bbf4-4c02-a086-fc70b1815583; Wed, 09 Dec 2020 15:55:02 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.6.3 DYNA|AUTH) with ESMTPSA id 007720wB9Fsv0b9 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Wed, 9 Dec 2020 16:54:57 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 33b82ef4-bbf4-4c02-a086-fc70b1815583 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1607529301; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:From: Subject:Sender; bh=DKL6ewFHEenBMo6vG4Fk2Fh+oKBRcf8oXazH6dWBh0w=; b=qTbLOn0LUJEyKmdhsn8RRZ3dC2L6b50tQtlFBRwsUKsDe7iE+FGqIx24SHulLvoDGS Hy7Ig8qIxbLnmQK8zcAMNBkAU994dgOByIXDOKSEL7qoCK32oJzyFfZprjuB4HndjLYQ /PGTV2ANwi6DofIhZXvRRgbzMH/QPNG4htS3eLcv2XR8q2ITWXwj6lYuSMfg9Lq8Dk5n FmIRfXkfxPl9BanVwxI0OpscY9gxBmqQbiqiaCwSemqJglNEtQlUu225O/87uISW7ti5 v4guYrkdGgZZCdxY0chtRmp3UuvC//SG+FX/zA7IuRyosOeYpXY3dnuRyhClkmA3kD20 AB4g== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuz7MdiQehTvc3KJf+TWodQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v1 2/3] tools: remove unused ORDER_LONG Date: Wed, 9 Dec 2020 16:54:50 +0100 Message-Id: <20201209155452.28376-2-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201209155452.28376-1-olaf@aepfle.de> References: <20201209155452.28376-1-olaf@aepfle.de> MIME-Version: 1.0 There are no users left, xenpaging has its own variant. The last user was removed with commit 11d0044a168994de85b9b328452292852aedc871 Signed-off-by: Olaf Hering Acked-by: Wei Liu --- tools/libs/ctrl/xc_bitops.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h index d6c5ea5138..f0bac4a071 100644 --- a/tools/libs/ctrl/xc_bitops.h +++ b/tools/libs/ctrl/xc_bitops.h @@ -6,9 +6,7 @@ #include #include -/* Needed by several includees, but no longer used for bitops. */ #define BITS_PER_LONG (sizeof(unsigned long) * 8) -#define ORDER_LONG (sizeof(unsigned long) == 4 ? 5 : 6) #define BITMAP_ENTRY(_nr,_bmap) ((_bmap))[(_nr) / 8] #define BITMAP_SHIFT(_nr) ((_nr) % 8) From patchwork Wed Dec 9 15:54:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 11961791 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BB79C4361B for ; Wed, 9 Dec 2020 15:55:18 +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 866FE22B4B for ; Wed, 9 Dec 2020 15:55:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 866FE22B4B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=aepfle.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.48404.85606 (Exim 4.92) (envelope-from ) id 1kn1o5-0000Rz-VW; Wed, 09 Dec 2020 15:55:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 48404.85606; Wed, 09 Dec 2020 15:55:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kn1o5-0000Rr-SU; Wed, 09 Dec 2020 15:55:09 +0000 Received: by outflank-mailman (input) for mailman id 48404; Wed, 09 Dec 2020 15:55:08 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kn1o4-0000O2-KB for xen-devel@lists.xenproject.org; Wed, 09 Dec 2020 15:55:08 +0000 Received: from mo4-p01-ob.smtp.rzone.de (unknown [81.169.146.164]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 31da302d-6595-43d6-aebb-98ed20980d29; Wed, 09 Dec 2020 15:55:03 +0000 (UTC) Received: from sender by smtp.strato.de (RZmta 47.6.3 DYNA|AUTH) with ESMTPSA id 007720wB9Fsx0bB (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256 bits)) (Client did not present a certificate); Wed, 9 Dec 2020 16:54:59 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 31da302d-6595-43d6-aebb-98ed20980d29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1607529303; s=strato-dkim-0002; d=aepfle.de; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:From: Subject:Sender; bh=ti7wpap7OKPtBty/ilhF07cZXxS6hyTWcz0abirc9Nk=; b=IqFVHRvEQJI8EdzsqLVU4d73cnsrkHaKATHpes1Gv8xzJG4nRbXnMc3Tsg9ovNcrXA Gcq+2lQHFp4cP9disWVwv3+8cc6XI3esQCp/bR+fbUAcNeA4roRNJYVglLxlHCfia2z8 CIBPXUPnO/YhoOm/0ayf8RUP1ZOeGUPZ9yxMPRRDKgh5gR3GZBVOW3n8N5qXWV7WMI0G oAOs9cLvagI3VwzJGL4OI7K0DVSMoFSLyPvL2wifIUDHkpC5TLknyFHtf3EJdXHIp1Ti XOMV350sUKuZiuFQUcyfPHxuzVBujESqdPlcwM3YGtiZI6HOoxjw1FfABNz011hsTnKf Socw== X-RZG-AUTH: ":P2EQZWCpfu+qG7CngxMFH1J+3q8wa/QXkBR9MXjAuz7MdiQehTvc3KJf+TWodQ==" X-RZG-CLASS-ID: mo00 From: Olaf Hering To: xen-devel@lists.xenproject.org Cc: Olaf Hering , Ian Jackson , Wei Liu Subject: [PATCH v1 3/3] tools: add API to work with sevaral bits at once Date: Wed, 9 Dec 2020 16:54:51 +0100 Message-Id: <20201209155452.28376-3-olaf@aepfle.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201209155452.28376-1-olaf@aepfle.de> References: <20201209155452.28376-1-olaf@aepfle.de> MIME-Version: 1.0 Introduce new API to test if a fixed number of bits is clear or set, and clear or set them all at once. The caller has to make sure the input bitnumber is a multiply of BITS_PER_LONG. This API avoids the loop over each bit in a known range just to see if all of them are either clear or set. Signed-off-by: Olaf Hering --- tools/libs/ctrl/xc_bitops.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/libs/ctrl/xc_bitops.h b/tools/libs/ctrl/xc_bitops.h index f0bac4a071..92f38872fb 100644 --- a/tools/libs/ctrl/xc_bitops.h +++ b/tools/libs/ctrl/xc_bitops.h @@ -77,4 +77,29 @@ static inline void bitmap_or(void *_dst, const void *_other, dst[i] |= other[i]; } +static inline int test_bit_long_set(unsigned long nr_base, const void *_addr) +{ + const unsigned long *addr = _addr; + unsigned long val = addr[nr_base / BITS_PER_LONG]; + return val == ~0; +} + +static inline int test_bit_long_clear(unsigned long nr_base, const void *_addr) +{ + const unsigned long *addr = _addr; + unsigned long val = addr[nr_base / BITS_PER_LONG]; + return val == 0; +} + +static inline void clear_bit_long(unsigned long nr_base, void *_addr) +{ + unsigned long *addr = _addr; + addr[nr_base / BITS_PER_LONG] = 0; +} + +static inline void set_bit_long(unsigned long nr_base, void *_addr) +{ + unsigned long *addr = _addr; + addr[nr_base / BITS_PER_LONG] = ~0; +} #endif /* XC_BITOPS_H */