From patchwork Fri Jul 15 02:47:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 9231101 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 BF69F60574 for ; Fri, 15 Jul 2016 02:56:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B60B6281A7 for ; Fri, 15 Jul 2016 02:56:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AAD6828326; Fri, 15 Jul 2016 02:56:07 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E4B7281A7 for ; Fri, 15 Jul 2016 02:56:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752377AbcGOC4D (ORCPT ); Thu, 14 Jul 2016 22:56:03 -0400 Received: from mga01.intel.com ([192.55.52.88]:10619 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752353AbcGOC4A (ORCPT ); Thu, 14 Jul 2016 22:56:00 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga101.fm.intel.com with ESMTP; 14 Jul 2016 19:56:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,365,1464678000"; d="scan'208";a="139539001" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.123]) by fmsmga004.fm.intel.com with ESMTP; 14 Jul 2016 19:55:58 -0700 From: Liang Li To: qemu-devel@nongnu.org Cc: mst@redhat.com, pbonzini@redhat.com, quintela@redhat.com, amit.shah@redhat.com, kvm@vger.kernel.org, dgilbert@redhat.com, thuth@redhat.com, Liang Li Subject: [QEMU v2 7/9] bitmap: Add a new bitmap_move function Date: Fri, 15 Jul 2016 10:47:27 +0800 Message-Id: <1468550849-22172-8-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> References: <1468550849-22172-1-git-send-email-liang.z.li@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Sometimes, it is need to move a portion of bitmap to another place in a large bitmap, if overlap happens, the bitmap_copy can't not work correctly, we need a new function to do this work. Signed-off-by: Liang Li Reviewed-by: Dr. David Alan Gilbert --- include/qemu/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index ec5146f..6ac89ca 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -37,6 +37,7 @@ * bitmap_set(dst, pos, nbits) Set specified bit area * bitmap_set_atomic(dst, pos, nbits) Set specified bit area with atomic ops * bitmap_clear(dst, pos, nbits) Clear specified bit area + * bitmap_move(dst, src, nbits) Move *src to *dst * bitmap_test_and_clear_atomic(dst, pos, nbits) Test and clear area * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area */ @@ -136,6 +137,18 @@ static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, } } +static inline void bitmap_move(unsigned long *dst, const unsigned long *src, + long nbits) +{ + if (small_nbits(nbits)) { + unsigned long tmp = *src; + *dst = tmp; + } else { + long len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + memmove(dst, src, len); + } +} + static inline int bitmap_and(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, long nbits) {