Repository navigation
Extract OpenBSD/NetBSD CentralProcessor common bases (BSD dedup) - #3387
Conversation
The OpenBSD JNA and FFM CentralProcessors were identical except for the sysctl backend and the native CPU-tick/load-average calls, and the dmesg-based topology/cache parsing was duplicated again in NetBSD. Add a cross-BSD BsdCentralProcessor base (oshi.hardware.common.platform.unix) holding the shared dmesg processor/cache enumeration, vmstat-backed context switch/interrupt counters, and an abstract int sysctl(name, def) hook plus an abstract queryVmStats(). NetBsdCentralProcessor and a new OpenBsdCentralProcessor extend it; OpenBsdCentralProcessor adds the shared processor identification, frequency, and OpenBSD vmstat parsing with abstract sysctl hooks, leaving only the native tick readers and getloadavg in the JNA and FFM subclasses. This fixes a pre-existing NetBSD bug: its initProcessorCounts split the dmesg cache line on regex group(1) (the cpu number) instead of group(2) (the cache description), so dmesg-derived cache detection never produced any caches; the shared base uses the correct group(2).
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
📝 WalkthroughWalkthroughThis PR extracts shared BSD dmesg-based CPU topology, cache, and VM-stat logic into a new BsdCentralProcessor base, adds an OpenBsdCentralProcessor for OpenBSD sysctl-based queries, and refactors NetBSD/OpenBSD adapters to extend the new hierarchy and provide platform sysctl bridges. ChangesBSD Central Processor Hierarchy Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 #3387 +/- ##
============================================
- Coverage 68.93% 68.83% -0.11%
Complexity 76 76
============================================
Files 574 576 +2
Lines 21622 21541 -81
Branches 3580 3560 -20
============================================
- Hits 14906 14827 -79
+ Misses 4888 4884 -4
- Partials 1828 1830 +2
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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java`:
- Around line 104-109: The loop in OpenBsdCentralProcessor (where
contextSwitches and interrupts are set) currently uses
ParseUtil.getFirstIntValue(line) which can truncate large counters; update this
to use ParseUtil.parseLongOrDefault(line, 0L) (or the equivalent long-parsing
helper used in NetBsdCentralProcessor.queryVmStats) and ensure the
contextSwitches and interrupts variables are long-typed (or cast/assigned
safely) so large values are preserved; modify the assignments in the same loop
that checks line.endsWith("cpu context switches") and
line.endsWith("interrupts") to use the long parser for consistency with
NetBsdCentralProcessor.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 18f9a08c-1fff-43b2-b5db-f6498e8f0444
📒 Files selected for processing (5)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- 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/common/platform/unix/openbsd/OpenBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.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/unix/openbsd/OpenBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdCentralProcessor.java (1)
1-185: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdCentralProcessor.java (1)
1-55: LGTM!Also applies to: 56-79, 81-97
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java (1)
1-233: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.java (1)
1-117: LGTM!oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java (1)
1-158: LGTM!
OpenBsdCentralProcessor.queryVmStats parsed the vmstat context-switch and interrupt counters with ParseUtil.getFirstIntValue, which returns an int and truncates values above ~2.1 billion that long-uptime systems routinely exceed. Use ParseUtil.parseLongOrDefault on the leading token instead, matching NetBsdCentralProcessor. This was pre-existing in both the JNA and FFM OpenBSD implementations; consolidation fixes both at once.
Summary
BsdCentralProcessorbase (oshi.hardware.common.platform.unix) holding the shareddmesg-based processor/cache enumeration (initProcessorCounts,parseCacheStr) and thevmstat-backed context-switch/interrupt counters, with an abstractint sysctl(name, def)hook and an abstractqueryVmStats()OpenBsdCentralProcessorbase extending it with the shared processor identification, frequency, and OpenBSDvmstatparsing; abstract sysctl overloads let the JNA and FFM subclasses supply their backendOpenBsdCentralProcessorJNA/FFMnow contain only sysctl delegation plus the native CPU-tick readers andgetloadavg;NetBsdCentralProcessorextends the cross-BSD base and keeps its command/text-based identification, ticks, and load averageinitProcessorCountssplit thedmesgcache line on regexgroup(1)(the cpu number) instead ofgroup(2)(the cache description), sodmesg-derived cache detection never produced any caches; the shared base uses the correctgroup(2)Test plan
Summary by CodeRabbit