From patchwork Tue Mar 15 09:36:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 635651 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2F9bU8M023353 for ; Tue, 15 Mar 2011 09:37:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756141Ab1COJhZ (ORCPT ); Tue, 15 Mar 2011 05:37:25 -0400 Received: from ch1outboundpool.messaging.microsoft.com ([216.32.181.184]:23583 "EHLO ch1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754928Ab1COJhR (ORCPT ); Tue, 15 Mar 2011 05:37:17 -0400 Received: from mail177-ch1-R.bigfish.com (216.32.181.173) by CH1EHSOBE015.bigfish.com (10.43.70.65) with Microsoft SMTP Server id 14.1.225.8; Tue, 15 Mar 2011 09:37:16 +0000 Received: from mail177-ch1 (localhost.localdomain [127.0.0.1]) by mail177-ch1-R.bigfish.com (Postfix) with ESMTP id B2C1910C8136; Tue, 15 Mar 2011 09:37:16 +0000 (UTC) X-SpamScore: -2 X-BigFish: VPS-2(zzbb2cKzz1202hzz8275bhz32i668h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp02.amd.com; RD:none; EFVD:NLI Received: from mail177-ch1 (localhost.localdomain [127.0.0.1]) by mail177-ch1 (MessageSwitch) id 1300181836465319_14995; Tue, 15 Mar 2011 09:37:16 +0000 (UTC) Received: from CH1EHSMHS007.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.241]) by mail177-ch1.bigfish.com (Postfix) with ESMTP id 6D9C2F48053; Tue, 15 Mar 2011 09:37:16 +0000 (UTC) Received: from ausb3twp02.amd.com (163.181.249.109) by CH1EHSMHS007.bigfish.com (10.43.70.7) with Microsoft SMTP Server id 14.1.225.8; Tue, 15 Mar 2011 09:37:16 +0000 X-WSS-ID: 0LI3EQ0-02-7QJ-02 X-M-MSG: Received: from sausexedgep01.amd.com (sausexedgep01-ext.amd.com [163.181.249.72]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp02.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 25836C8697; Tue, 15 Mar 2011 04:37:12 -0500 (CDT) Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep01.amd.com (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.106.1; Tue, 15 Mar 2011 04:44:09 -0500 Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 15 Mar 2011 04:37:14 -0500 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Tue, 15 Mar 2011 05:37:12 -0400 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id 14A5F49C58D; Tue, 15 Mar 2011 09:37:12 +0000 (GMT) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id 0601CFFC6A; Tue, 15 Mar 2011 10:37:11 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: Zachary Amsden , , Joerg Roedel Subject: [PATCH 2/6] KVM: X86: Let kvm-clock report the right tsc frequency Date: Tue, 15 Mar 2011 10:36:51 +0100 Message-ID: <1300181815-16190-3-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1300181815-16190-1-git-send-email-joerg.roedel@amd.com> References: <1300181815-16190-1-git-send-email-joerg.roedel@amd.com> MIME-Version: 1.0 X-OriginatorOrg: amd.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 15 Mar 2011 09:37:31 +0000 (UTC) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c8af099..a07df14 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -588,6 +588,8 @@ struct kvm_x86_ops { void (*write_tsc_offset)(struct kvm_vcpu *vcpu, u64 offset); + bool (*use_virtual_tsc_khz)(struct kvm_vcpu *vcpu); + void (*get_exit_info)(struct kvm_vcpu *vcpu, u64 *info1, u64 *info2); const struct trace_print_flags *exit_reasons_str; }; diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 72373b6..b91547a 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -914,6 +914,13 @@ static void svm_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment) mark_dirty(svm->vmcb, VMCB_INTERCEPTS); } +static bool svm_use_virtual_tsc_khz(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + return svm->tsc_scale.enabled; +} + static void init_vmcb(struct vcpu_svm *svm) { struct vmcb_control_area *control = &svm->vmcb->control; @@ -3996,6 +4003,7 @@ static struct kvm_x86_ops svm_x86_ops = { .write_tsc_offset = svm_write_tsc_offset, .adjust_tsc_offset = svm_adjust_tsc_offset, + .use_virtual_tsc_khz = svm_use_virtual_tsc_khz, .set_tdp_cr3 = set_tdp_cr3, }; diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index d8475a2..1425ae8 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -1163,6 +1163,11 @@ static void vmx_adjust_tsc_offset(struct kvm_vcpu *vcpu, s64 adjustment) vmcs_write64(TSC_OFFSET, offset + adjustment); } +static bool vmx_use_virtual_tsc_khz(struct kvm_vcpu *vcpu) +{ + return false; +} + /* * Reads an msr value (of 'msr_index') into 'pdata'. * Returns 0 on success, non-0 otherwise. @@ -4438,6 +4443,7 @@ static struct kvm_x86_ops vmx_x86_ops = { .write_tsc_offset = vmx_write_tsc_offset, .adjust_tsc_offset = vmx_adjust_tsc_offset, + .use_virtual_tsc_khz = vmx_use_virtual_tsc_khz, .set_tdp_cr3 = vmx_set_cr3, }; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f1e4025..50daff2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -982,6 +982,14 @@ static inline int kvm_tsc_changes_freq(void) return ret; } +static u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu) +{ + if (kvm_x86_ops->use_virtual_tsc_khz(vcpu)) + return vcpu->kvm->arch.virtual_tsc_khz; + else + return __this_cpu_read(cpu_tsc_khz); +} + static inline u64 nsec_to_cycles(u64 nsec) { u64 ret; @@ -1075,8 +1083,7 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) local_irq_save(flags); kvm_get_msr(v, MSR_IA32_TSC, &tsc_timestamp); kernel_ns = get_kernel_ns(); - this_tsc_khz = __this_cpu_read(cpu_tsc_khz); - + this_tsc_khz = vcpu_tsc_khz(v); if (unlikely(this_tsc_khz == 0)) { local_irq_restore(flags); kvm_make_request(KVM_REQ_CLOCK_UPDATE, v);