diff options
author | Erik Kundiman <erik@megapahit.org> | 2023-12-26 12:11:15 +0800 |
---|---|---|
committer | Erik Kundiman <erik@megapahit.org> | 2023-12-26 12:11:15 +0800 |
commit | b29e14eca719e5bea9f6b2d6ca9a63bf69528b8e (patch) | |
tree | d5fe3c0cff0b6de9ade75f770e5caa3bc215e0b1 /indra/llcommon | |
parent | 26fee3c935d4483c7204998c31bb1bf9034dbd7d (diff) |
An alternative in getting CPU freq on M-series
This solution was retrieved from
https://listman.redhat.com/archives/libvir-list/2022-February/228217.html
sysctl hw.cpufrequency would result as empty on Apple Silicon (at least) M1,
when run natively. Ironically (and that's why it's been working with viewers
relying on Rosetta 2), arch -x86_64 /bin/bash -c 'sysctl hw.cpufrequency'
run on an Apple Silicon would result in the correct number.
Diffstat (limited to 'indra/llcommon')
-rw-r--r-- | indra/llcommon/llprocessor.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index cf97e7d7da..da49c31558 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -637,7 +637,16 @@ 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 setInfo(eFrequency, (F64)frequency / (F64)1000000); } |