Skip to content

Read CPU topology and identifier on DragonFly BSD - #3789

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dragonfly-cpu-topology
Oct 12, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:dragonfly-cpu-topology

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Fixes CentralProcessor on DragonFly BSD, which reported one logical processor and no family, model, stepping, vendor or feature flags.

Topology

DragonFly has no kern.sched.topology_spec. When it is empty, FreeBsdCentralProcessor now reads hw.cpu_topology.cpuN.physical_id and core_id for each CPU. core_id exists only when a chip has more than one core, so a CPU without one is treated as a core of its own. physical_siblings is not used; on DragonFly 6.4 it reads cpus() for every CPU but the first.

Identifier

DragonFly's dmesg.boot writes Origin = "GenuineIntel" Id = 0x50655 Stepping = 5, with spaces around = and no Family or Model. The Origin line is now parsed as generic key=value fields, with family and model decoded from the CPUID signature when absent. The feature flags were missing because the code matched the exact text Origin=.

Pre-existing OpenBSD bug

The CPUID decoder moved from OpenBsdCentralProcessor to AbstractCentralProcessor so both share it. It combined the extended family incorrectly, decoding AMD Zen (0x00800F12) as family 143 instead of 23, so every AMD processor of family 16 or later showed an unknown microarchitecture on OpenBSD. Tests now assert 23, with Zen 3 and K8 vectors added.

Verification

  • DragonFly BSD 6.4 (cfarm152), JNA and FFM: 8 packages / 8 cores / 8 logical processors, Intel64 Family 6 Model 85 Stepping 5, Cascade Lake, feature flags present, per-processor load reports 8 values.
  • That VM publishes no core_id, so the multi-core and SMT grouping is covered only by unit tests.
  • The OpenBSD fix is tested by unit tests only; the OpenBSD cfarm box is Intel.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected DragonFly BSD processor detection to report logical processors and processor identity details.
    • Improved processor family detection for AMD processors on OpenBSD, helping identify their microarchitecture.

DragonFly BSD has no kern.sched.topology_spec, so FreeBsdCentralProcessor
fell back to a single logical processor. Read each CPU's package and core
from hw.cpu_topology.cpuN.physical_id and core_id instead; core_id is only
published when a chip has more than one core, so a missing one means a core
of its own. physical_siblings is not used: on DragonFly 6.4 it reads cpus()
for every CPU but the first.

DragonFly's dmesg.boot writes the Origin line as
  Origin = "GenuineIntel"  Id = 0x50655  Stepping = 5
with spaces around "=" and no Family or Model fields, which left vendor,
family, model, stepping and the feature flags (found by matching the exact
text "Origin=") empty. Parse the line's key=value fields generically and
decode family and model from the CPUID signature when they are absent.

Pre-existing bug: the CPUID decoder moved from OpenBsdCentralProcessor to
AbstractCentralProcessor so both can share it. It OR'd the extended family
into the base family instead of adding it, and only when the base was 0xF,
so AMD Zen (0x00800F12) decoded as family 143 rather than 23. The
microarchitecture table is keyed by the display family, so every AMD
processor of family 16 or later was unknown on OpenBSD. The test that
asserted 143 now asserts 23, with Zen 3 and K8 vectors added.

Verified on DragonFly BSD 6.4 (cfarm152), JNA and FFM: 8 packages, 8 cores,
8 logical processors, Intel64 Family 6 Model 85 Stepping 5, Cascade Lake,
feature flags present.
@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8299c4c-1cfe-4d8c-a33a-efef2b67acd3

📥 Commits

Reviewing files that changed from the base of the PR and between 2e4454d and d3c2791.


📒 Files selected for processing (7)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java
  • oshi-common/src/test/java/oshi/hardware/common/AbstractCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessorTest.java

💤 Files with no reviewable changes (2)
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessorTest.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📜 Recent review details
⏰ Context from checks skipped due to timeout. (13)
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Error Prone
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Analyze (java)

🧰 Additional context used
📚 Code guidelines (2)
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered

📓 Path-based instructions (2)
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/test/java/oshi/hardware/common/AbstractCentralProcessorTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessorTest.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java

Source excerpt: The Changelog lets users know what's changed.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md

🔇 Additional comments (7)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java (3)

361-372: Guard against a failed hw.ncpu sysctl on the empty-spec path.

