From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org
Cc: Marcelo Tosatti <mtosatti@redhat.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [uq/master patch 4/5] kvm: port qemu-kvm's bitmap scanning
Date: Fri, 23 Apr 2010 14:04:14 -0300 [thread overview]
Message-ID: <20100423170646.131945715@amt.cnet> (raw)
In-Reply-To: 20100423170410.914857113@amt.cnet
[-- Attachment #1: use-qemukvm-bitmap-scan --]
[-- Type: text/plain, Size: 3517 bytes --]
Which is significantly faster.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu-kvm/kvm-all.c
===================================================================
--- qemu-kvm.orig/kvm-all.c
+++ qemu-kvm/kvm-all.c
@@ -26,6 +26,7 @@
#include "hw/hw.h"
#include "gdbstub.h"
#include "kvm.h"
+#include "bswap.h"
/* KVM uses PAGE_SIZE in it's definition of COALESCED_MMIO_MAX */
#define PAGE_SIZE TARGET_PAGE_SIZE
@@ -305,11 +306,41 @@ static int kvm_set_migration_log(int ena
return 0;
}
-static int test_le_bit(unsigned long nr, unsigned char *addr)
-{
- return (addr[nr >> 3] >> (nr & 7)) & 1;
+/* get kvm's dirty pages bitmap and update qemu's */
+static int kvm_get_dirty_pages_log_range(unsigned long start_addr,
+ unsigned long *bitmap,
+ unsigned long offset,
+ unsigned long mem_size)
+{
+ unsigned int i, j;
+ unsigned long page_number, addr, addr1, c;
+ ram_addr_t ram_addr;
+ unsigned int len = ((mem_size / TARGET_PAGE_SIZE) + HOST_LONG_BITS - 1) /
+ HOST_LONG_BITS;
+
+ /*
+ * 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;
+ addr1 = page_number * TARGET_PAGE_SIZE;
+ addr = offset + addr1;
+ ram_addr = cpu_get_physical_page_desc(addr);
+ cpu_physical_memory_set_dirty(ram_addr);
+ } while (c != 0);
+ }
+ }
+ return 0;
}
+#define ALIGN(x, y) (((x)+(y)-1) & ~((y)-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().
@@ -323,8 +354,6 @@ static int kvm_physical_sync_dirty_bitma
{
KVMState *s = kvm_state;
unsigned long size, allocated_size = 0;
- target_phys_addr_t phys_addr;
- ram_addr_t addr;
KVMDirtyLog d;
KVMSlot *mem;
int ret = 0;
@@ -336,7 +365,7 @@ static int kvm_physical_sync_dirty_bitma
break;
}
- size = ((mem->memory_size >> TARGET_PAGE_BITS) + 7) / 8;
+ size = ALIGN(((mem->memory_size) >> TARGET_PAGE_BITS), HOST_LONG_BITS) / 8;
if (!d.dirty_bitmap) {
d.dirty_bitmap = qemu_malloc(size);
} else if (size > allocated_size) {
@@ -353,17 +382,9 @@ static int kvm_physical_sync_dirty_bitma
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);
- }
- }
- start_addr = phys_addr;
+ kvm_get_dirty_pages_log_range(mem->start_addr, d.dirty_bitmap,
+ mem->start_addr, mem->memory_size);
+ start_addr = mem->start_addr + mem->memory_size;
}
qemu_free(d.dirty_bitmap);
next prev parent reply other threads:[~2010-04-23 17:08 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-23 17:04 [Qemu-devel] [uq/master patch 0/5] prepare for qemu-kvm's usage of upstream memslot code Marcelo Tosatti
2010-04-23 17:04 ` [Qemu-devel] [uq/master patch 1/5] vga: fix typo in length passed to kvm_log_stop Marcelo Tosatti
2010-04-23 17:04 ` [Qemu-devel] [uq/master patch 2/5] kvm: add logging count to slots Marcelo Tosatti
2010-04-24 7:34 ` [Qemu-devel] " Jan Kiszka
2010-04-25 12:33 ` Avi Kivity
2010-04-25 13:57 ` Jan Kiszka
2010-04-25 14:17 ` Avi Kivity
2010-04-25 14:29 ` Jan Kiszka
2010-04-25 14:41 ` Avi Kivity
2010-04-25 14:51 ` Jan Kiszka
2010-04-25 14:58 ` Avi Kivity
2010-04-25 15:07 ` Jan Kiszka
2010-04-25 15:22 ` Avi Kivity
2010-04-25 16:42 ` Jan Kiszka
2010-04-26 5:37 ` Avi Kivity
2010-04-26 13:47 ` Marcelo Tosatti
2010-04-23 17:04 ` [Qemu-devel] [uq/master patch 3/5] introduce leul_to_cpu Marcelo Tosatti
2010-04-23 17:04 ` Marcelo Tosatti [this message]
2010-04-23 17:04 ` [Qemu-devel] [uq/master patch 5/5] introduce qemu_ram_map Marcelo Tosatti
2010-04-25 12:33 ` [Qemu-devel] Re: [uq/master patch 0/5] prepare for qemu-kvm's usage of upstream memslot code Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100423170646.131945715@amt.cnet \
--to=mtosatti@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).