From patchwork Mon Dec 6 14:03:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 74360 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 08FFFB7043 for ; Tue, 7 Dec 2010 01:11:08 +1100 (EST) Received: from localhost ([127.0.0.1]:42675 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPbmO-0002ch-05 for incoming@patchwork.ozlabs.org; Mon, 06 Dec 2010 09:11:00 -0500 Received: from [140.186.70.92] (port=56031 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PPbjR-0001SB-Bq for qemu-devel@nongnu.org; Mon, 06 Dec 2010 09:08:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PPbjP-0004kd-3F for qemu-devel@nongnu.org; Mon, 06 Dec 2010 09:07:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:26179) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PPbjO-0004kB-RS for qemu-devel@nongnu.org; Mon, 06 Dec 2010 09:07:55 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB6E7rYJ001630 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 6 Dec 2010 09:07:54 -0500 Received: from virtlab1.virt.bos.redhat.com (virtlab1.virt.bos.redhat.com [10.16.72.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB6E7pj0006031; Mon, 6 Dec 2010 09:07:53 -0500 From: Glauber Costa To: kvm@vger.kernel.org Date: Mon, 6 Dec 2010 09:03:47 -0500 Message-Id: <1291644227-22923-3-git-send-email-glommer@redhat.com> In-Reply-To: <1291644227-22923-1-git-send-email-glommer@redhat.com> References: <1291644227-22923-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Paolo Bonzini , mtosatti@redhat.com, qemu-devel@nongnu.org, avi@redhat.com Subject: [Qemu-devel] [PATCH v2 2/2] make kvmclock value idempotent for stopped machine 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 Although we never made such commitment clear (well, to the best of my knowledge), some people expect that two savevm issued in sequence in a stopped machine will yield the same results. This is not a crazy requirement, since we don't expect a stopped machine to be updating its state, for any device. With kvmclock, this is not the case, since the .pre_save hook will issue an ioctl to the host to acquire a timestamp, which is always changing. This patch moves the value acquisition to vm state change handlers, conditional on not being run. This could mean mean our get clock ioctl is issued more times, but this should be fine since vm_stop is not a hot path. When we do migrate, we'll transfer that value along. Signed-off-by: Glauber Costa CC: Paolo Bonzini --- qemu-kvm-x86.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 14a52ce..0e357ac 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -500,11 +500,11 @@ static int kvm_enable_tpr_access_reporting(CPUState *env) #ifdef KVM_CAP_ADJUST_CLOCK static struct kvm_clock_data kvmclock_data; -static void kvmclock_pre_save(void *opaque) +static void kvmclock_update_clock(void *opaque, int running, int reason) { struct kvm_clock_data *cl = opaque; - if (!kvmclock_enabled) + if ((!kvmclock_enabled) || running) return; kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, cl); @@ -522,7 +522,6 @@ static const VMStateDescription vmstate_kvmclock= { .version_id = 1, .minimum_version_id = 1, .minimum_version_id_old = 1, - .pre_save = kvmclock_pre_save, .post_load = kvmclock_post_load, .fields = (VMStateField []) { VMSTATE_U64(clock, struct kvm_clock_data), @@ -537,6 +536,7 @@ void kvmclock_register_savevm(void) #ifdef KVM_CAP_ADJUST_CLOCK if (kvmclock_enabled && kvm_check_extension(kvm_state, KVM_CAP_ADJUST_CLOCK)) { vmstate_register(NULL, 0, &vmstate_kvmclock, &kvmclock_data); + qemu_add_vm_change_state_handler(kvmclock_update_clock, &kvmclock_data); } #endif }