Repository navigation
amdgpu: use what gpu_metrics and the driver report - #570
Merged
Merged
Conversation
The encode and decode meter summed the usage of the processes nvtop can see, missing those of other users, containers and virtual machines. The driver reports the usage of the video engines of the whole device in vcn_busy_percent: for some APUs since Linux 6.10, and for RDNA 3, RDNA 4 and the other APUs since 6.15. Otherwise, as on MI300, the firmware reports it in gpu_metrics: from v1.1 to v1.3 for the whole video block, which RDNA 3 and 4 fill with their busier engine, and per engine in v1.5, v1.7, v1.8 and v1.9. Use it for the shared encode and decode meter, from VCN 4 on, with the busiest engine when there are several. Older VCNs keep their separate meters, as neither tells encoding from decoding.
Some devices report their PCIe throughput for both directions together, not apart. Add a field for it, shown as Throughput instead of the RX and TX values, and as pcie_throughput in the snapshot.
Since Linux 6.9, MI300 has no pcie_bw file, so nvtop showed no PCIe throughput for it. Its firmware reports the instantaneous PCIe bandwidth in gpu_metrics from v1.5 on, as a single value in whole GB/s, without saying whether it sums both directions. Show it as the throughput of both directions when pcie_bw is missing.
Without vcn_busy_percent, the video engine usage of the APUs from Renoir to Phoenix is in their own gpu_metrics formats, v2.1 to v2.4, as a single value for the whole video block. Phoenix is the only one of them with a shared encode and decode meter, which is all this value is used for: decode it from its v2.1 table, in hundredths of a percent as its firmware headers say and as its driver divides it for its own sensor. v2.2 to v2.4 are not needed, and Van Gogh reports them in percent with its newer firmware. The v3.0 table of the later APUs is not decoded for it: its unit depends on the driver and the kernel version, hundredths for Strix Point, Krackan and Strix Halo, and percent for the latest APUs on recent kernels.
gpu_metrics reports the clocks of the SoC, of the data fabric on the APUs, and of the video engines, which nvtop did not show. Report them as extra clocks: SOCCLK, FCLK, VCLK and DCLK, and VCLK1, DCLK1 and VPECLK as secondary domains. When a clock is reported per die or engine, as on MI300, show the highest one. RDNA 4 reports the clocks of its first video engine for the second one as well. Most APUs only report time averaged clocks, and Strix Point, Krackan and Strix Halo time filtered ones: use them there. The fabric clock of the APUs before Strix Point is the memory clock on all but Renoir, so it is left out.
The power sensor of an APU measures the whole socket, the CPU included. The v3.0 gpu_metrics of Strix Point, Krackan and Strix Halo reports the power of the graphics block alone: use it when reported. The graphics power of the older APU tables is the one of a rail the CPU cores share, so it is not used. A refresh whose table cannot be read keeps the socket power, as a value is better than none. There is no power cap of the graphics block alone: the socket one is only shown with the socket power.
An APU has no PCIe link of its own, so its RX and TX showed N/A. The v3.0 gpu_metrics of Strix Point, Krackan, Strix Halo and later APUs reports the DRAM read and write throughput, in MB/s: show them as RX and TX. It is the one of the whole SoC, the CPU included, which is still the memory traffic of the APU. The values are 16-bit, so a throughput beyond 65535 MB/s does not fit. The internal PCIe bridge of an APU does not bound that throughput: report no maximum PCIe link for APUs, so that their RX and TX are not plotted as a share of it.
The NPU utilization was the sum of the processes nvtop can see, from Linux 7.4 on, and the NPU had no power or clock. On Strix Point, Krackan and Strix Halo, the firmware reports the utilization of each NPU column, the NPU power and its clock in the v3.0 gpu_metrics table of the graphics block of the APU. Read them from there: a system has a single APU, and the dGPU tables have another format. When a table cannot be read, as while its GPU is runtime suspended, the table is looked for again at the next refreshes, up to 10 failed lookups: it may be the table of a dGPU, on a system whose APU has no table with its NPU.
The fan percentage was the PWM duty cycle when pwm1_enable was not 0, else the RPM over the maximum one when fan1_enable was not 0. These give the fan control mode, not whether the sensors are reported: fan1_enable is 0 in the default automatic mode, so the RPM was never used then. And the duty cycle is what the fan is driven with, not how fast it spins. Use the RPM over the maximum one when the driver reports it, capped at 100% as the maximum of the fan table is not always the top speed of the fan, and the duty cycle only for fans without one. Since Linux 6.13, the driver refuses to read them while the GPU is runtime suspended or reset: choose again at a later refresh rather than settle on the duty cycle. Also report the RPM, which the interface shows when the percentage is unknown.
The utilization of a device with several engines averages them, which hides a single busy one. Add the busiest engine to the utilization, shown in its meter as the encode and decode ones do, and in the snapshot, for the backends that measure each engine. It replaces the effective load in the value, as the more telling of the two.
The NPU utilization the firmware measures is the average over the NPU columns, which hides a single busy one: also report the busiest column.
…apshot The power was shown in whole watts, so the small ones said little: an NPU drawing 1.4 W showed 1 W. In the interface, show the power and the power cap with a tenth below 10 W, as they fit the same width; they are still truncated to whole watts from 10 W on. In the snapshot, which scripts read, give them in milliwatts, the resolution the backends report them in, rather than in truncated watts: "power_draw": "1400mW" instead of "1W".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
nvtop's amdgpu backend now reports most of what the amdgpu driver exposes in its
gpu_metricssysfs table, preferring the driver's own interfaces when they exist and usinggpu_metricsas the fallback. The AMD NPU backend reads the NPU values the firmware puts in the APU's table, and a few generic interface changes make room for the new values.What NVTOP now shows on AMD
-i)pcie_bwsince Linux 6.9Sources
vcn_busy_percentwhen the driver has it (some APUs since Linux 6.10, RDNA 3, RDNA 4 and the other APUs since 6.15). Otherwisegpu_metrics: v1.1–v1.3, per engine on MI300 (v1.5, v1.7, v1.8, v1.9), and v2.1 for Phoenix. It is only used for the shared encode/decode meter (VCN 4 and later), as neither source tells encoding from decoding. The v3.0 APU value is not decoded, because its unit depends on the driver and the kernel version.gpu_metricsdecoding: v1.0–v1.3, v1.5, v1.7, v1.8, the v1.9 attribute stream, v2.1–v2.4 and v3.0. The offsets were checked against the kernel'skgd_pp_interface.hof the releases that use them, on 64-bit and 32-bit layouts, and the tests use the kernel's offsets independently of nvtop's structs. Unreported fields (all ones) and truncated tables are rejected.gpu_metrics, not through amdxdna'sDRM_AMDXDNA_QUERY_SENSORS, which would need opening the NPU node. The backend deliberately never opens it, as an open creates a driver client and binds nvtop's address space. A table that cannot be read at startup (runtime-suspended GPU) is looked for again, up to 10 failed lookups.pwm1_enable/fan1_enable, which give the control mode. The measured RPM overfan1_maxis used first, capped at 100%, andpwm1/pwm1_maxonly for fans without an RPM sensor.Interface changes
pcie_throughputfield, shown as "Throughput" instead of RX/TX, and printed in the snapshot only for the devices that report it.gpu_util_busiest_enginein the snapshot. It takes precedence over the effective load in the value."power_draw": "1400mW"instead of"1W".Known limitations
Testing
pcie_bwfails to read on kernels before 6.10 and is hidden from 6.10.gpu_metrics, so nothing new is shown, as expected.