From mboxrd@z Thu Jan 1 00:00:00 1970 From: 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> References: <1447661048-31048-1-git-send-email-haozhong.zhang@intel.com> Cc: Paolo Bonzini , Richard Henderson , "Michael S. Tsirkin" , , Marcelo Tosatti , kvm@vger.kernel.org, Haozhong Zhang To: , Eduardo Habkost , "Dr. David Alan Gilbert" Return-path: 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 In-Reply-To: <1447661048-31048-1-git-send-email-haozhong.zhang@intel.com> Sender: kvm-owner@vger.kernel.org List-ID: 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; -- 2.4.8 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyEmN-0002Et-7E for qemu-devel@nongnu.org; Mon, 16 Nov 2015 03:04:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyEmK-00008n-1R for qemu-devel@nongnu.org; Mon, 16 Nov 2015 03:04:47 -0500 Received: from mga01.intel.com ([192.55.52.88]:48153) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyEmJ-00008j-Rb for qemu-devel@nongnu.org; Mon, 16 Nov 2015 03:04:43 -0500 From: Haozhong Zhang Date: Mon, 16 Nov 2015 16:04:07 +0800 Message-Id: <1447661048-31048-2-git-send-email-haozhong.zhang@intel.com> In-Reply-To: <1447661048-31048-1-git-send-email-haozhong.zhang@intel.com> References: <1447661048-31048-1-git-send-email-haozhong.zhang@intel.com> Subject: [Qemu-devel] [PATCH v4 1/2] target-i386: fallback vcpu's TSC rate to value returned by KVM List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Eduardo Habkost , "Dr. David Alan Gilbert" Cc: Haozhong Zhang , kvm@vger.kernel.org, "Michael S. Tsirkin" , Marcelo Tosatti , Paolo Bonzini , afaerber@suse.de, Richard Henderson 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; -- 2.4.8