From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zachary Amsden Subject: Re: [KVM timekeeping 17/35] Implement getnsboottime kernel API Date: Fri, 20 Aug 2010 14:52:45 -1000 Message-ID: <4C6F235D.5040100@redhat.com> References: <1282291669-25709-1-git-send-email-zamsden@redhat.com> <1282291669-25709-18-git-send-email-zamsden@redhat.com> <1282329594.3302.39.camel@localhost.localdomain> <4C6F11D6.1050101@redhat.com> <1282348958.28794.21.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Avi Kivity , Marcelo Tosatti , Glauber Costa , Thomas Gleixner , linux-kernel@vger.kernel.org To: john stultz Return-path: Received: from mx1.redhat.com ([209.132.183.28]:1025 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750843Ab0HUAw5 (ORCPT ); Fri, 20 Aug 2010 20:52:57 -0400 In-Reply-To: <1282348958.28794.21.camel@localhost.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On 08/20/2010 02:02 PM, john stultz wrote: > On Fri, 2010-08-20 at 13:37 -1000, Zachary Amsden wrote: > >> On 08/20/2010 08:39 AM, john stultz wrote: >> >>> On Thu, 2010-08-19 at 22:07 -1000, Zachary Amsden wrote: >>> >>> >>>> Add a kernel call to get the number of nanoseconds since boot. This >>>> is generally useful enough to make it a generic call. >>>> >>>> >>> Few comments here. >>> >>> >>> >>>> Signed-off-by: Zachary Amsden >>>> --- >>>> include/linux/time.h | 1 + >>>> kernel/time/timekeeping.c | 27 +++++++++++++++++++++++++++ >>>> 2 files changed, 28 insertions(+), 0 deletions(-) >>>> >>>> diff --git a/include/linux/time.h b/include/linux/time.h >>>> index ea3559f..5d04108 100644 >>>> --- a/include/linux/time.h >>>> +++ b/include/linux/time.h >>>> @@ -145,6 +145,7 @@ 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); >>>> >>>> >>> So instead of converting the timespec from getboottime, why did you add >>> a new interface? Also if not a timespec, why did you pick a s64 instead >>> of a ktime_t? >>> >>> >> The new interface was suggested several times, so I'm proposing it. I'm >> indifferent to putting it the kernel API or making it internal to KVM. >> KVM doesn't want to deal with conversions to / from ktime_t; this code >> uses a lot (too much) math, and it's easy to get wrong when splitting >> sec / nsec fields. So s64 seems a natural type for ns values. I >> realize it's not entirely consistent with the kernel API, but s64 >> representation for ns seems to be creeping in. >> > I can understand wanting that, way back I was pushing for s64 ns > representations for most time values, but the ktime_t was considered a > reasonable compromise to avoid costly 64bit divides to split (sec,nsec) > on 32bit arches. > We want time in simply parseable formats, so we always end up with sec / msec, sec / usec, sec / nsec. This is simply a convenient representation for humans. Programmers always end up copying this model and it causes so many lovely bugs. How many times can you race while reading CMOS Y/M/D/H/S? Fortunately now that 64-bit computing is nearly pervasive, we can make most of these problems go away. I think gettimefromboot_ns() is a good descriptive name, but slightly too long - it would ruin my indentation. Perhaps getrealtime_ns()? Zach