{"id":806489,"url":"http://patchwork.ozlabs.org/api/1.0/patches/806489/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<1503914913-28893-3-git-send-email-wei.w.wang@intel.com>","date":"2017-08-28T10:08:30","name":"[v15,2/5] lib/xbitmap: add xb_find_next_bit() and xb_zero()","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"facc9a4bea9674e76570107c555e18bf374cb26b","submitter":{"id":69100,"url":"http://patchwork.ozlabs.org/api/1.0/people/69100/?format=json","name":"Wang, Wei W","email":"wei.w.wang@intel.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/1503914913-28893-3-git-send-email-wei.w.wang@intel.com/mbox/","series":[{"id":126,"url":"http://patchwork.ozlabs.org/api/1.0/series/126/?format=json","date":"2017-08-28T10:08:28","name":"Virtio-balloon Enhancement","version":15,"mbox":"http://patchwork.ozlabs.org/series/126/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/806489/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xgnsG29tqz9ryr\n\tfor <incoming@patchwork.ozlabs.org>;\n\tMon, 28 Aug 2017 20:22:58 +1000 (AEST)","from localhost ([::1]:37857 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1dmHC4-00033Y-6O\n\tfor incoming@patchwork.ozlabs.org; Mon, 28 Aug 2017 06:22:56 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:57813)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <wei.w.wang@intel.com>) id 1dmH9k-0001xb-MW\n\tfor qemu-devel@nongnu.org; Mon, 28 Aug 2017 06:20:33 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <wei.w.wang@intel.com>) id 1dmH9j-0005zu-L9\n\tfor qemu-devel@nongnu.org; Mon, 28 Aug 2017 06:20:32 -0400","from mga04.intel.com ([192.55.52.120]:17236)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <wei.w.wang@intel.com>)\n\tid 1dmH9j-0005ys-CR\n\tfor qemu-devel@nongnu.org; Mon, 28 Aug 2017 06:20:31 -0400","from orsmga003.jf.intel.com ([10.7.209.27])\n\tby fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t28 Aug 2017 03:20:30 -0700","from devel-ww.sh.intel.com ([10.239.48.92])\n\tby orsmga003.jf.intel.com with ESMTP; 28 Aug 2017 03:20:26 -0700"],"X-ExtLoop1":"1","X-IronPort-AV":"E=Sophos; i=\"5.41,441,1498546800\"; d=\"scan'208\";\n\ta=\"1008318951\"","From":"Wei Wang <wei.w.wang@intel.com>","To":"virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org,\n\tqemu-devel@nongnu.org, virtualization@lists.linux-foundation.org,\n\tkvm@vger.kernel.org, linux-mm@kvack.org, mst@redhat.com,\n\tmhocko@kernel.org, akpm@linux-foundation.org, mawilcox@microsoft.com","Date":"Mon, 28 Aug 2017 18:08:30 +0800","Message-Id":"<1503914913-28893-3-git-send-email-wei.w.wang@intel.com>","X-Mailer":"git-send-email 2.7.4","In-Reply-To":"<1503914913-28893-1-git-send-email-wei.w.wang@intel.com>","References":"<1503914913-28893-1-git-send-email-wei.w.wang@intel.com>","X-detected-operating-system":"by eggs.gnu.org: Genre and OS details not\n\trecognized.","X-Received-From":"192.55.52.120","Subject":"[Qemu-devel] [PATCH v15 2/5] lib/xbitmap: add xb_find_next_bit()\n\tand xb_zero()","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"aarcange@redhat.com, yang.zhang.wz@gmail.com, david@redhat.com,\n\tliliang.opensource@gmail.com, willy@infradead.org,\n\tamit.shah@redhat.com, wei.w.wang@intel.com, quan.xu@aliyun.com,\n\tcornelia.huck@de.ibm.com, pbonzini@redhat.com,\n\tmgorman@techsingularity.net","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"xb_find_next_bit() is used to find the next \"1\" or \"0\" bit in the\ngiven range. xb_zero() is used to zero the given range of bits.\n\nSigned-off-by: Wei Wang <wei.w.wang@intel.com>\nCc: Andrew Morton <akpm@linux-foundation.org>\nCc: Matthew Wilcox <mawilcox@microsoft.com>\nCc: Michal Hocko <mhocko@kernel.org>\nCc: Michael S. Tsirkin <mst@redhat.com>\n---\n include/linux/xbitmap.h |  3 +++\n lib/xbitmap.c           | 39 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 42 insertions(+)","diff":"diff --git a/include/linux/xbitmap.h b/include/linux/xbitmap.h\nindex 25b05ff..0061f7a 100644\n--- a/include/linux/xbitmap.h\n+++ b/include/linux/xbitmap.h\n@@ -38,6 +38,9 @@ static inline void xb_init(struct xb *xb)\n int xb_set_bit(struct xb *xb, unsigned long bit);\n bool xb_test_bit(struct xb *xb, unsigned long bit);\n void xb_clear_bit(struct xb *xb, unsigned long bit);\n+void xb_zero(struct xb *xb, unsigned long start, unsigned long end);\n+unsigned long xb_find_next_bit(struct xb *xb, unsigned long start,\n+\t\t\t       unsigned long end, bool set);\n \n /* Check if the xb tree is empty */\n static inline bool xb_is_empty(const struct xb *xb)\ndiff --git a/lib/xbitmap.c b/lib/xbitmap.c\nindex 8c55296..b9e2a0c 100644\n--- a/lib/xbitmap.c\n+++ b/lib/xbitmap.c\n@@ -174,3 +174,42 @@ void xb_preload(gfp_t gfp)\n \t}\n }\n EXPORT_SYMBOL(xb_preload);\n+\n+/**\n+ *  xb_zero - zero a range of bits in the xbitmap\n+ *  @xb: the xbitmap that the bits reside in\n+ *  @start: the start of the range, inclusive\n+ *  @end: the end of the range, inclusive\n+ */\n+void xb_zero(struct xb *xb, unsigned long start, unsigned long end)\n+{\n+\tunsigned long i;\n+\n+\tfor (i = start; i <= end; i++)\n+\t\txb_clear_bit(xb, i);\n+}\n+EXPORT_SYMBOL(xb_zero);\n+\n+/**\n+ * xb_find_next_bit - find next 1 or 0 in the give range of bits\n+ * @xb: the xbitmap that the bits reside in\n+ * @start: the start of the range, inclusive\n+ * @end: the end of the range, inclusive\n+ * @set: the polarity (1 or 0) of the next bit to find\n+ *\n+ * Return the index of the found bit in the xbitmap. If the returned index\n+ * exceeds @end, it indicates that no such bit is found in the given range.\n+ */\n+unsigned long xb_find_next_bit(struct xb *xb, unsigned long start,\n+\t\t\t       unsigned long end, bool set)\n+{\n+\tunsigned long i;\n+\n+\tfor (i = start; i <= end; i++) {\n+\t\tif (xb_test_bit(xb, i) == set)\n+\t\t\tbreak;\n+\t}\n+\n+\treturn i;\n+}\n+EXPORT_SYMBOL(xb_find_next_bit);\n","prefixes":["v15","2/5"]}