[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20111017220425.GB18523@elte.hu>
Date:	Tue, 18 Oct 2011 00:04:26 +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:
> 
> * 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.)
that's timespec.nsecs - there's timeval.usecs. The same argument 
applies in both cases.
This would deobfuscate a rather important data type in the timer 
code.
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
 
