Browse Source

Merge pull request #3347 from harold-b/macos-timing-fix

Fix incorrect timings on macOS
Jeroen van Rijn 1 year ago
parent
commit
8899f42478
1 changed files with 12 additions and 11 deletions
  1. 12 11
      src/timings.cpp

+ 12 - 11
src/timings.cpp

@@ -33,22 +33,23 @@ gb_internal u64 win32_time_stamp__freq(void) {
 
 #include <mach/mach_time.h>
 
+gb_internal mach_timebase_info_data_t osx_init_timebase_info(void) {
+	mach_timebase_info_data_t data;
+	data.numer = 0;
+	data.denom = 0;
+	kern_return_t r = mach_timebase_info(&data);
+	GB_ASSERT(r == KERN_SUCCESS);
+
+	return data;
+}
+
 gb_internal u64 osx_time_stamp_time_now(void) {
 	return mach_absolute_time();
 }
 
 gb_internal u64 osx_time_stamp__freq(void) {
-	mach_timebase_info_data_t data;
-	data.numer = 0;
-	data.denom = 0;
-	mach_timebase_info(&data);
-#if defined(GB_CPU_ARM)
-	// NOTE(bill, 2021-02-25): M1 Chip seems to have a different freq count
-	// TODO(bill): Is this truly correct?
-	return (1000000llu * cast(u64)data.numer) / cast(u64)data.denom;
-#else
-	return (1000000000llu * cast(u64)data.numer) / cast(u64)data.denom;
-#endif
+	gb_local_persist mach_timebase_info_data_t data = osx_init_timebase_info();
+	return 1000000000ull * cast(u64)data.denom / cast(u64)data.numer;
 }
 
 #elif defined(GB_SYSTEM_UNIX)