From patchwork Tue Oct 20 07:22:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7442431 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 C1AA89F36A for ; Tue, 20 Oct 2015 07:23:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 07051205E3 for ; Tue, 20 Oct 2015 07:23:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F378C205E8 for ; Tue, 20 Oct 2015 07:23:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752765AbbJTHXo (ORCPT ); Tue, 20 Oct 2015 03:23:44 -0400 Received: from mga02.intel.com ([134.134.136.20]:49639 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752284AbbJTHXn (ORCPT ); Tue, 20 Oct 2015 03:23:43 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 20 Oct 2015 00:23:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,706,1437462000"; d="scan'208";a="830648115" Received: from hzzhang-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.12.28]) by orsmga002.jf.intel.com with ESMTP; 20 Oct 2015 00:23:40 -0700 From: Haozhong Zhang To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, "Michael S. Tsirkin" , afaerber@suse.de, Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcelo Tosatti , Haozhong Zhang Subject: [PATCH v2 2/3] target-i386: calculate vcpu's TSC rate to be migrated Date: Tue, 20 Oct 2015 15:22:53 +0800 Message-Id: <1445325774-7195-3-git-send-email-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.4.8 In-Reply-To: <1445325774-7195-1-git-send-email-haozhong.zhang@intel.com> References: <1445325774-7195-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, 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 vcpu's TSC rate is not specified by the cpu option 'tsc-freq', we will use the value returned by KVM_GET_TSC_KHZ; otherwise, we use the user-specified value. Signed-off-by: Haozhong Zhang --- target-i386/kvm.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 80d1a7e..698524a 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -2213,6 +2213,35 @@ static int kvm_get_debugregs(X86CPU *cpu) return 0; } +static int kvm_setup_tsc_khz(X86CPU *cpu, int level) +{ + CPUState *cs = CPU(cpu); + CPUX86State *env = &cpu->env; + int r; + + if (level < KVM_PUT_FULL_STATE) + return 0; + + /* + * Prepare the vcpu's TSC rate (ie. env->tsc_khz_incoming) to be migrated. + * 1. If no user-specified value is provided, we will use the value from + * KVM; + * 2. Otherwise, we just use the user-specified value. + */ + if (!env->tsc_khz) { + r = kvm_vcpu_ioctl(cs, KVM_GET_TSC_KHZ); + if (r < 0) { + fprintf(stderr, "KVM_GET_TSC_KHZ failed\n"); + return r; + } + env->tsc_khz_incoming = r; + } else { + env->tsc_khz_incoming = env->tsc_khz; + } + + return 0; +} + int kvm_arch_put_registers(CPUState *cpu, int level) { X86CPU *x86_cpu = X86_CPU(cpu); @@ -2248,6 +2277,10 @@ int kvm_arch_put_registers(CPUState *cpu, int level) if (ret < 0) { return ret; } + ret = kvm_setup_tsc_khz(x86_cpu, level); + if (ret < 0) { + return ret; + } ret = kvm_put_msrs(x86_cpu, level); if (ret < 0) { return ret;