From patchwork Wed Aug 25 21:43:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Glauber Costa X-Patchwork-Id: 132941 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o7PLxOVb027451 for ; Wed, 25 Aug 2010 21:59:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753628Ab0HYV7W (ORCPT ); Wed, 25 Aug 2010 17:59:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52255 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752480Ab0HYV7U (ORCPT ); Wed, 25 Aug 2010 17:59:20 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7PLxKaL024932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Aug 2010 17:59:20 -0400 Received: from localhost.localdomain (virtlab1.virt.bos.redhat.com [10.16.72.21]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7PLxDaY022101; Wed, 25 Aug 2010 17:59:18 -0400 From: Glauber Costa To: kvm@vger.kernel.org Cc: avi@redhat.com, zamsden@redhat.com, mtosatti@redhat.com, riel@redhat.com Subject: [RFC 5/7] kvm steal time implementation Date: Wed, 25 Aug 2010 17:43:15 -0400 Message-Id: <1282772597-4183-6-git-send-email-glommer@redhat.com> In-Reply-To: <1282772597-4183-5-git-send-email-glommer@redhat.com> References: <1282772597-4183-1-git-send-email-glommer@redhat.com> <1282772597-4183-2-git-send-email-glommer@redhat.com> <1282772597-4183-3-git-send-email-glommer@redhat.com> <1282772597-4183-4-git-send-email-glommer@redhat.com> <1282772597-4183-5-git-send-email-glommer@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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.3 (demeter.kernel.org [140.211.167.41]); Wed, 25 Aug 2010 21:59:24 +0000 (UTC) diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c index eb9b76c..a1f4852 100644 --- a/arch/x86/kernel/kvmclock.c +++ b/arch/x86/kernel/kvmclock.c @@ -18,6 +18,8 @@ #include #include +#include +#include #include #include #include @@ -41,6 +43,7 @@ early_param("no-kvmclock", parse_no_kvmclock); /* The hypervisor will put information about time periodically here */ static DEFINE_PER_CPU_SHARED_ALIGNED(struct pvclock_vcpu_time_info, hv_clock); +static DEFINE_PER_CPU(u64, steal_info); static struct pvclock_wall_clock wall_clock; /* @@ -82,6 +85,32 @@ static cycle_t kvm_clock_read(void) return ret; } +static DEFINE_PER_CPU(u64, steal_info); + +cputime_t kvm_get_steal_time(void) +{ + u64 delta = 0; + u64 *last_steal_info, this_steal_info; + struct pvclock_vcpu_time_info *src; + + src = &get_cpu_var(hv_clock); + if (!(src->flags & PVCLOCK_STEAL_BIT)) + goto out; + + this_steal_info = src->steal_time; + put_cpu_var(hv_clock); + + last_steal_info = &get_cpu_var(steal_info); + + delta = this_steal_info - *last_steal_info; + + *last_steal_info = this_steal_info; + put_cpu_var(steal_info); + +out: + return msecs_to_cputime(delta); +} + static cycle_t kvm_clock_get_cycles(struct clocksource *cs) { return kvm_clock_read(); @@ -134,6 +163,8 @@ static int kvm_register_clock(char *txt) printk(KERN_INFO "kvm-clock: cpu %d, msr %x:%x, %s\n", cpu, high, low, txt); + per_cpu(steal_info, cpu) = 0; + return native_write_msr_safe(msr_kvm_system_time, low, high); } @@ -218,4 +249,8 @@ void __init kvmclock_init(void) if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STABLE_BIT)) pvclock_set_flags(PVCLOCK_TSC_STABLE_BIT); + + + if (kvm_para_has_feature(KVM_FEATURE_CLOCKSOURCE_STEAL_BIT)) + hypervisor_steal_time = kvm_get_steal_time; }