From patchwork Tue Jun 15 07:34:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachary Amsden X-Patchwork-Id: 106135 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5F7b8xl009112 for ; Tue, 15 Jun 2010 07:37:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755562Ab0FOHex (ORCPT ); Tue, 15 Jun 2010 03:34:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9815 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755544Ab0FOHev (ORCPT ); Tue, 15 Jun 2010 03:34:51 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5F7Ypvg029162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Jun 2010 03:34:51 -0400 Received: from mysore (vpn-8-141.rdu.redhat.com [10.11.8.141]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5F7YL2m024602; Tue, 15 Jun 2010 03:34:49 -0400 From: Zachary Amsden To: avi@redhat.com, mtosatti@redhat.com, glommer@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Zachary Amsden Subject: [PATCH 12/17] Add helper function get_kernel_ns Date: Mon, 14 Jun 2010 21:34:14 -1000 Message-Id: <1276587259-32319-13-git-send-email-zamsden@redhat.com> In-Reply-To: <1276587259-32319-1-git-send-email-zamsden@redhat.com> References: <1276587259-32319-1-git-send-email-zamsden@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 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]); Tue, 15 Jun 2010 07:37:10 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 703ea43..15c7317 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -915,6 +915,16 @@ static void kvm_get_time_scale(uint32_t scaled_khz, uint32_t base_khz, __func__, base_khz, scaled_khz, shift, *pmultiplier); } +static inline u64 get_kernel_ns(void) +{ + struct timespec ts; + + WARN_ON(preemptible()); + ktime_get_ts(&ts); + monotonic_to_bootbased(&ts); + return timespec_to_ns(&ts); +} + static DEFINE_PER_CPU(unsigned long, cpu_tsc_khz); static inline void kvm_request_guest_time_update(struct kvm_vcpu *v) @@ -924,7 +934,6 @@ static inline void kvm_request_guest_time_update(struct kvm_vcpu *v) static int kvm_recompute_guest_time(struct kvm_vcpu *v) { - struct timespec ts; unsigned long flags; struct kvm_vcpu_arch *vcpu = &v->arch; void *shared_kaddr; @@ -944,9 +953,7 @@ static int kvm_recompute_guest_time(struct kvm_vcpu *v) local_irq_save(flags); this_tsc_khz = __get_cpu_var(cpu_tsc_khz); kvm_get_msr(v, MSR_IA32_TSC, &tsc_timestamp); - ktime_get_ts(&ts); - monotonic_to_bootbased(&ts); - kernel_ns = timespec_to_ns(&ts); + kernel_ns = get_kernel_ns(); local_irq_restore(flags); if (unlikely(this_tsc_khz == 0)) { @@ -1865,11 +1872,7 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) /* Subtract elapsed cycle time from the delta computation */ if (check_tsc_unstable() && vcpu->arch.last_host_ns) { - s64 delta; - struct timespec ts; - ktime_get_ts(&ts); - monotonic_to_bootbased(&ts); - delta = timespec_to_ns(&ts) - vcpu->arch.last_host_ns; + s64 delta = get_kernel_ns() - vcpu->arch.last_host_ns; delta = delta * per_cpu(cpu_tsc_khz, cpu); delta = delta / USEC_PER_SEC; tsc_delta -= delta; @@ -1898,10 +1901,7 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) * vcpu->cpu = -1 to force the recalibration above. */ if (check_tsc_unstable()) { - struct timespec ts; - ktime_get_ts(&ts); - monotonic_to_bootbased(&ts); - vcpu->arch.last_host_ns = timespec_to_ns(&ts); + vcpu->arch.last_host_ns = get_kernel_ns(); vcpu->cpu = -1; } }