Re: Linux 3.1-rc9

From: Ingo Molnar
Date: Mon Oct 17 2011 - 18:06:00 EST



* Ingo Molnar <mingo@xxxxxxx> wrote:

>
> * Ingo Molnar <mingo@xxxxxxx> 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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/