Report NPU power and per-column utilization from the sensor query - #1
Open
hiasihaho wants to merge 1 commit into
Open
Report NPU power and per-column utilization from the sensor query#1hiasihaho wants to merge 1 commit into
hiasihaho wants to merge 1 commit into
Conversation
The driver exposes a sensor block via GET_INFO param 4 that nputop was not reading: NPU package power and per-column busy percentage, both sourced from amd_pmf NPU metrics. Per-column busy is the utilization signal the TUI was missing. TOPS tracks the clock rather than the load, so it reads high whenever power management has clocked the NPU up, whether or not work is queued -- as the README already noted, it is a capacity metric. Make busy percentage the headline bar when it is available, keep TOPS as text alongside it, and add a per-column sparkline so it is visible when a workload occupies only part of the array. Power lands in the existing Power panel as a watts reading. The query needs HAVE_7_0_amd_pmf_get_npu_data in the driver and is unsupported on PHX/HPT, so treat an ioctl failure as "no sensors" and fall back to the previous TOPS bar. All-zero readings are a legitimate idle result and are shown as such. Two details of the kernel ABI worth recording: the driver truncates the sensor array silently instead of returning ENOSPC, so the buffer is oversized and the written byte count is what bounds parsing; and the raw value scales by 10**unitm to reach the SI base unit, which turns the power sensor's mW/-3 into watts.
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.
The driver exposes a sensor block via
GET_INFOparam 4 (DRM_AMDXDNA_QUERY_SENSORS) that nputop wasn't reading: NPU package power and per-column busy percentage, both sourced from amd_pmf NPU metrics. This adds the query and surfaces both.Per-column busy is the utilization signal the TUI was missing. As the README already notes, TOPS is a capacity metric — it's derived from the current clock, so it reads high whenever power management has clocked the NPU up, whether or not there's work queued. On my machine during an 8B decode it read
TOPS 41/58while the array was 99% busy, so the headline bar was showing ~70% for a saturated NPU. (It can also exceedtops_max; I've seen59/58.)So: busy percentage becomes the headline bar when available, TOPS stays as text next to Tasks, and a per-column sparkline shows whether a workload spans the array or sits in a corner. Power lands in the existing Power panel as a watts reading.
Display
Idle:
Under a FastFlowLM 8B decode:
Power tracked 0.78–1.9 W across runs depending on clock state.
Two ABI details worth recording
The driver truncates the sensor array silently instead of returning
ENOSPC.aie2_query_sensorsdecrementsbuffer_sizeper sensor written and jumps toout:when the next one won't fit, where it setsargs->buffer_size = sensors_count * sizeof(sensor). A too-small buffer therefore looks like "fewer sensors", not an error._get_infoassumes a fixed-size reply, so I added_get_info_sized(), which oversizes the buffer and bounds parsing by the byte count written back.The raw value scales by
10**unitmto reach the SI base unit. The header comment says "translates value into the correct unit via pow(10, unitm) * value", which taken together withunits = "mW"would make the power reading 1.887 mW under load. The driver assignssensor.input = npu_metrics.npu_power(mW) withunitm = -3, so the scaled value is watts andunitsdescribes the raw field. Column utilization is consistent with this:unitm = 0,units = "%". Flagging it because it's a judgement call and the header comment reads the other way.Degradation
The query needs
HAVE_7_0_amd_pmf_get_npu_datain the driver build, and AMD's docs say power reporting is unsupported on PHX/HPT. So an ioctl failure is treated as "no sensors" and the panel falls back to the previous TOPS bar, titledTOPS & Tasksas before. All-zero readings are a legitimate idle result and are shown as such rather than being mistaken for missing sensors.Panels gain a line when sensors are present and Rich sizes each independently, so they're pinned to a common height to keep the borders aligned.
Testing
Strix Halo, firmware 1.1.2.65, Fedora 43, kernel 7.1.0-rc5, AMD out-of-tree amdxdna (xrt-amdxdna 2.21.75) via DKMS.
query_sensors: returnsNone, power-without-columns, and columns-without-power. Each falls back correctly and keeps borders aligned.I can't test the PHX/HPT or no-PMF paths on this hardware — only that the fallback renders when the query is stubbed out.
🤖 Generated with Claude Code
https://claude.ai/code/session_016G1XTP4RxcrBsyrrDxMxPM