tbfreq x clockrate.hz only when cpufrequency is 0

Just maybe M3 implements cpufrequency, which should be more accurate
than the alternative (different results on my Intel Mac).
master
Erik Kundiman 2023-12-31 20:17:04 +08:00
parent 268281a570
commit 2117dca25e
1 changed files with 8 additions and 8 deletions

View File

@ -637,15 +637,15 @@ public:
LLProcessorInfoDarwinImpl()
{
getCPUIDInfo();
#ifdef __arm64__
auto frequency = getSysctlInt64("hw.tbfrequency");
struct clockinfo clockrate;
auto clockrate_len = sizeof(clockrate);
if (!sysctlbyname("kern.clockrate", &clockrate, &clockrate_len, NULL, 0))
frequency *= clockrate.hz;
#else
uint64_t frequency = getSysctlInt64("hw.cpufrequency");
#endif
if (!frequency)
{
auto tbfrequency = getSysctlInt64("hw.tbfrequency");
struct clockinfo clockrate;
auto clockrate_len = sizeof(clockrate);
if (!sysctlbyname("kern.clockrate", &clockrate, &clockrate_len, NULL, 0))
frequency = tbfrequency * clockrate.hz;
}
setInfo(eFrequency, (F64)frequency / (F64)1000000);
}