News for hackers. Stuff that matters.
Re:The slow currentTimeMillis() by pjc50 on Friday August 04, 2017 @08:21AM (#14928123)
The Windows version is absolutely brilliant: a shared area mapped into every process. Because of the way page tables work, this costs only one page (4k) of RAM and only has to be written once by the OS.
Re:The slow currentTimeMillis() by bonzini on Friday August 04, 2017 @10:30AM (#14928902)
The Linux version does the same, actually.

As explained in the article, the Windows version is so small because it can only provide a resolution limited to the timer tick's resolution (2048 Hz in this case, but unless a program explicitly requests a high resolution it can be as low as 64 Hz IIRC). The cost to having a higher resolution is also a higher number of interrupts per second, which wastes power unnecessarily when you are idle[1].

Instead, as the atthe Linux version can provide a resolution limited only by the actual clocksource, which is nanoseconds in the case of the TSC. There is no background process that "updates the fields of this structure at regular intervals"; the updates only need to happen if the speed of the clock changes, for example due to an NTP update. While in the blog post it's measured to happen every millisecond, it can be configured to be lower without affecting the resolution of gettimeofday. There is also a special mode where you make it tick as slowly as 1 Hz on CPUs that have only one runnable process (if you have more than one runnable process, the scheduler needs to do context switches so the kernel cannot tick slowly).

[1] https://randomascii.wordpress.com/2013/07/08/windows-timer-r...

Re:The slow currentTimeMillis() by jevinskie on Friday August 04, 2017 @07:36PM (#14933256)
XNU has an equivalent to vDSO: the commpage. It is also used for time.
Re:The slow currentTimeMillis() by richardwhiuk on Friday August 04, 2017 @09:01AM (#14928329)
The locking is also neat - no software locking, and yet you are guaranteed to get correct values. Simply read High, Low, High2, and then check that High and High2 are equal.

(Hitting the memory address will require some level of CPU level cache coherency protocol to kick in, but that's much cheaper than the equivalent mutex).

Re:The slow currentTimeMillis() by the8472 on Friday August 04, 2017 @09:15AM (#14928405)
interestingly this can only works on x86 due to it being a TSO architecture. windows on ARM must be doing something else since it's weakly ordered.
Re:The slow currentTimeMillis() by tankenmate on Friday August 04, 2017 @09:45AM (#14928575)
Memory barriers, these are instructions that force memory order. You can read about the ARM implementation of memory barriers here;

http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc....