Repository navigation
Description
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.ADLODNPerformanceStatusmapsiGPUActivityPercent(Adl.java#L89) and nothing reads it.AdlUtilJNA.performanceClockMhzalready pulls that exact struct throughADL2_OverdriveN_PerformanceStatus_Getfor both clocks, so the JNA side isperformanceClockMhzminus the/100unit 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, afteriCoreClock,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"
doneWorth 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-1unconditionally, but amdgpu exposesmem_info_gtt_usedin the same directory from which the class already readsmem_info_vram_used— the direct analogue of the WindowsSHARED_USAGEcounter. - Linux VRAM total falls back from NVML to lspci/lshw BAR-size parsing; amdgpu's
mem_info_vram_totalis exact and sits in that same directory. MacGpuStats.queryGpuTemperatureFromSmcis Apple-Silicon-only by design, so Intel Macs skip the SMC entirely and rely on IOAcceleratorTemperature(C). The javadoc states this, so it reads as deliberate — noting it only as a question.- Mac clocks, fan speed and shared memory return
-1unconditionally, all documented in the class javadoc, and no unwired source sits behind them. Mac fans are not per-GPU, so-1is 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
Read amdgpu shared and total memory from sysfs on Linux (#3687)