Skip to content

Commit

Permalink
darwin: removed unused Platform_calculateNanosecondsPerMachTick function
Browse files Browse the repository at this point in the history
  • Loading branch information
aestriplex committed Feb 25, 2025
1 parent 6a663f3 commit 03ecb2d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 41 deletions.
3 changes: 0 additions & 3 deletions darwin/Platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,11 @@ const MeterClass* const Platform_meterTypes[] = {
NULL
};

static double Platform_nanosecondsPerMachTick = 1.0;

static double Platform_nanosecondsPerSchedulerTick = -1;

static mach_port_t iokit_port; // the mach port used to initiate communication with IOKit

bool Platform_init(void) {
Platform_nanosecondsPerMachTick = Platform_calculateNanosecondsPerMachTick();

// Determine the number of scheduler clock ticks per second
errno = 0;
Expand Down
34 changes: 0 additions & 34 deletions darwin/PlatformHelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,37 +86,3 @@ bool Platform_isRunningTranslated(void) {
}
return ret;
}

double Platform_calculateNanosecondsPerMachTick(void) {
// Check if we can determine the timebase used on this system.
// If the API is unavailable assume we get our timebase in nanoseconds.
#ifndef HAVE_MACH_TIMEBASE_INFO
return 1.0;
#else
mach_timebase_info_data_t info;

/* WORKAROUND for `mach_timebase_info` giving incorrect values on M1 under Rosetta 2.
* rdar://FB9546856 https://openradar.appspot.com/radar?id=5055988478509056
*
* We don't know exactly what feature/attribute of the M1 chip causes this mistake under Rosetta 2.
* Until we have more Apple ARM chips to compare against, the best we can do is special-case
* the "Apple M1" chip specifically when running under Rosetta 2.
*/

bool isRunningUnderRosetta2 = Platform_isRunningTranslated();

// Kernel version 20.0.0 is macOS 11.0 (Big Sur)
bool isBuggedVersion = Platform_KernelVersionIsBetween((KernelVersion) {20, 0, 0}, (KernelVersion) {999, 999, 999});

if (isRunningUnderRosetta2 && isBuggedVersion) {
// In this case `mach_timebase_info` provides the wrong value, so we hard-code the correct factor,
// as determined from `mach_timebase_info` when the process running natively.
info = (mach_timebase_info_data_t) { .numer = 125, .denom = 3 };
} else {
// No workarounds needed, use the OS-provided value.
mach_timebase_info(&info);
}

return (double)info.numer / (double)info.denom;
#endif
}
4 changes: 0 additions & 4 deletions darwin/PlatformHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ int Platform_CompareKernelVersion(KernelVersion v);
// lowerBound <= currentVersion < upperBound
bool Platform_KernelVersionIsBetween(KernelVersion lowerBound, KernelVersion upperBound);

double Platform_calculateNanosecondsPerMachTick(void);

void Platform_getCPUBrandString(char* cpuBrandString, size_t cpuBrandStringSize);

bool Platform_isRunningTranslated(void);

double Platform_calculateNanosecondsPerMachTick(void);

#endif

0 comments on commit 03ecb2d

Please sign in to comment.