Repository navigation
Read Apple Silicon cluster frequencies lazily, not as a side effect - #3672
Conversation
On Apple Silicon the nominal performance and efficiency cluster frequencies come from the power manager's voltage-state tables, which were read by calculateNominalFrequencies() and stored in two volatile fields. Nothing called that method except queryProcessorId(), so getMaxFreq() and getCurrentFreq() returned the DEFAULT_FREQUENCY placeholder — 2.4 GHz for every core — unless a caller happened to ask for the processor identifier first. On an M3 Pro, maxFreq read 2.4 GHz cold and 4.056 GHz warm. Replace the two fields and the setters with a Supplier<Pair<Long, Long>> memoized indefinitely, since these are fixed hardware properties, and have all three consumers read it through the existing getters. queryProcessorId() no longer has a frequency side effect. The bug is in oshi-common, so both backends had it; it also made NativeComparisonTest.processorFrequencies fail on Apple Silicon, depending on which instance had its cpuid warmed.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📜 Recent review details⏰ Context from checks skipped due to timeout. (8)
🧰 Additional context used📓 Path-based instructions (5)CHANGELOG.md📄 CodeRabbit inference engine (AGENTS.md)
Files:
**📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/src/test/java/**/*Test.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (3)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-12T19:34:56.879ZApplied to files:
📚 Learning: 2026-08-03T00:46:14.953ZApplied to files:
🔇 Additional comments (11)
📝 WalkthroughWalkthroughApple Silicon nominal frequencies now use a lazily memoized performance and efficiency pair. Frequency reporting and processor identification share this query. Tests cover call order, cluster mapping, and query count. ChangesApple Silicon frequency reporting
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change makes Apple Silicon frequency discovery lazy and order-independent while preserving existing Intel behavior, with targeted tests and successful verification reported; no actionable merge-blocking risk remains after normal checks and review. Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3672 +/- ##
============================================
- Coverage 80.15% 80.15% -0.01%
- Complexity 4130 4367 +237
============================================
Files 703 703
Lines 24987 24985 -2
Branches 4185 4183 -2
============================================
- Hits 20028 20026 -2
- Misses 2778 2782 +4
+ Partials 2181 2177 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
On Apple Silicon the nominal performance and efficiency cluster frequencies come from the power manager's voltage-state tables (
voltage-states5-sramandvoltage-states1-sramon thepmgrAppleARMIODevicenode).MacCentralProcessorread them incalculateNominalFrequencies()and stored them in twovolatile longfields — but nothing called that method exceptqueryProcessorId().So
getMaxFreq()andgetCurrentFreq()returned theDEFAULT_FREQUENCYplaceholder, 2.4 GHz for every core, unless a caller happened to ask for the processor identifier first. Measured on an M3 Pro before this change:getMaxFreq()getCurrentFreq()getMaxFreq()firstgetProcessorIdentifier()firstThis is also why
oshi.comparison.NativeComparisonTest.processorFrequenciesfailed on Apple Silicon: not JNA/FFM divergence, just which instance had itscpuidwarmed first. The bug lives inoshi-common, so both backends had it.Change
The two fields and their setters are replaced by a
Supplier<Pair<Long, Long>>memoized indefinitely — these are fixed hardware properties — behind a newprotected Pair<Long, Long> queryNominalFrequencies()seam.getPerformanceCoreFrequency()/getEfficiencyCoreFrequency()keep their signatures and now read the supplier, so all three consumers (queryProcessorId,queryMaxFreq,queryCurrentFreq) get the real values in any order, from one IORegistry walk.queryProcessorId()no longer has a frequency side effect.Three tests in
MacCentralProcessorTestcover it against a new Apple Silicon stub (4 E + 4 P cores, distinct cluster frequencies): max frequency without first querying the identifier, per-cluster current frequencies, and one walk shared by all three consumers. Making the real frequency code paths reachable meant dropping the stub'squeryMaxFreq/queryCurrentFreqoverrides, which had returned 0.Verification
Verified on an M3 Pro (macOS 15, JNA and FFM): both call orders now report 4.056 GHz max and
[2.748 × 6, 4.056 × 6]current, andNativeComparisonTest.processorFrequenciespasses. Full gate green including-Paggregate-coverage,forbiddenapis:check,javadoc:javadocand-Perror-prone.Not verified: Intel Macs. That branch is untouched by this change —
isArmCpuis false there and both methods still readhw.cpufrequency*sysctls.Not in scope
Apple M5 renumbered the pmgr voltage-state power domains, so the hardcoded index 1 is absent there and the efficiency frequency will fall back to the placeholder. Filed separately; it needs dynamic discovery via pmgr
acc-clusters, which does not exist on M1–M4.Summary by CodeRabbit
Bug Fixes
Documentation