Skip to content

Read Apple Silicon cluster frequencies lazily, not as a side effect - #3672

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:mac-cluster-freq-init-order
Aug 20, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:mac-cluster-freq-init-order

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

On Apple Silicon the nominal performance and efficiency cluster frequencies come from the power manager's voltage-state tables (voltage-states5-sram and voltage-states1-sram on the pmgr AppleARMIODevice node). MacCentralProcessor read them in calculateNominalFrequencies() and stored them in two volatile long fields — but 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. Measured on an M3 Pro before this change:

call order getMaxFreq() getCurrentFreq()
getMaxFreq() first 2.400 GHz 2.4 GHz × 12
getProcessorIdentifier() first 4.056 GHz 2.748 × 6, 4.056 × 6

This is also why oshi.comparison.NativeComparisonTest.processorFrequencies failed on Apple Silicon: not JNA/FFM divergence, just which instance had its cpuid warmed first. The bug lives in oshi-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 new protected 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 MacCentralProcessorTest cover 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's queryMaxFreq/queryCurrentFreq overrides, 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, and NativeComparisonTest.processorFrequencies passes. Full gate green including -Paggregate-coverage, forbiddenapis:check, javadoc:javadoc and -Perror-prone.

Not verified: Intel Macs. That branch is untouched by this change — isArmCpu is false there and both methods still read hw.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

    • Corrected Apple Silicon processor frequency reporting.
    • Maximum and current frequencies now reflect the actual performance and efficiency cluster frequencies.
    • Frequency results are accurate regardless of whether processor identification or frequency queries occur first.
    • Improved reporting for systems with different performance and efficiency core configurations.
  • Documentation

    • Added release notes for version 7.6.0.

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.
@coderabbitai

coderabbitai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 73a9ad0a-557b-403d-b4f6-7dbd7db9db8b

📥 Commits

Reviewing files that changed from the base of the PR and between bd71af2 and 6d631ad.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java

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)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (5)
CHANGELOG.md

📄 CodeRabbit inference engine (AGENTS.md)

Add a CHANGELOG.md entry under Next Release only for user-visible changes.

Files:

  • CHANGELOG.md
**

📄 CodeRabbit inference engine (AGENTS.md)

**: Do not add dependencies without discussion, and do not bump dependency versions by hand —
Renovate handles that.
Do not commit generated output, target/, or IDE files.

Files:

  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java
oshi-common/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-common/src/main/java/**/*.java: Before writing any parsing helper, check whether ParseUtil already has one.
oshi-common may not reference com.sun.jna.**, java.lang.foreign.**, or any
System.load/loadLibrary. It must stay pure JDK.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
**/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/src/main/java/**/*.java: Javadoc. Every public and protected type and method needs javadoc.
Do not use fully-qualified class names in
code or in javadoc — including inside {@link ...}. Import the type and link the simple name.
New files get a current-year-only
header (Copyright 2026 The OSHI Project Contributors / SPDX-License-Identifier: MIT), even when
copied from an older file; spotless maintains end years on existing files.
Never add a line range to
config/checkstyle-suppressions.xml — a range breaks the moment anything above it shifts, including a
single added import, and the failure looks unrelated to the change that caused it.
new classes are
expected to declare one, and matching the annotation of the class you are modeling yours on is the
right default.
Do not reach for @Nullable to make a null return legal: the convention is a sentinel, not a
null
— Constants.UNKNOWN or "" for strings, an empty collection or array, and 0/-1/NaN
for numbers, whichever is outside the value's real range.
System calls are expensive, and callers poll. Values that are constant (CPU model,
serial number) or expensive-but-slow-changing are wrapped in
oshi.util.Memoizer.memoize(supplier, ...)

Files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
**/src/test/java/**/*Test.java

📄 CodeRabbit inference engine (AGENTS.md)

Test files are named *Test.java.

Files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java
🧠 Learnings (3)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.

Applied to files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java
🔇 Additional comments (11)
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java (5)

78-81: LGTM!


375-391: LGTM!


400-409: LGTM!


462-462: LGTM!


540-554: LGTM!

CHANGELOG.md (1)

18-18: LGTM!

oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java (5)

16-22: LGTM!


162-192: LGTM!


491-506: LGTM!


528-536: LGTM!


538-582: LGTM!


📝 Walkthrough

Walkthrough

Apple 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.

Changes

Apple Silicon frequency reporting

Layer / File(s) Summary
Lazy nominal-frequency reporting
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java, CHANGELOG.md
MacCentralProcessor now lazily queries and memoizes both cluster frequencies. ARM identification, current-frequency mapping, and maximum-frequency reporting use the accessors. The changelog records the fix.
Frequency regression coverage
oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java
Tests model an Apple M3 Pro topology and verify maximum frequency, cluster-specific current frequencies, call-order independence, and one nominal-frequency query.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 6d631

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

A rabbit checked the clusters twice,
Then cached their measured highs.
“Performance here, efficiency there,”
It mapped each core with care.
One query, correct replies! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.83% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 2 files. (1 skipped: 1 unsupported.) Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: lazy Apple Silicon cluster-frequency retrieval without side effects.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.15%. Comparing base (bd71af2) to head (6d631ad).

Files with missing lines Patch % Lines
...dware/common/platform/mac/MacCentralProcessor.java 85.71% 2 Missing ⚠️
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     
Flag Coverage Δ
linux 38.84% <71.42%> (+0.07%) ⬆️
macos 39.74% <85.71%> (-0.03%) ⬇️
windows 46.00% <71.42%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbwiddis
dbwiddis merged commit 3336d32 into oshi:master Aug 20, 2026
18 checks passed
@dbwiddis
dbwiddis deleted the mac-cluster-freq-init-order branch August 20, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant