[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20111017220321.GA18523@elte.hu>
Date: Tue, 18 Oct 2011 00:03:21 +0200
From: Ingo Molnar <mingo@...e.hu>
To: "H. Peter Anvin" <hpa@...or.com>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Simon Kirby <sim@...tway.ca>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Dave Jones <davej@...hat.com>,
Martin Schwidefsky <schwidefsky@...ibm.com>
Subject: Re: Linux 3.1-rc9
* Ingo Molnar <mingo@...e.hu> wrote:
> > > In particular we could try something like:
> > >
> > > (high*2^32 + low)/1e9 ~== ( high * (2^64/1e9) ) / 2^32
> > >
> > > ... which reduces it all to a 64-bit multiplication (or two
> > > 32-bit multiplications) with a known constant, at the cost of 1
> > > nsec imprecision of the result - but that's an OK approximation
> > > in my opinion.
> > >
> >
> > We can do much better than that with reciprocal multiplication.
>
> Yes, 2^64/1e9 is the reciprocal.
So basically, to extend on the pseudocode above, we could do the
equivalent of:
/* 2^64/1e9: */
#define MAGIC 18446744073ULL
secs_fast = ((nsecs >> 32) * MAGIC) >> 32;
secs_fast += (nsecs & 0xFFFFFFFF)/1000000000;
to get to the precise 'timeval.secs' field - these are all 32-bit
operations: a 32-bit multiplication and a 32-bit division if i
counted it right.
(Likewise we can get the remainder as well, for timeval.nsecs.)
So I think if we add 32-bit optimized reciprocal multiplication based
timeval and timespec routines, we can change ktime_t to a simple
scalar type on 64-bit and 32-bit architectures alike.
It would likely be faster as well: the 32-bit ktime operations are
more complex than straightforward u64 operations.
Thomas, what do you think?
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists