Skip to content

Windows GpuStats.getGpuUtilization() never consults NVML or ADL, unlike every other metric on the class #3682

Closed

Description

@dbwiddis

While reviewing #3681, which fixes exactly this bug on Linux, I audited the rest of the GPU code for the same shape of defect: a vendor utility method that exists and is correct, but that no HAL class ever calls. Windows has it too.

The defect

WindowsGpuStats.getGpuUtilization() (WindowsGpuStats.java#L262) consults no vendor API at all. Every other metric on that class runs NVML → ADL → LHM; utilization alone runs LHM → PDH engine-tick delta:

metric NVML ADL LHM PDH ticks
getTemperature 1st 2nd 3rd —
getPowerDraw 1st 2nd 3rd —
getCoreClockMhz 1st 2nd 3rd —
getMemoryClockMhz 1st 2nd 3rd —
getFanSpeedPercent 1st 2nd 3rd —
getGpuUtilization never never 1st 2nd

NvmlUtilJNA.getGpuUtilization and NvmlUtilFFM.getGpuUtilization both exist and both wrap nvmlDeviceGetUtilizationRates correctly. On the current default branch they have zero callers anywhere in main sources; once #3681 merges they have two, both on Linux.

Impact

LHM is a third-party application that must be installed and running with its WMI provider, so for most users the only live path is the PDH engine-tick delta. That means an NVIDIA or AMD card on a stock Windows install returns -1 on the first call to getGpuUtilization() and only yields a value from the second call onward — while the vendor API that all five sibling getters prefer would have answered instantly, with the number nvidia-smi and Radeon Software report.

This is less severe than the Linux bug (it is not -1 forever), but it is the same root cause, and it is the only getter on the class where a third-party WMI provider outranks the vendor API instead of the reverse.

The tick-delta path is worth keeping as the last fallback: it is vendor-neutral, covers Intel iGPUs, and sums all engines rather than just kernel execution. The fix is to insert NVML → ADL ahead of LHM so utilization matches its five siblings.

AMD: the value is one field of a struct the code already reads

There is no AdlUtil*.getGpuUtilization at all, which is why nothing in the ADL layer looked unused either. But the value is already being fetched and discarded:

  • Adl.ADLODNPerformanceStatus maps iGPUActivityPercent (Adl.java#L89) and nothing reads it.
  • AdlUtilJNA.performanceClockMhz already pulls that exact struct through ADL2_OverdriveN_PerformanceStatus_Get for both clocks, so the JNA side is performanceClockMhz minus the /100 unit conversion.
  • The FFM twin reads the same struct by offset and already allocates the full 72 bytes, so it needs one added constant: PERF_GPU_ACTIVITY_OFFSET = 24 (the 7th int, after iCoreClock, iMemoryClock, iDCEFClock, iGFXClock, iUVDClock, iVCEClock).

Small twin divergence worth closing at the same time: the JNA binding names iGPUActivityPercent, the FFM offset table does not mention it.

Why nothing flagged either omission

I checked all 29 abstract native-dispatch methods across LinuxGpuStats, WindowsGpuStats and MacGpuStats: every one has a call site. The defect lives one level up — a util method for which no dispatch method was ever declared — so nothing inside the HAL class looks unused, and because the utils are public in exported packages, no compiler or Sonar warning fires either (S1144 is private-only).

The detector that does work, and that found both of these:

# every public getter in the vendor utils should have at least one caller in main sources
for m in getGpuUtilization getVramTotal getVramUsed getTemperature getPowerDraw \
         getCoreClockMhz getMemoryClockMhz getFanSpeedPercent; do
  echo "$m -> $(grep -rl "Util\(JNA\|FFM\)\.$m(" --include='*.java' \
    oshi-core/src/main oshi-core-ffm/src/main oshi-common/src/main | wc -l) callers"
done

Worth re-running whenever NvmlUtil* or AdlUtil* gains a method.

WindowsGpuStats has no unit test

LinuxGpuStats has a ~600-line stub-based test and MacGpuStats has one; WindowsGpuStats has none, despite being the most source-complex of the three (18 dispatch points, four-deep priority chains). All 18 are trivially stubbable in exactly the shape LinuxGpuStatsTest uses. A test that pins the priority chain per metric would have made this omission visible as a conspicuously missing assertion.

Related coverage gap, applying to Linux as well: no test anywhere pins source priority, only source presence. Every NVML-path assertion in LinuxGpuStatsTest uses an empty drmDevicePath, so nothing fails if the NVML branch is dropped from a getter that also has a sysfs fallback.

Adjacent gaps found during the audit

Recorded here for the record; each is a feature rather than a wiring bug, so probably a separate issue if wanted:

  • Linux getSharedMemoryUsed() returns -1 unconditionally, but amdgpu exposes mem_info_gtt_used in the same directory from which the class already reads mem_info_vram_used — the direct analogue of the Windows SHARED_USAGE counter.
  • Linux VRAM total falls back from NVML to lspci/lshw BAR-size parsing; amdgpu's mem_info_vram_total is exact and sits in that same directory.
  • MacGpuStats.queryGpuTemperatureFromSmc is Apple-Silicon-only by design, so Intel Macs skip the SMC entirely and rely on IOAccelerator Temperature(C). The javadoc states this, so it reads as deliberate — noting it only as a question.
  • Mac clocks, fan speed and shared memory return -1 unconditionally, all documented in the class javadoc, and no unwired source sits behind them. Mac fans are not per-GPU, so -1 is the right answer rather than reporting a chassis fan.

Verification status

The findings above are structural and visible in source; they were reached by reading the code and running the caller-count greps, with nothing executed on Windows hardware. The claim that LHM is usually absent is a judgment about how it is deployed, not a measurement.

Activity

  1. added
    confirmed bug
    on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions