From: Sheng Yang <sheng@linux.intel.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, Sheng Yang <sheng@linux.intel.com>
Subject: [PATCH] kvm: Flush coalesced MMIO buffer periodly
Date: Fri, 22 Jan 2010 10:22:52 +0800 [thread overview]
Message-ID: <1264126972-29758-1-git-send-email-sheng@linux.intel.com> (raw)
In-Reply-To: <4B582A45.3020404@redhat.com>
The default action of coalesced MMIO is, cache the writing in buffer, until:
1. The buffer is full.
2. Or the exit to QEmu due to other reasons.
But this would result in a very late writing in some condition.
1. The each time write to MMIO content is small.
2. The writing interval is big.
3. No need for input or accessing other devices frequently.
This issue was observed in a experimental embbed system. The test image
simply print "test" every 1 seconds. The output in QEmu meets expectation,
but the output in KVM is delayed for seconds.
Per Avi's suggestion, I hooked a flushing for coalesced MMIO buffer in VGA
update handler. By this way, We don't need vcpu explicit exit to QEmu to
handle this issue.
Signed-off-by: Sheng Yang <sheng@linux.intel.com>
---
Like this?
qemu-kvm.c | 26 ++++++++++++++++++++++++--
qemu-kvm.h | 6 ++++++
vl.c | 2 ++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 599c3d6..a9b5107 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -463,6 +463,12 @@ static void kvm_create_vcpu(CPUState *env, int id)
goto err_fd;
}
+#ifdef KVM_CAP_COALESCED_MMIO
+ if (kvm_state->coalesced_mmio && !kvm_state->coalesced_mmio_ring)
+ kvm_state->coalesced_mmio_ring = (void *) env->kvm_run +
+ kvm_state->coalesced_mmio * PAGE_SIZE;
+#endif
+
return;
err_fd:
close(env->kvm_fd);
@@ -927,8 +933,7 @@ int kvm_run(CPUState *env)
#if defined(KVM_CAP_COALESCED_MMIO)
if (kvm_state->coalesced_mmio) {
- struct kvm_coalesced_mmio_ring *ring =
- (void *) run + kvm_state->coalesced_mmio * PAGE_SIZE;
+ struct kvm_coalesced_mmio_ring *ring = kvm_state->coalesced_mmio_ring;
while (ring->first != ring->last) {
cpu_physical_memory_rw(ring->coalesced_mmio[ring->first].phys_addr,
&ring->coalesced_mmio[ring->first].data[0],
@@ -2073,6 +2078,23 @@ static void io_thread_wakeup(void *opaque)
}
}
+#ifdef KVM_CAP_COALESCED_MMIO
+void kvm_flush_coalesced_mmio_buffer(void)
+{
+ if (kvm_state->coalesced_mmio_ring) {
+ struct kvm_coalesced_mmio_ring *ring =
+ kvm_state->coalesced_mmio_ring;
+ while (ring->first != ring->last) {
+ cpu_physical_memory_rw(ring->coalesced_mmio[ring->first].phys_addr,
+ &ring->coalesced_mmio[ring->first].data[0],
+ ring->coalesced_mmio[ring->first].len, 1);
+ smp_wmb();
+ ring->first = (ring->first + 1) % KVM_COALESCED_MMIO_MAX;
+ }
+ }
+}
+#endif
+
int kvm_main_loop(void)
{
int fds[2];
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 6b3e5a1..8188ff6 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -1125,6 +1125,11 @@ static inline int kvm_set_migration_log(int enable)
return kvm_physical_memory_set_dirty_tracking(enable);
}
+#ifdef KVM_CAP_COALESCED_MMIO
+void kvm_flush_coalesced_mmio_buffer(void);
+#else
+void kvm_flush_coalesced_mmio_buffer(void) {}
+#endif
int kvm_irqchip_in_kernel(void);
#ifdef CONFIG_KVM
@@ -1144,6 +1149,7 @@ typedef struct KVMState {
int fd;
int vmfd;
int coalesced_mmio;
+ struct kvm_coalesced_mmio_ring *coalesced_mmio_ring;
int broken_set_mem_region;
int migration_log;
int vcpu_events;
diff --git a/vl.c b/vl.c
index 9edea10..64902f2 100644
--- a/vl.c
+++ b/vl.c
@@ -3235,6 +3235,7 @@ static void gui_update(void *opaque)
interval = dcl->gui_timer_interval;
dcl = dcl->next;
}
+ kvm_flush_coalesced_mmio_buffer();
qemu_mod_timer(ds->gui_timer, interval + qemu_get_clock(rt_clock));
}
@@ -3242,6 +3243,7 @@ static void nographic_update(void *opaque)
{
uint64_t interval = GUI_REFRESH_INTERVAL;
+ kvm_flush_coalesced_mmio_buffer();
qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock));
}
--
1.5.4.5
next prev parent reply other threads:[~2010-01-22 2:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-21 9:37 [PATCH] kvm: Flush coalesced MMIO buffer periodly Sheng Yang
2010-01-21 10:19 ` Avi Kivity
2010-01-22 2:22 ` Sheng Yang [this message]
2010-01-24 7:35 ` Avi Kivity
2010-01-25 7:45 ` Sheng Yang
-- strict thread matches above, loose matches on Subject: below --
2010-01-25 7:46 Sheng Yang
2010-01-25 16:08 ` Marcelo Tosatti
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=1264126972-29758-1-git-send-email-sheng@linux.intel.com \
--to=sheng@linux.intel.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
/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