From patchwork Mon Nov 16 08:04:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7621661 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 CB77C9F2E2 for ; Mon, 16 Nov 2015 08:04:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08991205DD for ; Mon, 16 Nov 2015 08:04:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 187C8205DB for ; Mon, 16 Nov 2015 08:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751903AbbKPIEn (ORCPT ); Mon, 16 Nov 2015 03:04:43 -0500 Received: from mga09.intel.com ([134.134.136.24]:34178 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751665AbbKPIEm (ORCPT ); Mon, 16 Nov 2015 03:04:42 -0500 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 16 Nov 2015 00:04:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,301,1444719600"; d="scan'208";a="821051553" Received: from hzzhang-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.12.31]) by orsmga001.jf.intel.com with ESMTP; 16 Nov 2015 00:04:40 -0800 From: Haozhong Zhang To: , Eduardo Habkost , "Dr. David Alan Gilbert" Cc: Paolo Bonzini , Richard Henderson , "Michael S. Tsirkin" , , Marcelo Tosatti , kvm@vger.kernel.org, Haozhong Zhang Subject: [PATCH v4 1/2] target-i386: fallback vcpu's TSC rate to value returned by KVM Date: Mon, 16 Nov 2015 16:04:07 +0800 Message-Id: <1447661048-31048-2-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1447661048-31048-1-git-send-email-haozhong.zhang@intel.com> References: <1447661048-31048-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=-7.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 If no user-specified TSC rate is present, we will try to set env->tsc_khz to the value returned by KVM_GET_TSC_KHZ. Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 2a9953b..9084b29 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -2327,6 +2327,27 @@ static int kvm_get_debugregs(X86CPU *cpu) return 0; } +static void kvm_arch_set_tsc_khz(CPUState *cs) +{ + X86CPU *cpu = X86_CPU(cs); + CPUX86State *env = &cpu->env; + int r; + + /* + * If no user-specified TSC frequency is present, we will try to + * set env->tsc_khz to the value used by KVM. + */ + if (!env->tsc_khz) { + r = kvm_check_extension(cs->kvm_state, KVM_CAP_GET_TSC_KHZ) ? + kvm_vcpu_ioctl(cs, KVM_GET_TSC_KHZ) : -ENOTSUP; + if (r < 0) { + error_report("warning: KVM_GET_TSC_KHZ failed"); + } else { + env->tsc_khz = r; + } + } +} + int kvm_arch_put_registers(CPUState *cpu, int level) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -2341,6 +2362,10 @@ int kvm_arch_put_registers(CPUState *cpu, int level) } } + if (level == KVM_PUT_FULL_STATE) { + kvm_arch_set_tsc_khz(cpu); + } + ret = kvm_getput_regs(x86_cpu, 1); if (ret < 0) { return ret;