Skip to content

Split LinuxGraphicsCard, LinuxGpuStats, and NvmlUtil across modules - #3139

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:linux-gpu
Apr 11, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:linux-gpu

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 11, 2026 •

Copy link
Copy Markdown
Member

Move native-free logic for LinuxGraphicsCard and LinuxGpuStats to oshi-common as abstract classes, with JNA subclasses in oshi-core and FFM subclasses in oshi-core-java25.

NvmlUtil split

  • Rename NvmlUtil → NvmlUtilJNA in oshi-core
  • Create NvmlUtilFFM in oshi-core-java25 with identical public API
  • Create NvmlFunctions FFM bindings for the NVML library (lazy-loaded, struct layouts, method handles)

LinuxGpuStats split

  • Move sysfs/hwmon/DRM logic to abstract LinuxGpuStats in oshi-common
  • Define abstract nvml*() methods for NVML operations
  • LinuxGpuStatsJNA delegates to NvmlUtilJNA
  • LinuxGpuStatsFFM delegates to NvmlUtilFFM

LinuxGraphicsCard split

  • Move to oshi-common as public abstract class
  • Add Attrs inner class (JDK 8 compatible) to bundle graphics card attributes
  • Parameterize getGraphicsCards() with Function<Attrs, GraphicsCard> factory so JNA/FFM subclasses provide their concrete type
  • LinuxGraphicsCardJNA and LinuxGraphicsCardFFM override createStatsSession() to return their respective LinuxGpuStats subclass

Other updates

  • LinuxHardwareAbstractionLayerJNA → uses LinuxGraphicsCardJNA
  • LinuxHardwareAbstractionLayerFFM → uses LinuxGraphicsCardFFM
  • WindowsGpuStats → uses NvmlUtilJNA

Summary by CodeRabbit

  • Refactor
    • Refactored Linux GPU monitoring components into abstract base classes supporting multiple native binding strategies.
    • Added Foreign Function & Memory (FFM) API support for NVML bindings as a modern alternative to JNA (Java 25+).
    • Separated and clarified JNA and FFM implementations for improved maintainability.

Move native-free logic for LinuxGraphicsCard and LinuxGpuStats to
oshi-common as abstract classes. Create JNA subclasses in oshi-core
and FFM subclasses in oshi-core-java25.

Rename NvmlUtil to NvmlUtilJNA in oshi-core and create NvmlUtilFFM
in oshi-core-java25 with new NvmlFunctions FFM bindings.

LinuxGraphicsCard uses a factory Function<Attrs, GraphicsCard> parameter
so JNA/FFM subclasses can provide their concrete type from static
getGraphicsCards() methods.

LinuxGpuStats defines abstract nvml*() methods that JNA/FFM subclasses
implement by delegating to NvmlUtilJNA/NvmlUtilFFM respectively.
@coderabbitai

coderabbitai Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR refactors Linux GPU component handling by extracting LinuxGpuStats and LinuxGraphicsCard into abstract base classes in the common module, then creates FFM and JNA concrete implementations. It introduces FFM bindings for NVIDIA NVML and renames the JNA NVML utility wrapper.

Changes

Cohort / File(s) Summary
Core Abstraction Layer
CHANGELOG.md, oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java, oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
Extracted GPU components into abstract base classes in common module; LinuxGpuStats becomes public abstract with protected NVML hooks, LinuxGraphicsCard becomes public abstract with factory pattern using new Attrs data holder for card attributes and device resolution.
FFM NVML Bindings & Implementation
oshi-core-java25/src/main/java/oshi/ffm/common/NvmlFunctions.java, oshi-core-java25/src/main/java/oshi/ffm/common/package-info.java, oshi-core-java25/src/main/java/oshi/util/gpu/NvmlUtilFFM.java, oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java, oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
Added Foreign Function & Memory (FFM) bindings for NVIDIA NVML with struct layouts and downcall handles; new NvmlUtilFFM provides public measurement methods with lazy device enumeration and caching; LinuxGpuStatsFFM and LinuxGraphicsCardFFM implement FFM-backed GPU metrics.
JNA NVML Implementation
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java, oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java
Renamed NvmlUtil to NvmlUtilJNA and created new JNA-based LinuxGpuStatsJNA and LinuxGraphicsCardJNA implementations that delegate NVML operations to the renamed utility.
HAL & Windows Updates
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
Updated HAL implementations to use FFM/JNA-based graphics card factories; WindowsGpuStats refactored to use NvmlUtilJNA instead of legacy NvmlUtil.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • mprins

Poem

🐰✨ A tale of abstraction and modern binds,
Where GPU dreams split into FFM and JNA kinds,
Abstract classes bloom in the common ground,
While factory patterns spin metrics around! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: splitting LinuxGraphicsCard, LinuxGpuStats, and NvmlUtil components across modules (oshi-common, oshi-core, oshi-core-java25).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified 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.

❤️ Share

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

@codecov

codecov Bot commented Apr 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.21%. Comparing base (2e396bf) to head (5e6afbb).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3139      +/-   ##
============================================
+ Coverage     61.39%   62.21%   +0.81%     
  Complexity       12       12              
============================================
  Files            39       39              
  Lines          2329     2329              
  Branches        407      407              
============================================
+ Hits           1430     1449      +19     
+ Misses          783      770      -13     
+ Partials        116      110       -6     

