> why the TSC isn't used
Because on most modern CPUs, clock frequency is extremely unstable: Turbo Boost, SpeedStep, Cool'n'Quiet, etc. These features make TSC not suitable for time measures.
Re:The slow currentTimeMillis()
by bitcharmer on Friday August 04, 2017 @10:22AM
(#14928845)
Please check for what features like constant_tsc or nonstop_tsc are for before spreading misinformation
That thing is intel-only, or at least Linux kernel thinks so: https://github.com/torvalds/linux/blob/master/arch/x86/kerne...
And even on Intel, TSC is not reliable: https://lwn.net/Articles/388286/
AMD CPUs have supported constant_tsc and nonstop_tsc since the Phenom era too.
There have also been some multi-socket configurations where TSC will gradually become desynchronized across sockets.
That lkml thread was back in 2010, before invariant TSC was a thing.
Re:The slow currentTimeMillis()
by yjftsjthsd-h on Friday August 04, 2017 @02:11PM
(#14930641)
> intel-only
So... >99% of servers and the vast majority of desktops?
This is covered in the fine article.
Also:
> The second value is the nanoseconds time, relative to the last second, shifted left by gtod->shift, Or, rather, it the time measured in some units, which becomes the nanosecond time when shifted right by gtod->shift, which, in our case, is 25. This is very high precision. One nanosecond divided by 225 is about 30 attoseconds. Perhaps, Linux kernel designers looked far ahead, anticipating the future when we’ll need such accuracy for our time measurement.
That's not what's going on. This is straightforward fixed point arithmetic, where the point just happens to be variable.