From patchwork Wed Jul 12 12:40:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Wei W" X-Patchwork-Id: 9836611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9F27B602BD for ; Wed, 12 Jul 2017 12:49:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 912BE26E4A for ; Wed, 12 Jul 2017 12:49:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 859B628500; Wed, 12 Jul 2017 12:49:06 +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=-6.9 required=2.0 tests=BAYES_00,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 3089026E4A for ; Wed, 12 Jul 2017 12:49:06 +0000 (UTC) Received: from localhost ([::1]:52563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVH4j-0005oY-54 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Jul 2017 08:49:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVH3K-0005lv-5t for qemu-devel@nongnu.org; Wed, 12 Jul 2017 08:47:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVH3J-0003S4-31 for qemu-devel@nongnu.org; Wed, 12 Jul 2017 08:47:38 -0400 Received: from mga06.intel.com ([134.134.136.31]:42654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVH3I-0003Lp-Ob for qemu-devel@nongnu.org; Wed, 12 Jul 2017 08:47:36 -0400 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP; 12 Jul 2017 05:47:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,349,1496127600"; d="scan'208";a="124248016" Received: from devel-ww.sh.intel.com ([10.239.48.97]) by orsmga005.jf.intel.com with ESMTP; 12 Jul 2017 05:47:33 -0700 From: Wei Wang To: linux-kernel@vger.kernel.org, qemu-devel@nongnu.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, linux-mm@kvack.org, mst@redhat.com, david@redhat.com, cornelia.huck@de.ibm.com, akpm@linux-foundation.org, mgorman@techsingularity.net, aarcange@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, wei.w.wang@intel.com, liliang.opensource@gmail.com Date: Wed, 12 Jul 2017 20:40:17 +0800 Message-Id: <1499863221-16206-5-git-send-email-wei.w.wang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499863221-16206-1-git-send-email-wei.w.wang@intel.com> References: <1499863221-16206-1-git-send-email-wei.w.wang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.31 Subject: [Qemu-devel] [PATCH v12 4/8] xbitmap: add xb_find_next_bit() and xb_zero() 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: yang.zhang.wz@gmail.com, virtio-dev@lists.oasis-open.org, quan.xu@aliyun.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP xb_find_next_bit() is added to support find the next "1" or "0" bit in the given range. xb_zero() is added to support zero the given range of bits. Signed-off-by: Wei Wang --- include/linux/xbitmap.h | 4 ++++ lib/radix-tree.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/xbitmap.h b/include/linux/xbitmap.h index 0b93a46..88c2045 100644 --- a/include/linux/xbitmap.h +++ b/include/linux/xbitmap.h @@ -36,6 +36,10 @@ int xb_set_bit(struct xb *xb, unsigned long bit); bool xb_test_bit(const struct xb *xb, unsigned long bit); int xb_clear_bit(struct xb *xb, unsigned long bit); +void xb_zero(struct xb *xb, unsigned long start, unsigned long end); +unsigned long xb_find_next_bit(struct xb *xb, unsigned long start, + unsigned long end, bool set); + static inline bool xb_empty(const struct xb *xb) { return radix_tree_empty(&xb->xbrt); diff --git a/lib/radix-tree.c b/lib/radix-tree.c index d624914..c45b910 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -2271,6 +2271,32 @@ bool xb_test_bit(const struct xb *xb, unsigned long bit) return test_bit(bit, bitmap->bitmap); } +void xb_zero(struct xb *xb, unsigned long start, unsigned long end) +{ + unsigned long i; + + for (i = start; i <= end; i++) + xb_clear_bit(xb, i); +} + +/* + * Find the next one (@set = 1) or zero (@set = 0) bit within the bit range + * from @start to @end in @xb. If no such bit is found in the given range, + * bit end + 1 will be returned. + */ +unsigned long xb_find_next_bit(struct xb *xb, unsigned long start, + unsigned long end, bool set) +{ + unsigned long i; + + for (i = start; i <= end; i++) { + if (xb_test_bit(xb, i) == set) + break; + } + + return i; +} + void __rcu **idr_get_free(struct radix_tree_root *root, struct radix_tree_iter *iter, gfp_t gfp, int end) {