From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtBRg-00006T-EB for qemu-devel@nongnu.org; Mon, 02 Nov 2015 04:30:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtBRf-0007OQ-HJ for qemu-devel@nongnu.org; Mon, 02 Nov 2015 04:30:32 -0500 From: Haozhong Zhang Date: Mon, 2 Nov 2015 17:26:43 +0800 Message-Id: <1446456403-29909-4-git-send-email-haozhong.zhang@intel.com> In-Reply-To: <1446456403-29909-1-git-send-email-haozhong.zhang@intel.com> References: <1446456403-29909-1-git-send-email-haozhong.zhang@intel.com> Subject: [Qemu-devel] [PATCH v3 3/3] target-i386: load the migrated vcpu's TSC rate List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Eduardo Habkost , "Dr. David Alan Gilbert" Cc: Peter Maydell , James Hogan , kvm@vger.kernel.org, "Michael S. Tsirkin" , Marcelo Tosatti , Alexander Graf , Christian Borntraeger , qemu-ppc@nongnu.org, Haozhong Zhang , Cornelia Huck , Paolo Bonzini , Leon Alrae , Aurelien Jarno , Richard Henderson 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 --- 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