From patchwork Wed Sep 1 05:57:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachary Amsden X-Patchwork-Id: 146171 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 o815wBUW021655 for ; Wed, 1 Sep 2010 05:58:11 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752618Ab0IAF5f (ORCPT ); Wed, 1 Sep 2010 01:57:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64948 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752446Ab0IAF5W (ORCPT ); Wed, 1 Sep 2010 01:57:22 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o815vF84002620 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 1 Sep 2010 01:57:15 -0400 Received: from mysore (vpn-10-81.rdu.redhat.com [10.11.10.81]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o815vChJ007615; Wed, 1 Sep 2010 01:57:13 -0400 From: Zachary Amsden To: kvm@vger.kernel.org Cc: Zachary Amsden , Avi Kivity , Marcelo Tosatti , Glauber Costa , Jan Kiszka , Thomas Gleixner , John Stultz , linux-kernel@vger.kernel.org Subject: [KVM timekeeping] Revert getnsboottime() kernel API Date: Tue, 31 Aug 2010 19:57:04 -1000 Message-Id: <1283320624-31262-1-git-send-email-zamsden@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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 (demeter1.kernel.org [140.211.167.41]); Wed, 01 Sep 2010 05:58:11 +0000 (UTC) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 4014d6c..03605b8 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -919,6 +919,16 @@ static inline u64 nsec_to_cycles(u64 nsec) return ret; } +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); +} + void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data) { struct kvm *kvm = vcpu->kvm; @@ -928,7 +938,7 @@ void kvm_write_tsc(struct kvm_vcpu *vcpu, u64 data) spin_lock_irqsave(&kvm->arch.tsc_write_lock, flags); offset = data - native_read_tsc(); - ns = getnsboottime(); + ns = get_kernel_ns(); elapsed = ns - kvm->arch.last_tsc_nsec; sdiff = data - kvm->arch.last_tsc_write; if (sdiff < 0) @@ -981,7 +991,7 @@ static int kvm_write_guest_time(struct kvm_vcpu *v) /* Keep irq disabled to prevent changes to the clock */ local_irq_save(flags); kvm_get_msr(v, MSR_IA32_TSC, &tsc_timestamp); - kernel_ns = getnsboottime(); + kernel_ns = get_kernel_ns(); this_tsc_khz = __get_cpu_var(cpu_tsc_khz); local_irq_restore(flags); @@ -3327,7 +3337,7 @@ long kvm_arch_vm_ioctl(struct file *filp, goto out; r = 0; - now_ns = getnsboottime(); + now_ns = get_kernel_ns(); delta = user_ns.clock - now_ns; kvm->arch.kvmclock_offset = delta; break; @@ -3336,7 +3346,7 @@ long kvm_arch_vm_ioctl(struct file *filp, struct kvm_clock_data user_ns; u64 now_ns; - now_ns = getnsboottime(); + now_ns = get_kernel_ns(); user_ns.clock = kvm->arch.kvmclock_offset + now_ns; user_ns.flags = 0; diff --git a/include/linux/time.h b/include/linux/time.h index 909e62a..9f15ac7 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -160,7 +160,6 @@ extern void getnstimeofday(struct timespec *tv); extern void getrawmonotonic(struct timespec *ts); extern void getboottime(struct timespec *ts); extern void monotonic_to_bootbased(struct timespec *ts); -extern s64 getnsboottime(void); extern struct timespec timespec_trunc(struct timespec t, unsigned gran); extern int timekeeping_valid_for_hres(void); diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 77e930d..dfbe271 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -284,33 +284,6 @@ void ktime_get_ts(struct timespec *ts) } EXPORT_SYMBOL_GPL(ktime_get_ts); - -/** - * getnsboottime - get the bootbased clock in nsec format - * - * The function calculates the bootbased clock from the realtime - * clock and the wall_to_monotonic offset and stores the result - * in normalized timespec format in the variable pointed to by @ts. - */ -s64 getnsboottime(void) -{ - unsigned int seq; - s64 secs, nsecs; - - WARN_ON(timekeeping_suspended); - - do { - seq = read_seqbegin(&xtime_lock); - secs = xtime.tv_sec + wall_to_monotonic.tv_sec; - secs += total_sleep_time.tv_sec; - nsecs = xtime.tv_nsec + wall_to_monotonic.tv_nsec; - nsecs += total_sleep_time.tv_nsec + timekeeping_get_ns(); - - } while (read_seqretry(&xtime_lock, seq)); - return nsecs + (secs * NSEC_PER_SEC); -} -EXPORT_SYMBOL_GPL(getnsboottime); - /** * do_gettimeofday - Returns the time of day in a timeval * @tv: pointer to the timeval to be set @@ -327,6 +300,7 @@ void do_gettimeofday(struct timeval *tv) } EXPORT_SYMBOL(do_gettimeofday); + /** * do_settimeofday - Sets the time of day * @tv: pointer to the timespec variable containing the new time