runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[NativeAOT] Use clock_gettime_nsec_np if available in GCToOSInterface::GetLowPrecisionTimeStamp

Open filipnavara opened this issue 3 years ago • 7 comments

This aligns NativeAOT implementation closer to the CoreCLR one (1, 2).

Related to #75708.

filipnavara avatar Sep 19 '22 20:09 filipnavara

Tagging subscribers to this area: @dotnet/gc See info in area-owners.md if you want to be subscribed.

Issue Details

This aligns NativeAOT implementation closer to the CoreCLR one (1, 2).

Related to #75708.

Author: filipnavara
Assignees: -
Labels:

area-GC-coreclr

Milestone: -

ghost avatar Sep 19 '22 20:09 ghost

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?

Maoni0 avatar Sep 20 '22 05:09 Maoni0

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

VSadov avatar Sep 20 '22 05:09 VSadov

thanks @VSadov. do you happen to know the cost? it's not a huge deal but it's useful info to have.

Maoni0 avatar Sep 20 '22 06:09 Maoni0

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.

filipnavara avatar Sep 20 '22 07:09 filipnavara

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

VSadov avatar Sep 20 '22 07:09 VSadov

@filipnavara thanks for the info!

Maoni0 avatar Sep 20 '22 07:09 Maoni0

@Maoni0 for the gc.cpp changes.

VSadov avatar Sep 21 '22 17:09 VSadov

Thanks!!

VSadov avatar Sep 21 '22 18:09 VSadov