From patchwork Thu Mar 24 07:40:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 658071 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 p2O7fI9m000397 for ; Thu, 24 Mar 2011 07:41:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933603Ab1CXHkm (ORCPT ); Thu, 24 Mar 2011 03:40:42 -0400 Received: from ch1outboundpool.messaging.microsoft.com ([216.32.181.186]:47907 "EHLO ch1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933525Ab1CXHkf (ORCPT ); Thu, 24 Mar 2011 03:40:35 -0400 Received: from mail168-ch1-R.bigfish.com (216.32.181.173) by CH1EHSOBE009.bigfish.com (10.43.70.59) with Microsoft SMTP Server id 14.1.225.8; Thu, 24 Mar 2011 07:40:33 +0000 Received: from mail168-ch1 (localhost.localdomain [127.0.0.1]) by mail168-ch1-R.bigfish.com (Postfix) with ESMTP id A3741348380; Thu, 24 Mar 2011 07:40:33 +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 mail168-ch1 (localhost.localdomain [127.0.0.1]) by mail168-ch1 (MessageSwitch) id 1300952433477210_28992; Thu, 24 Mar 2011 07:40:33 +0000 (UTC) Received: from CH1EHSMHS029.bigfish.com (snatpool1.int.messaging.microsoft.com [10.43.68.247]) by mail168-ch1.bigfish.com (Postfix) with ESMTP id 66E29146004F; Thu, 24 Mar 2011 07:40:33 +0000 (UTC) Received: from ausb3twp02.amd.com (163.181.249.109) by CH1EHSMHS029.bigfish.com (10.43.70.29) with Microsoft SMTP Server id 14.1.225.8; Thu, 24 Mar 2011 07:40:29 +0000 X-WSS-ID: 0LIJXB9-02-EU4-02 X-M-MSG: Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (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 2CDCDC8AEA; Thu, 24 Mar 2011 02:40:21 -0500 (CDT) Received: from sausexhtp01.amd.com (163.181.3.165) by sausexedgep02.amd.com (163.181.36.59) with Microsoft SMTP Server (TLS) id 8.3.106.1; Thu, 24 Mar 2011 02:47:49 -0500 Received: from storexhtp02.amd.com (172.24.4.4) by sausexhtp01.amd.com (163.181.3.165) with Microsoft SMTP Server (TLS) id 8.3.83.0; Thu, 24 Mar 2011 02:40:28 -0500 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp02.amd.com (172.24.4.4) with Microsoft SMTP Server id 8.3.83.0; Thu, 24 Mar 2011 03:40:27 -0400 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id BF30A49C595; Thu, 24 Mar 2011 07:40:26 +0000 (GMT) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id AFA3D100BE1; Thu, 24 Mar 2011 08:40:26 +0100 (CET) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: Zachary Amsden , , Joerg Roedel Subject: [PATCH 4/6] KVM: SVM: Propagate requested TSC frequency on vcpu init Date: Thu, 24 Mar 2011 08:40:22 +0100 Message-ID: <1300952424-32014-5-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1300952424-32014-1-git-send-email-joerg.roedel@amd.com> References: <1300952424-32014-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]); Thu, 24 Mar 2011 07:41:18 +0000 (UTC) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 40ade85..d747db8 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -888,6 +888,36 @@ static u64 svm_scale_tsc(struct kvm_vcpu *vcpu, u64 tsc) return _tsc; } +static bool svm_vcpu_init_tsc(struct kvm *kvm, struct vcpu_svm *svm) +{ + u64 ratio; + u64 khz; + + /* TSC scaling supported? */ + if (!boot_cpu_has(X86_FEATURE_TSCRATEMSR)) + return true; + + /* Guest tsc same frequency as host tsc? */ + if (kvm->arch.virtual_tsc_khz == tsc_khz) + return true; + + khz = kvm->arch.virtual_tsc_khz; + + if (khz == 0) + return false; + + /* TSC scaling required - calculate ratio */ + ratio = (u64)khz << 32; + do_div(ratio, tsc_khz); + if (ratio == 0 || ratio & TSC_RATIO_RSVD) + return false; + + svm->tsc_scale.ratio = ratio; + svm->tsc_scale.enabled = true; + + return true; +} + static void svm_write_tsc_offset(struct kvm_vcpu *vcpu, u64 offset) { struct vcpu_svm *svm = to_svm(vcpu); @@ -1093,6 +1123,9 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) if (err) goto free_svm; + if (!svm_vcpu_init_tsc(kvm, svm)) + goto uninit; + err = -ENOMEM; page = alloc_page(GFP_KERNEL); if (!page)