From patchwork Tue Apr 20 03:40:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 50511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D7E8FB7D20 for ; Tue, 20 Apr 2010 14:21:09 +1000 (EST) Received: from localhost ([127.0.0.1]:41515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O44Rw-0001Js-Ob for incoming@patchwork.ozlabs.org; Mon, 19 Apr 2010 23:48:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O44MG-0008V9-RV for qemu-devel@nongnu.org; Mon, 19 Apr 2010 23:42:44 -0400 Received: from [140.186.70.92] (port=38932 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O44MC-0008SD-TC for qemu-devel@nongnu.org; Mon, 19 Apr 2010 23:42:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O44MA-0001it-AL for qemu-devel@nongnu.org; Mon, 19 Apr 2010 23:42:40 -0400 Received: from sh.osrg.net ([192.16.179.4]:56399) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O44M9-0001iT-OT for qemu-devel@nongnu.org; Mon, 19 Apr 2010 23:42:38 -0400 Received: from fs.osrg.net (postfix@fs.osrg.net [10.0.0.12]) by sh.osrg.net (8.14.3/8.14.3/OSRG-NET) with ESMTP id o3K3gSAe017541; Tue, 20 Apr 2010 12:42:29 +0900 Received: from localhost (hype-wd0.osrg.net [10.72.1.16]) by fs.osrg.net (Postfix) with ESMTP id B8CD03E02F0; Tue, 20 Apr 2010 12:42:28 +0900 (JST) From: Yoshiaki Tamura To: qemu-devel@nongnu.org Date: Tue, 20 Apr 2010 12:40:42 +0900 Message-Id: <1271734843-24231-4-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.31.g1df487 In-Reply-To: <1271734843-24231-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1271734843-24231-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 96 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Tue, 20 Apr 2010 12:42:30 +0900 (JST) X-Virus-Scanned: clamav-milter 0.95.3 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: aliguori@us.ibm.com, ohmura.kei@lab.ntt.co.jp, mtosatti@redhat.com, Yoshiaki Tamura , avi@redhat.com Subject: [Qemu-devel] [PATCH v4 3/4] Use cpu_physical_memory_set_dirty_range() to update phys_ram_dirty. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Modifies kvm_physical_sync_dirty_bitmap to use cpu_physical_memory_set_dirty_range() to update the row of the bit-based phys_ram_dirty bitmap at once. Signed-off-by: OHMURA Kei Signed-off-by: Yoshiaki Tamura --- bswap.h | 2 ++ kvm-all.c | 33 +++++++++++++++------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/bswap.h b/bswap.h index aace9b7..956f3fa 100644 --- a/bswap.h +++ b/bswap.h @@ -205,8 +205,10 @@ static inline void cpu_to_be32wu(uint32_t *p, uint32_t v) #ifdef HOST_WORDS_BIGENDIAN #define cpu_to_32wu cpu_to_be32wu +#define leul_to_cpu(v) le ## HOST_LONG_BITS ## _to_cpu(v) #else #define cpu_to_32wu cpu_to_le32wu +#define leul_to_cpu(v) (v) #endif #undef le_bswap diff --git a/kvm-all.c b/kvm-all.c index 7aa5e57..db762ff 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -282,11 +282,6 @@ static int kvm_set_migration_log(int enable) return 0; } -static int test_le_bit(unsigned long nr, unsigned char *addr) -{ - return (addr[nr >> 3] >> (nr & 7)) & 1; -} - /** * kvm_physical_sync_dirty_bitmap - Grab dirty bitmap from kernel space * This function updates qemu's dirty bitmap using cpu_physical_memory_set_dirty(). @@ -299,9 +294,9 @@ static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_addr_t end_addr) { KVMState *s = kvm_state; - unsigned long size, allocated_size = 0; - target_phys_addr_t phys_addr; - ram_addr_t addr; + unsigned long size, page_number, addr, addr1, *bitmap, + allocated_size = 0; + unsigned int i, len; KVMDirtyLog d; KVMSlot *mem; int ret = 0; @@ -313,7 +308,8 @@ static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, break; } - size = ((mem->memory_size >> TARGET_PAGE_BITS) + 7) / 8; + size = ((mem->memory_size >> TARGET_PAGE_BITS) + HOST_LONG_BITS - 1) / + HOST_LONG_BITS * HOST_LONG_SIZE; if (!d.dirty_bitmap) { d.dirty_bitmap = qemu_malloc(size); } else if (size > allocated_size) { @@ -330,17 +326,18 @@ static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, break; } - for (phys_addr = mem->start_addr, addr = mem->phys_offset; - phys_addr < mem->start_addr + mem->memory_size; - phys_addr += TARGET_PAGE_SIZE, addr += TARGET_PAGE_SIZE) { - unsigned char *bitmap = (unsigned char *)d.dirty_bitmap; - unsigned nr = (phys_addr - mem->start_addr) >> TARGET_PAGE_BITS; - - if (test_le_bit(nr, bitmap)) { - cpu_physical_memory_set_dirty(addr); + bitmap = (unsigned long *)d.dirty_bitmap; + len = size / HOST_LONG_SIZE; + for (i = 0; i < len; i++) { + if (bitmap[i] != 0) { + page_number = i * HOST_LONG_BITS; + addr1 = page_number * TARGET_PAGE_SIZE; + addr = mem->phys_offset + addr1; + cpu_physical_memory_set_dirty_range(addr, + leul_to_cpu(bitmap[i])); } } - start_addr = phys_addr; + start_addr = mem->start_addr + mem->memory_size; } qemu_free(d.dirty_bitmap);