☔ View full report in Codecov by Sentry.
📢 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java`:
- Around line 36-58: The overrides nvmlGetVramUsed, nvmlGetCoreClockMhz, and
nvmlGetMemoryClockMhz currently pass through NvmlUtilFFM's -1L failure sentinel,
violating LinuxGpuStats' contract that unavailable values must be 0; update each
of those methods to call the corresponding NvmlUtilFFM.get... method
(nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz) and return 0 if
the result is negative (e.g., return Math.max(0L, result) or equivalent) so
impossible negative values are clamped to 0.
🪄 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: ed9e3aae-2766-4c22-9a23-3f4e1f776af5

📥 Commits

Reviewing files that changed from the base of the PR and between 2e396bf and 5e6afbb.

📒 Files selected for processing (14)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
  • oshi-core-java25/src/main/java/oshi/ffm/common/NvmlFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/common/package-info.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.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). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (9)
📚 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/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/common/package-info.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java
  • oshi-core-java25/src/main/java/oshi/ffm/common/NvmlFunctions.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/common/package-info.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java
📚 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.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
  • oshi-core-java25/src/main/java/oshi/util/gpu/NvmlUtilFFM.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.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.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.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java
📚 Learning: 2026-04-05T05:40:45.797Z
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:45.797Z
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/util/gpu/NvmlUtilJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java
  • oshi-core-java25/src/main/java/oshi/util/gpu/NvmlUtilFFM.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/gpu/NvmlUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/common/NvmlFunctions.java
🔇 Additional comments (18)
CHANGELOG.md (1)

15-15: LGTM!

The changelog entry accurately describes the PR scope and follows the existing format conventions.

oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java (2)

42-44: LGTM!

The rename from NvmlUtil to NvmlUtilJNA is correct and consistent with the project's naming pattern for JNA-specific implementations. The logger is properly updated to reference the new class name.


75-76: LGTM!

Private constructor renamed correctly to match the new class name.

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStats.java (3)

26-26: LGTM!

Import correctly updated to use NvmlUtilJNA for Windows platform which uses JNA bindings.


198-198: LGTM!

All NVML metric method calls correctly updated to use NvmlUtilJNA. The method signatures match the utility class API.

Also applies to: 218-218, 242-242, 263-263, 284-284


334-344: LGTM!

Device discovery methods (isAvailable, findDevice, findDeviceByName) correctly updated to use NvmlUtilJNA. The caching logic in findNvmlDevice() is preserved.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java (4)

5-5: LGTM!

The refactoring to an abstract base class in oshi-common is well-structured:

  • Package move to oshi.hardware.common.platform.linux correctly places native-free code in the common module
  • Class made public abstract with protected constructor appropriately enables subclassing by JNA/FFM implementations

Also applies to: 29-29, 41-56


76-149: LGTM!

The abstract NVML hook methods provide a clean contract for JNA/FFM subclasses:

  • Availability check: nvmlIsAvailable()
  • Device resolution: nvmlFindDevice(), nvmlFindDeviceByName()
  • Metric retrieval: 6 methods for VRAM, temperature, power, clocks, and fan speed

The Javadoc clearly documents each method's purpose and return value semantics.


155-180: LGTM!

The findNvmlDevice() caching implementation correctly uses:

  • null to indicate "not yet resolved"
  • Empty string to indicate "resolved but unavailable"

This pattern is consistent with WindowsGpuStats.cachedNvmlDevice and avoids repeated NVML lookups.


223-241: LGTM!

The metric methods correctly delegate to abstract nvml* hooks while preserving the existing sysfs/hwmon/DRM fallback logic for non-NVIDIA GPUs.

Also applies to: 249-266, 268-285, 287-315, 317-340, 342-364

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java (1)

1-65: LGTM!

Clean implementation of the JNA-based Linux GPU stats:

  • Properly extends LinuxGpuStats abstract base class
  • All 9 abstract NVML methods correctly delegate to NvmlUtilJNA
  • Thread-safe annotation present
  • Package-private visibility appropriate for platform implementation detail
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java (1)

62-64: LGTM!

The JNA hardware abstraction layer correctly delegates to LinuxGraphicsCardJNA.getGraphicsCards(), which internally uses the LinuxGpuStatsJNA implementation for NVML operations.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java (1)

57-59: LGTM!

The FFM hardware abstraction layer correctly delegates to LinuxGraphicsCardFFM.getGraphicsCards(), which internally uses the LinuxGpuStatsFFM implementation for NVML operations via FFM bindings.

oshi-core-java25/src/main/java/oshi/ffm/common/package-info.java (1)

1-8: LGTM!

Standard package-info.java with appropriate copyright header and documentation describing the package's purpose for FFM bindings.

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardJNA.java (1)

25-38: Clean JNA adapter split.

Keeping discovery in the common class and limiting this class to JNA-specific stats-session creation makes the module boundary much clearer.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGraphicsCardFFM.java (1)

25-38: Clean FFM adapter split.

This is a good counterpart to the JNA path: common discovery stays shared, while the FFM module only supplies the concrete stats implementation.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java (1)

87-157: Nice extraction of the common discovery path.

The immutable Attrs carrier plus factory injection keeps the parsing code native-free while still letting JNA and FFM supply their own concrete GraphicsCard/stats behavior.

oshi-core-java25/src/main/java/oshi/ffm/common/NvmlFunctions.java (1)

80-140: Bootstrap looks solid.

The binding init fails closed via AVAILABLE and doesn't expose half-initialized handles when NVML isn't present.

@dbwiddis
dbwiddis merged commit 9dc0c2d into oshi:master Apr 11, 2026
16 of 17 checks passed
@dbwiddis
dbwiddis deleted the linux-gpu branch April 11, 2026 05:57
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