Repository navigation
Migrate LinuxCentralProcessor udev calls - #3120
Conversation
- De-finalize LinuxCentralProcessor; extract three udev-dependent methods (readTopologyWithUdev, queryCurrentFreqFromUdev, queryMaxFreqFromUdev) as protected hooks with sysfs fallbacks in the base class - Add LinuxCentralProcessorJNA (oshi-core) overriding the hooks with JNA Udev calls; LinuxHardwareAbstractionLayer now instantiates it - Add LinuxCentralProcessorFFM (oshi-core-java25) overriding the hooks with FFM UdevFunctions calls; LinuxHardwareAbstractionLayerFFM now instantiates it - Fix pre-existing OOB: move max-freq tracking inside cpu-index bounds check in queryCurrentFreqFromUdev(UdevContext, long[]) - Add null guard on udev_new() return in all three JNA overrides - Promote queryMaxFreqFromCpuFreqPath to protected static; remove duplicate queryMaxFreqFromCpuFreqPathFFM from FFM subclass
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial 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). (5)
🧰 Additional context used🧠 Learnings (8)📓 Common learnings📚 Learning: 2026-04-05T05:40:43.357ZApplied to files:
📚 Learning: 2026-04-05T05:39:18.791ZApplied to files:
📚 Learning: 2026-04-05T16:15:03.230ZApplied to files:
📚 Learning: 2026-03-29T20:01:06.452ZApplied to files:
📚 Learning: 2026-04-05T05:40:43.357ZApplied to files:
📚 Learning: 2026-04-05T05:39:18.791ZApplied to files:
📚 Learning: 2026-04-03T02:07:47.621ZApplied to files:
🔇 Additional comments (16)
📝 WalkthroughWalkthroughIntroduces backend-specific LinuxCentralProcessor subclasses (JNA and FFM) and refactors the base class to expose protected hooks for udev-based topology and frequency queries, with automatic fallbacks to sysfs-based implementations. Changes
Sequence DiagramsequenceDiagram
participant Client
participant HAL as LinuxHardwareAbstractionLayer
participant Proc as LinuxCentralProcessor (abstract)
participant Backend as ProcessorBackend (JNA/FFM)
participant Udev as udev (JNA or FFM)
participant Sysfs
Client->>HAL: createProcessor()
HAL->>Backend: new LinuxCentralProcessorJNA/FFM()
Client->>Backend: queryCurrentFreq()/queryMaxFreq()
Backend->>Backend: query*FromUdev(...)
Backend->>Udev: allocate/context & enumerate cpu devices
alt udev succeeds
Backend->>Backend: parse topology/freq from devices
Backend-->>Client: return values (scaled where applicable)
Backend->>Udev: unref/release
else udev fails
Backend->>Sysfs: call sysfs-based query helpers
Backend-->>Client: return sysfs-derived values
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3120 +/- ##
==========================================
+ Coverage 66.51% 68.04% +1.53%
==========================================
Files 37 37
Lines 2025 2025
Branches 336 336
==========================================
+ Hits 1347 1378 +31
+ Misses 563 529 -34
- Partials 115 118 +3 ☔ View full report in Codecov by Sentry. 🚀 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 the current code and only fix it if needed.
Inline comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java`:
- Around line 171-174: The call site currently checks the JNA flag
LinuxOperatingSystem.HAS_UDEV and chooses between readTopologyWithUdev() and
readTopologyFromSysfs(), which prevents the FFM backend
(LinuxCentralProcessorFFM.readTopologyWithUdev()) from deciding when to use
udev; remove the conditional and call readTopologyWithUdev() unconditionally so
the backend can internally fall back to sysfs as needed (leave
readTopologyFromSysfs() available for the backend to call). Use the existing
readTopologyWithUdev() symbol at this call site and eliminate the HAS_UDEV
branch so the backend implementation controls the udev/sysfs choice.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 768b79dd-1d6c-4dd0-89bb-c8b67a435e06
📒 Files selected for processing (5)
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.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). (4)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:43.357Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:18.791Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:43.357Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
📚 Learning: 2026-04-05T05:39:18.791Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:18.791Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java
🔇 Additional comments (7)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessor.java (2)
57-57: The extracted hook/helper surface is well placed.De-finalizing the base type and promoting the shared topology/max-frequency helpers keeps the proc/sysfs parsing centralized while leaving only the backend-specific native work to the JNA and FFM subclasses.
Also applies to: 203-301, 535-590
443-533: The current-frequency split looks good, including the bounds fix.Routing
queryCurrentFreq()through the protected hook keeps the fallback chain intact, and themaxupdate now stays inside the CPU-index guard.oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorJNA.java (1)
25-70: JNA context ownership looks correct.Each override guards
udev_new(), delegates to the shared helper, and unreferences theUdevContextinfinally, which matches the injected-context lifecycle inLinuxCentralProcessor.oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java (1)
38-40: Factory wiring looks right.This switches the default Linux HAL to the JNA-backed processor without changing the public
CentralProcessorcontract.oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxCentralProcessorFFM.java (2)
36-85: The FFM topology path mirrors the JNA lifecycle well.The confined arena, explicit
udev_*_unref()calls, and sysfs fallback keep the native lifetime bounded and aligned with the base hook contract.
87-172: The FFM frequency overrides preserve the shared fallback chain.Both methods keep the udev-specific work localized while reusing the base sysfs helpers for the final fallback and cpufreq parsing.
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java (1)
24-27: This override completes the processor backend swap.
LinuxHardwareAbstractionLayerFFMwill now instantiateLinuxCentralProcessorFFMinstead of inheriting the JNA default fromLinuxHardwareAbstractionLayer.
- Fix pre-existing OOB: move max-freq tracking inside cpu-index bounds check in queryCurrentFreqFromUdev - Add null guard on udev_new() return in all three JNA overrides - Make LinuxCentralProcessor abstract; make the three udev hook methods abstract (subclasses own the udev/sysfs decision) - Remove HAS_UDEV branch from initProcessorCounts(); call readTopologyWithUdev() unconditionally so the backend controls the udev/sysfs choice - Move all JNA udev helpers and imports out of LinuxCentralProcessor into LinuxCentralProcessorJNA; base class now has no JNA udev dependencies (only LinuxLibc remains, to be addressed later) - Promote queryMaxFreqFromCpuFreqPath to protected static; remove duplicate queryMaxFreqFromCpuFreqPathFFM from LinuxCentralProcessorFFM - Fix copyright year to 2026 on new files - Add CHANGELOG entry for #3120
Summary
Continues the FFM migration of udev-dependent HAL components (following
#3117 which covered PowerSource, UsbDevice, HWDiskStore, NetworkIF, and
LogicalVolumeGroup). This PR migrates
LinuxCentralProcessor.Changes
oshi-coreLinuxCentralProcessor(de-finalized): The three udev-dependentmethods are refactored into protected hooks with sysfs fallbacks:
readTopologyWithUdev()— delegates toreadTopologyFromSysfs()queryCurrentFreqFromUdev(long[])— delegates toqueryCurrentFreqFromSysfs(long[])queryMaxFreqFromUdev()— delegates toqueryMaxFreqFromSysfs()The corresponding JNA static helpers (
readTopologyFromUdev,queryCurrentFreqFromUdev(UdevContext, long[]),queryMaxFreqFromUdev(UdevContext)) and sysfs fallbacks are retainedas
protected staticmethods for use by subclasses.queryMaxFreqFromCpuFreqPathis promoted fromprivatetoprotected staticto avoid duplication.LinuxCentralProcessorJNA(new):finalsubclass overriding thethree hooks with
Udev.INSTANCEJNA calls, guarded byHAS_UDEV.LinuxHardwareAbstractionLayer:createProcessor()now returnsnew LinuxCentralProcessorJNA().oshi-core-java25LinuxCentralProcessorFFM(new):public finalsubclassoverriding the three hooks with
UdevFunctionsFFM calls insideArena.ofConfined()try-with-resources, guarded byHAS_UDEVfromLinuxOperatingSystemFFM. Falls back to sysfs on anyThrowable.LinuxHardwareAbstractionLayerFFM:createProcessor()nowreturns
new LinuxCentralProcessorFFM().Bug Fixes
Pre-existing OOB in
queryCurrentFreqFromUdev(UdevContext, long[]):The
maxtracking update was outside thecpu-index bounds check,causing a potential
ArrayIndexOutOfBoundsExceptionif udev reporteda CPU index beyond the logical processor count. Moved inside the guard.
Null guard on
udev_new()inLinuxCentralProcessorJNA: Allthree overrides now check for a
nullreturn fromUdev.INSTANCE.udev_new()before entering thetry/finallyblock,preventing a
NullPointerExceptionif context allocation fails.Summary by CodeRabbit