From patchwork Thu Jan 21 09:37:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sheng Yang X-Patchwork-Id: 74305 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id o0L9bvr4003939 for ; Thu, 21 Jan 2010 09:37:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752976Ab0AUJhz (ORCPT ); Thu, 21 Jan 2010 04:37:55 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753171Ab0AUJhy (ORCPT ); Thu, 21 Jan 2010 04:37:54 -0500 Received: from mga09.intel.com ([134.134.136.24]:8695 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752897Ab0AUJhx (ORCPT ); Thu, 21 Jan 2010 04:37:53 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 21 Jan 2010 01:37:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.49,316,1262592000"; d="scan'208";a="589097162" Received: from syang10-desktop.sh.intel.com (HELO syang10-desktop) ([10.239.36.165]) by orsmga001.jf.intel.com with ESMTP; 21 Jan 2010 01:37:49 -0800 Received: from yasker by syang10-desktop with local (Exim 4.69) (envelope-from ) id 1NXtTe-0006f1-7r; Thu, 21 Jan 2010 17:37:22 +0800 From: Sheng Yang To: Avi Kivity , Marcelo Tosatti Cc: kvm@vger.kernel.org, Sheng Yang Subject: [PATCH] kvm: Flush coalesced MMIO buffer periodly Date: Thu, 21 Jan 2010 17:37:20 +0800 Message-Id: <1264066640-25577-1-git-send-email-sheng@linux.intel.com> X-Mailer: git-send-email 1.6.3.3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/qemu-kvm.c b/qemu-kvm.c index 599c3d6..38f890c 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,29 @@ static void io_thread_wakeup(void *opaque) } } +#ifdef KVM_CAP_COALESCED_MMIO + +/* flush interval is 1/25 second */ +#define KVM_COALESCED_MMIO_FLUSH_INTERVAL 40000000LL + +static void flush_coalesced_mmio_buffer(void *opaque) +{ + 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; + } + } + qemu_mod_timer(kvm_state->coalesced_mmio_timer, + qemu_get_clock(host_clock) + KVM_COALESCED_MMIO_FLUSH_INTERVAL); +} +#endif + int kvm_main_loop(void) { int fds[2]; @@ -2117,6 +2145,15 @@ int kvm_main_loop(void) io_thread_sigfd = sigfd; cpu_single_env = NULL; +#ifdef KVM_CAP_COALESCED_MMIO + if (kvm_state->coalesced_mmio) { + kvm_state->coalesced_mmio_timer = + qemu_new_timer(host_clock, flush_coalesced_mmio_buffer, NULL); + qemu_mod_timer(kvm_state->coalesced_mmio_timer, + qemu_get_clock(host_clock) + KVM_COALESCED_MMIO_FLUSH_INTERVAL); + } +#endif + while (1) { main_loop_wait(1000); if (qemu_shutdown_requested()) { @@ -2135,6 +2172,12 @@ int kvm_main_loop(void) } } +#ifdef KVM_CAP_COALESCED_MMIO + if (kvm_state->coalesced_mmio) { + qemu_del_timer(kvm_state->coalesced_mmio_timer); + qemu_free_timer(kvm_state->coalesced_mmio_timer); + } +#endif pause_all_threads(); pthread_mutex_unlock(&qemu_mutex); diff --git a/qemu-kvm.h b/qemu-kvm.h index 6b3e5a1..17f9d1b 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -1144,6 +1144,8 @@ typedef struct KVMState { int fd; int vmfd; int coalesced_mmio; + struct kvm_coalesced_mmio_ring *coalesced_mmio_ring; + struct QEMUTimer *coalesced_mmio_timer; int broken_set_mem_region; int migration_log; int vcpu_events;