From patchwork Tue Dec 17 15:26:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 302249 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 821EA2C0079 for ; Wed, 18 Dec 2013 02:37:16 +1100 (EST) Received: from localhost ([::1]:33908 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vswht-0007Yc-KC for incoming@patchwork.ozlabs.org; Tue, 17 Dec 2013 10:37:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VswY4-0002iZ-N0 for qemu-devel@nongnu.org; Tue, 17 Dec 2013 10:27:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VswXy-00012U-Gp for qemu-devel@nongnu.org; Tue, 17 Dec 2013 10:27:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:6915) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VswXx-000118-UW for qemu-devel@nongnu.org; Tue, 17 Dec 2013 10:26:58 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rBHFQvGX024074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Dec 2013 10:26:57 -0500 Received: from trasno.mitica (ovpn-113-86.phx2.redhat.com [10.3.113.86]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rBHFQExG029768; Tue, 17 Dec 2013 10:26:56 -0500 From: Juan Quintela To: qemu-devel@nongnu.org Date: Tue, 17 Dec 2013 16:26:10 +0100 Message-Id: <1387293974-24718-35-git-send-email-quintela@redhat.com> In-Reply-To: <1387293974-24718-1-git-send-email-quintela@redhat.com> References: <1387293974-24718-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 34/38] memory: move bitmap synchronization to its own function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We want to have all the functions that handle directly the dirty bitmap near. We will change it later. Signed-off-by: Juan Quintela Reviewed-by: Orit Wasserman --- include/exec/ram_addr.h | 31 +++++++++++++++++++++++++++++++ kvm-all.c | 27 ++------------------------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index db977fb..c6736ed 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -79,6 +79,37 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start, xen_modified_memory(start, length); } +static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap, + ram_addr_t start, + ram_addr_t pages) +{ + unsigned int i, j; + unsigned long page_number, c; + hwaddr addr; + ram_addr_t ram_addr; + unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS; + unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE; + + /* + * bitmap-traveling is faster than memory-traveling (for addr...) + * especially when most of the memory is not dirty. + */ + for (i = 0; i < len; i++) { + if (bitmap[i] != 0) { + c = leul_to_cpu(bitmap[i]); + do { + j = ffsl(c) - 1; + c &= ~(1ul << j); + page_number = (i * HOST_LONG_BITS + j) * hpratio; + addr = page_number * TARGET_PAGE_SIZE; + ram_addr = start + addr; + cpu_physical_memory_set_dirty_range(ram_addr, + TARGET_PAGE_SIZE * hpratio); + } while (c != 0); + } + } +} + static inline void cpu_physical_memory_clear_dirty_range(ram_addr_t start, ram_addr_t length, unsigned client) diff --git a/kvm-all.c b/kvm-all.c index cb62ba4..0bfb060 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -380,33 +380,10 @@ static int kvm_set_migration_log(int enable) static int kvm_get_dirty_pages_log_range(MemoryRegionSection *section, unsigned long *bitmap) { - unsigned int i, j; - unsigned long page_number, c; - hwaddr addr; ram_addr_t start = section->offset_within_region + section->mr->ram_addr; - ram_addr_t ram_addr; - unsigned int pages = int128_get64(section->size) / getpagesize(); - unsigned int len = (pages + HOST_LONG_BITS - 1) / HOST_LONG_BITS; - unsigned long hpratio = getpagesize() / TARGET_PAGE_SIZE; + ram_addr_t pages = int128_get64(section->size) / getpagesize(); - /* - * bitmap-traveling is faster than memory-traveling (for addr...) - * especially when most of the memory is not dirty. - */ - for (i = 0; i < len; i++) { - if (bitmap[i] != 0) { - c = leul_to_cpu(bitmap[i]); - do { - j = ffsl(c) - 1; - c &= ~(1ul << j); - page_number = (i * HOST_LONG_BITS + j) * hpratio; - addr = page_number * TARGET_PAGE_SIZE; - ram_addr = start + addr; - cpu_physical_memory_set_dirty_range(ram_addr, - TARGET_PAGE_SIZE * hpratio); - } while (c != 0); - } - } + cpu_physical_memory_set_dirty_lebitmap(bitmap, start, pages); return 0; }