haasn / libplacebo

Official mirror of libplacebo
http://libplacebo.org/
GNU Lesser General Public License v2.1
547 stars 69 forks source link

pl_clock: use correct clock_id on apple platforms #208

Closed orion1vi closed 1 year ago

orion1vi commented 1 year ago

CLOCK_MONOTONIC_RAW on apple platforms is a monotonic clock that gets incremented while system is suspended, the clock_id that should actually be used is CLOCK_UPTIME_RAW, this clock does not get incremented while system is suspended and matches time value of mach_absolute_time but with timebase ratio applied, so returned time is in nano seconds.

Fixes discrepancy with PL_CLOCK_MACH path.

See: https://github.com/apple-oss-distributions/Libc/blob/c5a3293354e22262702a3add5b2dfc9bb0b93b85/gen/clock_gettime.c#L168

haasn commented 1 year ago

cc @kasper93

kasper93 commented 1 year ago

Why?

orion1vi commented 1 year ago

Because CLOCK_MONOTONIC_RAW means different things between Apple and Linux. Also matches macOS < 10.12 fallback, besides not requiring the timebase conversion.

kasper93 commented 1 year ago

I know what you are saying, but what functional change are you trying to make? In other words, what is the issue you are trying to fix? I don't mind either way, just asking what's the purpose of this change.

orion1vi commented 1 year ago

A more consistent behaviour between systems I guess.

kasper93 commented 1 year ago

I used CLOCK_MONOTONIC_RAW because libc++ also is using it for steady_clock. I'm fine changing it, if you feel it is better.

orion1vi commented 1 year ago

I looked into why it was changed https://reviews.llvm.org/D74341 and took closer look for what purposes the clock is used in libplacebo and it shouldn't matter much that it increments while system is sleeping, so I'll close this.