From patchwork Mon Sep 28 05:38:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7275161 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A96849FACA for ; Mon, 28 Sep 2015 05:38:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF3A1206E6 for ; Mon, 28 Sep 2015 05:38:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C46F3206E7 for ; Mon, 28 Sep 2015 05:38:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756069AbbI1Fi4 (ORCPT ); Mon, 28 Sep 2015 01:38:56 -0400 Received: from mga09.intel.com ([134.134.136.24]:2910 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbbI1Fiz (ORCPT ); Mon, 28 Sep 2015 01:38:55 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP; 27 Sep 2015 22:38:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,601,1437462000"; d="scan'208";a="569605773" Received: from hzzhang-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.12.62]) by FMSMGA003.fm.intel.com with ESMTP; 27 Sep 2015 22:38:54 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Paolo Bonzini , Marcelo Tosatti , Richard Henderson , Eduardo Habkost , Haozhong Zhang Subject: [PATCH 3/3] kvm-all: notice KVM of vcpu's TSC rate after migration Date: Mon, 28 Sep 2015 13:38:31 +0800 Message-Id: <1443418711-24106-4-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1443418711-24106-1-git-send-email-haozhong.zhang@intel.com> References: <1443418711-24106-1-git-send-email-haozhong.zhang@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a vcpu is created in KVM, its TSC rate is initially identical to the host TSC rate. If its state is migrated to a vcpu on another machine (target machine) which may uses a different host TSC rate, QEMU on the target machine should notice KVM of the migrated vcpu's TSC rate. In case that KVM on the target machine supports TSC scaling, guest programs running on the migrated vcpu will observe the same TSC rate before and after the migration. Signed-off-by: Haozhong Zhang --- kvm-all.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kvm-all.c b/kvm-all.c index 0be4615..e8de038 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1769,6 +1769,19 @@ void kvm_cpu_synchronize_post_reset(CPUState *cpu) static void do_kvm_cpu_synchronize_post_init(void *arg) { CPUState *cpu = arg; + CPUX86State *env = &X86_CPU(cpu)->env; + int r; + + /* + * XXX: KVM_SET_TSC_KHZ must be done before kvm_arch_put_registers(). + */ + r = kvm_check_extension(cpu->kvm_state, KVM_CAP_TSC_CONTROL); + if (r && env->tsc_khz) { + r = kvm_vcpu_ioctl(cpu, KVM_SET_TSC_KHZ, env->tsc_khz); + if (r < 0) { + fprintf(stderr, "KVM_SET_TSC_KHZ failed\n"); + } + } kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE); cpu->kvm_vcpu_dirty = false;