From patchwork Tue Apr 6 00:51:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshiaki Tamura X-Patchwork-Id: 90716 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o360vZ9B030505 for ; Tue, 6 Apr 2010 00:57:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756510Ab0DFA5d (ORCPT ); Mon, 5 Apr 2010 20:57:33 -0400 Received: from sh.osrg.net ([192.16.179.4]:47262 "EHLO sh.osrg.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756242Ab0DFA5S (ORCPT ); Mon, 5 Apr 2010 20:57:18 -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 o360uqao018728; Tue, 6 Apr 2010 09:56:52 +0900 Received: from localhost (hype-wd0.osrg.net [10.72.1.16]) by fs.osrg.net (Postfix) with ESMTP id 449633E02EE; Tue, 6 Apr 2010 09:56:50 +0900 (JST) From: Yoshiaki Tamura To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: avi@redhat.com, anthony@codemonkey.ws, aliguori@us.ibm.com, mtosatti@redhat.com, ohmura.kei@lab.ntt.co.jp, Yoshiaki Tamura Subject: [PATCH v2 5/6] Use cpu_physical_memory_set_dirty_range() to update phys_ram_dirty. Date: Tue, 6 Apr 2010 09:51:23 +0900 Message-Id: <1270515084-24120-6-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Mailer: git-send-email 1.7.0.31.g1df487 In-Reply-To: <1270515084-24120-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> References: <1270515084-24120-1-git-send-email-tamura.yoshiaki@lab.ntt.co.jp> X-Dispatcher: imput version 20070423(IM149) Lines: 96 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 06 Apr 2010 00:57:36 +0000 (UTC) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (sh.osrg.net [192.16.179.4]); Tue, 06 Apr 2010 09:56:52 +0900 (JST) X-Virus-Scanned: clamav-milter 0.95.3 at sh X-Virus-Status: Clean Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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);