From patchwork Mon Nov 2 09:26:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 7535161 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 9A0C5BEEA4 for ; Mon, 2 Nov 2015 09:29:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AB61C205EF for ; Mon, 2 Nov 2015 09:29:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A592C205EB for ; Mon, 2 Nov 2015 09:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752497AbbKBJ3j (ORCPT ); Mon, 2 Nov 2015 04:29:39 -0500 Received: from mga03.intel.com ([134.134.136.65]:35482 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751355AbbKBJ3i (ORCPT ); Mon, 2 Nov 2015 04:29:38 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 02 Nov 2015 01:29:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,234,1444719600"; d="scan'208";a="840476112" Received: from hzzhang-optiplex-9020.sh.intel.com (HELO localhost) ([10.239.12.31]) by orsmga002.jf.intel.com with ESMTP; 02 Nov 2015 01:28:38 -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 2/3] target-i386: calculate vcpu's TSC rate to be migrated Date: Mon, 2 Nov 2015 17:26:42 +0800 Message-Id: <1446456403-29909-3-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 The value of the migrated vcpu's TSC rate is determined as below. 1. If a TSC rate is specified by the cpu option 'tsc-freq', then this user-specified value will be used. 2. If neither a user-specified TSC rate nor a migrated TSC rate is present, we will use the TSC rate from KVM (returned by KVM_GET_TSC_KHZ). 3. Otherwise, we will use the migrated TSC rate. Signed-off-by: Haozhong Zhang --- include/sysemu/kvm.h | 2 ++ kvm-all.c | 1 + target-arm/kvm.c | 5 +++++ target-i386/kvm.c | 33 +++++++++++++++++++++++++++++++++ target-mips/kvm.c | 5 +++++ target-ppc/kvm.c | 5 +++++ target-s390x/kvm.c | 5 +++++ 7 files changed, 56 insertions(+) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index 461ef65..0ec8b98 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -328,6 +328,8 @@ int kvm_arch_fixup_msi_route(struct kvm_irq_routing_entry *route, int kvm_arch_msi_data_to_gsi(uint32_t data); +int kvm_arch_setup_tsc_khz(CPUState *cpu); + int kvm_set_irq(KVMState *s, int irq, int level); int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg); diff --git a/kvm-all.c b/kvm-all.c index c442838..1ecaf04 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -1757,6 +1757,7 @@ static void do_kvm_cpu_synchronize_post_init(void *arg) { CPUState *cpu = arg; + kvm_arch_setup_tsc_khz(cpu); kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE); cpu->kvm_vcpu_dirty = false; } diff --git a/target-arm/kvm.c b/target-arm/kvm.c index 79ef4c6..a724f6d 100644 --- a/target-arm/kvm.c +++ b/target-arm/kvm.c @@ -614,3 +614,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { return (data - 32) & 0xffff; } + +int kvm_arch_setup_tsc_khz(CPUState *cs) +{ + return 0; +} diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 64046cb..aae5e58 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -3034,3 +3034,36 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +int kvm_arch_setup_tsc_khz(CPUState *cs) +{ + X86CPU *cpu = X86_CPU(cs); + CPUX86State *env = &cpu->env; + int r; + + /* + * Prepare vcpu's TSC rate to be migrated. + * + * - If the user specifies the TSC rate by cpu option 'tsc-freq', + * we will use the user-specified value. + * + * - If there is neither user-specified TSC rate nor migrated TSC + * rate, we will ask KVM for the TSC rate by calling + * KVM_GET_TSC_KHZ. + * + * - Otherwise, if there is a migrated TSC rate, we will use the + * migrated value. + */ + if (env->tsc_khz) { + env->tsc_khz_saved = env->tsc_khz; + } else if (!env->tsc_khz_saved) { + 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_saved = r; + } + + return 0; +} diff --git a/target-mips/kvm.c b/target-mips/kvm.c index 12d7db3..fb26d7e 100644 --- a/target-mips/kvm.c +++ b/target-mips/kvm.c @@ -687,3 +687,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +int kvm_arch_setup_tsc_khz(CPUState *cs) +{ + return 0; +} diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index ac70f08..c429f0c 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -2510,3 +2510,8 @@ int kvmppc_enable_hwrng(void) return kvmppc_enable_hcall(kvm_state, H_RANDOM); } + +int kvm_arch_setup_tsc_khz(CPUState *cs) +{ + return 0; +} diff --git a/target-s390x/kvm.c b/target-s390x/kvm.c index c3be180..db5d436 100644 --- a/target-s390x/kvm.c +++ b/target-s390x/kvm.c @@ -2248,3 +2248,8 @@ int kvm_arch_msi_data_to_gsi(uint32_t data) { abort(); } + +int kvm_arch_setup_tsc_khz(CPUState *cs) +{ + return 0; +}