From patchwork Wed Feb 3 23:55:46 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 44436 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 7E7FAB7D36 for ; Thu, 4 Feb 2010 11:14:06 +1100 (EST) Received: from localhost ([127.0.0.1]:41569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NcpHh-00028A-3z for incoming@patchwork.ozlabs.org; Wed, 03 Feb 2010 19:09:25 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ncp6D-0007Ct-Hb for qemu-devel@nongnu.org; Wed, 03 Feb 2010 18:57:33 -0500 Received: from [199.232.76.173] (port=56407 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ncp6C-0007C9-9S for qemu-devel@nongnu.org; Wed, 03 Feb 2010 18:57:32 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Ncp68-00043V-Qy for qemu-devel@nongnu.org; Wed, 03 Feb 2010 18:57:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35268) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Ncp67-00043L-LV for qemu-devel@nongnu.org; Wed, 03 Feb 2010 18:57:28 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o13NvOTV012212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 3 Feb 2010 18:57:24 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o13NvOvh013524; Wed, 3 Feb 2010 18:57:24 -0500 Received: from amt.cnet (vpn-9-161.rdu.redhat.com [10.11.9.161]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o13NvMoJ026865; Wed, 3 Feb 2010 18:57:22 -0500 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id C8FCE68A8EE; Wed, 3 Feb 2010 21:56:14 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o13NuArV013142; Wed, 3 Feb 2010 21:56:10 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Wed, 3 Feb 2010 21:55:46 -0200 Message-Id: <62a2744ca09a0b44b8406ea0c430c4c67a2c3231.1265241351.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Sheng Yang Subject: [Qemu-devel] [PATCH 1/6] kvm: Flush coalesced MMIO buffer periodly 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 From: Sheng Yang 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 flushing 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 Signed-off-by: Marcelo Tosatti --- cpu-all.h | 2 ++ exec.c | 6 ++++++ kvm-all.c | 23 +++++++++++++++-------- kvm.h | 1 + vl.c | 2 ++ 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 57b69f8..1ccc9a8 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -915,6 +915,8 @@ void qemu_register_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size); void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size); +void qemu_flush_coalesced_mmio_buffer(void); + /*******************************************/ /* host CPU ticks (if available) */ diff --git a/exec.c b/exec.c index 76831a1..67fabae 100644 --- a/exec.c +++ b/exec.c @@ -2406,6 +2406,12 @@ void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size) kvm_uncoalesce_mmio_region(addr, size); } +void qemu_flush_coalesced_mmio_buffer(void) +{ + if (kvm_enabled()) + kvm_flush_coalesced_mmio_buffer(); +} + ram_addr_t qemu_ram_alloc(ram_addr_t size) { RAMBlock *new_block; diff --git a/kvm-all.c b/kvm-all.c index 15ec38e..f8350c9 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -59,6 +59,9 @@ struct KVMState int vmfd; int regs_modified; int coalesced_mmio; +#ifdef KVM_CAP_COALESCED_MMIO + struct kvm_coalesced_mmio_ring *coalesced_mmio_ring; +#endif int broken_set_mem_region; int migration_log; int vcpu_events; @@ -200,6 +203,12 @@ int kvm_init_vcpu(CPUState *env) goto err; } +#ifdef KVM_CAP_COALESCED_MMIO + if (s->coalesced_mmio && !s->coalesced_mmio_ring) + s->coalesced_mmio_ring = (void *) env->kvm_run + + s->coalesced_mmio * PAGE_SIZE; +#endif + ret = kvm_arch_init_vcpu(env); if (ret == 0) { qemu_register_reset(kvm_reset_vcpu, env); @@ -466,10 +475,10 @@ int kvm_init(int smp_cpus) goto err; } + s->coalesced_mmio = 0; #ifdef KVM_CAP_COALESCED_MMIO s->coalesced_mmio = kvm_check_extension(s, KVM_CAP_COALESCED_MMIO); -#else - s->coalesced_mmio = 0; + s->coalesced_mmio_ring = NULL; #endif s->broken_set_mem_region = 1; @@ -544,14 +553,12 @@ static int kvm_handle_io(uint16_t port, void *data, int direction, int size, return 1; } -static void kvm_run_coalesced_mmio(CPUState *env, struct kvm_run *run) +void kvm_flush_coalesced_mmio_buffer(void) { #ifdef KVM_CAP_COALESCED_MMIO KVMState *s = kvm_state; - if (s->coalesced_mmio) { - struct kvm_coalesced_mmio_ring *ring; - - ring = (void *)run + (s->coalesced_mmio * TARGET_PAGE_SIZE); + if (s->coalesced_mmio_ring) { + struct kvm_coalesced_mmio_ring *ring = s->coalesced_mmio_ring; while (ring->first != ring->last) { struct kvm_coalesced_mmio *ent; @@ -609,7 +616,7 @@ int kvm_cpu_exec(CPUState *env) abort(); } - kvm_run_coalesced_mmio(env, run); + kvm_flush_coalesced_mmio_buffer(); ret = 0; /* exit loop */ switch (run->exit_reason) { diff --git a/kvm.h b/kvm.h index 1c93ac5..59cba18 100644 --- a/kvm.h +++ b/kvm.h @@ -53,6 +53,7 @@ void kvm_setup_guest_memory(void *start, size_t size); int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); +void kvm_flush_coalesced_mmio_buffer(void); int kvm_insert_breakpoint(CPUState *current_env, target_ulong addr, target_ulong len, int type); diff --git a/vl.c b/vl.c index 39833fc..50f133d 100644 --- a/vl.c +++ b/vl.c @@ -2996,6 +2996,7 @@ static void gui_update(void *opaque) DisplayState *ds = opaque; DisplayChangeListener *dcl = ds->listeners; + qemu_flush_coalesced_mmio_buffer(); dpy_refresh(ds); while (dcl != NULL) { @@ -3011,6 +3012,7 @@ static void nographic_update(void *opaque) { uint64_t interval = GUI_REFRESH_INTERVAL; + qemu_flush_coalesced_mmio_buffer(); qemu_mod_timer(nographic_timer, interval + qemu_get_clock(rt_clock)); }