Set vcpu's TSC rate to the migrated value if the user does not specify a TSC rate by cpu option 'tsc-freq' and a migrated TSC rate does exist. If KVM supports TSC scaling, guest programs will observe TSC increasing in the migrated rate other than the host TSC rate. Signed-off-by: Haozhong Zhang <haozhong.zhang@xxxxxxxxx> --- target-i386/kvm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index aae5e58..2be70df 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -3042,6 +3042,27 @@ int kvm_arch_setup_tsc_khz(CPUState *cs) int r; /* + * If a TSC rate is migrated and the user does not specify the + * vcpu's TSC rate on the destination, the migrated TSC rate will + * be used on the destination after the migration. + */ + if (env->tsc_khz_saved && !env->tsc_khz) { + if (kvm_check_extension(cs->kvm_state, KVM_CAP_TSC_CONTROL)) { + r = kvm_vcpu_ioctl(cs, KVM_SET_TSC_KHZ, env->tsc_khz_saved); + if (r < 0) { + fprintf(stderr, "KVM_SET_TSC_KHZ failed\n"); + } + } else { + r = -1; + fprintf(stderr, "KVM doesn't support TSC scaling\n"); + } + if (r < 0) { + fprintf(stderr, "Use host TSC frequency instead. " + "Guest TSC may be inaccurate.\n"); + } + } + + /* * Prepare vcpu's TSC rate to be migrated. * * - If the user specifies the TSC rate by cpu option 'tsc-freq', -- 2.4.8 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html