Repository navigation
Derive Apple Silicon chip details at runtime - #3541
Conversation
macOS chip identification came from hardcoded tables that stopped at the M4, so an M5 or an A-series part was misreported. Everything needed to avoid those tables is already read from the IORegistry and then discarded. Core classification came from ARM_P_CORES, a set of four core codenames covering M1 through M4. An unlisted codename left the efficiency class 0 for every core, which is both a wrong PhysicalProcessor#getEfficiency and a degraded queryCurrentFreq, since that branches on getEfficiency. The cpuN nodes already walked for the compatible property also carry cluster-type, a single letter naming the cluster as performance or efficiency, which answers this directly and for any chip. That property is now read in the same pass, so neither the JNA nor the FFM backend changes. Where cluster-type is unavailable the codenames still group the cores, ordered by core number since macOS numbers efficiency cores first, and cross-checked against hw.perflevel0.physicalcpu where that count is unambiguous. That reproduces what the deleted table produced, so a machine without cluster-type is no worse off than before. Note that hw.nperflevels is deliberately not used to detect heterogeneity: it did not exist before macOS 12, so requiring it would misclassify an M1 running macOS 11. The microarchitecture is likewise assembled from the codenames, so an unlisted chip is described rather than reported as unknown. The architecture table is consulted first and still wins, because an entry may carry a curated name a derivation cannot reproduce, as the M3 Pro and M4 entries do. Passing the derived value needs a new ProcessorIdentifier constructor; japicmp reports the addition as a patch level change, so no version bump is required. Also removes the brand string fallback that reported any unrecognized chip as an M1, and the family constants that only it used. A missing hw.cpufamily now leaves the family zero, which misses the table and falls through to the derived description. Verified on an M2 Max: the microarchitecture, the per-core efficiency classes, and the split between efficiency and performance core frequencies are all unchanged.
|
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)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (6)
🔇 Additional comments (3)
📝 WalkthroughWalkthroughApple Silicon processor detection now derives core efficiency classes and microarchitecture descriptions from macOS IORegistry data. Processor identifiers retain architecture-property overrides and use derived values as fallback, with expanded tests and changelog documentation. ChangesApple Silicon identification
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant MacCentralProcessor
participant IORegistry
participant PhysicalProcessor
participant ProcessorIdentifier
MacCentralProcessor->>IORegistry: Read compatible and cluster-type properties
IORegistry-->>MacCentralProcessor: Return per-core values
MacCentralProcessor->>MacCentralProcessor: Derive efficiency classes
MacCentralProcessor->>PhysicalProcessor: Populate core efficiency and codename
MacCentralProcessor->>MacCentralProcessor: Derive microarchitecture
MacCentralProcessor->>ProcessorIdentifier: Pass derived microarchitecture
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 #3541 +/- ##
============================================
- Coverage 78.98% 78.96% -0.02%
- Complexity 76 3656 +3580
============================================
Files 699 699
Lines 24083 24160 +77
Branches 3986 4015 +29
============================================
+ Hits 19021 19079 +58
- Misses 2879 2889 +10
- Partials 2183 2192 +9
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:
|
There was a problem hiding this comment.
🧹 Nitpick comments (3)
CHANGELOG.md (1)
9-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueEntry is inserted out of PR-number order (3541 before 3536). Content accurately matches the implementation; ordering only.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@CHANGELOG.md` at line 9, Move the CHANGELOG entry for PR `#3541` below the existing PR `#3536` entry so the changelog remains ordered by PR number, while preserving the entry’s content unchanged.oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java (2)
271-278: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSimplify the perf-level tie-break condition.
firstMatches != (ordered.get(1).size() == topPerfLevelCores) && firstMatchesreduces tofirstMatches && ordered.get(1).size() != topPerfLevelCores, which reads directly as "only the first group matches". Behavior is correct as written; this is readability only.♻️ Proposed simplification
- if (ordered.size() == 2 && topPerfLevelCores > 0) { - boolean firstMatches = ordered.get(0).size() == topPerfLevelCores; - // Only decisive when exactly one group matches; an even split such as the base M1's 4+4 leaves the - // ordering to decide instead. - if (firstMatches != (ordered.get(1).size() == topPerfLevelCores) && firstMatches) { - Collections.reverse(ordered); - } - } + if (ordered.size() == 2 && topPerfLevelCores > 0 + // Only decisive when exactly the first group matches the highest perf level's core count; an even + // split such as the base M1's 4+4 leaves the ordering to decide instead. + && ordered.get(0).size() == topPerfLevelCores && ordered.get(1).size() != topPerfLevelCores) { + Collections.reverse(ordered); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java` around lines 271 - 278, In the perf-level ordering logic, simplify the nested condition in MacCentralProcessor so it directly checks that firstMatches is true and the second group size differs from topPerfLevelCores. Preserve the existing reverse behavior and tie-handling for evenly split groups.
334-360: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low value
getIdString()is dereferenced without a null check.
PhysicalProcessor's public 4-arg constructor accepts anyidString, so a null value would NPE here. Internal call sites always pass a non-null string, so this is defensive only.🛡️ Optional guard
for (PhysicalProcessor processor : physicalProcessors) { - Matcher m = APPLE_CORE.matcher(processor.getIdString().toLowerCase(Locale.ROOT)); + String idString = processor.getIdString(); + if (idString == null) { + continue; + } + Matcher m = APPLE_CORE.matcher(idString.toLowerCase(Locale.ROOT));🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java` around lines 334 - 360, Update deriveMicroarchitecture to guard processor.getIdString() before calling toLowerCase(Locale.ROOT) or matching it, skipping processors whose ID string is null while preserving the existing codename collection and sorting behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@CHANGELOG.md`:
- Line 9: Move the CHANGELOG entry for PR `#3541` below the existing PR `#3536`
entry so the changelog remains ordered by PR number, while preserving the
entry’s content unchanged.
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java`:
- Around line 271-278: In the perf-level ordering logic, simplify the nested
condition in MacCentralProcessor so it directly checks that firstMatches is true
and the second group size differs from topPerfLevelCores. Preserve the existing
reverse behavior and tie-handling for evenly split groups.
- Around line 334-360: Update deriveMicroarchitecture to guard
processor.getIdString() before calling toLowerCase(Locale.ROOT) or matching it,
skipping processors whose ID string is null while preserving the existing
codename collection and sorting behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b6b6f937-7ea1-4b70-b0dd-e5efab2661c5
📒 Files selected for processing (6)
CHANGELOG.mdoshi-common/src/main/java/oshi/hardware/CentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.javaoshi-common/src/main/resources/oshi.architecture.propertiesoshi-common/src/test/java/oshi/hardware/CentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (7)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 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/CentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-common/src/main/java/oshi/hardware/CentralProcessor.javaoshi-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
🔇 Additional comments (7)
oshi-common/src/main/java/oshi/hardware/CentralProcessor.java (1)
835-835: LGTM!Also applies to: 869-889, 1069-1075
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java (3)
12-15: LGTM!Also applies to: 37-37, 64-68, 172-197
226-269: LGTM!Also applies to: 279-291, 299-324
431-431: LGTM!Also applies to: 440-444, 471-471, 487-497
oshi-common/src/main/resources/oshi.architecture.properties (1)
337-340: LGTM!oshi-common/src/test/java/oshi/hardware/CentralProcessorTest.java (1)
21-21: LGTM!Also applies to: 121-146
oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java (1)
11-28: LGTM!Also applies to: 160-285, 286-352, 427-427, 436-438
deriveEfficiencyClasses discarded the cluster-type values it had already read whenever they did not cover every core. Strategy 3 began by clearing the map, and it also aborts when any core lacks a codename, so a machine where some cpuN nodes expose no readable properties fell all the way through to the class 0 default. Cores that had reported cluster-type P were then classified as efficiency cores, which is worse than the codename table this replaced and re-introduces the degraded queryCurrentFreq this change set out to fix. A cluster-type reading is exact, so those values are now kept and only the remaining cores fall to the default; the codename grouping applies only when cluster-type classified nothing at all. The propagation step also revisited every core rather than only the unclassified ones, so a core that reported its own cluster-type could be overwritten by a value inferred from another core sharing its codename, contradicting the documented intent of applying the mapping to the other cores. It now skips cores that are already classified. Also simplifies the perf-level tie-break condition to a plain conjunction and restores the CHANGELOG entry to PR number order, both per review feedback.
|
@coderabbitai thanks — addressed in 486633d. CHANGELOG ordering — fixed, Simplify the perf-level tie-break — fixed, adopted essentially as proposed.
Reviewing this on a second machine also turned up two real bugs in
Two regression tests added for these. Verified on an M3 Pro (6+6), which is a different chip from the M2 Max in the PR description and exercises the even-split path where |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- commit summary ---'
git show --stat --oneline 486633d
echo
echo '--- relevant follow-up diff ---'
git show --format=fuller --find-renames 486633d -- \
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
echo
echo '--- MacCentralProcessor outline ---'
ast-grep outline oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java \
--items all --type method --match 'deriveEfficiencyClasses|deriveMicroarchitecture|initProcessorCounts'
echo
echo '--- implementation and construction-site context ---'
rg -n -A100 -B15 \
'deriveEfficiencyClasses\s*\(|deriveMicroarchitecture\s*\(|new PhysicalProcessor\s*\(' \
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
echo
echo '--- regression-test context ---'
rg -n -A55 -B8 \
'partial|propagat|cluster.type|deriveEfficiencyClasses' \
oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.javaLength of output: 44176
Your Nice catch on the partial-readings regression—preserving exact IORegistry data is the right precedence. 🐇 ✏️ Learnings added
|
Closes #3537.
macOS chip identification came from hardcoded tables that stop at the M4, so an M5 or any A-series part is misreported. Everything needed to avoid those tables is already read from the IORegistry and then discarded.
Core classification
ARM_P_CORESwas a set of four core codenames — firestorm/avalanche/everest/donan, i.e. M1–M4. An unlisted codename leftefficiency0 for every core, which is both a wrongPhysicalProcessor#getEfficiency()and a degradedqueryCurrentFreq(), since that branches ongetEfficiency() > 0.The
cpuNnodes already walked forcompatiblealso carrycluster-type, a single letter naming the cluster:That answers the question directly, for any chip, with no table. It's read in the same pass as
compatible, andRegistryEntry.getByteArrayPropertyis already generic — so neither the JNA nor the FFM backend changes.Where
cluster-typeis unavailable the codenames still group the cores, ordered by core number (macOS numbers efficiency cores first) and cross-checked againsthw.perflevel0.physicalcpuwhere that count is unambiguous. That reproduces exactly what the deleted table produced, so a machine withoutcluster-typeis no worse off than today.hw.nperflevelsis deliberately not used to detect heterogeneity — it did not exist before macOS 12, so requiring it would misclassify an M1 running macOS 11. It keeps its existing job of sizing the cache loop.Microarchitecture
Assembled from the same codenames, so an unlisted chip is described rather than reported
unknown. The architecture table is consulted first and still wins, because an entry may carry a curated name a derivation cannot reproduce —M3 Pro (Lobos)andM4 (Donan)are exactly that case. Every chip currently in the table is byte-for-byte unchanged.This needs a new
ProcessorIdentifierconstructor. japicmp reports it as+++ NEW CONSTRUCTORwithSemantic versioning suggestion: 0.0.1, so no version bump is required — verified by runningverify, not assumed.Also
Removes the brand-string fallback that reported any unrecognised chip as an M1 (
"Apple M5"→ 5 →default→ M1), and the family constants only it used. A missinghw.cpufamilynow leaves the family zero, which misses the table and falls through to the derived description.protected static finalconstants (M1/M2/M3/M3_PRO/M4_CPUFAMILY) from a public but non-@PublicApiclass. Nothing in the project referenced them; a downstream subclass theoretically could.Verification
Live on an M2 Max — identical to before:
Those
effvalues now come fromcluster-type, sinceARM_P_CORESis gone — so the live run exercises the new path end to end.15 hardware-free fixture tests covering M2 Max 8+4, M1's ambiguous 4+4 even split,
cluster-typeabsent, partialcluster-typepropagated by codename,cluster-typewith no codename, perf-level count overriding core ordering, unrecognised cluster letters, homogeneous cores, no properties at all, and a fabricated future chip (apple,hydra/apple,coyote) that classifies correctly and derivesARM64 SoC: Hydra + Coyote— the case that fails without this change.The strongest check reads the shipped
oshi.architecture.propertiesand asserts the derived string equals the entry already published for M1, M2 and M3. It asserts those entries are non-null first, so it cannot pass vacuously if the table fails to load.Full gate clean on
oshi-common,oshi-core,oshi-core-ffm, clean full-reactorinstall, 0 tests failed.NativeComparisonTestpasses includingprocessorIdentifier()andprocessorTopology(), so JNA/FFM parity holds.Summary by CodeRabbit