[NativeAOT] Use clock_gettime_nsec_np if available in GCToOSInterface::GetLowPrecisionTimeStamp
Tagging subscribers to this area: @dotnet/gc See info in area-owners.md if you want to be subscribed.
GetLowPrecisionTimeStamp is supposed to be much cheaper than the high res version. although I'm not sure if gettimeofday is much cheaper than clock_gettime_nsec_np. do you happen to know?
macOS has a coarse monotonic timer that is in millisecond ticks, but nowdays Apple recommends using the nanosecond equivalent instead.
https://developer.apple.com/documentation/kernel/1646199-mach_continuous_time
thanks @VSadov. do you happen to know the cost? it's not a huge deal but it's useful info to have.
thanks @VSadov. do you happen to know the cost? it's not a huge deal but it's useful info to have.
I checked the libc code. This particular usage is implemented with mach_absolute_time which happens to be very similar to what GetTickCount does on Windows in terms of performance. It runs entirely in user mode and reads data from shared page and may augment it with something like rdtsc.
do you happen to know the cost?
Nope, I do not know. It probably varies for different platforms, but must be the best that Apple can do, since they deprecated other APIs.
It has been used in CoreCLR for 2 years now, so I assume the cost is acceptable to us. (Here is another discussion on this: https://github.com/dotnet/runtime/pull/40435#discussion_r500612807 )
This change just aligns the implementation that NativeAOT uses with what we have in CoreCLR. https://github.com/dotnet/runtime/blob/78528df15f9b7e214327d87a6596a77b6b9ea527/src/coreclr/pal/src/misc/time.cpp#L278-L310
@filipnavara thanks for the info!
@Maoni0 for the gc.cpp changes.
Thanks!!