From patchwork Mon Nov 2 09:26:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7535181 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 59382BEEA4 for ; Mon, 2 Nov 2015 09:30:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8BF12205EF for ; Mon, 2 Nov 2015 09:30:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9D196205EB for ; Mon, 2 Nov 2015 09:30:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753041AbbKBJab (ORCPT ); Mon, 2 Nov 2015 04:30:31 -0500 Received: from mga14.intel.com ([192.55.52.115]:60740 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752893AbbKBJaa (ORCPT ); Mon, 2 Nov 2015 04:30:30 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 02 Nov 2015 01:30:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,234,1444719600"; d="scan'208";a="824762720" Received: from hzzhang-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.12.31]) by fmsmga001.fm.intel.com with ESMTP; 02 Nov 2015 01:28:43 -0800 From: Haozhong Zhang To: qemu-devel@nongnu.org, Eduardo Habkost , "Dr. David Alan Gilbert" Cc: "Michael S. Tsirkin" , Paolo Bonzini , Richard Henderson , Peter Maydell , Marcelo Tosatti , James Hogan , Aurelien Jarno , Leon Alrae , Alexander Graf , Christian Borntraeger , Cornelia Huck , kvm@vger.kernel.org, qemu-ppc@nongnu.org, Haozhong Zhang Subject: [PATCH v3 3/3] target-i386: load the migrated vcpu's TSC rate Date: Mon, 2 Nov 2015 17:26:43 +0800 Message-Id: <1446456403-29909-4-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1446456403-29909-1-git-send-email-haozhong.zhang@intel.com> References: <1446456403-29909-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 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',