From patchwork Thu Oct 15 17:15:25 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 54065 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n9FHMGt1030296 for ; Thu, 15 Oct 2009 17:22:16 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935188AbZJORPy (ORCPT ); Thu, 15 Oct 2009 13:15:54 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S935185AbZJORPx (ORCPT ); Thu, 15 Oct 2009 13:15:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35596 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935184AbZJORPw (ORCPT ); Thu, 15 Oct 2009 13:15:52 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9FHFQgd009303 for ; Thu, 15 Oct 2009 13:15:26 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9FHFPt5027615; Thu, 15 Oct 2009 13:15:26 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com Subject: [RFC] Do clock adjustments over migration Date: Thu, 15 Oct 2009 13:15:25 -0400 Message-Id: <1255626925-3140-1-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index fffcfd8..75e2ffd 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -834,6 +834,9 @@ static int get_msr_entry(struct kvm_msr_entry *entry, CPUState *env) case MSR_VM_HSAVE_PA: env->vm_hsave = entry->data; break; + case MSR_KVM_SYSTEM_TIME: + env->system_time_msr = entry->data; + break; default: printf("Warning unknown msr index 0x%x\n", entry->index); return 1; @@ -1001,6 +1004,7 @@ void kvm_arch_load_regs(CPUState *env) set_msr_entry(&msrs[n++], MSR_LSTAR , env->lstar); } #endif + set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME, env->system_time_msr); rc = kvm_set_msrs(env->kvm_cpu_state.vcpu_ctx, msrs, n); if (rc == -1) @@ -1179,6 +1183,8 @@ void kvm_arch_save_regs(CPUState *env) msrs[n++].index = MSR_LSTAR; } #endif + msrs[n++].index = MSR_KVM_SYSTEM_TIME; + rc = kvm_get_msrs(env->kvm_cpu_state.vcpu_ctx, msrs, n); if (rc == -1) { perror("kvm_get_msrs FAILED"); diff --git a/qemu-kvm.c b/qemu-kvm.c index 87ece3d..75e9575 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -347,6 +347,34 @@ int kvm_dirty_pages_log_reset(kvm_context_t kvm) static int kvm_create_context(void); +static struct kvm_clock_data kvmclock_data; + +static void kvmclock_pre_save(void *opaque) +{ + struct kvm_clock_data *cl = opaque; + + kvm_vm_ioctl(kvm_state, KVM_GET_CLOCK, cl); +} + +static int kvmclock_post_load(void *opaque, int version_id) +{ + struct kvm_clock_data *cl = opaque; + + return kvm_vm_ioctl(kvm_state, KVM_SET_CLOCK, cl); +} + +static const VMStateDescription vmstate_kvmclock= { + .name = "timer", + .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), + VMSTATE_END_OF_LIST() + } +}; int kvm_init(int smp_cpus) { @@ -406,6 +434,7 @@ int kvm_init(int smp_cpus) set_gsi(kvm_context, i); } + vmstate_register(0, &vmstate_kvmclock, &kvmclock_data); pthread_mutex_lock(&qemu_mutex); return kvm_create_context(); diff --git a/target-i386/cpu.h b/target-i386/cpu.h index 278d3e3..8022772 100644 --- a/target-i386/cpu.h +++ b/target-i386/cpu.h @@ -667,6 +667,7 @@ typedef struct CPUX86State { target_ulong fmask; target_ulong kernelgsbase; #endif + uint64_t system_time_msr; uint64_t tsc; @@ -886,7 +887,7 @@ uint64_t cpu_get_tsc(CPUX86State *env); #define cpu_signal_handler cpu_x86_signal_handler #define cpu_list x86_cpu_list -#define CPU_SAVE_VERSION 11 +#define CPU_SAVE_VERSION 12 /* MMU modes definitions */ #define MMU_MODE0_SUFFIX _kernel diff --git a/target-i386/machine.c b/target-i386/machine.c index 16d9c57..d5267be 100644 --- a/target-i386/machine.c +++ b/target-i386/machine.c @@ -479,6 +479,8 @@ const VMStateDescription vmstate_cpu = { VMSTATE_UINT64_ARRAY_V(mce_banks, CPUState, MCE_BANKS_DEF *4, 10), /* rdtscp */ VMSTATE_UINT64_V(tsc_aux, CPUState, 11), + /* KVM pvclock msr */ + VMSTATE_UINT64_V(system_time_msr, CPUState, 12), VMSTATE_END_OF_LIST() } };