From patchwork Tue Apr 19 14:20:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 8880781 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 42964BF29F for ; Tue, 19 Apr 2016 14:29:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 73D1D20279 for ; Tue, 19 Apr 2016 14:29:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85AAB2026F for ; Tue, 19 Apr 2016 14:29:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754459AbcDSO3y (ORCPT ); Tue, 19 Apr 2016 10:29:54 -0400 Received: from mga03.intel.com ([134.134.136.65]:59749 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752775AbcDSO3y (ORCPT ); Tue, 19 Apr 2016 10:29:54 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 19 Apr 2016 07:29:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,506,1455004800"; d="scan'208";a="958262712" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by orsmga002.jf.intel.com with ESMTP; 19 Apr 2016 07:29:50 -0700 From: Liang Li To: mst@redhat.com, quintela@redhat.com, amit.shah@redhat.com, pbonzini@redhat.com, lcapitulino@redhat.com Cc: armbru@redhat.com, peter.maydell@linaro.org, rth@twiddle.net, ehabkost@redhat.com, james.hogan@imgtec.com, aurelien@aurel32.net, leon.alrae@imgtec.com, agraf@suse.de, borntraeger@de.ibm.com, cornelia.huck@de.ibm.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, Liang Li Subject: [PATCH QEMU 1/5] bitmap: Add a new bitmap_move function Date: Tue, 19 Apr 2016 22:20:39 +0800 Message-Id: <1461075643-3668-2-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461075643-3668-1-git-send-email-liang.z.li@intel.com> References: <1461075643-3668-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-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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 --- include/qemu/bitmap.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 0e33fa5..ce07444 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -38,6 +38,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 */ @@ -137,6 +138,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) {