When kern.sched.topology_spec is empty and hw.ncpu fails, ncpu is 0. buildTopologyFromIds then returns an empty list. The caller initProcessorCounts adds one processor, so this is safe. The same path also runs on FreeBSD systems where topology_spec is empty and hw.ncpu is valid. On those systems, the code now reads hw.cpu_topology.*, which does not exist, and it reports a distinct package for every CPU, using the default physical_id of 0 (so all CPUs share package 0). With core_id -1, each CPU becomes its own core in package 0. This result matches the old single-processor fallback or better, so no change is required.


243-255: LGTM!


445-467: LGTM!


oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java (1)

323-341: LGTM!


oshi-common/src/test/java/oshi/hardware/common/AbstractCentralProcessorTest.java (1)

373-416: LGTM!


oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessorTest.java (1)

62-114: LGTM!


CHANGELOG.md (1)

6-6: LGTM!



📝 Walkthrough

Walkthrough

The change adds shared x86 family, model, and stepping decoding. FreeBSD processor parsing now handles DragonFly BSD Origin fields and uses CPU IDs as a fallback for topology when the topology specification is empty.

Changes

Processor detection

Layer / File(s) Summary
CPUID decoding and Origin parsing
oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java, oshi-common/src/test/java/oshi/hardware/common/AbstractCentralProcessorTest.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessorTest.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessorTest.java, CHANGELOG.md
AbstractCentralProcessor now decodes x86 family, model, and stepping values. FreeBSD parsing accepts whitespace around Origin fields and derives missing or invalid family, model, and stepping values from the processor ID. Tests cover the decoding and DragonFly BSD Origin parsing.
DragonFly BSD topology fallback
oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessor.java, oshi-common/src/test/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdCentralProcessorTest.java
When the topology specification is empty, topology is built from CPU count and physical/core IDs. Tests cover missing core IDs, SMT across packages, and empty input.

Priority: ⬇️ Low

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

Change: Bug fix


Merge Risk: ⚪ Minimal · up to d3c27

No actionable issue is established; the change is mergeable after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. (1 skipped: … 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 primary change: detecting CPU topology and processor identifiers on DragonFly BSD.
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.

Full details: Docstring Coverage

Explanation

Docstring coverage is 27.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 4 files. (1 skipped: 1 unsupported.)


  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the processor line,
With family and model read just fine.
When topology specs are out of sight,
Core IDs help arrange them right.
The changelog marks the fix in ink.

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

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.94737% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.58%. Comparing base (2e4454d) to head (d3c2791).

Files with missing lines Patch % Lines
...platform/unix/freebsd/FreeBsdCentralProcessor.java 75.00% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3789      +/-   ##
============================================
- Coverage     80.62%   80.58%   -0.04%     
- Complexity      310      536     +226     
============================================
  Files           724      724              
  Lines         26005    26027      +22     
  Branches       4395     4401       +6     
============================================
+ Hits          20966    20974       +8     
- Misses         2795     2808      +13     
- Partials       2244     2245       +1     
Flag Coverage Δ
freebsd 36.57% <78.94%> (+0.02%) ⬆️
linux 40.30% <73.68%> (+0.03%) ⬆️
macos 41.13% <73.68%> (-0.02%) ⬇️
netbsd 35.25% <73.68%> (+0.01%) ⬆️
openbsd 35.83% <73.68%> (+0.02%) ⬆️
solaris 37.13% <73.68%> (+0.02%) ⬆️
windows 47.37% <73.68%> (+<0.01%) ⬆️

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 7a220ba into oshi:master Oct 12, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the dragonfly-cpu-topology branch October 12, 2026 01:29
dbwiddis added a commit that referenced this pull request Oct 12, 2026
createProcessorID builds the x86 processor signature (CPUID leaf 1 EAX) from
the displayed family, model and stepping when no platform source supplies
one. A family above 15 is defined as a base family of 15 plus an extended
family, but the encoder split the family's own bits between the two fields:
family 23 (AMD Zen) became base 7 / extended 1, giving 00100712 instead of
00800F12. Every AMD processor from family 16 (K10) on was affected; Intel's
families 6 and 15 were already correct.

This is the inverse of the decoding bug fixed in #3789.

The encoded value is used on Linux when neither dmidecode nor cpuid is
available, on Solaris, and on Windows when WMI returns no ProcessorId.

Tests encode Zen and Zen 4 against known signatures, and round-trip six
real Intel and AMD signatures through cpuidToFamilyModelStepping and back.
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