From patchwork Tue Aug 25 05:52:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Liang Z" X-Patchwork-Id: 510380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E2F121401F6 for ; Tue, 25 Aug 2015 15:55:07 +1000 (AEST) Received: from localhost ([::1]:58173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZU7CM-00078B-7S for incoming@patchwork.ozlabs.org; Tue, 25 Aug 2015 01:55:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZU7B9-00056b-Cg for qemu-devel@nongnu.org; Tue, 25 Aug 2015 01:53:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZU7B4-0001zy-BD for qemu-devel@nongnu.org; Tue, 25 Aug 2015 01:53:51 -0400 Received: from mga03.intel.com ([134.134.136.65]:32296) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZU7B4-0001zh-4J for qemu-devel@nongnu.org; Tue, 25 Aug 2015 01:53:46 -0400 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP; 24 Aug 2015 22:53:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,744,1432623600"; d="scan'208";a="631659518" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by orsmga003.jf.intel.com with ESMTP; 24 Aug 2015 22:53:43 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Tue, 25 Aug 2015 13:52:44 +0800 Message-Id: <1440481965-12318-2-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1440481965-12318-1-git-send-email-liang.z.li@intel.com> References: <1440481965-12318-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Cc: pbonzini@redhat.com, mtosatti@redhat.com, m.gibula@beyond.pl, Liang Li Subject: [Qemu-devel] [RFC 1/2] kvmclock: remove cpu_synchronize_all_states call X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The commit 317b0a6d8 fixed an issue which caused by the outdated env->tsc value, but the fix lead to cpu_synchronize_all_states called twice during live migration. The cpu_synchronize_all_states takes about 300us, which is a bit expensive. This patch tries to fix the issue in another way, and there is only one cpu_synchronize_all_states call during live migration. Signed-off-by: Liang Li --- cpus.c | 8 ++++++++ hw/i386/kvm/clock.c | 17 ----------------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/cpus.c b/cpus.c index c1e74d9..cd5abef 100644 --- a/cpus.c +++ b/cpus.c @@ -634,6 +634,14 @@ static int do_vm_stop(RunState state) pause_all_vcpus(); runstate_set(state); vm_state_notify(0, state); + switch (state) { + case RUN_STATE_PAUSED: + case RUN_STATE_SUSPENDED: + cpu_synchronize_all_states(); + break; + default: + break; + } qapi_event_send_stop(&error_abort); } diff --git a/hw/i386/kvm/clock.c b/hw/i386/kvm/clock.c index efdf165..a9db073 100644 --- a/hw/i386/kvm/clock.c +++ b/hw/i386/kvm/clock.c @@ -17,7 +17,6 @@ #include "qemu/host-utils.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" -#include "sysemu/cpus.h" #include "hw/sysbus.h" #include "hw/kvm/clock.h" @@ -125,22 +124,6 @@ static void kvmclock_vm_state_change(void *opaque, int running, return; } - cpu_synchronize_all_states(); - /* In theory, the cpu_synchronize_all_states() call above wouldn't - * affect the rest of the code, as the VCPU state inside CPUState - * is supposed to always match the VCPU state on the kernel side. - * - * In practice, calling cpu_synchronize_state() too soon will load the - * kernel-side APIC state into X86CPU.apic_state too early, APIC state - * won't be reloaded later because CPUState.vcpu_dirty==true, and - * outdated APIC state may be migrated to another host. - * - * The real fix would be to make sure outdated APIC state is read - * from the kernel again when necessary. While this is not fixed, we - * need the cpu_clean_all_dirty() call below. - */ - cpu_clean_all_dirty(); - ret = kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, &data); if (ret < 0) { fprintf(stderr, "KVM_GET_CLOCK failed: %s\n", strerror(ret));