Save/restore tsc adjust when migrate Signed-off-by: Liu, Jinsong <jinsong.liu@intel.com> diff -r d94d78756665 tools/misc/xen-hvmctx.c --- a/tools/misc/xen-hvmctx.c Thu Sep 20 21:57:36 2012 +0800 +++ b/tools/misc/xen-hvmctx.c Thu Sep 20 22:07:14 2012 +0800 @@ -392,6 +392,13 @@ printf(" VMCE_VCPU: bank1 mci_ctl2 %" PRIx64 "\n", p.mci_ctl2_bank1); } +static void dump_tsc_adjust(void) +{ + HVM_SAVE_TYPE(TSC_ADJUST) p; + READ(p); + printf(" TSC_ADJUST: tsc_adjust %" PRIx64 "\n", p.tsc_adjust); +} + int main(int argc, char **argv) { int entry, domid; @@ -459,6 +466,7 @@ case HVM_SAVE_CODE(VIRIDIAN_DOMAIN): dump_viridian_domain(); break; case HVM_SAVE_CODE(VIRIDIAN_VCPU): dump_viridian_vcpu(); break; case HVM_SAVE_CODE(VMCE_VCPU): dump_vmce_vcpu(); break; + case HVM_SAVE_CODE(TSC_ADJUST): dump_tsc_adjust(); break; case HVM_SAVE_CODE(END): break; default: printf(" ** Don''t understand type %u: skipping\n", diff -r d94d78756665 xen/arch/x86/hvm/hvm.c --- a/xen/arch/x86/hvm/hvm.c Thu Sep 20 21:57:36 2012 +0800 +++ b/xen/arch/x86/hvm/hvm.c Thu Sep 20 22:07:14 2012 +0800 @@ -605,6 +605,45 @@ hvm_destroy_cacheattr_region_list(d); } +static int hvm_save_tsc_adjust(struct domain *d, hvm_domain_context_t *h) +{ + struct vcpu *v; + struct hvm_tsc_adjust ctxt; + int err = 0; + + for_each_vcpu( d, v ){ + ctxt.tsc_adjust = v->arch.hvm_vcpu.msr_tsc_adjust; + err = hvm_save_entry(TSC_ADJUST, v->vcpu_id, h, &ctxt); + if ( err ) + break; + } + + return err; +} + +static int hvm_load_tsc_adjust(struct domain *d, hvm_domain_context_t *h) +{ + unsigned int vcpuid = hvm_load_instance(h); + struct vcpu *v; + struct hvm_tsc_adjust ctxt; + + if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL ) + { + dprintk(XENLOG_G_ERR, "HVM restore: dom%d has no vcpu%u\n", + d->domain_id, vcpuid); + return -EINVAL; + } + + if ( hvm_load_entry(TSC_ADJUST, h, &ctxt) != 0 ) + return -EINVAL; + + v->arch.hvm_vcpu.msr_tsc_adjust = ctxt.tsc_adjust; + return 0; +} + +HVM_REGISTER_SAVE_RESTORE(TSC_ADJUST, hvm_save_tsc_adjust, + hvm_load_tsc_adjust, 1, HVMSR_PER_VCPU); + static int hvm_save_cpu_ctxt(struct domain *d, hvm_domain_context_t *h) { struct vcpu *v; diff -r d94d78756665 xen/include/public/arch-x86/hvm/save.h --- a/xen/include/public/arch-x86/hvm/save.h Thu Sep 20 21:57:36 2012 +0800 +++ b/xen/include/public/arch-x86/hvm/save.h Thu Sep 20 22:07:14 2012 +0800 @@ -583,9 +583,15 @@ DECLARE_HVM_SAVE_TYPE(VMCE_VCPU, 18, struct hvm_vmce_vcpu); +struct hvm_tsc_adjust { + uint64_t tsc_adjust; +}; + +DECLARE_HVM_SAVE_TYPE(TSC_ADJUST, 19, struct hvm_tsc_adjust); + /* * Largest type-code in use */ -#define HVM_SAVE_CODE_MAX 18 +#define HVM_SAVE_CODE_MAX 19 #endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */ _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel