On Aug 15, 2012, at 8:17 PM, Ted Unangst <[email protected]> wrote:
> On Wed, Aug 15, 2012 at 13:25, Ted Unangst wrote: > > I will probably rename this just "tsc" after some prodding from mikeb, > that's a better name. I tend to focus on the instruction used, but we > should name it after the counter. > >> + rdtsc_timecounter.tc_frequency = cpuspeed; > >> + /* cpuspeed is scaled down, so for now, we do the same */ >> + tsc = rdtsc(); >> + tsc /= 1000000; >> + return (uint32_t)tsc; > > This I know is suboptimal. We need to scale down some, to avoid > overflow, but a factor of 1000 is probably better. Or 1024 and shift > for more speeds. If it's only about scaling >>= 10 or 20 is perfectly fine as long as no user of rdtsc_get_timecount tries to translate the return value back into reliable seconds. That would introduce minor jitter. Or maybe "frequency" needs to be adjusted accordingly. Or the translation should be done inline so that tsc is never leaked? Unfortunately, a lot of these high resolution scenarios are bound to "per second" metrics, so the trouble of making it as fast as possible only relays the inevitable. I guess it is best to leave it as is, although it would be nice for the magical 1000000 to be tied to the actual cpuspeed scaling. It could go out of sync. Franco
