Skip to content
This repository has been archived by the owner on Apr 10, 2021. It is now read-only.

Commit

Permalink
Fix order for converting mach absolute time
Browse files Browse the repository at this point in the history
The numer and denum [1] on regular mac are both 1 and numer and denum on
arm64 are 125 and 3. monotonic.py seem to have the order backwards
for converting mach absolute time to nanoseconds according to [2].

[1] https://opensource.apple.com/source/xnu/xnu-792/osfmk/mach/mach_time.h.auto.html
[2] https://developer.apple.com/documentation/apple_silicon/addressing_architectural_differences_in_your_macos_code
  • Loading branch information
k7z45 authored and atdt committed Jan 8, 2021
1 parent 7b07725 commit 58160d0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions monotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ class mach_timebase_info_data_t(ctypes.Structure):

timebase = mach_timebase_info_data_t()
libc.mach_timebase_info(ctypes.byref(timebase))
ticks_per_second = timebase.numer / timebase.denom * 1.0e9
nanoseconds_in_second = 1.0e9

def monotonic():
"""Monotonic clock, cannot go backward."""
return mach_absolute_time() / ticks_per_second
nanoseconds = mach_absolute_time() * timebase.numer / timebase.denom
return nanoseconds / nanoseconds_in_second

elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
if sys.platform.startswith('cygwin'):
Expand Down

0 comments on commit 58160d0

Please sign in to comment.