From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MVNmR-0000nG-Em for qemu-devel@nongnu.org; Mon, 27 Jul 2009 06:50:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MVNmM-0000n4-2S for qemu-devel@nongnu.org; Mon, 27 Jul 2009 06:50:06 -0400 Received: from [199.232.76.173] (port=56791 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MVNmL-0000n1-Sr for qemu-devel@nongnu.org; Mon, 27 Jul 2009 06:50:01 -0400 Received: from cantor2.suse.de ([195.135.220.15]:37410 helo=mx2.suse.de) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MVNmL-0000sS-8r for qemu-devel@nongnu.org; Mon, 27 Jul 2009 06:50:01 -0400 From: Alexander Graf Date: Mon, 27 Jul 2009 12:49:56 +0200 Message-Id: <1248691796-54179-1-git-send-email-agraf@suse.de> Subject: [Qemu-devel] [PATCH] Use Little Endian for Dirty Log List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: avi@redhat.com We currently use host endian long types to store information in the dirty bitmap. This works reasonably well on Little Endian targets, because the u32 after the first contains the next 32 bits. On Big Endian this breaks completely though, forcing us to be inventive here. So Ben suggested to always use Little Endian, which looks reasonable. We only have dirty bitmap implemented in Little Endian targets so far and since PowerPC would be the first Big Endian platform, we can just as well switch to Little Endian always with little effort without breaking existing targets. This is the userspace part of the patch. It shouldn't change anything for existing targets, but help PowerPC. It replaces my older patch called "Use 64bit pointer for dirty log". Signed-off-by: Alexander Graf --- kvm-all.c | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/kvm-all.c b/kvm-all.c index 824bb4c..91d9333 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -304,6 +304,11 @@ 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(). @@ -357,12 +362,10 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, 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 long *bitmap = (unsigned long *)d.dirty_bitmap; + unsigned char *bitmap = (unsigned char *)d.dirty_bitmap; unsigned nr = (phys_addr - mem->start_addr) >> TARGET_PAGE_BITS; - unsigned word = nr / (sizeof(*bitmap) * 8); - unsigned bit = nr % (sizeof(*bitmap) * 8); - if ((bitmap[word] >> bit) & 1) { + if (test_le_bit(nr, bitmap)) { cpu_physical_memory_set_dirty(addr); } else if (r < 0) { /* When our KVM implementation doesn't know about dirty logging -- 1.6.0.2